Skip to content
  • Paolo Bonzini's avatar
    73c6e401
    rcu: completely disable pthread_atfork callbacks as soon as possible · 73c6e401
    Paolo Bonzini authored
    
    
    Because of -daemonize, system mode QEMU sometimes needs to fork() and
    keep RCU enabled in the child.  However, there is a possible deadlock
    with synchronize_rcu:
    
    - the CPU thread is inside a RCU critical section and wants to take
      the BQL in order to do MMIO
    
    - the monitor thread, which is owning the BQL, calls rcu_init_lock
      which tries to take the rcu_sync_lock
    
    - the call_rcu thread has taken rcu_sync_lock in synchronize_rcu, but
      synchronize_rcu needs the CPU thread to end the critical section
      before returning.
    
    This cannot happen for user-mode emulation, because it does not have
    a BQL.
    
    To fix it, assume that system mode QEMU only forks in preparation for
    exec (except when daemonizing) and disable pthread_atfork as soon as
    the double fork has happened.
    
    Reported-by: default avatarDr. David Alan Gilbert <dgilbert@redhat.com>
    Tested-by: default avatarDr. David Alan Gilbert <dgilbert@redhat.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    73c6e401
    rcu: completely disable pthread_atfork callbacks as soon as possible
    Paolo Bonzini authored
    
    
    Because of -daemonize, system mode QEMU sometimes needs to fork() and
    keep RCU enabled in the child.  However, there is a possible deadlock
    with synchronize_rcu:
    
    - the CPU thread is inside a RCU critical section and wants to take
      the BQL in order to do MMIO
    
    - the monitor thread, which is owning the BQL, calls rcu_init_lock
      which tries to take the rcu_sync_lock
    
    - the call_rcu thread has taken rcu_sync_lock in synchronize_rcu, but
      synchronize_rcu needs the CPU thread to end the critical section
      before returning.
    
    This cannot happen for user-mode emulation, because it does not have
    a BQL.
    
    To fix it, assume that system mode QEMU only forks in preparation for
    exec (except when daemonizing) and disable pthread_atfork as soon as
    the double fork has happened.
    
    Reported-by: default avatarDr. David Alan Gilbert <dgilbert@redhat.com>
    Tested-by: default avatarDr. David Alan Gilbert <dgilbert@redhat.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Loading