]> xenbits.xensource.com Git - qemu-upstream-4.6-testing.git/commit
qemu-thread: fix qemu_event without futexes
authorPaolo Bonzini <pbonzini@redhat.com>
Mon, 2 Feb 2015 15:36:51 +0000 (16:36 +0100)
committerMichael Roth <mdroth@linux.vnet.ibm.com>
Tue, 24 Feb 2015 00:04:34 +0000 (18:04 -0600)
commita9eb2b60538e2cb48cc71824d2c6239a8aa85cb8
tree1c45d00797323e81c5bf20da3ba04d051da1506d
parent4d49de6b6f9b45446dd31990a177b13953f2e842
qemu-thread: fix qemu_event without futexes

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: qemu-stable@nongnu.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit 158ef8cbb7e0fe8bb430310924b8bebe5f186e6e)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
util/qemu-thread-posix.c