Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1547676rdb; Mon, 19 Feb 2024 22:12:43 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWMv3Y/w1q2J7iY3a1ofgQaPcozgjiroUbscYwvnzbdJ5x2/X2NfUqY0MUgM7mdbyYCOE2dnhqIXQj6L1tL1lhyMwgD17YlC64GGbacfQ== X-Google-Smtp-Source: AGHT+IHF2+dwW74fCLIB+VsLTzZR9sUlk7bV4ImtqPTugNqENeocVkOHBaG2U2smW25IjDdB5f4A X-Received: by 2002:a05:622a:1342:b0:42d:c8ed:6782 with SMTP id w2-20020a05622a134200b0042dc8ed6782mr19175558qtk.40.1708409563511; Mon, 19 Feb 2024 22:12:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708409563; cv=pass; d=google.com; s=arc-20160816; b=WiXGMUiWwQSRV997tdJTn4GyylLcSmZ3ID7aKpsJMYHwaWt9ba0DTwjdoPRGIo5+XP /z/Y5S/zyQa+tMbPkAz2vJeajypJ5DuKDSAqK+365Vfm1WtpQnZOND6znLlDtwoMIdy0 AB9R/0jDvYK8mbbik32GmwMWNFFDYJsx3u16W90a63iHgwp1NWxjrBxveEDM/LuYd1pS F5isotwBIJdPn2Z5s/tlLuMg8hsApYUDa6a/pmMIivtb/vxCApJKi6PAcXKmLuMpkCDE TnVpovbf0HVY660cnfNI0J/cYXQLZqM7FjKE7BEOezPwl6pi1YsJVXjoRyTKJDgD2W+a +8hg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:subject:cc:to:from; bh=jJmU/JGYrJipuId2IQUMvtvuw0QCHKdxGPz7eiQJ7/k=; fh=r88ULmOhzmh3DE8RgcUXK+PF5Q+3czCYkx5yGhGfkR0=; b=Z5/Y4myeaH3vDSk+Hj9Xp37XWBranYjMTZR/er3DTNK+FgDFu6bzCjo7sekfaUDShx 7Xs9Qc9LkPJbYD1vzueuC4NoLXhoImCT1/gVZv7SH+877NauzGuhrzysIPdsps+Xe6v5 /ISOMUUbFeC8rrPAWEp+kCfxjnKHbQnio87St+YIKxXJA5GTDK2vtAp9mOZzKyusgK93 pYYscy8fCeWy+7TIAa+dIAIBBuvUa+Dxhx/meTuIBtWsfkwl3OyK3tuShCzOmM/Z7CIo NIPcrqoxpNBf2cg24F5kwUFvZyoByZ1t27QSxsoTYkCkW9zQ2kEyr47B4BH9qhKwdbLh gxwQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-72390-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72390-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id y18-20020ac87092000000b0042aa5c657e7si7565492qto.449.2024.02.19.22.12.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 22:12:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72390-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-72390-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72390-linux.lists.archive=gmail.com@vger.kernel.org" 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 402F41C21D5D for ; Tue, 20 Feb 2024 06:12:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5D22C58104; Tue, 20 Feb 2024 06:12:35 +0000 (UTC) Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) (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 8319758205 for ; Tue, 20 Feb 2024 06:12:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708409554; cv=none; b=DcO+Omd4z/6BOgDO8pgqaaZnHnPflNnn0hfH6FW7hQc6s/qbb9ZNy2r1xy0QtL6Buf8zKyfB511Q2Nv3eUleslSToZBifK7UNzxmC0Idek4hRIiCQJdns19WzaLxVxJRvtrNwlBO4KcbaXAYRZpAPWJUdn9l9S0eWemhNA+OFMU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708409554; c=relaxed/simple; bh=fnveXVA8uwvpzeoXM7iu36eGk0swh3LJ1WxEDd6T8p8=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=V+9rs8r77LatrYGTLwC0eiAXBL/XgIOrCAHGRZ6gnTDdXCndQYR9U+Hig956A02kR2V4SV1seR2N4/GYIVuytEGpuny34/ASzyriqurdumdgtK/G2Xx1D/sbOjPz2N5eB2GAOfWERputDwj7CTCNCuEihUsO3SQaoKkgAY6h5To= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; arc=none smtp.client-ip=222.66.158.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 41K6BVwF081774; Tue, 20 Feb 2024 14:11:31 +0800 (+08) (envelope-from Zhiguo.Niu@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx02.spreadtrum.com [10.0.64.8]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4Tf8D24k1Qz2K4gjL; Tue, 20 Feb 2024 14:10:58 +0800 (CST) Received: from bj08434pcu.spreadtrum.com (10.0.73.87) by BJMBX02.spreadtrum.com (10.0.64.8) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Tue, 20 Feb 2024 14:11:29 +0800 From: Zhiguo Niu To: , CC: , , , , , Subject: [PATCH v4 4/4] f2fs: stop checkpoint when get a out-of-bounds segment Date: Tue, 20 Feb 2024 14:11:24 +0800 Message-ID: <1708409484-27326-1-git-send-email-zhiguo.niu@unisoc.com> X-Mailer: git-send-email 1.9.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL:SHSQR01.spreadtrum.com 41K6BVwF081774 There is low probability that an out-of-bounds segment will be got on a small-capacity device. In order to prevent subsequent write requests allocating block address from this invalid segment, which may cause unexpected issue, stop checkpoint should be performed. Also introduce a new stop cp reason: STOP_CP_REASON_NO_SEGMENT. Signed-off-by: Zhiguo Niu --- changes of v4: use more suitable MACRO name according to Chao's suggestions changes of v3: correct MACRO spelling and update based on the lastes code --- --- fs/f2fs/segment.c | 7 ++++++- include/linux/f2fs_fs.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index c25aaec..e42e34c 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -2665,7 +2665,12 @@ static void get_new_segment(struct f2fs_sb_info *sbi, if (secno >= MAIN_SECS(sbi)) { secno = find_first_zero_bit(free_i->free_secmap, MAIN_SECS(sbi)); - f2fs_bug_on(sbi, secno >= MAIN_SECS(sbi)); + if (secno >= MAIN_SECS(sbi)) { + f2fs_stop_checkpoint(sbi, false, + STOP_CP_REASON_NO_SEGMENT); + f2fs_bug_on(sbi, 1); + } + } segno = GET_SEG_FROM_SEC(sbi, secno); zoneno = GET_ZONE_FROM_SEC(sbi, secno); diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index 9b69c50..755e9a4 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -75,6 +75,7 @@ enum stop_cp_reason { STOP_CP_REASON_CORRUPTED_SUMMARY, STOP_CP_REASON_UPDATE_INODE, STOP_CP_REASON_FLUSH_FAIL, + STOP_CP_REASON_NO_SEGMENT, STOP_CP_REASON_MAX, }; -- 1.9.1