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(a)linux.vnet.ibm.com>
---
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);