linux-yocto/fs/f2fs
wangzijie 8ec4fa035c f2fs: fix zero-sized extent for precache extents
[ Upstream commit 8175c864391753b210f3dcfae1aeed686a226ebb ]

Script to reproduce:
f2fs_io write 1 0 1881 rand dsync testfile
f2fs_io fallocate 0 7708672 4096 testfile
f2fs_io write 1 1881 1 rand buffered testfile
fsync testfile
umount
mount
f2fs_io precache_extents testfile

When the data layout is something like this:
dnode1:                     dnode2:
[0]      A                  [0]    NEW_ADDR
[1]      A+1                [1]    0x0
...
[1016]   A+1016
[1017]   B (B!=A+1017)      [1017] 0x0

During precache_extents, we map the last block(valid blkaddr) in dnode1:
map->m_flags |= F2FS_MAP_MAPPED;
map->m_pblk = blkaddr(valid blkaddr);
map->m_len = 1;
then we goto next_dnode, meet the first block in dnode2(hole), goto sync_out:
map->m_flags & F2FS_MAP_MAPPED == true, and we make zero-sized extent:

map->m_len = 1
ofs = start_pgofs - map->m_lblk = 1882 - 1881 = 1
ei.fofs = start_pgofs = 1882
ei.len = map->m_len - ofs = 1 - 1 = 0

Rebased on patch[1], this patch can cover these cases to avoid zero-sized extent:
A,B,C is valid blkaddr
case1:
dnode1:                     dnode2:
[0]      A                  [0]    NEW_ADDR
[1]      A+1                [1]    0x0
...                         ....
[1016]   A+1016
[1017]   B (B!=A+1017)      [1017] 0x0

case2:
dnode1:                     dnode2:
[0]      A                  [0]    C (C!=B+1)
[1]      A+1                [1]    C+1
...                         ....
[1016]   A+1016
[1017]   B (B!=A+1017)      [1017] 0x0

case3:
dnode1:                     dnode2:
[0]      A                  [0]    C (C!=B+2)
[1]      A+1                [1]    C+1
...                         ....
[1015]   A+1015
[1016]   B (B!=A+1016)
[1017]   B+1                [1017] 0x0

[1] https://lore.kernel.org/linux-f2fs-devel/20250912081250.44383-1-chao@kernel.org/

Fixes: c4020b2da4 ("f2fs: support F2FS_IOC_PRECACHE_EXTENTS")
Signed-off-by: wangzijie <wangzijie1@honor.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2025-10-15 12:00:12 +02:00
..
acl.c f2fs: Use in_group_or_capable() helper 2024-06-25 11:15:48 +02:00
acl.h fs: port ->set_acl() to pass mnt_idmap 2023-01-19 09:24:27 +01:00
checkpoint.c Revert "f2fs: rebuild nat_bits during umount" 2025-04-20 10:15:20 +02:00
compress.c f2fs: use vmalloc instead of kvmalloc in .init_{,de}compress_ctx 2025-06-27 11:11:28 +01:00
data.c f2fs: fix zero-sized extent for precache extents 2025-10-15 12:00:12 +02:00
debug.c f2fs: clean up val{>>,<<}F2FS_BLKSIZE_BITS 2024-08-21 00:56:27 +00:00
dir.c f2fs: Introduce linear search for dentries 2025-02-08 09:58:11 +01:00
extent_cache.c f2fs: fix KMSAN uninit-value in extent_info usage 2025-08-15 12:14:00 +02:00
f2fs.h f2fs: fix condition in __allow_reserved_blocks() 2025-10-15 12:00:04 +02:00
file.c f2fs: fix to mitigate overhead of f2fs_zero_post_eof_page() 2025-10-15 12:00:12 +02:00
gc.c f2fs: turn off one_time when forcibly set to foreground GC 2025-08-15 12:14:00 +02:00
gc.h f2fs: decrease spare area for pinned files for zoned devices 2025-07-10 16:04:59 +02:00
hash.c
inline.c f2fs: Introduce linear search for dentries 2025-02-08 09:58:11 +01:00
inode.c f2fs: fix to avoid panic in f2fs_evict_inode 2025-08-15 12:14:01 +02:00
iostat.c f2fs: add async reset zone command support 2023-06-12 13:04:09 -07:00
iostat.h f2fs: use iostat_lat_type directly as a parameter in the iostat_update_and_unbind_ctx() 2023-02-07 10:39:28 -08:00
Kconfig fs: add CONFIG_BUFFER_HEAD 2023-08-02 09:13:09 -06:00
Makefile
namei.c f2fs: prevent kernel warning due to negative i_nlink from corrupted image 2025-06-27 11:11:21 +01:00
node.c f2fs: fix to avoid out-of-boundary access in dnode page 2025-08-28 16:30:59 +02:00
node.h f2fs: use BLKS_PER_SEG, BLKS_PER_SEC, and SEGS_PER_SEC 2024-02-27 09:41:12 -08:00
recovery.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
segment.c f2fs: zone: fix to calculate first_zoned_segno correctly 2025-07-10 16:04:59 +02:00
segment.h f2fs: fix to calculate dirty data during has_not_enough_free_secs() 2025-08-15 12:14:01 +02:00
shrinker.c f2fs: add block_age-based extent cache 2022-12-12 14:53:56 -08:00
super.c f2fs: fix bio memleak when committing super block 2025-08-15 12:14:00 +02:00
sysfs.c f2fs: fix to check upper boundary for gc_no_zoned_gc_percent 2025-08-15 12:14:01 +02:00
verity.c f2fs-6.12-rc1 2024-09-24 15:12:38 -07:00
xattr.c f2fs: reduce expensive checkpoint trigger frequency 2024-08-15 15:26:39 +00:00
xattr.h f2fs: move f2fs_xattr_handlers and f2fs_xattr_handler_map to .rodata 2023-10-09 16:24:18 +02:00