Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1387420lqp; Mon, 15 Apr 2024 05:17:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXGFVkkQo2x/sOhf2vWbg12IZnsNSglWokjvtQpoWIvaTs2GefdX/P9PxYxoDJ3VZRtOCYrHIsPuYm4rSYFrCpGAPaX86QIFveUWOtaAA== X-Google-Smtp-Source: AGHT+IGjDzgE7ru2QR44/JG/AD5BabZHP9lcOCOLtg4dtA//twmWN0nbCjEPdxR8v0zAyjy11StA X-Received: by 2002:a05:6358:218d:b0:184:fdc:2590 with SMTP id v13-20020a056358218d00b001840fdc2590mr10996792rwb.20.1713183460766; Mon, 15 Apr 2024 05:17:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713183460; cv=pass; d=google.com; s=arc-20160816; b=uTQNnVXz3J8G18YsmPAYL/EencoBVvZu2R8bg7SnsLhwYINdT6UDOuIHubtd+Wb+Fw NBRobwO98rSW2rsH6IIirV8voM2wv/oXL5TxeD+CZ+BM0sYEoeWbpembDIv4l80+xB5g eB+ooIUxC8uOodiwGCcdu4OJhU7bfW0NvMN6rXGT3Lu7C2yIG3Eg3lBXZa6DbaHUozLb 3QVgfbSWfVX4KliqY9vLSbVytsRbgJdgQAWrToBOWZajJp+JIZnEyIUNargUjxBhqlg6 wN7Wvbbio7YJXc4ttK752hbu6FCX4gMvfKWtoSque+vXdprN88B6R/9ifH0o2ZxXmNZZ cmNA== 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=MUIz2WXcd1HYxzmp7vhIzFMOBXygnNNbAKk+U02jfs0=; fh=U3WCvWtUlTvjXq63Q90uK7RusZkjqVEgDJC5CerGXFc=; b=viTpM1/UlTXX3YqLkrW1JQn3gA3RMFRiJwpFhkIUXrniTCvT0xT2z+61RloHd2dQxz GdDba7jwDmNoWI+XF2lWOVKJ/AXIk7uCjYLDBsuHt4m3NbpGHJGI6FCiS8Wurv/sXDNV CwEpAFMwkvZqWxKpf4QE/twXrjfx354MBXhsivxcmGfdNmg1SZqAjWDJPakC4IMxxZaa r7gVAlXkvzoOvBIvicuKcHVeWQ1UnvSIS25Cwx8FrbisvObo+IcqhVgJCa29jUih8Z4M hpe6oC017Sb+Y7jmqspye1aZIoS4wGIpSlIwfWu/YXGbMmUlOv2V+3xWFxl6VaAUumAX WQJQ==; 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-145049-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145049-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id v3-20020a63b643000000b005f3dca382b4si7594554pgt.476.2024.04.15.05.17.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 05:17:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-145049-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; 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-145049-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145049-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id E9CB0283616 for ; Mon, 15 Apr 2024 12:17:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5D2D06CDD2; Mon, 15 Apr 2024 12:17:29 +0000 (UTC) Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (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 E12C56A008 for ; Mon, 15 Apr 2024 12:17:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713183447; cv=none; b=MTSp0wLrr5pI9KnQDQVsmi4RlQEc0p9EU+Ak3AnSy7q2gH7DyG6iUwJJt1zH/8XZm0N7S7Q8eWFuWU3Mpmme5N2BYas5XpEQP2ac3nj47fA5xpz4Uw1SIlpU9qJWj4CVv7/We4cyPRD+IYB5cb9QBLB+eUBCFYf8toptBJvZAWo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713183447; c=relaxed/simple; bh=/jiMPAHA4Hgspd0jVoWNzbBi1puMkRRhwQ82n/Bi23Q=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=X0TpAJI6rVDZU9gjQ5cIr/4ouMmJm84v8RwcbU2BCxX80+n5VitgIUys/eWHOOXcV0+sM/CC2mvgYDPtHA15Vs9zxDntk5ZDSFmrW7FuMkckluoijEL2UexuNwQkTGM/pdyqBZtQMHrG+RXoePm8Ia1VgP289dFUfpRXc7BAkKE= 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.191 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.44]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4VJ5gr4LxTz1hwSk; Mon, 15 Apr 2024 20:14:16 +0800 (CST) Received: from dggpeml500021.china.huawei.com (unknown [7.185.36.21]) by mail.maildlp.com (Postfix) with ESMTPS id C694014011F; Mon, 15 Apr 2024 20:17:12 +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; Mon, 15 Apr 2024 20:17:12 +0800 From: Baokun Li To: CC: , , , , , , , , , Subject: [PATCH] erofs: set SB_NODEV sb_flags when mounting with fsid Date: Mon, 15 Apr 2024 20:17:46 +0800 Message-ID: <20240415121746.1207242-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) When erofs_kill_sb() is called in block dev based mode, s_bdev may not have been initialised yet, and if CONFIG_EROFS_FS_ONDEMAND is enabled, it will be mistaken for fscache mode, and then attempt to free an anon_dev that has never been allocated, triggering the following warning: ============================================ ida_free called for id=0 which is not allocated. WARNING: CPU: 14 PID: 926 at lib/idr.c:525 ida_free+0x134/0x140 Modules linked in: CPU: 14 PID: 926 Comm: mount Not tainted 6.9.0-rc3-dirty #630 RIP: 0010:ida_free+0x134/0x140 Call Trace: erofs_kill_sb+0x81/0x90 deactivate_locked_super+0x35/0x80 get_tree_bdev+0x136/0x1e0 vfs_get_tree+0x2c/0xf0 do_new_mount+0x190/0x2f0 [...] ============================================ To avoid this problem, add SB_NODEV to fc->sb_flags after successfully parsing the fsid, and then the superblock inherits this flag when it is allocated, so that the sb_flags can be used to distinguish whether it is in block dev based mode when calling erofs_kill_sb(). Signed-off-by: Baokun Li --- fs/erofs/super.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/erofs/super.c b/fs/erofs/super.c index b21bd8f78dc1..7539ce7d64bc 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -520,6 +520,7 @@ static int erofs_fc_parse_param(struct fs_context *fc, ctx->fsid = kstrdup(param->string, GFP_KERNEL); if (!ctx->fsid) return -ENOMEM; + fc->sb_flags |= SB_NODEV; break; case Opt_domain_id: kfree(ctx->domain_id); @@ -706,9 +707,7 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) static int erofs_fc_get_tree(struct fs_context *fc) { - struct erofs_fs_context *ctx = fc->fs_private; - - if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && ctx->fsid) + if (fc->sb_flags & SB_NODEV) return get_tree_nodev(fc, erofs_fc_fill_super); return get_tree_bdev(fc, erofs_fc_fill_super); @@ -801,7 +800,7 @@ static void erofs_kill_sb(struct super_block *sb) { struct erofs_sb_info *sbi; - if (erofs_is_fscache_mode(sb)) + if (sb->s_flags & SB_NODEV) kill_anon_super(sb); else kill_block_super(sb); -- 2.31.1