Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp454134lqi; Thu, 7 Mar 2024 02:10:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW49QO372rekkHhHWhBJX8GU1rKsvcxgGniRE+GPzxU3CW5I+nzGEpsoRODVrYBwG5DTW90F/8Qra0LS9Uqdz7dR1wnWnLK6Qf4TLc6Xw== X-Google-Smtp-Source: AGHT+IHKsuHrfexBTClSRQIX+XeXnNoeWAmcu03r1/kaA8219cXZtOsMv7/UKN64Nu9nopypJifi X-Received: by 2002:a05:622a:28d:b0:42e:fa57:e07e with SMTP id z13-20020a05622a028d00b0042efa57e07emr8360918qtw.9.1709806204859; Thu, 07 Mar 2024 02:10:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709806204; cv=pass; d=google.com; s=arc-20160816; b=fjnbQ5u90ADv+1Bzy8fSJBldlrU3oxUCdZDUF225Ie8MsSXEFwtNZ0H5MjmTV+z/p2 54AIEg0+FfySepZ3gq1MbiiU1Xaikla949lMDuzOHNw7A0DPn/IzbXYt54J0IgFuShW0 QcyT2t4Wx9+vowNkfyEK0rUxkZRw8fy+d1xsSKJJMi2isS+mGckskphg96H6BvajDuMv OmnXiPhPRBiq6wq8kE2tFkoltWQL3AB59tdqJ5kqz+mo5qpT8z0nLPCX2IIM4XLUJ6Zi ZzWaeaMFT6vDyGVvDmgx+XNXXBjA6LFFwe6DL2A0oyC+U+nb2eHEYoZY+dCv/73NAT67 3wbg== 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=Oa54O49FaYa3ExRL7VX2tppnqcFkfOcwkYNopdNhrj8=; fh=NpmrzqCtAHUIOgMPW1pHVQ4BQctXw1TRIE836xsTmb0=; b=Mmdm/5ZooY6vq0a4S2fOr3B5/JtLRxbPc2R1FirhhKTlpQ4Yl85ou+lKS4x2245U/b 8VDm6WrFAvNgqyGQdFDzx2NkN1tZcet791p5xDMNCstMbWRFQr1vpDo3kXTJlJcFN4qZ pjHacFzf9/nyYEefKJ9aBVbzxnK9B+OZPg4FXUdZT6sa1ceysbzW7AmGPH9sWVR8WHWr KWrbKkX2p9F7DvXvkb6MfmEJI14ZIXjCAe0wwS7KVYJQRp00s1iDL+fMXYJP2tZe4nlM gaWOwWJlccv8vH8KADk70mL9krFr04f2NJJxiiuWU1dCQv3mvHj0Qe4ntojIsHB/0Uk1 o/UA==; 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-95304-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-95304-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id c20-20020a05622a025400b0042f201ccd72si310848qtx.551.2024.03.07.02.10.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 02:10:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-95304-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::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-95304-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-95304-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 876301C2167D for ; Thu, 7 Mar 2024 10:10:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7DB8083CAE; Thu, 7 Mar 2024 10:08:51 +0000 (UTC) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 DC4DC83CBB for ; Thu, 7 Mar 2024 10:08:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709806130; cv=none; b=Te7tLeElunD0wO9n8qgCcSfTwW5Z49vioXoidyWIdDplyHVFWHabgvwdUmDbor82bsQhqf+TwL4++CH8diajCWvE4uUQWhlwJdWx+DLk1n8dm7Gta5wcPUFezNgwshNAaSrGZaPg94YHzh8pq2Qb9RZ6T/5uCpr1wKz8uSBDqr0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709806130; c=relaxed/simple; bh=Whn5ZLyLq1DOG3TJgmxyixKav0+Ndf9qDu+kdSelk7M=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=kJIESUb5eUmsQXcLHBia20Ari3tklmEgnzqItiBtqLZOcqNli4HpviKM8WxVCaKeux9T8vjHCwkVVvI/wwrCRD9iVClpgNucdcSe6qZD3FS/JJt0FS1w7Jzt/PyjAOtJOsLUguwXCtNmasz4E39YfNRwwcdTSKsi3j/ppHO0emI= 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.187 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.163.174]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Tr4hj3HLVzsX8w; Thu, 7 Mar 2024 18:06:45 +0800 (CST) Received: from dggpeml500021.china.huawei.com (unknown [7.185.36.21]) by mail.maildlp.com (Postfix) with ESMTPS id 98A4D140F52; Thu, 7 Mar 2024 18:08:44 +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 18:08:43 +0800 From: Baokun Li To: CC: , , , , , , , , , , , Subject: [PATCH v2] erofs: fix lockdep false positives on initializing erofs_pseudo_mnt Date: Thu, 7 Mar 2024 18:10:18 +0800 Message-ID: <20240307101018.2021925-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: dggems703-chm.china.huawei.com (10.3.19.180) 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 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. Signed-off-by: Baokun Li --- V1->V2: Modified as suggested by Al Viro to simplify the code. 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 89a7c2453aae..122a4753ecea 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 0f0706325b7b..701d4eec693a 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 9b4b66dcdd4f..6fbb1fba2d31 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.31.1