qemu: Drop KVM assignment

KVM style of PCI devices assignment was dropped in kernel in
favor of vfio pci (see kernel commit v4.12-rc1~68^2~65). Since
vfio is around for quite some time now and is far superior
discourage people in using KVM style.

Ideally, I'd make QEMU_CAPS_VFIO_PCI implicitly assumed but turns
out qemu-3.0.0 doesn't support vfio-pci device for RISC-V.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
Michal Privoznik 2019-05-03 15:25:07 +02:00
parent 985f035fbf
commit 80b58a7c1a
8 changed files with 14 additions and 113 deletions

View File

@ -5338,7 +5338,6 @@ static int
virQEMUCapsFillDomainDeviceHostdevCaps(virQEMUCapsPtr qemuCaps, virQEMUCapsFillDomainDeviceHostdevCaps(virQEMUCapsPtr qemuCaps,
virDomainCapsDeviceHostdevPtr hostdev) virDomainCapsDeviceHostdevPtr hostdev)
{ {
bool supportsPassthroughKVM = qemuHostdevHostSupportsPassthroughLegacy();
bool supportsPassthroughVFIO = qemuHostdevHostSupportsPassthroughVFIO(); bool supportsPassthroughVFIO = qemuHostdevHostSupportsPassthroughVFIO();
hostdev->supported = VIR_TRISTATE_BOOL_YES; hostdev->supported = VIR_TRISTATE_BOOL_YES;
@ -5374,11 +5373,6 @@ virQEMUCapsFillDomainDeviceHostdevCaps(virQEMUCapsPtr qemuCaps,
VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO); VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO);
} }
if (supportsPassthroughKVM) {
VIR_DOMAIN_CAPS_ENUM_SET(hostdev->pciBackend,
VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT,
VIR_DOMAIN_HOSTDEV_PCI_BACKEND_KVM);
}
return 0; return 0;
} }

View File

@ -4904,7 +4904,6 @@ char *
qemuBuildPCIHostdevDevStr(const virDomainDef *def, qemuBuildPCIHostdevDevStr(const virDomainDef *def,
virDomainHostdevDefPtr dev, virDomainHostdevDefPtr dev,
unsigned int bootIndex, /* used iff dev->info->bootIndex == 0 */ unsigned int bootIndex, /* used iff dev->info->bootIndex == 0 */
const char *configfd,
virQEMUCapsPtr qemuCaps) virQEMUCapsPtr qemuCaps)
{ {
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
@ -4913,16 +4912,11 @@ qemuBuildPCIHostdevDevStr(const virDomainDef *def,
/* caller has to assign proper passthrough backend type */ /* caller has to assign proper passthrough backend type */
switch ((virDomainHostdevSubsysPCIBackendType)backend) { switch ((virDomainHostdevSubsysPCIBackendType)backend) {
case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_KVM:
virBufferAddLit(&buf, "pci-assign");
if (configfd && *configfd)
virBufferAsprintf(&buf, ",configfd=%s", configfd);
break;
case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO: case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO:
virBufferAddLit(&buf, "vfio-pci"); virBufferAddLit(&buf, "vfio-pci");
break; break;
case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_KVM:
case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT: case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT:
case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN: case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN:
case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_TYPE_LAST: case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_TYPE_LAST:
@ -5676,7 +5670,6 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
} }
} }
char *configfd_name = NULL;
unsigned int bootIndex = hostdev->info->bootIndex; unsigned int bootIndex = hostdev->info->bootIndex;
/* bootNet will be non-0 if boot order was set and no other /* bootNet will be non-0 if boot order was set and no other
@ -5686,27 +5679,12 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
bootIndex = *bootHostdevNet; bootIndex = *bootHostdevNet;
*bootHostdevNet = 0; *bootHostdevNet = 0;
} }
if (backend != VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
int configfd = qemuOpenPCIConfig(hostdev);
if (configfd >= 0) {
if (virAsprintf(&configfd_name, "%d", configfd) < 0) {
VIR_FORCE_CLOSE(configfd);
return -1;
}
virCommandPassFD(cmd, configfd,
VIR_COMMAND_PASS_FD_CLOSE_PARENT);
}
}
if (qemuCommandAddExtDevice(cmd, hostdev->info) < 0) if (qemuCommandAddExtDevice(cmd, hostdev->info) < 0)
return -1; return -1;
virCommandAddArg(cmd, "-device"); virCommandAddArg(cmd, "-device");
devstr = qemuBuildPCIHostdevDevStr(def, hostdev, bootIndex, devstr = qemuBuildPCIHostdevDevStr(def, hostdev, bootIndex, qemuCaps);
configfd_name, qemuCaps);
VIR_FREE(configfd_name);
if (!devstr) if (!devstr)
return -1; return -1;
virCommandAddArg(cmd, devstr); virCommandAddArg(cmd, devstr);

View File

@ -148,7 +148,6 @@ char *qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem,
char *qemuBuildPCIHostdevDevStr(const virDomainDef *def, char *qemuBuildPCIHostdevDevStr(const virDomainDef *def,
virDomainHostdevDefPtr dev, virDomainHostdevDefPtr dev,
unsigned int bootIndex, unsigned int bootIndex,
const char *configfd,
virQEMUCapsPtr qemuCaps); virQEMUCapsPtr qemuCaps);
char *qemuBuildRNGDevStr(const virDomainDef *def, char *qemuBuildRNGDevStr(const virDomainDef *def,

View File

@ -13517,7 +13517,6 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
int ret = -1; int ret = -1;
virNodeDeviceDefPtr def = NULL; virNodeDeviceDefPtr def = NULL;
char *xml = NULL; char *xml = NULL;
bool legacy = qemuHostdevHostSupportsPassthroughLegacy();
bool vfio = qemuHostdevHostSupportsPassthroughVFIO(); bool vfio = qemuHostdevHostSupportsPassthroughVFIO();
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr; virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
@ -13541,18 +13540,8 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
if (!pci) if (!pci)
goto cleanup; goto cleanup;
if (!driverName) { if (!driverName)
if (vfio) { driverName = "vfio";
driverName = "vfio";
} else if (legacy) {
driverName = "kvm";
} else {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("neither VFIO nor KVM device assignment is "
"currently supported on this system"));
goto cleanup;
}
}
if (STREQ(driverName, "vfio")) { if (STREQ(driverName, "vfio")) {
if (!vfio) { if (!vfio) {
@ -13563,13 +13552,10 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
} }
virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_VFIO); virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_VFIO);
} else if (STREQ(driverName, "kvm")) { } else if (STREQ(driverName, "kvm")) {
if (!legacy) { virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", _("KVM device assignment is no longer "
_("KVM device assignment is currently not " "supported on this system"));
"supported on this system")); goto cleanup;
goto cleanup;
}
virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_KVM);
} else { } else {
virReportError(VIR_ERR_INVALID_ARG, virReportError(VIR_ERR_INVALID_ARG,
_("unknown driver name '%s'"), driverName); _("unknown driver name '%s'"), driverName);

View File

@ -133,44 +133,11 @@ qemuHostdevHostSupportsPassthroughVFIO(void)
} }
#if HAVE_LINUX_KVM_H
# include <linux/kvm.h>
bool
qemuHostdevHostSupportsPassthroughLegacy(void)
{
int kvmfd = -1;
bool ret = false;
if ((kvmfd = open("/dev/kvm", O_RDONLY)) < 0)
goto cleanup;
# ifdef KVM_CAP_IOMMU
if ((ioctl(kvmfd, KVM_CHECK_EXTENSION, KVM_CAP_IOMMU)) <= 0)
goto cleanup;
ret = true;
# endif
cleanup:
VIR_FORCE_CLOSE(kvmfd);
return ret;
}
#else
bool
qemuHostdevHostSupportsPassthroughLegacy(void)
{
return false;
}
#endif
static bool static bool
qemuHostdevPreparePCIDevicesCheckSupport(virDomainHostdevDefPtr *hostdevs, qemuHostdevPreparePCIDevicesCheckSupport(virDomainHostdevDefPtr *hostdevs,
size_t nhostdevs, size_t nhostdevs,
virQEMUCapsPtr qemuCaps) virQEMUCapsPtr qemuCaps)
{ {
bool supportsPassthroughKVM = qemuHostdevHostSupportsPassthroughLegacy();
bool supportsPassthroughVFIO = qemuHostdevHostSupportsPassthroughVFIO(); bool supportsPassthroughVFIO = qemuHostdevHostSupportsPassthroughVFIO();
size_t i; size_t i;
@ -189,8 +156,6 @@ qemuHostdevPreparePCIDevicesCheckSupport(virDomainHostdevDefPtr *hostdevs,
if (supportsPassthroughVFIO && if (supportsPassthroughVFIO &&
virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) { virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
*backend = VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO; *backend = VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO;
} else if (supportsPassthroughKVM) {
*backend = VIR_DOMAIN_HOSTDEV_PCI_BACKEND_KVM;
} else { } else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("host doesn't support passthrough of " _("host doesn't support passthrough of "
@ -209,12 +174,9 @@ qemuHostdevPreparePCIDevicesCheckSupport(virDomainHostdevDefPtr *hostdevs,
break; break;
case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_KVM: case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_KVM:
if (!supportsPassthroughKVM) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("host doesn't support legacy PCI passthrough"));
_("host doesn't support legacy PCI passthrough")); return false;
return false;
}
break; break;
case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN: case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN:

View File

@ -24,7 +24,6 @@
#include "qemu_conf.h" #include "qemu_conf.h"
#include "domain_conf.h" #include "domain_conf.h"
bool qemuHostdevHostSupportsPassthroughLegacy(void);
bool qemuHostdevHostSupportsPassthroughVFIO(void); bool qemuHostdevHostSupportsPassthroughVFIO(void);
int qemuHostdevUpdateActiveMediatedDevices(virQEMUDriverPtr driver, int qemuHostdevUpdateActiveMediatedDevices(virQEMUDriverPtr driver,

View File

@ -1465,8 +1465,6 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
virDomainDeviceInfoPtr info = hostdev->info; virDomainDeviceInfoPtr info = hostdev->info;
int ret; int ret;
char *devstr = NULL; char *devstr = NULL;
int configfd = -1;
char *configfd_name = NULL;
bool releaseaddr = false; bool releaseaddr = false;
bool teardowncgroup = false; bool teardowncgroup = false;
bool teardownlabel = false; bool teardownlabel = false;
@ -1547,13 +1545,6 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
if (qemuDomainEnsurePCIAddress(vm, &dev, driver) < 0) if (qemuDomainEnsurePCIAddress(vm, &dev, driver) < 0)
goto error; goto error;
releaseaddr = true; releaseaddr = true;
if (backend != VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
configfd = qemuOpenPCIConfig(hostdev);
if (configfd >= 0) {
if (virAsprintf(&configfd_name, "fd-%s", info->alias) < 0)
goto error;
}
}
if (!virDomainObjIsActive(vm)) { if (!virDomainObjIsActive(vm)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@ -1561,8 +1552,7 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
goto error; goto error;
} }
if (!(devstr = qemuBuildPCIHostdevDevStr(vm->def, hostdev, 0, if (!(devstr = qemuBuildPCIHostdevDevStr(vm->def, hostdev, 0, priv->qemuCaps)))
configfd_name, priv->qemuCaps)))
goto error; goto error;
qemuDomainObjEnterMonitor(driver, vm); qemuDomainObjEnterMonitor(driver, vm);
@ -1570,10 +1560,8 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
if ((ret = qemuDomainAttachExtensionDevice(priv->mon, hostdev->info)) < 0) if ((ret = qemuDomainAttachExtensionDevice(priv->mon, hostdev->info)) < 0)
goto exit_monitor; goto exit_monitor;
if ((ret = qemuMonitorAddDeviceWithFd(priv->mon, devstr, if ((ret = qemuMonitorAddDevice(priv->mon, devstr)) < 0)
configfd, configfd_name)) < 0) {
ignore_value(qemuDomainDetachExtensionDevice(priv->mon, hostdev->info)); ignore_value(qemuDomainDetachExtensionDevice(priv->mon, hostdev->info));
}
exit_monitor: exit_monitor:
if (qemuDomainObjExitMonitor(driver, vm) < 0) if (qemuDomainObjExitMonitor(driver, vm) < 0)
@ -1586,8 +1574,6 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
vm->def->hostdevs[vm->def->nhostdevs++] = hostdev; vm->def->hostdevs[vm->def->nhostdevs++] = hostdev;
VIR_FREE(devstr); VIR_FREE(devstr);
VIR_FREE(configfd_name);
VIR_FORCE_CLOSE(configfd);
return 0; return 0;
@ -1607,8 +1593,6 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
qemuHostdevReAttachPCIDevices(driver, vm->def->name, &hostdev, 1); qemuHostdevReAttachPCIDevices(driver, vm->def->name, &hostdev, 1);
VIR_FREE(devstr); VIR_FREE(devstr);
VIR_FREE(configfd_name);
VIR_FORCE_CLOSE(configfd);
cleanup: cleanup:
return -1; return -1;

View File

@ -111,8 +111,7 @@ fillQemuCaps(virDomainCapsPtr domCaps,
cfg->nfirmwares) < 0) cfg->nfirmwares) < 0)
goto cleanup; goto cleanup;
/* The function above tries to query host's KVM & VFIO capabilities by /* The function above tries to query host's VFIO capabilities by calling
* calling qemuHostdevHostSupportsPassthroughLegacy() and
* qemuHostdevHostSupportsPassthroughVFIO() which, however, can't be * qemuHostdevHostSupportsPassthroughVFIO() which, however, can't be
* successfully mocked as they are not exposed as internal APIs. Therefore, * successfully mocked as they are not exposed as internal APIs. Therefore,
* instead of mocking set the expected values here by hand. */ * instead of mocking set the expected values here by hand. */