On 14.11.2015 09:36, Shivaprasad G Bhat wrote:
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 | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index de029a0..f24ccd8 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -1590,18 +1590,35 @@ virHostdevPCINodeDeviceReAttach(virHostdevManagerPtr
hostdev_mgr,
virPCIDevicePtr pci)
{
virPCIDeviceAddressPtr devAddr = NULL;
+ bool usesVfio = false;
+ char *drvPath = NULL;
+ char *drvName = NULL;
struct virHostdevIsPCINodeDeviceUsedData data = {hostdev_mgr, NULL,
false};
int ret = -1;
+ if (virPCIDeviceGetDriverPathAndName(pci, &drvPath, &drvName) < 0)
+ goto out;
+
+ if (STREQ_NULLABLE(drvName, "vfio-pci"))
+ usesVfio = true;
+
virObjectLock(hostdev_mgr->activePCIHostdevs);
virObjectLock(hostdev_mgr->inactivePCIHostdevs);
if (!(devAddr = virPCIDeviceGetAddress(pci)))
goto out;
- if (virHostdevIsPCINodeDeviceUsed(devAddr, &data))
+ if (usesVfio) {
+ /* Doesn't matter which device. If any domain is actively using the
+ * iommu group, refuse to reattach */
s/reattach/reattach./
And, does not matter right now, but maybe we will need to set
data.usesVfio = true; in this case. Currently, this will result in no-op
+ if (virPCIDeviceAddressIOMMUGroupIterate(devAddr,
+ virHostdevIsPCINodeDeviceUsed,
+ &data) < 0)
+ goto out;
+ } else if (virHostdevIsPCINodeDeviceUsed(devAddr, &data)) {
goto out;
+ }
virPCIDeviceReattachInit(pci);
@@ -1614,6 +1631,8 @@ virHostdevPCINodeDeviceReAttach(virHostdevManagerPtr hostdev_mgr,
virObjectUnlock(hostdev_mgr->inactivePCIHostdevs);
virObjectUnlock(hostdev_mgr->activePCIHostdevs);
VIR_FREE(devAddr);
+ VIR_FREE(drvPath);
+ VIR_FREE(drvName);
return ret;
}
And as you and Laine agreed, this is going to be turned into a list, so
this patch probably ends up being dropped anyway.
Michal