Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2380082lqp; Sun, 24 Mar 2024 16:50:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU1Z994EQC0i2nwbxVLyZLTzsXD7mW7ZxscDsbFlf1M9aMn6eUXEHL/2Eciz8sztY47SZGJd1nYhweu4GqgSt4Yj5lsk3JEi02G2xN0/w== X-Google-Smtp-Source: AGHT+IHoJyixf0dV79aNumY54BCx0K4TJopGSlrnFdnzpdRBxAWrBCIKmA6LoiKcvECOfbv3deOy X-Received: by 2002:a05:6a20:3944:b0:1a3:add6:96ab with SMTP id r4-20020a056a20394400b001a3add696abmr7512818pzg.21.1711324222990; Sun, 24 Mar 2024 16:50:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711324222; cv=pass; d=google.com; s=arc-20160816; b=CMjebSEn9AcEWXYTziH76iPzeb01GxVD/jr8G3gJr/IrhMYkLXR2rC6iPd7kedtXSK FZdgWbukm2zMn8D5IO8mebY1H4ybsH6kevLtjDm24Mq5uynblE8AAKlVdWTfv3MHKFGY AdOJZ4o8WlrPry1inNvAR/+z+Pnf3M8VJmUKIJZV5uy3lWX8FCgiRjpzDEj5/CvMSJqB 8IwNKUhZqrrRnaEnv8SZWrZdoqwUEb9rn4aMfg4seRXZLE+N4knINPawbThjiujBbQBb PLQT5uOOIqF1OO6yFHEO/ZID9rJ0s5O413idn9zad8r46Dp4xakBovzBshTGMjKfxd1X xutg== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=cTtFy5FecD4Dw924aTeGSxM3FWH3yfxI8seobQ88E0o=; fh=lOTZgZHHxejyL63Y8MfgX1mRlMbqL8vKwfEZJ3DT1UQ=; b=T9aQPO3Do80rO4BcVLzX5tu9J4mBPUoluk+964QfIMZYieFTF1pDHqBsb3MlWlQ6si jRFgtV5fLE+2Ua87/1pnE4jdlohGv5dzZ/5VobQfducZePJOUvATJFDqCNvFyC6obI8o tTlVCVpAvtSh9wQU40i8LJO9/o6SfYDLjqWwMq2CbVkOrLVFme57GuUgYYGDLMqDOVGH ByXsmxnOc5zX0AK8RBXXYQSJawbGwCyj7GW97KwZCBDjFZAMu1e8a84AbVVV5nkyR9YM OAYy63F8eMageoXMWMD+K9Xr0a924v1BZ+LY73XuxK6cS6t604VZcd+ffsvxkPxRSc56 isCQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=A3AazCkb; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113226-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113226-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id e23-20020a63db17000000b005dccf9c665csi6373631pgg.664.2024.03.24.16.50.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 16:50:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113226-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=A3AazCkb; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113226-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113226-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 30D6328A82F for ; Sun, 24 Mar 2024 23:49:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A0472182770; Sun, 24 Mar 2024 22:40:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="A3AazCkb" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 684AF18274B; Sun, 24 Mar 2024 22:40:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320027; cv=none; b=rqS07AM+Uie5VyKCJnXMkqhhSNYgCyEvevSCoQ8EziY7Esrhh2FnzvbtssYH6zpktcfkzQCfrSIsfVGKhqPTajjgNIRrFr0X0E5svA3S9TcOsKRRZ2xGGIi1rsNVQBbXbMhJk5H6cyW/ca+k/4V96q9VUBimB4sdo24jZQtB7z4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320027; c=relaxed/simple; bh=jLep0Qm18v0+lf/rVqUKcq5gN5cPgy//4JMpC19HHDY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KEshDfAv6+epRtHXQZV0oLbuTGUsmMGwfB0d8wJ2R0OArf2zNbVK8wtbKCpgPHNfrjypExGuUg+Qf3XzGoWOBPmU9oej9tjNeawIVigpn+s1cK7MvHVBV+ys8DHUFvGTPHOxT5B/kGTrqgtQqoSUita164N9+/3yC47IrcLoUsM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=A3AazCkb; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6071CC433C7; Sun, 24 Mar 2024 22:40:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320027; bh=jLep0Qm18v0+lf/rVqUKcq5gN5cPgy//4JMpC19HHDY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A3AazCkbZYPD4vbVu4kESQjg7BgZTLja2Br506PJw3+4k1boeM6X0QEQrpc5LAURp T1gcfvsJSYVchQEGvlDI5L5AOTaKaFYPhp1KSykRk6RbLy7IcGu1Xd1OTNSKWxL1Jr Gpe2PMZVK1nK1JA8GivvA2X9gJ92/6ZqHG3sYEMhFUU9R6FqrPqYmTGbylqm9IbiJS KmBn1UTxvC/jxp4GplWI17PF/QTuClkl/UBnrdQB7mlPwPJ+VfO1HryJM97anUzRgs eBkcb8gSMXkS+vlXANYhggvcefnx8awuE9YOw0UrRimJ2znsYH1qOwjSYReHHrsLGU WdS821SNQqMYQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Baokun Li , Al Viro , Jingbo Xu , Yang Erkun , Gao Xiang , Sasha Levin Subject: [PATCH 6.8 335/715] erofs: fix lockdep false positives on initializing erofs_pseudo_mnt Date: Sun, 24 Mar 2024 18:28:34 -0400 Message-ID: <20240324223455.1342824-336-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Baokun Li [ Upstream commit 0f28be64d132aaf95d06375c8002ad9ecea69d71 ] 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 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 Fixes: a9849560c55e ("erofs: introduce a pseudo mnt to manage shared cookies") Signed-off-by: Baokun Li Reviewed-and-tested-by: Jingbo Xu Reviewed-by: Yang Erkun Link: https://lore.kernel.org/r/20240307101018.2021925-1-libaokun1@huawei.com Signed-off-by: Gao Xiang Signed-off-by: Sasha Levin --- fs/erofs/fscache.c | 15 ++++++++++++++- fs/erofs/internal.h | 1 - fs/erofs/super.c | 30 +----------------------------- 3 files changed, 15 insertions(+), 31 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 89a7c2453aae6..122a4753ecea4 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -3,6 +3,7 @@ * Copyright (C) 2022, Alibaba Cloud * Copyright (C) 2022, Bytedance Inc. All rights reserved. */ +#include #include #include "internal.h" @@ -12,6 +13,18 @@ static LIST_HEAD(erofs_domain_list); static LIST_HEAD(erofs_domain_cookies_list); static struct vfsmount *erofs_pseudo_mnt; +static int erofs_anon_init_fs_context(struct fs_context *fc) +{ + return init_pseudo(fc, EROFS_SUPER_MAGIC) ? 0 : -ENOMEM; +} + +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 = kill_anon_super, +}; + struct erofs_fscache_request { struct erofs_fscache_request *primary; struct netfs_cache_resources cache_resources; @@ -381,7 +394,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 b0409badb0172..410f5af623540 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; diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 5f60f163bd56e..24788c230b494 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, -- 2.43.0