This is needed so that IOMMU devices can have addresses. Existing IOMMU devices (intel-iommu and SMMUv3) are system devices and as such don't have an address associated to them, but virtio-iommu is a PCI device and needs one. Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx> --- docs/schemas/domaincommon.rng | 63 +++++++++++++++++++---------------- src/conf/domain_conf.c | 37 +++++++++++++------- src/conf/domain_conf.h | 1 + 3 files changed, 60 insertions(+), 41 deletions(-) diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 2f30b15c48..6dffe3afae 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -5418,35 +5418,40 @@ <value>virtio</value> </choice> </attribute> - <optional> - <element name="driver"> - <optional> - <attribute name="intremap"> - <ref name="virOnOff"/> - </attribute> - </optional> - <optional> - <attribute name="caching_mode"> - <ref name="virOnOff"/> - </attribute> - </optional> - <optional> - <attribute name="eim"> - <ref name="virOnOff"/> - </attribute> - </optional> - <optional> - <attribute name="iotlb"> - <ref name="virOnOff"/> - </attribute> - </optional> - <optional> - <attribute name="aw_bits"> - <ref name="uint8"/> - </attribute> - </optional> - </element> - </optional> + <interleave> + <optional> + <element name="driver"> + <optional> + <attribute name="intremap"> + <ref name="virOnOff"/> + </attribute> + </optional> + <optional> + <attribute name="caching_mode"> + <ref name="virOnOff"/> + </attribute> + </optional> + <optional> + <attribute name="eim"> + <ref name="virOnOff"/> + </attribute> + </optional> + <optional> + <attribute name="iotlb"> + <ref name="virOnOff"/> + </attribute> + </optional> + <optional> + <attribute name="aw_bits"> + <ref name="uint8"/> + </attribute> + </optional> + </element> + </optional> + <optional> + <ref name="address"/> + </optional> + </interleave> </element> </define> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a2d155069f..3b23c32a96 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2542,6 +2542,7 @@ virDomainIOMMUDefFree(virDomainIOMMUDef *iommu) if (!iommu) return; + virDomainDeviceInfoClear(&iommu->info); g_free(iommu); } @@ -4230,13 +4231,14 @@ virDomainDeviceGetInfo(virDomainDeviceDef *device) return &device->data.panic->info; case VIR_DOMAIN_DEVICE_MEMORY: return &device->data.memory->info; + case VIR_DOMAIN_DEVICE_IOMMU: + return &device->data.iommu->info; case VIR_DOMAIN_DEVICE_VSOCK: return &device->data.vsock->info; /* The following devices do not contain virDomainDeviceInfo */ case VIR_DOMAIN_DEVICE_LEASE: case VIR_DOMAIN_DEVICE_GRAPHICS: - case VIR_DOMAIN_DEVICE_IOMMU: case VIR_DOMAIN_DEVICE_AUDIO: case VIR_DOMAIN_DEVICE_LAST: case VIR_DOMAIN_DEVICE_NONE: @@ -4532,6 +4534,13 @@ virDomainDeviceInfoIterateFlags(virDomainDef *def, return rc; } + device.type = VIR_DOMAIN_DEVICE_IOMMU; + if (def->iommu) { + device.data.iommu = def->iommu; + if ((rc = cb(def, &device, &def->iommu->info, opaque)) != 0) + return rc; + } + device.type = VIR_DOMAIN_DEVICE_VSOCK; if (def->vsock) { device.data.vsock = def->vsock; @@ -4559,12 +4568,6 @@ virDomainDeviceInfoIterateFlags(virDomainDef *def, if ((rc = cb(def, &device, NULL, opaque)) != 0) return rc; } - device.type = VIR_DOMAIN_DEVICE_IOMMU; - if (def->iommu) { - device.data.iommu = def->iommu; - if ((rc = cb(def, &device, NULL, opaque)) != 0) - return rc; - } } /* Coverity is not very happy with this - all dead_error_condition */ @@ -14933,8 +14936,10 @@ virDomainMemoryDefParseXML(virDomainXMLOption *xmlopt, static virDomainIOMMUDef * -virDomainIOMMUDefParseXML(xmlNodePtr node, - xmlXPathContextPtr ctxt) +virDomainIOMMUDefParseXML(virDomainXMLOption *xmlopt, + xmlNodePtr node, + xmlXPathContextPtr ctxt, + unsigned int flags) { VIR_XPATH_NODE_AUTORESTORE(ctxt) xmlNodePtr driver; @@ -14970,6 +14975,10 @@ virDomainIOMMUDefParseXML(xmlNodePtr node, return NULL; } + if (virDomainDeviceInfoParseXML(xmlopt, node, ctxt, + &iommu->info, flags) < 0) + return NULL; + return g_steal_pointer(&iommu); } @@ -15167,7 +15176,8 @@ virDomainDeviceDefParse(const char *xmlStr, return NULL; break; case VIR_DOMAIN_DEVICE_IOMMU: - if (!(dev->data.iommu = virDomainIOMMUDefParseXML(node, ctxt))) + if (!(dev->data.iommu = virDomainIOMMUDefParseXML(xmlopt, node, + ctxt, flags))) return NULL; break; case VIR_DOMAIN_DEVICE_VSOCK: @@ -20285,7 +20295,8 @@ virDomainDefParseXML(xmlXPathContextPtr ctxt, } if (n > 0) { - if (!(def->iommu = virDomainIOMMUDefParseXML(nodes[0], ctxt))) + if (!(def->iommu = virDomainIOMMUDefParseXML(xmlopt, nodes[0], + ctxt, flags))) return NULL; } VIR_FREE(nodes); @@ -22107,7 +22118,7 @@ virDomainIOMMUDefCheckABIStability(virDomainIOMMUDef *src, return false; } - return true; + return virDomainDeviceInfoCheckABIStability(&src->info, &dst->info); } @@ -27494,6 +27505,8 @@ virDomainIOMMUDefFormat(virBuffer *buf, virXMLFormatElement(&childBuf, "driver", &driverAttrBuf, NULL); + virDomainDeviceInfoFormat(&childBuf, &iommu->info, 0); + virBufferAsprintf(&attrBuf, " model='%s'", virDomainIOMMUModelTypeToString(iommu->model)); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 21e069f42e..1961a686e6 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2708,6 +2708,7 @@ struct _virDomainIOMMUDef { virTristateSwitch eim; virTristateSwitch iotlb; unsigned int aw_bits; + virDomainDeviceInfo info; }; typedef enum { -- 2.31.1