]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: add passthrough and xtsup attributes for IOMMU
authorJán Tomko <jtomko@redhat.com>
Fri, 14 Mar 2025 16:13:31 +0000 (17:13 +0100)
committerJán Tomko <jtomko@redhat.com>
Tue, 24 Jun 2025 10:14:04 +0000 (12:14 +0200)
For the newly supported AMD device.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
docs/formatdomain.rst
src/conf/domain_conf.c
src/conf/domain_conf.h
src/conf/domain_validate.c
src/conf/schemas/domaincommon.rng
src/qemu/qemu_command.c
tests/qemuxmlconfdata/amd-iommu.x86_64-latest.args
tests/qemuxmlconfdata/amd-iommu.xml

index 7ebb4c3e9e08c52edceaee52b383754fd49d6a33..4c7ec17d45007f6a8b61723d14273015caa5b082 100644 (file)
@@ -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``).
 
index 12882291a6e7e017afb10155dd2ad6bdee24e682..2469144a66bacf350a5253bf266ff04bdab25f69 100644 (file)
@@ -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);
 
index 051037eff994ddde01b644a698fdc02cfa2c33d8..667b3ff10a5cf33d5df115b17ad1830d8076de31 100644 (file)
@@ -3025,6 +3025,8 @@ struct _virDomainIOMMUDef {
     unsigned int aw_bits;
     virDomainDeviceInfo info;
     virTristateSwitch dma_translation;
+    virTristateSwitch xtsup;
+    virTristateSwitch pt;
 };
 
 typedef enum {
index b9a6740437ecf9f912900eafb76d979b4301a00f..b28af7fa5618c2066129e27320114f9740490382 100644 (file)
@@ -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;
     }
index 92b9ba3cc720cd8b738ca2f74c49d1bddffe8506..1ff441e1845c434cc84fb071cc87323e76cf5b65 100644 (file)
                 <ref name="virOnOff"/>
               </attribute>
             </optional>
+            <optional>
+              <attribute name="xtsup">
+                <ref name="virOnOff"/>
+              </attribute>
+            </optional>
+            <optional>
+              <attribute name="passthrough">
+                <ref name="virOnOff"/>
+              </attribute>
+            </optional>
           </element>
         </optional>
         <optional>
index 6fae9b1f5aaa720c50fb847ad434c0df3e8d75d1..b752a828bab070ca035001432e0149926444acfd 100644 (file)
@@ -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;
index 36244edb3ae7f160cf6372dbb1e05422e8499599..20d7e379e60d8f7f01952c247c04ddc45a5451dd 100644 (file)
@@ -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 \
index 0668ed4237d540aa06a381bb0d366b1ef513078d..4ad79ce4ae3e0f5d15c5c22622ecc0f6d7d4eaa5 100644 (file)
@@ -32,7 +32,7 @@
     <watchdog model='itco' action='reset'/>
     <memballoon model='none'/>
     <iommu model='amd'>
-      <driver intremap='on' iotlb='on'/>
+      <driver intremap='on' iotlb='on' passthrough='on' xtsup='on'/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
     </iommu>
   </devices>