[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 068/108] aio: fix qemu_bh_schedule() bh->ctx race co
From: |
Michael Roth |
Subject: |
[Qemu-devel] [PATCH 068/108] aio: fix qemu_bh_schedule() bh->ctx race condition |
Date: |
Wed, 6 Aug 2014 15:39:18 -0500 |
From: Stefan Hajnoczi <address@hidden>
qemu_bh_schedule() is supposed to be thread-safe at least the first time
it is called. Unfortunately this is not quite true:
bh->scheduled = 1;
aio_notify(bh->ctx);
Since another thread may run the BH callback once it has been scheduled,
there is a race condition if the callback frees the BH before
aio_notify(bh->ctx) has a chance to run.
Reported-by: Stefan Priebe <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
Reviewed-by: Paolo Bonzini <address@hidden>
Tested-by: Stefan Priebe <address@hidden>
(cherry picked from commit 924fe1293c3e7a3c787bbdfb351e7f168caee3e9)
Signed-off-by: Michael Roth <address@hidden>
---
async.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/async.c b/async.c
index 6930185..5b6fe6b 100644
--- a/async.c
+++ b/async.c
@@ -117,15 +117,21 @@ void qemu_bh_schedule_idle(QEMUBH *bh)
void qemu_bh_schedule(QEMUBH *bh)
{
+ AioContext *ctx;
+
if (bh->scheduled)
return;
+ ctx = bh->ctx;
bh->idle = 0;
- /* Make sure that idle & any writes needed by the callback are done
- * before the locations are read in the aio_bh_poll.
+ /* Make sure that:
+ * 1. idle & any writes needed by the callback are done before the
+ * locations are read in the aio_bh_poll.
+ * 2. ctx is loaded before scheduled is set and the callback has a chance
+ * to execute.
*/
- smp_wmb();
+ smp_mb();
bh->scheduled = 1;
- aio_notify(bh->ctx);
+ aio_notify(ctx);
}
--
1.9.1
- [Qemu-devel] [PATCH 059/108] blockdev: Plug memory leak in drive_init(), (continued)
- [Qemu-devel] [PATCH 059/108] blockdev: Plug memory leak in drive_init(), Michael Roth, 2014/08/06
- [Qemu-devel] [PATCH 060/108] blockdev: Plug memory leak in blockdev_init(), Michael Roth, 2014/08/06
- [Qemu-devel] [PATCH 062/108] block: Plug memory leak on brv_open_image() error path, Michael Roth, 2014/08/06
- [Qemu-devel] [PATCH 064/108] linux-user: Don't overrun guest buffer in sched_getaffinity, Michael Roth, 2014/08/06
- [Qemu-devel] [PATCH 063/108] qcow2: Plug memory leak on qcow2_invalidate_cache() error paths, Michael Roth, 2014/08/06
- [Qemu-devel] [PATCH 061/108] qemu-io: Plug memory leak in open command, Michael Roth, 2014/08/06
- [Qemu-devel] [PATCH 065/108] tcg-i386: Fix win64 qemu store, Michael Roth, 2014/08/06
- [Qemu-devel] [PATCH 066/108] target-arm: Fix errors in writes to generic timer control registers, Michael Roth, 2014/08/06
- [Qemu-devel] [PATCH 034/108] qdev: Fix crash by validating the object type, Michael Roth, 2014/08/06
- [Qemu-devel] [PATCH 067/108] s390x/css: handle emw correctly for tsch, Michael Roth, 2014/08/06
- [Qemu-devel] [PATCH 068/108] aio: fix qemu_bh_schedule() bh->ctx race condition,
Michael Roth <=
- [Qemu-devel] [PATCH 070/108] migration: remove duplicate code, Michael Roth, 2014/08/06
- [Qemu-devel] [PATCH 069/108] qga: Fix handle fd leak in acquire_privilege(), Michael Roth, 2014/08/06
- [Qemu-devel] [PATCH 071/108] arch_init: Be sure of only one exit entry with DPRINTF() for ram_load(), Michael Roth, 2014/08/06
- [Qemu-devel] [PATCH 072/108] migration: catch unknown flags in ram_load, Michael Roth, 2014/08/06
- [Qemu-devel] [PATCH 073/108] rdma: bug fixes, Michael Roth, 2014/08/06
- [Qemu-devel] [PATCH 075/108] qdev: reorganize error reporting in bus_set_realized, Michael Roth, 2014/08/06
- [Qemu-devel] [PATCH 076/108] qdev: recursively unrealize devices when unrealizing bus, Michael Roth, 2014/08/06
- [Qemu-devel] [PATCH 078/108] vhost: fix resource leak in error handling, Michael Roth, 2014/08/06
- [Qemu-devel] [PATCH 077/108] scsi-disk: fix bug in scsi_block_new_request() introduced by commit 137745c, Michael Roth, 2014/08/06
- [Qemu-devel] [PATCH 079/108] virtio-scsi: define dummy handle_output for vhost-scsi vqs, Michael Roth, 2014/08/06