]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Add virtio related options to vsock
authorBoris Fiuczynski <fiuczy@linux.ibm.com>
Wed, 27 Jan 2021 18:46:59 +0000 (19:46 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 29 Jan 2021 11:25:49 +0000 (12:25 +0100)
Add virtio related options iommu, ats and packed as driver element attributes
to vsock devices. Ex:

 <vsock model='virtio'>
   <cid auto='no' address='3'/>
   <driver iommu='on'/>
 </vsock>

Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
12 files changed:
docs/formatdomain.rst
docs/schemas/domaincommon.rng
src/conf/domain_conf.c
src/conf/domain_conf.h
src/conf/domain_validate.c
src/qemu/qemu_command.c
src/qemu/qemu_validate.c
tests/qemuxml2argvdata/vhost-vsock-ccw-iommu.s390x-latest.args [new file with mode: 0644]
tests/qemuxml2argvdata/vhost-vsock-ccw-iommu.xml [new file with mode: 0644]
tests/qemuxml2argvtest.c
tests/qemuxml2xmloutdata/vhost-vsock-ccw-iommu.s390x-latest.xml [new symlink]
tests/qemuxml2xmltest.c

index c738078b90db1917c19d06ded788c472f2d7dbac..a09868bed5ee66834be5de0634cd7872f9678ef2 100644 (file)
@@ -7433,6 +7433,8 @@ devices <#elementsVirtioTransitional>`__ for more details. The optional
 attribute ``address`` of the ``cid`` element specifies the CID assigned to the
 guest. If the attribute ``auto`` is set to ``yes``, libvirt will assign a free
 CID automatically on domain startup. :since:`Since 4.4.0`
+The optional ``driver`` element allows to specify virtio options, see
+`Virtio-specific options <#elementsVirtio>`__  for more details. :since:`Since 7.1.0`
 
 ::
 
index a4bddcf1326784017851a2e37cb74101a95c5ed5..232587e69005a59cdc16ff47f69afe27d0d2e436 100644 (file)
         <optional>
           <ref name="alias"/>
         </optional>
+        <optional>
+          <element name="driver">
+            <ref name="virtioOptions"/>
+          </element>
+        </optional>
       </interleave>
     </element>
   </define>
index 905f8f0691f3e11a16e20727806d82b8fa831392..25f405625be49235558ac502239cd9be1fe4bae1 100644 (file)
@@ -2457,6 +2457,7 @@ virDomainVsockDefFree(virDomainVsockDefPtr vsock)
 
     virObjectUnref(vsock->privateData);
     virDomainDeviceInfoClear(&vsock->info);
+    VIR_FREE(vsock->virtio);
     VIR_FREE(vsock);
 }
 
@@ -15663,6 +15664,11 @@ virDomainVsockDefParseXML(virDomainXMLOptionPtr xmlopt,
     if (virDomainDeviceInfoParseXML(xmlopt, node, &vsock->info, flags) < 0)
         return NULL;
 
+    if (virDomainVirtioOptionsParseXML(virXPathNode("./driver", ctxt),
+                                       &vsock->virtio) < 0)
+        return NULL;
+
+
     return g_steal_pointer(&vsock);
 }
 
@@ -22850,6 +22856,9 @@ virDomainVsockDefCheckABIStability(virDomainVsockDefPtr src,
         return false;
     }
 
+    if (!virDomainVirtioOptionsCheckABIStability(src->virtio, dst->virtio))
+        return false;
+
     if (!virDomainDeviceInfoCheckABIStability(&src->info, &dst->info))
         return false;
 
@@ -28040,6 +28049,7 @@ virDomainVsockDefFormat(virBufferPtr buf,
     g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
     g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
     g_auto(virBuffer) cidAttrBuf = VIR_BUFFER_INITIALIZER;
+    g_auto(virBuffer) drvAttrBuf = VIR_BUFFER_INITIALIZER;
 
     if (vsock->model) {
         virBufferAsprintf(&attrBuf, " model='%s'",
@@ -28056,6 +28066,9 @@ virDomainVsockDefFormat(virBufferPtr buf,
 
     virDomainDeviceInfoFormat(&childBuf, &vsock->info, 0);
 
+    virDomainVirtioOptionsFormat(&drvAttrBuf, vsock->virtio);
+
+    virXMLFormatElement(&childBuf, "driver", &drvAttrBuf, NULL);
     virXMLFormatElement(buf, "vsock", &attrBuf, &childBuf);
 }
 
index 95ad052891bc9bca1f0d3d1abaf4cf0250c36725..0a5d151150731aaad8c7b53a316629cc445ed4cd 100644 (file)
@@ -2543,6 +2543,7 @@ struct _virDomainVsockDef {
     virTristateBool auto_cid;
 
     virDomainDeviceInfo info;
+    virDomainVirtioOptionsPtr virtio;
 };
 
 struct _virDomainVirtioOptions {
index 37c09ff648a76f198353342bba97eb0bc6e87942..dd4c6e0fb318ece4daba02bcc8649df2e2f12c75 100644 (file)
@@ -1494,6 +1494,15 @@ virDomainMemoryDefValidate(const virDomainMemoryDef *mem,
 }
 
 
+static bool
+virDomainVsockIsVirtioModel(const virDomainVsockDef *vsock)
+{
+    return (vsock->model == VIR_DOMAIN_VSOCK_MODEL_VIRTIO ||
+            vsock->model == VIR_DOMAIN_VSOCK_MODEL_VIRTIO_TRANSITIONAL ||
+            vsock->model == VIR_DOMAIN_VSOCK_MODEL_VIRTIO_NON_TRANSITIONAL);
+}
+
+
 static int
 virDomainVsockDefValidate(const virDomainVsockDef *vsock)
 {
@@ -1503,6 +1512,10 @@ virDomainVsockDefValidate(const virDomainVsockDef *vsock)
         return -1;
     }
 
+    if (!virDomainVsockIsVirtioModel(vsock) &&
+        virDomainCheckVirtioOptions(vsock->virtio) < 0)
+        return -1;
+
     return 0;
 }
 
index 1ec302d4ac5e8d955437aa5dfa1f7711f179dcdd..4986ca8b084e2064540799e3fd80da64db249506 100644 (file)
@@ -9733,6 +9733,9 @@ qemuBuildVsockDevStr(virDomainDefPtr def,
     virBufferAsprintf(&buf, ",id=%s", vsock->info.alias);
     virBufferAsprintf(&buf, ",guest-cid=%u", vsock->guest_cid);
     virBufferAsprintf(&buf, ",vhostfd=%s%u", fdprefix, priv->vhostfd);
+
+    qemuBuildVirtioOptionsStr(&buf, vsock->virtio);
+
     if (qemuBuildDeviceAddressStr(&buf, def, &vsock->info, qemuCaps) < 0)
         return NULL;
 
index a060bd98baf35732636b99b9f8ef00adfb482ad6..cb9311cb9c0c7d253657928f86e9e62eaca92627 100644 (file)
@@ -4200,6 +4200,9 @@ qemuValidateDomainDeviceDefVsock(const virDomainVsockDef *vsock,
                                               "vsock"))
         return -1;
 
+    if (qemuValidateDomainVirtioOptions(vsock->virtio, qemuCaps) < 0)
+        return -1;
+
     return 0;
 }
 
diff --git a/tests/qemuxml2argvdata/vhost-vsock-ccw-iommu.s390x-latest.args b/tests/qemuxml2argvdata/vhost-vsock-ccw-iommu.s390x-latest.args
new file mode 100644 (file)
index 0000000..aed32ee
--- /dev/null
@@ -0,0 +1,42 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-QEMUGuest1 \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-system-s390x \
+-name guest=QEMUGuest1,debug-threads=on \
+-S \
+-object secret,id=masterKey0,format=raw,\
+file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \
+-machine s390-ccw-virtio,accel=tcg,usb=off,dump-guest-core=off,\
+memory-backend=s390.ram \
+-cpu qemu \
+-m 214 \
+-object memory-backend-ram,id=s390.ram,size=224395264 \
+-overcommit mem-lock=off \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,fd=1729,server,nowait \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-boot strict=on \
+-blockdev '{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest1",\
+"node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \
+-blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw",\
+"file":"libvirt-1-storage"}' \
+-device virtio-blk-ccw,devno=fe.0.0000,drive=libvirt-1-format,id=virtio-disk0,\
+bootindex=1 \
+-device virtio-balloon-ccw,id=balloon0,devno=fe.0.0001 \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
+resourcecontrol=deny \
+-device vhost-vsock-ccw,id=vsock0,guest-cid=4,vhostfd=6789,iommu_platform=on,\
+devno=fe.0.0002 \
+-msg timestamp=on
diff --git a/tests/qemuxml2argvdata/vhost-vsock-ccw-iommu.xml b/tests/qemuxml2argvdata/vhost-vsock-ccw-iommu.xml
new file mode 100644 (file)
index 0000000..dbfe082
--- /dev/null
@@ -0,0 +1,37 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='s390x' machine='s390-ccw-virtio'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <cpu mode='custom' match='exact' check='none'>
+    <model fallback='forbid'>qemu</model>
+  </cpu>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu-system-s390x</emulator>
+    <disk type='block' device='disk'>
+      <driver name='qemu' type='raw'/>
+      <source dev='/dev/HostVG/QEMUGuest1'/>
+      <target dev='hda' bus='virtio'/>
+      <address type='ccw' cssid='0xfe' ssid='0x0' devno='0x0000'/>
+    </disk>
+    <controller type='pci' index='0' model='pci-root'/>
+    <memballoon model='virtio'>
+      <address type='ccw' cssid='0xfe' ssid='0x0' devno='0x0001'/>
+    </memballoon>
+    <panic model='s390'/>
+    <vsock model='virtio'>
+      <cid auto='no' address='4'/>
+      <address type='ccw' cssid='0xfe' ssid='0x0' devno='0x0002'/>
+      <driver iommu='on'/>
+    </vsock>
+  </devices>
+</domain>
index cf77224fc37c215263f16529c893edcd2abfd777..c5d82ac72e9c07eed471294ede297713231adfef 100644 (file)
@@ -3400,6 +3400,7 @@ mymain(void)
     DO_TEST_CAPS_LATEST("vhost-vsock-auto");
     DO_TEST_CAPS_ARCH_LATEST("vhost-vsock-ccw", "s390x");
     DO_TEST_CAPS_ARCH_LATEST("vhost-vsock-ccw-auto", "s390x");
+    DO_TEST_CAPS_ARCH_LATEST("vhost-vsock-ccw-iommu", "s390x");
 
     DO_TEST_CAPS_VER("launch-security-sev", "2.12.0");
     DO_TEST_CAPS_VER("launch-security-sev-missing-platform-info", "2.12.0");
diff --git a/tests/qemuxml2xmloutdata/vhost-vsock-ccw-iommu.s390x-latest.xml b/tests/qemuxml2xmloutdata/vhost-vsock-ccw-iommu.s390x-latest.xml
new file mode 120000 (symlink)
index 0000000..78971a8
--- /dev/null
@@ -0,0 +1 @@
+../qemuxml2argvdata/vhost-vsock-ccw-iommu.xml
\ No newline at end of file
index 9553a8a4f858645bcf2bbb6b846e7723e371381f..50dd9707893d42bd996c9b7dacf4d6637b235b19 100644 (file)
@@ -1403,6 +1403,8 @@ mymain(void)
             QEMU_CAPS_CCW);
     DO_TEST("vhost-vsock-ccw-auto", QEMU_CAPS_DEVICE_VHOST_VSOCK,
             QEMU_CAPS_CCW);
+    DO_TEST_CAPS_ARCH_LATEST("vhost-vsock-ccw-iommu", "s390x");
+
 
     DO_TEST_CAPS_LATEST("vhost-user-fs-fd-memory");
     DO_TEST_CAPS_LATEST("vhost-user-fs-hugepages");