[PATCH v2 6/7] qemu_validate: Check whether granule of virtio-iommu is supported

Michal Privoznik via Devel posted 7 patches 6 days, 20 hours ago
[PATCH v2 6/7] qemu_validate: Check whether granule of virtio-iommu is supported
Posted by Michal Privoznik via Devel 6 days, 20 hours ago
From: Michal Privoznik <mprivozn@redhat.com>

Just like with other features, check whether QEMU supports them
based on capabilities. Now, instead of inventing a new QEMU
capability, an existing one can be used:
QEMU_CAPS_VIRTIO_IOMMU_AW_BITS.

This is because the aw-bits and granule attributes were
introduced into QEMU in close succession (v9.0.0-rc0~9^2~7
v9.0.0-rc0~9^2~11), neither can be disabled at compile time and
backporting just one without the other makes almost no sense.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_validate.c | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 8f85334cf9..6b44d8d785 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -5685,15 +5685,27 @@ qemuValidateDomainDeviceDefIOMMU(const virDomainIOMMUDef *iommu,
         return -1;
     }
 
-    /* QEMU supports only 4KiB, 8KiB, 16KiB and 64KiB granule size */
-    if (iommu->granule > 0 &&
-        !(iommu->granule == 4 ||
-          iommu->granule == 8 ||
-          iommu->granule == 16 ||
-          iommu->granule == 64)) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("iommu: unsupported granule size. Supported values are 4, 8, 16 and 64 KiB"));
-        return -1;
+    if (iommu->granule > 0) {
+        /* QEMU supports only 4KiB, 8KiB, 16KiB and 64KiB granule size */
+        if (!(iommu->granule == 4 ||
+              iommu->granule == 8 ||
+              iommu->granule == 16 ||
+              iommu->granule == 64)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("iommu: unsupported granule size. Supported values are 4, 8, 16 and 64 KiB"));
+            return -1;
+        }
+
+        /* While the QEMU_CAPS_VIRTIO_IOMMU_AW_BITS tracks .aw-bits attribute of
+         * virtio-iommu it is also a good indicator of .granule attribute as both
+         * attributes were introduced in neighboring commits, in the same release,
+         * neither can be disabled at compile time and backporting one without the
+         * other makes no sense. */
+        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_IOMMU_AW_BITS)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("iommu: page granule is not supported with this QEMU binary"));
+            return -1;
+        }
     }
 
     return 0;
-- 
2.52.0