diff mbox series

[RFC,v3,09/11] virtio-net: Offload hashing without vhost

Message ID 20240915-hash-v3-9-79cb08d28647@daynix.com (mailing list archive)
State New, archived
Headers show
Series virtio-net: Offload hashing without eBPF | expand

Commit Message

Akihiko Odaki Sept. 15, 2024, 1:23 a.m. UTC
This is necessary to offload hashing to tap.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
 hw/net/virtio-net.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index be6759d1c0f4..72493b652bf5 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -1695,7 +1695,11 @@  static size_t receive_header(VirtIONet *n, struct virtio_net_hdr *hdr,
 {
     size_t hdr_len = n->guest_hdr_len;
 
-    memcpy(hdr, buf, sizeof(struct virtio_net_hdr));
+    memcpy(hdr, buf,
+           n->rss_data.populate_hash &&
+           n->rss_data.enabled && !n->rss_data.enabled_software_rss ?
+           sizeof(struct virtio_net_hdr_v1_hash) :
+           sizeof(struct virtio_net_hdr));
 
     *buf_offset = n->host_hdr_len;
     work_around_broken_dhclient(hdr, &hdr_len, buf, buf_size, buf_offset);
@@ -3072,11 +3076,13 @@  static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features,
     }
 
     if (!get_vhost_net(nc->peer)) {
-        if (!use_own_hash) {
-            virtio_clear_feature(&features, VIRTIO_NET_F_HASH_REPORT);
-            virtio_clear_feature(&features, VIRTIO_NET_F_RSS);
-        } else if (virtio_has_feature(features, VIRTIO_NET_F_RSS)) {
-            virtio_net_load_ebpf(n);
+        if (!use_peer_hash) {
+            if (!use_own_hash) {
+                virtio_clear_feature(&features, VIRTIO_NET_F_HASH_REPORT);
+                virtio_clear_feature(&features, VIRTIO_NET_F_RSS);
+            } else if (virtio_has_feature(features, VIRTIO_NET_F_RSS)) {
+                virtio_net_load_ebpf(n);
+            }
         }
 
         return features;