6ae9ed
From 9843ec11c61f08a0f0c9cc23397f28daf87b121a Mon Sep 17 00:00:00 2001
6ae9ed
Message-Id: <9843ec11c61f08a0f0c9cc23397f28daf87b121a@dist-git>
6ae9ed
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
6ae9ed
Date: Mon, 25 Jul 2016 10:24:58 +0200
6ae9ed
Subject: [PATCH] qemu: format intel-iommu on the command line
6ae9ed
MIME-Version: 1.0
6ae9ed
Content-Type: text/plain; charset=UTF-8
6ae9ed
Content-Transfer-Encoding: 8bit
6ae9ed
6ae9ed
<devices>
6ae9ed
  <iommu model='intel'/>
6ae9ed
</devices>
6ae9ed
6ae9ed
results in:
6ae9ed
6ae9ed
-device intel-iommu
6ae9ed
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1235581
6ae9ed
(cherry picked from commit 4c382376da95bf84c9903e62c714ffa33f85d404)
6ae9ed
Signed-off-by: Ján Tomko <jtomko@redhat.com>
6ae9ed
6ae9ed
Conflicts:
6ae9ed
  tests - downstream does not assume QEMU_CAPS_SMP_TOPOLOGY
6ae9ed
---
6ae9ed
 src/qemu/qemu_command.c                            | 35 ++++++++++++++++++++++
6ae9ed
 .../qemuxml2argvdata/qemuxml2argv-intel-iommu.args | 22 ++++++++++++++
6ae9ed
 tests/qemuxml2argvtest.c                           |  2 ++
6ae9ed
 3 files changed, 59 insertions(+)
6ae9ed
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-intel-iommu.args
6ae9ed
6ae9ed
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
6ae9ed
index 300c01c..b87d9c3 100644
6ae9ed
--- a/src/qemu/qemu_command.c
6ae9ed
+++ b/src/qemu/qemu_command.c
6ae9ed
@@ -6172,6 +6172,38 @@ qemuBuildBootCommandLine(virCommandPtr cmd,
6ae9ed
 
6ae9ed
 
6ae9ed
 static int
6ae9ed
+qemuBuildIOMMUCommandLine(virCommandPtr cmd,
6ae9ed
+                          const virDomainDef *def,
6ae9ed
+                          virQEMUCapsPtr qemuCaps)
6ae9ed
+{
6ae9ed
+    if (!def->iommu)
6ae9ed
+        return 0;
6ae9ed
+
6ae9ed
+    switch (def->iommu->model) {
6ae9ed
+    case VIR_DOMAIN_IOMMU_MODEL_INTEL:
6ae9ed
+        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_INTEL_IOMMU)) {
6ae9ed
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
6ae9ed
+                           _("IOMMU device: '%s' is not supported with "
6ae9ed
+                             "this QEMU binary"),
6ae9ed
+                           virDomainIOMMUModelTypeToString(def->iommu->model));
6ae9ed
+            return -1;
6ae9ed
+        }
6ae9ed
+        if (!qemuDomainMachineIsQ35(def)) {
6ae9ed
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
6ae9ed
+                           _("IOMMU device: '%s' is only supported with "
6ae9ed
+                             "Q35 machines"),
6ae9ed
+                           virDomainIOMMUModelTypeToString(def->iommu->model));
6ae9ed
+            return -1;
6ae9ed
+        }
6ae9ed
+        virCommandAddArgList(cmd, "-device", "intel-iommu", NULL);
6ae9ed
+    case VIR_DOMAIN_IOMMU_MODEL_LAST:
6ae9ed
+        break;
6ae9ed
+    }
6ae9ed
+    return 0;
6ae9ed
+}
6ae9ed
+
6ae9ed
+
6ae9ed
+static int
6ae9ed
 qemuBuildGlobalControllerCommandLine(virCommandPtr cmd,
6ae9ed
                                      const virDomainDef *def,
6ae9ed
                                      virQEMUCapsPtr qemuCaps)
6ae9ed
@@ -9273,6 +9305,9 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
6ae9ed
     if (qemuBuildBootCommandLine(cmd, def, qemuCaps, &emitBootindex) < 0)
6ae9ed
         goto error;
6ae9ed
 
6ae9ed
+    if (qemuBuildIOMMUCommandLine(cmd, def, qemuCaps) < 0)
6ae9ed
+        goto error;
6ae9ed
+
6ae9ed
     if (qemuBuildGlobalControllerCommandLine(cmd, def, qemuCaps) < 0)
6ae9ed
         goto error;
6ae9ed
 
6ae9ed
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-intel-iommu.args b/tests/qemuxml2argvdata/qemuxml2argv-intel-iommu.args
6ae9ed
new file mode 100644
6ae9ed
index 0000000..69e4490
6ae9ed
--- /dev/null
6ae9ed
+++ b/tests/qemuxml2argvdata/qemuxml2argv-intel-iommu.args
6ae9ed
@@ -0,0 +1,22 @@
6ae9ed
+LC_ALL=C \
6ae9ed
+PATH=/bin \
6ae9ed
+HOME=/home/test \
6ae9ed
+USER=test \
6ae9ed
+LOGNAME=test \
6ae9ed
+QEMU_AUDIO_DRV=none \
6ae9ed
+/usr/bin/qemu \
6ae9ed
+-name QEMUGuest1 \
6ae9ed
+-S \
6ae9ed
+-M q35 \
6ae9ed
+-m 214 \
6ae9ed
+-smp 1 \
6ae9ed
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
6ae9ed
+-nographic \
6ae9ed
+-nodefaults \
6ae9ed
+-monitor unix:/tmp/lib/domain--1-QEMUGuest1/monitor.sock,server,nowait \
6ae9ed
+-no-acpi \
6ae9ed
+-boot c \
6ae9ed
+-device intel-iommu \
6ae9ed
+-device i82801b11-bridge,id=pci.1,bus=pcie.0,addr=0x1e \
6ae9ed
+-device pci-bridge,chassis_nr=2,id=pci.2,bus=pci.1,addr=0x0 \
6ae9ed
+-device virtio-balloon-pci,id=balloon0,bus=pci.2,addr=0x1
6ae9ed
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
6ae9ed
index 51bab61..7fc10a8 100644
6ae9ed
--- a/tests/qemuxml2argvtest.c
6ae9ed
+++ b/tests/qemuxml2argvtest.c
6ae9ed
@@ -2043,6 +2043,8 @@ mymain(void)
6ae9ed
                               QEMU_CAPS_NODEFCONFIG, QEMU_CAPS_USB_HUB);
6ae9ed
 
6ae9ed
     DO_TEST("acpi-table", NONE);
6ae9ed
+    DO_TEST("intel-iommu", QEMU_CAPS_DEVICE_PCI_BRIDGE,
6ae9ed
+            QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE, QEMU_CAPS_DEVICE_INTEL_IOMMU);
6ae9ed
 
6ae9ed
     qemuTestDriverFree(&driver);
6ae9ed
 
6ae9ed
-- 
6ae9ed
2.9.2
6ae9ed