FAILED: patch "[PATCH] f2fs: fix to migrate all curseg types during" failed to apply to 6.1-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x 8ec06f50ddd8d201bd7e55b896ae28ed9d4cb7d1
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026090947-whimsical-pleat-2344@gregkh' --subject-prefix 'PATCH 6.1.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 8ec06f50ddd8d201bd7e55b896ae28ed9d4cb7d1 Mon Sep 17 00:00:00 2001
From: Daeho Jeong <[email protected]>
Date: Wed, 19 Aug 2026 11:06:35 -0700
Subject: [PATCH] f2fs: fix to migrate all curseg types during
free_segment_range
In free_segment_range(), the curseg evacuation loop only iterates up to NR_CURSEG_PERSIST_TYPE (0..5), missing non-persistent in-memory curseg types such as CURSEG_COLD_DATA_PINNED and CURSEG_ALL_DATA_ATGC.
Even though these in-memory curseg types are not saved in the on-disk checkpoint header, they still occupy active physical segments at runtime. If an active in-memory curseg happens to be allocated within the segment range being truncated during filesystem shrink, failing to evacuate it will cause subsequent writes to the curseg attempting out-of-bounds I/O on the truncated storage range.
Fix this by expanding the curseg evacuation loop upper bound to NR_CURSEG_TYPE to ensure all active curseg types are safely migrated out of the target range.
fs/f2fs/gc.c +1 -1
@@ -2240,7 +2240,7 @@ static int free_segment_range(struct f2fs_sb_info *sbi,f2fs_reset_gc_victim_resource (sbi, start, end);/* Move out cursegs from the target range */ -for (type =CURSEG_HOT_DATA ; type <NR_CURSEG_PERSIST_TYPE ; type++) { +for (type =CURSEG_HOT_DATA ; type <NR_CURSEG_TYPE ; type++) { err =f2fs_allocate_segment_for_resize (sbi, type, start, end);if (err) goto out;
Sasha Levin
maintainerPATCH 1/3 f2fs: delete f2fs_get_new_segment() declaration
From: Chao Yu <[email protected]>
[ Upstream commit e24e8333d0f3110473c6e6a20afd51911984e901 ]
Commit 093749e296e2 ("f2fs: support age threshold based garbage collection") added this declaration, but w/ definition, delete it.
Stable-dep-of: 8ec06f50ddd8 ("f2fs: fix to migrate all curseg types during free_segment_range")
--- fs/f2fs/f2fs.h | 2 -- 1 file changed, 2 deletions(-)
fs/f2fs/f2fs.h +0 -2
@@ -3653,8 +3653,6 @@ bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno);void f2fs_init_inmem_curseg (struct f2fs_sb_info *sbi);void f2fs_save_inmem_curseg (struct f2fs_sb_info *sbi);void f2fs_restore_inmem_curseg (struct f2fs_sb_info *sbi); -void f2fs_get_new_segment (struct f2fs_sb_info *sbi, -unsigned int *newseg,bool new_sec,int dir);void f2fs_allocate_segment_for_resize (struct f2fs_sb_info *sbi,int type,unsigned int start,unsigned int end);void f2fs_allocate_new_section (struct f2fs_sb_info *sbi,int type,bool force);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/3 f2fs: fix to handle error paths of {new,change}_curseg()
From: Zhiguo Niu <[email protected]>
[ Upstream commit 245930617c9bd85330c78e1a70775e1f61b12f7a ]
{new,change}_curseg() may return error in some special cases, error handling should be did in their callers, and this will also facilitate subsequent error path expansion in {new,change}_curseg().
[ Backport to 6.1: retain the resize error-handling prerequisite for
8ec06f50ddd8 ("f2fs: fix to migrate all curseg types during free_segment_range"). Return summary-page read errors from change_curseg() through f2fs_allocate_segment_for_resize(), and stop free_segment_range() through its existing cleanup path on failure.
Keep new_curseg() as void: this branch's get_new_segment() has no recoverable error return. Drop the unrelated ATGC initialization, mount, data-allocation and block-replacement hunks. The data-allocation changes assume newer return-value and ENOSPC handling absent from this tree, and none of these paths is required by the target's resize-loop fix. ]
[ sashal: Reduced backport -- upstream 245930617c9bd touches 4 file(s), this
backport carries 3. Not backported here:
fs/f2fs/super.c
This note is generated from the file lists only; see the resolution record for the reasoning. ]
Stable-dep-of: 8ec06f50ddd8 ("f2fs: fix to migrate all curseg types during free_segment_range")
--- fs/f2fs/f2fs.h | 2 +- fs/f2fs/gc.c | 7 +++++-- fs/f2fs/segment.c | 11 +++++++---- 3 files changed, 13 insertions(+), 7 deletions(-)
fs/f2fs/f2fs.h +1 -1
@@ -3653,7 +3653,7 @@ bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno);void f2fs_init_inmem_curseg (struct f2fs_sb_info *sbi);void f2fs_save_inmem_curseg (struct f2fs_sb_info *sbi);void f2fs_restore_inmem_curseg (struct f2fs_sb_info *sbi); -void f2fs_allocate_segment_for_resize (struct f2fs_sb_info *sbi,int type, +int f2fs_allocate_segment_for_resize (struct f2fs_sb_info *sbi,int type,unsigned int start,unsigned int end);void f2fs_allocate_new_section (struct f2fs_sb_info *sbi,int type,bool force);void f2fs_allocate_new_segments (struct f2fs_sb_info *sbi);
fs/f2fs/gc.c +5 -2
@@ -2014,8 +2014,11 @@ static int free_segment_range(struct f2fs_sb_info *sbi,mutex_unlock (&DIRTY_I (sbi)->seglist_lock);/* Move out cursegs from the target range */ -for (type =CURSEG_HOT_DATA ; type <NR_CURSEG_PERSIST_TYPE ; type++) -f2fs_allocate_segment_for_resize (sbi, type, start, end); +for (type =CURSEG_HOT_DATA ; type <NR_CURSEG_PERSIST_TYPE ; type++) { + err =f2fs_allocate_segment_for_resize (sbi, type, start, end); +if (err) + goto out; + }/* do GC to move out valid blocks in the range */ for (segno = start; segno <= end; segno += sbi->segs_per_sec) {
fs/f2fs/segment.c +7 -4
@@ -2674,7 +2674,7 @@ bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno)* This function always allocates a used segment(from dirty seglist) by SSR * manner, so it should recover the existing segment information of valid blocks */ -static void change_curseg (struct f2fs_sb_info *sbi,int type) +static int change_curseg (struct f2fs_sb_info *sbi,int type) {struct dirty_seglist_info *dirty_i =DIRTY_I (sbi);struct curseg_info *curseg =CURSEG_I (sbi, type);
@@ -2700,11 +2700,12 @@ static void change_curseg(struct f2fs_sb_info *sbi, int type)if (IS_ERR (sum_page)) {/* GC won't be able to use stale summary pages by cp_error */ memset (curseg->sum_blk,0 ,SUM_ENTRY_SIZE ); -return ; +return PTR_ERR (sum_page); } sum_node = (struct f2fs_summary_block *)page_address (sum_page);memcpy (curseg->sum_blk, sum_node,SUM_ENTRY_SIZE );f2fs_put_page (sum_page,1 ); +return 0 ; } static int get_ssr_segment(struct f2fs_sb_info *sbi, int type,
@@ -2882,11 +2883,12 @@ static bool need_new_seg(struct f2fs_sb_info *sbi, int type)return false; } -void f2fs_allocate_segment_for_resize (struct f2fs_sb_info *sbi,int type, +int f2fs_allocate_segment_for_resize (struct f2fs_sb_info *sbi,int type,unsigned int start,unsigned int end) {struct curseg_info *curseg =CURSEG_I (sbi, type);unsigned int segno; +int ret =0 ;f2fs_down_read (&SM_I (sbi)->curseg_lock);mutex_lock (&curseg->curseg_mutex);
@@ -2897,7 +2899,7 @@ void f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type, goto unlock;if (f2fs_need_SSR (sbi) &&get_ssr_segment (sbi, type,SSR ,0 )) -change_curseg (sbi, type); + ret =change_curseg (sbi, type);else new_curseg (sbi, type, true);
@@ -2913,6 +2915,7 @@ void f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type,mutex_unlock (&curseg->curseg_mutex);f2fs_up_read (&SM_I (sbi)->curseg_lock); +return ret; } static void __allocate_new_segment(struct f2fs_sb_info *sbi, int type,
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/3 f2fs: fix to migrate all curseg types during free_segment_range
In reply to Sasha LevinFrom: Daeho Jeong <[email protected]>
[ Upstream commit 8ec06f50ddd8d201bd7e55b896ae28ed9d4cb7d1 ]
In free_segment_range(), the curseg evacuation loop only iterates up to NR_CURSEG_PERSIST_TYPE (0..5), missing non-persistent in-memory curseg types such as CURSEG_COLD_DATA_PINNED and CURSEG_ALL_DATA_ATGC.
Even though these in-memory curseg types are not saved in the on-disk checkpoint header, they still occupy active physical segments at runtime. If an active in-memory curseg happens to be allocated within the segment range being truncated during filesystem shrink, failing to evacuate it will cause subsequent writes to the curseg attempting out-of-bounds I/O on the truncated storage range.
Fix this by expanding the curseg evacuation loop upper bound to NR_CURSEG_TYPE to ensure all active curseg types are safely migrated out of the target range.
--- fs/f2fs/gc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/gc.c +1 -1
@@ -2014,7 +2014,7 @@ static int free_segment_range(struct f2fs_sb_info *sbi,mutex_unlock (&DIRTY_I (sbi)->seglist_lock);/* Move out cursegs from the target range */ -for (type =CURSEG_HOT_DATA ; type <NR_CURSEG_PERSIST_TYPE ; type++) { +for (type =CURSEG_HOT_DATA ; type <NR_CURSEG_TYPE ; type++) { err =f2fs_allocate_segment_for_resize (sbi, type, start, end);if (err) goto out;
Signature · 1 line
2.53.0