render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
3e5111
From 27eff2a6edc81f85757d7d03134dc65d737c316f Mon Sep 17 00:00:00 2001
3e5111
Message-Id: <27eff2a6edc81f85757d7d03134dc65d737c316f@dist-git>
3e5111
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
3e5111
Date: Fri, 9 Jun 2017 12:49:09 +0200
3e5111
Subject: [PATCH] qemu: format virtio-related options on the command line
3e5111
MIME-Version: 1.0
3e5111
Content-Type: text/plain; charset=UTF-8
3e5111
Content-Transfer-Encoding: 8bit
3e5111
3e5111
Format iommu_platform= and ats= for virtio devices.
3e5111
3e5111
https://bugzilla.redhat.com/show_bug.cgi?id=1283251
3e5111
3e5111
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
3e5111
(cherry picked from commit b2cbc3a0607bf26a82911f7db6dcbc09c9bbf5e8)
3e5111
Signed-off-by: Ján Tomko <jtomko@redhat.com>
3e5111
3e5111
Conflicts:
3e5111
	tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml
3e5111
          the version again
3e5111
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
3e5111
---
3e5111
 src/qemu/qemu_capabilities.c                       | 12 ++++-
3e5111
 src/qemu/qemu_capabilities.h                       |  2 +
3e5111
 src/qemu/qemu_command.c                            | 58 ++++++++++++++++++++++
3e5111
 tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml   |  2 +
3e5111
 .../qemuxml2argv-virtio-options.args               | 37 ++++++++------
3e5111
 tests/qemuxml2argvtest.c                           |  4 +-
3e5111
 6 files changed, 98 insertions(+), 17 deletions(-)
3e5111
3e5111
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
3e5111
index d8f3079083..eea57e4c9c 100644
3e5111
--- a/src/qemu/qemu_capabilities.c
3e5111
+++ b/src/qemu/qemu_capabilities.c
3e5111
@@ -374,6 +374,8 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
3e5111
               "intel-iommu.eim",
3e5111
 
3e5111
               "intel-iommu.device-iotlb", /* 260 */
3e5111
+              "virtio.iommu_platform",
3e5111
+              "virtio.ats",
3e5111
     );
3e5111
 
3e5111
 
3e5111
@@ -1851,7 +1853,7 @@ struct virQEMUCapsPropTypeObjects {
3e5111
     const char **objects;
3e5111
 };
3e5111
 
3e5111
-static const char *virQEMUCapsVirtioPCIDisableLegacyObjects[] = {
3e5111
+static const char *virQEMUCapsVirtioPCIObjects[] = {
3e5111
      "virtio-balloon-pci",
3e5111
      "virtio-blk-pci",
3e5111
      "virtio-scsi-pci",
3e5111
@@ -1870,7 +1872,13 @@ static const char *virQEMUCapsVirtioPCIDisableLegacyObjects[] = {
3e5111
 static struct virQEMUCapsPropTypeObjects virQEMUCapsPropObjects[] = {
3e5111
     { "disable-legacy",
3e5111
       QEMU_CAPS_VIRTIO_PCI_DISABLE_LEGACY,
3e5111
-      virQEMUCapsVirtioPCIDisableLegacyObjects }
3e5111
+      virQEMUCapsVirtioPCIObjects },
3e5111
+    { "iommu_platform",
3e5111
+      QEMU_CAPS_VIRTIO_PCI_IOMMU_PLATFORM,
3e5111
+      virQEMUCapsVirtioPCIObjects },
3e5111
+    { "ats",
3e5111
+      QEMU_CAPS_VIRTIO_PCI_ATS,
3e5111
+      virQEMUCapsVirtioPCIObjects },
3e5111
 };
3e5111
 
3e5111
 
3e5111
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
3e5111
index e0f81711fe..bbc6f6812f 100644
3e5111
--- a/src/qemu/qemu_capabilities.h
3e5111
+++ b/src/qemu/qemu_capabilities.h
3e5111
@@ -413,6 +413,8 @@ typedef enum {
3e5111
 
3e5111
     /* 260 */
3e5111
     QEMU_CAPS_INTEL_IOMMU_DEVICE_IOTLB, /* intel-iommu.device-iotlb */
3e5111
+    QEMU_CAPS_VIRTIO_PCI_IOMMU_PLATFORM, /* virtio-*-pci.iommu_platform */
3e5111
+    QEMU_CAPS_VIRTIO_PCI_ATS, /* virtio-*-pci.ats */
3e5111
 
3e5111
     QEMU_CAPS_LAST /* this must always be the last item */
3e5111
 } virQEMUCapsFlags;
3e5111
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
3e5111
index 9c5639b036..e220bf5ba0 100644
3e5111
--- a/src/qemu/qemu_command.c
3e5111
+++ b/src/qemu/qemu_command.c
3e5111
@@ -389,6 +389,38 @@ qemuBuildDeviceAddressStr(virBufferPtr buf,
3e5111
 }
3e5111
 
3e5111
 static int
3e5111
+qemuBuildVirtioOptionsStr(virBufferPtr buf,
3e5111
+                          virDomainVirtioOptionsPtr virtio,
3e5111
+                          virQEMUCapsPtr qemuCaps)
3e5111
+{
3e5111
+    if (!virtio)
3e5111
+        return 0;
3e5111
+
3e5111
+    if (virtio->iommu != VIR_TRISTATE_SWITCH_ABSENT) {
3e5111
+        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_PCI_IOMMU_PLATFORM)) {
3e5111
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
3e5111
+                           _("the iommu setting is not supported "
3e5111
+                             "with this QEMU binary"));
3e5111
+            return -1;
3e5111
+        }
3e5111
+        virBufferAsprintf(buf, ",iommu_platform=%s",
3e5111
+                          virTristateSwitchTypeToString(virtio->iommu));
3e5111
+    }
3e5111
+    if (virtio->ats != VIR_TRISTATE_SWITCH_ABSENT) {
3e5111
+        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_PCI_ATS)) {
3e5111
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
3e5111
+                           _("the ats setting is not supported with this "
3e5111
+                             "QEMU binary"));
3e5111
+            return -1;
3e5111
+        }
3e5111
+        virBufferAsprintf(buf, ",ats=%s",
3e5111
+                          virTristateSwitchTypeToString(virtio->ats));
3e5111
+    }
3e5111
+
3e5111
+    return 0;
3e5111
+}
3e5111
+
3e5111
+static int
3e5111
 qemuBuildRomStr(virBufferPtr buf,
3e5111
                 virDomainDeviceInfoPtr info)
3e5111
 {
3e5111
@@ -2167,6 +2199,10 @@ qemuBuildDriveDevStr(const virDomainDef *def,
3e5111
                               (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN)
3e5111
                               ? "on" : "off");
3e5111
         }
3e5111
+
3e5111
+        if (qemuBuildVirtioOptionsStr(&opt, disk->virtio, qemuCaps) < 0)
3e5111
+            goto error;
3e5111
+
3e5111
         if (qemuBuildDeviceAddressStr(&opt, def, &disk->info, qemuCaps) < 0)
3e5111
             goto error;
3e5111
         break;
3e5111
@@ -2490,6 +2526,8 @@ qemuBuildFSDevStr(const virDomainDef *def,
3e5111
                       QEMU_FSDEV_HOST_PREFIX, fs->info.alias);
3e5111
     virBufferAsprintf(&opt, ",mount_tag=%s", fs->dst);
3e5111
 
3e5111
+    qemuBuildVirtioOptionsStr(&opt, fs->virtio, qemuCaps);
3e5111
+
3e5111
     if (qemuBuildDeviceAddressStr(&opt, def, &fs->info, qemuCaps) < 0)
3e5111
         goto error;
3e5111
 
3e5111
@@ -2734,6 +2772,8 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
3e5111
                                       def->iothread);
3e5111
                 }
3e5111
             }
3e5111
+            if (qemuBuildVirtioOptionsStr(&buf, def->virtio, qemuCaps) < 0)
3e5111
+                goto error;
3e5111
             break;
3e5111
         case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC:
3e5111
             virBufferAddLit(&buf, "lsi");
3e5111
@@ -2779,6 +2819,8 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef,
3e5111
             virBufferAsprintf(&buf, ",vectors=%d",
3e5111
                               def->opts.vioserial.vectors);
3e5111
         }
3e5111
+        if (qemuBuildVirtioOptionsStr(&buf, def->virtio, qemuCaps) < 0)
3e5111
+            goto error;
3e5111
         break;
3e5111
 
3e5111
     case VIR_DOMAIN_CONTROLLER_TYPE_CCID:
3e5111
@@ -3773,12 +3815,16 @@ qemuBuildNicDevStr(virDomainDefPtr def,
3e5111
     virBufferAsprintf(&buf, ",id=%s", net->info.alias);
3e5111
     virBufferAsprintf(&buf, ",mac=%s",
3e5111
                       virMacAddrFormat(&net->mac, macaddr));
3e5111
+
3e5111
     if (qemuBuildDeviceAddressStr(&buf, def, &net->info, qemuCaps) < 0)
3e5111
         goto error;
3e5111
     if (qemuBuildRomStr(&buf, &net->info) < 0)
3e5111
         goto error;
3e5111
     if (bootindex && virQEMUCapsGet(qemuCaps, QEMU_CAPS_BOOTINDEX))
3e5111
         virBufferAsprintf(&buf, ",bootindex=%u", bootindex);
3e5111
+    if (usingVirtio &&
3e5111
+        qemuBuildVirtioOptionsStr(&buf, net->virtio, qemuCaps) < 0)
3e5111
+        goto error;
3e5111
 
3e5111
     if (virBufferCheckError(&buf) < 0)
3e5111
         goto error;
3e5111
@@ -4053,6 +4099,9 @@ qemuBuildMemballoonCommandLine(virCommandPtr cmd,
3e5111
                           virTristateSwitchTypeToString(def->memballoon->autodeflate));
3e5111
     }
3e5111
 
3e5111
+    if (qemuBuildVirtioOptionsStr(&buf, def->memballoon->virtio, qemuCaps) < 0)
3e5111
+        goto error;
3e5111
+
3e5111
     virCommandAddArg(cmd, "-device");
3e5111
     virCommandAddArgBuffer(cmd, &buf;;
3e5111
     return 0;
3e5111
@@ -4183,6 +4232,9 @@ qemuBuildVirtioInputDevStr(const virDomainDef *def,
3e5111
     if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0)
3e5111
         goto error;
3e5111
 
3e5111
+    if (qemuBuildVirtioOptionsStr(&buf, dev->virtio, qemuCaps) < 0)
3e5111
+        goto error;
3e5111
+
3e5111
     if (virBufferCheckError(&buf) < 0)
3e5111
         goto error;
3e5111
 
3e5111
@@ -4495,6 +4547,9 @@ qemuBuildDeviceVideoStr(const virDomainDef *def,
3e5111
     if (qemuBuildDeviceAddressStr(&buf, def, &video->info, qemuCaps) < 0)
3e5111
         goto error;
3e5111
 
3e5111
+    if (qemuBuildVirtioOptionsStr(&buf, video->virtio, qemuCaps) < 0)
3e5111
+        goto error;
3e5111
+
3e5111
     if (virBufferCheckError(&buf) < 0)
3e5111
         goto error;
3e5111
 
3e5111
@@ -5860,6 +5915,9 @@ qemuBuildRNGDevStr(const virDomainDef *def,
3e5111
             virBufferAddLit(&buf, ",period=1000");
3e5111
     }
3e5111
 
3e5111
+    if (qemuBuildVirtioOptionsStr(&buf, dev->virtio, qemuCaps) < 0)
3e5111
+        goto error;
3e5111
+
3e5111
     if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0)
3e5111
         goto error;
3e5111
     if (virBufferCheckError(&buf) < 0)
3e5111
diff --git a/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml b/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml
3e5111
index 29a483d123..2140eab398 100644
3e5111
--- a/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml
3e5111
+++ b/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml
3e5111
@@ -215,6 +215,8 @@
3e5111
   <flag name='intel-iommu.caching-mode'/>
3e5111
   <flag name='intel-iommu.eim'/>
3e5111
   <flag name='intel-iommu.device-iotlb'/>
3e5111
+  <flag name='virtio.iommu_platform'/>
3e5111
+  <flag name='virtio.ats'/>
3e5111
   <version>2008090</version>
3e5111
   <kvmVersion>0</kvmVersion>
3e5111
   <package> (v2.9.0-rc0-142-g940a8ce)</package>
3e5111
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-virtio-options.args b/tests/qemuxml2argvdata/qemuxml2argv-virtio-options.args
3e5111
index f9f3c2cbad..ce0388dfc2 100644
3e5111
--- a/tests/qemuxml2argvdata/qemuxml2argv-virtio-options.args
3e5111
+++ b/tests/qemuxml2argvdata/qemuxml2argv-virtio-options.args
3e5111
@@ -16,26 +16,35 @@ QEMU_AUDIO_DRV=none \
3e5111
 -monitor unix:/tmp/lib/domain--1-QEMUGuest1/monitor.sock,server,nowait \
3e5111
 -no-acpi \
3e5111
 -boot c \
3e5111
--device virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x8 \
3e5111
--device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x9 \
3e5111
+-device virtio-scsi-pci,iommu_platform=on,ats=on,id=scsi0,bus=pci.0,addr=0x8 \
3e5111
+-device virtio-serial-pci,id=virtio-serial0,iommu_platform=on,ats=on,bus=pci.0,\
3e5111
+addr=0x9 \
3e5111
 -usb \
3e5111
 -drive file=/var/lib/libvirt/images/img1,format=raw,if=none,\
3e5111
 id=drive-virtio-disk0 \
3e5111
--device virtio-blk-pci,bus=pci.0,addr=0xa,drive=drive-virtio-disk0,\
3e5111
-id=virtio-disk0 \
3e5111
+-device virtio-blk-pci,iommu_platform=on,ats=on,bus=pci.0,addr=0xa,\
3e5111
+drive=drive-virtio-disk0,id=virtio-disk0 \
3e5111
 -fsdev local,security_model=passthrough,id=fsdev-fs0,path=/export/fs1 \
3e5111
--device virtio-9p-pci,id=fs0,fsdev=fsdev-fs0,mount_tag=fs1,bus=pci.0,addr=0x3 \
3e5111
+-device virtio-9p-pci,id=fs0,fsdev=fsdev-fs0,mount_tag=fs1,iommu_platform=on,\
3e5111
+ats=on,bus=pci.0,addr=0x3 \
3e5111
 -fsdev local,security_model=mapped,writeout=immediate,id=fsdev-fs1,\
3e5111
 path=/export/fs2 \
3e5111
--device virtio-9p-pci,id=fs1,fsdev=fsdev-fs1,mount_tag=fs2,bus=pci.0,addr=0x4 \
3e5111
--device virtio-net-pci,vlan=0,id=net0,mac=52:54:56:58:5a:5c,bus=pci.0,addr=0x6 \
3e5111
+-device virtio-9p-pci,id=fs1,fsdev=fsdev-fs1,mount_tag=fs2,iommu_platform=on,\
3e5111
+ats=on,bus=pci.0,addr=0x4 \
3e5111
+-device virtio-net-pci,vlan=0,id=net0,mac=52:54:56:58:5a:5c,bus=pci.0,addr=0x6,\
3e5111
+iommu_platform=on,ats=on \
3e5111
 -net user,vlan=0,name=hostnet0 \
3e5111
--device virtio-mouse-pci,id=input0,bus=pci.0,addr=0xe \
3e5111
--device virtio-keyboard-pci,id=input1,bus=pci.0,addr=0x10 \
3e5111
--device virtio-tablet-pci,id=input2,bus=pci.0,addr=0x11 \
3e5111
+-device virtio-mouse-pci,id=input0,bus=pci.0,addr=0xe,iommu_platform=on,ats=on \
3e5111
+-device virtio-keyboard-pci,id=input1,bus=pci.0,addr=0x10,iommu_platform=on,\
3e5111
+ats=on \
3e5111
+-device virtio-tablet-pci,id=input2,bus=pci.0,addr=0x11,iommu_platform=on,\
3e5111
+ats=on \
3e5111
 -device virtio-input-host-pci,id=input3,evdev=/dev/input/event1234,bus=pci.0,\
3e5111
-addr=0x12 \
3e5111
--device virtio-gpu-pci,id=video0,virgl=on,bus=pci.0,addr=0x2 \
3e5111
--device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0xc \
3e5111
+addr=0x12,iommu_platform=on,ats=on \
3e5111
+-device virtio-gpu-pci,id=video0,virgl=on,bus=pci.0,addr=0x2,iommu_platform=on,\
3e5111
+ats=on \
3e5111
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0xc,iommu_platform=on,\
3e5111
+ats=on \
3e5111
 -object rng-random,id=objrng0,filename=/dev/random \
3e5111
--device virtio-rng-pci,rng=objrng0,id=rng0,bus=pci.0,addr=0xd
3e5111
+-device virtio-rng-pci,rng=objrng0,id=rng0,iommu_platform=on,ats=on,bus=pci.0,\
3e5111
+addr=0xd
3e5111
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
3e5111
index c186780ef1..175037bf96 100644
3e5111
--- a/tests/qemuxml2argvtest.c
3e5111
+++ b/tests/qemuxml2argvtest.c
3e5111
@@ -2558,7 +2558,9 @@ mymain(void)
3e5111
             QEMU_CAPS_VIRTIO_GPU_VIRGL,
3e5111
             QEMU_CAPS_DEVICE_VIRTIO_RNG,
3e5111
             QEMU_CAPS_OBJECT_RNG_RANDOM,
3e5111
-            QEMU_CAPS_DEVICE_VIDEO_PRIMARY);
3e5111
+            QEMU_CAPS_DEVICE_VIDEO_PRIMARY,
3e5111
+            QEMU_CAPS_VIRTIO_PCI_IOMMU_PLATFORM,
3e5111
+            QEMU_CAPS_VIRTIO_PCI_ATS);
3e5111
 
3e5111
     DO_TEST("fd-memory-numa-topology", QEMU_CAPS_MEM_PATH, QEMU_CAPS_OBJECT_MEMORY_FILE,
3e5111
             QEMU_CAPS_KVM);
3e5111
-- 
3e5111
2.13.1
3e5111