]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Move capability checks for IOMMU features
authorAndrea Bolognani <abologna@redhat.com>
Tue, 28 May 2019 14:00:57 +0000 (16:00 +0200)
committerAndrea Bolognani <abologna@redhat.com>
Mon, 3 Jun 2019 15:40:54 +0000 (17:40 +0200)
All current IOMMU features are specific to Intel IOMMU, so
understandably we check for the corresponding capabilities
inside the Intel-specific switch() branch; however, we want
to make sure SMMUv3 IOMMU users get an error if they try to
enable any of those features in their guest, and performing
the capability checks unconditionally is both the easiest
way to achieve that, as well as the one least likely to
result in us inadvertently letting users enable some new
Intel-specific IOMMU feature for ARM guests later on.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_domain.c

index 3290cdae5fa617fdda0e51d0c134539fd7ea821b..4d3a8868b235f38cc21bda191fe9f80b94792d49 100644 (file)
@@ -6105,34 +6105,6 @@ qemuDomainDeviceDefValidateIOMMU(const virDomainIOMMUDef *iommu,
                            virDomainIOMMUModelTypeToString(iommu->model));
             return -1;
         }
-        if (iommu->intremap != VIR_TRISTATE_SWITCH_ABSENT &&
-            !virQEMUCapsGet(qemuCaps, QEMU_CAPS_INTEL_IOMMU_INTREMAP)) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("iommu: interrupt remapping is not supported "
-                             "with this QEMU binary"));
-            return -1;
-        }
-        if (iommu->caching_mode != VIR_TRISTATE_SWITCH_ABSENT &&
-            !virQEMUCapsGet(qemuCaps, QEMU_CAPS_INTEL_IOMMU_CACHING_MODE))  {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("iommu: caching mode is not supported "
-                             "with this QEMU binary"));
-            return -1;
-        }
-        if (iommu->eim != VIR_TRISTATE_SWITCH_ABSENT &&
-            !virQEMUCapsGet(qemuCaps, QEMU_CAPS_INTEL_IOMMU_EIM))  {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("iommu: eim is not supported "
-                             "with this QEMU binary"));
-            return -1;
-        }
-        if (iommu->iotlb != VIR_TRISTATE_SWITCH_ABSENT &&
-            !virQEMUCapsGet(qemuCaps, QEMU_CAPS_INTEL_IOMMU_DEVICE_IOTLB)) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("iommu: device IOTLB is not supported "
-                             "with this QEMU binary"));
-            return -1;
-        }
         break;
 
     case VIR_DOMAIN_IOMMU_MODEL_SMMUV3:
@@ -6158,6 +6130,40 @@ qemuDomainDeviceDefValidateIOMMU(const virDomainIOMMUDef *iommu,
         return -1;
     }
 
+    /* These capability checks ensure we're not trying to use features
+     * of Intel IOMMU that the QEMU binary does not support, but they
+     * also make sure we report an error when trying to use features
+     * that are not implemented by SMMUv3 */
+
+    if (iommu->intremap != VIR_TRISTATE_SWITCH_ABSENT &&
+        !virQEMUCapsGet(qemuCaps, QEMU_CAPS_INTEL_IOMMU_INTREMAP)) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("iommu: interrupt remapping is not supported "
+                         "with this QEMU binary"));
+        return -1;
+    }
+    if (iommu->caching_mode != VIR_TRISTATE_SWITCH_ABSENT &&
+        !virQEMUCapsGet(qemuCaps, QEMU_CAPS_INTEL_IOMMU_CACHING_MODE))  {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("iommu: caching mode is not supported "
+                         "with this QEMU binary"));
+        return -1;
+    }
+    if (iommu->eim != VIR_TRISTATE_SWITCH_ABSENT &&
+        !virQEMUCapsGet(qemuCaps, QEMU_CAPS_INTEL_IOMMU_EIM))  {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("iommu: eim is not supported "
+                         "with this QEMU binary"));
+        return -1;
+    }
+    if (iommu->iotlb != VIR_TRISTATE_SWITCH_ABSENT &&
+        !virQEMUCapsGet(qemuCaps, QEMU_CAPS_INTEL_IOMMU_DEVICE_IOTLB)) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("iommu: device IOTLB is not supported "
+                         "with this QEMU binary"));
+        return -1;
+    }
+
     return 0;
 }