Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp602336pxj; Tue, 18 May 2021 10:03:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6NNJ6RKv+aqzEqM8Z6q8uK5xfE0imM6JxqJOEGasmw13Nd74BLEpFzTrn0djGlV6jlJ/8 X-Received: by 2002:a02:9f96:: with SMTP id a22mr6806208jam.14.1621357388212; Tue, 18 May 2021 10:03:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621357388; cv=none; d=google.com; s=arc-20160816; b=JwAg5QzWc8bfKwLLcKa2hETke+CJVwPYErr5mAhU9aOADZK4yIyzhG6d4Kndd7Nf31 daBAB9HzyWF3YpLnYPOOqHDH6dg/RXc91N5W62n8DBWWZjqrRNh1A0zL3CYkgDc8VR1x CqmyxpcAjgbqS6fNORZCmenbfRGz9x4yTZu6j+2gWuccgUeShGXk29jezCF2NgYBvifI hAMLMQp01SGLavXdAf5SYbaEYetIhc7AMf6mrUN+T28V53ammhX+WluN8etxdPMYPwfl tpT+Qy1MNmIJYWOZJnuKIaVeQMzLJeZSvsAM2mmPsOaujJl8OU5i4farl89LrbhHqhIv tQJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hbYsGYhF75Fqcgj43zsVixX7ovVJ9dr3TXIb1B+acZk=; b=zhRqe3w26/e6mmKXhO4hOy3ebNff/VWisYcNVwpAK3VfDu7e6v3idSy7BVd7Sso7BV Rl4/5bFtI6A3CLUcbmwH5HaHFk3iOjUcv+uHcIu+HlS4mWi8J0/ZnpU+AjkutuUP68Zy Ib1VTDqlDeNGF9SVeTlFIBsi7zCV7kEhmBEG3sefrNY8f5JE6bUAbShoYtSzcd8tuoXR DhVzHN09YLSo5DP2vd25bse4gAtNnnGsbX8pKby5UkLlsQqAbZzZimEZF3IEmRLu8954 tPBlXTr87cJF/oYTAkGxdArVZNX3gG2YUr0L5+3K31kUtipjsDi7cI3JzwrRh3fqMM89 WukQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oTBCFBtZ; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f14si2589365ilj.120.2021.05.18.10.02.38; Tue, 18 May 2021 10:03:08 -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=@linuxfoundation.org header.s=korg header.b=oTBCFBtZ; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343987AbhEQQIN (ORCPT + 99 others); Mon, 17 May 2021 12:08:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:36438 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344714AbhEQPpb (ORCPT ); Mon, 17 May 2021 11:45:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 98D5561D31; Mon, 17 May 2021 14:43:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262625; bh=QXHIcgxXCMsYEp8HK4WnUJS8HGDDPdqg5mi9M4eJkqg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oTBCFBtZkd/+TcELDEXbkvDWKoP4HEgoGoXyyvjzB6oqXtiCnV5tTnrG0zrAafV/W wyDtvOowr3ASn6n715p1V+IZ/9eg3JgIcj3B52CcD3Lu/6m5L5yO6CLg4ROzZ9xOOC LuLD1bq6MDYnjJyXaWyYJhuTV8LydD02muaKba4w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 5.10 236/289] f2fs: compress: fix to assign cc.cluster_idx correctly Date: Mon, 17 May 2021 16:02:41 +0200 Message-Id: <20210517140313.119972534@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chao Yu [ Upstream commit 8bfbfb0ddd706b1ce2e89259ecc45f192c0ec2bf ] 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 Signed-off-by: Sasha Levin --- fs/f2fs/compress.c | 17 +++++++++-------- fs/f2fs/data.c | 6 +++--- fs/f2fs/f2fs.h | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c index 58eb5eefe268..f94b13075ea4 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -151,13 +151,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) @@ -984,7 +985,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) @@ -1011,7 +1012,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; } } @@ -1044,7 +1045,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; } @@ -1080,7 +1081,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; } @@ -1299,7 +1300,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: @@ -1461,7 +1462,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 901bd1d963ee..bdc0f3b2d7ab 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2419,7 +2419,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; } @@ -2464,7 +2464,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 @@ -3168,7 +3168,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; diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 036d2a3a2f41..69a390c6064c 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -3856,7 +3856,7 @@ void f2fs_free_dic(struct decompress_io_ctx *dic); void f2fs_decompress_end_io(struct page **rpages, unsigned int cluster_size, bool err, bool verity); int f2fs_init_compress_ctx(struct compress_ctx *cc); -void f2fs_destroy_compress_ctx(struct compress_ctx *cc); +void f2fs_destroy_compress_ctx(struct compress_ctx *cc, bool reuse); void f2fs_init_compress_info(struct f2fs_sb_info *sbi); int f2fs_init_page_array_cache(struct f2fs_sb_info *sbi); void f2fs_destroy_page_array_cache(struct f2fs_sb_info *sbi); -- 2.30.2