If nodedev-detach with '--driver', it does not check whether host
currentlly supports vfio passthrough. That will cause the detached
node device failed to bind to vfio driver when iommu is off:
"kernel: vfio-pci: probe of 0000:01:00.0 failed with error -22"
https://bugzilla.redhat.com/show_bug.cgi?id=1046919
So it should check passthrough support before set stub driver.
---
src/qemu/qemu_driver.c | 33 ++++++++++++++++++++++++---------
1 file changed, 24 insertions(+), 9 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index ebb77dc..0e0b170 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -10793,6 +10793,8 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
int ret = -1;
virNodeDeviceDefPtr def = NULL;
char *xml = NULL;
+ bool supportsPassthroughKVM = qemuHostdevHostSupportsPassthroughLegacy();
+ bool supportsPassthroughVFIO = qemuHostdevHostSupportsPassthroughVFIO();
virCheckFlags(0, -1);
@@ -10815,22 +10817,35 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
goto cleanup;
if (!driverName) {
- /* prefer vfio */
- if (qemuHostdevHostSupportsPassthroughVFIO())
+ /* decide a driver, prefer vfio */
+ if (supportsPassthroughVFIO)
driverName = "vfio";
- else if (qemuHostdevHostSupportsPassthroughLegacy())
+ else if (supportsPassthroughKVM)
driverName = "kvm";
+ else {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("neither VFIO nor kvm device assignment is "
+ "currently supported on this system"));
+ goto cleanup;
+ }
}
- if (!driverName) {
- virReportError(VIR_ERR_INVALID_ARG, "%s",
- _("neither VFIO nor kvm device assignment is "
- "currently supported on this system"));
- goto cleanup;
- } else if (STREQ(driverName, "vfio")) {
+ if (STREQ(driverName, "vfio")) {
+ if (!supportsPassthroughVFIO) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("VFIO device assignment is currently not "
+ "supported on this system"));
+ goto cleanup;
+ }
if (virPCIDeviceSetStubDriver(pci, "vfio-pci") < 0)
goto cleanup;
} else if (STREQ(driverName, "kvm")) {
+ if (!supportsPassthroughKVM) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("kvm device assignment is currently not "
+ "supported on this system"));
+ goto cleanup;
+ }
if (virPCIDeviceSetStubDriver(pci, "pci-stub") < 0)
goto cleanup;
} else {
--
1.8.3.1