mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-11-02 11:21:12 +00:00
7882c6eca5
A deadlock situation can occur when autostarting a LXC domain 'guest' due to two threads attempting to take opposing locks while holding opposing locks (AB BA problem). Thread A takes and holds the 'vm' lock while attempting to take the 'client' lock, meanwhile, thread B takes and holds the 'client' lock while attempting to take the 'vm' lock. The potential for this can be seen as follows: Thread A: virLXCProcessAutostartDomain (takes vm lock) --> virLXCProcessStart --> virLXCProcessConnectMonitor --> virLXCMonitorNew --> virNetClientSetCloseCallback (wants client lock) Thread B: virNetClientIncomingEvent (takes client lock) --> virNetClientIOHandleInput --> virNetClientCallDispatch --> virNetClientCallDispatchMessage --> virNetClientProgramDispatch --> virLXCMonitorHandleEventInit --> virLXCProcessMonitorInitNotify (wants vm lock) Since these threads are scheduled independently and are preemptible it is possible for the deadlock scenario to occur where each thread locks their first lock but both will fail to get their second lock and just spin forever. You get something like: virLXCProcessAutostartDomain (takes vm lock) --> virLXCProcessStart --> virLXCProcessConnectMonitor --> virLXCMonitorNew <...> virNetClientIncomingEvent (takes client lock) --> virNetClientIOHandleInput --> virNetClientCallDispatch --> virNetClientCallDispatchMessage --> virNetClientProgramDispatch --> virLXCMonitorHandleEventInit --> virLXCProcessMonitorInitNotify (wants vm lock but spins) <...> --> virNetClientSetCloseCallback (wants client lock but spins) Neither thread ever gets the lock it needs to be able to continue while holding the lock that the other thread needs. The actual window for preemption which can cause this deadlock is rather small, between the calls to virNetClientProgramNew() and execution of virNetClientSetCloseCallback(), both in virLXCMonitorNew(). But it can be seen in real world use that this small window is enough. By moving the call to virNetClientSetCloseCallback() ahead of virNetClientProgramNew() we can close any possible chance of the deadlock taking place. There should be no other implications to the move since the close callback (in the unlikely event was called) will spin on the vm lock. The remaining work that takes place between the old call location of virNetClientSetCloseCallback() and the new location is unaffected by the move. Signed-off-by: Mark Asselstine <mark.asselstine@windriver.com> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> |
||
---|---|---|
.. | ||
access | ||
admin | ||
bhyve | ||
conf | ||
cpu | ||
cpu_map | ||
esx | ||
hyperv | ||
interface | ||
keycodemapdb@16e5b07876 | ||
libxl | ||
locking | ||
logging | ||
lxc | ||
network | ||
node_device | ||
nwfilter | ||
openvz | ||
phyp | ||
qemu | ||
remote | ||
rpc | ||
secret | ||
security | ||
storage | ||
test | ||
uml | ||
util | ||
vbox | ||
vmware | ||
vmx | ||
vz | ||
xenapi | ||
xenconfig | ||
admin_protocol-structs | ||
check-aclperms.pl | ||
check-aclrules.pl | ||
check-driverimpls.pl | ||
check-drivername.pl | ||
check-symfile.pl | ||
check-symsorting.pl | ||
datatypes.c | ||
datatypes.h | ||
driver-hypervisor.h | ||
driver-interface.h | ||
driver-network.h | ||
driver-nodedev.h | ||
driver-nwfilter.h | ||
driver-secret.h | ||
driver-state.h | ||
driver-storage.h | ||
driver-stream.h | ||
driver.c | ||
driver.h | ||
dtrace2systemtap.pl | ||
internal.h | ||
libvirt_admin_private.syms | ||
libvirt_admin_public.syms | ||
libvirt_atomic.syms | ||
libvirt_driver_modules.syms | ||
libvirt_esx.syms | ||
libvirt_internal.h | ||
libvirt_libssh2.syms | ||
libvirt_libssh.syms | ||
libvirt_linux.syms | ||
libvirt_lxc.syms | ||
libvirt_openvz.syms | ||
libvirt_private.syms | ||
libvirt_probes.d | ||
libvirt_public.syms | ||
libvirt_qemu_probes.d | ||
libvirt_qemu.syms | ||
libvirt_remote.syms | ||
libvirt_sasl.syms | ||
libvirt_vmware.syms | ||
libvirt_vmx.syms | ||
libvirt_xenconfig.syms | ||
libvirt-admin.c | ||
libvirt-admin.conf | ||
libvirt-domain-snapshot.c | ||
libvirt-domain.c | ||
libvirt-host.c | ||
libvirt-interface.c | ||
libvirt-lxc.c | ||
libvirt-lxc.pc.in | ||
libvirt-network.c | ||
libvirt-nodedev.c | ||
libvirt-nwfilter.c | ||
libvirt-qemu.c | ||
libvirt-qemu.pc.in | ||
libvirt-secret.c | ||
libvirt-storage.c | ||
libvirt-stream.c | ||
libvirt.c | ||
libvirt.conf | ||
libvirt.pc.in | ||
lock_protocol-structs | ||
lxc_monitor_protocol-structs | ||
lxc_protocol-structs | ||
Makefile.am | ||
qemu_protocol-structs | ||
README | ||
remote_protocol-structs | ||
virkeepaliveprotocol-structs | ||
virnetprotocol-structs |
libvirt library code README =========================== The directory provides the bulk of the libvirt codebase. Everything except for the libvirtd daemon and client tools. The build uses a large number of libtool convenience libraries - one for each child directory, and then links them together for the final libvirt.so, although some bits get linked directly to libvirtd daemon instead. The files directly in this directory are supporting the public API entry points & data structures. There are two core shared modules to be aware of: * util/ - a collection of shared APIs that can be used by any code. This directory is always in the include path for all things built * conf/ - APIs for parsing / manipulating all the official XML files used by the public API. This directory is only in the include path for driver implementation modules * vmx/ - VMware VMX config handling (used by esx/ and vmware/) Then there are the hypervisor implementations: * bhyve - bhyve - The BSD Hypervisor * esx/ - VMware ESX and GSX support using vSphere API over SOAP * hyperv/ - Microsoft Hyper-V support using WinRM * lxc/ - Linux Native Containers * openvz/ - OpenVZ containers using cli tools * phyp/ - IBM Power Hypervisor using CLI tools over SSH * qemu/ - QEMU / KVM using qemu CLI/monitor * remote/ - Generic libvirt native RPC client * test/ - A "mock" driver for testing * uml/ - User Mode Linux * vbox/ - Virtual Box using native API * vmware/ - VMware Workstation and Player using the vmrun tool * xen/ - Xen using hypercalls, XenD SEXPR & XenStore * xenapi/ - Xen using libxenserver Finally some secondary drivers that are shared for several HVs. Currently these are used by LXC, OpenVZ, QEMU, UML and Xen drivers. The ESX, Hyper-V, Power Hypervisor, Remote, Test & VirtualBox drivers all implement the secondary drivers directly * cpu/ - CPU feature management * interface/ - Host network interface management * network/ - Virtual NAT networking * nwfilter/ - Network traffic filtering rules * node_device/ - Host device enumeration * secret/ - Secret management * security/ - Mandatory access control drivers * storage/ - Storage management drivers Since both the hypervisor and secondary drivers can be built as dlopen()able modules, it is *FORBIDDEN* to have build dependencies between these directories. Drivers are only allowed to depend on the public API, and the internal APIs in the util/ and conf/ directories