Blob Blame History Raw
From 27eff2a6edc81f85757d7d03134dc65d737c316f Mon Sep 17 00:00:00 2001
Message-Id: <27eff2a6edc81f85757d7d03134dc65d737c316f@dist-git>
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
Date: Fri, 9 Jun 2017 12:49:09 +0200
Subject: [PATCH] qemu: format virtio-related options on the command line
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Format iommu_platform= and ats= for virtio devices.

https://bugzilla.redhat.com/show_bug.cgi?id=1283251

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit b2cbc3a0607bf26a82911f7db6dcbc09c9bbf5e8)
Signed-off-by: Ján Tomko <jtomko@redhat.com>

Conflicts:
	tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml
          the version again
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu_capabilities.c                       | 12 ++++-
 src/qemu/qemu_capabilities.h                       |  2 +
 src/qemu/qemu_command.c                            | 58 ++++++++++++++++++++++
 tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml   |  2 +
 .../qemuxml2argv-virtio-options.args               | 37 ++++++++------
 tests/qemuxml2argvtest.c                           |  4 +-
 6 files changed, 98 insertions(+), 17 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index d8f3079083..eea57e4c9c 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -374,6 +374,8 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
               "intel-iommu.eim",
 
               "intel-iommu.device-iotlb", /* 260 */
+              "virtio.iommu_platform",
+              "virtio.ats",
     );
 
 
@@ -1851,7 +1853,7 @@ struct virQEMUCapsPropTypeObjects {
     const char **objects;
 };
 
-static const char *virQEMUCapsVirtioPCIDisableLegacyObjects[] = {
+static const char *virQEMUCapsVirtioPCIObjects[] = {
      "virtio-balloon-pci",
      "virtio-blk-pci",
      "virtio-scsi-pci",
@@ -1870,7 +1872,13 @@ static const char *virQEMUCapsVirtioPCIDisableLegacyObjects[] = {
 static struct virQEMUCapsPropTypeObjects virQEMUCapsPropObjects[] = {
     { "disable-legacy",
       QEMU_CAPS_VIRTIO_PCI_DISABLE_LEGACY,
-      virQEMUCapsVirtioPCIDisableLegacyObjects }
+      virQEMUCapsVirtioPCIObjects },
+    { "iommu_platform",
+      QEMU_CAPS_VIRTIO_PCI_IOMMU_PLATFORM,
+      virQEMUCapsVirtioPCIObjects },
+    { "ats",
+      QEMU_CAPS_VIRTIO_PCI_ATS,
+      virQEMUCapsVirtioPCIObjects },
 };
 
 
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index e0f81711fe..bbc6f6812f 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -413,6 +413,8 @@ typedef enum {
 
     /* 260 */
     QEMU_CAPS_INTEL_IOMMU_DEVICE_IOTLB, /* intel-iommu.device-iotlb */
+    QEMU_CAPS_VIRTIO_PCI_IOMMU_PLATFORM, /* virtio-*-pci.iommu_platform */
+    QEMU_CAPS_VIRTIO_PCI_ATS, /* virtio-*-pci.ats */
 
     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 9c5639b036..e220bf5ba0 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -389,6 +389,38 @@ qemuBuildDeviceAddressStr(virBufferPtr buf,
 }
 
 static int
+qemuBuildVirtioOptionsStr(virBufferPtr buf,
+                          virDomainVirtioOptionsPtr virtio,
+                          virQEMUCapsPtr qemuCaps)
+{
+    if (!virtio)
+        return 0;
+
+    if (virtio->iommu != VIR_TRISTATE_SWITCH_ABSENT) {
+        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_PCI_IOMMU_PLATFORM)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("the iommu setting is not supported "
+                             "with this QEMU binary"));
+            return -1;
+        }
+        virBufferAsprintf(buf, ",iommu_platform=%s",
+                          virTristateSwitchTypeToString(virtio->iommu));
+    }
+    if (virtio->ats != VIR_TRISTATE_SWITCH_ABSENT) {
+        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_PCI_ATS)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("the ats setting is not supported with this "
+                             "QEMU binary"));
+            return -1;
+        }
+        virBufferAsprintf(buf, ",ats=%s",
+                          virTristateSwitchTypeToString(virtio->ats));
+    }
+
+    return 0;
+}
+
+static int
 qemuBuildRomStr(virBufferPtr buf,
                 virDomainDeviceInfoPtr info)
 {
@@ -2167,6 +2199,10 @@ qemuBuildDriveDevStr(const virDomainDef *def,
                               (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN)
                               ? "on" : "off");
         }
+
+        if (qemuBuildVirtioOptionsStr(&opt, disk->virtio, qemuCaps) < 0)
+            goto error;
+
         if (qemuBuildDeviceAddressStr(&opt, def, &disk->info, qemuCaps) < 0)
             goto error;
         break;
@@ -2490,6 +2526,8 @@ qemuBuildFSDevStr(const virDomainDef *def,
                       QEMU_FSDEV_HOST_PREFIX, fs->info.alias);
     virBufferAsprintf(&opt, ",mount_tag=%s", fs->dst);
 
+    qemuBuildVirtioOptionsStr(&opt, fs->virtio, qemuCaps);
+
     if (qemuBuildDeviceAddressStr(&opt, def, &fs->info, qemuCaps) < 0)
         goto error;
 
@@ -2734,6 +2772,8 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
                                       def->iothread);
                 }
             }
+            if (qemuBuildVirtioOptionsStr(&buf, def->virtio, qemuCaps) < 0)
+                goto error;
             break;
         case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC:
             virBufferAddLit(&buf, "lsi");
@@ -2779,6 +2819,8 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
             virBufferAsprintf(&buf, ",vectors=%d",
                               def->opts.vioserial.vectors);
         }
+        if (qemuBuildVirtioOptionsStr(&buf, def->virtio, qemuCaps) < 0)
+            goto error;
         break;
 
     case VIR_DOMAIN_CONTROLLER_TYPE_CCID:
@@ -3773,12 +3815,16 @@ qemuBuildNicDevStr(virDomainDefPtr def,
     virBufferAsprintf(&buf, ",id=%s", net->info.alias);
     virBufferAsprintf(&buf, ",mac=%s",
                       virMacAddrFormat(&net->mac, macaddr));
+
     if (qemuBuildDeviceAddressStr(&buf, def, &net->info, qemuCaps) < 0)
         goto error;
     if (qemuBuildRomStr(&buf, &net->info) < 0)
         goto error;
     if (bootindex && virQEMUCapsGet(qemuCaps, QEMU_CAPS_BOOTINDEX))
         virBufferAsprintf(&buf, ",bootindex=%u", bootindex);
+    if (usingVirtio &&
+        qemuBuildVirtioOptionsStr(&buf, net->virtio, qemuCaps) < 0)
+        goto error;
 
     if (virBufferCheckError(&buf) < 0)
         goto error;
@@ -4053,6 +4099,9 @@ qemuBuildMemballoonCommandLine(virCommandPtr cmd,
                           virTristateSwitchTypeToString(def->memballoon->autodeflate));
     }
 
+    if (qemuBuildVirtioOptionsStr(&buf, def->memballoon->virtio, qemuCaps) < 0)
+        goto error;
+
     virCommandAddArg(cmd, "-device");
     virCommandAddArgBuffer(cmd, &buf);
     return 0;
@@ -4183,6 +4232,9 @@ qemuBuildVirtioInputDevStr(const virDomainDef *def,
     if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0)
         goto error;
 
+    if (qemuBuildVirtioOptionsStr(&buf, dev->virtio, qemuCaps) < 0)
+        goto error;
+
     if (virBufferCheckError(&buf) < 0)
         goto error;
 
@@ -4495,6 +4547,9 @@ qemuBuildDeviceVideoStr(const virDomainDef *def,
     if (qemuBuildDeviceAddressStr(&buf, def, &video->info, qemuCaps) < 0)
         goto error;
 
+    if (qemuBuildVirtioOptionsStr(&buf, video->virtio, qemuCaps) < 0)
+        goto error;
+
     if (virBufferCheckError(&buf) < 0)
         goto error;
 
@@ -5860,6 +5915,9 @@ qemuBuildRNGDevStr(const virDomainDef *def,
             virBufferAddLit(&buf, ",period=1000");
     }
 
+    if (qemuBuildVirtioOptionsStr(&buf, dev->virtio, qemuCaps) < 0)
+        goto error;
+
     if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0)
         goto error;
     if (virBufferCheckError(&buf) < 0)
diff --git a/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml b/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml
index 29a483d123..2140eab398 100644
--- a/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml
+++ b/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml
@@ -215,6 +215,8 @@
   <flag name='intel-iommu.caching-mode'/>
   <flag name='intel-iommu.eim'/>
   <flag name='intel-iommu.device-iotlb'/>
+  <flag name='virtio.iommu_platform'/>
+  <flag name='virtio.ats'/>
   <version>2008090</version>
   <kvmVersion>0</kvmVersion>
   <package> (v2.9.0-rc0-142-g940a8ce)</package>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-virtio-options.args b/tests/qemuxml2argvdata/qemuxml2argv-virtio-options.args
index f9f3c2cbad..ce0388dfc2 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-virtio-options.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-virtio-options.args
@@ -16,26 +16,35 @@ QEMU_AUDIO_DRV=none \
 -monitor unix:/tmp/lib/domain--1-QEMUGuest1/monitor.sock,server,nowait \
 -no-acpi \
 -boot c \
--device virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x8 \
--device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x9 \
+-device virtio-scsi-pci,iommu_platform=on,ats=on,id=scsi0,bus=pci.0,addr=0x8 \
+-device virtio-serial-pci,id=virtio-serial0,iommu_platform=on,ats=on,bus=pci.0,\
+addr=0x9 \
 -usb \
 -drive file=/var/lib/libvirt/images/img1,format=raw,if=none,\
 id=drive-virtio-disk0 \
--device virtio-blk-pci,bus=pci.0,addr=0xa,drive=drive-virtio-disk0,\
-id=virtio-disk0 \
+-device virtio-blk-pci,iommu_platform=on,ats=on,bus=pci.0,addr=0xa,\
+drive=drive-virtio-disk0,id=virtio-disk0 \
 -fsdev local,security_model=passthrough,id=fsdev-fs0,path=/export/fs1 \
--device virtio-9p-pci,id=fs0,fsdev=fsdev-fs0,mount_tag=fs1,bus=pci.0,addr=0x3 \
+-device virtio-9p-pci,id=fs0,fsdev=fsdev-fs0,mount_tag=fs1,iommu_platform=on,\
+ats=on,bus=pci.0,addr=0x3 \
 -fsdev local,security_model=mapped,writeout=immediate,id=fsdev-fs1,\
 path=/export/fs2 \
--device virtio-9p-pci,id=fs1,fsdev=fsdev-fs1,mount_tag=fs2,bus=pci.0,addr=0x4 \
--device virtio-net-pci,vlan=0,id=net0,mac=52:54:56:58:5a:5c,bus=pci.0,addr=0x6 \
+-device virtio-9p-pci,id=fs1,fsdev=fsdev-fs1,mount_tag=fs2,iommu_platform=on,\
+ats=on,bus=pci.0,addr=0x4 \
+-device virtio-net-pci,vlan=0,id=net0,mac=52:54:56:58:5a:5c,bus=pci.0,addr=0x6,\
+iommu_platform=on,ats=on \
 -net user,vlan=0,name=hostnet0 \
--device virtio-mouse-pci,id=input0,bus=pci.0,addr=0xe \
--device virtio-keyboard-pci,id=input1,bus=pci.0,addr=0x10 \
--device virtio-tablet-pci,id=input2,bus=pci.0,addr=0x11 \
+-device virtio-mouse-pci,id=input0,bus=pci.0,addr=0xe,iommu_platform=on,ats=on \
+-device virtio-keyboard-pci,id=input1,bus=pci.0,addr=0x10,iommu_platform=on,\
+ats=on \
+-device virtio-tablet-pci,id=input2,bus=pci.0,addr=0x11,iommu_platform=on,\
+ats=on \
 -device virtio-input-host-pci,id=input3,evdev=/dev/input/event1234,bus=pci.0,\
-addr=0x12 \
--device virtio-gpu-pci,id=video0,virgl=on,bus=pci.0,addr=0x2 \
--device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0xc \
+addr=0x12,iommu_platform=on,ats=on \
+-device virtio-gpu-pci,id=video0,virgl=on,bus=pci.0,addr=0x2,iommu_platform=on,\
+ats=on \
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0xc,iommu_platform=on,\
+ats=on \
 -object rng-random,id=objrng0,filename=/dev/random \
--device virtio-rng-pci,rng=objrng0,id=rng0,bus=pci.0,addr=0xd
+-device virtio-rng-pci,rng=objrng0,id=rng0,iommu_platform=on,ats=on,bus=pci.0,\
+addr=0xd
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index c186780ef1..175037bf96 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -2558,7 +2558,9 @@ mymain(void)
             QEMU_CAPS_VIRTIO_GPU_VIRGL,
             QEMU_CAPS_DEVICE_VIRTIO_RNG,
             QEMU_CAPS_OBJECT_RNG_RANDOM,
-            QEMU_CAPS_DEVICE_VIDEO_PRIMARY);
+            QEMU_CAPS_DEVICE_VIDEO_PRIMARY,
+            QEMU_CAPS_VIRTIO_PCI_IOMMU_PLATFORM,
+            QEMU_CAPS_VIRTIO_PCI_ATS);
 
     DO_TEST("fd-memory-numa-topology", QEMU_CAPS_MEM_PATH, QEMU_CAPS_OBJECT_MEMORY_FILE,
             QEMU_CAPS_KVM);
-- 
2.13.1