Skip to content

Commit 482ad2a

Browse files
edumazetkuba-moo
authored andcommitted
net: add dev_net_rcu() helper
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 <[email protected]> Reviewed-by: Kuniyuki Iwashima <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 3cf0a98 commit 482ad2a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

include/linux/netdevice.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2663,6 +2663,12 @@ struct net *dev_net(const struct net_device *dev)
26632663
return read_pnet(&dev->nd_net);
26642664
}
26652665

2666+
static inline
2667+
struct net *dev_net_rcu(const struct net_device *dev)
2668+
{
2669+
return read_pnet_rcu(&dev->nd_net);
2670+
}
2671+
26662672
static inline
26672673
void dev_net_set(struct net_device *dev, struct net *net)
26682674
{

include/net/net_namespace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ static inline struct net *read_pnet(const possible_net_t *pnet)
398398
#endif
399399
}
400400

401-
static inline struct net *read_pnet_rcu(possible_net_t *pnet)
401+
static inline struct net *read_pnet_rcu(const possible_net_t *pnet)
402402
{
403403
#ifdef CONFIG_NET_NS
404404
return rcu_dereference(pnet->net);

0 commit comments

Comments
 (0)