Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4666314iob; Sun, 8 May 2022 21:12:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHGsB8sWHM6eO3ilfLs3U/WZRsllHikR68z+ixJSwh5ZxtvbDVopLdkpAvLtK0OyTWvXE2 X-Received: by 2002:a17:90b:1bc3:b0:1dc:61fd:7ea4 with SMTP id oa3-20020a17090b1bc300b001dc61fd7ea4mr24030784pjb.31.1652069562006; Sun, 08 May 2022 21:12:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652069562; cv=none; d=google.com; s=arc-20160816; b=lTtytW06Asw0etdfbtt6wdnurvXSBTqsQGg/tceHubiTUWGx5bkWTk29JJs25vaXMi uSTZgmzb6RFxGVmmRzkU5fW2JwhFtsEToW25s3uUcuTYVmB3HS/WDoysIuu87yOhdgwm LSg0p/8nDcmMVR+5oiVRM/2OmuNFbnnq3QXXOg5AwECD0GNjyFKD1oAeIFatioonVzQW ZxQCE3Xi7QjV45O2zX7OZxwLhEKJWFWINRtu0SMIozmtgzKzGUHv8sN8OGFlRWcOUuA2 TNbsvXwNjUqwdAeEK5ZSTBONjs/KZBz+Jaz2D8GjxGNrysPnt5hGQ+zUA7mJmyI26R2d byGQ== 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=W4qy/vudMhSGD8brwSb4qSWoFA29i2qlwowm5rnKYuw=; b=HO6KIIVEeEvykvcVf0Y4h0wmEhDgjLgrEaVzoIj8gXM7naKKYy3Dzraca8vhlArIG5 EoY9gkvJI/1ypWIqSig5AanbZZAO9LsPUbM1DDqggaHlQQw3lqSXuyBGwl/J2xaHm0D9 nzkL+FmsrR1HlC7zf3/6PjUYcSl1b7IjFIEHtAbKigNtB7VSFrcths7mR9dMtLwiYU0R w+AhD74N9BRsu19uuwiEBd+v5eXl8yZFVr+JuJjx9N3amw+Ja4B7IoVI0D5yViJ0HV+T 9YbJh5u+wKrPl9CUHuZd2qEMX36Oq5ppYVPt2hWYZhtk6NoBksQeHHIn2F1jYhBe8btw RE3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dovigtcA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c4-20020a056a000ac400b0050dd2797010si13628341pfl.321.2022.05.08.21.12.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 21:12:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dovigtcA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0D41810B3E2; Sun, 8 May 2022 21:10:31 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1387713AbiEFA45 (ORCPT + 99 others); Thu, 5 May 2022 20:56:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1387704AbiEFA44 (ORCPT ); Thu, 5 May 2022 20:56:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4464B5AA55; Thu, 5 May 2022 17:53:15 -0700 (PDT) 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 DDC6C61FE3; Fri, 6 May 2022 00:53:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D4D2C385A4; Fri, 6 May 2022 00:53:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651798394; bh=CNebCznOeFAnc8qF6ffneuM6vdU/dd66WedXNIT0M8w=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=dovigtcA3VXNPZG51qgWyU8q0YoWECeHnTSiLjpmlFf0s6FHu8gmNtyzrjM3QjwdE ZTEkQutbBE7obZqc+pVF9qImpxq6To8kdZ0zyDJSK2zvXzH5tdN2baXbYz9dOseVSy 2JmaTI+vriQVf/XM0MQt+z8+kK39heOSmrfX4csfZfvVenpQ5E5fl6rmMdWgMdn/vz Qg0OpLoFDUWCbeuoSXX7EKBjRr3F3xXuMMo/RnxlqR2tEv6W8Mxx8afKsDVwx9Kjs9 CL8W2vdRZ72MswASqWHK89vVKYTYPWZzIQcF1f59iJlwwFPJydG8Aa6YLAWABubtbg m90KJo5ySD3dA== Date: Thu, 5 May 2022 17:53:12 -0700 From: Jaegeuk Kim To: Chao Yu Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Ming Yan , Chao Yu Subject: Re: [PATCH v2] f2fs: fix to do sanity check on total_data_blocks Message-ID: References: <20220505141507.6616-1-chao@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220505141507.6616-1-chao@kernel.org> X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: X-Mailing-List: linux-kernel@vger.kernel.org On 05/05, Chao Yu wrote: > As Yanming reported in bugzilla: > > https://bugzilla.kernel.org/show_bug.cgi?id=215916 > > The kernel message is shown below: > > kernel BUG at fs/f2fs/segment.c:2560! > Call Trace: > allocate_segment_by_default+0x228/0x440 > f2fs_allocate_data_block+0x13d1/0x31f0 > do_write_page+0x18d/0x710 > f2fs_outplace_write_data+0x151/0x250 > f2fs_do_write_data_page+0xef9/0x1980 > move_data_page+0x6af/0xbc0 > do_garbage_collect+0x312f/0x46f0 > f2fs_gc+0x6b0/0x3bc0 > f2fs_balance_fs+0x921/0x2260 > f2fs_write_single_data_page+0x16be/0x2370 > f2fs_write_cache_pages+0x428/0xd00 > f2fs_write_data_pages+0x96e/0xd50 > do_writepages+0x168/0x550 > __writeback_single_inode+0x9f/0x870 > writeback_sb_inodes+0x47d/0xb20 > __writeback_inodes_wb+0xb2/0x200 > wb_writeback+0x4bd/0x660 > wb_workfn+0x5f3/0xab0 > process_one_work+0x79f/0x13e0 > worker_thread+0x89/0xf60 > kthread+0x26a/0x300 > ret_from_fork+0x22/0x30 > RIP: 0010:new_curseg+0xe8d/0x15f0 > > The root cause is: ckpt.valid_block_count is inconsistent with SIT table, > stat info indicates filesystem has free blocks, but SIT table indicates > filesystem has no free segment. > > So that during garbage colloection, it triggers panic when LFS allocator > fails to find free segment. > > This patch tries to fix this issue by checking consistency in between > ckpt.valid_block_count and block accounted from SIT. > > Cc: stable@vger.kernel.org > Reported-by: Ming Yan > Signed-off-by: Chao Yu > --- > v2: > - adjust check condition according to the case Jaegeuk mentioned. > fs/f2fs/segment.c | 24 +++++++++++++++++++++--- > 1 file changed, 21 insertions(+), 3 deletions(-) > > diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c > index 3a3e2cec2ac4..942d6d8c18e6 100644 > --- a/fs/f2fs/segment.c > +++ b/fs/f2fs/segment.c > @@ -4462,6 +4462,7 @@ static int build_sit_entries(struct f2fs_sb_info *sbi) > unsigned int readed, start_blk = 0; > int err = 0; > block_t total_node_blocks = 0; > + block_t total_data_blocks = 0; How about something like "sit_valid_blocks[DATA | NODE]"? > > do { > readed = f2fs_ra_meta_pages(sbi, start_blk, BIO_MAX_VECS, > @@ -4488,6 +4489,8 @@ static int build_sit_entries(struct f2fs_sb_info *sbi) > seg_info_from_raw_sit(se, &sit); > if (IS_NODESEG(se->type)) > total_node_blocks += se->valid_blocks; > + else > + total_data_blocks += se->valid_blocks; > > if (f2fs_block_unit_discard(sbi)) { > /* build discard map only one time */ > @@ -4529,6 +4532,8 @@ static int build_sit_entries(struct f2fs_sb_info *sbi) > old_valid_blocks = se->valid_blocks; > if (IS_NODESEG(se->type)) > total_node_blocks -= old_valid_blocks; > + else > + total_data_blocks -= old_valid_blocks; > > err = check_block_count(sbi, start, &sit); > if (err) > @@ -4536,6 +4541,8 @@ static int build_sit_entries(struct f2fs_sb_info *sbi) > seg_info_from_raw_sit(se, &sit); > if (IS_NODESEG(se->type)) > total_node_blocks += se->valid_blocks; > + else > + total_data_blocks += se->valid_blocks; > > if (f2fs_block_unit_discard(sbi)) { > if (is_set_ckpt_flags(sbi, CP_TRIMMED_FLAG)) { > @@ -4557,13 +4564,24 @@ static int build_sit_entries(struct f2fs_sb_info *sbi) > } > up_read(&curseg->journal_rwsem); > > - if (!err && total_node_blocks != valid_node_count(sbi)) { > + if (err) > + return err; > + > + if (total_node_blocks != valid_node_count(sbi)) { > f2fs_err(sbi, "SIT is corrupted node# %u vs %u", > total_node_blocks, valid_node_count(sbi)); > - err = -EFSCORRUPTED; > + return -EFSCORRUPTED; > } > > - return err; > + if (total_data_blocks + total_node_blocks > > + valid_user_blocks(sbi)) { > + f2fs_err(sbi, "SIT is corrupted data# %u %u vs %u", > + total_data_blocks, total_node_blocks, > + valid_user_blocks(sbi)); > + return -EFSCORRUPTED; > + } > + > + return 0; > } > > static void init_free_segmap(struct f2fs_sb_info *sbi) > -- > 2.32.0