]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Validate machine type used with virtio-iommu
authorAndrea Bolognani <abologna@redhat.com>
Wed, 22 Sep 2021 17:02:17 +0000 (19:02 +0200)
committerAndrea Bolognani <abologna@redhat.com>
Fri, 1 Apr 2022 17:30:59 +0000 (19:30 +0200)
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_validate.c
tests/qemuxml2argvdata/virtio-iommu-wrong-machine.x86_64-latest.err [new file with mode: 0644]
tests/qemuxml2argvdata/virtio-iommu-wrong-machine.xml [new file with mode: 0644]
tests/qemuxml2argvtest.c

index f2548a31ae519ab433dba42240ee291b7adb686f..eb3200712cf5bdc258f548d202a10ab1a0c649d8 100644 (file)
@@ -4866,6 +4866,14 @@ qemuValidateDomainDeviceDefIOMMU(const virDomainIOMMUDef *iommu,
         break;
 
     case VIR_DOMAIN_IOMMU_MODEL_VIRTIO:
+        if (!qemuDomainIsARMVirt(def) &&
+            !qemuDomainIsQ35(def)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("IOMMU device: '%s' is only supported with "
+                             "Q35 and ARM Virt machines"),
+                           virDomainIOMMUModelTypeToString(iommu->model));
+            return -1;
+        }
         break;
 
     case VIR_DOMAIN_IOMMU_MODEL_LAST:
diff --git a/tests/qemuxml2argvdata/virtio-iommu-wrong-machine.x86_64-latest.err b/tests/qemuxml2argvdata/virtio-iommu-wrong-machine.x86_64-latest.err
new file mode 100644 (file)
index 0000000..8d1cd19
--- /dev/null
@@ -0,0 +1 @@
+unsupported configuration: IOMMU device: 'virtio' is only supported with Q35 and ARM Virt machines
diff --git a/tests/qemuxml2argvdata/virtio-iommu-wrong-machine.xml b/tests/qemuxml2argvdata/virtio-iommu-wrong-machine.xml
new file mode 100644 (file)
index 0000000..ad2a516
--- /dev/null
@@ -0,0 +1,18 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219100</memory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+  </os>
+  <features>
+    <acpi/>
+  </features>
+  <devices>
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
+    <controller type='usb' model='none'/>
+    <memballoon model='none'/>
+    <iommu model='virtio'/>
+  </devices>
+</domain>
index 7c2191f5807e2d146a77d596cedd1e1a1e0e4e43..f4c5c5bb3129db3ba949dd2b8f3a675130b2021c 100644 (file)
@@ -3249,6 +3249,7 @@ mymain(void)
     DO_TEST_CAPS_ARCH_LATEST("iommu-smmuv3", "aarch64");
     DO_TEST_CAPS_LATEST("virtio-iommu-x86_64");
     DO_TEST_CAPS_ARCH_LATEST("virtio-iommu-aarch64", "aarch64");
+    DO_TEST_CAPS_LATEST_PARSE_ERROR("virtio-iommu-wrong-machine");
 
     DO_TEST("cpu-hotplug-startup", QEMU_CAPS_QUERY_HOTPLUGGABLE_CPUS);
     DO_TEST_PARSE_ERROR("cpu-hotplug-granularity",