From fc6cde6cb1eae11e33002a41778f2f0348dfa9f3 Mon Sep 17 00:00:00 2001 From: Andrea Bolognani Date: Thu, 7 Oct 2021 19:53:45 +0200 Subject: [PATCH] qemu: Validate address type for virtio-iommu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit virtio-iommu is a PCI device and attempts to use a different address type should be rejected. Signed-off-by: Andrea Bolognani Reviewed-by: Ján Tomko --- src/qemu/qemu_validate.c | 7 +++++++ ...mmu-invalid-address-type.x86_64-latest.err | 1 + .../virtio-iommu-invalid-address-type.xml | 20 +++++++++++++++++++ tests/qemuxml2argvtest.c | 1 + 4 files changed, 29 insertions(+) create mode 100644 tests/qemuxml2argvdata/virtio-iommu-invalid-address-type.x86_64-latest.err create mode 100644 tests/qemuxml2argvdata/virtio-iommu-invalid-address-type.xml diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 1e6900bfd0..0ffe02be5b 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -4888,6 +4888,13 @@ qemuValidateDomainDeviceDefIOMMU(const virDomainIOMMUDef *iommu, virDomainIOMMUModelTypeToString(iommu->model)); return -1; } + if (iommu->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE && + iommu->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("IOMMU device: '%s' needs a PCI address"), + virDomainIOMMUModelTypeToString(iommu->model)); + return -1; + } break; case VIR_DOMAIN_IOMMU_MODEL_LAST: diff --git a/tests/qemuxml2argvdata/virtio-iommu-invalid-address-type.x86_64-latest.err b/tests/qemuxml2argvdata/virtio-iommu-invalid-address-type.x86_64-latest.err new file mode 100644 index 0000000000..216848eaf8 --- /dev/null +++ b/tests/qemuxml2argvdata/virtio-iommu-invalid-address-type.x86_64-latest.err @@ -0,0 +1 @@ +unsupported configuration: IOMMU device: 'virtio' needs a PCI address diff --git a/tests/qemuxml2argvdata/virtio-iommu-invalid-address-type.xml b/tests/qemuxml2argvdata/virtio-iommu-invalid-address-type.xml new file mode 100644 index 0000000000..8c227c38a4 --- /dev/null +++ b/tests/qemuxml2argvdata/virtio-iommu-invalid-address-type.xml @@ -0,0 +1,20 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 1 + + hvm + + + + + + /usr/bin/qemu-system-x86_64 + + + +
+ + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 88863d94f3..f6ce8e0200 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -3252,6 +3252,7 @@ mymain(void) DO_TEST_CAPS_ARCH_LATEST("virtio-iommu-aarch64", "aarch64"); DO_TEST_CAPS_LATEST_PARSE_ERROR("virtio-iommu-wrong-machine"); DO_TEST_CAPS_LATEST_PARSE_ERROR("virtio-iommu-no-acpi"); + DO_TEST_CAPS_LATEST_PARSE_ERROR("virtio-iommu-invalid-address-type"); DO_TEST("cpu-hotplug-startup", QEMU_CAPS_QUERY_HOTPLUGGABLE_CPUS); DO_TEST_PARSE_ERROR("cpu-hotplug-granularity",