Skip to content
  • Paolo Bonzini's avatar
    158ef8cb
    qemu-thread: fix qemu_event without futexes · 158ef8cb
    Paolo Bonzini authored
    
    
    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: default avatarPaolo Bonzini <pbonzini@redhat.com>
    158ef8cb
    qemu-thread: fix qemu_event without futexes
    Paolo Bonzini authored
    
    
    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: default avatarPaolo Bonzini <pbonzini@redhat.com>
Loading