Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2720174pxj; Mon, 10 May 2021 09:14:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPBdHDRdLwSiuNcuPPTFmjC73cGa43VkHMuN5YWLRbxo8hvPPVMcxn8ZAQMsAnsL5tNUoB X-Received: by 2002:a05:6402:1b0d:: with SMTP id by13mr30689339edb.328.1620663241008; Mon, 10 May 2021 09:14:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620663241; cv=none; d=google.com; s=arc-20160816; b=g8jQKRtQWrH4mWl3FE3np7PTJTaF9MyqOCrcZcuQw2MI+eEt4DopgFEhWcSSi3z/46 aoQm3yNvyNgNf7XNPSY9JBeetlW0UqjexlMK6RCKFkodtBFN8MpwZQCBlHCK+x8Ar+x1 hPo2ofhQVZBKrh7sWhqHsedWjnASOB/qa7P8MBPFjaGbyTI7AEQuHLciuLPWZZmcO6z5 fuBGhPhTMpQimQ4tM6maAhq07N2QXF8PldYu24WIKA5ircqnewQvs25IVs8D0cI8M9sE k/Og5O46PmMKGle49m5cbu8+JkpSXTjUucVFusbzwCQqQwaYPO40dv/HHAZFgl+DVBtf ajXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=uQHnJrtktALEqem+hCPibbBCdIujn04Aiu/7JrYjIqQ=; b=RoO+IBoq/jS/CCVyeMuaCB158pWNAJsB/Dl33P3NK8qVYXt1culBJTGnntl8Kr4z9H zDfX0Oj+oN6KC0IG9UDw1klP+CL/RbDNnY8Y9VPHia2JOEup1/yC9bdHbxQJjIuHZqAb 8cW3j/08KCNG3TAHiEcVXc70c5CA9DpZalx6jqxZXPT1PwZKlwAc7n+rnBmyQzgu+K96 C2u3LZ5P6wU582ZhqRU/GDKENRqpDgPbc4XuLchoP165KiGCFO8nsOFO06nADJQSzzPX Wf/OIm9HDl7JiSiLAQ/dDA1W8rOAu8VdxCH6PeJssC2t1VxMLtcV+wZPiy9YewPanS3P WxAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=u+0D1TxU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u14si13769447ejz.667.2021.05.10.09.13.36; Mon, 10 May 2021 09:14:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=u+0D1TxU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230254AbhEJQLA (ORCPT + 99 others); Mon, 10 May 2021 12:11:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:54576 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230145AbhEJQK6 (ORCPT ); Mon, 10 May 2021 12:10:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 78ED96108B; Mon, 10 May 2021 16:09:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1620662993; bh=OeMcOYr8TZ/o6MhIlP2/j3/CcS6n961yxSdIDXmvodI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=u+0D1TxUJGcewnlne7UdPyqxTkt+b4C6AX9EoG0X22OZvUHeaD3lh84zEHdt1dLkj 545rmDbAAeHQCSl8/J/HvuBD54SFgIw+3t5pW1CdbIW3PK0xC+b/peCgTgfCyyh+mo N1bXUF1c2x3FEj76lGhK87BIFOWHbWn7a+diyBtz+4J3qzBsXew+OV7gmV2BpNeH/j 4oPAQXlWgMszQJ5N2mMSGKUXwk3YX8aSNfhQ3bkVgv/x6GJVGQ6KycfStolZ3isX6O HppxZH5bznmqvzZNWhH+tmCZyPlAmV4kDxyqze2prsMT4qa90vViPYxp83dIC7lFlh Sc1weUMravF6g== Date: Mon, 10 May 2021 09:09:51 -0700 From: Jaegeuk Kim To: Chao Yu Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, chao@kernel.org Subject: Re: [PATCH 3/3] f2fs: compress: fix to assign cc.cluster_idx correctly Message-ID: References: <20210510093032.35466-1-yuchao0@huawei.com> <20210510093032.35466-3-yuchao0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210510093032.35466-3-yuchao0@huawei.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/10, Chao Yu wrote: > In f2fs_destroy_compress_ctx(), after f2fs_destroy_compress_ctx(), > cc.cluster_idx will be cleared w/ NULL_CLUSTER, f2fs_cluster_blocks() > may check wrong cluster metadata, fix it. > > Fixes: 4c8ff7095bef ("f2fs: support data compression") > Signed-off-by: Chao Yu > --- > fs/f2fs/compress.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c > index 340815cd0887..30b003447510 100644 > --- a/fs/f2fs/compress.c > +++ b/fs/f2fs/compress.c > @@ -1066,6 +1066,8 @@ static int prepare_compress_overwrite(struct compress_ctx *cc, > f2fs_put_rpages(cc); > f2fs_unlock_rpages(cc, i + 1); > f2fs_destroy_compress_ctx(cc); > + cc->cluster_idx = index >> > + F2FS_I(cc->inode)->i_log_cluster_size; I didn't test tho, how about this? From 904abb77e82ea982f68960148b75d0a12f771c2e Mon Sep 17 00:00:00 2001 From: Chao Yu Date: Mon, 10 May 2021 17:30:32 +0800 Subject: [PATCH] f2fs: compress: fix to assign cc.cluster_idx correctly In f2fs_destroy_compress_ctx(), after f2fs_destroy_compress_ctx(), cc.cluster_idx will be cleared w/ NULL_CLUSTER, f2fs_cluster_blocks() may check wrong cluster metadata, fix it. Fixes: 4c8ff7095bef ("f2fs: support data compression") Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim --- fs/f2fs/compress.c | 17 +++++++++-------- fs/f2fs/data.c | 6 +++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c index 79348bc56e35..925a5ca3744a 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -145,13 +145,14 @@ int f2fs_init_compress_ctx(struct compress_ctx *cc) return cc->rpages ? 0 : -ENOMEM; } -void f2fs_destroy_compress_ctx(struct compress_ctx *cc) +void f2fs_destroy_compress_ctx(struct compress_ctx *cc, bool reuse) { page_array_free(cc->inode, cc->rpages, cc->cluster_size); cc->rpages = NULL; cc->nr_rpages = 0; cc->nr_cpages = 0; - cc->cluster_idx = NULL_CLUSTER; + if (!reuse) + cc->cluster_idx = NULL_CLUSTER; } void f2fs_compress_ctx_add_page(struct compress_ctx *cc, struct page *page) @@ -1034,7 +1035,7 @@ static int prepare_compress_overwrite(struct compress_ctx *cc, ret = f2fs_read_multi_pages(cc, &bio, cc->cluster_size, &last_block_in_bio, false, true); f2fs_put_rpages(cc); - f2fs_destroy_compress_ctx(cc); + f2fs_destroy_compress_ctx(cc, true); if (ret) goto out; if (bio) @@ -1061,7 +1062,7 @@ static int prepare_compress_overwrite(struct compress_ctx *cc, release_and_retry: f2fs_put_rpages(cc); f2fs_unlock_rpages(cc, i + 1); - f2fs_destroy_compress_ctx(cc); + f2fs_destroy_compress_ctx(cc, true); goto retry; } } @@ -1094,7 +1095,7 @@ static int prepare_compress_overwrite(struct compress_ctx *cc, unlock_pages: f2fs_put_rpages(cc); f2fs_unlock_rpages(cc, i); - f2fs_destroy_compress_ctx(cc); + f2fs_destroy_compress_ctx(cc, true); out: return ret; } @@ -1130,7 +1131,7 @@ bool f2fs_compress_write_end(struct inode *inode, void *fsdata, set_cluster_dirty(&cc); f2fs_put_rpages_wbc(&cc, NULL, false, 1); - f2fs_destroy_compress_ctx(&cc); + f2fs_destroy_compress_ctx(&cc, false); return first_index; } @@ -1350,7 +1351,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc, f2fs_put_rpages(cc); page_array_free(cc->inode, cc->cpages, cc->nr_cpages); cc->cpages = NULL; - f2fs_destroy_compress_ctx(cc); + f2fs_destroy_compress_ctx(cc, false); return 0; out_destroy_crypt: @@ -1512,7 +1513,7 @@ int f2fs_write_multi_pages(struct compress_ctx *cc, err = f2fs_write_raw_pages(cc, submitted, wbc, io_type); f2fs_put_rpages_wbc(cc, wbc, false, 0); destroy_out: - f2fs_destroy_compress_ctx(cc); + f2fs_destroy_compress_ctx(cc, false); return err; } diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 96f1a354f89f..33e56ae84e35 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2287,7 +2287,7 @@ static int f2fs_mpage_readpages(struct inode *inode, max_nr_pages, &last_block_in_bio, rac != NULL, false); - f2fs_destroy_compress_ctx(&cc); + f2fs_destroy_compress_ctx(&cc, false); if (ret) goto set_error_page; } @@ -2332,7 +2332,7 @@ static int f2fs_mpage_readpages(struct inode *inode, max_nr_pages, &last_block_in_bio, rac != NULL, false); - f2fs_destroy_compress_ctx(&cc); + f2fs_destroy_compress_ctx(&cc, false); } } #endif @@ -3033,7 +3033,7 @@ static int f2fs_write_cache_pages(struct address_space *mapping, } } if (f2fs_compressed_file(inode)) - f2fs_destroy_compress_ctx(&cc); + f2fs_destroy_compress_ctx(&cc, false); #endif if (retry) { index = 0; -- 2.31.1.607.g51e8a6a459-goog > goto retry; > } > } > -- > 2.29.2