Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp958404rdb; Sun, 18 Feb 2024 22:07:17 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXICxge6Pdz9SXZ11iIDvk1NB1X7zXlStqxZVz6q0aHP9ALaso2XLdqEmDar3HkrGV2w2CVkcD2OhYeKb3pQwpm3l0TW9pZnHtorV/W+w== X-Google-Smtp-Source: AGHT+IHGRiipel7711rdTYz+pfqxCEza+WqavS38/Hy9Im9Jtxvx0lxeRliygx80+u4s+EOPvZZX X-Received: by 2002:a0c:ab5c:0:b0:68f:2eac:5e1e with SMTP id i28-20020a0cab5c000000b0068f2eac5e1emr8550493qvb.38.1708322836850; Sun, 18 Feb 2024 22:07:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708322836; cv=pass; d=google.com; s=arc-20160816; b=n45Yd4LIcBtOYHErBhBvAiUCqviwuT6Z8GhtA7XH3bmzoeT5+qGS9GojsFI/2mF57Z Cx0j6yYKv7E+1e3jL8sZrFbb0vYE7YqfbKXFNbKaSeTXY2chBt084KJCnPqCX3g7NyJO /fIsouu4xd64JBGHInX9IzRPZx6C2vAGJZ6c/YeXojFVoPSIvncWY4v0913+bkzX903H Ph4tsLvJk3CCQLltbB91bG3lywgRu2vteaVkq9orfHgjSYi6z2Gh1WZcs2PeH2e+3/EA nB3I144TtODHFYCOLqrbEzCLopyz6x0LaEooTPRPEmYZwetE6qlcpCyEdqy9Q4HXX/ql Si1Q== 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=VjKnYAUrVx3Ki5CL6XKIjEzACQo+j6qELWT75/S1DDk=; fh=r88ULmOhzmh3DE8RgcUXK+PF5Q+3czCYkx5yGhGfkR0=; b=TfIPtyx85Qo0UDsI+JYsWygI2GEOh//S9sqFvIHOf3nEl9NX9c7rGQI+LFBhSvnDV9 TcK4WFcHQMIbbz6TVsO9NA+n5mBxvu7Nldi9bNn/JCtGLhr955DINE16hvOB6N+3GyL+ 6LwgVwsfqjUi/kiVsxgRSe54wInsJ1R7D5yNaYSuEvOX0uAbNSPLTPZG4DsDBfQ8AVMG Uf/YNpBAOTYfIVpu9OSMrylw1bOpMNMt4tnPXUFBiN9Kou8dasCZyWUVUZAg7K/zIhq0 MAlkTLe/VBkI6FkNXP5G8GQn6Gn+wG9C0ideBYf6rdJ6CpzcQHqj6Wvj0pjWI/hG3TBZ qW/A==; 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-70756-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70756-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id e6-20020a0562141d0600b0068f4553e43dsi5245218qvd.39.2024.02.18.22.07.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 22:07:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70756-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-70756-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70756-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 983761C20A60 for ; Mon, 19 Feb 2024 06:07:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6E352200BA; Mon, 19 Feb 2024 06:07:10 +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 1483D200AA for ; Mon, 19 Feb 2024 06:07:03 +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=1708322830; cv=none; b=BETuhnJNO6hyeDzeIckBd+u/VdMm2Cnvhu8BMxPLTRaInsqEA/pPVZpnrnM4+MZX9UuBns5wRnNIfXnnysZSF9o+dkV0pVZoZtQhQkv8oJanwB8o4H6fJkKOCt1juAgiAJOwBK1AbyUEhmwVh7NRcZWQSBZlhBJQnpM0tR32COQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708322830; c=relaxed/simple; bh=HxgbNk8HYWRJ+vJKOBWDpmgpChZqbFRAVYDH1On6wmM=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=gDJROEiTpocMTdHeUkrLG3s9JfB/+80F5S6YGhVzLG65EAcvivvRZ6clKeFTYLbDLmRUN00Yr6fS2g6lWvWJNVGJv8Lr765rqDgZOhsngZn4WZdZw5f+q8eCSvBmay86Pnc3hFW8XGqjpzE/iS+Rn+YYvV5NIeSxZcVjZt6GHww= 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 41J66QAm087442; Mon, 19 Feb 2024 14:06:26 +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 4TdX8g1Q9Gz2KG46m; Mon, 19 Feb 2024 14:05:55 +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; Mon, 19 Feb 2024 14:06:24 +0800 From: Zhiguo Niu To: , CC: , , , , , Subject: [PATCH v3 4/4] f2fs: stop checkpoint when get a out-of-bounds segment Date: Mon, 19 Feb 2024 14:05:41 +0800 Message-ID: <1708322741-14849-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: SHCAS01.spreadtrum.com (10.0.1.201) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL:SHSQR01.spreadtrum.com 41J66QAm087442 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_OUT_OF_RANGE. Signed-off-by: Zhiguo Niu --- 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..8f7ac49 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_OUT_OF_RANGE); + 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..56e260c 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_OUT_OF_RANGE, STOP_CP_REASON_MAX, }; -- 1.9.1