linux-stable/fs/erofs
Baokun Li b50efb417c erofs: fix lockdep false positives on initializing erofs_pseudo_mnt
[ Upstream commit 0f28be64d1 ]

Lockdep reported the following issue when mounting erofs with a domain_id:

============================================
WARNING: possible recursive locking detected
6.8.0-rc7-xfstests #521 Not tainted
--------------------------------------------
mount/396 is trying to acquire lock:
ffff907a8aaaa0e0 (&type->s_umount_key#50/1){+.+.}-{3:3},
						at: alloc_super+0xe3/0x3d0

but task is already holding lock:
ffff907a8aaa90e0 (&type->s_umount_key#50/1){+.+.}-{3:3},
						at: alloc_super+0xe3/0x3d0

other info that might help us debug this:
 Possible unsafe locking scenario:

       CPU0
       ----
  lock(&type->s_umount_key#50/1);
  lock(&type->s_umount_key#50/1);

 *** DEADLOCK ***

 May be due to missing lock nesting notation

2 locks held by mount/396:
 #0: ffff907a8aaa90e0 (&type->s_umount_key#50/1){+.+.}-{3:3},
			at: alloc_super+0xe3/0x3d0
 #1: ffffffffc00e6f28 (erofs_domain_list_lock){+.+.}-{3:3},
			at: erofs_fscache_register_fs+0x3d/0x270 [erofs]

stack backtrace:
CPU: 1 PID: 396 Comm: mount Not tainted 6.8.0-rc7-xfstests #521
Call Trace:
 <TASK>
 dump_stack_lvl+0x64/0xb0
 validate_chain+0x5c4/0xa00
 __lock_acquire+0x6a9/0xd50
 lock_acquire+0xcd/0x2b0
 down_write_nested+0x45/0xd0
 alloc_super+0xe3/0x3d0
 sget_fc+0x62/0x2f0
 vfs_get_super+0x21/0x90
 vfs_get_tree+0x2c/0xf0
 fc_mount+0x12/0x40
 vfs_kern_mount.part.0+0x75/0x90
 kern_mount+0x24/0x40
 erofs_fscache_register_fs+0x1ef/0x270 [erofs]
 erofs_fc_fill_super+0x213/0x380 [erofs]

This is because the file_system_type of both erofs and the pseudo-mount
point of domain_id is erofs_fs_type, so two successive calls to
alloc_super() are considered to be using the same lock and trigger the
warning above.

Therefore add a nodev file_system_type called erofs_anon_fs_type in
fscache.c to silence this complaint. Because kern_mount() takes a
pointer to struct file_system_type, not its (string) name. So we don't
need to call register_filesystem(). In addition, call init_pseudo() in
erofs_anon_init_fs_context() as suggested by Al Viro, so that we can
remove erofs_fc_fill_pseudo_super(), erofs_fc_anon_get_tree(), and
erofs_anon_context_ops.

Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
Fixes: a9849560c5 ("erofs: introduce a pseudo mnt to manage shared cookies")
Signed-off-by: Baokun Li <libaokun1@huawei.com>
Reviewed-and-tested-by: Jingbo Xu <jefflexu@linux.alibaba.com>
Reviewed-by: Yang Erkun <yangerkun@huawei.com>
Link: https://lore.kernel.org/r/20240307101018.2021925-1-libaokun1@huawei.com
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-03-26 18:16:56 -04:00
..
Kconfig netfs, fscache: Combine fscache with netfs 2023-12-24 15:08:46 +00:00
Makefile erofs: DEFLATE compression support 2023-08-11 12:11:17 +08:00
compress.h erofs: relaxed temporary buffers allocation on readahead 2024-01-27 12:28:08 +08:00
data.c erofs: apply proper VMA alignment for memory mapped files on THP 2024-03-07 10:21:10 +08:00
decompressor.c erofs: fix uninitialized page cache reported by KMSAN 2024-03-07 10:21:00 +08:00
decompressor_deflate.c erofs: relaxed temporary buffers allocation on readahead 2024-01-27 12:28:08 +08:00
decompressor_lzma.c erofs: relaxed temporary buffers allocation on readahead 2024-01-27 12:28:08 +08:00
dir.c erofs: keep meta inode into erofs_buf 2023-04-17 01:15:50 +08:00
erofs_fs.h erofs: update on-disk format for xattr name filter 2023-08-11 12:11:44 +08:00
fscache.c erofs: fix lockdep false positives on initializing erofs_pseudo_mnt 2024-03-26 18:16:56 -04:00
inode.c erofs: get rid of unneeded GFP_NOFS 2024-01-25 11:24:19 +08:00
internal.h erofs: fix lockdep false positives on initializing erofs_pseudo_mnt 2024-03-26 18:16:56 -04:00
namei.c erofs: fix refcount on the metabuf used for inode lookup 2024-02-22 15:54:21 +08:00
pcpubuf.c erofs: mark z_erofs_lzma_init/erofs_pcpubuf_init w/ __init 2023-03-09 22:49:30 +08:00
super.c erofs: fix lockdep false positives on initializing erofs_pseudo_mnt 2024-03-26 18:16:56 -04:00
sysfs.c erofs: make kobj_type structures constant 2023-02-15 08:11:26 +08:00
utils.c erofs: get rid of unneeded GFP_NOFS 2024-01-25 11:24:19 +08:00
xattr.c erofs: move erofs_xattr_handlers and xattr_handler_map to .rodata 2023-10-09 16:24:17 +02:00
xattr.h erofs: move erofs_xattr_handlers and xattr_handler_map to .rodata 2023-10-09 16:24:17 +02:00
zdata.c erofs: relaxed temporary buffers allocation on readahead 2024-01-27 12:28:08 +08:00
zmap.c Changes since last update: 2024-01-18 18:12:26 -08:00