Received: by 2002:a05:7412:2a8a:b0:fc:a2b0:25d7 with SMTP id u10csp31213rdh; Tue, 6 Feb 2024 18:03:14 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVYbeusZHuG7O949m6nUcXcoejgjEG8RVR7Qh98gGTxZHyZFYFZfLBqoqVFVpBdt9nsrlZ7CvQ9P/hNqfMnj9BUu3Mfq5CACYk6ZwqT9w== X-Google-Smtp-Source: AGHT+IFkui7e2KwgwTYtkizyt8XRVStNG7RWfRH5szaiQ9KbZhfwWv1iZ7OcpWOM5Z63tx7MNtK5 X-Received: by 2002:a17:906:3285:b0:a38:404b:b900 with SMTP id 5-20020a170906328500b00a38404bb900mr1624857ejw.5.1707271393935; Tue, 06 Feb 2024 18:03:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707271393; cv=pass; d=google.com; s=arc-20160816; b=kuMa0lgGqX0OAIm6vCWUvhYOm5Siczx+vyeqzHbBDNM160uM0ZmTkk58PUBtWYgX2y vMujprWOf4vqiS2YP0k9C6x8TNB/Nj47K/Gjxvt2KBI6+hZt136PFIzxJaiRK6V5wITJ 80G/tPG18/O4oePF4qf5wtNXXGWm1PnkU0EWwgix7VsGLSx4QVXOnOLauaenuIoo2Ezt 83y687P8ODFZmiQGeVnIKtv8cRY0+u05h6NC46GgX9qrbV4+zFVx+ghozwK8457455ZY VAjvogNDW2j48VBw1hj/BuYsQI/cDo7fQ2TqKUvKG9f9EsSkgw8F/5Vivchhl3Gdazwy RzOQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=UUapLQNZ1dFdUivHxq6wW1o7ulSeHAgqxA8ZephskyA=; fh=501rfalSXj07z/c/q/b3MeIYZxZ5wdu7mwwU7f26/xQ=; b=WJAUuoy5peJqREUbl7CC3g/AnM7eJyh7mUAax50+3Q+iZWDR0NYdwiEs8Rfs6fyl59 FSmVez6aV2yGTTB+MpPAc12QPMGLwx67Z2U0hfIptA4nKjlIQhBepGbDiRm8It4PupAS Y7ynn6jRORU99Yhi2QZN/gLTvugsDQjvu2YkinFgIOf0EC3ErYsNfmIMjQmxu/enqKr/ oZl21uRYY0cMuOgG6bsnE6/V611FpU9XjJZsDCjbVqNHkJVLUGf8tN4B3uic6/dppNeo MFzbgbOV/ZxdN+NSzlwlisk5BKphh0i0K5KmuR2uI/OJ8m0DCj2wgDW9gYc2wyUXZgkd twpA==; 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-55831-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55831-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCVCjQPbCkBpdT67hsX+ZOHqx0zYCKKK0AhdUpwny0pVedU0pjdtxfreN5SS4LQcX+x2HfTEaAGiaPZZlFtLJfLccYFcSrWhUAlT1kOH4g== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id gf19-20020a170906e21300b00a383403fbf0si227709ejb.577.2024.02.06.18.03.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 18:03:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55831-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-55831-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55831-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 am.mirrors.kernel.org (Postfix) with ESMTPS id ACB011F277D6 for ; Wed, 7 Feb 2024 02:03:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D3DAA15E96; Wed, 7 Feb 2024 02:02:16 +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 8B268134A4 for ; Wed, 7 Feb 2024 02:02:14 +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=1707271336; cv=none; b=BubJWg8EYabNIOm/U5bFaBIifguF+Dz9/AMiGtfitE6d/d0k2HLPDRav8UAZy1umefQ9zNY6F6B6F0vN6xRVwrthAGmuqRb5aYEYucYkCeupdlHw6BUZCuVAA+xf7iIW4LoePqDlyJ6KECIPOmj/SFoQtSkP7s5bBwRmi9gJ7kc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707271336; c=relaxed/simple; bh=ax5uZYqMwPzUWWg81cnbAG10+zb+AYQ7l9nQlARj9WM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uQNkHr9/MEKmxMYCAUtHqg7tYGAFcurolYAkgKaXAGPE0l7lIyxIBCnRnBGbwdoOxP1RuD2A5+MITe1niAvaDrqzRbwYb08AppJegSu+dZLbGlAovbaa6YHN5QcEFulZrYEUx4iHO7hbhTZrO/8uROaSsv6Gg32V4D0jh4Ncwbk= 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 41721cDM075958; Wed, 7 Feb 2024 10:01:38 +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 4TV3JC0nQwz2K4cHw; Wed, 7 Feb 2024 10:01:31 +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; Wed, 7 Feb 2024 10:01:36 +0800 From: Zhiguo Niu To: , CC: , , , , , Subject: [PATCH v2 4/4] f2fs: stop checkpoint when get a out-of-bounds segment Date: Wed, 7 Feb 2024 10:01:04 +0800 Message-ID: <1707271264-5551-5-git-send-email-zhiguo.niu@unisoc.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1707271264-5551-1-git-send-email-zhiguo.niu@unisoc.com> References: <1707271264-5551-1-git-send-email-zhiguo.niu@unisoc.com> 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 41721cDM075958 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_OUTOF_RAGNE. Signed-off-by: Zhiguo Niu --- fs/f2fs/segment.c | 12 ++++++++++-- include/linux/f2fs_fs.h | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 6772ad4..6fe2baf 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -2666,7 +2666,11 @@ static void get_new_segment(struct f2fs_sb_info *sbi, if (dir == ALLOC_RIGHT) { 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_OUTOF_RAGNE); + f2fs_bug_on(sbi, 1); + } } else { go_left = 1; left_start = hint - 1; @@ -2682,7 +2686,11 @@ static void get_new_segment(struct f2fs_sb_info *sbi, } left_start = find_first_zero_bit(free_i->free_secmap, MAIN_SECS(sbi)); - f2fs_bug_on(sbi, left_start >= MAIN_SECS(sbi)); + if (left_start >= MAIN_SECS(sbi)) { + f2fs_stop_checkpoint(sbi, false, + STOP_CP_REASON_OUTOF_RAGNE); + f2fs_bug_on(sbi, 1); + } break; } secno = left_start; diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index 053137a0..72c6782 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -81,6 +81,7 @@ enum stop_cp_reason { STOP_CP_REASON_CORRUPTED_SUMMARY, STOP_CP_REASON_UPDATE_INODE, STOP_CP_REASON_FLUSH_FAIL, + STOP_CP_REASON_OUTOF_RAGNE, STOP_CP_REASON_MAX, }; -- 1.9.1