]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: fix command line building for iommu devices
authorDaniel P. Berrange <berrange@redhat.com>
Mon, 3 Oct 2016 12:31:12 +0000 (13:31 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Fri, 7 Oct 2016 15:52:35 +0000 (16:52 +0100)
The intel-iommu device has existed since QEMU 2.2.0, but
it was only possible to create it with -device since
QEMU 2.7.0, thanks to:

  commit 621d983a1f9051f4cfc3f402569b46b77d8449fc
  Author: Marcel Apfelbaum <marcel@redhat.com>
  Date:   Mon Jun 27 18:38:34 2016 +0300

    hw/iommu: enable iommu with -device

    Use the standard '-device intel-iommu' to create the IOMMU device.
    The legacy '-machine,iommu=on' can still be used.

The libvirt capability check & command line formatting code
is thus broken for all QEMU versions 2.2.0 -> 2.6.0 inclusive.

This fixes it to use iommu=on instead.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
src/qemu/qemu_capabilities.c
src/qemu/qemu_capabilities.h
src/qemu/qemu_command.c
tests/qemucapabilitiesdata/caps_2.4.0.x86_64.xml
tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml
tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml
tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-machine.args [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-machine.xml [new file with mode: 0644]
tests/qemuxml2argvtest.c

index cc8ec5857111e4ff40eacd179caa595fa094efeb..da8f3d1ed1515ad2c1a87a83655f722b67cb85d1 100644 (file)
@@ -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) &&
index ba0ef4859d42e1f144ef5feb4df24178b6cfe389..51c2372b8a58bbd553147080bf7f85ad241b252b 100644 (file)
@@ -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;
index 578ff8b23a2c5fa7fb287282bb14229e613b0c3c..080413363b211e17b69cea1299d57f5d31a8d96a 100644 (file)
@@ -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);
     }
 
index db778ef4c92c2dc6afd915f6b7c395f88d239efd..abb9c66ad8af68e1c724f84d41db2eb7a161a212 100644 (file)
   <flag name='spice-unix'/>
   <flag name='drive-detect-zeroes'/>
   <flag name='display'/>
-  <flag name='intel-iommu'/>
   <flag name='smm'/>
   <flag name='virtio-pci-disable-legacy'/>
+  <flag name='machine-iommu'/>
   <version>2004000</version>
   <kvmVersion>0</kvmVersion>
   <package></package>
index fc915ad254794308320b7ba3c74b0d67a884eb13..cbf2e1ebc23835654fe844b66a5fbf1644374a84 100644 (file)
   <flag name='drive-detect-zeroes'/>
   <flag name='tls-creds-x509'/>
   <flag name='display'/>
-  <flag name='intel-iommu'/>
   <flag name='smm'/>
   <flag name='virtio-pci-disable-legacy'/>
+  <flag name='machine-iommu'/>
   <version>2005000</version>
   <kvmVersion>0</kvmVersion>
   <package></package>
index 60f1fcfe85d5f2253e8611bca0b76ae6b5f3e969..116c5062c58c5d67b090ce4b57c468265e42235c 100644 (file)
   <flag name='drive-detect-zeroes'/>
   <flag name='tls-creds-x509'/>
   <flag name='display'/>
-  <flag name='intel-iommu'/>
   <flag name='smm'/>
   <flag name='virtio-pci-disable-legacy'/>
+  <flag name='machine-iommu'/>
   <version>2006000</version>
   <kvmVersion>0</kvmVersion>
   <package></package>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-machine.args b/tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-machine.args
new file mode 100644 (file)
index 0000000..9221b79
--- /dev/null
@@ -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 (file)
index 0000000..b5b2b51
--- /dev/null
@@ -0,0 +1,37 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219100</memory>
+  <currentMemory unit='KiB'>219100</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64' machine='q35'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu</emulator>
+    <controller type='pci' index='0' model='pcie-root'/>
+    <controller type='pci' index='1' model='dmi-to-pci-bridge'>
+      <model name='i82801b11-bridge'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x1e' function='0x0'/>
+    </controller>
+    <controller type='pci' index='2' model='pci-bridge'>
+      <model name='pci-bridge'/>
+      <target chassisNr='2'/>
+      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
+    </controller>
+    <controller type='sata' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
+    </controller>
+    <input type='mouse' bus='ps2'/>
+    <input type='keyboard' bus='ps2'/>
+    <memballoon model='virtio'>
+      <address type='pci' domain='0x0000' bus='0x02' slot='0x01' function='0x0'/>
+    </memballoon>
+    <iommu model='intel'/>
+  </devices>
+</domain>
index 4b9ecb82f8bc7d081a41a2e50f53497ac334afb5..903276db370b4f3c9fca28b18a5271b47f325311 100644 (file)
@@ -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);