From: Akihiko Odaki <akihiko.odaki@daynix.com>
To: qemu-devel@nongnu.org,
Yuri Benditovich <yuri.benditovich@daynix.com>,
Andrew Melnychenko <andrew@daynix.com>,
"Michael S . Tsirkin" <mst@redhat.com>,
Jason Wang <jasowang@redhat.com>,
Paolo Abeni <pabeni@redhat.com>,
devel@daynix.com
Cc: Akihiko Odaki <akihiko.odaki@daynix.com>
Subject: [PATCH RFC v5 2/5] virtio-net: Offload hashing to peer
Date: Fri, 30 May 2025 13:39:10 +0900 [thread overview]
Message-ID: <20250530-hash-v5-2-343d7d7a8200@daynix.com> (raw)
In-Reply-To: <20250530-hash-v5-0-343d7d7a8200@daynix.com>
This allows offloading hash reporting and RSS to tap.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
hw/net/virtio-net.c | 69 +++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 56 insertions(+), 13 deletions(-)
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 52fe404b3431..0a333d560d7b 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -1213,20 +1213,58 @@ static void virtio_net_detach_ebpf_rss(VirtIONet *n)
static void virtio_net_commit_rss_config(VirtIONet *n)
{
- if (n->rss_data.peer_hash_available) {
- return;
- }
-
if (n->rss_data.enabled) {
- n->rss_data.enabled_software_rss = n->rss_data.populate_hash;
- if (n->rss_data.populate_hash) {
- virtio_net_detach_ebpf_rss(n);
- } else if (!virtio_net_attach_ebpf_rss(n)) {
- if (get_vhost_net(qemu_get_queue(n->nic)->peer)) {
- warn_report("Can't load eBPF RSS for vhost");
+ if (n->rss_data.peer_hash_available &&
+ (n->rss_data.peer_hash_types & n->rss_data.runtime_hash_types) ==
+ n->rss_data.runtime_hash_types) {
+ if (n->rss_data.redirect) {
+ size_t indirection_table_size =
+ n->rss_data.indirections_len *
+ sizeof(*n->rss_data.indirections_table);
+
+ size_t hash_size = sizeof(NetVnetRss) +
+ indirection_table_size +
+ sizeof(n->rss_data.key);
+
+ g_autofree struct {
+ NetVnetRss hdr;
+ uint8_t footer[];
+ } *rss = g_malloc(hash_size);
+
+ rss->hdr.hash_types = n->rss_data.runtime_hash_types;
+ rss->hdr.indirection_table_mask =
+ n->rss_data.indirections_len - 1;
+ rss->hdr.unclassified_queue = n->rss_data.default_queue;
+
+ memcpy(rss->footer, n->rss_data.indirections_table,
+ indirection_table_size);
+
+ memcpy(rss->footer + indirection_table_size, n->rss_data.key,
+ sizeof(n->rss_data.key));
+
+ qemu_set_vnet_rss(qemu_get_queue(n->nic)->peer, &rss->hdr,
+ n->rss_data.populate_hash);
} else {
- warn_report("Can't load eBPF RSS - fallback to software RSS");
- n->rss_data.enabled_software_rss = true;
+ qemu_set_vnet_automq(qemu_get_queue(n->nic)->peer,
+ n->rss_data.runtime_hash_types);
+ }
+
+ n->rss_data.enabled_software_rss = false;
+ } else {
+ if (n->rss_data.peer_hash_available) {
+ qemu_set_vnet_automq(qemu_get_queue(n->nic)->peer, 0);
+ }
+
+ n->rss_data.enabled_software_rss = n->rss_data.populate_hash;
+ if (n->rss_data.populate_hash) {
+ virtio_net_detach_ebpf_rss(n);
+ } else if (!virtio_net_attach_ebpf_rss(n)) {
+ if (get_vhost_net(qemu_get_queue(n->nic)->peer)) {
+ warn_report("Can't load eBPF RSS for vhost");
+ } else {
+ warn_report("Can't load eBPF RSS - fallback to software RSS");
+ n->rss_data.enabled_software_rss = true;
+ }
}
}
@@ -1235,7 +1273,12 @@ static void virtio_net_commit_rss_config(VirtIONet *n)
n->rss_data.indirections_len,
sizeof(n->rss_data.key));
} else {
- virtio_net_detach_ebpf_rss(n);
+ if (n->rss_data.peer_hash_available) {
+ qemu_set_vnet_automq(qemu_get_queue(n->nic)->peer, 0);
+ } else {
+ virtio_net_detach_ebpf_rss(n);
+ }
+
trace_virtio_net_rss_disable(n);
}
}
--
2.49.0
next prev parent reply other threads:[~2025-05-30 4:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-30 4:39 [PATCH RFC v5 0/5] virtio-net: Offload hashing without eBPF Akihiko Odaki
2025-05-30 4:39 ` [PATCH RFC v5 1/5] net: Allow configuring virtio hashing Akihiko Odaki
2025-05-30 4:39 ` Akihiko Odaki [this message]
2025-05-30 4:39 ` [PATCH RFC v5 3/5] virtio-net: Offload hashing without vhost Akihiko Odaki
2025-05-30 4:39 ` [PATCH RFC v5 4/5] tap: Report virtio-net hashing support on Linux Akihiko Odaki
2025-05-30 4:39 ` [PATCH RFC v5 5/5] docs/devel/ebpf_rss.rst: Update for peer RSS Akihiko Odaki
2025-06-03 6:35 ` [PATCH RFC v5 0/5] virtio-net: Offload hashing without eBPF Lei Yang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250530-hash-v5-2-343d7d7a8200@daynix.com \
--to=akihiko.odaki@daynix.com \
--cc=andrew@daynix.com \
--cc=devel@daynix.com \
--cc=jasowang@redhat.com \
--cc=mst@redhat.com \
--cc=pabeni@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=yuri.benditovich@daynix.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).