Patch "f2fs: stop checkpoint when get a out-of-bounds segment" has been added to the 6.6-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    f2fs: stop checkpoint when get a out-of-bounds segment

to the 6.6-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     f2fs-stop-checkpoint-when-get-a-out-of-bounds-segmen.patch
and it can be found in the queue-6.6 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit ef74a30a7fe55bda5e0a31916e74e32d53c3ed31
Author: Zhiguo Niu <zhiguo.niu@xxxxxxxxxx>
Date:   Tue Feb 20 14:11:24 2024 +0800

    f2fs: stop checkpoint when get a out-of-bounds segment
    
    [ Upstream commit f9e28904e6442019043a8e94ec6747a064d06003 ]
    
    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.
    
    Note, f2fs_stop_checkpoint(, false) is complex and it may sleep, so we should
    move it outside segmap_lock spinlock coverage in get_new_segment().
    
    Signed-off-by: Zhiguo Niu <zhiguo.niu@xxxxxxxxxx>
    Reviewed-by: Chao Yu <chao@xxxxxxxxxx>
    Signed-off-by: Jaegeuk Kim <jaegeuk@xxxxxxxxxx>
    Stable-dep-of: b084403cfc32 ("f2fs: write missing last sum blk of file pinning section")
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index a29fdf30c5842..42653202b3fea 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -2647,6 +2647,7 @@ static void get_new_segment(struct f2fs_sb_info *sbi,
 	unsigned int old_zoneno = GET_ZONE_FROM_SEG(sbi, *newseg);
 	bool init = true;
 	int i;
+	int ret = 0;
 
 	spin_lock(&free_i->segmap_lock);
 
@@ -2671,7 +2672,10 @@ 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)) {
+			ret = -ENOSPC;
+			goto out_unlock;
+		}
 	}
 	segno = GET_SEG_FROM_SEC(sbi, secno);
 	zoneno = GET_ZONE_FROM_SEC(sbi, secno);
@@ -2701,7 +2705,13 @@ static void get_new_segment(struct f2fs_sb_info *sbi,
 	f2fs_bug_on(sbi, test_bit(segno, free_i->free_segmap));
 	__set_inuse(sbi, segno);
 	*newseg = segno;
+out_unlock:
 	spin_unlock(&free_i->segmap_lock);
+
+	if (ret) {
+		f2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_NO_SEGMENT);
+		f2fs_bug_on(sbi, 1);
+	}
 }
 
 static void reset_curseg(struct f2fs_sb_info *sbi, int type, int modified)
diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h
index 3b04657787d09..1352a24d72ef4 100644
--- a/include/linux/f2fs_fs.h
+++ b/include/linux/f2fs_fs.h
@@ -76,6 +76,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,
 };
 




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux