thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-virtio-net-dynamic-network-offloads-configuration.patch

5d360b
From bb34da88524f313681005435f8fd6d905ca81b6a Mon Sep 17 00:00:00 2001
840376
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
840376
Date: Thu, 17 Aug 2017 09:45:35 +0200
5d360b
Subject: [PATCH 2/4] virtio-net: dynamic network offloads configuration
840376
840376
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
840376
Message-id: <20170817094536.12740-2-dgilbert@redhat.com>
840376
Patchwork-id: 76021
840376
O-Subject: [RHEL-7.5/7.4.z/7.3.z/7.2.z qemu-kvm PATCH v2 1/2] virtio-net: dynamic network offloads configuration
5d360b
Bugzilla: 1480428
840376
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
840376
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
840376
RH-Acked-by: Thomas Huth <thuth@redhat.com>
840376
840376
From: Dmitry Fleytman <dfleytma@redhat.com>
840376
840376
Virtio-net driver currently negotiates network offloads
840376
on startup via features mechanism and have no ability to
840376
disable and re-enable offloads later.
840376
This patch introduced a new control command that allows
840376
to configure device network offloads state dynamically.
840376
The patch also introduces a new feature flag
840376
VIRTIO_NET_F_CTRL_GUEST_OFFLOADS.
840376
840376
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
840376
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
840376
Message-id: 20130520081814.GA8162@redhat.com
840376
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
840376
(cherry picked from commit 644c98587d4ccc09e7592e1688e4e7fa363c5a75)
840376
840376
RHEL7.0 qemu-kvm only: Configure ctrl_guest_offloads off
840376
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
840376
840376
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
840376
---
840376
 hw/net/virtio-net.c            | 99 +++++++++++++++++++++++++++++++++++-------
840376
 include/hw/i386/pc.h           |  4 ++
840376
 include/hw/virtio/virtio-net.h | 14 ++++++
840376
 3 files changed, 102 insertions(+), 15 deletions(-)
840376
840376
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
840376
index 3fde455..eb2feaf 100644
840376
--- a/hw/net/virtio-net.c
840376
+++ b/hw/net/virtio-net.c
840376
@@ -477,6 +477,34 @@ static uint32_t virtio_net_bad_features(VirtIODevice *vdev)
840376
     return features;
840376
 }
840376
 
840376
+static void virtio_net_apply_guest_offloads(VirtIONet *n)
840376
+{
840376
+    tap_set_offload(qemu_get_subqueue(n->nic, 0)->peer,
840376
+            !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_CSUM)),
840376
+            !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_TSO4)),
840376
+            !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_TSO6)),
840376
+            !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_ECN)),
840376
+            !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_UFO)));
840376
+}
840376
+
840376
+static uint64_t virtio_net_guest_offloads_by_features(uint32_t features)
840376
+{
840376
+    static const uint64_t guest_offloads_mask =
840376
+        (1ULL << VIRTIO_NET_F_GUEST_CSUM) |
840376
+        (1ULL << VIRTIO_NET_F_GUEST_TSO4) |
840376
+        (1ULL << VIRTIO_NET_F_GUEST_TSO6) |
840376
+        (1ULL << VIRTIO_NET_F_GUEST_ECN)  |
840376
+        (1ULL << VIRTIO_NET_F_GUEST_UFO);
840376
+
840376
+    return guest_offloads_mask & features;
840376
+}
840376
+
840376
+static inline uint64_t virtio_net_supported_guest_offloads(VirtIONet *n)
840376
+{
840376
+    VirtIODevice *vdev = VIRTIO_DEVICE(n);
840376
+    return virtio_net_guest_offloads_by_features(vdev->guest_features);
840376
+}
840376
+
840376
 static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features)
840376
 {
840376
     VirtIONet *n = VIRTIO_NET(vdev);
840376
@@ -487,12 +515,9 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features)
840376
     virtio_net_set_mrg_rx_bufs(n, !!(features & (1 << VIRTIO_NET_F_MRG_RXBUF)));
840376
 
840376
     if (n->has_vnet_hdr) {
840376
-        tap_set_offload(qemu_get_subqueue(n->nic, 0)->peer,
840376
-                        (features >> VIRTIO_NET_F_GUEST_CSUM) & 1,
840376
-                        (features >> VIRTIO_NET_F_GUEST_TSO4) & 1,
840376
-                        (features >> VIRTIO_NET_F_GUEST_TSO6) & 1,
840376
-                        (features >> VIRTIO_NET_F_GUEST_ECN)  & 1,
840376
-                        (features >> VIRTIO_NET_F_GUEST_UFO)  & 1);
840376
+        n->curr_guest_offloads =
840376
+            virtio_net_guest_offloads_by_features(features);
840376
+        virtio_net_apply_guest_offloads(n);
840376
     }
840376
 
840376
     for (i = 0;  i < n->max_queues; i++) {
840376
@@ -547,6 +572,43 @@ static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd,
840376
     return VIRTIO_NET_OK;
840376
 }
840376
 
840376
+static int virtio_net_handle_offloads(VirtIONet *n, uint8_t cmd,
840376
+                                     struct iovec *iov, unsigned int iov_cnt)
840376
+{
840376
+    VirtIODevice *vdev = VIRTIO_DEVICE(n);
840376
+    uint64_t offloads;
840376
+    size_t s;
840376
+
840376
+    if (!((1 << VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) & vdev->guest_features)) {
840376
+        return VIRTIO_NET_ERR;
840376
+    }
840376
+
840376
+    s = iov_to_buf(iov, iov_cnt, 0, &offloads, sizeof(offloads));
840376
+    if (s != sizeof(offloads)) {
840376
+        return VIRTIO_NET_ERR;
840376
+    }
840376
+
840376
+    if (cmd == VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET) {
840376
+        uint64_t supported_offloads;
840376
+
840376
+        if (!n->has_vnet_hdr) {
840376
+            return VIRTIO_NET_ERR;
840376
+        }
840376
+
840376
+        supported_offloads = virtio_net_supported_guest_offloads(n);
840376
+        if (offloads & ~supported_offloads) {
840376
+            return VIRTIO_NET_ERR;
840376
+        }
840376
+
840376
+        n->curr_guest_offloads = offloads;
840376
+        virtio_net_apply_guest_offloads(n);
840376
+
840376
+        return VIRTIO_NET_OK;
840376
+    } else {
840376
+        return VIRTIO_NET_ERR;
840376
+    }
840376
+}
840376
+
840376
 static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd,
840376
                                  struct iovec *iov, unsigned int iov_cnt)
840376
 {
840376
@@ -735,6 +797,8 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
840376
             status = virtio_net_handle_vlan_table(n, ctrl.cmd, iov, iov_cnt);
840376
         } else if (ctrl.class == VIRTIO_NET_CTRL_MQ) {
840376
             status = virtio_net_handle_mq(n, ctrl.cmd, iov, iov_cnt);
840376
+        } else if (ctrl.class == VIRTIO_NET_CTRL_GUEST_OFFLOADS) {
840376
+            status = virtio_net_handle_offloads(n, ctrl.cmd, iov, iov_cnt);
840376
         }
840376
 
840376
         s = iov_from_buf(elem.in_sg, elem.in_num, 0, &status, sizeof(status));
840376
@@ -1253,6 +1317,10 @@ static void virtio_net_save(QEMUFile *f, void *opaque)
840376
             qemu_put_be32(f, n->vqs[i].tx_waiting);
840376
         }
840376
     }
840376
+
840376
+    if ((1 << VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) & vdev->guest_features) {
840376
+        qemu_put_be64(f, n->curr_guest_offloads);
840376
+    }
840376
 }
840376
 
840376
 static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
840376
@@ -1317,15 +1385,6 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
840376
             error_report("virtio-net: saved image requires vnet_hdr=on");
840376
             return -1;
840376
         }
840376
-
840376
-        if (n->has_vnet_hdr) {
840376
-            tap_set_offload(qemu_get_queue(n->nic)->peer,
840376
-                    (vdev->guest_features >> VIRTIO_NET_F_GUEST_CSUM) & 1,
840376
-                    (vdev->guest_features >> VIRTIO_NET_F_GUEST_TSO4) & 1,
840376
-                    (vdev->guest_features >> VIRTIO_NET_F_GUEST_TSO6) & 1,
840376
-                    (vdev->guest_features >> VIRTIO_NET_F_GUEST_ECN)  & 1,
840376
-                    (vdev->guest_features >> VIRTIO_NET_F_GUEST_UFO)  & 1);
840376
-        }
840376
     }
840376
 
840376
     if (version_id >= 9) {
840376
@@ -1364,6 +1423,16 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
840376
         }
840376
     }
840376
 
840376
+    if ((1 << VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) & vdev->guest_features) {
840376
+        n->curr_guest_offloads = qemu_get_be64(f);
840376
+    } else {
840376
+        n->curr_guest_offloads = virtio_net_supported_guest_offloads(n);
840376
+    }
840376
+
840376
+    if (peer_has_vnet_hdr(n)) {
840376
+        virtio_net_apply_guest_offloads(n);
840376
+    }
840376
+
840376
     virtio_net_set_queues(n);
840376
 
840376
     /* Find the first multicast entry in the saved MAC filter */
840376
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
840376
index 3b8f7d8..89bb458 100644
840376
--- a/include/hw/i386/pc.h
840376
+++ b/include/hw/i386/pc.h
840376
@@ -318,6 +318,10 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t);
840376
             .property = "vectors",\
840376
             /* DEV_NVECTORS_UNSPECIFIED as a uint32_t string */\
840376
             .value    = stringify(0xFFFFFFFF),\
840376
+        },{ \
840376
+            .driver   = "virtio-net-pci", \
840376
+            .property = "ctrl_guest_offloads", \
840376
+            .value    = "off", \
840376
         },{\
840376
             .driver   = "e1000",\
840376
             .property = "romfile",\
840376
diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h
840376
index a02fc50..02fa5c5 100644
840376
--- a/include/hw/virtio/virtio-net.h
840376
+++ b/include/hw/virtio/virtio-net.h
840376
@@ -31,6 +31,8 @@
840376
 /* The feature bitmap for virtio net */
840376
 #define VIRTIO_NET_F_CSUM       0       /* Host handles pkts w/ partial csum */
840376
 #define VIRTIO_NET_F_GUEST_CSUM 1       /* Guest handles pkts w/ partial csum */
840376
+#define VIRTIO_NET_F_CTRL_GUEST_OFFLOADS 2 /* Control channel offload
840376
+                                         * configuration support */
840376
 #define VIRTIO_NET_F_MAC        5       /* Host has given MAC address. */
840376
 #define VIRTIO_NET_F_GSO        6       /* Host handles pkts w/ any GSO type */
840376
 #define VIRTIO_NET_F_GUEST_TSO4 7       /* Guest can handle TSOv4 in. */
840376
@@ -190,6 +192,7 @@ typedef struct VirtIONet {
840376
     size_t config_size;
840376
     char *netclient_name;
840376
     char *netclient_type;
840376
+    uint64_t curr_guest_offloads;
840376
 } VirtIONet;
840376
 
840376
 #define VIRTIO_NET_CTRL_MAC    1
840376
@@ -229,6 +232,15 @@ struct virtio_net_ctrl_mq {
840376
  #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN        1
840376
  #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX        0x8000
840376
 
840376
+/*
840376
+ * Control network offloads
840376
+ *
840376
+ * Dynamic offloads are available with the
840376
+ * VIRTIO_NET_F_CTRL_GUEST_OFFLOADS feature bit.
840376
+ */
840376
+#define VIRTIO_NET_CTRL_GUEST_OFFLOADS   5
840376
+ #define VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET        0
840376
+
840376
 #define DEFINE_VIRTIO_NET_FEATURES(_state, _field) \
840376
         DEFINE_VIRTIO_COMMON_FEATURES(_state, _field), \
840376
         DEFINE_PROP_BIT("any_layout", _state, _field, VIRTIO_F_ANY_LAYOUT, true), \
840376
@@ -250,6 +262,8 @@ struct virtio_net_ctrl_mq {
840376
         DEFINE_PROP_BIT("ctrl_vlan", _state, _field, VIRTIO_NET_F_CTRL_VLAN, true), \
840376
         DEFINE_PROP_BIT("ctrl_rx_extra", _state, _field, VIRTIO_NET_F_CTRL_RX_EXTRA, true), \
840376
         DEFINE_PROP_BIT("ctrl_mac_addr", _state, _field, VIRTIO_NET_F_CTRL_MAC_ADDR, true), \
840376
+        /* RHEL 7.0 qemu-kvm: ctrl_guest_offloads always configured off */ \
840376
+        DEFINE_PROP_BIT("ctrl_guest_offloads", _state, _field, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS, false), \
840376
         DEFINE_PROP_BIT("mq", _state, _field, VIRTIO_NET_F_MQ, false)
840376
 
840376
 #define DEFINE_VIRTIO_NET_PROPERTIES(_state, _field)                           \
840376
-- 
840376
1.8.3.1
840376