Commit 2034d90a authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

net: treat possible_net_t net pointer as an RCU one and add read_pnet_rcu()

Make the net pointer stored in possible_net_t structure annotated as
an RCU pointer. Change the access helpers to treat it as such.
Introduce read_pnet_rcu() helper to allow caller to dereference
the net pointer under RCU read lock.
Signed-off-by: default avatarJiri Pirko <jiri@nvidia.com>
Reviewed-by: default avatarSimon Horman <horms@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ee2a35fe
...@@ -368,21 +368,30 @@ static inline void put_net_track(struct net *net, netns_tracker *tracker) ...@@ -368,21 +368,30 @@ static inline void put_net_track(struct net *net, netns_tracker *tracker)
typedef struct { typedef struct {
#ifdef CONFIG_NET_NS #ifdef CONFIG_NET_NS
struct net *net; struct net __rcu *net;
#endif #endif
} possible_net_t; } possible_net_t;
static inline void write_pnet(possible_net_t *pnet, struct net *net) static inline void write_pnet(possible_net_t *pnet, struct net *net)
{ {
#ifdef CONFIG_NET_NS #ifdef CONFIG_NET_NS
pnet->net = net; rcu_assign_pointer(pnet->net, net);
#endif #endif
} }
static inline struct net *read_pnet(const possible_net_t *pnet) static inline struct net *read_pnet(const possible_net_t *pnet)
{ {
#ifdef CONFIG_NET_NS #ifdef CONFIG_NET_NS
return pnet->net; return rcu_dereference_protected(pnet->net, true);
#else
return &init_net;
#endif
}
static inline struct net *read_pnet_rcu(possible_net_t *pnet)
{
#ifdef CONFIG_NET_NS
return rcu_dereference(pnet->net);
#else #else
return &init_net; return &init_net;
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment