Skip to contentSkip to conversation

reference implementation of RSS

PATCH Superseded Yuri Benditovich 3 participants 19 messages Feb 26, 2020 – Mar 8, 2020

v1 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

cover reference implementation of RSS

Support for VIRTIO_NET_F_RSS feature in QEMU for reference purpose. Implements Toeplitz hash calculation for incoming packets according to configuration provided by driver.

This series requires previously submitted and accepted patch to be applied:
https://lists.gnu.org/archive/html/qemu-devel/2020-01/msg06448.html

Yuri Benditovich (3):
virtio-net: introduce RSS RX steering feature
virtio-net: implement RSS configuration command
virtio-net: implement RX RSS processing

 hw/net/trace-events                         |   3 +
 hw/net/virtio-net.c                         | 234 +++++++++++++++++++-VIRTIO_NET_F_RSS
 include/hw/virtio/virtio-net.h              |  12 +
 include/standard-headers/linux/virtio_net.h |  37 +++-
 4 files changed, 273 insertions(+), 13 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/3 virtio-net: introduce RSS RX steering feature

---
 include/standard-headers/linux/virtio_net.h | 37 +++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)
include/standard-headers/linux/virtio_net.h +35 -2
index 260c3681d7..3bc100afe3 100644
@@ -57,6 +57,7 @@
 					 * Steering */
 #define VIRTIO_NET_F_CTRL_MAC_ADDR 23	/* Set MAC address */
 
+#define VIRTIO_NET_F_RSS    	  60	/* Supports RSS RX steering */
 #define VIRTIO_NET_F_STANDBY	  62	/* Act as standby for another device
 					 * with the same MAC.
 					 */
@@ -69,6 +70,16 @@
 #define VIRTIO_NET_S_LINK_UP	1	/* Link is up */
 #define VIRTIO_NET_S_ANNOUNCE	2	/* Announcement is needed */
 
+#define VIRTIO_NET_RSS_HASH_TYPE_IPv4              (1 << 0)
+#define VIRTIO_NET_RSS_HASH_TYPE_TCPv4             (1 << 1)
+#define VIRTIO_NET_RSS_HASH_TYPE_UDPv4             (1 << 2)
+#define VIRTIO_NET_RSS_HASH_TYPE_IPv6              (1 << 3)
+#define VIRTIO_NET_RSS_HASH_TYPE_TCPv6             (1 << 4)
+#define VIRTIO_NET_RSS_HASH_TYPE_UDPv6             (1 << 5)
+#define VIRTIO_NET_RSS_HASH_TYPE_IP_EX             (1 << 6)
+#define VIRTIO_NET_RSS_HASH_TYPE_TCP_EX            (1 << 7)
+#define VIRTIO_NET_RSS_HASH_TYPE_UDP_EX            (1 << 8)
+
 struct virtio_net_config {
 	/* The config defining mac address (if VIRTIO_NET_F_MAC) */
 	uint8_t mac[ETH_ALEN];
@@ -92,6 +103,14 @@ struct virtio_net_config {
 	 * Any other value stands for unknown.
 	 */
 	uint8_t duplex;
+
+	/* maximal size of RSS key */
+	uint8_t rss_max_key_size;
+	/* maximal number of indirection table entries */
+	uint16_t rss_max_indirection_table_length;
+	/* bitmask of supported VIRTIO_NET_RSS_HASH_ types */
+	uint32_t supported_hash_types;
+
 } QEMU_PACKED;
 
 /*
@@ -237,15 +256,29 @@ struct virtio_net_ctrl_mac {
  * Accordingly, driver should not transmit new packets  on virtqueues other than
  * specified.
  */
+#define VIRTIO_NET_CTRL_MQ   4
+ #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET        0
+ #define VIRTIO_NET_CTRL_MQ_RSS_CONFIG          1
+
+/* for VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET */
 struct virtio_net_ctrl_mq {
 	__virtio16 virtqueue_pairs;
 };
 
-#define VIRTIO_NET_CTRL_MQ   4
- #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET        0
  #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN        1
  #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX        0x8000
 
+/* for VIRTIO_NET_CTRL_MQ_RSS_CONFIG */
+struct virtio_net_rss_config {
+    uint32_t hash_types;
+    uint16_t indirection_table_mask;
+    uint16_t unclassified_queue;
+    uint16_t indirection_table[1/* + indirection_table_mask*/];
+    uint16_t max_tx_vq;
+    uint8_t hash_key_length;
+    uint8_t hash_key_data[/*hash_key_length*/];
+};
+
 /*
  * Control network offloads
  *
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH 1/3] virtio-net: introduce RSS RX steering feature

Quoted 4 lines · Yuri Benditovich
---
 include/standard-headers/linux/virtio_net.h | 37 +++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)

It will take a bit until next merge window when the linux headers will be updated.
Until that happens you can just put these defines where they are used.

Quoted 78 lines
include/standard-headers/linux/virtio_net.h +35 -2
index 260c3681d7..3bc100afe3 100644
@@ -57,6 +57,7 @@
 					 * Steering */
 #define VIRTIO_NET_F_CTRL_MAC_ADDR 23	/* Set MAC address */
 
+#define VIRTIO_NET_F_RSS    	  60	/* Supports RSS RX steering */
 #define VIRTIO_NET_F_STANDBY	  62	/* Act as standby for another device
 					 * with the same MAC.
 					 */
@@ -69,6 +70,16 @@
 #define VIRTIO_NET_S_LINK_UP	1	/* Link is up */
 #define VIRTIO_NET_S_ANNOUNCE	2	/* Announcement is needed */
 
+#define VIRTIO_NET_RSS_HASH_TYPE_IPv4              (1 << 0)
+#define VIRTIO_NET_RSS_HASH_TYPE_TCPv4             (1 << 1)
+#define VIRTIO_NET_RSS_HASH_TYPE_UDPv4             (1 << 2)
+#define VIRTIO_NET_RSS_HASH_TYPE_IPv6              (1 << 3)
+#define VIRTIO_NET_RSS_HASH_TYPE_TCPv6             (1 << 4)
+#define VIRTIO_NET_RSS_HASH_TYPE_UDPv6             (1 << 5)
+#define VIRTIO_NET_RSS_HASH_TYPE_IP_EX             (1 << 6)
+#define VIRTIO_NET_RSS_HASH_TYPE_TCP_EX            (1 << 7)
+#define VIRTIO_NET_RSS_HASH_TYPE_UDP_EX            (1 << 8)
+
 struct virtio_net_config {
 	/* The config defining mac address (if VIRTIO_NET_F_MAC) */
 	uint8_t mac[ETH_ALEN];
@@ -92,6 +103,14 @@ struct virtio_net_config {
 	 * Any other value stands for unknown.
 	 */
 	uint8_t duplex;
+
+	/* maximal size of RSS key */
+	uint8_t rss_max_key_size;
+	/* maximal number of indirection table entries */
+	uint16_t rss_max_indirection_table_length;
+	/* bitmask of supported VIRTIO_NET_RSS_HASH_ types */
+	uint32_t supported_hash_types;
+
 } QEMU_PACKED;
 
 /*
@@ -237,15 +256,29 @@ struct virtio_net_ctrl_mac {
  * Accordingly, driver should not transmit new packets  on virtqueues other than
  * specified.
  */
+#define VIRTIO_NET_CTRL_MQ   4
+ #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET        0
+ #define VIRTIO_NET_CTRL_MQ_RSS_CONFIG          1
+
+/* for VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET */
 struct virtio_net_ctrl_mq {
 	__virtio16 virtqueue_pairs;
 };
 
-#define VIRTIO_NET_CTRL_MQ   4
- #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET        0
  #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN        1
  #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX        0x8000
 
+/* for VIRTIO_NET_CTRL_MQ_RSS_CONFIG */
+struct virtio_net_rss_config {
+    uint32_t hash_types;
+    uint16_t indirection_table_mask;
+    uint16_t unclassified_queue;
+    uint16_t indirection_table[1/* + indirection_table_mask*/];
+    uint16_t max_tx_vq;
+    uint8_t hash_key_length;
+    uint8_t hash_key_data[/*hash_key_length*/];
+};
+
 /*
  * Control network offloads
  *
Signature · 1 line
2.17.1
#3 lore raw

Re: [PATCH 1/3] virtio-net: introduce RSS RX steering feature

Quoted 7 lines · Michael S. Tsirkin
Quoted 4 lines · Yuri Benditovich
---
 include/standard-headers/linux/virtio_net.h | 37 +++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)
Quoted 5 lines

It will take a bit until next merge window when the linux headers will be updated.
Until that happens you can just put these defines where they are used.

We also extend the configuration virtio_net_config structure and its field 'supported_hash_types' uses these defines. Please advise.

Quoted 85 lines

Review

Quoted 2 lines
(quoted diff) +0 -0

b/include/standard-headers/linux/virtio_net.h

include/standard-headers/linux/virtio_net.h line 61

Quoted 9 lines

index 260c3681d7..3bc100afe3 100644

include/standard-headers/linux/virtio_net.h +1 -0
@@ -57,6 +57,7 @@
                                       * Steering */
 #define VIRTIO_NET_F_CTRL_MAC_ADDR 23        /* Set MAC address */
 
+#define VIRTIO_NET_F_RSS       60    /* Supports RSS RX steering */
 #define VIRTIO_NET_F_STANDBY   62    /* Act as standby for another

device

include/standard-headers/linux/virtio_net.h line 71

Quoted 5 lines
include/standard-headers/linux/virtio_net.h +0 -0
                                       * with the same MAC.
                                       */
@@ -69,6 +70,16 @@
 #define VIRTIO_NET_S_LINK_UP 1       /* Link is up */
 #define VIRTIO_NET_S_ANNOUNCE        2       /* Announcement is needed

*/

Quoted 30 lines
include/standard-headers/linux/virtio_net.h +18 -0
+#define VIRTIO_NET_RSS_HASH_TYPE_IPv4              (1 << 0)
+#define VIRTIO_NET_RSS_HASH_TYPE_TCPv4             (1 << 1)
+#define VIRTIO_NET_RSS_HASH_TYPE_UDPv4             (1 << 2)
+#define VIRTIO_NET_RSS_HASH_TYPE_IPv6              (1 << 3)
+#define VIRTIO_NET_RSS_HASH_TYPE_TCPv6             (1 << 4)
+#define VIRTIO_NET_RSS_HASH_TYPE_UDPv6             (1 << 5)
+#define VIRTIO_NET_RSS_HASH_TYPE_IP_EX             (1 << 6)
+#define VIRTIO_NET_RSS_HASH_TYPE_TCP_EX            (1 << 7)
+#define VIRTIO_NET_RSS_HASH_TYPE_UDP_EX            (1 << 8)
+
 struct virtio_net_config {
      /* The config defining mac address (if VIRTIO_NET_F_MAC) */
      uint8_t mac[ETH_ALEN];
@@ -92,6 +103,14 @@ struct virtio_net_config {
       * Any other value stands for unknown.
       */
      uint8_t duplex;
+
+     /* maximal size of RSS key */
+     uint8_t rss_max_key_size;
+     /* maximal number of indirection table entries */
+     uint16_t rss_max_indirection_table_length;
+     /* bitmask of supported VIRTIO_NET_RSS_HASH_ types */
+     uint32_t supported_hash_types;
+
 } QEMU_PACKED;
 
 /*

include/standard-headers/linux/virtio_net.h struct virtio_net_ctrl_mac { · line 256

Quoted 1 line
include/standard-headers/linux/virtio_net.h +0 -0
@@ -237,15 +256,29 @@ struct virtio_net_ctrl_mac {
  * Accordingly, driver should not transmit new packets  on virtqueues

other than

Quoted 32 lines
include/standard-headers/linux/virtio_net.h +16 -3
  * specified.
  */
+#define VIRTIO_NET_CTRL_MQ   4
+ #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET        0
+ #define VIRTIO_NET_CTRL_MQ_RSS_CONFIG          1
+
+/* for VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET */
 struct virtio_net_ctrl_mq {
      __virtio16 virtqueue_pairs;
 };
 
-#define VIRTIO_NET_CTRL_MQ   4
- #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET        0
  #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN        1
  #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX        0x8000
 
+/* for VIRTIO_NET_CTRL_MQ_RSS_CONFIG */
+struct virtio_net_rss_config {
+    uint32_t hash_types;
+    uint16_t indirection_table_mask;
+    uint16_t unclassified_queue;
+    uint16_t indirection_table[1/* + indirection_table_mask*/];
+    uint16_t max_tx_vq;
+    uint8_t hash_key_length;
+    uint8_t hash_key_data[/*hash_key_length*/];
+};
+
 /*
  * Control network offloads
  *
--

2.17.1

#4 lore raw

Re: [PATCH 1/3] virtio-net: introduce RSS RX steering feature

Quoted 11 lines · Yuri Benditovich

On Thu, Mar 5, 2020 at 3:21 PM Michael S. Tsirkin <[email protected]> wrote:

On Wed, Feb 26, 2020 at 07:48:07PM +0200, Yuri Benditovich wrote:
> Signed-off-by: Yuri Benditovich <[email protected]> > ---
>  include/standard-headers/linux/virtio_net.h | 37 +++++++++++++++++++-- >  1 file changed, 35 insertions(+), 2 deletions(-)

Quoted 8 lines

It will take a bit until next merge window when the linux headers will be updated.
Until that happens you can just put these defines where they are used.

We also extend the configuration virtio_net_config structure and its field 'supported_hash_types' uses these defines. Please advise.

Make a private copy of it with a different name for now. Add a comment so we don't forget to remove down the road.

Quoted 86 lines

include/

Quoted 3 lines
include/ renamed from include/standard-headers/linux/virtio_net.h +0 -0
    standard-headers/linux/virtio_net.h
    > index 260c3681d7..3bc100afe3 100644
    > --- a/include/standard-headers/linux/virtio_net.h
    > +++ b/include/standard-headers/linux/virtio_net.h
    > @@ -57,6 +57,7 @@
    >                                        * Steering */
    >  #define VIRTIO_NET_F_CTRL_MAC_ADDR 23        /* Set MAC address */
    > 
    > +#define VIRTIO_NET_F_RSS       60    /* Supports RSS RX steering */
    >  #define VIRTIO_NET_F_STANDBY   62    /* Act as standby for another
    device
    >                                        * with the same MAC.
    >                                        */
    > @@ -69,6 +70,16 @@
    >  #define VIRTIO_NET_S_LINK_UP 1       /* Link is up */
    >  #define VIRTIO_NET_S_ANNOUNCE        2       /* Announcement is needed *
    /
    > 
    > +#define VIRTIO_NET_RSS_HASH_TYPE_IPv4              (1 << 0)
    > +#define VIRTIO_NET_RSS_HASH_TYPE_TCPv4             (1 << 1)
    > +#define VIRTIO_NET_RSS_HASH_TYPE_UDPv4             (1 << 2)
    > +#define VIRTIO_NET_RSS_HASH_TYPE_IPv6              (1 << 3)
    > +#define VIRTIO_NET_RSS_HASH_TYPE_TCPv6             (1 << 4)
    > +#define VIRTIO_NET_RSS_HASH_TYPE_UDPv6             (1 << 5)
    > +#define VIRTIO_NET_RSS_HASH_TYPE_IP_EX             (1 << 6)
    > +#define VIRTIO_NET_RSS_HASH_TYPE_TCP_EX            (1 << 7)
    > +#define VIRTIO_NET_RSS_HASH_TYPE_UDP_EX            (1 << 8)
    > +
    >  struct virtio_net_config {
    >       /* The config defining mac address (if VIRTIO_NET_F_MAC) */
    >       uint8_t mac[ETH_ALEN];
    > @@ -92,6 +103,14 @@ struct virtio_net_config {
    >        * Any other value stands for unknown.
    >        */
    >       uint8_t duplex;
    > +
    > +     /* maximal size of RSS key */
    > +     uint8_t rss_max_key_size;
    > +     /* maximal number of indirection table entries */
    > +     uint16_t rss_max_indirection_table_length;
    > +     /* bitmask of supported VIRTIO_NET_RSS_HASH_ types */
    > +     uint32_t supported_hash_types;
    > +
    >  } QEMU_PACKED;
    > 
    >  /*
    > @@ -237,15 +256,29 @@ struct virtio_net_ctrl_mac {
    >   * Accordingly, driver should not transmit new packets  on virtqueues
    other than
    >   * specified.
    >   */
    > +#define VIRTIO_NET_CTRL_MQ   4
    > + #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET        0
    > + #define VIRTIO_NET_CTRL_MQ_RSS_CONFIG          1
    > +
    > +/* for VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET */
    >  struct virtio_net_ctrl_mq {
    >       __virtio16 virtqueue_pairs;
    >  };
    > 
    > -#define VIRTIO_NET_CTRL_MQ   4
    > - #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET        0
    >   #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN        1
    >   #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX        0x8000
    > 
    > +/* for VIRTIO_NET_CTRL_MQ_RSS_CONFIG */
    > +struct virtio_net_rss_config {
    > +    uint32_t hash_types;
    > +    uint16_t indirection_table_mask;
    > +    uint16_t unclassified_queue;
    > +    uint16_t indirection_table[1/* + indirection_table_mask*/];
    > +    uint16_t max_tx_vq;
    > +    uint8_t hash_key_length;
    > +    uint8_t hash_key_data[/*hash_key_length*/];
    > +};
    > +
    >  /*
    >   * Control network offloads
    >   *
    > --
    > 2.17.1
#5 lore raw

PATCH 2/3 virtio-net: implement RSS configuration command

In reply to Yuri Benditovich

Optionally report RSS feature.
Handle RSS configuration command and keep RSS parameters in virtio-net device context.

---
 hw/net/trace-events            |   3 +
 hw/net/virtio-net.c            | 148 +++++++++++++++++++++++++++++++--
 include/hw/virtio/virtio-net.h |  11 +++
 3 files changed, 153 insertions(+), 9 deletions(-)
hw/net/trace-events +3 -0
index 4939321493..0f47b7c450 100644
@@ -371,6 +371,9 @@ virtio_net_announce_notify(void) ""
 virtio_net_announce_timer(int round) "%d"
 virtio_net_handle_announce(int round) "%d"
 virtio_net_post_load_device(void)
+virtio_net_rss_disable(void)
+virtio_net_rss_error(int error_case) "case %d"
+virtio_net_rss_enable(uint32_t p1, uint16_t p2, uint8_t p3) "hashes 0x%x, table of %d, key of %d"
 
 # tulip.c
 tulip_reg_write(uint64_t addr, const char *name, int size, uint64_t val) "addr 0x%02"PRIx64" (%s) size %d value 0x%08"PRIx64
hw/net/virtio-net.c +139 -9

200 lines not on this page · raw message

include/hw/virtio/virtio-net.h +11 -0
index 96c68d4a92..cf16f5192e 100644
@@ -126,6 +126,9 @@ typedef struct VirtioNetRscChain {
 /* Maximum packet size we can receive from tap device: header + 64k */
 #define VIRTIO_NET_MAX_BUFSIZE (sizeof(struct virtio_net_hdr) + (64 * KiB))
 
+#define VIRTIO_NET_RSS_MAX_KEY_SIZE     40
+#define VIRTIO_NET_RSS_MAX_TABLE_LEN    128
+
 typedef struct VirtIONetQueue {
     VirtQueue *rx_vq;
     VirtQueue *tx_vq;
@@ -199,6 +202,14 @@ struct VirtIONet {
     bool failover;
     DeviceListener primary_listener;
     Notifier migration_state;
+    struct {
+        bool    enabled;
+        uint32_t hash_types;
+        uint8_t key[VIRTIO_NET_RSS_MAX_KEY_SIZE];
+        uint16_t indirections[VIRTIO_NET_RSS_MAX_TABLE_LEN];
+        uint16_t indirections_len;
+        uint16_t default_queue;
+    } rss_data;
 };
 
 void virtio_net_set_netclient_name(VirtIONet *n, const char *name,
Signature · 1 line
2.17.1
#6 lore raw

PATCH 3/3 virtio-net: implement RX RSS processing

In reply to Yuri Benditovich

If VIRTIO_NET_F_RSS negotiated and RSS is enabled, process incoming packets, calculate packet's hash and place the packet into respective RX virtqueue.

---
 hw/net/virtio-net.c            | 86 +++++++++++++++++++++++++++++++++-
 include/hw/virtio/virtio-net.h |  1 +
 2 files changed, 85 insertions(+), 2 deletions(-)
hw/net/virtio-net.c +84 -2
index c5d21675a9..adf7b88d7a 100644
@@ -42,6 +42,7 @@
 #include "trace.h"
 #include "monitor/qdev.h"
 #include "hw/pci/pci.h"
+#include "net_rx_pkt.h"
 
 #define VIRTIO_NET_VM_VERSION    11
 
@@ -1515,8 +1516,78 @@ static int receive_filter(VirtIONet *n, const uint8_t *buf, int size)
     return 0;
 }
 
+static uint8_t virtio_net_get_hash_type(bool isip4,
+                                        bool isip6,
+                                        bool isudp,
+                                        bool istcp,
+                                        uint32_t types)
+{
+    uint32_t mask;
+    if (isip4) {
+        if (istcp && (types & VIRTIO_NET_RSS_HASH_TYPE_TCPv4)) {
+            return NetPktRssIpV4Tcp;
+        }
+        if (isudp && (types & VIRTIO_NET_RSS_HASH_TYPE_UDPv4)) {
+            return NetPktRssIpV4Udp;
+        }
+        if (types & VIRTIO_NET_RSS_HASH_TYPE_IPv4) {
+            return NetPktRssIpV4;
+        }
+    } else if (isip6) {
+        mask = VIRTIO_NET_RSS_HASH_TYPE_TCP_EX | VIRTIO_NET_RSS_HASH_TYPE_TCPv6;
+        if (istcp && (types & mask)) {
+            return (types & VIRTIO_NET_RSS_HASH_TYPE_TCP_EX) ?
+                NetPktRssIpV6TcpEx : NetPktRssIpV6Tcp;
+        }
+        mask = VIRTIO_NET_RSS_HASH_TYPE_UDP_EX | VIRTIO_NET_RSS_HASH_TYPE_UDPv6;
+        if (isudp && (types & mask)) {
+            return (types & VIRTIO_NET_RSS_HASH_TYPE_UDP_EX) ?
+                NetPktRssIpV6UdpEx : NetPktRssIpV6Udp;
+        }
+        mask = VIRTIO_NET_RSS_HASH_TYPE_IP_EX | VIRTIO_NET_RSS_HASH_TYPE_IPv6;
+        if (types & mask) {
+            return (types & VIRTIO_NET_RSS_HASH_TYPE_IP_EX) ?
+                NetPktRssIpV6Ex : NetPktRssIpV6;
+        }
+    }
+    return 0xff;
+}
+
+static int virtio_net_process_rss(NetClientState *nc, const uint8_t *buf,
+                                  size_t size)
+{
+    VirtIONet *n = qemu_get_nic_opaque(nc);
+    unsigned int index = nc->queue_index, new_index;
+    struct NetRxPkt *pkt = n->rss_data.pkt;
+    uint8_t net_hash_type;
+    uint32_t hash;
+    bool isip4, isip6, isudp, istcp;
+    net_rx_pkt_set_protocols(pkt, buf + n->host_hdr_len,
+                             size - n->host_hdr_len);
+    net_rx_pkt_get_protocols(pkt, &isip4, &isip6, &isudp, &istcp);
+    if (isip4 && (net_rx_pkt_get_ip4_info(pkt)->fragment)) {
+        istcp = isudp = false;
+    }
+    if (isip6 && (net_rx_pkt_get_ip6_info(pkt)->fragment)) {
+        istcp = isudp = false;
+    }
+    net_hash_type = virtio_net_get_hash_type(isip4, isip6, isudp, istcp,
+                                             n->rss_data.hash_types);
+    if (net_hash_type > NetPktRssIpV6UdpEx) {
+        return n->rss_data.default_queue;
+    }
+
+    hash = net_rx_pkt_calc_rss_hash(pkt, net_hash_type, n->rss_data.key);
+    new_index = hash & (n->rss_data.indirections_len - 1);
+    new_index = n->rss_data.indirections[new_index];
+    if (index == new_index) {
+        return -1;
+    }
+    return new_index;
+}
+
 static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf,
-                                      size_t size)
+                                      size_t size, bool no_rss)
 {
     VirtIONet *n = qemu_get_nic_opaque(nc);
     VirtIONetQueue *q = virtio_net_get_subqueue(nc);
@@ -1530,6 +1601,14 @@ static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf,
         return -1;
     }
 
+    if (!no_rss && n->rss_data.enabled) {
+        int index = virtio_net_process_rss(nc, buf, size);
+        if (index >= 0) {
+            NetClientState *nc2 = qemu_get_subqueue(n->nic, index);
+            return virtio_net_receive_rcu(nc2, buf, size, true);
+        }
+    }
+
     /* hdr_len refers to the header we supply to the guest */
     if (!virtio_net_has_buffers(q, size + n->guest_hdr_len - n->host_hdr_len)) {
         return 0;
@@ -1624,7 +1703,7 @@ static ssize_t virtio_net_do_receive(NetClientState *nc, const uint8_t *buf,
 {
     RCU_READ_LOCK_GUARD();
 
-    return virtio_net_receive_rcu(nc, buf, size);
+    return virtio_net_receive_rcu(nc, buf, size, false);
 }
 
 static void virtio_net_rsc_extract_unit4(VirtioNetRscChain *chain,
@@ -3200,6 +3279,8 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
 
     QTAILQ_INIT(&n->rsc_chains);
     n->qdev = dev;
+
+    net_rx_pkt_init(&n->rss_data.pkt, false);
 }
 
 static void virtio_net_device_unrealize(DeviceState *dev, Error **errp)
@@ -3236,6 +3317,7 @@ static void virtio_net_device_unrealize(DeviceState *dev, Error **errp)
     g_free(n->vqs);
     qemu_del_nic(n->nic);
     virtio_net_rsc_cleanup(n);
+    net_rx_pkt_uninit(n->rss_data.pkt);
     virtio_cleanup(vdev);
 }
 
include/hw/virtio/virtio-net.h +1 -0
index cf16f5192e..45670dd054 100644
@@ -209,6 +209,7 @@ struct VirtIONet {
         uint16_t indirections[VIRTIO_NET_RSS_MAX_TABLE_LEN];
         uint16_t indirections_len;
         uint16_t default_queue;
+        struct NetRxPkt *pkt;
     } rss_data;
 };
 
Signature · 1 line
2.17.1
#7 lore raw

Re: [PATCH 3/3] virtio-net: implement RX RSS processing

Quoted 48 lines · Yuri Benditovich

If VIRTIO_NET_F_RSS negotiated and RSS is enabled, process incoming packets, calculate packet's hash and place the packet into respective RX virtqueue.

---
 hw/net/virtio-net.c            | 86 +++++++++++++++++++++++++++++++++-
 include/hw/virtio/virtio-net.h |  1 +
 2 files changed, 85 insertions(+), 2 deletions(-)
hw/net/virtio-net.c +23 -0
index c5d21675a9..adf7b88d7a 100644
@@ -42,6 +42,7 @@
 #include "trace.h"
 #include "monitor/qdev.h"
 #include "hw/pci/pci.h"
+#include "net_rx_pkt.h"
 
 #define VIRTIO_NET_VM_VERSION    11
 
@@ -1515,8 +1516,78 @@ static int receive_filter(VirtIONet *n, const uint8_t *buf, int size)
     return 0;
 }
 
+static uint8_t virtio_net_get_hash_type(bool isip4,
+                                        bool isip6,
+                                        bool isudp,
+                                        bool istcp,
+                                        uint32_t types)
+{
+    uint32_t mask;
+    if (isip4) {
+        if (istcp && (types & VIRTIO_NET_RSS_HASH_TYPE_TCPv4)) {
+            return NetPktRssIpV4Tcp;
+        }
+        if (isudp && (types & VIRTIO_NET_RSS_HASH_TYPE_UDPv4)) {
+            return NetPktRssIpV4Udp;
+        }
+        if (types & VIRTIO_NET_RSS_HASH_TYPE_IPv4) {
+            return NetPktRssIpV4;
+        }
+    } else if (isip6) {
+        mask = VIRTIO_NET_RSS_HASH_TYPE_TCP_EX | VIRTIO_NET_RSS_HASH_TYPE_TCPv6;
+        if (istcp && (types & mask)) {
+            return (types & VIRTIO_NET_RSS_HASH_TYPE_TCP_EX) ?
+                NetPktRssIpV6TcpEx : NetPktRssIpV6Tcp;

hw/net/virtio-net.c static int receive_filter(VirtIONet *n, const uint8_t *buf, int size) · line 1550

Quoted 10 lines
hw/net/virtio-net.c +10 -0
+        }
+        mask = VIRTIO_NET_RSS_HASH_TYPE_UDP_EX | VIRTIO_NET_RSS_HASH_TYPE_UDPv6;
+        if (isudp && (types & mask)) {
+            return (types & VIRTIO_NET_RSS_HASH_TYPE_UDP_EX) ?
+                NetPktRssIpV6UdpEx : NetPktRssIpV6Udp;
+        }
+        mask = VIRTIO_NET_RSS_HASH_TYPE_IP_EX | VIRTIO_NET_RSS_HASH_TYPE_IPv6;
+        if (types & mask) {
+            return (types & VIRTIO_NET_RSS_HASH_TYPE_IP_EX) ?
+                NetPktRssIpV6Ex : NetPktRssIpV6;

BTW we really need to fix up hw/net/net_rx_pkt.h to match qemu coding style.
Could you do it pls?

Quoted 99 lines
hw/net/virtio-net.c +51 -2
+        }
+    }
+    return 0xff;
+}
+
+static int virtio_net_process_rss(NetClientState *nc, const uint8_t *buf,
+                                  size_t size)
+{
+    VirtIONet *n = qemu_get_nic_opaque(nc);
+    unsigned int index = nc->queue_index, new_index;
+    struct NetRxPkt *pkt = n->rss_data.pkt;
+    uint8_t net_hash_type;
+    uint32_t hash;
+    bool isip4, isip6, isudp, istcp;
+    net_rx_pkt_set_protocols(pkt, buf + n->host_hdr_len,
+                             size - n->host_hdr_len);
+    net_rx_pkt_get_protocols(pkt, &isip4, &isip6, &isudp, &istcp);
+    if (isip4 && (net_rx_pkt_get_ip4_info(pkt)->fragment)) {
+        istcp = isudp = false;
+    }
+    if (isip6 && (net_rx_pkt_get_ip6_info(pkt)->fragment)) {
+        istcp = isudp = false;
+    }
+    net_hash_type = virtio_net_get_hash_type(isip4, isip6, isudp, istcp,
+                                             n->rss_data.hash_types);
+    if (net_hash_type > NetPktRssIpV6UdpEx) {
+        return n->rss_data.default_queue;
+    }
+
+    hash = net_rx_pkt_calc_rss_hash(pkt, net_hash_type, n->rss_data.key);
+    new_index = hash & (n->rss_data.indirections_len - 1);
+    new_index = n->rss_data.indirections[new_index];
+    if (index == new_index) {
+        return -1;
+    }
+    return new_index;
+}
+
 static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf,
-                                      size_t size)
+                                      size_t size, bool no_rss)
 {
     VirtIONet *n = qemu_get_nic_opaque(nc);
     VirtIONetQueue *q = virtio_net_get_subqueue(nc);
@@ -1530,6 +1601,14 @@ static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf,
         return -1;
     }
 
+    if (!no_rss && n->rss_data.enabled) {
+        int index = virtio_net_process_rss(nc, buf, size);
+        if (index >= 0) {
+            NetClientState *nc2 = qemu_get_subqueue(n->nic, index);
+            return virtio_net_receive_rcu(nc2, buf, size, true);
+        }
+    }
+
     /* hdr_len refers to the header we supply to the guest */
     if (!virtio_net_has_buffers(q, size + n->guest_hdr_len - n->host_hdr_len)) {
         return 0;
@@ -1624,7 +1703,7 @@ static ssize_t virtio_net_do_receive(NetClientState *nc, const uint8_t *buf,
 {
     RCU_READ_LOCK_GUARD();
 
-    return virtio_net_receive_rcu(nc, buf, size);
+    return virtio_net_receive_rcu(nc, buf, size, false);
 }
 
 static void virtio_net_rsc_extract_unit4(VirtioNetRscChain *chain,
@@ -3200,6 +3279,8 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
 
     QTAILQ_INIT(&n->rsc_chains);
     n->qdev = dev;
+
+    net_rx_pkt_init(&n->rss_data.pkt, false);
 }
 
 static void virtio_net_device_unrealize(DeviceState *dev, Error **errp)
@@ -3236,6 +3317,7 @@ static void virtio_net_device_unrealize(DeviceState *dev, Error **errp)
     g_free(n->vqs);
     qemu_del_nic(n->nic);
     virtio_net_rsc_cleanup(n);
+    net_rx_pkt_uninit(n->rss_data.pkt);
     virtio_cleanup(vdev);
 }
 
include/hw/virtio/virtio-net.h +1 -0
index cf16f5192e..45670dd054 100644
@@ -209,6 +209,7 @@ struct VirtIONet {
         uint16_t indirections[VIRTIO_NET_RSS_MAX_TABLE_LEN];
         uint16_t indirections_len;
         uint16_t default_queue;
+        struct NetRxPkt *pkt;
     } rss_data;
 };
 
Signature · 1 line
2.17.1
#8 lore raw

Re: [PATCH 3/3] virtio-net: implement RX RSS processing

Quoted 57 lines · Michael S. Tsirkin
Quoted 55 lines · Yuri Benditovich

If VIRTIO_NET_F_RSS negotiated and RSS is enabled, process incoming packets, calculate packet's hash and place the packet into respective RX virtqueue.

---
 hw/net/virtio-net.c            | 86 +++++++++++++++++++++++++++++++++-
 include/hw/virtio/virtio-net.h |  1 +
 2 files changed, 85 insertions(+), 2 deletions(-)
hw/net/virtio-net.c +30 -0
index c5d21675a9..adf7b88d7a 100644
@@ -42,6 +42,7 @@
 #include "trace.h"
 #include "monitor/qdev.h"
 #include "hw/pci/pci.h"
+#include "net_rx_pkt.h"
 
 #define VIRTIO_NET_VM_VERSION    11
 
@@ -1515,8 +1516,78 @@ static int receive_filter(VirtIONet *n, const uint8_t *buf, int size)
     return 0;
 }
 
+static uint8_t virtio_net_get_hash_type(bool isip4,
+                                        bool isip6,
+                                        bool isudp,
+                                        bool istcp,
+                                        uint32_t types)
+{
+    uint32_t mask;
+    if (isip4) {
+        if (istcp && (types & VIRTIO_NET_RSS_HASH_TYPE_TCPv4)) {
+            return NetPktRssIpV4Tcp;
+        }
+        if (isudp && (types & VIRTIO_NET_RSS_HASH_TYPE_UDPv4)) {
+            return NetPktRssIpV4Udp;
+        }
+        if (types & VIRTIO_NET_RSS_HASH_TYPE_IPv4) {
+            return NetPktRssIpV4;
+        }
+    } else if (isip6) {
+        mask = VIRTIO_NET_RSS_HASH_TYPE_TCP_EX | VIRTIO_NET_RSS_HASH_TYPE_TCPv6;
+        if (istcp && (types & mask)) {
+            return (types & VIRTIO_NET_RSS_HASH_TYPE_TCP_EX) ?
+                NetPktRssIpV6TcpEx : NetPktRssIpV6Tcp;
+        }
+        mask = VIRTIO_NET_RSS_HASH_TYPE_UDP_EX | VIRTIO_NET_RSS_HASH_TYPE_UDPv6;
+        if (isudp && (types & mask)) {
+            return (types & VIRTIO_NET_RSS_HASH_TYPE_UDP_EX) ?
+                NetPktRssIpV6UdpEx : NetPktRssIpV6Udp;
+        }
+        mask = VIRTIO_NET_RSS_HASH_TYPE_IP_EX | VIRTIO_NET_RSS_HASH_TYPE_IPv6;
Quoted 9 lines

hw/net/virtio-net.c static int receive_filter(VirtIONet *n, const uint8_t *buf, int size) · line 1550

Quoted 3 lines
hw/net/virtio-net.c +3 -0
+        if (types & mask) {
+            return (types & VIRTIO_NET_RSS_HASH_TYPE_IP_EX) ?
+                NetPktRssIpV6Ex : NetPktRssIpV6;

BTW we really need to fix up hw/net/net_rx_pkt.h to match qemu coding style.
Could you do it pls?

Can you please point on exact style problem in net_rx_pkt.h?

Quoted 100 lines
Quoted 99 lines
hw/net/virtio-net.c +51 -2
+        }
+    }
+    return 0xff;
+}
+
+static int virtio_net_process_rss(NetClientState *nc, const uint8_t *buf,
+                                  size_t size)
+{
+    VirtIONet *n = qemu_get_nic_opaque(nc);
+    unsigned int index = nc->queue_index, new_index;
+    struct NetRxPkt *pkt = n->rss_data.pkt;
+    uint8_t net_hash_type;
+    uint32_t hash;
+    bool isip4, isip6, isudp, istcp;
+    net_rx_pkt_set_protocols(pkt, buf + n->host_hdr_len,
+                             size - n->host_hdr_len);
+    net_rx_pkt_get_protocols(pkt, &isip4, &isip6, &isudp, &istcp);
+    if (isip4 && (net_rx_pkt_get_ip4_info(pkt)->fragment)) {
+        istcp = isudp = false;
+    }
+    if (isip6 && (net_rx_pkt_get_ip6_info(pkt)->fragment)) {
+        istcp = isudp = false;
+    }
+    net_hash_type = virtio_net_get_hash_type(isip4, isip6, isudp, istcp,
+                                             n->rss_data.hash_types);
+    if (net_hash_type > NetPktRssIpV6UdpEx) {
+        return n->rss_data.default_queue;
+    }
+
+    hash = net_rx_pkt_calc_rss_hash(pkt, net_hash_type, n->rss_data.key);
+    new_index = hash & (n->rss_data.indirections_len - 1);
+    new_index = n->rss_data.indirections[new_index];
+    if (index == new_index) {
+        return -1;
+    }
+    return new_index;
+}
+
 static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf,
-                                      size_t size)
+                                      size_t size, bool no_rss)
 {
     VirtIONet *n = qemu_get_nic_opaque(nc);
     VirtIONetQueue *q = virtio_net_get_subqueue(nc);
@@ -1530,6 +1601,14 @@ static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf,
         return -1;
     }
 
+    if (!no_rss && n->rss_data.enabled) {
+        int index = virtio_net_process_rss(nc, buf, size);
+        if (index >= 0) {
+            NetClientState *nc2 = qemu_get_subqueue(n->nic, index);
+            return virtio_net_receive_rcu(nc2, buf, size, true);
+        }
+    }
+
     /* hdr_len refers to the header we supply to the guest */
     if (!virtio_net_has_buffers(q, size + n->guest_hdr_len - n->host_hdr_len)) {
         return 0;
@@ -1624,7 +1703,7 @@ static ssize_t virtio_net_do_receive(NetClientState *nc, const uint8_t *buf,
 {
     RCU_READ_LOCK_GUARD();
 
-    return virtio_net_receive_rcu(nc, buf, size);
+    return virtio_net_receive_rcu(nc, buf, size, false);
 }
 
 static void virtio_net_rsc_extract_unit4(VirtioNetRscChain *chain,
@@ -3200,6 +3279,8 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
 
     QTAILQ_INIT(&n->rsc_chains);
     n->qdev = dev;
+
+    net_rx_pkt_init(&n->rss_data.pkt, false);
 }
 
 static void virtio_net_device_unrealize(DeviceState *dev, Error **errp)
@@ -3236,6 +3317,7 @@ static void virtio_net_device_unrealize(DeviceState *dev, Error **errp)
     g_free(n->vqs);
     qemu_del_nic(n->nic);
     virtio_net_rsc_cleanup(n);
+    net_rx_pkt_uninit(n->rss_data.pkt);
     virtio_cleanup(vdev);
 }
 
include/hw/virtio/virtio-net.h +1 -1
index cf16f5192e..45670dd054 100644
@@ -209,6 +209,7 @@ struct VirtIONet {
         uint16_t indirections[VIRTIO_NET_RSS_MAX_TABLE_LEN];
         uint16_t indirections_len;
         uint16_t default_queue;
+        struct NetRxPkt *pkt;
     } rss_data;
 };
 
--

2.17.1

#9 lore raw

Re: [PATCH 3/3] virtio-net: implement RX RSS processing

Quoted 68 lines · Yuri Benditovich
Quoted 57 lines · Michael S. Tsirkin
Quoted 55 lines · Yuri Benditovich

If VIRTIO_NET_F_RSS negotiated and RSS is enabled, process incoming packets, calculate packet's hash and place the packet into respective RX virtqueue.

---
 hw/net/virtio-net.c            | 86 +++++++++++++++++++++++++++++++++-
 include/hw/virtio/virtio-net.h |  1 +
 2 files changed, 85 insertions(+), 2 deletions(-)
hw/net/virtio-net.c +30 -0
index c5d21675a9..adf7b88d7a 100644
@@ -42,6 +42,7 @@
 #include "trace.h"
 #include "monitor/qdev.h"
 #include "hw/pci/pci.h"
+#include "net_rx_pkt.h"
 
 #define VIRTIO_NET_VM_VERSION    11
 
@@ -1515,8 +1516,78 @@ static int receive_filter(VirtIONet *n, const uint8_t *buf, int size)
     return 0;
 }
 
+static uint8_t virtio_net_get_hash_type(bool isip4,
+                                        bool isip6,
+                                        bool isudp,
+                                        bool istcp,
+                                        uint32_t types)
+{
+    uint32_t mask;
+    if (isip4) {
+        if (istcp && (types & VIRTIO_NET_RSS_HASH_TYPE_TCPv4)) {
+            return NetPktRssIpV4Tcp;
+        }
+        if (isudp && (types & VIRTIO_NET_RSS_HASH_TYPE_UDPv4)) {
+            return NetPktRssIpV4Udp;
+        }
+        if (types & VIRTIO_NET_RSS_HASH_TYPE_IPv4) {
+            return NetPktRssIpV4;
+        }
+    } else if (isip6) {
+        mask = VIRTIO_NET_RSS_HASH_TYPE_TCP_EX | VIRTIO_NET_RSS_HASH_TYPE_TCPv6;
+        if (istcp && (types & mask)) {
+            return (types & VIRTIO_NET_RSS_HASH_TYPE_TCP_EX) ?
+                NetPktRssIpV6TcpEx : NetPktRssIpV6Tcp;
+        }
+        mask = VIRTIO_NET_RSS_HASH_TYPE_UDP_EX | VIRTIO_NET_RSS_HASH_TYPE_UDPv6;
+        if (isudp && (types & mask)) {
+            return (types & VIRTIO_NET_RSS_HASH_TYPE_UDP_EX) ?
+                NetPktRssIpV6UdpEx : NetPktRssIpV6Udp;
+        }
+        mask = VIRTIO_NET_RSS_HASH_TYPE_IP_EX | VIRTIO_NET_RSS_HASH_TYPE_IPv6;
Quoted 9 lines

hw/net/virtio-net.c static int receive_filter(VirtIONet *n, const uint8_t *buf, int size) · line 1550

Quoted 3 lines
hw/net/virtio-net.c +3 -0
+        if (types & mask) {
+            return (types & VIRTIO_NET_RSS_HASH_TYPE_IP_EX) ?
+                NetPktRssIpV6Ex : NetPktRssIpV6;

BTW we really need to fix up hw/net/net_rx_pkt.h to match qemu coding style.
Could you do it pls?

Quoted 1 line

Can you please point on exact style problem in net_rx_pkt.h?

Two issues that I noticed:

- Use of "struct" instead of a typedef with struct names.
- Mixed case for enum values instead of upper case.

Quoted 100 lines
Quoted 100 lines
Quoted 99 lines
hw/net/virtio-net.c +51 -2
+        }
+    }
+    return 0xff;
+}
+
+static int virtio_net_process_rss(NetClientState *nc, const uint8_t *buf,
+                                  size_t size)
+{
+    VirtIONet *n = qemu_get_nic_opaque(nc);
+    unsigned int index = nc->queue_index, new_index;
+    struct NetRxPkt *pkt = n->rss_data.pkt;
+    uint8_t net_hash_type;
+    uint32_t hash;
+    bool isip4, isip6, isudp, istcp;
+    net_rx_pkt_set_protocols(pkt, buf + n->host_hdr_len,
+                             size - n->host_hdr_len);
+    net_rx_pkt_get_protocols(pkt, &isip4, &isip6, &isudp, &istcp);
+    if (isip4 && (net_rx_pkt_get_ip4_info(pkt)->fragment)) {
+        istcp = isudp = false;
+    }
+    if (isip6 && (net_rx_pkt_get_ip6_info(pkt)->fragment)) {
+        istcp = isudp = false;
+    }
+    net_hash_type = virtio_net_get_hash_type(isip4, isip6, isudp, istcp,
+                                             n->rss_data.hash_types);
+    if (net_hash_type > NetPktRssIpV6UdpEx) {
+        return n->rss_data.default_queue;
+    }
+
+    hash = net_rx_pkt_calc_rss_hash(pkt, net_hash_type, n->rss_data.key);
+    new_index = hash & (n->rss_data.indirections_len - 1);
+    new_index = n->rss_data.indirections[new_index];
+    if (index == new_index) {
+        return -1;
+    }
+    return new_index;
+}
+
 static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf,
-                                      size_t size)
+                                      size_t size, bool no_rss)
 {
     VirtIONet *n = qemu_get_nic_opaque(nc);
     VirtIONetQueue *q = virtio_net_get_subqueue(nc);
@@ -1530,6 +1601,14 @@ static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf,
         return -1;
     }
 
+    if (!no_rss && n->rss_data.enabled) {
+        int index = virtio_net_process_rss(nc, buf, size);
+        if (index >= 0) {
+            NetClientState *nc2 = qemu_get_subqueue(n->nic, index);
+            return virtio_net_receive_rcu(nc2, buf, size, true);
+        }
+    }
+
     /* hdr_len refers to the header we supply to the guest */
     if (!virtio_net_has_buffers(q, size + n->guest_hdr_len - n->host_hdr_len)) {
         return 0;
@@ -1624,7 +1703,7 @@ static ssize_t virtio_net_do_receive(NetClientState *nc, const uint8_t *buf,
 {
     RCU_READ_LOCK_GUARD();
 
-    return virtio_net_receive_rcu(nc, buf, size);
+    return virtio_net_receive_rcu(nc, buf, size, false);
 }
 
 static void virtio_net_rsc_extract_unit4(VirtioNetRscChain *chain,
@@ -3200,6 +3279,8 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
 
     QTAILQ_INIT(&n->rsc_chains);
     n->qdev = dev;
+
+    net_rx_pkt_init(&n->rss_data.pkt, false);
 }
 
 static void virtio_net_device_unrealize(DeviceState *dev, Error **errp)
@@ -3236,6 +3317,7 @@ static void virtio_net_device_unrealize(DeviceState *dev, Error **errp)
     g_free(n->vqs);
     qemu_del_nic(n->nic);
     virtio_net_rsc_cleanup(n);
+    net_rx_pkt_uninit(n->rss_data.pkt);
     virtio_cleanup(vdev);
 }
 
include/hw/virtio/virtio-net.h +1 -1
index cf16f5192e..45670dd054 100644
@@ -209,6 +209,7 @@ struct VirtIONet {
         uint16_t indirections[VIRTIO_NET_RSS_MAX_TABLE_LEN];
         uint16_t indirections_len;
         uint16_t default_queue;
+        struct NetRxPkt *pkt;
     } rss_data;
 };
 
--

2.17.1

#10 lore raw

Re: [PATCH 3/3] virtio-net: implement RX RSS processing

Quoted 75 lines · Michael S. Tsirkin
Quoted 1 line · Yuri Benditovich

On Thu, Mar 5, 2020 at 3:20 PM Michael S. Tsirkin <[email protected]>

Quoted 9 lines · wrote:
Quoted 9 lines · Yuri Benditovich
Quoted 7 lines

If VIRTIO_NET_F_RSS negotiated and RSS is enabled, process incoming packets, calculate packet's hash and place the packet into respective RX virtqueue.

---
 hw/net/virtio-net.c            | 86

+++++++++++++++++++++++++++++++++-

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
 include/hw/virtio/virtio-net.h |  1 +
 2 files changed, 85 insertions(+), 2 deletions(-)
hw/net/virtio-net.c +1 -0
index c5d21675a9..adf7b88d7a 100644
@@ -42,6 +42,7 @@
 #include "trace.h"
 #include "monitor/qdev.h"
 #include "hw/pci/pci.h"
+#include "net_rx_pkt.h"
 
Quoted 3 lines
Quoted 3 lines

hw/net/virtio-net.c static int receive_filter(VirtIONet *n, const

Quoted 3 lines
hw/net/virtio-net.c +0 -0
 #define VIRTIO_NET_VM_VERSION    11
 
@@ -1515,8 +1516,78 @@ static int receive_filter(VirtIONet *n, const

uint8_t *buf, int size)

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
hw/net/virtio-net.c +11 -0
     return 0;
 }
 
+static uint8_t virtio_net_get_hash_type(bool isip4,
+                                        bool isip6,
+                                        bool isudp,
+                                        bool istcp,
+                                        uint32_t types)
+{
+    uint32_t mask;
+    if (isip4) {
+        if (istcp && (types & VIRTIO_NET_RSS_HASH_TYPE_TCPv4)) {
+            return NetPktRssIpV4Tcp;
+        }
Quoted 8 lines
Quoted 8 lines

hw/net/virtio-net.c static int receive_filter(VirtIONet *n, const uint8_t *buf, int size)

Quoted 8 lines
hw/net/virtio-net.c +8 -0
+        if (isudp && (types & VIRTIO_NET_RSS_HASH_TYPE_UDPv4)) {
+            return NetPktRssIpV4Udp;
+        }
+        if (types & VIRTIO_NET_RSS_HASH_TYPE_IPv4) {
+            return NetPktRssIpV4;
+        }
+    } else if (isip6) {
+        mask = VIRTIO_NET_RSS_HASH_TYPE_TCP_EX |

VIRTIO_NET_RSS_HASH_TYPE_TCPv6;

Quoted 5 lines
Quoted 5 lines

hw/net/virtio-net.c static int receive_filter(VirtIONet *n, const uint8_t *buf, int size)

Quoted 5 lines
hw/net/virtio-net.c +5 -0
+        if (istcp && (types & mask)) {
+            return (types & VIRTIO_NET_RSS_HASH_TYPE_TCP_EX) ?
+                NetPktRssIpV6TcpEx : NetPktRssIpV6Tcp;
+        }
+        mask = VIRTIO_NET_RSS_HASH_TYPE_UDP_EX |

VIRTIO_NET_RSS_HASH_TYPE_UDPv6;

Quoted 5 lines
Quoted 5 lines

hw/net/virtio-net.c static int receive_filter(VirtIONet *n, const uint8_t *buf, int size)

Quoted 5 lines
hw/net/virtio-net.c +5 -0
+        if (isudp && (types & mask)) {
+            return (types & VIRTIO_NET_RSS_HASH_TYPE_UDP_EX) ?
+                NetPktRssIpV6UdpEx : NetPktRssIpV6Udp;
+        }
+        mask = VIRTIO_NET_RSS_HASH_TYPE_IP_EX |

VIRTIO_NET_RSS_HASH_TYPE_IPv6;

Quoted 10 lines
Quoted 9 lines

hw/net/virtio-net.c static int receive_filter(VirtIONet *n, const uint8_t *buf, int size) · line 1550

Quoted 3 lines
hw/net/virtio-net.c +3 -0
+        if (types & mask) {
+            return (types & VIRTIO_NET_RSS_HASH_TYPE_IP_EX) ?
+                NetPktRssIpV6Ex : NetPktRssIpV6;

BTW we really need to fix up hw/net/net_rx_pkt.h to match qemu coding style.
Could you do it pls?

Quoted 8 lines
Quoted 1 line

Can you please point on exact style problem in net_rx_pkt.h?

Two issues that I noticed:

- Use of "struct" instead of a typedef with struct names.
- Mixed case for enum values instead of upper case.

I will discuss it with the maintainer of net_rx_pkt.
Note that struct without typedef especially allowed by qemu coding style doc.
Note also that the doc rather requires camel case for enums and both uppercase and camel case are widely used in the code.

Quoted 116 lines
Quoted 8 lines
Quoted 8 lines

hw/net/virtio-net.c static int receive_filter(VirtIONet *n, const uint8_t *buf, int size)

Quoted 8 lines
hw/net/virtio-net.c +6 -0
+        }
+    }
+    return 0xff;
+}
+
+static int virtio_net_process_rss(NetClientState *nc, const uint8_t

*buf,

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
hw/net/virtio-net.c +10 -0
+                                  size_t size)
+{
+    VirtIONet *n = qemu_get_nic_opaque(nc);
+    unsigned int index = nc->queue_index, new_index;
+    struct NetRxPkt *pkt = n->rss_data.pkt;
+    uint8_t net_hash_type;
+    uint32_t hash;
+    bool isip4, isip6, isudp, istcp;
+    net_rx_pkt_set_protocols(pkt, buf + n->host_hdr_len,
+                             size - n->host_hdr_len);
Quoted 8 lines
Quoted 8 lines

hw/net/virtio-net.c static int receive_filter(VirtIONet *n, const uint8_t *buf, int size)

Quoted 8 lines
hw/net/virtio-net.c +8 -0
+    net_rx_pkt_get_protocols(pkt, &isip4, &isip6, &isudp, &istcp);
+    if (isip4 && (net_rx_pkt_get_ip4_info(pkt)->fragment)) {
+        istcp = isudp = false;
+    }
+    if (isip6 && (net_rx_pkt_get_ip6_info(pkt)->fragment)) {
+        istcp = isudp = false;
+    }
+    net_hash_type = virtio_net_get_hash_type(isip4, isip6, isudp,

istcp,

Quoted 1 line
Quoted 1 line

hw/net/virtio-net.c static int receive_filter(VirtIONet *n, const · line 1575

Quoted 1 line
hw/net/virtio-net.c +1 -0
+

n->rss_data.hash_types);

Quoted 5 lines
Quoted 5 lines

hw/net/virtio-net.c static int receive_filter(VirtIONet *n, const uint8_t *buf, int size)

Quoted 5 lines
hw/net/virtio-net.c +5 -0
+    if (net_hash_type > NetPktRssIpV6UdpEx) {
+        return n->rss_data.default_queue;
+    }
+
+    hash = net_rx_pkt_calc_rss_hash(pkt, net_hash_type,

n->rss_data.key);

Quoted 9 lines
Quoted 9 lines

hw/net/virtio-net.c static int receive_filter(VirtIONet *n, const uint8_t *buf, int size)

Quoted 9 lines
hw/net/virtio-net.c +8 -0
+    new_index = hash & (n->rss_data.indirections_len - 1);
+    new_index = n->rss_data.indirections[new_index];
+    if (index == new_index) {
+        return -1;
+    }
+    return new_index;
+}
+
 static ssize_t virtio_net_receive_rcu(NetClientState *nc, const

uint8_t *buf,

Quoted 6 lines
Quoted 6 lines

hw/net/virtio-net.c static ssize_t

Quoted 6 lines
hw/net/virtio-net.c +1 -1
-                                      size_t size)
+                                      size_t size, bool no_rss)
 {
     VirtIONet *n = qemu_get_nic_opaque(nc);
     VirtIONetQueue *q = virtio_net_get_subqueue(nc);
@@ -1530,6 +1601,14 @@ static ssize_t

virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf,

Quoted 13 lines
Quoted 13 lines

hw/net/virtio-net.c static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf,

Quoted 13 lines
hw/net/virtio-net.c +8 -0
         return -1;
     }
 
+    if (!no_rss && n->rss_data.enabled) {
+        int index = virtio_net_process_rss(nc, buf, size);
+        if (index >= 0) {
+            NetClientState *nc2 = qemu_get_subqueue(n->nic, index);
+            return virtio_net_receive_rcu(nc2, buf, size, true);
+        }
+    }
+
     /* hdr_len refers to the header we supply to the guest */
     if (!virtio_net_has_buffers(q, size + n->guest_hdr_len -

n->host_hdr_len)) {

Quoted 2 lines
Quoted 2 lines

hw/net/virtio-net.c static ssize_t

Quoted 2 lines
hw/net/virtio-net.c +0 -0
         return 0;
@@ -1624,7 +1703,7 @@ static ssize_t

virtio_net_do_receive(NetClientState *nc, const uint8_t *buf,

Quoted 9 lines
Quoted 9 lines

hw/net/virtio-net.c static void

Quoted 9 lines
hw/net/virtio-net.c +1 -1
 {
     RCU_READ_LOCK_GUARD();
 
-    return virtio_net_receive_rcu(nc, buf, size);
+    return virtio_net_receive_rcu(nc, buf, size, false);
 }
 
 static void virtio_net_rsc_extract_unit4(VirtioNetRscChain *chain,
@@ -3200,6 +3279,8 @@ static void

virtio_net_device_realize(DeviceState *dev, Error **errp)

Quoted 8 lines
Quoted 8 lines

hw/net/virtio-net.c static void virtio_net_device_realize(DeviceState *dev, Error **errp)

Quoted 8 lines
hw/net/virtio-net.c +2 -0
     QTAILQ_INIT(&n->rsc_chains);
     n->qdev = dev;
+
+    net_rx_pkt_init(&n->rss_data.pkt, false);
 }
 
 static void virtio_net_device_unrealize(DeviceState *dev, Error

**errp)

Quoted 1 line
Quoted 1 line

hw/net/virtio-net.c static void

Quoted 1 line
hw/net/virtio-net.c +0 -0
@@ -3236,6 +3317,7 @@ static void

virtio_net_device_unrealize(DeviceState *dev, Error **errp)

Quoted 8 lines
Quoted 8 lines

Review

Quoted 8 lines
hw/net/virtio-net.c +1 -0
     g_free(n->vqs);
     qemu_del_nic(n->nic);
     virtio_net_rsc_cleanup(n);
+    net_rx_pkt_uninit(n->rss_data.pkt);
     virtio_cleanup(vdev);
 }
 
(quoted diff) +0 -0

b/include/hw/virtio/virtio-net.h

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

index cf16f5192e..45670dd054 100644

include/hw/virtio/virtio-net.h +1 -1
@@ -209,6 +209,7 @@ struct VirtIONet {
         uint16_t indirections[VIRTIO_NET_RSS_MAX_TABLE_LEN];
         uint16_t indirections_len;
         uint16_t default_queue;
+        struct NetRxPkt *pkt;
     } rss_data;
 };
 
--

2.17.1

#11 lore raw
In reply to Yuri Benditovich

ping

Quoted 23 lines · Yuri Benditovich

Support for VIRTIO_NET_F_RSS feature in QEMU for reference purpose. Implements Toeplitz hash calculation for incoming packets according to configuration provided by driver.

This series requires previously submitted and accepted patch to be applied:
https://lists.gnu.org/archive/html/qemu-devel/2020-01/msg06448.html

Yuri Benditovich (3):
virtio-net: introduce RSS RX steering feature
virtio-net: implement RSS configuration command
virtio-net: implement RX RSS processing

 hw/net/trace-events                         |   3 +
 hw/net/virtio-net.c                         | 234 +++++++++++++++++++-VIRTIO_NET_F_RSS
 include/hw/virtio/virtio-net.h              |  12 +
 include/standard-headers/linux/virtio_net.h |  37 +++-
 4 files changed, 273 insertions(+), 13 deletions(-)

--
2.17.1

#12 lore raw
In reply to Yuri Benditovich
Quoted 13 lines · Yuri Benditovich

Support for VIRTIO_NET_F_RSS feature in QEMU for reference purpose. Implements Toeplitz hash calculation for incoming packets according to configuration provided by driver.

This series requires previously submitted and accepted patch to be applied:
https://lists.gnu.org/archive/html/qemu-devel/2020-01/msg06448.html

Yuri Benditovich (3):
virtio-net: introduce RSS RX steering feature
virtio-net: implement RSS configuration command
virtio-net: implement RX RSS processing

Quoted 6 lines
  hw/net/trace-events                         |   3 +
  hw/net/virtio-net.c                         | 234 +++++++++++++++++++-VIRTIO_NET_F_RSS
  include/hw/virtio/virtio-net.h              |  12 +
  include/standard-headers/linux/virtio_net.h |  37 +++-
  4 files changed, 273 insertions(+), 13 deletions(-)

One question before the reviewing.

Do we need to deal with migration (which I think yes)?

Thanks

#13 lore raw
Quoted 18 lines · Jason Wang
Quoted 8 lines · Yuri Benditovich

Support for VIRTIO_NET_F_RSS feature in QEMU for reference purpose. Implements Toeplitz hash calculation for incoming packets according to configuration provided by driver.

This series requires previously submitted and accepted patch to be applied:
https://lists.gnu.org/archive/html/qemu-devel/2020-01/msg06448.html

Quoted 7 lines

Yuri Benditovich (3):
virtio-net: introduce RSS RX steering feature
virtio-net: implement RSS configuration command
virtio-net: implement RX RSS processing

  hw/net/trace-events                         |   3 +
  hw/net/virtio-net.c                         | 234

+++++++++++++++++++-VIRTIO_NET_F_RSS

Quoted 9 lines
Quoted 4 lines
  include/hw/virtio/virtio-net.h              |  12 +
  include/standard-headers/linux/virtio_net.h |  37 +++-
  4 files changed, 273 insertions(+), 13 deletions(-)

One question before the reviewing.

Do we need to deal with migration (which I think yes)?

I think we don't (yet) as this is a reference implementation and the main goal is to provide the functional reference for hardware solution. I agree with the general direction that for complete support of RSS and hash delivery the best way is to do that in kernel using bpf. For that, IMO, the bpf should be a part of the kernel (it uses skb fields) and the tap should receive just RSS parameters for it.
At this stage we definitely will need to add migration support and propagation of RSS parameters.

Quoted 4 lines

Thanks

#14 lore raw
Quoted 27 lines · Yuri Benditovich

On Fri, Mar 6, 2020 at 11:27 AM Jason Wang <[email protected]> wrote:

On 2020/2/27 上午1:48, Yuri Benditovich wrote:
> Support for VIRTIO_NET_F_RSS feature in QEMU for reference > purpose. Implements Toeplitz hash calculation for incoming > packets according to configuration provided by driver. >
> This series requires previously submitted and accepted > patch to be applied:
> https://lists.gnu.org/archive/html/qemu-devel/2020-01/msg06448.html
>
> Yuri Benditovich (3):
>    virtio-net: introduce RSS RX steering feature
>    virtio-net: implement RSS configuration command
>    virtio-net: implement RX RSS processing
>
>   hw/net/trace-events                         |   3 +
>   hw/net/virtio-net.c                         | 234 +++++++++++++++++++-VIRTIO_NET_F_RSS
>   include/hw/virtio/virtio-net.h              |  12 +
>   include/standard-headers/linux/virtio_net.h |  37 +++- >   4 files changed, 273 insertions(+), 13 deletions(-)
>

Quoted 7 lines

One question before the reviewing.

Do we need to deal with migration (which I think yes)?

I think we don't (yet) as this is a reference implementation and the main goal is to provide the functional reference for hardware solution.

That's fine, but then we must block migration, and add appropriate code comments. Just silently losing data isn't a good idea.

Quoted 12 lines

I agree with the general direction that for complete support of RSS and hash delivery the best way is to do that in kernel using bpf.
For that, IMO, the bpf should be a part of the kernel (it uses skb fields) and the tap should receive just RSS parameters for it.
At this stage we definitely will need to add migration support and propagation of RSS parameters.

Thanks

#15 lore raw
Quoted 34 lines · Michael S. Tsirkin
Quoted 32 lines · Yuri Benditovich

On Fri, Mar 6, 2020 at 11:27 AM Jason Wang <[email protected]> wrote:

On 2020/2/27 上午1:48, Yuri Benditovich wrote:
> Support for VIRTIO_NET_F_RSS feature in QEMU for reference > purpose. Implements Toeplitz hash calculation for incoming > packets according to configuration provided by driver. >
> This series requires previously submitted and accepted > patch to be applied:
> https://lists.gnu.org/archive/html/qemu-devel/2020-01/msg06448.html
>
> Yuri Benditovich (3):
> virtio-net: introduce RSS RX steering feature
> virtio-net: implement RSS configuration command
> virtio-net: implement RX RSS processing
>
> hw/net/trace-events | 3 +
> hw/net/virtio-net.c | 234
+++++++++++++++++++-VIRTIO_NET_F_RSS
> include/hw/virtio/virtio-net.h | 12 +
> include/standard-headers/linux/virtio_net.h | 37 +++-
> 4 files changed, 273 insertions(+), 13 deletions(-)
>

One question before the reviewing.

Do we need to deal with migration (which I think yes)?

Quoted 6 lines
Quoted 2 lines

I think we don't (yet) as this is a reference implementation and the main goal is to provide the functional reference for hardware solution.

That's fine, but then we must block migration, and add appropriate code comments. Just silently losing data isn't a good idea.

Note that there is no data lost, just the configuration of RSS is not migrating. So, qemu just will not redirect the data to different queues after migration. I would add the migration prevention in the next series with implementation of hash delivery to prevent different packet sizes in driver and qemu.

Quoted 14 lines
Quoted 13 lines

I agree with the general direction that for complete support of RSS and hash delivery the best way is to do that in kernel using bpf.
For that, IMO, the bpf should be a part of the kernel (it uses skb fields) and the tap should receive just RSS parameters for it.
At this stage we definitely will need to add migration support and propagation of RSS parameters.

Thanks

#16 lore raw
Quoted 39 lines · Yuri Benditovich
Quoted 38 lines · Michael S. Tsirkin
Quoted 34 lines · Yuri Benditovich

On Fri, Mar 6, 2020 at 11:27 AM Jason Wang <[email protected]> wrote:

On 2020/2/27 上午1:48, Yuri Benditovich wrote:
> Support for VIRTIO_NET_F_RSS feature in QEMU for reference > purpose. Implements Toeplitz hash calculation for incoming > packets according to configuration provided by driver. >
> This series requires previously submitted and accepted > patch to be applied:
> https://lists.gnu.org/archive/html/qemu-devel/2020-01/msg06448.html
>
> Yuri Benditovich (3):
> virtio-net: introduce RSS RX steering feature
> virtio-net: implement RSS configuration command
> virtio-net: implement RX RSS processing
>
> hw/net/trace-events | 3 +
> hw/net/virtio-net.c | 234
+++++++++++++++++++-VIRTIO_NET_F_RSS
> include/hw/virtio/virtio-net.h | 12 +
> include/standard-headers/linux/virtio_net.h | 37 +++-
> 4 files changed, 273 insertions(+), 13 deletions(-)
>

One question before the reviewing.

Do we need to deal with migration (which I think yes)?

I think we don't (yet) as this is a reference implementation and the main goal is to provide the functional reference for hardware solution.

Quoted 5 lines
Quoted 2 lines

That's fine, but then we must block migration, and add appropriate code comments. Just silently losing data isn't a good idea.

Note that there is no data lost, just the configuration of RSS is not migrating. So, qemu just will not redirect the data to different queues after migration.

Right. Unlike auto-mq, the spec doesn't say the direction is best effort though, so that would be a spec violation.

Quoted 3 lines

I would add the migration prevention in the next series with implementation of hash delivery to prevent different packet sizes in driver and qemu.

And hopefully full migration support will follow.

One other thing to check is vhost - I didn't check what happens with this patchset but
I think at a minimum we need to fail vhost init, until the backend implements the feature biit.

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

I agree with the general direction that for complete support of RSS and hash delivery the best way is to do that in kernel using bpf.
For that, IMO, the bpf should be a part of the kernel (it uses skb fields) and the tap should receive just RSS parameters for it.
At this stage we definitely will need to add migration support and propagation of RSS parameters.

Thanks

#17 lore raw
Quoted 54 lines · Michael S. Tsirkin
Quoted 39 lines · Yuri Benditovich
Quoted 38 lines · Michael S. Tsirkin
Quoted 34 lines · Yuri Benditovich

On Fri, Mar 6, 2020 at 11:27 AM Jason Wang <[email protected]> wrote:

On 2020/2/27 上午1:48, Yuri Benditovich wrote:
> Support for VIRTIO_NET_F_RSS feature in QEMU for reference > purpose. Implements Toeplitz hash calculation for incoming > packets according to configuration provided by driver. >
> This series requires previously submitted and accepted > patch to be applied:
> https://lists.gnu.org/archive/html/qemu-devel/2020-01/msg06448.html
>
> Yuri Benditovich (3):
> virtio-net: introduce RSS RX steering feature
> virtio-net: implement RSS configuration command
> virtio-net: implement RX RSS processing
>
> hw/net/trace-events | 3 +
> hw/net/virtio-net.c | 234
+++++++++++++++++++-VIRTIO_NET_F_RSS
> include/hw/virtio/virtio-net.h | 12 +
> include/standard-headers/linux/virtio_net.h | 37 +++-
> 4 files changed, 273 insertions(+), 13 deletions(-)
>

One question before the reviewing.

Do we need to deal with migration (which I think yes)?

I think we don't (yet) as this is a reference implementation and the main goal is to provide the functional reference for hardware solution.

Quoted 5 lines
Quoted 2 lines

That's fine, but then we must block migration, and add appropriate code comments. Just silently losing data isn't a good idea.

Note that there is no data lost, just the configuration of RSS is not migrating. So, qemu just will not redirect the data to different queues after migration.

Right. Unlike auto-mq, the spec doesn't say the direction is best effort though, so that would be a spec violation.

Quoted 3 lines

I would add the migration prevention in the next series with implementation of hash delivery to prevent different packet sizes in driver and qemu.

Quoted 6 lines

And hopefully full migration support will follow.

One other thing to check is vhost - I didn't check what happens with this patchset but
I think at a minimum we need to fail vhost init, until the backend implements the feature biit.

RSS feature currently is not indicated in case vhost is on. The same will be with hash report.

Quoted 17 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines

I agree with the general direction that for complete support of RSS and hash delivery the best way is to do that in kernel using bpf.
For that, IMO, the bpf should be a part of the kernel (it uses skb fields) and the tap should receive just RSS parameters for it.
At this stage we definitely will need to add migration support and propagation of RSS parameters.

Thanks

#18 lore raw
Quoted 57 lines · Yuri Benditovich
Quoted 56 lines · Michael S. Tsirkin
Quoted 39 lines · Yuri Benditovich
Quoted 38 lines · Michael S. Tsirkin
Quoted 34 lines · Yuri Benditovich

On Fri, Mar 6, 2020 at 11:27 AM Jason Wang <[email protected]> wrote:

On 2020/2/27 上午1:48, Yuri Benditovich wrote:
> Support for VIRTIO_NET_F_RSS feature in QEMU for reference > purpose. Implements Toeplitz hash calculation for incoming > packets according to configuration provided by driver. >
> This series requires previously submitted and accepted > patch to be applied:
> https://lists.gnu.org/archive/html/qemu-devel/2020-01/msg06448.html
>
> Yuri Benditovich (3):
> virtio-net: introduce RSS RX steering feature
> virtio-net: implement RSS configuration command
> virtio-net: implement RX RSS processing
>
> hw/net/trace-events | 3 +
> hw/net/virtio-net.c | 234
+++++++++++++++++++-VIRTIO_NET_F_RSS
> include/hw/virtio/virtio-net.h | 12 +
> include/standard-headers/linux/virtio_net.h | 37 +++-
> 4 files changed, 273 insertions(+), 13 deletions(-)
>

One question before the reviewing.

Do we need to deal with migration (which I think yes)?

I think we don't (yet) as this is a reference implementation and the main goal is to provide the functional reference for hardware solution.

Quoted 5 lines
Quoted 2 lines

That's fine, but then we must block migration, and add appropriate code comments. Just silently losing data isn't a good idea.

Note that there is no data lost, just the configuration of RSS is not migrating. So, qemu just will not redirect the data to different queues after migration.

Right. Unlike auto-mq, the spec doesn't say the direction is best effort though, so that would be a spec violation.

Quoted 3 lines

I would add the migration prevention in the next series with implementation of hash delivery to prevent different packet sizes in driver and qemu.

And hopefully full migration support will follow.

Quoted 7 lines
Quoted 4 lines

One other thing to check is vhost - I didn't check what happens with this patchset but
I think at a minimum we need to fail vhost init, until the backend implements the feature biit.

RSS feature currently is not indicated in case vhost is on. The same will be with hash report.

IIRC with vhost features not listed are assumed to be implemented by qemu and not to need backend support.

Maybe we should change that to make things more robust in the future ... Jason, Marc-André am I right? what do you think?

Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines

I agree with the general direction that for complete support of RSS and hash delivery the best way is to do that in kernel using bpf.
For that, IMO, the bpf should be a part of the kernel (it uses skb fields) and the tap should receive just RSS parameters for it.
At this stage we definitely will need to add migration support and propagation of RSS parameters.

Thanks