]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: add dev_net_rcu() helper
authorEric Dumazet <edumazet@google.com>
Wed, 5 Feb 2025 15:51:09 +0000 (15:51 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Mar 2025 11:47:21 +0000 (12:47 +0100)
[ Upstream commit 482ad2a4ace2740ca0ff1cbc8f3c7f862f3ab507 ]

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>
Link: https://patch.msgid.link/20250205155120.1676781-2-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Stable-dep-of: dd205fcc33d9 ("ipv4: use RCU protection in rt_is_expired()")
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/linux/netdevice.h
include/net/net_namespace.h

index 3380668478e8ac75d0f88e07ce0ef40d02aeb9c4..06b37f45b67c9adeff9007d6a73d9fdf5cbedfc9 100644 (file)
@@ -2361,6 +2361,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)
 {
index 0dfcf2f0ef62a3ea89a0a60ef48bbd854a1a250e..3cf6a5c17b84cdd3a0afee85db8005c05eea6b94 100644 (file)
@@ -340,7 +340,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);