]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
hypervisor: Call virWaitForDevices() after detaching host devices
authorPavel Hrdina <phrdina@redhat.com>
Thu, 26 Mar 2026 13:32:36 +0000 (14:32 +0100)
committerPavel Hrdina <phrdina@redhat.com>
Fri, 27 Mar 2026 12:58:35 +0000 (13:58 +0100)
On systems with selinux enabled starting a VM with managed host device
using IOMMUFD backend can run into race-condition where both libvirt and
udev are setting selinux label on /dev/vfio/devices/vfioX device. If
udev is the last one to set selinux label starting VM fails with:

error: internal error: QEMU unexpectedly closed the monitor (vm='test'): 2026-03-26T15:47:36.620422Z qemu-kvm: -device {"driver":"vfio-pci","id":"hostdev0","iommufd":"iommufd0","fd":"20","bus":"pci.7","addr":"0x0"}: vfio hostdev0: Failed to add fd 20 to KVM VFIO device: Invalid argument

We need to wait for udev to finish processing all events.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/hypervisor/virhostdev.c

index f4d217620496165dd8e0958eadd280b59ce3e3a5..b063a44f622976f7855c1bc42ec9f3a82038261c 100644 (file)
@@ -782,6 +782,9 @@ virHostdevPreparePCIDevicesImpl(virHostdevManager *mgr,
         }
     }
 
+    /* Step 2.5: Wait for udev to handle all events for devices. */
+    virWaitForDevices();
+
     /* At this point, all devices are attached to the stub driver and have
      * been marked as inactive */