Skip to contentSkip to conversation

SUNRPC: add some netns refcount trackers

PATCH Applied Eric Dumazet 3 participants 6 messages Jan 27, 2022 – Jan 28, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover SUNRPC: add some netns refcount trackers

From: Eric Dumazet <[email protected]>

Effort started in linux-5.17

Our goal is to replace get_net()/put_net() pairs with get_net_track()/put_net_track() to get instant notifications of imbalance bugs in the future.

Patches were split from a bigger series sent one month ago.

Eric Dumazet (3):
SUNRPC: add netns refcount tracker to struct svc_xprt
SUNRPC: add netns refcount tracker to struct gss_auth
SUNRPC: add netns refcount tracker to struct rpc_xprt

 include/linux/sunrpc/svc_xprt.h |  1 +
 include/linux/sunrpc/xprt.h     |  1 +
 net/sunrpc/auth_gss/auth_gss.c  | 10 ++++++----
 net/sunrpc/svc_xprt.c           |  4 ++--
 net/sunrpc/xprt.c               |  4 ++--
 5 files changed, 12 insertions(+), 8 deletions(-)
Signature · 1 line
2.35.0.rc0.227.g00780c9af4-goog
#1 lore raw

PATCH 1/3 SUNRPC: add netns refcount tracker to struct svc_xprt

From: Eric Dumazet <[email protected]>

struct svc_xprt holds a long lived reference to a netns, it is worth tracking it.

---
 include/linux/sunrpc/svc_xprt.h | 1 +
 net/sunrpc/svc_xprt.c           | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)
include/linux/sunrpc/svc_xprt.h +1 -0
index 571f605bc91ef8fa190e7fd5504efb76ec3fa89e..382af90320acc3a7b3817bf66f65fbb15447ae7d 100644
@@ -88,6 +88,7 @@ struct svc_xprt {
 	struct list_head	xpt_users;	/* callbacks on free */
 
 	struct net		*xpt_net;
+	netns_tracker		ns_tracker;
 	const struct cred	*xpt_cred;
 	struct rpc_xprt		*xpt_bc_xprt;	/* NFSv4.1 backchannel */
 	struct rpc_xprt_switch	*xpt_bc_xps;	/* NFSv4.1 backchannel */
net/sunrpc/svc_xprt.c +2 -2
index b21ad79941474685597c9c7c07b862ef7e98ad74..db878e833b672864551bc9ef884a3cd6ca6c2603 100644
@@ -162,7 +162,7 @@ static void svc_xprt_free(struct kref *kref)
 	if (test_bit(XPT_CACHE_AUTH, &xprt->xpt_flags))
 		svcauth_unix_info_release(xprt);
 	put_cred(xprt->xpt_cred);
-	put_net(xprt->xpt_net);
+	put_net_track(xprt->xpt_net, &xprt->ns_tracker);
 	/* See comment on corresponding get in xs_setup_bc_tcp(): */
 	if (xprt->xpt_bc_xprt)
 		xprt_put(xprt->xpt_bc_xprt);
@@ -198,7 +198,7 @@ void svc_xprt_init(struct net *net, struct svc_xprt_class *xcl,
 	mutex_init(&xprt->xpt_mutex);
 	spin_lock_init(&xprt->xpt_lock);
 	set_bit(XPT_BUSY, &xprt->xpt_flags);
-	xprt->xpt_net = get_net(net);
+	xprt->xpt_net = get_net_track(net, &xprt->ns_tracker, GFP_ATOMIC);
 	strcpy(xprt->xpt_remotebuf, "uninitialized");
 }
 EXPORT_SYMBOL_GPL(svc_xprt_init);
Signature · 1 line
2.35.0.rc0.227.g00780c9af4-goog
Acked-by on v1 1/3
#2 lore raw

Re: [PATCH net-next 1/3] SUNRPC: add netns refcount tracker to struct svc_xprt

Quoted 10 lines · Eric Dumazet

From: Eric Dumazet <[email protected]>

struct svc_xprt holds a long lived reference to a netns, it is worth tracking it.

I haven't followed the requirements for the extended tracking, but I have no objection to this change.

Quoted 42 lines

---
include/linux/sunrpc/svc_xprt.h | 1 +
net/sunrpc/svc_xprt.c | 4 ++--

2 files changed, 3 insertions(+), 2 deletions(-)
include/linux/sunrpc/svc_xprt.h +1 -0
index 571f605bc91ef8fa190e7fd5504efb76ec3fa89e..382af90320acc3a7b3817bf66f65fbb15447ae7d 100644
@@ -88,6 +88,7 @@ struct svc_xprt {
 	struct list_head	xpt_users;	/* callbacks on free */
 
 	struct net		*xpt_net;
+	netns_tracker		ns_tracker;
 	const struct cred	*xpt_cred;
 	struct rpc_xprt		*xpt_bc_xprt;	/* NFSv4.1 backchannel */
 	struct rpc_xprt_switch	*xpt_bc_xps;	/* NFSv4.1 backchannel */
net/sunrpc/svc_xprt.c +2 -2
index b21ad79941474685597c9c7c07b862ef7e98ad74..db878e833b672864551bc9ef884a3cd6ca6c2603 100644
@@ -162,7 +162,7 @@ static void svc_xprt_free(struct kref *kref)
 	if (test_bit(XPT_CACHE_AUTH, &xprt->xpt_flags))
 		svcauth_unix_info_release(xprt);
 	put_cred(xprt->xpt_cred);
-	put_net(xprt->xpt_net);
+	put_net_track(xprt->xpt_net, &xprt->ns_tracker);
 	/* See comment on corresponding get in xs_setup_bc_tcp(): */
 	if (xprt->xpt_bc_xprt)
 		xprt_put(xprt->xpt_bc_xprt);
@@ -198,7 +198,7 @@ void svc_xprt_init(struct net *net, struct svc_xprt_class *xcl,
 	mutex_init(&xprt->xpt_mutex);
 	spin_lock_init(&xprt->xpt_lock);
 	set_bit(XPT_BUSY, &xprt->xpt_flags);
-	xprt->xpt_net = get_net(net);
+	xprt->xpt_net = get_net_track(net, &xprt->ns_tracker, GFP_ATOMIC);
 	strcpy(xprt->xpt_remotebuf, "uninitialized");
 }
 EXPORT_SYMBOL_GPL(svc_xprt_init);
Signature · 1 line
2.35.0.rc0.227.g00780c9af4-goog

--
Chuck Lever

#3 lore raw

PATCH 2/3 SUNRPC: add netns refcount tracker to struct gss_auth

In reply to Eric Dumazet

From: Eric Dumazet <[email protected]>

---
 net/sunrpc/auth_gss/auth_gss.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
net/sunrpc/auth_gss/auth_gss.c +6 -4
index 5f42aa5fc612850b526c160ab5e5c75416862676..8eb7e8544815a8bc20a79b21b01e3ba110fc6b47 100644
@@ -72,7 +72,8 @@ struct gss_auth {
 	struct gss_api_mech *mech;
 	enum rpc_gss_svc service;
 	struct rpc_clnt *client;
-	struct net *net;
+	struct net	*net;
+	netns_tracker	ns_tracker;
 	/*
 	 * There are two upcall pipes; dentry[1], named "gssd", is used
 	 * for the new text-based upcall; dentry[0] is named after the
@@ -1013,7 +1014,8 @@ gss_create_new(const struct rpc_auth_create_args *args, struct rpc_clnt *clnt)
 			goto err_free;
 	}
 	gss_auth->client = clnt;
-	gss_auth->net = get_net(rpc_net_ns(clnt));
+	gss_auth->net = get_net_track(rpc_net_ns(clnt), &gss_auth->ns_tracker,
+				      GFP_KERNEL);
 	err = -EINVAL;
 	gss_auth->mech = gss_mech_get_by_pseudoflavor(flavor);
 	if (!gss_auth->mech)
@@ -1068,7 +1070,7 @@ gss_create_new(const struct rpc_auth_create_args *args, struct rpc_clnt *clnt)
 err_put_mech:
 	gss_mech_put(gss_auth->mech);
 err_put_net:
-	put_net(gss_auth->net);
+	put_net_track(gss_auth->net, &gss_auth->ns_tracker);
 err_free:
 	kfree(gss_auth->target_name);
 	kfree(gss_auth);
@@ -1084,7 +1086,7 @@ gss_free(struct gss_auth *gss_auth)
 	gss_pipe_free(gss_auth->gss_pipe[0]);
 	gss_pipe_free(gss_auth->gss_pipe[1]);
 	gss_mech_put(gss_auth->mech);
-	put_net(gss_auth->net);
+	put_net_track(gss_auth->net, &gss_auth->ns_tracker);
 	kfree(gss_auth->target_name);
 
 	kfree(gss_auth);
Signature · 1 line
2.35.0.rc0.227.g00780c9af4-goog
#4 lore raw

PATCH 3/3 SUNRPC: add netns refcount tracker to struct rpc_xprt

In reply to Eric Dumazet

From: Eric Dumazet <[email protected]>

---
 include/linux/sunrpc/xprt.h | 1 +
 net/sunrpc/xprt.c           | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)
include/linux/sunrpc/xprt.h +1 -0
index 955ea4d7af0b2fea1300a46fad963df35f25810c..3cdc8d878d81122e3318447df4770100500403e4 100644
@@ -284,6 +284,7 @@ struct rpc_xprt {
 	} stat;
 
 	struct net		*xprt_net;
+	netns_tracker		ns_tracker;
 	const char		*servername;
 	const char		*address_strings[RPC_DISPLAY_MAX];
 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
net/sunrpc/xprt.c +2 -2
index a02de2bddb28b48bb6798327c0814e769314621b..5af484d6ba5e8bfb871768122009ee330c708c04 100644
@@ -1835,7 +1835,7 @@ EXPORT_SYMBOL_GPL(xprt_alloc);
 
 void xprt_free(struct rpc_xprt *xprt)
 {
-	put_net(xprt->xprt_net);
+	put_net_track(xprt->xprt_net, &xprt->ns_tracker);
 	xprt_free_all_slots(xprt);
 	xprt_free_id(xprt);
 	rpc_sysfs_xprt_destroy(xprt);
@@ -2027,7 +2027,7 @@ static void xprt_init(struct rpc_xprt *xprt, struct net *net)
 
 	xprt_init_xid(xprt);
 
-	xprt->xprt_net = get_net(net);
+	xprt->xprt_net = get_net_track(net, &xprt->ns_tracker, GFP_KERNEL);
 }
 
 /**
Signature · 1 line
2.35.0.rc0.227.g00780c9af4-goog
#5 lore raw
In reply to Eric Dumazet
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Quoted 9 lines · On Thu, 27 Jan 2022 12:09:34 -0800 you wrote:

From: Eric Dumazet <[email protected]>

Effort started in linux-5.17

Our goal is to replace get_net()/put_net() pairs with get_net_track()/put_net_track() to get instant notifications of imbalance bugs in the future.

[...]

Here is the summary with links:
- [net-next,1/3] SUNRPC: add netns refcount tracker to struct svc_xprt

    https://git.kernel.org/netdev/net-next/c/6cdef8a6ee74
  - [net-next,2/3] SUNRPC: add netns refcount tracker to struct gss_auth
    https://git.kernel.org/netdev/net-next/c/9b1831e56c7f
  - [net-next,3/3] SUNRPC: add netns refcount tracker to struct rpc_xprt
    https://git.kernel.org/netdev/net-next/c/b9a0d6d143ec

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html