From: Nathan Chen <nathanc@nvidia.com> Introduce support for an "identifier" IOMMU attribute that allows the CMDQV DSDT device to be correctly associated with its SMMU. Signed-off-by: Nathan Chen <nathanc@nvidia.com> --- docs/formatdomain.rst | 7 +++++++ src/conf/domain_conf.c | 17 +++++++++++++++++ src/conf/domain_conf.h | 1 + src/conf/domain_validate.c | 5 ++++- src/conf/schemas/domaincommon.rng | 5 +++++ src/qemu/qemu_command.c | 1 + 6 files changed, 35 insertions(+), 1 deletion(-) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 74431838ff..c5eb4ac886 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -9347,6 +9347,13 @@ Examples: passthrough of physical SMMU-CMDQ linked command queue from host space to VM. :since:`Since 12.1.0` (QEMU/KVM and ``smmuv3`` model only) + ``identifier`` + The ``identifier`` attribute can be used to provide a stable per-device + identifier independent of enumeration order. This attribute is required for + supporting NVIDIA Tegra241 CMDQV, and is used to correctly associate the + CMDQV DSDT device with its SMMU. + :since:`Since 12.1.0` (QEMU/KVM and ``smmuv3`` model only) + In case of ``virtio`` IOMMU device, the ``driver`` element can optionally contain ``granule`` subelement that allows to choose which granule will be used by default. It is useful when running guests with different page size diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6385420c10..0c11a3e2bc 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2852,6 +2852,8 @@ virDomainIOMMUDefNew(void) iommu->pci_bus = -1; + iommu->identifier = -1; + return g_steal_pointer(&iommu); } @@ -14684,6 +14686,10 @@ virDomainIOMMUDefParseXML(virDomainXMLOption *xmlopt, &iommu->cmdqv) < 0) return NULL; + if (virXMLPropInt(driver, "identifier", 10, VIR_XML_PROP_NONE, + &iommu->identifier, -1) < 0) + return NULL; + if ((granule = virXPathNode("./driver/granule", ctxt))) { g_autofree char *mode = virXMLPropString(granule, "mode"); unsigned long long size; @@ -16786,6 +16792,7 @@ virDomainIOMMUDefEquals(const virDomainIOMMUDef *a, a->aw_bits != b->aw_bits || a->dma_translation != b->dma_translation || a->cmdqv != b->cmdqv || + a->identifier != b->identifier || a->granule != b->granule) return false; @@ -22548,6 +22555,12 @@ virDomainIOMMUDefCheckABIStability(virDomainIOMMUDef *src, dst->cmdqv, src->cmdqv); return false; } + if (src->identifier != dst->identifier) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target domain IOMMU device identifier '%1$d' does not match source '%2$d'"), + dst->identifier, + src->identifier); + } if (src->dma_translation != dst->dma_translation) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Target domain IOMMU device dma translation '%1$s' does not match source '%2$s'"), @@ -28956,6 +28969,10 @@ virDomainIOMMUDefFormat(virBuffer *buf, virBufferAsprintf(&driverAttrBuf, " cmdqv='%s'", virTristateSwitchTypeToString(iommu->cmdqv)); } + if (iommu->identifier >= 0) { + virBufferAsprintf(&driverAttrBuf, " identifier='%d'", + iommu->identifier); + } if (iommu->granule != 0) { if (iommu->granule == -1) { virBufferAddLit(&driverChildBuf, "<granule mode='host'/>\n"); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 41dba29a4f..2cf414d307 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3076,6 +3076,7 @@ struct _virDomainIOMMUDef { virTristateSwitch pt; int granule; /* -1 means 'host', 0 unset, page size in KiB otherwise */ virTristateSwitch cmdqv; + int identifier; }; typedef enum { diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index cac5dabf06..9cd8efae52 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -3209,7 +3209,8 @@ virDomainIOMMUDefValidate(const virDomainIOMMUDef *iommu) iommu->iotlb != VIR_TRISTATE_SWITCH_ABSENT || iommu->dma_translation != VIR_TRISTATE_SWITCH_ABSENT || iommu->pci_bus >= 0 || - iommu->cmdqv != VIR_TRISTATE_SWITCH_ABSENT) { + iommu->cmdqv != VIR_TRISTATE_SWITCH_ABSENT || + iommu->identifier >= 0) { virReportError(VIR_ERR_XML_ERROR, _("iommu model '%1$s' doesn't support some additional attributes"), virDomainIOMMUModelTypeToString(iommu->model)); @@ -3233,6 +3234,7 @@ virDomainIOMMUDefValidate(const virDomainIOMMUDef *iommu) iommu->dma_translation != VIR_TRISTATE_SWITCH_ABSENT || iommu->pci_bus >= 0 || iommu->cmdqv != VIR_TRISTATE_SWITCH_ABSENT || + iommu->identifier >= 0 || iommu->granule != 0) { virReportError(VIR_ERR_XML_ERROR, _("iommu model '%1$s' doesn't support some additional attributes"), @@ -3246,6 +3248,7 @@ virDomainIOMMUDefValidate(const virDomainIOMMUDef *iommu) iommu->xtsup != VIR_TRISTATE_SWITCH_ABSENT || iommu->pci_bus >= 0 || iommu->cmdqv != VIR_TRISTATE_SWITCH_ABSENT || + iommu->identifier >= 0 || iommu->granule != 0) { virReportError(VIR_ERR_XML_ERROR, _("iommu model '%1$s' doesn't support some additional attributes"), diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincommon.rng index 2677207ae4..ab142502e7 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -6357,6 +6357,11 @@ <ref name="virOnOff"/> </attribute> </optional> + <optional> + <attribute name="identifier"> + <data type="unsignedInt"/> + </attribute> + </optional> <optional> <element name="granule"> <choice> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 3735387ebd..37bb876b66 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6331,6 +6331,7 @@ qemuBuildPCINestedSmmuv3DevProps(const virDomainDef *def, "s:primary-bus", bus, "s:id", iommu->info.alias, "B:tegra241-cmdqv", (iommu->cmdqv == VIR_TRISTATE_SWITCH_ON), + "k:identifier", iommu->identifier, NULL) < 0) return NULL; -- 2.43.0