netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Dumazet <edumazet@google.com>
To: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	 Paolo Abeni <pabeni@redhat.com>
Cc: netdev@vger.kernel.org, Kuniyuki Iwashima <kuniyu@amazon.com>,
	 Simon Horman <horms@kernel.org>,
	eric.dumazet@gmail.com,  Eric Dumazet <edumazet@google.com>
Subject: [PATCH v2 net 01/16] net: add dev_net_rcu() helper
Date: Mon,  3 Feb 2025 14:30:31 +0000	[thread overview]
Message-ID: <20250203143046.3029343-2-edumazet@google.com> (raw)
In-Reply-To: <20250203143046.3029343-1-edumazet@google.com>

dev->nd_net can change, readers should either
use rcu_read_lock() or RTNL.

We currently use a generic helper, dev_net() with
no debugging support. We probably have many hidden bugs.

Add dev_net_rcu() helper for callers using rcu_read_lock()
protection.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
 include/linux/netdevice.h   | 6 ++++++
 include/net/net_namespace.h | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 2a59034a5fa2fb53300657968c2053ab354bb746..046015adf2856f859b9a671e2be4ef674125ef96 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -2663,6 +2663,12 @@ struct net *dev_net(const struct net_device *dev)
 	return read_pnet(&dev->nd_net);
 }
 
+static inline
+struct net *dev_net_rcu(const struct net_device *dev)
+{
+	return read_pnet_rcu(&dev->nd_net);
+}
+
 static inline
 void dev_net_set(struct net_device *dev, struct net *net)
 {
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
index 0f5eb9db0c6264efc1ac83ab577511fd6823f4fe..7ba1402ca7796663bed3373b1a0c6a0249cd1599 100644
--- a/include/net/net_namespace.h
+++ b/include/net/net_namespace.h
@@ -398,7 +398,7 @@ static inline struct net *read_pnet(const possible_net_t *pnet)
 #endif
 }
 
-static inline struct net *read_pnet_rcu(possible_net_t *pnet)
+static inline struct net *read_pnet_rcu(const possible_net_t *pnet)
 {
 #ifdef CONFIG_NET_NS
 	return rcu_dereference(pnet->net);
-- 
2.48.1.362.g079036d154-goog


  reply	other threads:[~2025-02-03 14:30 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-03 14:30 [PATCH v2 net 00/16] net: first round to use dev_net_rcu() Eric Dumazet
2025-02-03 14:30 ` Eric Dumazet [this message]
2025-02-03 14:30 ` [PATCH v2 net 02/16] ipv4: add RCU protection to ip4_dst_hoplimit() Eric Dumazet
2025-02-03 14:30 ` [PATCH v2 net 03/16] ipv4: use RCU protection in ip_dst_mtu_maybe_forward() Eric Dumazet
2025-02-03 14:30 ` [PATCH v2 net 04/16] ipv4: use RCU protection in ipv4_default_advmss() Eric Dumazet
2025-02-03 14:30 ` [PATCH v2 net 05/16] ipv4: use RCU protection in rt_is_expired() Eric Dumazet
2025-02-03 14:30 ` [PATCH v2 net 06/16] tcp: convert to dev_net_rcu() Eric Dumazet
2025-02-03 14:30 ` [PATCH v2 net 07/16] net: gro: convert four dev_net() calls Eric Dumazet
2025-02-03 14:30 ` [PATCH v2 net 08/16] udp: convert to dev_net_rcu() Eric Dumazet
2025-02-03 14:30 ` [PATCH v2 net 09/16] ipv4: icmp: " Eric Dumazet
2025-02-03 23:36   ` Jakub Kicinski
2025-02-04  4:14     ` Eric Dumazet
2025-02-04  4:57       ` Eric Dumazet
2025-02-04 10:35         ` Eric Dumazet
2025-02-04 16:21           ` Matthieu Baerts
2025-02-04 16:56             ` Eric Dumazet
2025-02-04 16:21           ` Jakub Kicinski
2025-02-03 14:30 ` [PATCH v2 net 10/16] ipv6: " Eric Dumazet
2025-02-03 14:30 ` [PATCH v2 net 11/16] ipv6: input: " Eric Dumazet
2025-02-03 14:30 ` [PATCH v2 net 12/16] ipv6: output: " Eric Dumazet
2025-02-03 14:30 ` [PATCH v2 net 13/16] ipv6: use RCU protection in ip6_default_advmss() Eric Dumazet
2025-02-03 14:30 ` [PATCH v2 net 14/16] net: filter: convert to dev_net_rcu() Eric Dumazet
2025-02-03 14:30 ` [PATCH v2 net 15/16] flow_dissector: use rcu protection to fetch dev_net() Eric Dumazet
2025-02-03 23:38   ` Jakub Kicinski
2025-02-04  4:16     ` Eric Dumazet
2025-02-03 14:30 ` [PATCH v2 net 16/16] ipv4: use RCU protection in inet_select_addr() Eric Dumazet

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=20250203143046.3029343-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=kuniyu@amazon.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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).