diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index cc8ec58571..da8f3d1ed1 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -344,6 +344,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
"query-hotpluggable-cpus",
"virtio-net.rx_queue_size", /* 235 */
+ "machine-iommu",
);
@@ -3804,6 +3805,17 @@ virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps,
if (virQEMUCapsProbeQMPMigrationCapabilities(qemuCaps, mon) < 0)
goto cleanup;
+ /* 'intel-iommu' shows up as a device since 2.2.0, but can
+ * not be used with -device until 2.7.0. Before that it
+ * requires -machine iommu=on. So we must clear the device
+ * capability we detected on older QEMUs
+ */
+ if (qemuCaps->version < 2007000 &&
+ virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_INTEL_IOMMU)) {
+ virQEMUCapsClear(qemuCaps, QEMU_CAPS_DEVICE_INTEL_IOMMU);
+ virQEMUCapsSet(qemuCaps, QEMU_CAPS_MACHINE_IOMMU);
+ }
+
/* GIC capabilities, eg. available GIC versions */
if ((qemuCaps->arch == VIR_ARCH_AARCH64 ||
qemuCaps->arch == VIR_ARCH_ARMV7L) &&
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index ba0ef4859d..51c2372b8a 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -378,6 +378,7 @@ typedef enum {
/* 235 */
QEMU_CAPS_VIRTIO_NET_RX_QUEUE_SIZE, /* virtio-net-*.rx_queue_size */
+ QEMU_CAPS_MACHINE_IOMMU, /* -machine iommu=on */
QEMU_CAPS_LAST /* this must always be the last item */
} virQEMUCapsFlags;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 578ff8b23a..080413363b 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -6414,6 +6414,9 @@ qemuBuildIOMMUCommandLine(virCommandPtr cmd,
if (!def->iommu)
return 0;
+ if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_MACHINE_IOMMU))
+ return 0; /* Already handled via -machine */
+
switch (def->iommu->model) {
case VIR_DOMAIN_IOMMU_MODEL_INTEL:
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_INTEL_IOMMU)) {
@@ -7044,6 +7047,25 @@ qemuBuildMachineCommandLine(virCommandPtr cmd,
}
}
+ /* We don't report errors on missing cap here - -device code will do that */
+ if (def->iommu &&
+ virQEMUCapsGet(qemuCaps, QEMU_CAPS_MACHINE_IOMMU)) {
+ switch (def->iommu->model) {
+ case VIR_DOMAIN_IOMMU_MODEL_INTEL:
+ if (!qemuDomainMachineIsQ35(def)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("IOMMU device: '%s' is only supported with "
+ "Q35 machines"),
+ virDomainIOMMUModelTypeToString(def->iommu->model));
+ return -1;
+ }
+ virBufferAddLit(&buf, ",iommu=on");
+ break;
+ case VIR_DOMAIN_IOMMU_MODEL_LAST:
+ break;
+ }
+ }
+
virCommandAddArgBuffer(cmd, &buf);
}
diff --git a/tests/qemucapabilitiesdata/caps_2.4.0.x86_64.xml b/tests/qemucapabilitiesdata/caps_2.4.0.x86_64.xml
index db778ef4c9..abb9c66ad8 100644
--- a/tests/qemucapabilitiesdata/caps_2.4.0.x86_64.xml
+++ b/tests/qemucapabilitiesdata/caps_2.4.0.x86_64.xml
@@ -182,9 +182,9 @@
-
+
2004000
0
diff --git a/tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml b/tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml
index fc915ad254..cbf2e1ebc2 100644
--- a/tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml
+++ b/tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml
@@ -187,9 +187,9 @@
-
+
2005000
0
diff --git a/tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml b/tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml
index 60f1fcfe85..116c5062c5 100644
--- a/tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml
+++ b/tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml
@@ -193,9 +193,9 @@
-
+
2006000
0
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-machine.args b/tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-machine.args
new file mode 100644
index 0000000000..9221b790de
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-machine.args
@@ -0,0 +1,21 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/home/test \
+USER=test \
+LOGNAME=test \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu \
+-name QEMUGuest1 \
+-S \
+-machine q35,accel=tcg,iommu=on \
+-m 214 \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
+-nographic \
+-nodefaults \
+-monitor unix:/tmp/lib/domain--1-QEMUGuest1/monitor.sock,server,nowait \
+-no-acpi \
+-boot c \
+-device i82801b11-bridge,id=pci.1,bus=pcie.0,addr=0x1e \
+-device pci-bridge,chassis_nr=2,id=pci.2,bus=pci.1,addr=0x0 \
+-device virtio-balloon-pci,id=balloon0,bus=pci.2,addr=0x1
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-machine.xml b/tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-machine.xml
new file mode 100644
index 0000000000..b5b2b5158a
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-machine.xml
@@ -0,0 +1,37 @@
+
+ QEMUGuest1
+ c7a5fdbd-edaf-9455-926a-d65c16db1809
+ 219100
+ 219100
+ 1
+
+ hvm
+
+
+
+ destroy
+ restart
+ destroy
+
+ /usr/bin/qemu
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 4b9ecb82f8..903276db37 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -2157,6 +2157,8 @@ mymain(void)
DO_TEST("acpi-table", NONE);
DO_TEST("intel-iommu", QEMU_CAPS_DEVICE_PCI_BRIDGE,
QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE, QEMU_CAPS_DEVICE_INTEL_IOMMU);
+ DO_TEST("intel-iommu-machine", QEMU_CAPS_DEVICE_PCI_BRIDGE, QEMU_CAPS_MACHINE_OPT,
+ QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE, QEMU_CAPS_MACHINE_IOMMU);
DO_TEST("cpu-hotplug-startup", QEMU_CAPS_QUERY_HOTPLUGGABLE_CPUS);