From 856f667c8a3b44417f3b5bb42db5e8bf971bacd4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A1n=20Tomko?= Date: Fri, 14 Mar 2025 17:13:31 +0100 Subject: [PATCH] conf: add passthrough and xtsup attributes for IOMMU MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit For the newly supported AMD device. Signed-off-by: Ján Tomko Reviewed-by: Peter Krempa --- docs/formatdomain.rst | 8 +++++ src/conf/domain_conf.c | 30 +++++++++++++++++++ src/conf/domain_conf.h | 2 ++ src/conf/domain_validate.c | 9 ++++++ src/conf/schemas/domaincommon.rng | 10 +++++++ src/qemu/qemu_command.c | 2 ++ .../amd-iommu.x86_64-latest.args | 2 +- tests/qemuxmlconfdata/amd-iommu.xml | 2 +- 8 files changed, 63 insertions(+), 2 deletions(-) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 7ebb4c3e9e..4c7ec17d45 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -9104,6 +9104,14 @@ Example: example to efficiently enable more than 255 vCPUs. :since:`Since 10.7.0` (QEMU/KVM and ``intel`` model only) + ``passthrough`` + Enable passthrough. In this mode, DMA read/writes are not translated. + :since:`Since 11.5.0` (QEMU/KVM and ``amd`` model only) + + ``xtsup`` + Enable x2APIC mode. Useful for higher number of guest CPUs. + :since:`Since 11.5.0` (QEMU/KVM and ``amd`` model only) + The ``virtio`` IOMMU devices can further have ``address`` element as described in `Device addresses`_ (address has to by type of ``pci``). diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 12882291a6..2469144a66 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -14360,6 +14360,14 @@ virDomainIOMMUDefParseXML(virDomainXMLOption *xmlopt, if (virXMLPropTristateSwitch(driver, "dma_translation", VIR_XML_PROP_NONE, &iommu->dma_translation) < 0) return NULL; + + if (virXMLPropTristateSwitch(driver, "xtsup", VIR_XML_PROP_NONE, + &iommu->xtsup) < 0) + return NULL; + + if (virXMLPropTristateSwitch(driver, "passthrough", VIR_XML_PROP_NONE, + &iommu->pt) < 0) + return NULL; } if (virDomainDeviceInfoParseXML(xmlopt, node, ctxt, @@ -21994,6 +22002,20 @@ virDomainIOMMUDefCheckABIStability(virDomainIOMMUDef *src, virTristateSwitchTypeToString(src->dma_translation)); return false; } + if (src->pt != dst->pt) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target domain IOMMU device dma translation '%1$s' does not match source '%2$s'"), + virTristateSwitchTypeToString(dst->pt), + virTristateSwitchTypeToString(src->pt)); + return false; + } + if (src->xtsup != dst->xtsup) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target domain IOMMU device dma translation '%1$s' does not match source '%2$s'"), + virTristateSwitchTypeToString(dst->xtsup), + virTristateSwitchTypeToString(src->xtsup)); + return false; + } return virDomainDeviceInfoCheckABIStability(&src->info, &dst->info); } @@ -28261,6 +28283,14 @@ virDomainIOMMUDefFormat(virBuffer *buf, virBufferAsprintf(&driverAttrBuf, " dma_translation='%s'", virTristateSwitchTypeToString(iommu->dma_translation)); } + if (iommu->pt != VIR_TRISTATE_SWITCH_ABSENT) { + virBufferAsprintf(&driverAttrBuf, " passthrough='%s'", + virTristateSwitchTypeToString(iommu->pt)); + } + if (iommu->xtsup != VIR_TRISTATE_SWITCH_ABSENT) { + virBufferAsprintf(&driverAttrBuf, " xtsup='%s'", + virTristateSwitchTypeToString(iommu->xtsup)); + } virXMLFormatElement(&childBuf, "driver", &driverAttrBuf, NULL); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 051037eff9..667b3ff10a 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3025,6 +3025,8 @@ struct _virDomainIOMMUDef { unsigned int aw_bits; virDomainDeviceInfo info; virTristateSwitch dma_translation; + virTristateSwitch xtsup; + virTristateSwitch pt; }; typedef enum { diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index b9a6740437..b28af7fa56 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -3095,6 +3095,15 @@ virDomainIOMMUDefValidate(const virDomainIOMMUDef *iommu) break; case VIR_DOMAIN_IOMMU_MODEL_INTEL: + if (iommu->pt != VIR_TRISTATE_SWITCH_ABSENT || + iommu->xtsup != VIR_TRISTATE_SWITCH_ABSENT) { + virReportError(VIR_ERR_XML_ERROR, + _("iommu model '%1$s' doesn't support some additional attributes"), + virDomainIOMMUModelTypeToString(iommu->model)); + return -1; + } + break; + case VIR_DOMAIN_IOMMU_MODEL_LAST: break; } diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincommon.rng index 92b9ba3cc7..1ff441e184 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -6237,6 +6237,16 @@ + + + + + + + + + + diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 6fae9b1f5a..b752a828ba 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6227,6 +6227,8 @@ qemuBuildIOMMUCommandLine(virCommand *cmd, "s:driver", "amd-iommu", "s:pci-id", iommu->info.alias, "S:intremap", qemuOnOffAuto(iommu->intremap), + "T:pt", iommu->pt, + "T:xtsup", iommu->xtsup, "T:device-iotlb", iommu->iotlb, NULL) < 0) return -1; diff --git a/tests/qemuxmlconfdata/amd-iommu.x86_64-latest.args b/tests/qemuxmlconfdata/amd-iommu.x86_64-latest.args index 36244edb3a..20d7e379e6 100644 --- a/tests/qemuxmlconfdata/amd-iommu.x86_64-latest.args +++ b/tests/qemuxmlconfdata/amd-iommu.x86_64-latest.args @@ -27,7 +27,7 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \ -no-shutdown \ -boot strict=on \ -device '{"driver":"AMDVI-PCI","id":"iommu0","bus":"pcie.0","addr":"0x1"}' \ --device '{"driver":"amd-iommu","pci-id":"iommu0","intremap":"on","device-iotlb":true}' \ +-device '{"driver":"amd-iommu","pci-id":"iommu0","intremap":"on","pt":true,"xtsup":true,"device-iotlb":true}' \ -audiodev '{"id":"audio1","driver":"none"}' \ -global ICH9-LPC.noreboot=off \ -watchdog-action reset \ diff --git a/tests/qemuxmlconfdata/amd-iommu.xml b/tests/qemuxmlconfdata/amd-iommu.xml index 0668ed4237..4ad79ce4ae 100644 --- a/tests/qemuxmlconfdata/amd-iommu.xml +++ b/tests/qemuxmlconfdata/amd-iommu.xml @@ -32,7 +32,7 @@ - +
-- 2.47.3