Message ID | 20230210213250.3471246-1-jaegeuk@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1187247wrn; Fri, 10 Feb 2023 13:34:01 -0800 (PST) X-Google-Smtp-Source: AK7set/d1MEtHk7v3MNnAtoagi5GnZjY2vUJYyKgHE8CkOAU6TynVkRGVF6I+qmw0hzCYhiFIyk4 X-Received: by 2002:a17:902:dcc5:b0:199:4d:40d1 with SMTP id t5-20020a170902dcc500b00199004d40d1mr11816840pll.46.1676064841653; Fri, 10 Feb 2023 13:34:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676064841; cv=none; d=google.com; s=arc-20160816; b=QfR5PRCW5BaE8ZwZbyC+UOWv2MdcTMJFAxMFEDVlLDvcIESdE3ph+LMiDpsell8fqc /VcXreGW9w6kEbn8idzpTPpEvBkq7+VQyDsdn8EZxtSF59tebsTF1Lbl2bn/+v0DD52F Ku1Q35Ncq6QA1dSrUVPq2DE6szP+5RKaIF5/avvSsXzqJUy37/2sNsCusT1A8BlnkUDd OiGnB+t58lWR38SEridpOnWBxr37RVMC0BT/kfeu/2dfXkzZrm0Zuq7dFysP73gQpFWV 6OlTgiMuV4/bH+QTHfxQbp9nismAhXtr8SQzEQaK5bVoYJ4tCSscTSr79AqwcAK0GQ6q JvHQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=EL6W5emnmivlXeG1YEhXRBAOcS1npi8mWtqG8Erd8mE=; b=aaxdxHzfWO7FThuFYOGnGDrAV0qYXrKtdFVGIT/Qx8MauCx9SHrZWopkJjz25zQtXS 6Tu83vH3oGb1WUCQeBkcnozQEs6TNme/lLdbTBBiKJ+ri4z3M1YU6stJ1JolT6y4cRj0 mBkXXCDP0KbTwT8T2+5s/FWMBmx4d18XNhmyYECC8QD9GFyfD4TNmKWcZZrTy2jTZAZg 6ZDo2SsVF3ilr+ZU97Hhtw5ts2UongBE74qJ1B4DUqs6+Cdrp0WcybzhTjXk7Xd46Cp4 FnokV7A2vl5FJGysJTD7tIqDe+Or5G6MxRsqaP/D3RXVEJCXuu1/BqNBfEnOhdp/KoBk AHEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UlHZ7Wr9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e3-20020a17090301c300b001967653c1cdsi5993646plh.595.2023.02.10.13.33.48; Fri, 10 Feb 2023 13:34:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UlHZ7Wr9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S233524AbjBJVc6 (ORCPT <rfc822;ybw1215001957@gmail.com> + 99 others); Fri, 10 Feb 2023 16:32:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233131AbjBJVc4 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 10 Feb 2023 16:32:56 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 814E181CD9 for <linux-kernel@vger.kernel.org>; Fri, 10 Feb 2023 13:32:55 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1069B61EAF for <linux-kernel@vger.kernel.org>; Fri, 10 Feb 2023 21:32:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54472C433D2; Fri, 10 Feb 2023 21:32:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676064774; bh=J3Gyaseg7yhQVMzzAFVCsvKsCGLb9pPjdnQxlIuqQSM=; h=From:To:Cc:Subject:Date:From; b=UlHZ7Wr9nKKcfNOZ+RrvVsHagvQ1NcpyDMwY0EEiuLVJIv/32rh11KQzSYSt6eNBm 0WoXa3ggxLx7SE11k1rpBpLPbjN+cjSA/qHiDN44gOtzMQCpQ12FsU2ynCUxsDrX32 EzGfEGwGjsnkGsc7sIDzTLJ/Eek7fkEsLH24TdmAEZPbKe87+wWEu5j+JfQwUqxgbR Z9024rKOqhd7Pbqvd48GC2SHHXefCfURVsiyVTKIi32EsT5+VKhtcAIJSGohaDU2pL LBFEYUvjpEZ4JWYKCNTdACxDwasYtaeI6/G7j1B0DU7NUGl2y7wgTMpPFbyJ87mydl IcWBcCuWaD4PQ== From: Jaegeuk Kim <jaegeuk@kernel.org> To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim <jaegeuk@kernel.org> Subject: [PATCH] f2fs: fix wrong segment count Date: Fri, 10 Feb 2023 13:32:50 -0800 Message-Id: <20230210213250.3471246-1-jaegeuk@kernel.org> X-Mailer: git-send-email 2.39.1.581.gbfd45094c4-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757481366976632888?= X-GMAIL-MSGID: =?utf-8?q?1757481366976632888?= |
Series |
f2fs: fix wrong segment count
|
|
Commit Message
Jaegeuk Kim
Feb. 10, 2023, 9:32 p.m. UTC
MAIN_SEGS is for data area, while TOTAL_SEGS includes data and metadata.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
fs/f2fs/segment.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Comments
On 2023/2/11 5:32, Jaegeuk Kim wrote: > MAIN_SEGS is for data area, while TOTAL_SEGS includes data and metadata. Good catch! Could you please add fixes line? Thanks, > > Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> > --- > fs/f2fs/segment.h | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h > index 8ee5e5db9287..6003fbaf4b7d 100644 > --- a/fs/f2fs/segment.h > +++ b/fs/f2fs/segment.h > @@ -720,7 +720,7 @@ static inline unsigned char curseg_alloc_type(struct f2fs_sb_info *sbi, > > static inline void check_seg_range(struct f2fs_sb_info *sbi, unsigned int segno) > { > - f2fs_bug_on(sbi, segno > TOTAL_SEGS(sbi) - 1); > + f2fs_bug_on(sbi, segno > MAIN_SEGS(sbi) - 1); > } > > static inline void verify_fio_blkaddr(struct f2fs_io_info *fio) > @@ -775,7 +775,7 @@ static inline int check_block_count(struct f2fs_sb_info *sbi, > > /* check segment usage, and check boundary of a given segment number */ > if (unlikely(GET_SIT_VBLOCKS(raw_sit) > usable_blks_per_seg > - || segno > TOTAL_SEGS(sbi) - 1)) { > + || segno > MAIN_SEGS(sbi) - 1)) { > f2fs_err(sbi, "Wrong valid blocks %d or segno %u", > GET_SIT_VBLOCKS(raw_sit), segno); > set_sbi_flag(sbi, SBI_NEED_FSCK);
On 02/13, Chao Yu wrote: > On 2023/2/11 5:32, Jaegeuk Kim wrote: > > MAIN_SEGS is for data area, while TOTAL_SEGS includes data and metadata. > > Good catch! > > Could you please add fixes line? It seems this is not a bug case, and exisits from the first F2FS patch. :) > > Thanks, > > > > > Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> > > --- > > fs/f2fs/segment.h | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h > > index 8ee5e5db9287..6003fbaf4b7d 100644 > > --- a/fs/f2fs/segment.h > > +++ b/fs/f2fs/segment.h > > @@ -720,7 +720,7 @@ static inline unsigned char curseg_alloc_type(struct f2fs_sb_info *sbi, > > static inline void check_seg_range(struct f2fs_sb_info *sbi, unsigned int segno) > > { > > - f2fs_bug_on(sbi, segno > TOTAL_SEGS(sbi) - 1); > > + f2fs_bug_on(sbi, segno > MAIN_SEGS(sbi) - 1); > > } > > static inline void verify_fio_blkaddr(struct f2fs_io_info *fio) > > @@ -775,7 +775,7 @@ static inline int check_block_count(struct f2fs_sb_info *sbi, > > /* check segment usage, and check boundary of a given segment number */ > > if (unlikely(GET_SIT_VBLOCKS(raw_sit) > usable_blks_per_seg > > - || segno > TOTAL_SEGS(sbi) - 1)) { > > + || segno > MAIN_SEGS(sbi) - 1)) { > > f2fs_err(sbi, "Wrong valid blocks %d or segno %u", > > GET_SIT_VBLOCKS(raw_sit), segno); > > set_sbi_flag(sbi, SBI_NEED_FSCK);
MAIN_SEGS is for data area, while TOTAL_SEGS includes data and metadata.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
Change log from v1:
- replace check_seg_range with valid_main_segno to avoid confusion.
fs/f2fs/segment.h | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
index 92c8be00d396..efdb7fc3b797 100644
--- a/fs/f2fs/segment.h
+++ b/fs/f2fs/segment.h
@@ -719,9 +719,10 @@ static inline unsigned char curseg_alloc_type(struct f2fs_sb_info *sbi,
return curseg->alloc_type;
}
-static inline void check_seg_range(struct f2fs_sb_info *sbi, unsigned int segno)
+static inline bool valid_main_segno(struct f2fs_sb_info *sbi,
+ unsigned int segno)
{
- f2fs_bug_on(sbi, segno > TOTAL_SEGS(sbi) - 1);
+ return segno <= (MAIN_SEGS(sbi) - 1);
}
static inline void verify_fio_blkaddr(struct f2fs_io_info *fio)
@@ -776,7 +777,7 @@ static inline int check_block_count(struct f2fs_sb_info *sbi,
/* check segment usage, and check boundary of a given segment number */
if (unlikely(GET_SIT_VBLOCKS(raw_sit) > usable_blks_per_seg
- || segno > TOTAL_SEGS(sbi) - 1)) {
+ || !valid_main_segno(sbi, segno))) {
f2fs_err(sbi, "Wrong valid blocks %d or segno %u",
GET_SIT_VBLOCKS(raw_sit), segno);
set_sbi_flag(sbi, SBI_NEED_FSCK);
@@ -793,7 +794,7 @@ static inline pgoff_t current_sit_addr(struct f2fs_sb_info *sbi,
unsigned int offset = SIT_BLOCK_OFFSET(start);
block_t blk_addr = sit_i->sit_base_addr + offset;
- check_seg_range(sbi, start);
+ f2fs_bug_on(sbi, !valid_main_segno(sbi, start));
#ifdef CONFIG_F2FS_CHECK_FS
if (f2fs_test_bit(offset, sit_i->sit_bitmap) !=
On 2023/2/14 1:48, Jaegeuk Kim wrote: > On 02/13, Chao Yu wrote: >> On 2023/2/11 5:32, Jaegeuk Kim wrote: >>> MAIN_SEGS is for data area, while TOTAL_SEGS includes data and metadata. >> >> Good catch! >> >> Could you please add fixes line? > > It seems this is not a bug case, and exisits from the first F2FS patch. :) Alright, anyway, it looks good to me. Reviewed-by: Chao Yu <chao@kernel.org> Thanks, > >> >> Thanks, >> >>> >>> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> >>> --- >>> fs/f2fs/segment.h | 4 ++-- >>> 1 file changed, 2 insertions(+), 2 deletions(-) >>> >>> diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h >>> index 8ee5e5db9287..6003fbaf4b7d 100644 >>> --- a/fs/f2fs/segment.h >>> +++ b/fs/f2fs/segment.h >>> @@ -720,7 +720,7 @@ static inline unsigned char curseg_alloc_type(struct f2fs_sb_info *sbi, >>> static inline void check_seg_range(struct f2fs_sb_info *sbi, unsigned int segno) >>> { >>> - f2fs_bug_on(sbi, segno > TOTAL_SEGS(sbi) - 1); >>> + f2fs_bug_on(sbi, segno > MAIN_SEGS(sbi) - 1); >>> } >>> static inline void verify_fio_blkaddr(struct f2fs_io_info *fio) >>> @@ -775,7 +775,7 @@ static inline int check_block_count(struct f2fs_sb_info *sbi, >>> /* check segment usage, and check boundary of a given segment number */ >>> if (unlikely(GET_SIT_VBLOCKS(raw_sit) > usable_blks_per_seg >>> - || segno > TOTAL_SEGS(sbi) - 1)) { >>> + || segno > MAIN_SEGS(sbi) - 1)) { >>> f2fs_err(sbi, "Wrong valid blocks %d or segno %u", >>> GET_SIT_VBLOCKS(raw_sit), segno); >>> set_sbi_flag(sbi, SBI_NEED_FSCK);
On 02/14, Chao Yu wrote: > On 2023/2/14 1:48, Jaegeuk Kim wrote: > > On 02/13, Chao Yu wrote: > > > On 2023/2/11 5:32, Jaegeuk Kim wrote: > > > > MAIN_SEGS is for data area, while TOTAL_SEGS includes data and metadata. > > > > > > Good catch! > > > > > > Could you please add fixes line? > > > > It seems this is not a bug case, and exisits from the first F2FS patch. :) > > Alright, anyway, it looks good to me. > > Reviewed-by: Chao Yu <chao@kernel.org> I assumed this for v2. Let me know if you have other concern. > > Thanks, > > > > > > > > > Thanks, > > > > > > > > > > > Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> > > > > --- > > > > fs/f2fs/segment.h | 4 ++-- > > > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > > > > > diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h > > > > index 8ee5e5db9287..6003fbaf4b7d 100644 > > > > --- a/fs/f2fs/segment.h > > > > +++ b/fs/f2fs/segment.h > > > > @@ -720,7 +720,7 @@ static inline unsigned char curseg_alloc_type(struct f2fs_sb_info *sbi, > > > > static inline void check_seg_range(struct f2fs_sb_info *sbi, unsigned int segno) > > > > { > > > > - f2fs_bug_on(sbi, segno > TOTAL_SEGS(sbi) - 1); > > > > + f2fs_bug_on(sbi, segno > MAIN_SEGS(sbi) - 1); > > > > } > > > > static inline void verify_fio_blkaddr(struct f2fs_io_info *fio) > > > > @@ -775,7 +775,7 @@ static inline int check_block_count(struct f2fs_sb_info *sbi, > > > > /* check segment usage, and check boundary of a given segment number */ > > > > if (unlikely(GET_SIT_VBLOCKS(raw_sit) > usable_blks_per_seg > > > > - || segno > TOTAL_SEGS(sbi) - 1)) { > > > > + || segno > MAIN_SEGS(sbi) - 1)) { > > > > f2fs_err(sbi, "Wrong valid blocks %d or segno %u", > > > > GET_SIT_VBLOCKS(raw_sit), segno); > > > > set_sbi_flag(sbi, SBI_NEED_FSCK);
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h index 8ee5e5db9287..6003fbaf4b7d 100644 --- a/fs/f2fs/segment.h +++ b/fs/f2fs/segment.h @@ -720,7 +720,7 @@ static inline unsigned char curseg_alloc_type(struct f2fs_sb_info *sbi, static inline void check_seg_range(struct f2fs_sb_info *sbi, unsigned int segno) { - f2fs_bug_on(sbi, segno > TOTAL_SEGS(sbi) - 1); + f2fs_bug_on(sbi, segno > MAIN_SEGS(sbi) - 1); } static inline void verify_fio_blkaddr(struct f2fs_io_info *fio) @@ -775,7 +775,7 @@ static inline int check_block_count(struct f2fs_sb_info *sbi, /* check segment usage, and check boundary of a given segment number */ if (unlikely(GET_SIT_VBLOCKS(raw_sit) > usable_blks_per_seg - || segno > TOTAL_SEGS(sbi) - 1)) { + || segno > MAIN_SEGS(sbi) - 1)) { f2fs_err(sbi, "Wrong valid blocks %d or segno %u", GET_SIT_VBLOCKS(raw_sit), segno); set_sbi_flag(sbi, SBI_NEED_FSCK);