Re: [f2fs-dev] [PATCH] f2fs: migrate all curseg types when reserving device alias

From: Daeho Jeong

Date: Thu Dec 03 2026 - 13:58:19 EST


On Thu, Dec 3, 2026 at 8:39 AM Kyuwon Cho <kyuwon.cho@xxxxxxxx> wrote:
>
> The device-alias reserve ioctl moves persistent current segments out of
> the target range before reserving it, but leaves the in-memory ATGC
> current segment in place. A subsequent ATGC allocation can then consume a
> block that the ioctl has marked reserved and corrupt the SIT accounting.
>
> Iterate through every current segment type, as free_segment_range() does,
> so no active allocation cursor remains in the reserved range.
>
> Fixes: eae3faf210bd ("f2fs: support dynamic reserve/release for device aliasing")
> Signed-off-by: Kyuwon Cho <kyuwon.cho@xxxxxxxx>
> ---
> The issue was found by an LLM-guided test generator that we are
> developing as a research prototype.
>
> The reproducer mounts a two-device F2FS filesystem, places the ATGC
> current segment on the secondary device, reserves that device as an alias,
> and triggers another ATGC allocation. The mount and device-management
> ioctls require root in the initial namespace.
>

Hi Kyuwon,

Thanks for the fix, the change looks right to me.

The trace below is from the reserve ioctl itself, not from a subsequent
ATGC allocation, though. f2fs_gc_range() skips the section of a current
segment, so the valid blocks in the segment of the ATGC curseg are left in
the range, and f2fs_reserve_device_alias() adds the whole segment on top of
them. It looks like that is what hits the f2fs_bug_on() on new_vblocks in
update_sit_entry(). Could you describe it that way in the commit message?

This commit went into v7.3-rc1, so please add Cc: stable@xxxxxxxxxxxxxxx.

This doesn't apply to dev-test. Please rebase it onto dev-test.

Thanks,

> The decoded trace is:
>
> WARNING: fs/f2fs/segment.c:2669 at update_sit_entry
> update_sit_entry (fs/f2fs/segment.c:2669)
> f2fs_reserve_device_alias (fs/f2fs/segment.c:2759)
> f2fs_ioc_reserve_dev_alias (fs/f2fs/file.c:3861)
>
> With this patch, the reproducer completes without the warning on
> fe6ff8d5d675. The patch also builds on the current F2FS tree at
> b61a029304bb.
>
> fs/f2fs/file.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index c80dbbe76f8f..ebfe010fec43 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -4111,7 +4111,7 @@ static int f2fs_ioc_reserve_dev_alias(struct file *filp)
> 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_gc_unlock;
>
>
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@xxxxxxxxxxxxxxxxxxxxx
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel