]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virhostdev: Check driver name too in virHostdevIsPCINodeDeviceUsed()
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 14 Aug 2019 09:13:21 +0000 (11:13 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Sat, 17 Aug 2019 10:25:29 +0000 (12:25 +0200)
It may happen that there are two domains with the same name in
two separate drivers (e.g. qemu and lxc). That is why for PCI
devices we track both names of driver and domain combination
which has taken the device. However, when we check if given PCI
device is in use (or PCI devices from the same IOMMU group) we
compare only domain name. This means that we can mistakenly claim
device as free to use while in fact it isn't.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
src/util/virhostdev.c

index 75e44b5227518954d019748a38094b5a93e7a61f..cb69582c211259680576d2176b8a7bea2f1e90ec 100644 (file)
@@ -51,6 +51,7 @@ static virHostdevManagerPtr virHostdevManagerNew(void);
 
 struct virHostdevIsPCINodeDeviceUsedData {
     virHostdevManagerPtr mgr;
+    const char *driverName;
     const char *domainName;
     const bool usesVFIO;
 };
@@ -91,8 +92,8 @@ static int virHostdevIsPCINodeDeviceUsed(virPCIDeviceAddressPtr devAddr, void *o
         virPCIDeviceGetUsedBy(actual, &actual_drvname, &actual_domname);
 
         if (helperData->usesVFIO &&
-            (actual_domname && helperData->domainName) &&
-            (STREQ(actual_domname, helperData->domainName)))
+            STREQ_NULLABLE(actual_drvname, helperData->driverName) &&
+            STREQ_NULLABLE(actual_domname, helperData->domainName))
             goto iommu_owner;
 
         if (actual_drvname && actual_domname)
@@ -706,7 +707,7 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr,
         virPCIDevicePtr pci = virPCIDeviceListGet(pcidevs, i);
         bool strict_acs_check = !!(flags & VIR_HOSTDEV_STRICT_ACS_CHECK);
         bool usesVFIO = (virPCIDeviceGetStubDriver(pci) == VIR_PCI_STUB_DRIVER_VFIO);
-        struct virHostdevIsPCINodeDeviceUsedData data = { mgr, dom_name, usesVFIO };
+        struct virHostdevIsPCINodeDeviceUsedData data = {mgr, drv_name, dom_name, usesVFIO};
         int hdrType = -1;
 
         if (virPCIGetHeaderType(pci, &hdrType) < 0)
@@ -1995,7 +1996,7 @@ int
 virHostdevPCINodeDeviceDetach(virHostdevManagerPtr mgr,
                               virPCIDevicePtr pci)
 {
-    struct virHostdevIsPCINodeDeviceUsedData data = { mgr, NULL, false };
+    struct virHostdevIsPCINodeDeviceUsedData data = {mgr, NULL, NULL, false};
     int ret = -1;
 
     virObjectLock(mgr->activePCIHostdevs);
@@ -2021,7 +2022,7 @@ int
 virHostdevPCINodeDeviceReAttach(virHostdevManagerPtr mgr,
                                 virPCIDevicePtr pci)
 {
-    struct virHostdevIsPCINodeDeviceUsedData data = { mgr, NULL, false };
+    struct virHostdevIsPCINodeDeviceUsedData data = {mgr, NULL, NULL, false};
     int ret = -1;
 
     virObjectLock(mgr->activePCIHostdevs);