On Tue, Sep 16, 2025 at 05:46:48AM +0100, Al Viro wrote: > On Tue, Sep 16, 2025 at 04:59:49AM +0100, Al Viro wrote: > > On Tue, Sep 16, 2025 at 04:56:33AM +0100, Al Viro wrote: > > > if (!RB_EMPTY_NODE(to_ns_common(ns)->ns_tree_node)) > > > > if (!RB_EMPTY_NODE(&to_ns_common(ns)->ns_tree_node)) > > > > obviously... > > FWIW, how about the following - I put the commit below into never-rebased > branch, pull it into #work.mount and you do the same to your branch > just prior to 18/33? The difference from one in #work.mount is that > this variant checks RB_EMPTY_NODE(&ns->mnt_ns_tree_node) instead of > list_empty(&ns->mnt_ns_list). The reasons why it's safe lockless are > pretty much the same... > > Objections? Does vfs/vfs.git #no-rebases-mnt_ns_tree_remove look sane > for you?
Perfect, thank you! > > mnt_ns_tree_remove(): DTRT if mnt_ns had never been added to mnt_ns_list > > Actual removal is done under the lock, but for checking if need to bother > the lockless RB_EMPTY_NODE() is safe - either that namespace had never > been added to mnt_ns_tree, in which case the the node will stay empty, or > whoever had allocated it has called mnt_ns_tree_add() and it has already > run to completion. After that point RB_EMPTY_NODE() will become false and > will remain false, no matter what we do with other nodes in the tree. > > Signed-off-by: Al Viro <v...@zeniv.linux.org.uk> > --- > diff --git a/fs/namespace.c b/fs/namespace.c > index ae6d1312b184..39afeb521a80 100644 > --- a/fs/namespace.c > +++ b/fs/namespace.c > @@ -187,7 +187,7 @@ static void mnt_ns_release_rcu(struct rcu_head *rcu) > static void mnt_ns_tree_remove(struct mnt_namespace *ns) > { > /* remove from global mount namespace list */ > - if (!is_anon_ns(ns)) { > + if (!RB_EMPTY_NODE(&ns->mnt_ns_tree_node)) { > mnt_ns_tree_write_lock(); > rb_erase(&ns->mnt_ns_tree_node, &mnt_ns_tree); > list_bidir_del_rcu(&ns->mnt_ns_list);