render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
397dc2
From 362d106d8897a3982f5eaed0c4bc0194d6f9ef28 Mon Sep 17 00:00:00 2001
397dc2
Message-Id: <362d106d8897a3982f5eaed0c4bc0194d6f9ef28@dist-git>
f43bc9
From: Boris Fiuczynski <fiuczy@linux.ibm.com>
397dc2
Date: Fri, 26 Feb 2021 06:43:35 -0500
f43bc9
Subject: [PATCH] qemu: Add virtio related options to vsock
f43bc9
f43bc9
Add virtio related options iommu, ats and packed as driver element attributes
f43bc9
to vsock devices. Ex:
f43bc9
f43bc9
 <vsock model='virtio'>
f43bc9
   <cid auto='no' address='3'/>
f43bc9
   <driver iommu='on'/>
f43bc9
 </vsock>
f43bc9
f43bc9
Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
f43bc9
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
f43bc9
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
f43bc9
(cherry picked from commit bd112c9e0f7523b90bf1362cf60deea7db05a32b)
f43bc9
397dc2
Resolves: https://bugzilla.redhat.com/1931548
f43bc9
f43bc9
Note: since the virtio option packed is not yet available in the code
f43bc9
version it will also not be available with this backported patch.
f43bc9
f43bc9
Conflicts: docs/formatdomain.rst:
f43bc9
    converted changes into docs/formatdomain.html.in
f43bc9
    src/conf/domain_conf.c:
f43bc9
    resolved conflicts by moving the code into the correct methods
f43bc9
    src/conf/domain_validate.c:
f43bc9
    does not exist downstream. moved code to src/conf/domain_conf.c
f43bc9
    src/qemu/qemu_validate.c:
f43bc9
    does not exist downstream. can be neglected
f43bc9
397dc2
Message-Id: <20210226114335.100390-2-bfiuczyn@redhat.com>
397dc2
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
f43bc9
---
f43bc9
 docs/formatdomain.html.in                     |  5 ++-
f43bc9
 docs/schemas/domaincommon.rng                 |  5 +++
f43bc9
 src/conf/domain_conf.c                        | 27 ++++++++++++++
f43bc9
 src/conf/domain_conf.h                        |  1 +
f43bc9
 src/qemu/qemu_command.c                       |  4 ++
f43bc9
 .../vhost-vsock-ccw-iommu.s390x-latest.args   | 37 +++++++++++++++++++
f43bc9
 .../vhost-vsock-ccw-iommu.xml                 | 37 +++++++++++++++++++
f43bc9
 tests/qemuxml2argvtest.c                      |  1 +
f43bc9
 .../vhost-vsock-ccw-iommu.s390x-latest.xml    |  1 +
f43bc9
 tests/qemuxml2xmltest.c                       |  2 +
f43bc9
 10 files changed, 119 insertions(+), 1 deletion(-)
f43bc9
 create mode 100644 tests/qemuxml2argvdata/vhost-vsock-ccw-iommu.s390x-latest.args
f43bc9
 create mode 100644 tests/qemuxml2argvdata/vhost-vsock-ccw-iommu.xml
f43bc9
 create mode 120000 tests/qemuxml2xmloutdata/vhost-vsock-ccw-iommu.s390x-latest.xml
f43bc9
f43bc9
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
397dc2
index bec753e37f..127dd13cc0 100644
f43bc9
--- a/docs/formatdomain.html.in
f43bc9
+++ b/docs/formatdomain.html.in
397dc2
@@ -9240,7 +9240,10 @@ qemu-kvm -net nic,model=? /dev/null
f43bc9
     element specifies the CID assigned to the guest. If the attribute
f43bc9
     auto is set to yes, libvirt
f43bc9
     will assign a free CID automatically on domain startup.
f43bc9
-    Since 4.4.0

f43bc9
+    Since 4.4.0
f43bc9
+    The optional driver element allows to specify virtio options, see
f43bc9
+    Virtio-specific options for more details.
f43bc9
+    Since 7.1.0

f43bc9
 
f43bc9
 
f43bc9
 ...
f43bc9
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
f43bc9
index 9fda5f17e0..4a42cb9b40 100644
f43bc9
--- a/docs/schemas/domaincommon.rng
f43bc9
+++ b/docs/schemas/domaincommon.rng
f43bc9
@@ -4685,6 +4685,11 @@
f43bc9
         <optional>
f43bc9
           <ref name="alias"/>
f43bc9
         </optional>
f43bc9
+        <optional>
f43bc9
+          <element name="driver">
f43bc9
+            <ref name="virtioOptions"/>
f43bc9
+          </element>
f43bc9
+        </optional>
f43bc9
       </interleave>
f43bc9
     </element>
f43bc9
   </define>
f43bc9
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
397dc2
index c5a0442c6f..166c3e48d2 100644
f43bc9
--- a/src/conf/domain_conf.c
f43bc9
+++ b/src/conf/domain_conf.c
f43bc9
@@ -2392,6 +2392,7 @@ virDomainVsockDefFree(virDomainVsockDefPtr vsock)
f43bc9
 
f43bc9
     virObjectUnref(vsock->privateData);
f43bc9
     virDomainDeviceInfoClear(&vsock->info);
f43bc9
+    VIR_FREE(vsock->virtio);
f43bc9
     VIR_FREE(vsock);
f43bc9
 }
f43bc9
 
f43bc9
@@ -6504,6 +6505,15 @@ virDomainMemoryDefValidate(const virDomainMemoryDef *mem)
f43bc9
 }
f43bc9
 
f43bc9
 
f43bc9
+static bool
f43bc9
+virDomainVsockIsVirtioModel(const virDomainVsockDef *vsock)
f43bc9
+{
f43bc9
+    return (vsock->model == VIR_DOMAIN_VSOCK_MODEL_VIRTIO ||
f43bc9
+            vsock->model == VIR_DOMAIN_VSOCK_MODEL_VIRTIO_TRANSITIONAL ||
f43bc9
+            vsock->model == VIR_DOMAIN_VSOCK_MODEL_VIRTIO_NON_TRANSITIONAL);
f43bc9
+}
f43bc9
+
f43bc9
+
f43bc9
 static int
f43bc9
 virDomainVsockDefValidate(const virDomainVsockDef *vsock)
f43bc9
 {
f43bc9
@@ -6513,6 +6523,10 @@ virDomainVsockDefValidate(const virDomainVsockDef *vsock)
f43bc9
         return -1;
f43bc9
     }
f43bc9
 
f43bc9
+    if (!virDomainVsockIsVirtioModel(vsock) &&
f43bc9
+        virDomainCheckVirtioOptions(vsock->virtio) < 0)
f43bc9
+        return -1;
f43bc9
+
f43bc9
     return 0;
f43bc9
 }
f43bc9
 
397dc2
@@ -16649,6 +16663,11 @@ virDomainVsockDefParseXML(virDomainXMLOptionPtr xmlopt,
f43bc9
     if (virDomainDeviceInfoParseXML(xmlopt, node, &vsock->info, flags) < 0)
f43bc9
         return NULL;
f43bc9
 
f43bc9
+    if (virDomainVirtioOptionsParseXML(virXPathNode("./driver", ctxt),
f43bc9
+                                       &vsock->virtio) < 0)
f43bc9
+        return NULL;
f43bc9
+
f43bc9
+
f43bc9
     return g_steal_pointer(&vsock);
f43bc9
 }
f43bc9
 
397dc2
@@ -23350,6 +23369,10 @@ virDomainVsockDefCheckABIStability(virDomainVsockDefPtr src,
f43bc9
         return false;
f43bc9
     }
f43bc9
 
f43bc9
+    if (src->virtio && dst->virtio &&
f43bc9
+        !virDomainVirtioOptionsCheckABIStability(src->virtio, dst->virtio))
f43bc9
+        return false;
f43bc9
+
f43bc9
     if (!virDomainDeviceInfoCheckABIStability(&src->info, &dst->info))
f43bc9
         return false;
f43bc9
 
397dc2
@@ -28364,6 +28387,7 @@ virDomainVsockDefFormat(virBufferPtr buf,
f43bc9
     g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
f43bc9
     g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
f43bc9
     g_auto(virBuffer) cidAttrBuf = VIR_BUFFER_INITIALIZER;
f43bc9
+    g_auto(virBuffer) drvAttrBuf = VIR_BUFFER_INITIALIZER;
f43bc9
 
f43bc9
     if (vsock->model) {
f43bc9
         virBufferAsprintf(&attrBuf, " model='%s'",
397dc2
@@ -28381,6 +28405,9 @@ virDomainVsockDefFormat(virBufferPtr buf,
f43bc9
     if (virDomainDeviceInfoFormat(&childBuf, &vsock->info, 0) < 0)
f43bc9
         return -1;
f43bc9
 
f43bc9
+    virDomainVirtioOptionsFormat(&drvAttrBuf, vsock->virtio);
f43bc9
+
f43bc9
+    virXMLFormatElement(&childBuf, "driver", &drvAttrBuf, NULL);
f43bc9
     virXMLFormatElement(buf, "vsock", &attrBuf, &childBuf);
f43bc9
 
f43bc9
     return 0;
f43bc9
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
f43bc9
index 118077edaa..3aed1fb22a 100644
f43bc9
--- a/src/conf/domain_conf.h
f43bc9
+++ b/src/conf/domain_conf.h
f43bc9
@@ -2389,6 +2389,7 @@ struct _virDomainVsockDef {
f43bc9
     virTristateBool auto_cid;
f43bc9
 
f43bc9
     virDomainDeviceInfo info;
f43bc9
+    virDomainVirtioOptionsPtr virtio;
f43bc9
 };
f43bc9
 
f43bc9
 struct _virDomainVirtioOptions {
f43bc9
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
397dc2
index 67d7334b0f..998c3c90f8 100644
f43bc9
--- a/src/qemu/qemu_command.c
f43bc9
+++ b/src/qemu/qemu_command.c
397dc2
@@ -9965,6 +9965,10 @@ qemuBuildVsockDevStr(virDomainDefPtr def,
f43bc9
     virBufferAsprintf(&buf, ",id=%s", vsock->info.alias);
f43bc9
     virBufferAsprintf(&buf, ",guest-cid=%u", vsock->guest_cid);
f43bc9
     virBufferAsprintf(&buf, ",vhostfd=%s%u", fdprefix, priv->vhostfd);
f43bc9
+
f43bc9
+    if (qemuBuildVirtioOptionsStr(&buf, vsock->virtio, qemuCaps) < 0)
f43bc9
+        return NULL;
f43bc9
+
f43bc9
     if (qemuBuildDeviceAddressStr(&buf, def, &vsock->info, qemuCaps) < 0)
f43bc9
         return NULL;
f43bc9
 
f43bc9
diff --git a/tests/qemuxml2argvdata/vhost-vsock-ccw-iommu.s390x-latest.args b/tests/qemuxml2argvdata/vhost-vsock-ccw-iommu.s390x-latest.args
f43bc9
new file mode 100644
f43bc9
index 0000000000..78eede78d3
f43bc9
--- /dev/null
f43bc9
+++ b/tests/qemuxml2argvdata/vhost-vsock-ccw-iommu.s390x-latest.args
f43bc9
@@ -0,0 +1,37 @@
f43bc9
+LC_ALL=C \
f43bc9
+PATH=/bin \
f43bc9
+HOME=/tmp/lib/domain--1-QEMUGuest1 \
f43bc9
+USER=test \
f43bc9
+LOGNAME=test \
f43bc9
+XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \
f43bc9
+XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \
f43bc9
+XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
f43bc9
+QEMU_AUDIO_DRV=none \
f43bc9
+/usr/bin/qemu-system-s390x \
f43bc9
+-name guest=QEMUGuest1,debug-threads=on \
f43bc9
+-S \
f43bc9
+-object secret,id=masterKey0,format=raw,\
f43bc9
+file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \
f43bc9
+-machine s390-ccw-virtio,accel=tcg,usb=off,dump-guest-core=off \
f43bc9
+-cpu qemu \
f43bc9
+-m 214 \
f43bc9
+-overcommit mem-lock=off \
f43bc9
+-smp 1,sockets=1,cores=1,threads=1 \
f43bc9
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
f43bc9
+-display none \
f43bc9
+-no-user-config \
f43bc9
+-nodefaults \
f43bc9
+-chardev socket,id=charmonitor,fd=1729,server,nowait \
f43bc9
+-mon chardev=charmonitor,id=monitor,mode=control \
f43bc9
+-rtc base=utc \
f43bc9
+-no-shutdown \
f43bc9
+-boot strict=on \
f43bc9
+-drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-virtio-disk0 \
f43bc9
+-device virtio-blk-ccw,scsi=off,devno=fe.0.0000,drive=drive-virtio-disk0,\
f43bc9
+id=virtio-disk0,bootindex=1 \
f43bc9
+-device virtio-balloon-ccw,id=balloon0,devno=fe.0.0001 \
f43bc9
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
f43bc9
+resourcecontrol=deny \
f43bc9
+-device vhost-vsock-ccw,id=vsock0,guest-cid=4,vhostfd=6789,iommu_platform=on,\
f43bc9
+devno=fe.0.0002 \
f43bc9
+-msg timestamp=on
f43bc9
diff --git a/tests/qemuxml2argvdata/vhost-vsock-ccw-iommu.xml b/tests/qemuxml2argvdata/vhost-vsock-ccw-iommu.xml
f43bc9
new file mode 100644
f43bc9
index 0000000000..dbfe082a6f
f43bc9
--- /dev/null
f43bc9
+++ b/tests/qemuxml2argvdata/vhost-vsock-ccw-iommu.xml
f43bc9
@@ -0,0 +1,37 @@
f43bc9
+<domain type='qemu'>
f43bc9
+  <name>QEMUGuest1</name>
f43bc9
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
f43bc9
+  <memory unit='KiB'>219136</memory>
f43bc9
+  <currentMemory unit='KiB'>219136</currentMemory>
f43bc9
+  <vcpu placement='static'>1</vcpu>
f43bc9
+  <os>
f43bc9
+    <type arch='s390x' machine='s390-ccw-virtio'>hvm</type>
f43bc9
+    <boot dev='hd'/>
f43bc9
+  </os>
f43bc9
+  <cpu mode='custom' match='exact' check='none'>
f43bc9
+    <model fallback='forbid'>qemu</model>
f43bc9
+  </cpu>
f43bc9
+  <clock offset='utc'/>
f43bc9
+  <on_poweroff>destroy</on_poweroff>
f43bc9
+  <on_reboot>restart</on_reboot>
f43bc9
+  <on_crash>destroy</on_crash>
f43bc9
+  <devices>
f43bc9
+    <emulator>/usr/bin/qemu-system-s390x</emulator>
f43bc9
+    <disk type='block' device='disk'>
f43bc9
+      <driver name='qemu' type='raw'/>
f43bc9
+      <source dev='/dev/HostVG/QEMUGuest1'/>
f43bc9
+      <target dev='hda' bus='virtio'/>
f43bc9
+      <address type='ccw' cssid='0xfe' ssid='0x0' devno='0x0000'/>
f43bc9
+    </disk>
f43bc9
+    <controller type='pci' index='0' model='pci-root'/>
f43bc9
+    <memballoon model='virtio'>
f43bc9
+      <address type='ccw' cssid='0xfe' ssid='0x0' devno='0x0001'/>
f43bc9
+    </memballoon>
f43bc9
+    <panic model='s390'/>
f43bc9
+    <vsock model='virtio'>
f43bc9
+      <cid auto='no' address='4'/>
f43bc9
+      <address type='ccw' cssid='0xfe' ssid='0x0' devno='0x0002'/>
f43bc9
+      <driver iommu='on'/>
f43bc9
+    </vsock>
f43bc9
+  </devices>
f43bc9
+</domain>
f43bc9
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
397dc2
index 629f5ac100..a22e3ba157 100644
f43bc9
--- a/tests/qemuxml2argvtest.c
f43bc9
+++ b/tests/qemuxml2argvtest.c
397dc2
@@ -3056,6 +3056,7 @@ mymain(void)
f43bc9
     DO_TEST_CAPS_LATEST("vhost-vsock-auto");
f43bc9
     DO_TEST_CAPS_ARCH_LATEST("vhost-vsock-ccw", "s390x");
f43bc9
     DO_TEST_CAPS_ARCH_LATEST("vhost-vsock-ccw-auto", "s390x");
f43bc9
+    DO_TEST_CAPS_ARCH_LATEST("vhost-vsock-ccw-iommu", "s390x");
f43bc9
 
f43bc9
     DO_TEST_CAPS_VER("launch-security-sev", "2.12.0");
f43bc9
 
f43bc9
diff --git a/tests/qemuxml2xmloutdata/vhost-vsock-ccw-iommu.s390x-latest.xml b/tests/qemuxml2xmloutdata/vhost-vsock-ccw-iommu.s390x-latest.xml
f43bc9
new file mode 120000
f43bc9
index 0000000000..78971a8ef9
f43bc9
--- /dev/null
f43bc9
+++ b/tests/qemuxml2xmloutdata/vhost-vsock-ccw-iommu.s390x-latest.xml
f43bc9
@@ -0,0 +1 @@
f43bc9
+../qemuxml2argvdata/vhost-vsock-ccw-iommu.xml
f43bc9
\ No newline at end of file
f43bc9
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
397dc2
index 60efcac6c8..461b5bc68f 100644
f43bc9
--- a/tests/qemuxml2xmltest.c
f43bc9
+++ b/tests/qemuxml2xmltest.c
397dc2
@@ -1433,6 +1433,8 @@ mymain(void)
f43bc9
             QEMU_CAPS_CCW);
f43bc9
     DO_TEST("vhost-vsock-ccw-auto", QEMU_CAPS_DEVICE_VHOST_VSOCK,
f43bc9
             QEMU_CAPS_CCW);
f43bc9
+    DO_TEST_CAPS_ARCH_LATEST("vhost-vsock-ccw-iommu", "s390x");
f43bc9
+
f43bc9
 
f43bc9
     DO_TEST_CAPS_LATEST("vhost-user-fs-fd-memory");
f43bc9
     DO_TEST_CAPS_LATEST("vhost-user-fs-hugepages");
f43bc9
-- 
397dc2
2.30.0
f43bc9