qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] hotplug: VM got stuck when attaching a pass-through device to the non-pass-through VM for the first time
@ 2014-02-18  2:38 Zhanghaoyu (A)
  2014-02-18 10:38 ` Michael S. Tsirkin
  0 siblings, 1 reply; 9+ messages in thread
From: Zhanghaoyu (A) @ 2014-02-18  2:38 UTC (permalink / raw)
  To: qemu-devel@nongnu.org, KVM, Paolo Bonzini, Gleb Natapov,
	Michael S. Tsirkin, Avi Kivity, Eric Blake
  Cc: chenliang (T), Huangweidong (C), Zhanghaoyu (A), Luonengjun,
	Gonglei (Arei), Gaowei (UVP)

Hi, all

The VM will get stuck for a while(about 6s for a VM with 20GB memory) when attaching a pass-through PCI card to the non-pass-through VM for the first time. 
The reason is that the host will build the whole VT-d GPA->HPA DMAR page-table, which needs a lot of time, and during this time, the qemu_global_mutex
lock is hold by the main-thread, if the vcpu thread IOCTL return, it will be blocked to waiting main-thread to release the qemu_global_mutex lock,
so the VM got stuck.
The race between qemu-main-thread and vcpu-thread is shown as below,

              QEMU-main-thread                                vcpu-thread           
                     |                                             |
      qemu_mutex_lock_iothread                     qemu_mutex_lock(&qemu_global_mutex)
                     |                                             |
        +----loop- ->+                               +----loop---->+               
        |            |                               |             |
        |  qemu_mutex_unlock_iothread                | qemu_mutex_unlock_iothread 
        |            |                               |             |              
        |           poll                             |    kvm_vcpu_ioctl(KVM_RUN) 
        |            |                               |             |              
        | qemu_mutex_lock_iothread                   |             |
        |            |                               |             | 
 --------------------------------------------------------------------------------------
        |            |                               |  qemu_mutex_lock_iothread
        |   kvm_device_pci_assign                    |             |              
        |            |                               |   blocked to waiting main-thread to release the qemu lock
        |      about 6 sec for 20GB memory           |             |              
        |            |                               |             |                     
        +------------+                               +-------------+              


Any advises?

Thanks,
Zhang Haoyu

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-02-24 11:38 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-18  2:38 [Qemu-devel] hotplug: VM got stuck when attaching a pass-through device to the non-pass-through VM for the first time Zhanghaoyu (A)
2014-02-18 10:38 ` Michael S. Tsirkin
2014-02-18 10:42   ` Paolo Bonzini
2014-02-18 10:51     ` Michael S. Tsirkin
2014-02-18 11:05       ` Paolo Bonzini
2014-02-18 11:16         ` Michael S. Tsirkin
2014-02-24 11:38         ` Zhanghaoyu (A)
2014-02-18 11:17     ` Zhanghaoyu (A)
2014-02-18 10:59   ` Zhanghaoyu (A)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).