[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 38/43] qemu-thread: fix qemu_event without futexes
From: |
Michael Roth |
Subject: |
[Qemu-devel] [PATCH 38/43] qemu-thread: fix qemu_event without futexes |
Date: |
Tue, 24 Feb 2015 15:48:13 -0600 |
From: Paolo Bonzini <address@hidden>
This had a possible deadlock that was visible with rcutorture.
qemu_event_set qemu_event_wait
----------------------------------------------------------------
cmpxchg reads FREE, writes BUSY
futex_wait: pthread_mutex_lock
futex_wait: value == BUSY
xchg reads BUSY, writes SET
futex_wake: pthread_cond_broadcast
futex_wait: pthread_cond_wait
<deadlock>
The fix is simply to avoid condvar tricks and do the obvious locking
around pthread_cond_broadcast:
qemu_event_set qemu_event_wait
----------------------------------------------------------------
cmpxchg reads FREE, writes BUSY
futex_wait: pthread_mutex_lock
futex_wait: value == BUSY
xchg reads BUSY, writes SET
futex_wake: pthread_mutex_lock
(blocks)
futex_wait: pthread_cond_wait
(mutex unlocked)
futex_wake: pthread_cond_broadcast
futex_wake: pthread_mutex_unlock
futex_wait: pthread_mutex_unlock
Cc: address@hidden
Signed-off-by: Paolo Bonzini <address@hidden>
(cherry picked from commit 158ef8cbb7e0fe8bb430310924b8bebe5f186e6e)
Signed-off-by: Michael Roth <address@hidden>
---
util/qemu-thread-posix.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c
index d05a649..bb14ad4 100644
--- a/util/qemu-thread-posix.c
+++ b/util/qemu-thread-posix.c
@@ -306,11 +306,13 @@ static inline void futex_wait(QemuEvent *ev, unsigned val)
#else
static inline void futex_wake(QemuEvent *ev, int n)
{
+ pthread_mutex_lock(&ev->lock);
if (n == 1) {
pthread_cond_signal(&ev->cond);
} else {
pthread_cond_broadcast(&ev->cond);
}
+ pthread_mutex_unlock(&ev->lock);
}
static inline void futex_wait(QemuEvent *ev, unsigned val)
--
1.9.1
- [Qemu-devel] [PATCH 33/43] virtio: fix feature bit checks, (continued)
- [Qemu-devel] [PATCH 33/43] virtio: fix feature bit checks, Michael Roth, 2015/02/24
- [Qemu-devel] [PATCH 32/43] vt82c686: avoid out-of-bounds read, Michael Roth, 2015/02/24
- [Qemu-devel] [PATCH 31/43] target-i386: fix movntsd on big-endian hosts, Michael Roth, 2015/02/24
- [Qemu-devel] [PATCH 30/43] scsi: fix cancellation when I/O was completed but DMA was not., Michael Roth, 2015/02/24
- [Qemu-devel] [PATCH 02/43] block: Omit bdrv_find_format for essential drivers, Michael Roth, 2015/02/24
- [Qemu-devel] [PATCH 36/43] target-arm/translate-a64: Fix wrong mmu_idx usage for LDT/STT, Michael Roth, 2015/02/24
- [Qemu-devel] [PATCH 34/43] sb16: fix interrupt acknowledgement, Michael Roth, 2015/02/24
- [Qemu-devel] [PATCH 35/43] hw/input/hid.c Fix capslock hid code, Michael Roth, 2015/02/24
- [Qemu-devel] [PATCH 39/43] libcacard: stop linking against every single 3rd party library, Michael Roth, 2015/02/24
- [Qemu-devel] [PATCH 37/43] vfio-pci: Fix missing unparent of dynamically allocated MemoryRegion, Michael Roth, 2015/02/24
- [Qemu-devel] [PATCH 38/43] qemu-thread: fix qemu_event without futexes,
Michael Roth <=
- [Qemu-devel] [PATCH 40/43] fix mc146818rtc wrong subsection name to avoid vmstate_subsection_load() fail, Michael Roth, 2015/02/24
- [Qemu-devel] [PATCH 03/43] block/vvfat: qcow driver may not be found, Michael Roth, 2015/02/24
- [Qemu-devel] [PATCH 43/43] exec: change default exception_index value for migration to -1, Michael Roth, 2015/02/24
- [Qemu-devel] [PATCH 41/43] block/iscsi: fix uninitialized variable, Michael Roth, 2015/02/24
- [Qemu-devel] [PATCH 42/43] qtest: Fix deadloop by running main loop AIO context's timers, Michael Roth, 2015/02/24
- [Qemu-devel] [PATCH 06/43] qemu-img: Check create_opts before image creation, Michael Roth, 2015/02/24
- [Qemu-devel] [PATCH 04/43] block/nfs: Add create_opts, Michael Roth, 2015/02/24
- [Qemu-devel] [PATCH 08/43] iotests: Only kill NBD server if it runs, Michael Roth, 2015/02/24
- [Qemu-devel] [PATCH 05/43] block: Check create_opts before image creation, Michael Roth, 2015/02/24
- [Qemu-devel] [PATCH 07/43] qemu-img: Check create_opts before image amendment, Michael Roth, 2015/02/24