]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: Allow aw_bits for virtio-iommu
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 21 Jan 2026 09:46:43 +0000 (10:46 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 6 Feb 2026 15:13:34 +0000 (16:13 +0100)
Introduced in QEMU commit of v9.0.0-rc0~9^2~7 the virtio-iommu
device is also capable of using different addres width. The
corresponding attribute is also called 'aw-bits', just like in
case of intel-iommu. Wire up the missing pieces.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
docs/formatdomain.rst
src/conf/domain_validate.c
src/qemu/qemu_validate.c
tests/qemuxmlconfdata/virtio-iommu-aarch64.aarch64-latest.xml
tests/qemuxmlconfdata/virtio-iommu-aarch64.xml
tests/qemuxmlconfdata/virtio-iommu-dma-translation.x86_64-latest.err

index 0fa9d2e08b3b24483922533a56e867d0c30ccc05..7dd99e040f9d35f4316bd38f7831c7985831a66f 100644 (file)
@@ -9253,7 +9253,7 @@ Example:
    ``aw_bits``
       The ``aw_bits`` attribute can be used to set the address width to allow
       mapping larger iova addresses in the guest. :since:`Since 6.5.0` (QEMU/KVM
-      and ``intel`` model only)
+      and ``intel`` or ``virtio`` models only)
 
    ``dma_translation``
       The ``dma_translation`` attribute with possible values ``on`` and ``off`` can
index 44822030874c4911cd80aca6de3ed51116583b75..c83fff132b81f46da55f1c4989f58b627811d3de 100644 (file)
@@ -3206,14 +3206,22 @@ virDomainIOMMUDefValidate(const virDomainIOMMUDef *iommu)
             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->pci_bus >= 0) {
             virReportError(VIR_ERR_XML_ERROR,
-                           _("iommu model '%1$s' doesn't support additional attributes"),
+                           _("iommu model '%1$s' doesn't support some additional attributes"),
                            virDomainIOMMUModelTypeToString(iommu->model));
             return -1;
         }
+
+        /* QEMU mandates address width of the IOVA address space to be inside
+         * [32,64] range, but since it stems from virtio specification it can
+         * be assumed to be hypervisor agnostic and thus can live here. */
+        if (iommu->aw_bits != 0 && (iommu->aw_bits < 32 || iommu->aw_bits > 64)) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("aw-bits must be within [32,64]"));
+            return -1;
+        }
         break;
 
     case VIR_DOMAIN_IOMMU_MODEL_AMD:
index 5474d00ecd18ba77c1c532e5ca747f8235c2bef7..d0572bcbb2cca63f0c51247bb255eda8418a3a67 100644 (file)
@@ -5552,6 +5552,8 @@ qemuValidateDomainDeviceDefIOMMU(const virDomainIOMMUDef *iommu,
                                  const virDomainDef *def,
                                  virQEMUCaps *qemuCaps)
 {
+    bool aw_bits_supported = false;
+
     switch (iommu->model) {
     case VIR_DOMAIN_IOMMU_MODEL_INTEL:
         if (!qemuDomainIsQ35(def)) {
@@ -5566,6 +5568,7 @@ qemuValidateDomainDeviceDefIOMMU(const virDomainIOMMUDef *iommu,
                            virDomainIOMMUModelTypeToString(iommu->model));
             return -1;
         }
+        aw_bits_supported = virQEMUCapsGet(qemuCaps, QEMU_CAPS_INTEL_IOMMU_AW_BITS);
         break;
 
     case VIR_DOMAIN_IOMMU_MODEL_SMMUV3:
@@ -5611,6 +5614,7 @@ qemuValidateDomainDeviceDefIOMMU(const virDomainIOMMUDef *iommu,
                            virDomainIOMMUModelTypeToString(iommu->model));
             return -1;
         }
+        aw_bits_supported = virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_IOMMU_AW_BITS);
         break;
 
     case VIR_DOMAIN_IOMMU_MODEL_AMD:
@@ -5670,8 +5674,7 @@ qemuValidateDomainDeviceDefIOMMU(const virDomainIOMMUDef *iommu,
                        _("iommu: device IOTLB is not supported with this QEMU binary"));
         return -1;
     }
-    if (iommu->aw_bits > 0 &&
-        !virQEMUCapsGet(qemuCaps, QEMU_CAPS_INTEL_IOMMU_AW_BITS)) {
+    if (iommu->aw_bits > 0 && !aw_bits_supported) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("iommu: aw_bits is not supported with this QEMU binary"));
         return -1;
index 3cb794cbc9f9e0ccea7ff58e6406a9b5a6d507a1..4ae628ab5a0a7cd6a7369f1963fef53c6e007fd6 100644 (file)
@@ -29,6 +29,7 @@
     <audio id='1' type='none'/>
     <memballoon model='none'/>
     <iommu model='virtio'>
+      <driver aw_bits='48'/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
     </iommu>
   </devices>
index 8d252bfcf92927dc574c6f2611abb007b280a415..96e5ea05ae4a988c3d950cab5bdbd8355880e6da 100644 (file)
@@ -13,6 +13,8 @@
     <emulator>/usr/bin/qemu-system-aarch64</emulator>
     <controller type='usb' model='none'/>
     <memballoon model='none'/>
-    <iommu model='virtio'/>
+    <iommu model='virtio'>
+      <driver aw_bits='48'/>
+    </iommu>
   </devices>
 </domain>
index 2c3a27272540e6b3f6c1892989fadf7c61bae222..f4405a9b7d9d16677f5ccc1baaacf83352ba3b2b 100644 (file)
@@ -1 +1 @@
-XML error: iommu model 'virtio' doesn't support additional attributes
+XML error: iommu model 'virtio' doesn't support some additional attributes