summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJiri Pirko <jiri@nvidia.com>2023-10-13 15:10:23 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-02-21 15:57:20 +0300
commit4cfecb7fc742888bf31bd49cfa16dd6eb42641e6 (patch)
tree17a26fb2e4c3d76888396f43f2615ab0964eb074 /include
parentafd983f102f8de01f59ec7ca5a8a49335ffe8c1a (diff)
downloadlinux-4cfecb7fc742888bf31bd49cfa16dd6eb42641e6.tar.xz
net: treat possible_net_t net pointer as an RCU one and add read_pnet_rcu()
[ Upstream commit 2034d90ae41ae93e30d492ebcf1f06f97a9cfba6 ] 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> Stable-dep-of: 71b8471c93fa ("ipv4: use RCU protection in ipv4_default_advmss()") Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'include')
-rw-r--r--include/net/net_namespace.h15
1 files changed, 12 insertions, 3 deletions
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
index 1befad79a673..b767bdcd9e12 100644
--- a/include/net/net_namespace.h
+++ b/include/net/net_namespace.h
@@ -369,21 +369,30 @@ static inline void put_net_track(struct net *net, netns_tracker *tracker)
typedef struct {
#ifdef CONFIG_NET_NS
- struct net *net;
+ struct net __rcu *net;
#endif
} possible_net_t;
static inline void write_pnet(possible_net_t *pnet, struct net *net)
{
#ifdef CONFIG_NET_NS
- pnet->net = net;
+ rcu_assign_pointer(pnet->net, net);
#endif
}
static inline struct net *read_pnet(const possible_net_t *pnet)
{
#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
return &init_net;
#endif