From: Kuniyuki Iwashima <kuniyu@google.com>
To: brauner@kernel.org
Cc: amir73il@gmail.com, axboe@kernel.dk, cgroups@vger.kernel.org,
chuck.lever@oracle.com, cyphar@cyphar.com,
daan.j.demeyer@gmail.com, edumazet@google.com,
hannes@cmpxchg.org, horms@kernel.org, jack@suse.cz,
jlayton@kernel.org, josef@toxicpanda.com, kuba@kernel.org,
linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-nfs@vger.kernel.org, me@yhndnzj.com, mkoutny@suse.com,
mzxreary@0pointer.de, netdev@vger.kernel.org, pabeni@redhat.com,
tj@kernel.org, viro@zeniv.linux.org.uk, zbyszek@in.waw.pl,
kuniyu@google.com
Subject: Re: [PATCH v2 21/33] net: support ns lookup
Date: Tue, 16 Sep 2025 03:59:34 +0000 [thread overview]
Message-ID: <20250916040214.319783-1-kuniyu@google.com> (raw)
In-Reply-To: <20250912-work-namespace-v2-21-1a247645cef5@kernel.org>
From: Christian Brauner <brauner@kernel.org>
Date: Fri, 12 Sep 2025 13:52:44 +0200
> Support the generic ns lookup infrastructure to support file handles for
> namespaces.
>
> The network namespace has a separate list with different lifetime rules
> which we can just leave in tact. We have a similar concept for mount
> namespaces as well where it is on two differenet lists for different
> purposes.
>
> Signed-off-by: Christian Brauner <brauner@kernel.org>
> ---
> include/net/net_namespace.h | 1 +
> net/core/net_namespace.c | 8 ++++++--
> 2 files changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
> index 025a7574b275..42075748dff1 100644
> --- a/include/net/net_namespace.h
> +++ b/include/net/net_namespace.h
> @@ -11,6 +11,7 @@
> #include <linux/list.h>
> #include <linux/sysctl.h>
> #include <linux/uidgid.h>
> +#include <linux/nstree.h>
>
> #include <net/flow.h>
> #include <net/netns/core.h>
> diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
> index 5fb7bd8ac45a..169ec22c4758 100644
> --- a/net/core/net_namespace.c
> +++ b/net/core/net_namespace.c
> @@ -20,6 +20,7 @@
> #include <linux/sched/task.h>
> #include <linux/uidgid.h>
> #include <linux/proc_fs.h>
> +#include <linux/nstree.h>
>
> #include <net/aligned_data.h>
nit: This is no longer necessary.
> #include <net/sock.h>
> @@ -445,7 +446,7 @@ static __net_init int setup_net(struct net *net)
> LIST_HEAD(net_exit_list);
> int error = 0;
>
> - net->net_cookie = atomic64_inc_return(&net_aligned_data.net_cookie);
> + net->net_cookie = ns_tree_gen_id(&net->ns);
>
> list_for_each_entry(ops, &pernet_list, list) {
> error = ops_init(ops, net);
> @@ -455,6 +456,7 @@ static __net_init int setup_net(struct net *net)
> down_write(&net_rwsem);
> list_add_tail_rcu(&net->list, &net_namespace_list);
> up_write(&net_rwsem);
> + ns_tree_add_raw(net);
> out:
> return error;
>
> @@ -674,8 +676,10 @@ static void cleanup_net(struct work_struct *work)
>
> /* Don't let anyone else find us. */
> down_write(&net_rwsem);
> - llist_for_each_entry(net, net_kill_list, cleanup_list)
> + llist_for_each_entry(net, net_kill_list, cleanup_list) {
> + ns_tree_remove(net);
Looking at refcount_inc_not_zero() in nsfs_fh_to_dentry(),
I think ns_tree_remove() fits better in __put_net() which
is called just after refcount_dec_and_test(&net->ns.count).
cleanup_net() is single threaded work and somtimes takes long with
too many netns and the netns may stay longer unnecessarily until
next cleanup_net().
> list_del_rcu(&net->list);
> + }
> /* Cache last net. After we unlock rtnl, no one new net
> * added to net_namespace_list can assign nsid pointer
> * to a net from net_kill_list (see peernet2id_alloc()).
>
> --
> 2.47.3
next prev parent reply other threads:[~2025-09-16 4:02 UTC|newest]
Thread overview: 71+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-12 11:52 [PATCH v2 00/33] ns: support file handles Christian Brauner
2025-09-12 11:52 ` [PATCH v2 01/33] pidfs: validate extensible ioctls Christian Brauner
2025-09-12 11:52 ` [PATCH v2 02/33] nsfs: drop tautological ioctl() check Christian Brauner
2025-09-12 11:52 ` [PATCH v2 03/33] nsfs: validate extensible ioctls Christian Brauner
2025-09-12 11:52 ` [PATCH v2 04/33] block: use extensible_ioctl_valid() Christian Brauner
2025-09-16 11:18 ` Mark Brown
2025-09-16 13:40 ` Dan Carpenter
2025-09-18 13:17 ` Jan Kara
2025-09-19 12:28 ` Christian Brauner
2025-09-12 11:52 ` [PATCH v2 05/33] ns: move to_ns_common() to ns_common.h Christian Brauner
2025-09-12 11:52 ` [PATCH v2 06/33] nsfs: add nsfs.h header Christian Brauner
2025-09-12 11:52 ` [PATCH v2 07/33] ns: uniformly initialize ns_common Christian Brauner
2025-09-12 11:52 ` [PATCH v2 08/33] cgroup: use ns_common_init() Christian Brauner
2025-09-12 15:48 ` Tejun Heo
2025-09-12 11:52 ` [PATCH v2 09/33] ipc: " Christian Brauner
2025-09-12 11:52 ` [PATCH v2 10/33] mnt: " Christian Brauner
2025-09-12 11:52 ` [PATCH v2 11/33] net: " Christian Brauner
2025-09-15 11:07 ` Jan Kara
2025-09-15 11:42 ` Christian Brauner
2025-09-15 11:50 ` Jan Kara
2025-09-15 22:59 ` Al Viro
2025-09-12 11:52 ` [PATCH v2 12/33] pid: " Christian Brauner
2025-09-12 11:52 ` [PATCH v2 13/33] time: " Christian Brauner
2025-09-12 11:52 ` [PATCH v2 14/33] user: " Christian Brauner
2025-09-12 11:52 ` [PATCH v2 15/33] uts: " Christian Brauner
2025-09-12 11:52 ` [PATCH v2 16/33] ns: remove ns_alloc_inum() Christian Brauner
2025-09-12 11:52 ` [PATCH v2 17/33] nstree: make iterator generic Christian Brauner
2025-09-15 11:49 ` Jan Kara
2025-09-12 11:52 ` [PATCH v2 18/33] mnt: support ns lookup Christian Brauner
2025-09-15 11:48 ` Jan Kara
2025-09-15 13:45 ` Christian Brauner
2025-09-16 3:24 ` Kuniyuki Iwashima
2025-09-16 3:59 ` Al Viro
2025-09-16 3:56 ` Al Viro
2025-09-16 3:59 ` Al Viro
2025-09-16 4:46 ` Al Viro
2025-09-17 9:50 ` Christian Brauner
2025-09-18 10:21 ` Al Viro
2025-09-12 11:52 ` [PATCH v2 19/33] cgroup: " Christian Brauner
2025-09-15 11:53 ` Jan Kara
2025-09-12 11:52 ` [PATCH v2 20/33] ipc: " Christian Brauner
2025-09-15 11:56 ` Jan Kara
2025-09-12 11:52 ` [PATCH v2 21/33] net: " Christian Brauner
2025-09-15 12:02 ` Jan Kara
2025-09-15 13:47 ` Christian Brauner
2025-09-16 3:59 ` Kuniyuki Iwashima [this message]
2025-09-12 11:52 ` [PATCH v2 22/33] pid: " Christian Brauner
2025-09-15 12:04 ` Jan Kara
2025-09-12 11:52 ` [PATCH v2 23/33] time: " Christian Brauner
2025-09-15 12:06 ` Jan Kara
2025-09-12 11:52 ` [PATCH v2 24/33] user: " Christian Brauner
2025-09-15 12:11 ` Jan Kara
2025-09-15 13:54 ` Christian Brauner
2025-09-15 14:14 ` Jan Kara
2025-09-12 11:52 ` [PATCH v2 25/33] uts: " Christian Brauner
2025-09-15 12:59 ` Jan Kara
2025-09-12 11:52 ` [PATCH v2 26/33] ns: add to_<type>_ns() to respective headers Christian Brauner
2025-09-15 12:06 ` Jan Kara
2025-09-12 11:52 ` [PATCH v2 27/33] nsfs: add current_in_namespace() Christian Brauner
2025-09-15 13:08 ` Jan Kara
2025-09-12 11:52 ` [PATCH v2 28/33] nsfs: support file handles Christian Brauner
2025-09-15 13:25 ` Jan Kara
2025-09-15 13:55 ` Christian Brauner
2025-09-12 11:52 ` [PATCH v2 29/33] nsfs: support exhaustive " Christian Brauner
2025-09-15 13:26 ` Jan Kara
2025-09-12 11:52 ` [PATCH v2 30/33] nsfs: add missing id retrieval support Christian Brauner
2025-09-15 13:28 ` Jan Kara
2025-09-12 11:52 ` [PATCH v2 31/33] tools: update nsfs.h uapi header Christian Brauner
2025-09-12 11:52 ` [PATCH v2 32/33] selftests/namespaces: add identifier selftests Christian Brauner
2025-09-12 11:52 ` [PATCH v2 33/33] selftests/namespaces: add file handle selftests Christian Brauner
2025-09-16 4:55 ` [PATCH v2 00/33] ns: support file handles Al Viro
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=20250916040214.319783-1-kuniyu@google.com \
--to=kuniyu@google.com \
--cc=amir73il@gmail.com \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=chuck.lever@oracle.com \
--cc=cyphar@cyphar.com \
--cc=daan.j.demeyer@gmail.com \
--cc=edumazet@google.com \
--cc=hannes@cmpxchg.org \
--cc=horms@kernel.org \
--cc=jack@suse.cz \
--cc=jlayton@kernel.org \
--cc=josef@toxicpanda.com \
--cc=kuba@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=me@yhndnzj.com \
--cc=mkoutny@suse.com \
--cc=mzxreary@0pointer.de \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=tj@kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=zbyszek@in.waw.pl \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).