When intel-iommu device is configured with First-Stage Translation Support ('fsts'), physical PCI device assignment requires the modern iommufd backend in QEMU, because the legacy container-based VFIO backend cannot support first-stage translation. Introduce virDomainDefHasIntelIOMMUWithFSTS() in the domain configuration layer and export it to query whether a domain definition contains an intel-iommu with 'fsts' enabled. In the QEMU driver validator, reject PCI hostdev assignments that do not use the 'iommufd' backend when 'fsts' is active on an intel-iommu device. Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com> --- src/conf/domain_conf.c | 25 +++++++++++++++++++++++++ src/conf/domain_conf.h | 3 +++ src/libvirt_private.syms | 1 + src/qemu/qemu_validate.c | 4 ++++ 4 files changed, 33 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 920bd0b840..9b8048f895 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -33585,3 +33585,28 @@ virDomainDefHasTimer(const virDomainDef *def, return false; } + + +static bool +virIOMMUIsIntelWithFSTS(const virDomainIOMMUDef *iommu) +{ + if (iommu && iommu->model == VIR_DOMAIN_IOMMU_MODEL_INTEL && + iommu->fsts == VIR_TRISTATE_SWITCH_ON) + return true; + + return false; +} + + +bool +virDomainDefHasIntelIOMMUWithFSTS(const virDomainDef *def) +{ + size_t i; + + for (i = 0; i < def->niommus; i++) { + if (virIOMMUIsIntelWithFSTS(def->iommus[i])) + return true; + } + + return false; +} diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index e2076e7c36..d9ec2dc786 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -4841,3 +4841,6 @@ virDomainThrottleFilterFind(const virDomainDiskDef *def, bool virDomainDefHasTimer(const virDomainDef *def, virDomainTimerNameType name); + +bool +virDomainDefHasIntelIOMMUWithFSTS(const virDomainDef *def); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 798d2d28c8..db8bbfbe1b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -341,6 +341,7 @@ virDomainDefGetVcpusMax; virDomainDefGetVcpusTopology; virDomainDefHasDeviceAddress; virDomainDefHasGraphics; +virDomainDefHasIntelIOMMUWithFSTS; virDomainDefHasManagedPR; virDomainDefHasMdevHostdev; virDomainDefHasMemballoon; diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 764d7c819e..fb4d100be3 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -2833,6 +2833,10 @@ qemuValidateDomainDeviceDefHostdev(const virDomainHostdevDef *hostdev, _("IOMMUFD is not supported by host kernel")); return -1; } + } else if (virDomainDefHasIntelIOMMUWithFSTS(def)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("VFIO PCI device assignment without 'iommufd' is not compatible with 'intel' IOMMU with 'fsts'")); + return -1; } } -- 2.52.0