33234a
From 9b3184784e1243a81a4b8de350fb0434a1ad1f28 Mon Sep 17 00:00:00 2001
33234a
Message-Id: <9b3184784e1243a81a4b8de350fb0434a1ad1f28@dist-git>
33234a
From: Michal Privoznik <mprivozn@redhat.com>
33234a
Date: Fri, 18 Aug 2017 09:35:54 +0200
33234a
Subject: [PATCH] Add support for virtio-net.tx_queue_size
33234a
33234a
RHEL-7.5:   https://bugzilla.redhat.com/show_bug.cgi?id=1462653
33234a
RHEL-7.4.z: https://bugzilla.redhat.com/show_bug.cgi?id=1482514
33234a
33234a
Just like I've added support for setting rx_queue_size (in
33234a
c56cdf259 and friends), qemu just gained support for setting tx
33234a
ring size.
33234a
33234a
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
33234a
(cherry picked from commit 2074ef6cd4a2e033813ec091487d027a85f73509)
33234a
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
33234a
33234a
Conflicts:
33234a
      src/qemu/qemu_capabilities.c:
33234a
      src/qemu/qemu_capabilities.h: Context because of some caps
33234a
                                    missing
33234a
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
33234a
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
33234a
---
33234a
 docs/formatdomain.html.in                                | 15 ++++++++++++++-
33234a
 docs/schemas/domaincommon.rng                            |  5 +++++
33234a
 src/conf/domain_conf.c                                   | 16 ++++++++++++++++
33234a
 src/conf/domain_conf.h                                   |  1 +
33234a
 src/qemu/qemu_capabilities.c                             |  2 ++
33234a
 src/qemu/qemu_capabilities.h                             |  1 +
33234a
 src/qemu/qemu_command.c                                  |  8 ++++++++
33234a
 src/qemu/qemu_domain.c                                   | 16 +++++++++++-----
33234a
 ...e.args => qemuxml2argv-net-virtio-rxtxqueuesize.args} |  4 ++--
33234a
 ...ize.xml => qemuxml2argv-net-virtio-rxtxqueuesize.xml} |  2 +-
33234a
 tests/qemuxml2argvtest.c                                 |  5 +++--
33234a
 ...e.xml => qemuxml2xmlout-net-virtio-rxtxqueuesize.xml} |  2 +-
33234a
 tests/qemuxml2xmltest.c                                  |  2 +-
33234a
 13 files changed, 66 insertions(+), 13 deletions(-)
33234a
 rename tests/qemuxml2argvdata/{qemuxml2argv-net-virtio-rxqueuesize.args => qemuxml2argv-net-virtio-rxtxqueuesize.args} (83%)
33234a
 rename tests/qemuxml2argvdata/{qemuxml2argv-net-virtio-rxqueuesize.xml => qemuxml2argv-net-virtio-rxtxqueuesize.xml} (93%)
33234a
 rename tests/qemuxml2xmloutdata/{qemuxml2xmlout-net-virtio-rxqueuesize.xml => qemuxml2xmlout-net-virtio-rxtxqueuesize.xml} (96%)
33234a
33234a
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
33234a
index dc8e7d2dc7..024debe862 100644
33234a
--- a/docs/formatdomain.html.in
33234a
+++ b/docs/formatdomain.html.in
33234a
@@ -5038,7 +5038,7 @@ qemu-kvm -net nic,model=? /dev/null
33234a
     <source network='default'/>
33234a
     <target dev='vnet1'/>
33234a
     <model type='virtio'/>
33234a
-    <driver name='vhost' txmode='iothread' ioeventfd='on' event_idx='off' queues='5' rx_queue_size='256'>
33234a
+    <driver name='vhost' txmode='iothread' ioeventfd='on' event_idx='off' queues='5' rx_queue_size='256' tx_queue_size='256'>
33234a
       <host csum='off' gso='off' tso4='off' tso6='off' ecn='off' ufo='off' mrg_rxbuf='off'/>
33234a
       <guest csum='off' tso4='off' tso6='off' ecn='off' ufo='off'/>
33234a
     </driver>
33234a
@@ -5168,6 +5168,19 @@ qemu-kvm -net nic,model=? /dev/null
33234a
         In general you should leave this option alone, unless you
33234a
         are very certain you know what you are doing.
33234a
       
33234a
+      
tx_queue_size
33234a
+      
33234a
+        The optional tx_queue_size attribute controls
33234a
+        the size of virtio ring for each queue as described above.
33234a
+        The default value is hypervisor dependent and may change
33234a
+        across its releases. Moreover, some hypervisors may pose
33234a
+        some restrictions on actual value. For instance, QEMU
33234a
+        v2.9  requires value to be a power of two from [256, 1024] range.
33234a
+        Since 3.7.0 (QEMU and KVM only)

33234a
+
33234a
+        In general you should leave this option alone, unless you
33234a
+        are very certain you know what you are doing.
33234a
+      
33234a
       
virtio options
33234a
       
33234a
         For virtio interfaces,
33234a
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
33234a
index 78023ff4af..bb077ed5a0 100644
33234a
--- a/docs/schemas/domaincommon.rng
33234a
+++ b/docs/schemas/domaincommon.rng
33234a
@@ -2619,6 +2619,11 @@
33234a
                   <ref name='positiveInteger'/>
33234a
                 </attribute>
33234a
               </optional>
33234a
+              <optional>
33234a
+                <attribute name='tx_queue_size'>
33234a
+                  <ref name='positiveInteger'/>
33234a
+                </attribute>
33234a
+              </optional>
33234a
               <optional>
33234a
                 <attribute name="txmode">
33234a
                   <choice>
33234a
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
33234a
index d8ca25da38..806582fb8f 100644
33234a
--- a/src/conf/domain_conf.c
33234a
+++ b/src/conf/domain_conf.c
33234a
@@ -9721,6 +9721,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
33234a
     char *event_idx = NULL;
33234a
     char *queues = NULL;
33234a
     char *rx_queue_size = NULL;
33234a
+    char *tx_queue_size = NULL;
33234a
     char *str = NULL;
33234a
     char *filter = NULL;
33234a
     char *internal = NULL;
33234a
@@ -9894,6 +9895,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
33234a
                 event_idx = virXMLPropString(cur, "event_idx");
33234a
                 queues = virXMLPropString(cur, "queues");
33234a
                 rx_queue_size = virXMLPropString(cur, "rx_queue_size");
33234a
+                tx_queue_size = virXMLPropString(cur, "tx_queue_size");
33234a
             } else if (xmlStrEqual(cur->name, BAD_CAST "filterref")) {
33234a
                 if (filter) {
33234a
                     virReportError(VIR_ERR_XML_ERROR, "%s",
33234a
@@ -10291,6 +10293,16 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
33234a
             }
33234a
             def->driver.virtio.rx_queue_size = q;
33234a
         }
33234a
+        if (tx_queue_size) {
33234a
+            unsigned int q;
33234a
+            if (virStrToLong_uip(tx_queue_size, NULL, 10, &q) < 0) {
33234a
+                virReportError(VIR_ERR_XML_DETAIL,
33234a
+                               _("'tx_queue_size' attribute must be positive number: %s"),
33234a
+                               tx_queue_size);
33234a
+                goto error;
33234a
+            }
33234a
+            def->driver.virtio.tx_queue_size = q;
33234a
+        }
33234a
         if ((str = virXPathString("string(./driver/host/@csum)", ctxt))) {
33234a
             if ((val = virTristateSwitchTypeFromString(str)) <= 0) {
33234a
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
33234a
@@ -10488,6 +10500,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
33234a
     VIR_FREE(event_idx);
33234a
     VIR_FREE(queues);
33234a
     VIR_FREE(rx_queue_size);
33234a
+    VIR_FREE(tx_queue_size);
33234a
     VIR_FREE(str);
33234a
     VIR_FREE(filter);
33234a
     VIR_FREE(type);
33234a
@@ -22264,6 +22277,9 @@ virDomainVirtioNetDriverFormat(char **outstr,
33234a
     if (def->driver.virtio.rx_queue_size)
33234a
         virBufferAsprintf(&buf, " rx_queue_size='%u'",
33234a
                           def->driver.virtio.rx_queue_size);
33234a
+    if (def->driver.virtio.tx_queue_size)
33234a
+        virBufferAsprintf(&buf, " tx_queue_size='%u'",
33234a
+                          def->driver.virtio.tx_queue_size);
33234a
 
33234a
     virDomainVirtioOptionsFormat(&buf, def->virtio);
33234a
 
33234a
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
33234a
index 4c33b0d15e..7372a52856 100644
33234a
--- a/src/conf/domain_conf.h
33234a
+++ b/src/conf/domain_conf.h
33234a
@@ -967,6 +967,7 @@ struct _virDomainNetDef {
33234a
             virTristateSwitch event_idx;
33234a
             unsigned int queues; /* Multiqueue virtio-net */
33234a
             unsigned int rx_queue_size;
33234a
+            unsigned int tx_queue_size;
33234a
             struct {
33234a
                 virTristateSwitch csum;
33234a
                 virTristateSwitch gso;
33234a
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
33234a
index f22c11941c..6f8b1ac735 100644
33234a
--- a/src/qemu/qemu_capabilities.c
33234a
+++ b/src/qemu/qemu_capabilities.c
33234a
@@ -376,6 +376,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
33234a
               "intel-iommu.device-iotlb", /* 260 */
33234a
               "virtio.iommu_platform",
33234a
               "virtio.ats",
33234a
+              "virtio-net.tx_queue_size",
33234a
     );
33234a
 
33234a
 
33234a
@@ -1642,6 +1643,7 @@ static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsVirtioNet[] = {
33234a
     { "tx", QEMU_CAPS_VIRTIO_TX_ALG },
33234a
     { "event_idx", QEMU_CAPS_VIRTIO_NET_EVENT_IDX },
33234a
     { "rx_queue_size", QEMU_CAPS_VIRTIO_NET_RX_QUEUE_SIZE },
33234a
+    { "tx_queue_size", QEMU_CAPS_VIRTIO_NET_TX_QUEUE_SIZE },
33234a
     { "host_mtu", QEMU_CAPS_VIRTIO_NET_HOST_MTU },
33234a
 };
33234a
 
33234a
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
33234a
index c28c80d40a..281fe7d483 100644
33234a
--- a/src/qemu/qemu_capabilities.h
33234a
+++ b/src/qemu/qemu_capabilities.h
33234a
@@ -415,6 +415,7 @@ typedef enum {
33234a
     QEMU_CAPS_INTEL_IOMMU_DEVICE_IOTLB, /* intel-iommu.device-iotlb */
33234a
     QEMU_CAPS_VIRTIO_PCI_IOMMU_PLATFORM, /* virtio-*-pci.iommu_platform */
33234a
     QEMU_CAPS_VIRTIO_PCI_ATS, /* virtio-*-pci.ats */
33234a
+    QEMU_CAPS_VIRTIO_NET_TX_QUEUE_SIZE, /* virtio-net-*.tx_queue_size */
33234a
 
33234a
     QEMU_CAPS_LAST /* this must always be the last item */
33234a
 } virQEMUCapsFlags;
33234a
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
33234a
index a4184b7378..f16029aa83 100644
33234a
--- a/src/qemu/qemu_command.c
33234a
+++ b/src/qemu/qemu_command.c
33234a
@@ -3788,6 +3788,14 @@ qemuBuildNicDevStr(virDomainDefPtr def,
33234a
         }
33234a
         virBufferAsprintf(&buf, ",rx_queue_size=%u", net->driver.virtio.rx_queue_size);
33234a
     }
33234a
+    if (usingVirtio && net->driver.virtio.tx_queue_size) {
33234a
+        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_NET_TX_QUEUE_SIZE)) {
33234a
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
33234a
+                           _("virtio tx_queue_size option is not supported with this QEMU binary"));
33234a
+            goto error;
33234a
+        }
33234a
+        virBufferAsprintf(&buf, ",tx_queue_size=%u", net->driver.virtio.tx_queue_size);
33234a
+    }
33234a
 
33234a
     if (usingVirtio && net->mtu) {
33234a
         if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_NET_HOST_MTU)) {
33234a
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
33234a
index c9c668b892..a41657099f 100644
33234a
--- a/src/qemu/qemu_domain.c
33234a
+++ b/src/qemu/qemu_domain.c
33234a
@@ -3121,11 +3121,17 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
33234a
             goto cleanup;
33234a
         }
33234a
 
33234a
-        if (STREQ_NULLABLE(net->model, "virtio") &&
33234a
-            net->driver.virtio.rx_queue_size & (net->driver.virtio.rx_queue_size - 1)) {
33234a
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
33234a
-                           _("rx_queue_size has to be a power of two"));
33234a
-            goto cleanup;
33234a
+        if (STREQ_NULLABLE(net->model, "virtio")) {
33234a
+            if (net->driver.virtio.rx_queue_size & (net->driver.virtio.rx_queue_size - 1)) {
33234a
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
33234a
+                               _("rx_queue_size has to be a power of two"));
33234a
+                goto cleanup;
33234a
+            }
33234a
+            if (net->driver.virtio.tx_queue_size & (net->driver.virtio.tx_queue_size - 1)) {
33234a
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
33234a
+                               _("tx_queue_size has to be a power of two"));
33234a
+                goto cleanup;
33234a
+            }
33234a
         }
33234a
 
33234a
         if (net->mtu &&
33234a
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-rxqueuesize.args b/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-rxtxqueuesize.args
33234a
similarity index 83%
33234a
rename from tests/qemuxml2argvdata/qemuxml2argv-net-virtio-rxqueuesize.args
33234a
rename to tests/qemuxml2argvdata/qemuxml2argv-net-virtio-rxtxqueuesize.args
33234a
index 7d275a723d..68b87b4ffe 100644
33234a
--- a/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-rxqueuesize.args
33234a
+++ b/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-rxtxqueuesize.args
33234a
@@ -19,7 +19,7 @@ QEMU_AUDIO_DRV=none \
33234a
 -usb \
33234a
 -drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \
33234a
 -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
33234a
--device virtio-net-pci,rx_queue_size=512,vlan=0,id=net0,mac=00:11:22:33:44:55,\
33234a
-bus=pci.0,addr=0x3 \
33234a
+-device virtio-net-pci,rx_queue_size=512,tx_queue_size=1024,vlan=0,id=net0,\
33234a
+mac=00:11:22:33:44:55,bus=pci.0,addr=0x3 \
33234a
 -net user,vlan=0,name=hostnet0 \
33234a
 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x4
33234a
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-rxqueuesize.xml b/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-rxtxqueuesize.xml
33234a
similarity index 93%
33234a
rename from tests/qemuxml2argvdata/qemuxml2argv-net-virtio-rxqueuesize.xml
33234a
rename to tests/qemuxml2argvdata/qemuxml2argv-net-virtio-rxtxqueuesize.xml
33234a
index cfb4742fc6..14d357bba3 100644
33234a
--- a/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-rxqueuesize.xml
33234a
+++ b/tests/qemuxml2argvdata/qemuxml2argv-net-virtio-rxtxqueuesize.xml
33234a
@@ -22,7 +22,7 @@
33234a
     <interface type='user'>
33234a
       <mac address='00:11:22:33:44:55'/>
33234a
       <model type='virtio'/>
33234a
-      <driver rx_queue_size='512'/>
33234a
+      <driver rx_queue_size='512' tx_queue_size='1024'/>
33234a
     </interface>
33234a
     <memballoon model='virtio'/>
33234a
   </devices>
33234a
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
33234a
index 5ca27f105d..827fe90239 100644
33234a
--- a/tests/qemuxml2argvtest.c
33234a
+++ b/tests/qemuxml2argvtest.c
33234a
@@ -1145,8 +1145,9 @@ mymain(void)
33234a
             QEMU_CAPS_VIRTIO_S390);
33234a
     DO_TEST("net-virtio-ccw",
33234a
             QEMU_CAPS_VIRTIO_CCW, QEMU_CAPS_VIRTIO_S390);
33234a
-    DO_TEST("net-virtio-rxqueuesize",
33234a
-            QEMU_CAPS_VIRTIO_NET_RX_QUEUE_SIZE);
33234a
+    DO_TEST("net-virtio-rxtxqueuesize",
33234a
+            QEMU_CAPS_VIRTIO_NET_RX_QUEUE_SIZE,
33234a
+            QEMU_CAPS_VIRTIO_NET_TX_QUEUE_SIZE);
33234a
     DO_TEST_PARSE_ERROR("net-virtio-rxqueuesize-invalid-size", NONE);
33234a
     DO_TEST("net-eth", NONE);
33234a
     DO_TEST("net-eth-ifname", NONE);
33234a
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-net-virtio-rxqueuesize.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-net-virtio-rxtxqueuesize.xml
33234a
similarity index 96%
33234a
rename from tests/qemuxml2xmloutdata/qemuxml2xmlout-net-virtio-rxqueuesize.xml
33234a
rename to tests/qemuxml2xmloutdata/qemuxml2xmlout-net-virtio-rxtxqueuesize.xml
33234a
index 5b41936063..34e1e40012 100644
33234a
--- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-net-virtio-rxqueuesize.xml
33234a
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-net-virtio-rxtxqueuesize.xml
33234a
@@ -29,7 +29,7 @@
33234a
     <interface type='user'>
33234a
       <mac address='00:11:22:33:44:55'/>
33234a
       <model type='virtio'/>
33234a
-      <driver rx_queue_size='512'/>
33234a
+      <driver rx_queue_size='512' tx_queue_size='1024'/>
33234a
       <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
33234a
     </interface>
33234a
     <input type='mouse' bus='ps2'/>
33234a
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
33234a
index f2abad00cf..62bce8d240 100644
33234a
--- a/tests/qemuxml2xmltest.c
33234a
+++ b/tests/qemuxml2xmltest.c
33234a
@@ -523,7 +523,7 @@ mymain(void)
33234a
     DO_TEST("net-eth-ifname", NONE);
33234a
     DO_TEST("net-eth-hostip", NONE);
33234a
     DO_TEST("net-virtio-network-portgroup", NONE);
33234a
-    DO_TEST("net-virtio-rxqueuesize", NONE);
33234a
+    DO_TEST("net-virtio-rxtxqueuesize", NONE);
33234a
     DO_TEST("net-hostdev", NONE);
33234a
     DO_TEST("net-hostdev-vfio", NONE);
33234a
     DO_TEST("net-midonet", NONE);
33234a
-- 
33234a
2.14.1
33234a