Swap the list/hlist write-side operations on @super_blocks and @fs_type->fs_supers over to their _rcu variants. All three call sites still hold sb_lock; this is a purely mechanical change that establishes the writer-side memory ordering lockless RCU readers can rely on in the next patch. The affected sites are sget_fc() (list_add_tail() and hlist_add_head() at the publish step), __put_super() (list_del_init() -> list_bidir_del_rcu() of s_list when the last temporary reference is dropped) and kill_super_notify() (hlist_del_init() -> hlist_del_rcu() of s_instances). @super_blocks gets list_bidir_del_rcu() rather than list_del_rcu() because the next patch walks the list backward for filesystems_freeze() and do_emergency_remount(). list_del_rcu() preserves the unlinked entry's ->next pointer but poisons ->prev with LIST_POISON2, which would crash any concurrent reverse traversal that landed on the just-unlinked entry between the SB_DYING check and the cursor advance. list_bidir_del_rcu() preserves both ->next and ->prev so reverse traversal stays safe. See kernel/nstree.c for the canonical bidirectional-RCU list pattern. The "_init" half of the deletions is not used elsewhere on these list nodes after removal so dropping it is fine. The entry is about to be freed via call_rcu(destroy_super_rcu) (for s_list) or to disappear with the superblock (for s_instances, once the list has done its job notifying SB_DEAD waiters). Iterators keep using plain list_for_each_entry() and hlist_for_each_entry() under sb_lock. Their conversion to lockless RCU traversal with refcount_inc_not_zero() is the next patch. Signed-off-by: Christian Brauner (Amutable) --- fs/super.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/super.c b/fs/super.c index 2fa7023010ec..8c01b95be717 100644 --- a/fs/super.c +++ b/fs/super.c @@ -407,7 +407,7 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags, static void __put_super(struct super_block *s) { if (refcount_dec_and_test(&s->s_count)) { - list_del_init(&s->s_list); + list_bidir_del_rcu(&s->s_list); WARN_ON(s->s_dentry_lru.node); WARN_ON(s->s_inode_lru.node); WARN_ON(s->s_mounts); @@ -445,7 +445,7 @@ static void kill_super_notify(struct super_block *sb) * SB_DEAD. */ spin_lock(&sb_lock); - hlist_del_init(&sb->s_instances); + hlist_del_rcu(&sb->s_instances); spin_unlock(&sb_lock); /* @@ -784,8 +784,8 @@ struct super_block *sget_fc(struct fs_context *fc, * It's in a nascent state and users should wait on SB_BORN or * SB_DYING to be set. */ - list_add_tail(&s->s_list, &super_blocks); - hlist_add_head(&s->s_instances, &s->s_type->fs_supers); + list_add_tail_rcu(&s->s_list, &super_blocks); + hlist_add_head_rcu(&s->s_instances, &s->s_type->fs_supers); spin_unlock(&sb_lock); get_filesystem(s->s_type); shrinker_register(s->s_shrink); -- 2.47.3