Skip to content
  • Paolo Bonzini's avatar
    6b49809c
    cpus: fix deadlock and segfault in qemu_mutex_lock_iothread · 6b49809c
    Paolo Bonzini authored
    
    
    When two threads (other than the low-priority TCG VCPU thread)
    are competing for the iothread lock, a deadlock can happen.  This
    is because iothread_requesting_mutex is set to false by the first
    thread that gets the mutex, and then the VCPU thread might never
    yield from the execution loop.  If iothread_requesting_mutex is
    changed from a bool to a counter, the deadlock is fixed.
    
    However, there is another bug in qemu_mutex_lock_iothread that
    can be triggered by the new call_rcu thread.  The bug happens
    if qemu_mutex_lock_iothread is called before the CPUs are
    created.  In that case, first_cpu is NULL and the caller
    segfaults in qemu_mutex_lock_iothread.  To fix this, just
    do not do the kick if first_cpu is NULL.
    
    Reported-by: default avatarLeon Alrae <leon.alrae@imgtec.com>
    Reported-by: default avatarAndreas Gustafsson <gson@gson.org>
    Tested-by: default avatarLeon Alrae <leon.alrae@imgtec.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    6b49809c
    cpus: fix deadlock and segfault in qemu_mutex_lock_iothread
    Paolo Bonzini authored
    
    
    When two threads (other than the low-priority TCG VCPU thread)
    are competing for the iothread lock, a deadlock can happen.  This
    is because iothread_requesting_mutex is set to false by the first
    thread that gets the mutex, and then the VCPU thread might never
    yield from the execution loop.  If iothread_requesting_mutex is
    changed from a bool to a counter, the deadlock is fixed.
    
    However, there is another bug in qemu_mutex_lock_iothread that
    can be triggered by the new call_rcu thread.  The bug happens
    if qemu_mutex_lock_iothread is called before the CPUs are
    created.  In that case, first_cpu is NULL and the caller
    segfaults in qemu_mutex_lock_iothread.  To fix this, just
    do not do the kick if first_cpu is NULL.
    
    Reported-by: default avatarLeon Alrae <leon.alrae@imgtec.com>
    Reported-by: default avatarAndreas Gustafsson <gson@gson.org>
    Tested-by: default avatarLeon Alrae <leon.alrae@imgtec.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Loading