Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp299537lqi; Wed, 6 Mar 2024 18:44:59 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW0UiJjoFQl+2HsiU5lUknH3PcmOKg/HJPDoOagU9jST6jRKN2JIfLASwP3HpD2fNCvzYL+NCFWsvAMlZuWLAhhdQ6EZMztjA9SmRbTAg== X-Google-Smtp-Source: AGHT+IHKJ+cHXQ0eLD0tCwyiLh/8Ixvyu0wAlY7uZypb43JvtPqNnjTq/rwLcdDSA8xPTtUCx7CV X-Received: by 2002:a05:6358:7e8b:b0:17b:c7b8:be7f with SMTP id o11-20020a0563587e8b00b0017bc7b8be7fmr8379012rwn.32.1709779499416; Wed, 06 Mar 2024 18:44:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709779499; cv=pass; d=google.com; s=arc-20160816; b=Ih3/fej2yW90T9GpPgFjTL9P8RSTP/AujzBSZcJXEJyIcd0wAQIRLh/kM0P9djql9p G4M/ZDfdDJHtIBxaqd3giDUg9l0z51o5LCC6kMDNZmmxuN04e7Eglhb1KupVdeqfiS63 6xKm8OnTC9oWedpoJldcHcL5IP2UWPC0+OhXNdt55ISBY4WZyPLbkd6/IjvnS9IvSnb3 XHN3AI//ATXi9h2SFUh5AM2TYnh14f+QG6KcS72r54kL/vBioBDBTmsm/P4tF6RPDY2n vVZ64Ag1HKqMELsu7nP4TpuiBf4Zg0xaJxArNfEjO4k0pfS1dTK3Cdrno3AoHSb97d5d /Z+A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=roXAKIyD1Es5HHbfbabufI3pRvjacQcWDWOoQ3TxeS4=; fh=wxS4d8T9SsehhtyvruNcrD7uk0MkTd1n4hh3H0ha8FE=; b=tjfkadSX06kTcl7uTjB1QIWmm8RmrdZ1NLXZ9vwPbKdBJjukguzqkrmU8e+yrnOmsY Sq4gz9K9G3FPHpJRovRZuVxXb5xAT46ijlz58mn5TAYmAjhXrp2E0Z6wANUvvub44EPH FdBHpfWlXPDc3bl7o8rU2uHVKS5njtwSjG7ioUbud5olawfLdUf0HZ8JBfnQj4Tvs/v7 S84CdFHcOwzX7rqBsV1UV6cZtX5eHauKoXgFfurI8Uag9cdbAwX6bUXNtH9lH55Lg6eX /LN1aaBaosv3Wz4dhiL25MkUxcckrgQ1ZQy9CCTqycKVC7hkzoLk49JBvbWEs5I1FJqD O0LA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-94880-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94880-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 10-20020a63174a000000b005dc67975e49si13146127pgx.897.2024.03.06.18.44.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 18:44:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-94880-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-94880-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94880-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id CE828B22782 for ; Thu, 7 Mar 2024 02:44:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7D5345C89; Thu, 7 Mar 2024 02:43:32 +0000 (UTC) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04BEF4C83 for ; Thu, 7 Mar 2024 02:43:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709779411; cv=none; b=bytCDH1OKBBBpJ8vHhBTGYekH5zhbUbLc01SBThIT3oMR6/ctoQFom4FiB3DKcWO5A1OmGZDSDRrjyBVneO4V69nS9hTh2r1Ux/kefymXotHROLCBMcXJ9Uh9ZksRTz/cdjdLs+M9LAZyq+6V82tg8myW1W+9JRYROlNw/KTDes= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709779411; c=relaxed/simple; bh=IFJcv5OolozBC9RcBgjiB5PcgCxmVMNlt2wVg1YxrU8=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=LoxwURl4idkC43f928afnD7r8NXmuUjJizxNkCXYDJITSWtihKKuBfhDH79tTr3033mqdHwQP5qgccd9SOiry0jpCT/RODvuzozsdgapLENDjDIDS1RH1uZbqQRuiMcMhDtqGlOM4UatPo77fjePcKhQv1IOutr9N8+3neftFTU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4TqtrM0mvxzbcpg; Thu, 7 Mar 2024 10:42:43 +0800 (CST) Received: from dggpeml500021.china.huawei.com (unknown [7.185.36.21]) by mail.maildlp.com (Postfix) with ESMTPS id C8B4418001D; Thu, 7 Mar 2024 10:43:25 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggpeml500021.china.huawei.com (7.185.36.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Thu, 7 Mar 2024 10:43:25 +0800 From: Baokun Li To: CC: , , , , , , , , , Subject: [PATCH] erofs: fix lockdep false positives on initializing erofs_pseudo_mnt Date: Thu, 7 Mar 2024 10:44:59 +0800 Message-ID: <20240307024459.883044-1-libaokun1@huawei.com> X-Mailer: git-send-email 2.31.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500021.china.huawei.com (7.185.36.21) 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: 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 named erofs_anon_fs_type to silence this complaint. In addition, to reduce code coupling, refactor out the erofs_anon_init_fs_context() and erofs_kill_pseudo_sb() functions and move the erofs_pseudo_mnt related code to fscache.c. Signed-off-by: Baokun Li --- fs/erofs/fscache.c | 48 ++++++++++++++++++++++++++++++++++++++++++++- fs/erofs/internal.h | 10 +++++++++- fs/erofs/super.c | 37 ++++++++-------------------------- 3 files changed, 64 insertions(+), 31 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 89a7c2453aae..a346884a2c00 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -4,6 +4,7 @@ * Copyright (C) 2022, Bytedance Inc. All rights reserved. */ #include +#include #include "internal.h" static DEFINE_MUTEX(erofs_domain_list_lock); @@ -12,6 +13,51 @@ static LIST_HEAD(erofs_domain_list); static LIST_HEAD(erofs_domain_cookies_list); static struct vfsmount *erofs_pseudo_mnt; +static int +erofs_fc_fill_pseudo_super(struct super_block *sb, struct fs_context *fc) +{ + static const struct tree_descr empty_descr = {""}; + + return simple_fill_super(sb, EROFS_SUPER_MAGIC, &empty_descr); +} + +static int erofs_fc_anon_get_tree(struct fs_context *fc) +{ + return get_tree_nodev(fc, erofs_fc_fill_pseudo_super); +} + +static const struct fs_context_operations erofs_anon_context_ops = { + .get_tree = erofs_fc_anon_get_tree, +}; + +static int erofs_anon_init_fs_context(struct fs_context *fc) +{ + fc->ops = &erofs_anon_context_ops; + return 0; +} + +static void erofs_kill_pseudo_sb(struct super_block *sb) +{ + kill_anon_super(sb); +} + +static struct file_system_type erofs_anon_fs_type = { + .owner = THIS_MODULE, + .name = "pseudo_erofs", + .init_fs_context = erofs_anon_init_fs_context, + .kill_sb = erofs_kill_pseudo_sb, +}; + +int erofs_anon_register_fs(void) +{ + return register_filesystem(&erofs_anon_fs_type); +} + +void erofs_anon_unregister_fs(void) +{ + unregister_filesystem(&erofs_anon_fs_type); +} + struct erofs_fscache_request { struct erofs_fscache_request *primary; struct netfs_cache_resources cache_resources; @@ -381,7 +427,7 @@ static int erofs_fscache_init_domain(struct super_block *sb) goto out; if (!erofs_pseudo_mnt) { - struct vfsmount *mnt = kern_mount(&erofs_fs_type); + struct vfsmount *mnt = kern_mount(&erofs_anon_fs_type); if (IS_ERR(mnt)) { err = PTR_ERR(mnt); goto out; diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 0f0706325b7b..d9e30ccceb39 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -385,7 +385,6 @@ struct erofs_map_dev { unsigned int m_deviceid; }; -extern struct file_system_type erofs_fs_type; extern const struct super_operations erofs_sops; extern const struct address_space_operations erofs_raw_access_aops; @@ -507,6 +506,9 @@ static inline int z_erofs_deflate_exit(void) { return 0; } #endif /* !CONFIG_EROFS_FS_ZIP_DEFLATE */ #ifdef CONFIG_EROFS_FS_ONDEMAND +int erofs_anon_register_fs(void); +void erofs_anon_unregister_fs(void); + int erofs_fscache_register_fs(struct super_block *sb); void erofs_fscache_unregister_fs(struct super_block *sb); @@ -514,6 +516,12 @@ struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, char *name, unsigned int flags); void erofs_fscache_unregister_cookie(struct erofs_fscache *fscache); #else +static inline int erofs_anon_register_fs(void) +{ + return 0; +} +static inline void erofs_anon_unregister_fs(void) {} + static inline int erofs_fscache_register_fs(struct super_block *sb) { return -EOPNOTSUPP; diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 9b4b66dcdd4f..a745010e9fe6 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -579,13 +579,6 @@ static const struct export_operations erofs_export_ops = { .get_parent = erofs_get_parent, }; -static int erofs_fc_fill_pseudo_super(struct super_block *sb, struct fs_context *fc) -{ - static const struct tree_descr empty_descr = {""}; - - return simple_fill_super(sb, EROFS_SUPER_MAGIC, &empty_descr); -} - static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) { struct inode *inode; @@ -712,11 +705,6 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) return 0; } -static int erofs_fc_anon_get_tree(struct fs_context *fc) -{ - return get_tree_nodev(fc, erofs_fc_fill_pseudo_super); -} - static int erofs_fc_get_tree(struct fs_context *fc) { struct erofs_fs_context *ctx = fc->fs_private; @@ -789,20 +777,10 @@ static const struct fs_context_operations erofs_context_ops = { .free = erofs_fc_free, }; -static const struct fs_context_operations erofs_anon_context_ops = { - .get_tree = erofs_fc_anon_get_tree, -}; - static int erofs_init_fs_context(struct fs_context *fc) { struct erofs_fs_context *ctx; - /* pseudo mount for anon inodes */ - if (fc->sb_flags & SB_KERNMOUNT) { - fc->ops = &erofs_anon_context_ops; - return 0; - } - ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); if (!ctx) return -ENOMEM; @@ -824,12 +802,6 @@ static void erofs_kill_sb(struct super_block *sb) { struct erofs_sb_info *sbi; - /* pseudo mount for anon inodes */ - if (sb->s_flags & SB_KERNMOUNT) { - kill_anon_super(sb); - return; - } - if (erofs_is_fscache_mode(sb)) kill_anon_super(sb); else @@ -868,7 +840,7 @@ static void erofs_put_super(struct super_block *sb) erofs_fscache_unregister_fs(sb); } -struct file_system_type erofs_fs_type = { +static struct file_system_type erofs_fs_type = { .owner = THIS_MODULE, .name = "erofs", .init_fs_context = erofs_init_fs_context, @@ -911,6 +883,10 @@ static int __init erofs_module_init(void) if (err) goto sysfs_err; + err = erofs_anon_register_fs(); + if (err) + goto anon_err; + err = register_filesystem(&erofs_fs_type); if (err) goto fs_err; @@ -918,6 +894,8 @@ static int __init erofs_module_init(void) return 0; fs_err: + erofs_anon_unregister_fs(); +anon_err: erofs_exit_sysfs(); sysfs_err: z_erofs_exit_zip_subsystem(); @@ -935,6 +913,7 @@ static int __init erofs_module_init(void) static void __exit erofs_module_exit(void) { unregister_filesystem(&erofs_fs_type); + erofs_anon_unregister_fs(); /* Ensure all RCU free inodes / pclusters are safe to be destroyed. */ rcu_barrier(); -- 2.31.1