Introduce support for "smmuv3Dev" IOMMU model and
"parentIdx" and "accel" IOMMU device attributes. The
former indicates the index of the controller that a
smmuv3Dev IOMMU device is attached to, while the
latter indicates whether hardware accelerated SMMUv3
support is to be enabled.
Signed-off-by: Nathan Chen <nathanc(a)nvidia.com>
---
docs/formatdomain.rst | 13 +++++-
src/conf/domain_conf.c | 35 +++++++++++++++
src/conf/domain_conf.h | 3 ++
src/conf/domain_validate.c | 26 +++++++++--
src/conf/schemas/domaincommon.rng | 11 +++++
src/qemu/qemu_command.c | 73 +++++++++++++++++++++++++++++--
src/qemu/qemu_domain_address.c | 2 +
src/qemu/qemu_validate.c | 16 +++++++
8 files changed, 170 insertions(+), 9 deletions(-)
diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst
index 976746e292..2558df18ef 100644
--- a/docs/formatdomain.rst
+++ b/docs/formatdomain.rst
@@ -9090,8 +9090,17 @@ Example:
``model``
Supported values are ``intel`` (for Q35 guests) ``smmuv3``
(:since:`since 5.5.0`, for ARM virt guests), ``virtio``
- (:since:`since 8.3.0`, for Q35 and ARM virt guests) and
- ``amd`` (:since:`since 11.5.0`).
+ (:since:`since 8.3.0`, for Q35 and ARM virt guests),
+ ``amd`` (:since:`since 11.5.0`), and ``smmuv3Dev`` (for
+ ARM virt guests).
+
+``parentIdx``
+ The ``parentIdx`` attribute notes the index of the controller that a
+ smmuv3Dev IOMMU device is attached to.
+
+``accel``
+ The ``accel`` attribute with possible values ``on`` and ``off`` can be used
+ to enable hardware acceleration support for smmuv3Dev IOMMU devices.
``driver``
The ``driver`` subelement can be used to configure additional options, some
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 59958c2f08..dc222887d4 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1353,6 +1353,7 @@ VIR_ENUM_IMPL(virDomainIOMMUModel,
"smmuv3",
"virtio",
"amd",
+ "smmuv3Dev",
);
VIR_ENUM_IMPL(virDomainVsockModel,
@@ -2813,6 +2814,8 @@ virDomainIOMMUDefNew(void)
iommu = g_new0(virDomainIOMMUDef, 1);
+ iommu->parent_idx = -1;
+
return g_steal_pointer(&iommu);
}
@@ -14362,6 +14365,14 @@ virDomainIOMMUDefParseXML(virDomainXMLOption *xmlopt,
VIR_XML_PROP_REQUIRED, &iommu->model) < 0)
return NULL;
+ if (virXMLPropInt(node, "parentIdx", 10, VIR_XML_PROP_NONE,
+ &iommu->parent_idx, -1) < 0)
+ return NULL;
+
+ if (virXMLPropTristateSwitch(node, "accel", VIR_XML_PROP_NONE,
+ &iommu->accel) < 0)
+ return NULL;
+
if ((driver = virXPathNode("./driver", ctxt))) {
if (virXMLPropTristateSwitch(driver, "intremap", VIR_XML_PROP_NONE,
&iommu->intremap) < 0)
@@ -22021,6 +22032,18 @@ virDomainIOMMUDefCheckABIStability(virDomainIOMMUDef *src,
dst->aw_bits, src->aw_bits);
return false;
}
+ if (src->parent_idx != dst->parent_idx) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Target domain IOMMU device parent_idx value '%1$d'
does not match source '%2$d'"),
+ dst->parent_idx, src->parent_idx);
+ return false;
+ }
+ if (src->accel != dst->accel) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Target domain IOMMU device accel value '%1$d' does
not match source '%2$d'"),
+ dst->accel, src->accel);
+ return false;
+ }
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'"),
@@ -28342,6 +28365,18 @@ virDomainIOMMUDefFormat(virBuffer *buf,
virBufferAsprintf(&attrBuf, " model='%s'",
virDomainIOMMUModelTypeToString(iommu->model));
+ if (iommu->parent_idx >= 0 && iommu->model ==
VIR_DOMAIN_IOMMU_MODEL_SMMUV3_DEV) {
+ virBufferAsprintf(&attrBuf, " parentIdx='%d'",
+ iommu->parent_idx);
+ }
+
+ if (iommu->model == VIR_DOMAIN_IOMMU_MODEL_SMMUV3_DEV) {
+ if (iommu->accel != VIR_TRISTATE_SWITCH_ABSENT) {
+ virBufferAsprintf(&attrBuf, " accel='%s'",
+ virTristateSwitchTypeToString(iommu->accel));
+ }
+ }
+
virXMLFormatElement(buf, "iommu", &attrBuf, &childBuf);
}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 596d138973..f87c5bbe93 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3036,6 +3036,7 @@ typedef enum {
VIR_DOMAIN_IOMMU_MODEL_SMMUV3,
VIR_DOMAIN_IOMMU_MODEL_VIRTIO,
VIR_DOMAIN_IOMMU_MODEL_AMD,
+ VIR_DOMAIN_IOMMU_MODEL_SMMUV3_DEV,
VIR_DOMAIN_IOMMU_MODEL_LAST
} virDomainIOMMUModel;
@@ -3047,10 +3048,12 @@ struct _virDomainIOMMUDef {
virTristateSwitch eim;
virTristateSwitch iotlb;
unsigned int aw_bits;
+ int parent_idx;
virDomainDeviceInfo info;
virTristateSwitch dma_translation;
virTristateSwitch xtsup;
virTristateSwitch pt;
+ virTristateSwitch accel;
};
typedef enum {
diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
index 40edecef83..f1b1b8cc55 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -3085,7 +3085,8 @@ virDomainIOMMUDefValidate(const virDomainIOMMUDef *iommu)
iommu->eim != VIR_TRISTATE_SWITCH_ABSENT ||
iommu->iotlb != VIR_TRISTATE_SWITCH_ABSENT ||
iommu->aw_bits != 0 ||
- iommu->dma_translation != VIR_TRISTATE_SWITCH_ABSENT) {
+ iommu->dma_translation != VIR_TRISTATE_SWITCH_ABSENT ||
+ iommu->accel != VIR_TRISTATE_SWITCH_ABSENT) {
virReportError(VIR_ERR_XML_ERROR,
_("iommu model '%1$s' doesn't support
additional attributes"),
virDomainIOMMUModelTypeToString(iommu->model));
@@ -3097,7 +3098,8 @@ virDomainIOMMUDefValidate(const virDomainIOMMUDef *iommu)
if (iommu->caching_mode != VIR_TRISTATE_SWITCH_ABSENT ||
iommu->eim != VIR_TRISTATE_SWITCH_ABSENT ||
iommu->aw_bits != 0 ||
- iommu->dma_translation != VIR_TRISTATE_SWITCH_ABSENT) {
+ iommu->dma_translation != VIR_TRISTATE_SWITCH_ABSENT ||
+ iommu->accel != VIR_TRISTATE_SWITCH_ABSENT) {
virReportError(VIR_ERR_XML_ERROR,
_("iommu model '%1$s' doesn't support some
additional attributes"),
virDomainIOMMUModelTypeToString(iommu->model));
@@ -3107,7 +3109,24 @@ virDomainIOMMUDefValidate(const virDomainIOMMUDef *iommu)
case VIR_DOMAIN_IOMMU_MODEL_INTEL:
if (iommu->pt != VIR_TRISTATE_SWITCH_ABSENT ||
- iommu->xtsup != VIR_TRISTATE_SWITCH_ABSENT) {
+ iommu->xtsup != VIR_TRISTATE_SWITCH_ABSENT ||
+ iommu->accel != 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_SMMUV3_DEV:
+ if (iommu->intremap != VIR_TRISTATE_SWITCH_ABSENT ||
+ iommu->caching_mode != VIR_TRISTATE_SWITCH_ABSENT ||
+ iommu->eim != VIR_TRISTATE_SWITCH_ABSENT ||
+ iommu->iotlb != VIR_TRISTATE_SWITCH_ABSENT ||
+ iommu->aw_bits != 0 ||
+ iommu->dma_translation != VIR_TRISTATE_SWITCH_ABSENT ||
+ iommu->xtsup != VIR_TRISTATE_SWITCH_ABSENT ||
+ iommu->pt != VIR_TRISTATE_SWITCH_ABSENT) {
virReportError(VIR_ERR_XML_ERROR,
_("iommu model '%1$s' doesn't support some
additional attributes"),
virDomainIOMMUModelTypeToString(iommu->model));
@@ -3132,6 +3151,7 @@ virDomainIOMMUDefValidate(const virDomainIOMMUDef *iommu)
case VIR_DOMAIN_IOMMU_MODEL_VIRTIO:
case VIR_DOMAIN_IOMMU_MODEL_AMD:
+ case VIR_DOMAIN_IOMMU_MODEL_SMMUV3_DEV:
case VIR_DOMAIN_IOMMU_MODEL_LAST:
break;
}
diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincommon.rng
index a714c3fcc5..0e57d2a9b9 100644
--- a/src/conf/schemas/domaincommon.rng
+++ b/src/conf/schemas/domaincommon.rng
@@ -6246,8 +6246,19 @@
<value>smmuv3</value>
<value>virtio</value>
<value>amd</value>
+ <value>smmuv3Dev</value>
</choice>
</attribute>
+ <optional>
+ <attribute name="parentIdx">
+ <data type="unsignedInt"/>
+ </attribute>
+ </optional>
+ <optional>
+ <attribute name="accel">
+ <ref name="virOnOff"/>
+ </attribute>
+ </optional>
<interleave>
<optional>
<element name="driver">
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 457dee7029..8a124a495b 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -6250,6 +6250,63 @@ qemuBuildBootCommandLine(virCommand *cmd,
}
+static virJSONValue *
+qemuBuildPCISmmuv3DevDevProps(const virDomainDef *def,
+ const virDomainIOMMUDef *iommu)
+{
+ g_autoptr(virJSONValue) props = NULL;
+ g_autofree char *bus = NULL;
+ size_t i;
+ bool contIsPHB = false;
+
+ for (i = 0; i < def->ncontrollers; i++) {
+ virDomainControllerDef *cont = def->controllers[i];
+ if (cont->idx == iommu->parent_idx) {
+ if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI) {
+ const char *alias = cont->info.alias;
+ contIsPHB = virDomainControllerIsPSeriesPHB(cont);
+
+ if (!alias)
+ return NULL;
+
+ if (virDomainDeviceAliasIsUserAlias(alias)) {
+ if (cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT
&&
+ iommu->parent_idx <= 0) {
+ if (qemuDomainSupportsPCIMultibus(def))
+ bus = g_strdup("pci.0");
+ else
+ bus = g_strdup("pci");
+ } else if (cont->model == VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT)
{
+ bus = g_strdup("pcie.0");
+ }
+ } else {
+ bus = g_strdup(alias);
+ }
+ break;
+ }
+ }
+ }
+
+ if (!bus)
+ return NULL;
+
+ if (contIsPHB && iommu->parent_idx > 0) {
+ char *temp_bus = g_strdup_printf("%s.0", bus);
+ g_free(bus);
+ bus = temp_bus;
+ }
+
+ if (virJSONValueObjectAdd(&props,
+ "s:driver", "arm-smmuv3",
+ "s:primary-bus", bus,
+ "b:accel", (iommu->accel ==
VIR_TRISTATE_SWITCH_ON),
+ NULL) < 0)
+ return NULL;
+
+ return g_steal_pointer(&props);
+}
+
+
static int
qemuBuildIOMMUCommandLine(virCommand *cmd,
const virDomainDef *def,
@@ -6298,7 +6355,6 @@ qemuBuildIOMMUCommandLine(virCommand *cmd,
return 0;
case VIR_DOMAIN_IOMMU_MODEL_SMMUV3:
- /* There is no -device for SMMUv3, so nothing to be done here */
return 0;
case VIR_DOMAIN_IOMMU_MODEL_AMD:
@@ -6329,6 +6385,14 @@ qemuBuildIOMMUCommandLine(virCommand *cmd,
return 0;
+ case VIR_DOMAIN_IOMMU_MODEL_SMMUV3_DEV:
+ if (!(props = qemuBuildPCISmmuv3DevDevProps(def, iommu)))
+ return -1;
+ if (qemuBuildDeviceCommandlineFromJSON(cmd, props, def, qemuCaps) < 0)
+ return -1;
+
+ return 0;
+
case VIR_DOMAIN_IOMMU_MODEL_LAST:
default:
virReportEnumRangeError(virDomainIOMMUModel, iommu->model);
@@ -7162,6 +7226,7 @@ qemuBuildMachineCommandLine(virCommand *cmd,
case VIR_DOMAIN_IOMMU_MODEL_INTEL:
case VIR_DOMAIN_IOMMU_MODEL_VIRTIO:
case VIR_DOMAIN_IOMMU_MODEL_AMD:
+ case VIR_DOMAIN_IOMMU_MODEL_SMMUV3_DEV:
/* These IOMMUs are formatted in qemuBuildIOMMUCommandLine */
break;
@@ -10807,15 +10872,15 @@ qemuBuildCommandLine(virDomainObj *vm,
if (qemuBuildBootCommandLine(cmd, def) < 0)
return NULL;
- if (qemuBuildIOMMUCommandLine(cmd, def, qemuCaps) < 0)
- return NULL;
-
if (qemuBuildGlobalControllerCommandLine(cmd, def) < 0)
return NULL;
if (qemuBuildControllersCommandLine(cmd, def, qemuCaps) < 0)
return NULL;
+ if (qemuBuildIOMMUCommandLine(cmd, def, qemuCaps) < 0)
+ return NULL;
+
if (qemuBuildMemoryDeviceCommandLine(cmd, cfg, def, priv) < 0)
return NULL;
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 96a9ca9b14..06bf4fab32 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -952,6 +952,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDef *dev,
case VIR_DOMAIN_IOMMU_MODEL_INTEL:
case VIR_DOMAIN_IOMMU_MODEL_SMMUV3:
+ case VIR_DOMAIN_IOMMU_MODEL_SMMUV3_DEV:
case VIR_DOMAIN_IOMMU_MODEL_LAST:
/* These are not PCI devices */
return 0;
@@ -2378,6 +2379,7 @@ qemuDomainAssignDevicePCISlots(virDomainDef *def,
case VIR_DOMAIN_IOMMU_MODEL_INTEL:
case VIR_DOMAIN_IOMMU_MODEL_SMMUV3:
+ case VIR_DOMAIN_IOMMU_MODEL_SMMUV3_DEV:
case VIR_DOMAIN_IOMMU_MODEL_LAST:
/* These are not PCI devices */
break;
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index adba3e4a89..163d7758b8 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -5406,6 +5406,22 @@ qemuValidateDomainDeviceDefIOMMU(const virDomainIOMMUDef *iommu,
}
break;
+ case VIR_DOMAIN_IOMMU_MODEL_SMMUV3_DEV:
+ if (!qemuDomainIsARMVirt(def)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("IOMMU device: '%1$s' is only supported with
ARM Virt machines"),
+ virDomainIOMMUModelTypeToString(iommu->model));
+ return -1;
+ }
+ // TODO: Check for pluggable device SMMUv3 qemu capability
+ if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_MACHINE_VIRT_IOMMU)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("IOMMU device: '%1$s' is not supported with
this QEMU binary"),
+ virDomainIOMMUModelTypeToString(iommu->model));
+ return -1;
+ }
+ break;
+
case VIR_DOMAIN_IOMMU_MODEL_LAST:
default:
virReportEnumRangeError(virDomainIOMMUModel, iommu->model);
--
2.43.0