Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp360124lqb; Tue, 16 Apr 2024 20:00:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVHsqiAsDWqgtCVNWIc5J72lXe5hhqk7J9CUfH9RfkECfBeGKUh6HlZ8/56k5vP308R51F/i7bXYfBZYLlnwLrKWdFUsJWH0k7rddp57w== X-Google-Smtp-Source: AGHT+IEktAzAx5jU5fwXYhWrPrJdgdX1Yx3siV9nc0OOnaUFCS1eOKTrPe4GEBvgAy00cfG2F7qP X-Received: by 2002:a50:ab42:0:b0:570:5b3d:4f60 with SMTP id t2-20020a50ab42000000b005705b3d4f60mr520340edc.25.1713322808269; Tue, 16 Apr 2024 20:00:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713322808; cv=pass; d=google.com; s=arc-20160816; b=eYlroqxgB3aGHJGzpr0BedrTWdrTSsakQbqmFFArJXLizLwA9vSfC39BYIxNYDpHTu 7ksEPd93zH/NFy+M/nzvv8/Iv5VxM0LEWWVraAIF16rX1Tt5S+PM3hVyqXpYmMV4aDiY Ve+cUhKkq8xw5EQZiz7zRSLEVvfZcdoZ4UpALEXe2AHYgTVP3UsdzW8WjBlU8Tj7reNo FYHmskKVR6O9UKjFi1JYmKnGYEWUisnV69l4FMFOSdpCB43XymGRbgraCGpdpnPGhh7l H7f67pxcVanN1y7W1TeBwOvycolr+JEVkn+Hx+W3N3EffXesmbS9+VmgXTF8jJsZGc4z nsKg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:cc:content-language :references:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=IKFR71LzdrWQMT5y8MP7VYNzYGoSwtAnaQ/d3XHNVZo=; fh=R36cQ43PvBk/7Dlpjlldkysz4tGjkVOcmINAXrsyrt8=; b=MOA84DKuZT3K0ei6n8GB5mq1db1v+OEPoPvQl7QsxO2Z8Ew2cZPorTkMBOAoYbVPhZ 50AsJ7okUJ5tX7iEeeUIkgFTiSBWJr4u/xWMnxFKqRRLd/Gj9Hhr2em5NHQYtqejakDh meIljZ5hGEwsB08PLSXOhcIcFHNJl9v9IWTNshqEigNFuUbO8dc0IlZjdAWqNv5m3PfN djgfG3ugl8FLH63J7v6YFb55hQrsapnbHcvv3ctclCCbsKySqwUrcLlEVRhbYoHwOjPq 6ufF7YBpPgrhTEjo/jWONBzz9auZEjVRHI5am3p8BWnfpdNptc3BNvauRrqX4MNrAKqD ee+Q==; 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-147872-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147872-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id c14-20020a05640227ce00b0056e22b3a04fsi6315971ede.329.2024.04.16.20.00.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 20:00:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-147872-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; 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-147872-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147872-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 am.mirrors.kernel.org (Postfix) with ESMTPS id D29211F21FB4 for ; Wed, 17 Apr 2024 03:00:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 91886BE4E; Wed, 17 Apr 2024 03:00:00 +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 DFFACB65D for ; Wed, 17 Apr 2024 02:59:56 +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=1713322800; cv=none; b=iTTbY/jS/5dG2Gg6OoK2RmhH8UW4dm167K0zwvuDVQVKeKlpqZNfzVsPT7f+sp/q4CulPME3lah1DyWigmVFqTGsB/ndp187MGwhC7dR7JjCPuWnC0pnicgDmVqPeYBONxKREhSEs6wJQS13o0O+z5gCQyi89+QS6UECkCXp35k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713322800; c=relaxed/simple; bh=8V8+PUTimmKNjO86uSZW0P7YBukBxEl8aYf5MLNjTvA=; h=Message-ID:Date:MIME-Version:Subject:To:References:CC:From: In-Reply-To:Content-Type; b=uv8xXvAzBSgBS8rRkNT6hdoFSMcDJgADef6H5OWau680dhoGF6n+p0Xs9wZvC0S/xUy4PdOPjFzm7W8jc69KqbzTwGR30wtYfR9vak8YrLoNDb0S0RwOaXMDlXy68gxRfIx1IilvO1zJr9Y2Puc5hv/srWREby/VuXeGmvYK/yc= 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.162.254]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4VK5Cl3GM4zwSJw; Wed, 17 Apr 2024 10:56:51 +0800 (CST) Received: from dggpeml500021.china.huawei.com (unknown [7.185.36.21]) by mail.maildlp.com (Postfix) with ESMTPS id 38D021800C3; Wed, 17 Apr 2024 10:59:54 +0800 (CST) Received: from [10.174.177.174] (10.174.177.174) 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; Wed, 17 Apr 2024 10:59:53 +0800 Message-ID: <779ff32f-3f3b-c602-5da8-c88b361716ac@huawei.com> Date: Wed, 17 Apr 2024 10:59:53 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.1.2 Subject: Re: [PATCH] erofs: set SB_NODEV sb_flags when mounting with fsid To: Christian Brauner , References: <20240415121746.1207242-1-libaokun1@huawei.com> <20240415-betagten-querlatte-feb727ed56c1@brauner> <15ab9875-5123-7bc2-bb25-fc683129ad9e@huawei.com> <20240416-blumig-dachgeschoss-bc683f4ef1bf@brauner> Content-Language: en-US CC: , , , , , , , , Baokun Li From: Baokun Li In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml500021.china.huawei.com (7.185.36.21) On 2024/4/16 22:49, Gao Xiang wrote: > On Tue, Apr 16, 2024 at 02:35:08PM +0200, Christian Brauner wrote: >>>> 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. > Hi Christian, > > Yeah, that is a good way I think. Although sbi will be allocated > unconditionally instead but that is minor. > > I'm on OSSNA this week, will test this patch more when returning. > > Hi Baokun, > > Could you also check this on your side? > > Thanks, > Gao Xiang Hi Xiang, This patch does fix the initial problem. Hi Christian, Thanks for the patch, this is a good idea. Just with nits below. Otherwise feel free to add. Reviewed-and-tested-by: Baokun Li > >> 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 >> SNIP >> >> 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; This line is no longer needed. >> 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; Since erofs_sb_info is now allocated in erofs_fc_get_tree(), why not encapsulate the above lines as erofs_ctx_to_info() helper function to be called in erofs_fc_get_tree()?Then erofs_fc_fill_super() wouldn't have to use erofs_fs_context and would prevent the fsid from being freed twice. >> @@ -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; Here ctx->fsid is not set to null, so fsid may be freed twice. >> + 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); There's no need to check sbi, kfree does. >> } >> >> 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 >>