From: Eric Dumazet <edumazet@google.com>
To: "David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>
Cc: Willem de Bruijn <willemb@google.com>,
Simon Horman <horms@kernel.org>,
netdev@vger.kernel.org, eric.dumazet@gmail.com,
Eric Dumazet <edumazet@google.com>
Subject: [PATCH v2 net-next 1/4] net: synchronize proc_do_rss_key() with netdev_rss_key_fill()
Date: Tue, 22 Sep 2026 16:34:55 +0000 [thread overview]
Message-ID: <20260922163458.3900996-2-edumazet@google.com> (raw)
In-Reply-To: <20260922163458.3900996-1-edumazet@google.com>
proc_do_rss_key() reads netdev_rss_key[] without synchronization, so a
concurrent reader of /proc/sys/net/core/netdev_rss_key can observe a
partially populated key while netdev_rss_key_fill() is initializing it.
Publish a boolean flag after an smp_wmb() once netdev_rss_key_fill() has
populated netdev_rss_key[], and pair it with an smp_rmb() in
proc_do_rss_key(), printing zero bytes until the flag is set.
Fixes: 960fb622f851 ("net: provide a per host RSS key generic infrastructure")
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
net/core/dev.h | 1 +
net/core/sysctl_net_core.c | 7 ++++++-
net/ethtool/ioctl.c | 7 +++++++
3 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/net/core/dev.h b/net/core/dev.h
index b757faead4d1a3e445e54d2f468c38c9e09b6762..0127b4d03e5251e0ad695aa649d0c52c2248bc8c 100644
--- a/net/core/dev.h
+++ b/net/core/dev.h
@@ -95,6 +95,7 @@ extern int netdev_unregister_timeout_secs;
extern int weight_p;
extern int dev_weight_rx_bias;
extern int dev_weight_tx_bias;
+extern bool netdev_rss_key_initialized;
extern struct rw_semaphore dev_addr_sem;
diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
index 23310581f494553e3ad8c4e010c7799e04f976c0..473c162736d6928d13d22e9902262a43705196d9 100644
--- a/net/core/sysctl_net_core.c
+++ b/net/core/sysctl_net_core.c
@@ -337,10 +337,15 @@ static int proc_do_rss_key(const struct ctl_table *table, int write,
{
char buf[NETDEV_RSS_KEY_LEN * 3];
struct ctl_table fake_table;
+ bool initialized;
char *pos = buf;
+ initialized = READ_ONCE(netdev_rss_key_initialized);
+ /* Pair with smp_wmb() in netdev_rss_key_fill(). */
+ smp_rmb();
+
for (int i = 0; i < NETDEV_RSS_KEY_LEN; i++) {
- pos = hex_byte_pack(pos, netdev_rss_key[i]);
+ pos = hex_byte_pack(pos, initialized ? netdev_rss_key[i] : 0);
*pos++ = ':';
}
*(--pos) = 0;
diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
index 4b0bc503f9307880e436d5ee30f75476264a0c6b..b2820f02ca2790a8a3c13395e20040ee6976006f 100644
--- a/net/ethtool/ioctl.c
+++ b/net/ethtool/ioctl.c
@@ -34,6 +34,7 @@
#include <net/netdev_lock.h>
#include <net/netdev_queues.h>
+#include "../core/dev.h"
#include "common.h"
/* State held across locks and calls for commands which have devlink fallback */
@@ -1302,11 +1303,17 @@ static int ethtool_copy_validate_indir(u32 *indir, void __user *useraddr,
}
u8 netdev_rss_key[NETDEV_RSS_KEY_LEN] __read_mostly;
+bool netdev_rss_key_initialized __read_mostly;
void netdev_rss_key_fill(void *buffer, size_t len)
{
BUG_ON(len > sizeof(netdev_rss_key));
net_get_random_once(netdev_rss_key, sizeof(netdev_rss_key));
+ if (unlikely(!READ_ONCE(netdev_rss_key_initialized))) {
+ /* Pair with smp_rmb() in proc_do_rss_key(). */
+ smp_wmb();
+ WRITE_ONCE(netdev_rss_key_initialized, true);
+ }
memcpy(buffer, netdev_rss_key, len);
}
EXPORT_SYMBOL(netdev_rss_key_fill);
--
2.55.0.1082.g2b9226bbc0-goog
next prev parent reply other threads:[~2026-09-22 16:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-22 16:34 [PATCH v2 net-next 0/4] net: ethtool: make netdev_rss_key_fill() spread flows over all queues Eric Dumazet
2026-09-22 16:34 ` Eric Dumazet [this message]
2026-09-23 22:36 ` [PATCH v2 net-next 1/4] net: synchronize proc_do_rss_key() with netdev_rss_key_fill() netdev-bot+sashiko
2026-09-22 16:34 ` [PATCH v2 net-next 2/4] net: ethtool: generate RSS keys that spread flows over all queues Eric Dumazet
2026-09-23 22:36 ` netdev-bot+sashiko
2026-09-23 23:33 ` Eric Dumazet
2026-09-22 16:34 ` [PATCH v2 net-next 3/4] netdevsim: support reporting RSS key, indirection table, and flow hash fields Eric Dumazet
2026-09-22 16:34 ` [PATCH v2 net-next 4/4] selftests: drivers: net: check the host and device RSS keys Eric Dumazet
2026-09-25 23:40 ` [PATCH v2 net-next 0/4] net: ethtool: make netdev_rss_key_fill() spread flows over all queues patchwork-bot+netdevbpf
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=20260922163458.3900996-2-edumazet@google.com \
--to=edumazet@google.com \
--cc=davem@davemloft.net \
--cc=eric.dumazet@gmail.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=willemb@google.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