All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>
Cc: netdev <netdev@vger.kernel.org>,
	Eric Dumazet <edumazet@google.com>,
	Eric Dumazet <eric.dumazet@gmail.com>
Subject: [PATCH net-next 13/17] net: add netns refcount tracker to struct nsproxy
Date: Mon,  6 Dec 2021 16:51:38 -0800	[thread overview]
Message-ID: <20211207005142.1688204-14-eric.dumazet@gmail.com> (raw)
In-Reply-To: <20211207005142.1688204-1-eric.dumazet@gmail.com>

From: Eric Dumazet <edumazet@google.com>

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 include/linux/nsproxy.h  | 2 ++
 kernel/nsproxy.c         | 5 +++--
 net/core/net_namespace.c | 4 ++--
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/include/linux/nsproxy.h b/include/linux/nsproxy.h
index cdb171efc7cb052dd4844ae182206939627c68e8..eed7768daf428cfede70f438ecd366af23da85f2 100644
--- a/include/linux/nsproxy.h
+++ b/include/linux/nsproxy.h
@@ -4,6 +4,7 @@
 
 #include <linux/spinlock.h>
 #include <linux/sched.h>
+#include <net/net_trackers.h>
 
 struct mnt_namespace;
 struct uts_namespace;
@@ -35,6 +36,7 @@ struct nsproxy {
 	struct mnt_namespace *mnt_ns;
 	struct pid_namespace *pid_ns_for_children;
 	struct net 	     *net_ns;
+	netns_tracker	     ns_tracker;
 	struct time_namespace *time_ns;
 	struct time_namespace *time_ns_for_children;
 	struct cgroup_namespace *cgroup_ns;
diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c
index eec72ca962e249c94266192b77a3c1f92ec8e889..8b50e8153bc8957b47e2fce860aacce4e9f56616 100644
--- a/kernel/nsproxy.c
+++ b/kernel/nsproxy.c
@@ -112,6 +112,7 @@ static struct nsproxy *create_new_namespaces(unsigned long flags,
 		err = PTR_ERR(new_nsp->net_ns);
 		goto out_net;
 	}
+	netns_tracker_alloc(new_nsp->net_ns, &new_nsp->ns_tracker, GFP_KERNEL);
 
 	new_nsp->time_ns_for_children = copy_time_ns(flags, user_ns,
 					tsk->nsproxy->time_ns_for_children);
@@ -124,7 +125,7 @@ static struct nsproxy *create_new_namespaces(unsigned long flags,
 	return new_nsp;
 
 out_time:
-	put_net(new_nsp->net_ns);
+	put_net_track(new_nsp->net_ns, &new_nsp->ns_tracker);
 out_net:
 	put_cgroup_ns(new_nsp->cgroup_ns);
 out_cgroup:
@@ -200,7 +201,7 @@ void free_nsproxy(struct nsproxy *ns)
 	if (ns->time_ns_for_children)
 		put_time_ns(ns->time_ns_for_children);
 	put_cgroup_ns(ns->cgroup_ns);
-	put_net(ns->net_ns);
+	put_net_track(ns->net_ns, &ns->ns_tracker);
 	kmem_cache_free(nsproxy_cachep, ns);
 }
 
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 3ea5321430ee21af687510917da9b9aea5154e12..962062ad8cc4697ff6791aea7c48aea0b5db94a5 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -1355,8 +1355,8 @@ static int netns_install(struct nsset *nsset, struct ns_common *ns)
 	    !ns_capable(nsset->cred->user_ns, CAP_SYS_ADMIN))
 		return -EPERM;
 
-	put_net(nsproxy->net_ns);
-	nsproxy->net_ns = get_net(net);
+	put_net_track(nsproxy->net_ns, &nsproxy->ns_tracker);
+	nsproxy->net_ns = get_net_track(net, &nsproxy->ns_tracker, GFP_KERNEL);
 	return 0;
 }
 
-- 
2.34.1.400.ga245620fadb-goog


  parent reply	other threads:[~2021-12-07  0:52 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-07  0:51 [PATCH net-next 00/17] net: netns refcount tracking series Eric Dumazet
2021-12-07  0:51 ` [PATCH net-next 01/17] net: add networking namespace refcount tracker Eric Dumazet
2021-12-07  0:51 ` [PATCH net-next 02/17] net: add netns refcount tracker to struct sock Eric Dumazet
2021-12-07  0:51 ` [PATCH net-next 03/17] net: add netns refcount tracker to struct seq_net_private Eric Dumazet
2021-12-07  0:51 ` [PATCH net-next 04/17] net: sched: add netns refcount tracker to struct tcf_exts Eric Dumazet
2021-12-07  0:51 ` [PATCH net-next 05/17] netfilter: nfnetlink: add netns refcount tracker to struct nfulnl_instance Eric Dumazet
2021-12-07  0:51 ` [PATCH net-next 06/17] l2tp: add netns refcount tracker to l2tp_dfs_seq_data Eric Dumazet
2021-12-07  0:51 ` [PATCH net-next 07/17] ppp: add netns refcount tracker Eric Dumazet
2021-12-07  0:51 ` [PATCH net-next 08/17] netfilter: nf_nat_masquerade: add netns refcount tracker to masq_dev_work Eric Dumazet
2021-12-07  0:51 ` [PATCH net-next 09/17] SUNRPC: add netns refcount tracker to struct svc_xprt Eric Dumazet
2021-12-07  0:51 ` [PATCH net-next 10/17] SUNRPC: add netns refcount tracker to struct gss_auth Eric Dumazet
2021-12-07  0:51 ` [PATCH net-next 11/17] SUNRPC: add netns refcount tracker to struct rpc_xprt Eric Dumazet
2021-12-07  0:51 ` [PATCH net-next 12/17] net: initialize init_net earlier Eric Dumazet
2021-12-07  0:51 ` Eric Dumazet [this message]
2021-12-07  0:51 ` [PATCH net-next 14/17] vfs: add netns refcount tracker to struct fs_context Eric Dumazet
2021-12-07  0:51 ` [PATCH net-next 15/17] audit: add netns refcount tracker to struct audit_net Eric Dumazet
2021-12-07 14:40   ` Jakub Kicinski
2021-12-07  0:51 ` [PATCH net-next 16/17] audit: add netns refcount tracker to struct audit_reply Eric Dumazet
2021-12-07  0:51 ` [PATCH net-next 17/17] audit: add netns refcount tracker to struct audit_netlink_list Eric Dumazet
2021-12-09 20:03 ` [PATCH net-next 00/17] net: netns refcount tracking series Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211207005142.1688204-14-eric.dumazet@gmail.com \
    --to=eric.dumazet@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.