]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Hack around asynchronous device_del
authorJiri Denemark <jdenemar@redhat.com>
Mon, 9 Aug 2010 12:14:34 +0000 (14:14 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Tue, 10 Aug 2010 14:59:49 +0000 (16:59 +0200)
device_del command is not synchronous for PCI devices, it merely asks
the guest to release the device and returns. If the host wants to use
that device before the guest actually releases it, we are in big
trouble. To avoid this, we already added a loop which waits up to 10
seconds until the device is actually released before we do anything else
with that device. But we only added this loop for managed PCI devices
before we try reattach them back to the host.

However, we need to wait even for non-managed devices. We don't reattach
them automatically, but we still want to prevent the host from using it.
This was revealed thanks to sVirt: when we relabel sysfs files
corresponding to the PCI device before the guest finished releasing the
device, qemu is no longer allowed to access those files and if it wants
(as a result of guest's request) to write anything to them, it just
exits, which kills the guest.

This is not a proper fix and needs some further work both on libvirt and
qemu side in the future.

src/qemu/qemu_driver.c

index 57b82712a7975f8f66979d3338f507e02e1c3da5..e4f47d4ff7f8b7df1dcf9e2c277b96b05aed9112 100644 (file)
@@ -3209,16 +3209,17 @@ qemuPrepareChardevDevice(virDomainDefPtr def ATTRIBUTE_UNUSED,
 
 
 static void
-qemudReattachManagedDevice(pciDevice *dev, struct qemud_driver *driver)
+qemudReattachPciDevice(pciDevice *dev, struct qemud_driver *driver)
 {
     int retries = 100;
 
+    while (pciWaitForDeviceCleanup(dev, "kvm_assigned_device")
+           && retries) {
+        usleep(100*1000);
+        retries--;
+    }
+
     if (pciDeviceGetManaged(dev)) {
-        while (pciWaitForDeviceCleanup(dev, "kvm_assigned_device")
-               && retries) {
-            usleep(100*1000);
-            retries--;
-        }
         if (pciReAttachDevice(dev, driver->activePciHostdevs) < 0) {
             virErrorPtr err = virGetLastError();
             VIR_ERROR(_("Failed to re-attach PCI device: %s"),
@@ -3264,7 +3265,7 @@ qemuDomainReAttachHostdevDevices(struct qemud_driver *driver,
 
     for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
         pciDevice *dev = pciDeviceListGet(pcidevs, i);
-        qemudReattachManagedDevice(dev, driver);
+        qemudReattachPciDevice(dev, driver);
     }
 
     pciDeviceListFree(pcidevs);
@@ -8997,7 +8998,7 @@ static int qemudDomainDetachHostPciDevice(struct qemud_driver *driver,
         pciDeviceListDel(driver->activePciHostdevs, pci);
         if (pciResetDevice(pci, driver->activePciHostdevs, NULL) < 0)
             ret = -1;
-        qemudReattachManagedDevice(pci, driver);
+        qemudReattachPciDevice(pci, driver);
         pciFreeDevice(pci);
     }