[PATCH v3 4/9] Refuse to reattach from vfio if the iommu group is in use by any domain

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It is incorrect to attempt the device reattach of a function,
when some other domain is using some functions belonging to the same iommu
group.

Signed-off-by: Shivaprasad G Bhat <sbhat@xxxxxxxxxxxxxxxxxx>
---
 src/util/virhostdev.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index de029a0..4c441b9 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -1590,6 +1590,7 @@ virHostdevPCINodeDeviceReAttach(virHostdevManagerPtr hostdev_mgr,
                                 virPCIDevicePtr pci)
 {
     virPCIDeviceAddressPtr devAddr = NULL;
+    bool usesVfio = STREQ_NULLABLE(virPCIDeviceGetStubDriver(pci), "vfio-pci");
     struct virHostdevIsPCINodeDeviceUsedData data = {hostdev_mgr, NULL,
                                                      false};
     int ret = -1;
@@ -1600,8 +1601,16 @@ virHostdevPCINodeDeviceReAttach(virHostdevManagerPtr hostdev_mgr,
     if (!(devAddr = virPCIDeviceGetAddress(pci)))
         goto out;
 
-    if (virHostdevIsPCINodeDeviceUsed(devAddr, &data))
+    if (usesVfio) {
+    /* Doesn't matter which function. If any domain is actively using the
+     * iommu group, refuse to reattach */
+        if (virPCIDeviceAddressIOMMUGroupIterate(devAddr,
+                                                 virHostdevIsPCINodeDeviceUsed,
+                                                 &data) < 0)
+            goto out;
+    } else if (virHostdevIsPCINodeDeviceUsed(devAddr, &data)) {
         goto out;
+    }
 
     virPCIDeviceReattachInit(pci);
 

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]