diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index a794e47209..67b549c1f5 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -10737,12 +10737,25 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev, if (!pci) goto cleanup; - if (!driverName || STREQ(driverName, "kvm")) { - if (virPCIDeviceSetStubDriver(pci, "pci-stub") < 0) - goto cleanup; + if (!driverName) { + /* prefer vfio */ + if (qemuHostdevHostSupportsPassthroughVFIO()) + driverName = "vfio"; + else if (qemuHostdevHostSupportsPassthroughLegacy()) + driverName = "kvm"; + } + + 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 (virPCIDeviceSetStubDriver(pci, "vfio-pci") < 0) goto cleanup; + } else if (STREQ(driverName, "kvm")) { + if (virPCIDeviceSetStubDriver(pci, "pci-stub") < 0) + goto cleanup; } else { virReportError(VIR_ERR_INVALID_ARG, _("unknown driver name '%s'"), driverName); diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c index f5cad15cf9..dee61e742d 100644 --- a/src/qemu/qemu_hostdev.c +++ b/src/qemu/qemu_hostdev.c @@ -501,7 +501,7 @@ qemuDomainHostdevNetConfigRestore(virDomainHostdevDefPtr hostdev, } -static bool +bool qemuHostdevHostSupportsPassthroughVFIO(void) { DIR *iommuDir = NULL; @@ -541,7 +541,7 @@ cleanup: #if HAVE_LINUX_KVM_H # include -static bool +bool qemuHostdevHostSupportsPassthroughLegacy(void) { int kvmfd = -1; @@ -563,7 +563,7 @@ cleanup: return ret; } #else -static bool +bool qemuHostdevHostSupportsPassthroughLegacy(void) { return false; diff --git a/src/qemu/qemu_hostdev.h b/src/qemu/qemu_hostdev.h index 272086effa..ffb3167ca1 100644 --- a/src/qemu/qemu_hostdev.h +++ b/src/qemu/qemu_hostdev.h @@ -1,7 +1,7 @@ /* * qemu_hostdev.h: QEMU hostdev management * - * Copyright (C) 2006-2007, 2009-2010 Red Hat, Inc. + * Copyright (C) 2006-2007, 2009-2013 Red Hat, Inc. * Copyright (C) 2006 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -33,6 +33,8 @@ int qemuUpdateActiveUsbHostdevs(virQEMUDriverPtr driver, virDomainDefPtr def); int qemuUpdateActiveScsiHostdevs(virQEMUDriverPtr driver, virDomainDefPtr def); +bool qemuHostdevHostSupportsPassthroughLegacy(void); +bool qemuHostdevHostSupportsPassthroughVFIO(void); int qemuPrepareHostdevPCIDevices(virQEMUDriverPtr driver, const char *name, const unsigned char *uuid,