Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp2027562lqp; Tue, 16 Apr 2024 05:35:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXvki3eZObsVw//umMTv6+2zusB/BrW1BLvQYEp3BqAUF3DjRm+83v73mTGebXZ2ChzmoO8WKqDwQfCEX+FVAQq3iTEhdy2v8+5QzObcg== X-Google-Smtp-Source: AGHT+IHK3I5bVlOourVeZXYiBB7QgVRHMTXslySp7/RQYcEwwbnRCZuXJPfXXXbIwcLAA3JWVnSj X-Received: by 2002:a05:6214:c43:b0:699:2673:1dea with SMTP id r3-20020a0562140c4300b0069926731deamr15603388qvj.33.1713270926614; Tue, 16 Apr 2024 05:35:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713270926; cv=pass; d=google.com; s=arc-20160816; b=eYS7h+NLPicnnUA/Us7E8QBZMPB3QKv2D5fm8MvJTw5RM3esftYP2gVV7YOKOd8vEc Zee/E5UDIei2ShFhckoF0EMx+FKZgoTy1HhpoXIj2Q3vpXTLDU0CCKtDjTeZA1NDquIR CVc7wFfP2YUvEC7ZbITLGLGyDXKirt6hweAyOQD3v/NtZMXA51bTZefAnm1bz8e3B6k0 Q/WIUjG9zDHq5erqmwROeCgPm7ieLRvzhD8+brOsffDO97CnQ/b6LRoS0X4vTEE9Vl9w 5sM8T70Kn6pf1GiONStkJb/AV7mQZaEuOg5ASefzTzh1L64CiTYS2XT+mwgponToVNrl oGeg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=+3FdLiESZq6AzNyn66ruLn8nQbqtsd7tQf922lRuOe4=; fh=SAjsjMuLvgP5d12Fo4XvTJARhFKNkz1UirMlGK5+PEA=; b=VJ1A0DFwn23GuoD9LyZfgal9ueDx2rtktcmBmQ1t/H6JDqCf18jKwE1t5AGqrGE8sQ ukTHWeU2SzXoZZ+u9As3Hh44nA5EKWYQZcSsQul+HSK/o6SWG15jRPyQH4aS/h6KCu48 7dOTBMhlTwA+EJ4x+8D7HzF9IVIUamvoq5B9Fnp7TVgr5z+jM+AxlNAlDgDzjMwe8HXF 4pvKqV704Piqy8DlBuebxb7CeEgmGygq1mI7gDMJ73JJMbCUg6HsyXPfvwAcelcqzL6X j90QbvIg0enveqc86o4X58fCrWcuVId4kxed2Lcbk3brX9ujnoxAVb9Hsn5xRLYApotC GC3A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="HUiOn/P4"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-146795-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146795-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id i9-20020ad44109000000b0069b520e8703si11439839qvp.154.2024.04.16.05.35.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 05:35:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-146795-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="HUiOn/P4"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-146795-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146795-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 450961C21460 for ; Tue, 16 Apr 2024 12:35:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B57A41D530; Tue, 16 Apr 2024 12:35:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HUiOn/P4" 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 CEE4D811F1 for ; Tue, 16 Apr 2024 12:35:15 +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=1713270915; cv=none; b=ImYsVjrjMhe+KxYRCBFoaf71HxKWFaENhoA+lGsNmouIxrUl2Vrz/r6ASxyA4/A29s9H/Q/nDJGMr+wQ+w5vp/8BZ8RnYwMK4CzU2ZyIrl97SHfz19YZUhHca15iCMSIP1rOkoJUfne/GSKvtXi66DxESUY0MvcziF9jLQ1tHsE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713270915; c=relaxed/simple; bh=W4gLhMYBW/ZraqK7XK4tE2RzWIlDbdedkPsX1xzYe0E=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cFnwmhds7d9MUDajMswwbgm1FLuXKy/qiDTqYbkbbGJxm/T/T2v3FVAdIWx604mrN88DhuUItagGyLrKscp2M/atX8AA/6gjP2ksmgohcK/kZYhjBcQppxkDoJWp+pGZd9zAFrXLsR9zwno7jBA0VW41sx2Xplgn3ImjEJiyQAM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HUiOn/P4; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91289C2BD10; Tue, 16 Apr 2024 12:35:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713270915; bh=W4gLhMYBW/ZraqK7XK4tE2RzWIlDbdedkPsX1xzYe0E=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HUiOn/P45P7AqQvb9DGoA46RI6Y3Bl/s7pkU1WdZnMWPoj6yI5YTN9NOXZp7/epLP hqMAnRkkSlC5UxSJNVAmoSvMNiPnnB3Z2qUM8mZY47HQdEUNN3dmODIODlT3vEEqxd VDH223ob+kLNrtfjxCsD4BmrNld36LU7UL74VHXWwih/kkKwLRUvxtxJlk9kW1KaoT 0xF4R3Q/RJoX7dk8OSCfGH3AKQIL6F0xuh/y6nkm1f9tXpIjCyv4rqxUYzQM/u/dLn yMJ/Me88KP87/6Ka+l4PVnVZPW5uezNyzTtNuw6LHlqSHjjIDdc6pwqt/IACzX8Pr6 f8kGJoAt4o4KA== Date: Tue, 16 Apr 2024 14:35:08 +0200 From: Christian Brauner To: Baokun Li Cc: xiang@kernel.org, linux-erofs@lists.ozlabs.org, chao@kernel.org, huyue2@coolpad.com, jefflexu@linux.alibaba.com, viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org, yangerkun@huawei.com, houtao1@huawei.com Subject: Re: [PATCH] erofs: set SB_NODEV sb_flags when mounting with fsid Message-ID: <20240416-blumig-dachgeschoss-bc683f4ef1bf@brauner> References: <20240415121746.1207242-1-libaokun1@huawei.com> <20240415-betagten-querlatte-feb727ed56c1@brauner> <15ab9875-5123-7bc2-bb25-fc683129ad9e@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="egxumnqaekjz7vjs" Content-Disposition: inline In-Reply-To: --egxumnqaekjz7vjs Content-Type: text/plain; charset=utf-8 Content-Disposition: inline > > I'm not sure how to resolve it in EROFS itself, anyway... Instead of allocating the erofs_sb_info in fill_super() allocate it during erofs_get_tree() and then you can ensure that you always have the info you need available during erofs_kill_sb(). See the appended (untested) patch. --egxumnqaekjz7vjs Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename="0001-erofs-reliably-distinguish-block-based-and-fscache-m.patch" From e4f586a41748b6edc05aca36d49b7b39e55def81 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Mon, 15 Apr 2024 20:17:46 +0800 Subject: [PATCH] erofs: reliably distinguish block based and fscache mode 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 [...] ============================================ Instead of allocating the erofs_sb_info in fill_super() allocate it during erofs_get_tree() and ensure that erofs can always have the info available during erofs_kill_sb(). Signed-off-by: Baokun Li Signed-off-by: Christian Brauner --- fs/erofs/super.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/fs/erofs/super.c b/fs/erofs/super.c index c0eb139adb07..4ed80154edf8 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -581,7 +581,7 @@ static const struct export_operations erofs_export_ops = { static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) { struct inode *inode; - struct erofs_sb_info *sbi; + struct erofs_sb_info *sbi = EROFS_SB(sb); struct erofs_fs_context *ctx = fc->fs_private; int err; @@ -590,15 +590,10 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) sb->s_maxbytes = MAX_LFS_FILESIZE; sb->s_op = &erofs_sops; - sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); - if (!sbi) - return -ENOMEM; - sb->s_fs_info = sbi; sbi->opt = ctx->opt; sbi->devs = ctx->devs; ctx->devs = NULL; - sbi->fsid = ctx->fsid; ctx->fsid = NULL; sbi->domain_id = ctx->domain_id; ctx->domain_id = NULL; @@ -707,8 +702,15 @@ 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; + struct erofs_sb_info *sbi; + + sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); + if (!sbi) + return -ENOMEM; - if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && ctx->fsid) + fc->s_fs_info = sbi; + sbi->fsid = ctx->fsid; + if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && sbi->fsid) return get_tree_nodev(fc, erofs_fc_fill_super); return get_tree_bdev(fc, erofs_fc_fill_super); @@ -762,11 +764,15 @@ static void erofs_free_dev_context(struct erofs_dev_context *devs) static void erofs_fc_free(struct fs_context *fc) { struct erofs_fs_context *ctx = fc->fs_private; + struct erofs_sb_info *sbi = fc->s_fs_info; erofs_free_dev_context(ctx->devs); kfree(ctx->fsid); kfree(ctx->domain_id); kfree(ctx); + + if (sbi) + kfree(sbi); } static const struct fs_context_operations erofs_context_ops = { @@ -783,6 +789,7 @@ static int erofs_init_fs_context(struct fs_context *fc) ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); if (!ctx) return -ENOMEM; + ctx->devs = kzalloc(sizeof(struct erofs_dev_context), GFP_KERNEL); if (!ctx->devs) { kfree(ctx); @@ -799,17 +806,13 @@ static int erofs_init_fs_context(struct fs_context *fc) static void erofs_kill_sb(struct super_block *sb) { - struct erofs_sb_info *sbi; + struct erofs_sb_info *sbi = EROFS_SB(sb); - if (erofs_is_fscache_mode(sb)) + if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && sbi->fsid) kill_anon_super(sb); else kill_block_super(sb); - sbi = EROFS_SB(sb); - if (!sbi) - return; - erofs_free_dev_context(sbi->devs); fs_put_dax(sbi->dax_dev, NULL); erofs_fscache_unregister_fs(sb); -- 2.43.0 --egxumnqaekjz7vjs--