6ae9ed
From bf9cd171c0979ae6a2eee0bee7841c23c69a1f42 Mon Sep 17 00:00:00 2001
6ae9ed
Message-Id: <bf9cd171c0979ae6a2eee0bee7841c23c69a1f42@dist-git>
6ae9ed
From: Michal Privoznik <mprivozn@redhat.com>
6ae9ed
Date: Sat, 10 Sep 2016 08:25:09 +0200
6ae9ed
Subject: [PATCH] conf: Add support for virtio-net.rx_queue_size
6ae9ed
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1366989
6ae9ed
6ae9ed
QEMU added another virtio-net tunable [1]. It basically allows
6ae9ed
users to set the size of RX virtio ring. But because virtio-net
6ae9ed
uses two separate ring buffers to pass data from/to guest they
6ae9ed
named it explicitly rx_queue_size. We should expose it in our XML
6ae9ed
too.
6ae9ed
6ae9ed
1: http://lists.nongnu.org/archive/html/qemu-devel/2016-08/msg02029.html
6ae9ed
6ae9ed
Conflicts: tests/qemuxml2xmltest.c - there are more tests in
6ae9ed
upstream.
6ae9ed
6ae9ed
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6ae9ed
(cherry picked from commit c56cdf25935e0e7fe6b0e803d62fec223b9a0df2)
6ae9ed
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6ae9ed
---
6ae9ed
 docs/formatdomain.html.in                          | 16 ++++++++-
6ae9ed
 docs/schemas/domaincommon.rng                      |  5 +++
6ae9ed
 src/conf/domain_conf.c                             | 16 +++++++++
6ae9ed
 src/conf/domain_conf.h                             |  1 +
6ae9ed
 src/qemu/qemu_domain.c                             |  7 ++++
6ae9ed
 ...ml2argv-net-virtio-rxqueuesize-invalid-size.xml | 29 +++++++++++++++
6ae9ed
 .../qemuxml2argv-net-virtio-rxqueuesize.xml        | 29 +++++++++++++++
6ae9ed
 tests/qemuxml2argvtest.c                           |  1 +
6ae9ed
 .../qemuxml2xmlout-net-virtio-rxqueuesize.xml      | 41 ++++++++++++++++++++++
6ae9ed
 tests/qemuxml2xmltest.c                            |  1 +
6ae9ed
 10 files changed, 145 insertions(+), 1 deletion(-)
6ae9ed
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-net-virtio-rxqueuesize-invalid-size.xml
6ae9ed
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-net-virtio-rxqueuesize.xml
6ae9ed
 create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-net-virtio-rxqueuesize.xml
6ae9ed
6ae9ed
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
6ae9ed
index 5b4f83e..4970d61 100644
6ae9ed
--- a/docs/formatdomain.html.in
6ae9ed
+++ b/docs/formatdomain.html.in
6ae9ed
@@ -4648,7 +4648,7 @@ qemu-kvm -net nic,model=? /dev/null
6ae9ed
       <source network='default'/>
6ae9ed
       <target dev='vnet1'/>
6ae9ed
       <model type='virtio'/>
6ae9ed
-      <driver name='vhost' txmode='iothread' ioeventfd='on' event_idx='off' queues='5'>
6ae9ed
+      <driver name='vhost' txmode='iothread' ioeventfd='on' event_idx='off' queues='5' rx_queue_size='256'>
6ae9ed
         <host csum='off' gso='off' tso4='off' tso6='off' ecn='off' ufo='off' mrg_rxbuf='off'/>
6ae9ed
         <guest csum='off' tso4='off' tso6='off' ecn='off' ufo='off'/>
6ae9ed
       </driver>
6ae9ed
@@ -4764,6 +4764,20 @@ qemu-kvm -net nic,model=? /dev/null
6ae9ed
         virtio-net since 1.0.6 (QEMU and KVM only)
6ae9ed
         vhost-user since 1.2.17 (QEMU and KVM only)
6ae9ed
       
6ae9ed
+      
rx_queue_size
6ae9ed
+      
6ae9ed
+        The optional rx_queue_size attribute controls
6ae9ed
+        the size of virtio ring for each queue as described above.
6ae9ed
+        The default value is hypervisor dependent and may change
6ae9ed
+        across its releases. Moreover, some hypervisors may pose
6ae9ed
+        some restrictions on actual value. For instance, latest
6ae9ed
+        QEMU (as of 2016-09-01) requires value to be a power of two
6ae9ed
+        from [256, 1024] range.
6ae9ed
+        Since 2.3.0 (QEMU and KVM only)

6ae9ed
+
6ae9ed
+        In general you should leave this option alone, unless you
6ae9ed
+        are very certain you know what you are doing.
6ae9ed
+      
6ae9ed
     
6ae9ed
     

6ae9ed
       Offloading options for the host and guest can be configured using
6ae9ed
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
6ae9ed
index 44e39c8..6935b0d 100644
6ae9ed
--- a/docs/schemas/domaincommon.rng
6ae9ed
+++ b/docs/schemas/domaincommon.rng
6ae9ed
@@ -2530,6 +2530,11 @@
6ae9ed
                 </attribute>
6ae9ed
               </optional>
6ae9ed
               <optional>
6ae9ed
+                <attribute name='rx_queue_size'>
6ae9ed
+                  <ref name='positiveInteger'/>
6ae9ed
+                </attribute>
6ae9ed
+              </optional>
6ae9ed
+              <optional>
6ae9ed
                 <attribute name="txmode">
6ae9ed
                   <choice>
6ae9ed
                     <value>iothread</value>
6ae9ed
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
6ae9ed
index edf5de2..caa9ce0 100644
6ae9ed
--- a/src/conf/domain_conf.c
6ae9ed
+++ b/src/conf/domain_conf.c
6ae9ed
@@ -9059,6 +9059,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
6ae9ed
     char *ioeventfd = NULL;
6ae9ed
     char *event_idx = NULL;
6ae9ed
     char *queues = NULL;
6ae9ed
+    char *rx_queue_size = NULL;
6ae9ed
     char *str = NULL;
6ae9ed
     char *filter = NULL;
6ae9ed
     char *internal = NULL;
6ae9ed
@@ -9222,6 +9223,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
6ae9ed
                 ioeventfd = virXMLPropString(cur, "ioeventfd");
6ae9ed
                 event_idx = virXMLPropString(cur, "event_idx");
6ae9ed
                 queues = virXMLPropString(cur, "queues");
6ae9ed
+                rx_queue_size = virXMLPropString(cur, "rx_queue_size");
6ae9ed
             } else if (xmlStrEqual(cur->name, BAD_CAST "filterref")) {
6ae9ed
                 if (filter) {
6ae9ed
                     virReportError(VIR_ERR_XML_ERROR, "%s",
6ae9ed
@@ -9605,6 +9607,16 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
6ae9ed
             if (q > 1)
6ae9ed
                 def->driver.virtio.queues = q;
6ae9ed
         }
6ae9ed
+        if (rx_queue_size) {
6ae9ed
+            unsigned int q;
6ae9ed
+            if (virStrToLong_uip(rx_queue_size, NULL, 10, &q) < 0) {
6ae9ed
+                virReportError(VIR_ERR_XML_DETAIL,
6ae9ed
+                               _("'rx_queue_size' attribute must be positive number: %s"),
6ae9ed
+                               rx_queue_size);
6ae9ed
+                goto error;
6ae9ed
+            }
6ae9ed
+            def->driver.virtio.rx_queue_size = q;
6ae9ed
+        }
6ae9ed
         if ((str = virXPathString("string(./driver/host/@csum)", ctxt))) {
6ae9ed
             if ((val = virTristateSwitchTypeFromString(str)) <= 0) {
6ae9ed
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
6ae9ed
@@ -9785,6 +9797,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
6ae9ed
     VIR_FREE(ioeventfd);
6ae9ed
     VIR_FREE(event_idx);
6ae9ed
     VIR_FREE(queues);
6ae9ed
+    VIR_FREE(rx_queue_size);
6ae9ed
     VIR_FREE(str);
6ae9ed
     VIR_FREE(filter);
6ae9ed
     VIR_FREE(type);
6ae9ed
@@ -20964,6 +20977,9 @@ virDomainVirtioNetDriverFormat(char **outstr,
6ae9ed
     }
6ae9ed
     if (def->driver.virtio.queues)
6ae9ed
         virBufferAsprintf(&buf, "queues='%u' ", def->driver.virtio.queues);
6ae9ed
+    if (def->driver.virtio.rx_queue_size)
6ae9ed
+        virBufferAsprintf(&buf, "rx_queue_size='%u' ",
6ae9ed
+                          def->driver.virtio.rx_queue_size);
6ae9ed
 
6ae9ed
     virBufferTrim(&buf, " ", -1);
6ae9ed
 
6ae9ed
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
6ae9ed
index 305ae96..c674796 100644
6ae9ed
--- a/src/conf/domain_conf.h
6ae9ed
+++ b/src/conf/domain_conf.h
6ae9ed
@@ -903,6 +903,7 @@ struct _virDomainNetDef {
6ae9ed
             virTristateSwitch ioeventfd;
6ae9ed
             virTristateSwitch event_idx;
6ae9ed
             unsigned int queues; /* Multiqueue virtio-net */
6ae9ed
+            unsigned int rx_queue_size;
6ae9ed
             struct {
6ae9ed
                 virTristateSwitch csum;
6ae9ed
                 virTristateSwitch gso;
6ae9ed
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
6ae9ed
index 989baa5..f001c6e 100644
6ae9ed
--- a/src/qemu/qemu_domain.c
6ae9ed
+++ b/src/qemu/qemu_domain.c
6ae9ed
@@ -2469,6 +2469,13 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
6ae9ed
                              "not supported by QEMU"));
6ae9ed
             goto cleanup;
6ae9ed
         }
6ae9ed
+
6ae9ed
+        if (STREQ_NULLABLE(net->model, "virtio") &&
6ae9ed
+            net->driver.virtio.rx_queue_size & (net->driver.virtio.rx_queue_size - 1)) {
6ae9ed
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
6ae9ed
+                           _("rx_queue_size has to be a power of two"));
6ae9ed
+            goto cleanup;
6ae9ed
+        }
6ae9ed
     }
6ae9ed
 
6ae9ed
     ret = 0;
6ae9ed
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-rxqueuesize-invalid-size.xml b/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-rxqueuesize-invalid-size.xml
6ae9ed
new file mode 100644
6ae9ed
index 0000000..d308bc1
6ae9ed
--- /dev/null
6ae9ed
+++ b/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-rxqueuesize-invalid-size.xml
6ae9ed
@@ -0,0 +1,29 @@
6ae9ed
+<domain type='qemu'>
6ae9ed
+  <name>QEMUGuest1</name>
6ae9ed
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
6ae9ed
+  <memory unit='KiB'>219100</memory>
6ae9ed
+  <currentMemory unit='KiB'>219100</currentMemory>
6ae9ed
+  <vcpu placement='static'>1</vcpu>
6ae9ed
+  <os>
6ae9ed
+    <type arch='i686' machine='pc'>hvm</type>
6ae9ed
+    <boot dev='hd'/>
6ae9ed
+  </os>
6ae9ed
+  <clock offset='utc'/>
6ae9ed
+  <on_poweroff>destroy</on_poweroff>
6ae9ed
+  <on_reboot>restart</on_reboot>
6ae9ed
+  <on_crash>destroy</on_crash>
6ae9ed
+  <devices>
6ae9ed
+    <emulator>/usr/bin/qemu</emulator>
6ae9ed
+    <disk type='block' device='disk'>
6ae9ed
+      <source dev='/dev/HostVG/QEMUGuest1'/>
6ae9ed
+      <target dev='hda' bus='ide'/>
6ae9ed
+    </disk>
6ae9ed
+    <controller type='usb' index='0'/>
6ae9ed
+    <interface type='user'>
6ae9ed
+      <mac address='00:11:22:33:44:55'/>
6ae9ed
+      <model type='virtio'/>
6ae9ed
+      <driver rx_queue_size='511'/>
6ae9ed
+    </interface>
6ae9ed
+    <memballoon model='virtio'/>
6ae9ed
+  </devices>
6ae9ed
+</domain>
6ae9ed
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-rxqueuesize.xml b/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-rxqueuesize.xml
6ae9ed
new file mode 100644
6ae9ed
index 0000000..cfb4742
6ae9ed
--- /dev/null
6ae9ed
+++ b/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-rxqueuesize.xml
6ae9ed
@@ -0,0 +1,29 @@
6ae9ed
+<domain type='qemu'>
6ae9ed
+  <name>QEMUGuest1</name>
6ae9ed
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
6ae9ed
+  <memory unit='KiB'>219100</memory>
6ae9ed
+  <currentMemory unit='KiB'>219100</currentMemory>
6ae9ed
+  <vcpu placement='static'>1</vcpu>
6ae9ed
+  <os>
6ae9ed
+    <type arch='i686' machine='pc'>hvm</type>
6ae9ed
+    <boot dev='hd'/>
6ae9ed
+  </os>
6ae9ed
+  <clock offset='utc'/>
6ae9ed
+  <on_poweroff>destroy</on_poweroff>
6ae9ed
+  <on_reboot>restart</on_reboot>
6ae9ed
+  <on_crash>destroy</on_crash>
6ae9ed
+  <devices>
6ae9ed
+    <emulator>/usr/bin/qemu</emulator>
6ae9ed
+    <disk type='block' device='disk'>
6ae9ed
+      <source dev='/dev/HostVG/QEMUGuest1'/>
6ae9ed
+      <target dev='hda' bus='ide'/>
6ae9ed
+    </disk>
6ae9ed
+    <controller type='usb' index='0'/>
6ae9ed
+    <interface type='user'>
6ae9ed
+      <mac address='00:11:22:33:44:55'/>
6ae9ed
+      <model type='virtio'/>
6ae9ed
+      <driver rx_queue_size='512'/>
6ae9ed
+    </interface>
6ae9ed
+    <memballoon model='virtio'/>
6ae9ed
+  </devices>
6ae9ed
+</domain>
6ae9ed
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
6ae9ed
index 9de2f94..f4054e7 100644
6ae9ed
--- a/tests/qemuxml2argvtest.c
6ae9ed
+++ b/tests/qemuxml2argvtest.c
6ae9ed
@@ -1040,6 +1040,7 @@ mymain(void)
6ae9ed
             QEMU_CAPS_VIRTIO_S390);
6ae9ed
     DO_TEST("net-virtio-ccw",
6ae9ed
             QEMU_CAPS_VIRTIO_CCW, QEMU_CAPS_VIRTIO_S390);
6ae9ed
+    DO_TEST_PARSE_ERROR("net-virtio-rxqueuesize-invalid-size", NONE);
6ae9ed
     DO_TEST("net-eth", NONE);
6ae9ed
     DO_TEST("net-eth-ifname", NONE);
6ae9ed
     DO_TEST("net-eth-names", NONE);
6ae9ed
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-net-virtio-rxqueuesize.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-net-virtio-rxqueuesize.xml
6ae9ed
new file mode 100644
6ae9ed
index 0000000..5b41936
6ae9ed
--- /dev/null
6ae9ed
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-net-virtio-rxqueuesize.xml
6ae9ed
@@ -0,0 +1,41 @@
6ae9ed
+<domain type='qemu'>
6ae9ed
+  <name>QEMUGuest1</name>
6ae9ed
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
6ae9ed
+  <memory unit='KiB'>219100</memory>
6ae9ed
+  <currentMemory unit='KiB'>219100</currentMemory>
6ae9ed
+  <vcpu placement='static'>1</vcpu>
6ae9ed
+  <os>
6ae9ed
+    <type arch='i686' machine='pc'>hvm</type>
6ae9ed
+    <boot dev='hd'/>
6ae9ed
+  </os>
6ae9ed
+  <clock offset='utc'/>
6ae9ed
+  <on_poweroff>destroy</on_poweroff>
6ae9ed
+  <on_reboot>restart</on_reboot>
6ae9ed
+  <on_crash>destroy</on_crash>
6ae9ed
+  <devices>
6ae9ed
+    <emulator>/usr/bin/qemu</emulator>
6ae9ed
+    <disk type='block' device='disk'>
6ae9ed
+      <source dev='/dev/HostVG/QEMUGuest1'/>
6ae9ed
+      <target dev='hda' bus='ide'/>
6ae9ed
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
6ae9ed
+    </disk>
6ae9ed
+    <controller type='usb' index='0'>
6ae9ed
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
6ae9ed
+    </controller>
6ae9ed
+    <controller type='pci' index='0' model='pci-root'/>
6ae9ed
+    <controller type='ide' index='0'>
6ae9ed
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
6ae9ed
+    </controller>
6ae9ed
+    <interface type='user'>
6ae9ed
+      <mac address='00:11:22:33:44:55'/>
6ae9ed
+      <model type='virtio'/>
6ae9ed
+      <driver rx_queue_size='512'/>
6ae9ed
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
6ae9ed
+    </interface>
6ae9ed
+    <input type='mouse' bus='ps2'/>
6ae9ed
+    <input type='keyboard' bus='ps2'/>
6ae9ed
+    <memballoon model='virtio'>
6ae9ed
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
6ae9ed
+    </memballoon>
6ae9ed
+  </devices>
6ae9ed
+</domain>
6ae9ed
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
6ae9ed
index 639494b..5458361 100644
6ae9ed
--- a/tests/qemuxml2xmltest.c
6ae9ed
+++ b/tests/qemuxml2xmltest.c
6ae9ed
@@ -518,6 +518,7 @@ mymain(void)
6ae9ed
     DO_TEST("net-eth");
6ae9ed
     DO_TEST("net-eth-ifname");
6ae9ed
     DO_TEST("net-virtio-network-portgroup");
6ae9ed
+    DO_TEST("net-virtio-rxqueuesize");
6ae9ed
     DO_TEST("net-hostdev");
6ae9ed
     DO_TEST("net-hostdev-vfio");
6ae9ed
     DO_TEST("net-midonet");
6ae9ed
-- 
6ae9ed
2.10.0
6ae9ed