Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <jiri@nvidia.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Jiri Pirko and committed by
David S. Miller
2034d90a ee2a35fe

+12 -3
+12 -3
include/net/net_namespace.h
··· 368 368 369 369 typedef struct { 370 370 #ifdef CONFIG_NET_NS 371 - struct net *net; 371 + struct net __rcu *net; 372 372 #endif 373 373 } possible_net_t; 374 374 375 375 static inline void write_pnet(possible_net_t *pnet, struct net *net) 376 376 { 377 377 #ifdef CONFIG_NET_NS 378 - pnet->net = net; 378 + rcu_assign_pointer(pnet->net, net); 379 379 #endif 380 380 } 381 381 382 382 static inline struct net *read_pnet(const possible_net_t *pnet) 383 383 { 384 384 #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); 386 395 #else 387 396 return &init_net; 388 397 #endif