Skip to content

Commit 2034d90

Browse files
Jiri Pirkodavem330
authored andcommitted
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: Jiri Pirko <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ee2a35f commit 2034d90

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

include/net/net_namespace.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,21 +368,30 @@ static inline void put_net_track(struct net *net, netns_tracker *tracker)
368368

369369
typedef struct {
370370
#ifdef CONFIG_NET_NS
371-
struct net *net;
371+
struct net __rcu *net;
372372
#endif
373373
} possible_net_t;
374374

375375
static inline void write_pnet(possible_net_t *pnet, struct net *net)
376376
{
377377
#ifdef CONFIG_NET_NS
378-
pnet->net = net;
378+
rcu_assign_pointer(pnet->net, net);
379379
#endif
380380
}
381381

382382
static inline struct net *read_pnet(const possible_net_t *pnet)
383383
{
384384
#ifdef CONFIG_NET_NS
385-
return pnet->net;
385+
return rcu_dereference_protected(pnet->net, true);
386+
#else
387+
return &init_net;
388+
#endif
389+
}
390+
391+
static inline struct net *read_pnet_rcu(possible_net_t *pnet)
392+
{
393+
#ifdef CONFIG_NET_NS
394+
return rcu_dereference(pnet->net);
386395
#else
387396
return &init_net;
388397
#endif

0 commit comments

Comments
 (0)