Skip to content

Commit 0f28be6

Browse files
LiBaokun96hsiangkao
authored andcommitted
erofs: fix lockdep false positives on initializing erofs_pseudo_mnt
Lockdep reported the following issue when mounting erofs with a domain_id: ============================================ WARNING: possible recursive locking detected 6.8.0-rc7-xfstests torvalds#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 torvalds#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 <[email protected]> Fixes: a984956 ("erofs: introduce a pseudo mnt to manage shared cookies") Signed-off-by: Baokun Li <[email protected]> Reviewed-and-tested-by: Jingbo Xu <[email protected]> Reviewed-by: Yang Erkun <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Gao Xiang <[email protected]>
1 parent 706fd68 commit 0f28be6

File tree

3 files changed

+15
-31
lines changed

3 files changed

+15
-31
lines changed

fs/erofs/fscache.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright (C) 2022, Alibaba Cloud
44
* Copyright (C) 2022, Bytedance Inc. All rights reserved.
55
*/
6+
#include <linux/pseudo_fs.h>
67
#include <linux/fscache.h>
78
#include "internal.h"
89

@@ -12,6 +13,18 @@ static LIST_HEAD(erofs_domain_list);
1213
static LIST_HEAD(erofs_domain_cookies_list);
1314
static struct vfsmount *erofs_pseudo_mnt;
1415

16+
static int erofs_anon_init_fs_context(struct fs_context *fc)
17+
{
18+
return init_pseudo(fc, EROFS_SUPER_MAGIC) ? 0 : -ENOMEM;
19+
}
20+
21+
static struct file_system_type erofs_anon_fs_type = {
22+
.owner = THIS_MODULE,
23+
.name = "pseudo_erofs",
24+
.init_fs_context = erofs_anon_init_fs_context,
25+
.kill_sb = kill_anon_super,
26+
};
27+
1528
struct erofs_fscache_request {
1629
struct erofs_fscache_request *primary;
1730
struct netfs_cache_resources cache_resources;
@@ -381,7 +394,7 @@ static int erofs_fscache_init_domain(struct super_block *sb)
381394
goto out;
382395

383396
if (!erofs_pseudo_mnt) {
384-
struct vfsmount *mnt = kern_mount(&erofs_fs_type);
397+
struct vfsmount *mnt = kern_mount(&erofs_anon_fs_type);
385398
if (IS_ERR(mnt)) {
386399
err = PTR_ERR(mnt);
387400
goto out;

fs/erofs/internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,6 @@ struct erofs_map_dev {
385385
unsigned int m_deviceid;
386386
};
387387

388-
extern struct file_system_type erofs_fs_type;
389388
extern const struct super_operations erofs_sops;
390389

391390
extern const struct address_space_operations erofs_raw_access_aops;

fs/erofs/super.c

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -579,13 +579,6 @@ static const struct export_operations erofs_export_ops = {
579579
.get_parent = erofs_get_parent,
580580
};
581581

582-
static int erofs_fc_fill_pseudo_super(struct super_block *sb, struct fs_context *fc)
583-
{
584-
static const struct tree_descr empty_descr = {""};
585-
586-
return simple_fill_super(sb, EROFS_SUPER_MAGIC, &empty_descr);
587-
}
588-
589582
static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
590583
{
591584
struct inode *inode;
@@ -712,11 +705,6 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
712705
return 0;
713706
}
714707

715-
static int erofs_fc_anon_get_tree(struct fs_context *fc)
716-
{
717-
return get_tree_nodev(fc, erofs_fc_fill_pseudo_super);
718-
}
719-
720708
static int erofs_fc_get_tree(struct fs_context *fc)
721709
{
722710
struct erofs_fs_context *ctx = fc->fs_private;
@@ -789,20 +777,10 @@ static const struct fs_context_operations erofs_context_ops = {
789777
.free = erofs_fc_free,
790778
};
791779

792-
static const struct fs_context_operations erofs_anon_context_ops = {
793-
.get_tree = erofs_fc_anon_get_tree,
794-
};
795-
796780
static int erofs_init_fs_context(struct fs_context *fc)
797781
{
798782
struct erofs_fs_context *ctx;
799783

800-
/* pseudo mount for anon inodes */
801-
if (fc->sb_flags & SB_KERNMOUNT) {
802-
fc->ops = &erofs_anon_context_ops;
803-
return 0;
804-
}
805-
806784
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
807785
if (!ctx)
808786
return -ENOMEM;
@@ -824,12 +802,6 @@ static void erofs_kill_sb(struct super_block *sb)
824802
{
825803
struct erofs_sb_info *sbi;
826804

827-
/* pseudo mount for anon inodes */
828-
if (sb->s_flags & SB_KERNMOUNT) {
829-
kill_anon_super(sb);
830-
return;
831-
}
832-
833805
if (erofs_is_fscache_mode(sb))
834806
kill_anon_super(sb);
835807
else
@@ -868,7 +840,7 @@ static void erofs_put_super(struct super_block *sb)
868840
erofs_fscache_unregister_fs(sb);
869841
}
870842

871-
struct file_system_type erofs_fs_type = {
843+
static struct file_system_type erofs_fs_type = {
872844
.owner = THIS_MODULE,
873845
.name = "erofs",
874846
.init_fs_context = erofs_init_fs_context,

0 commit comments

Comments
 (0)