If the config for a device has specified <driver name='vfio'/>,
"backend" in the pci part of the hostdev object will be set to
..._VFIO. In this case, when creating a virPCIDevice set the
stubDriver to "vfio-pci", otherwise set it to "pci-stub". We will
rely
on the lower levels to report an error if the vfio driver isn't
loaded.
The detach/attach functions in virpci.c will pay attention to the
stubDriver setting in the device, and bind/unbind the appropriate
driver when preparing hostdevs for the domain.
Note that we don't yet attempt to do anything to mark active any other
devices in the same vfio "group" as a single device that is being
marked active. We do need to do that, but in order to get basic VFIO
functionality testing sooner rather than later, initially we'll just
live with more cryptic errors when someone tries to do that.
---
src/qemu/qemu_hostdev.c | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index 308fdcd..036e922 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -67,6 +67,12 @@ qemuGetPciHostDeviceList(virDomainHostdevDefPtr *hostdevs, int
nhostdevs)
}
virPCIDeviceSetManaged(dev, hostdev->managed);
+ if (hostdev->source.subsys.u.pci.backend
+ == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_TYPE_VFIO) {
+ virPCIDeviceSetStubDriver(dev, "vfio-pci");
+ } else {
+ virPCIDeviceSetStubDriver(dev, "pci-stub");
+ }
}
return list;
@@ -150,6 +156,12 @@ int qemuUpdateActivePciHostdevs(virQEMUDriverPtr driver,
goto cleanup;
virPCIDeviceSetManaged(dev, hostdev->managed);
+ if (hostdev->source.subsys.u.pci.backend
+ == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_TYPE_VFIO) {
+ virPCIDeviceSetStubDriver(dev, "vfio-pci");
+ } else {
+ virPCIDeviceSetStubDriver(dev, "pci-stub");
+ }
virPCIDeviceSetUsedBy(dev, def->name);
/* Setup the original states for the PCI device */
@@ -472,11 +484,11 @@ int qemuPrepareHostdevPCIDevices(virQEMUDriverPtr driver,
}
}
- /* Loop 2: detach managed devices */
+ /* Loop 2: detach managed devices (i.e. bind to appropriate stub driver) */
for (i = 0; i < virPCIDeviceListCount(pcidevs); i++) {
virPCIDevicePtr dev = virPCIDeviceListGet(pcidevs, i);
if (virPCIDeviceGetManaged(dev) &&
- virPCIDeviceDetach(dev, driver->activePciHostdevs, NULL,
"pci-stub") < 0)
+ virPCIDeviceDetach(dev, driver->activePciHostdevs, NULL, NULL) < 0)
goto reattachdevs;
}
@@ -593,7 +605,11 @@ resetvfnetconfig:
reattachdevs:
for (i = 0; i < virPCIDeviceListCount(pcidevs); i++) {
virPCIDevicePtr dev = virPCIDeviceListGet(pcidevs, i);
- virPCIDeviceReattach(dev, driver->activePciHostdevs, NULL,
"pci-stub");
+
+ /* NB: This doesn't actually re-bind to original driver, just
+ * unbinds from the stub driver
+ */
+ virPCIDeviceReattach(dev, driver->activePciHostdevs, NULL, NULL);
}
cleanup:
--
1.7.11.7