* [PATCH -next 0/8] Fix some issues about ext4-test
@ 2026-03-10 13:04 Ye Bin
2026-03-10 13:04 ` [PATCH -next 1/8] ext4: fix mballoc-test.c is not compiled when EXT4_KUNIT_TESTS=M Ye Bin
` (8 more replies)
0 siblings, 9 replies; 21+ messages in thread
From: Ye Bin @ 2026-03-10 13:04 UTC (permalink / raw)
To: tytso, adilger.kernel, linux-ext4; +Cc: jack
From: Ye Bin <yebin10@huawei.com>
Patch [1]-[2]:
Decoupled mballoc-test and extents-test from ext4. Patch [1] does not
have any changes compared to the previously released version, so the
reviewed-by is added.
Patch [3-7]:
Bugfix for extents-test.c.
Patch [8]:
Bugfix for mballoc-test.c.
Ye Bin (8):
ext4: fix mballoc-test.c is not compiled when EXT4_KUNIT_TESTS=M
ext4: introduce EXPORT_SYMBOL_FOR_EXT4_TEST() helper
ext4: fix extents-test.c is not compiled when EXT4_KUNIT_TESTS=M
ext4: fix miss unlock 'sb->s_umount' in extents_kunit_init()
ext4: fix miss free super_block in extents_kunit_exit()
ext4: fix the error handling process in extents_kunit_init).
ext4: fix possible null-ptr-deref in extents_kunit_exit()
ext4: fix possible null-ptr-deref in mbt_kunit_exit()
fs/ext4/Makefile | 5 +-
fs/ext4/ext4.h | 5 ++
fs/ext4/ext4_extents.h | 12 +++++
fs/ext4/extents-test.c | 59 ++++++++++++++++--------
fs/ext4/extents.c | 38 ++++++++++++---
fs/ext4/mballoc-test.c | 87 ++++++++++++++++++-----------------
fs/ext4/mballoc.c | 102 +++++++++++++++++++++++++++++++++++++++--
fs/ext4/mballoc.h | 30 ++++++++++++
8 files changed, 268 insertions(+), 70 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 21+ messages in thread* [PATCH -next 1/8] ext4: fix mballoc-test.c is not compiled when EXT4_KUNIT_TESTS=M 2026-03-10 13:04 [PATCH -next 0/8] Fix some issues about ext4-test Ye Bin @ 2026-03-10 13:04 ` Ye Bin 2026-03-11 2:44 ` kernel test robot 2026-03-11 3:26 ` kernel test robot 2026-03-10 13:04 ` [PATCH -next 2/8] ext4: introduce EXPORT_SYMBOL_FOR_EXT4_TEST() helper Ye Bin ` (7 subsequent siblings) 8 siblings, 2 replies; 21+ messages in thread From: Ye Bin @ 2026-03-10 13:04 UTC (permalink / raw) To: tytso, adilger.kernel, linux-ext4; +Cc: jack From: Ye Bin <yebin10@huawei.com> Now, only EXT4_KUNIT_TESTS=Y testcase will be compiled in 'mballoc.c'. To solve this issue, the ext4 test code needs to be decoupled. The ext4 test module is compiled into a separate module. Reported-by: ChenXiaoSong <chenxiaosong@kylinos.cn> Closes: https://patchwork.kernel.org/project/cifs-client/patch/20260118091313.1988168-2-chenxiaosong.chenxiaosong@linux.dev/ Fixes: 7c9fa399a369 ("ext4: add first unit test for ext4_mb_new_blocks_simple in mballoc") Signed-off-by: Ye Bin <yebin10@huawei.com> Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com> --- fs/ext4/Makefile | 4 +- fs/ext4/mballoc-test.c | 81 +++++++++++++++---------------- fs/ext4/mballoc.c | 105 +++++++++++++++++++++++++++++++++++++++-- fs/ext4/mballoc.h | 30 ++++++++++++ 4 files changed, 175 insertions(+), 45 deletions(-) diff --git a/fs/ext4/Makefile b/fs/ext4/Makefile index 72206a292676..d836c3fe311b 100644 --- a/fs/ext4/Makefile +++ b/fs/ext4/Makefile @@ -14,7 +14,7 @@ ext4-y := balloc.o bitmap.o block_validity.o dir.o ext4_jbd2.o extents.o \ ext4-$(CONFIG_EXT4_FS_POSIX_ACL) += acl.o ext4-$(CONFIG_EXT4_FS_SECURITY) += xattr_security.o -ext4-inode-test-objs += inode-test.o -obj-$(CONFIG_EXT4_KUNIT_TESTS) += ext4-inode-test.o +ext4-test-objs += inode-test.o mballoc-test.o +obj-$(CONFIG_EXT4_KUNIT_TESTS) += ext4-test.o ext4-$(CONFIG_FS_VERITY) += verity.o ext4-$(CONFIG_FS_ENCRYPTION) += crypto.o diff --git a/fs/ext4/mballoc-test.c b/fs/ext4/mballoc-test.c index b9f22e3a8d5c..c75b91ae0cf0 100644 --- a/fs/ext4/mballoc-test.c +++ b/fs/ext4/mballoc-test.c @@ -8,6 +8,7 @@ #include <linux/random.h> #include "ext4.h" +#include "mballoc.h" struct mbt_grp_ctx { struct buffer_head bitmap_bh; @@ -336,7 +337,7 @@ ext4_mb_mark_context_stub(handle_t *handle, struct super_block *sb, bool state, if (state) mb_set_bits(bitmap_bh->b_data, blkoff, len); else - mb_clear_bits(bitmap_bh->b_data, blkoff, len); + mb_clear_bits_test(bitmap_bh->b_data, blkoff, len); return 0; } @@ -413,14 +414,14 @@ static void test_new_blocks_simple(struct kunit *test) /* get block at goal */ ar.goal = ext4_group_first_block_no(sb, goal_group); - found = ext4_mb_new_blocks_simple(&ar, &err); + found = ext4_mb_new_blocks_simple_test(&ar, &err); KUNIT_ASSERT_EQ_MSG(test, ar.goal, found, "failed to alloc block at goal, expected %llu found %llu", ar.goal, found); /* get block after goal in goal group */ ar.goal = ext4_group_first_block_no(sb, goal_group); - found = ext4_mb_new_blocks_simple(&ar, &err); + found = ext4_mb_new_blocks_simple_test(&ar, &err); KUNIT_ASSERT_EQ_MSG(test, ar.goal + EXT4_C2B(sbi, 1), found, "failed to alloc block after goal in goal group, expected %llu found %llu", ar.goal + 1, found); @@ -428,7 +429,7 @@ static void test_new_blocks_simple(struct kunit *test) /* get block after goal group */ mbt_ctx_mark_used(sb, goal_group, 0, EXT4_CLUSTERS_PER_GROUP(sb)); ar.goal = ext4_group_first_block_no(sb, goal_group); - found = ext4_mb_new_blocks_simple(&ar, &err); + found = ext4_mb_new_blocks_simple_test(&ar, &err); KUNIT_ASSERT_EQ_MSG(test, ext4_group_first_block_no(sb, goal_group + 1), found, "failed to alloc block after goal group, expected %llu found %llu", @@ -438,7 +439,7 @@ static void test_new_blocks_simple(struct kunit *test) for (i = goal_group; i < ext4_get_groups_count(sb); i++) mbt_ctx_mark_used(sb, i, 0, EXT4_CLUSTERS_PER_GROUP(sb)); ar.goal = ext4_group_first_block_no(sb, goal_group); - found = ext4_mb_new_blocks_simple(&ar, &err); + found = ext4_mb_new_blocks_simple_test(&ar, &err); KUNIT_ASSERT_EQ_MSG(test, ext4_group_first_block_no(sb, 0) + EXT4_C2B(sbi, 1), found, "failed to alloc block before goal group, expected %llu found %llu", @@ -448,7 +449,7 @@ static void test_new_blocks_simple(struct kunit *test) for (i = 0; i < ext4_get_groups_count(sb); i++) mbt_ctx_mark_used(sb, i, 0, EXT4_CLUSTERS_PER_GROUP(sb)); ar.goal = ext4_group_first_block_no(sb, goal_group); - found = ext4_mb_new_blocks_simple(&ar, &err); + found = ext4_mb_new_blocks_simple_test(&ar, &err); KUNIT_ASSERT_NE_MSG(test, err, 0, "unexpectedly get block when no block is available"); } @@ -492,16 +493,16 @@ validate_free_blocks_simple(struct kunit *test, struct super_block *sb, continue; bitmap = mbt_ctx_bitmap(sb, i); - bit = mb_find_next_zero_bit(bitmap, max, 0); + bit = mb_find_next_zero_bit_test(bitmap, max, 0); KUNIT_ASSERT_EQ_MSG(test, bit, max, "free block on unexpected group %d", i); } bitmap = mbt_ctx_bitmap(sb, goal_group); - bit = mb_find_next_zero_bit(bitmap, max, 0); + bit = mb_find_next_zero_bit_test(bitmap, max, 0); KUNIT_ASSERT_EQ(test, bit, start); - bit = mb_find_next_bit(bitmap, max, bit + 1); + bit = mb_find_next_bit_test(bitmap, max, bit + 1); KUNIT_ASSERT_EQ(test, bit, start + len); } @@ -524,7 +525,7 @@ test_free_blocks_simple_range(struct kunit *test, ext4_group_t goal_group, block = ext4_group_first_block_no(sb, goal_group) + EXT4_C2B(sbi, start); - ext4_free_blocks_simple(inode, block, len); + ext4_free_blocks_simple_test(inode, block, len); validate_free_blocks_simple(test, sb, goal_group, start, len); mbt_ctx_mark_used(sb, goal_group, 0, EXT4_CLUSTERS_PER_GROUP(sb)); } @@ -566,15 +567,15 @@ test_mark_diskspace_used_range(struct kunit *test, bitmap = mbt_ctx_bitmap(sb, TEST_GOAL_GROUP); memset(bitmap, 0, sb->s_blocksize); - ret = ext4_mb_mark_diskspace_used(ac, NULL); + ret = ext4_mb_mark_diskspace_used_test(ac, NULL); KUNIT_ASSERT_EQ(test, ret, 0); max = EXT4_CLUSTERS_PER_GROUP(sb); - i = mb_find_next_bit(bitmap, max, 0); + i = mb_find_next_bit_test(bitmap, max, 0); KUNIT_ASSERT_EQ(test, i, start); - i = mb_find_next_zero_bit(bitmap, max, i + 1); + i = mb_find_next_zero_bit_test(bitmap, max, i + 1); KUNIT_ASSERT_EQ(test, i, start + len); - i = mb_find_next_bit(bitmap, max, i + 1); + i = mb_find_next_bit_test(bitmap, max, i + 1); KUNIT_ASSERT_EQ(test, max, i); } @@ -617,54 +618,54 @@ static void mbt_generate_buddy(struct super_block *sb, void *buddy, max = EXT4_CLUSTERS_PER_GROUP(sb); bb_h = buddy + sbi->s_mb_offsets[1]; - off = mb_find_next_zero_bit(bb, max, 0); + off = mb_find_next_zero_bit_test(bb, max, 0); grp->bb_first_free = off; while (off < max) { grp->bb_counters[0]++; grp->bb_free++; - if (!(off & 1) && !mb_test_bit(off + 1, bb)) { + if (!(off & 1) && !mb_test_bit_test(off + 1, bb)) { grp->bb_free++; grp->bb_counters[0]--; - mb_clear_bit(off >> 1, bb_h); + mb_clear_bit_test(off >> 1, bb_h); grp->bb_counters[1]++; grp->bb_largest_free_order = 1; off++; } - off = mb_find_next_zero_bit(bb, max, off + 1); + off = mb_find_next_zero_bit_test(bb, max, off + 1); } for (order = 1; order < MB_NUM_ORDERS(sb) - 1; order++) { bb = buddy + sbi->s_mb_offsets[order]; bb_h = buddy + sbi->s_mb_offsets[order + 1]; max = max >> 1; - off = mb_find_next_zero_bit(bb, max, 0); + off = mb_find_next_zero_bit_test(bb, max, 0); while (off < max) { - if (!(off & 1) && !mb_test_bit(off + 1, bb)) { + if (!(off & 1) && !mb_test_bit_test(off + 1, bb)) { mb_set_bits(bb, off, 2); grp->bb_counters[order] -= 2; - mb_clear_bit(off >> 1, bb_h); + mb_clear_bit_test(off >> 1, bb_h); grp->bb_counters[order + 1]++; grp->bb_largest_free_order = order + 1; off++; } - off = mb_find_next_zero_bit(bb, max, off + 1); + off = mb_find_next_zero_bit_test(bb, max, off + 1); } } max = EXT4_CLUSTERS_PER_GROUP(sb); - off = mb_find_next_zero_bit(bitmap, max, 0); + off = mb_find_next_zero_bit_test(bitmap, max, 0); while (off < max) { grp->bb_fragments++; - off = mb_find_next_bit(bitmap, max, off + 1); + off = mb_find_next_bit_test(bitmap, max, off + 1); if (off + 1 >= max) break; - off = mb_find_next_zero_bit(bitmap, max, off + 1); + off = mb_find_next_zero_bit_test(bitmap, max, off + 1); } } @@ -706,7 +707,7 @@ do_test_generate_buddy(struct kunit *test, struct super_block *sb, void *bitmap, /* needed by validation in ext4_mb_generate_buddy */ ext4_grp->bb_free = mbt_grp->bb_free; memset(ext4_buddy, 0xff, sb->s_blocksize); - ext4_mb_generate_buddy(sb, ext4_buddy, bitmap, TEST_GOAL_GROUP, + ext4_mb_generate_buddy_test(sb, ext4_buddy, bitmap, TEST_GOAL_GROUP, ext4_grp); KUNIT_ASSERT_EQ(test, memcmp(mbt_buddy, ext4_buddy, sb->s_blocksize), @@ -760,7 +761,7 @@ test_mb_mark_used_range(struct kunit *test, struct ext4_buddy *e4b, ex.fe_group = TEST_GOAL_GROUP; ext4_lock_group(sb, TEST_GOAL_GROUP); - mb_mark_used(e4b, &ex); + mb_mark_used_test(e4b, &ex); ext4_unlock_group(sb, TEST_GOAL_GROUP); mb_set_bits(bitmap, start, len); @@ -769,7 +770,7 @@ test_mb_mark_used_range(struct kunit *test, struct ext4_buddy *e4b, memset(buddy, 0xff, sb->s_blocksize); for (i = 0; i < MB_NUM_ORDERS(sb); i++) grp->bb_counters[i] = 0; - ext4_mb_generate_buddy(sb, buddy, bitmap, 0, grp); + ext4_mb_generate_buddy_test(sb, buddy, bitmap, 0, grp); KUNIT_ASSERT_EQ(test, memcmp(buddy, e4b->bd_buddy, sb->s_blocksize), 0); @@ -798,7 +799,7 @@ static void test_mb_mark_used(struct kunit *test) bb_counters[MB_NUM_ORDERS(sb)]), GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, grp); - ret = ext4_mb_load_buddy(sb, TEST_GOAL_GROUP, &e4b); + ret = ext4_mb_load_buddy_test(sb, TEST_GOAL_GROUP, &e4b); KUNIT_ASSERT_EQ(test, ret, 0); grp->bb_free = EXT4_CLUSTERS_PER_GROUP(sb); @@ -809,7 +810,7 @@ static void test_mb_mark_used(struct kunit *test) test_mb_mark_used_range(test, &e4b, ranges[i].start, ranges[i].len, bitmap, buddy, grp); - ext4_mb_unload_buddy(&e4b); + ext4_mb_unload_buddy_test(&e4b); } static void @@ -825,16 +826,16 @@ test_mb_free_blocks_range(struct kunit *test, struct ext4_buddy *e4b, return; ext4_lock_group(sb, e4b->bd_group); - mb_free_blocks(NULL, e4b, start, len); + mb_free_blocks_test(NULL, e4b, start, len); ext4_unlock_group(sb, e4b->bd_group); - mb_clear_bits(bitmap, start, len); + mb_clear_bits_test(bitmap, start, len); /* bypass bb_free validatoin in ext4_mb_generate_buddy */ grp->bb_free += len; memset(buddy, 0xff, sb->s_blocksize); for (i = 0; i < MB_NUM_ORDERS(sb); i++) grp->bb_counters[i] = 0; - ext4_mb_generate_buddy(sb, buddy, bitmap, 0, grp); + ext4_mb_generate_buddy_test(sb, buddy, bitmap, 0, grp); KUNIT_ASSERT_EQ(test, memcmp(buddy, e4b->bd_buddy, sb->s_blocksize), 0); @@ -865,7 +866,7 @@ static void test_mb_free_blocks(struct kunit *test) bb_counters[MB_NUM_ORDERS(sb)]), GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, grp); - ret = ext4_mb_load_buddy(sb, TEST_GOAL_GROUP, &e4b); + ret = ext4_mb_load_buddy_test(sb, TEST_GOAL_GROUP, &e4b); KUNIT_ASSERT_EQ(test, ret, 0); ex.fe_start = 0; @@ -873,7 +874,7 @@ static void test_mb_free_blocks(struct kunit *test) ex.fe_group = TEST_GOAL_GROUP; ext4_lock_group(sb, TEST_GOAL_GROUP); - mb_mark_used(&e4b, &ex); + mb_mark_used_test(&e4b, &ex); ext4_unlock_group(sb, TEST_GOAL_GROUP); grp->bb_free = 0; @@ -886,7 +887,7 @@ static void test_mb_free_blocks(struct kunit *test) test_mb_free_blocks_range(test, &e4b, ranges[i].start, ranges[i].len, bitmap, buddy, grp); - ext4_mb_unload_buddy(&e4b); + ext4_mb_unload_buddy_test(&e4b); } #define COUNT_FOR_ESTIMATE 100000 @@ -904,7 +905,7 @@ static void test_mb_mark_used_cost(struct kunit *test) if (sb->s_blocksize > PAGE_SIZE) kunit_skip(test, "blocksize exceeds pagesize"); - ret = ext4_mb_load_buddy(sb, TEST_GOAL_GROUP, &e4b); + ret = ext4_mb_load_buddy_test(sb, TEST_GOAL_GROUP, &e4b); KUNIT_ASSERT_EQ(test, ret, 0); ex.fe_group = TEST_GOAL_GROUP; @@ -918,7 +919,7 @@ static void test_mb_mark_used_cost(struct kunit *test) ex.fe_start = ranges[i].start; ex.fe_len = ranges[i].len; ext4_lock_group(sb, TEST_GOAL_GROUP); - mb_mark_used(&e4b, &ex); + mb_mark_used_test(&e4b, &ex); ext4_unlock_group(sb, TEST_GOAL_GROUP); } end = jiffies; @@ -929,14 +930,14 @@ static void test_mb_mark_used_cost(struct kunit *test) continue; ext4_lock_group(sb, TEST_GOAL_GROUP); - mb_free_blocks(NULL, &e4b, ranges[i].start, + mb_free_blocks_test(NULL, &e4b, ranges[i].start, ranges[i].len); ext4_unlock_group(sb, TEST_GOAL_GROUP); } } kunit_info(test, "costed jiffies %lu\n", all); - ext4_mb_unload_buddy(&e4b); + ext4_mb_unload_buddy_test(&e4b); } static const struct mbt_ext4_block_layout mbt_test_layouts[] = { diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index fcc55d2a00a1..842a604ae5db 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -4088,7 +4088,7 @@ void ext4_exit_mballoc(void) #define EXT4_MB_BITMAP_MARKED_CHECK 0x0001 #define EXT4_MB_SYNC_UPDATE 0x0002 -static int +int ext4_mb_mark_context(handle_t *handle, struct super_block *sb, bool state, ext4_group_t group, ext4_grpblk_t blkoff, ext4_grpblk_t len, int flags, ext4_grpblk_t *ret_changed) @@ -7192,6 +7192,105 @@ ext4_mballoc_query_range( return error; } -#ifdef CONFIG_EXT4_KUNIT_TESTS -#include "mballoc-test.c" +#if IS_ENABLED(CONFIG_EXT4_KUNIT_TESTS) +#define EXPORT_SYMBOL_FOR_EXT4_TEST(sym) \ + EXPORT_SYMBOL_FOR_MODULES(sym, "ext4-test") + +void mb_clear_bits_test(void *bm, int cur, int len) +{ + mb_clear_bits(bm, cur, len); +} +EXPORT_SYMBOL_FOR_EXT4_TEST(mb_clear_bits_test); + +ext4_fsblk_t +ext4_mb_new_blocks_simple_test(struct ext4_allocation_request *ar, + int *errp) +{ + return ext4_mb_new_blocks_simple(ar, errp); +} +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_mb_new_blocks_simple_test); + +int mb_find_next_zero_bit_test(void *addr, int max, int start) +{ + return mb_find_next_zero_bit(addr, max, start); +} +EXPORT_SYMBOL_FOR_EXT4_TEST(mb_find_next_zero_bit_test); + +int mb_find_next_bit_test(void *addr, int max, int start) +{ + return mb_find_next_bit(addr, max, start); +} +EXPORT_SYMBOL_FOR_EXT4_TEST(mb_find_next_bit_test); + +void mb_clear_bit_test(int bit, void *addr) +{ + mb_clear_bit(bit, addr); +} +EXPORT_SYMBOL_FOR_EXT4_TEST(mb_clear_bit_test); + +int mb_test_bit_test(int bit, void *addr) +{ + return mb_test_bit(bit, addr); +} +EXPORT_SYMBOL_FOR_EXT4_TEST(mb_test_bit_test); + +int ext4_mb_mark_diskspace_used_test(struct ext4_allocation_context *ac, + handle_t *handle) +{ + return ext4_mb_mark_diskspace_used(ac, handle); +} +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_mb_mark_diskspace_used_test); + +int mb_mark_used_test(struct ext4_buddy *e4b, struct ext4_free_extent *ex) +{ + return mb_mark_used(e4b, ex); +} +EXPORT_SYMBOL_FOR_EXT4_TEST(mb_mark_used_test); + +void ext4_mb_generate_buddy_test(struct super_block *sb, void *buddy, + void *bitmap, ext4_group_t group, + struct ext4_group_info *grp) +{ + ext4_mb_generate_buddy(sb, buddy, bitmap, group, grp); +} +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_mb_generate_buddy_test); + +int ext4_mb_load_buddy_test(struct super_block *sb, ext4_group_t group, + struct ext4_buddy *e4b) +{ + return ext4_mb_load_buddy(sb, group, e4b); +} +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_mb_load_buddy_test); + +void ext4_mb_unload_buddy_test(struct ext4_buddy *e4b) +{ + ext4_mb_unload_buddy(e4b); +} +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_mb_unload_buddy_test); + +void mb_free_blocks_test(struct inode *inode, struct ext4_buddy *e4b, + int first, int count) +{ + mb_free_blocks(inode, e4b, first, count); +} +EXPORT_SYMBOL_FOR_EXT4_TEST(mb_free_blocks_test); + +void ext4_free_blocks_simple_test(struct inode *inode, ext4_fsblk_t block, + unsigned long count) +{ + return ext4_free_blocks_simple(inode, block, count); +} +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_free_blocks_simple_test); + +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_wait_block_bitmap); +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_mb_init); +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_get_group_desc); +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_count_free_clusters); +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_get_group_info); +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_free_group_clusters_set); +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_mb_release); +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_read_block_bitmap_nowait); +EXPORT_SYMBOL_FOR_EXT4_TEST(mb_set_bits); +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_fc_init_inode); +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_mb_mark_context); #endif diff --git a/fs/ext4/mballoc.h b/fs/ext4/mballoc.h index 15a049f05d04..b32e03e7ae8d 100644 --- a/fs/ext4/mballoc.h +++ b/fs/ext4/mballoc.h @@ -270,4 +270,34 @@ ext4_mballoc_query_range( ext4_mballoc_query_range_fn formatter, void *priv); +#if IS_ENABLED(CONFIG_EXT4_KUNIT_TESTS) +extern void mb_clear_bits_test(void *bm, int cur, int len); +extern int ext4_mb_mark_context(handle_t *handle, + struct super_block *sb, bool state, + ext4_group_t group, ext4_grpblk_t blkoff, + ext4_grpblk_t len, int flags, + ext4_grpblk_t *ret_changed); +extern ext4_fsblk_t +ext4_mb_new_blocks_simple_test(struct ext4_allocation_request *ar, + int *errp); +extern int mb_find_next_zero_bit_test(void *addr, int max, int start); +extern int mb_find_next_bit_test(void *addr, int max, int start); +extern void mb_clear_bit_test(int bit, void *addr); +extern int mb_test_bit_test(int bit, void *addr); +extern int +ext4_mb_mark_diskspace_used_test(struct ext4_allocation_context *ac, + handle_t *handle); +extern int mb_mark_used_test(struct ext4_buddy *e4b, + struct ext4_free_extent *ex); +extern void ext4_mb_generate_buddy_test(struct super_block *sb, + void *buddy, void *bitmap, ext4_group_t group, + struct ext4_group_info *grp); +extern int ext4_mb_load_buddy_test(struct super_block *sb, + ext4_group_t group, struct ext4_buddy *e4b); +extern void ext4_mb_unload_buddy_test(struct ext4_buddy *e4b); +extern void mb_free_blocks_test(struct inode *inode, + struct ext4_buddy *e4b, int first, int count); +extern void ext4_free_blocks_simple_test(struct inode *inode, + ext4_fsblk_t block, unsigned long count); +#endif #endif -- 2.34.1 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH -next 1/8] ext4: fix mballoc-test.c is not compiled when EXT4_KUNIT_TESTS=M 2026-03-10 13:04 ` [PATCH -next 1/8] ext4: fix mballoc-test.c is not compiled when EXT4_KUNIT_TESTS=M Ye Bin @ 2026-03-11 2:44 ` kernel test robot 2026-03-11 3:26 ` kernel test robot 1 sibling, 0 replies; 21+ messages in thread From: kernel test robot @ 2026-03-11 2:44 UTC (permalink / raw) To: Ye Bin, tytso, adilger.kernel, linux-ext4; +Cc: oe-kbuild-all, jack Hi Ye, kernel test robot noticed the following build warnings: [auto build test WARNING on next-20260309] url: https://github.com/intel-lab-lkp/linux/commits/Ye-Bin/ext4-fix-mballoc-test-c-is-not-compiled-when-EXT4_KUNIT_TESTS-M/20260310-225016 base: next-20260309 patch link: https://lore.kernel.org/r/20260310130412.3156753-2-yebin%40huaweicloud.com patch subject: [PATCH -next 1/8] ext4: fix mballoc-test.c is not compiled when EXT4_KUNIT_TESTS=M config: sh-defconfig (https://download.01.org/0day-ci/archive/20260311/202603111026.Utt3pe7W-lkp@intel.com/config) compiler: sh4-linux-gcc (GCC) 15.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260311/202603111026.Utt3pe7W-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202603111026.Utt3pe7W-lkp@intel.com/ All warnings (new ones prefixed by >>): >> fs/ext4/mballoc.c:4088:1: warning: no previous prototype for 'ext4_mb_mark_context' [-Wmissing-prototypes] 4088 | ext4_mb_mark_context(handle_t *handle, struct super_block *sb, bool state, | ^~~~~~~~~~~~~~~~~~~~ vim +/ext4_mb_mark_context +4088 fs/ext4/mballoc.c c9de560ded61faa Alex Tomas 2008-01-29 4084 c431d3867e0a825 Kemeng Shi 2023-09-29 4085 #define EXT4_MB_BITMAP_MARKED_CHECK 0x0001 c431d3867e0a825 Kemeng Shi 2023-09-29 4086 #define EXT4_MB_SYNC_UPDATE 0x0002 74bd22ec0285256 Ye Bin 2026-03-10 4087 int c431d3867e0a825 Kemeng Shi 2023-09-29 @4088 ext4_mb_mark_context(handle_t *handle, struct super_block *sb, bool state, c431d3867e0a825 Kemeng Shi 2023-09-29 4089 ext4_group_t group, ext4_grpblk_t blkoff, c431d3867e0a825 Kemeng Shi 2023-09-29 4090 ext4_grpblk_t len, int flags, ext4_grpblk_t *ret_changed) f9e2d95a4532185 Kemeng Shi 2023-09-29 4091 { f9e2d95a4532185 Kemeng Shi 2023-09-29 4092 struct ext4_sb_info *sbi = EXT4_SB(sb); f9e2d95a4532185 Kemeng Shi 2023-09-29 4093 struct buffer_head *bitmap_bh = NULL; f9e2d95a4532185 Kemeng Shi 2023-09-29 4094 struct ext4_group_desc *gdp; f9e2d95a4532185 Kemeng Shi 2023-09-29 4095 struct buffer_head *gdp_bh; f9e2d95a4532185 Kemeng Shi 2023-09-29 4096 int err; c431d3867e0a825 Kemeng Shi 2023-09-29 4097 unsigned int i, already, changed = len; bdefd689b7ff0ea Kemeng Shi 2023-09-29 4098 bdefd689b7ff0ea Kemeng Shi 2023-09-29 4099 KUNIT_STATIC_STUB_REDIRECT(ext4_mb_mark_context, bdefd689b7ff0ea Kemeng Shi 2023-09-29 4100 handle, sb, state, group, blkoff, len, bdefd689b7ff0ea Kemeng Shi 2023-09-29 4101 flags, ret_changed); f9e2d95a4532185 Kemeng Shi 2023-09-29 4102 c431d3867e0a825 Kemeng Shi 2023-09-29 4103 if (ret_changed) c431d3867e0a825 Kemeng Shi 2023-09-29 4104 *ret_changed = 0; f9e2d95a4532185 Kemeng Shi 2023-09-29 4105 bitmap_bh = ext4_read_block_bitmap(sb, group); f9e2d95a4532185 Kemeng Shi 2023-09-29 4106 if (IS_ERR(bitmap_bh)) f9e2d95a4532185 Kemeng Shi 2023-09-29 4107 return PTR_ERR(bitmap_bh); f9e2d95a4532185 Kemeng Shi 2023-09-29 4108 c431d3867e0a825 Kemeng Shi 2023-09-29 4109 if (handle) { c431d3867e0a825 Kemeng Shi 2023-09-29 4110 BUFFER_TRACE(bitmap_bh, "getting write access"); c431d3867e0a825 Kemeng Shi 2023-09-29 4111 err = ext4_journal_get_write_access(handle, sb, bitmap_bh, c431d3867e0a825 Kemeng Shi 2023-09-29 4112 EXT4_JTR_NONE); c431d3867e0a825 Kemeng Shi 2023-09-29 4113 if (err) c431d3867e0a825 Kemeng Shi 2023-09-29 4114 goto out_err; c431d3867e0a825 Kemeng Shi 2023-09-29 4115 } c431d3867e0a825 Kemeng Shi 2023-09-29 4116 f9e2d95a4532185 Kemeng Shi 2023-09-29 4117 err = -EIO; f9e2d95a4532185 Kemeng Shi 2023-09-29 4118 gdp = ext4_get_group_desc(sb, group, &gdp_bh); f9e2d95a4532185 Kemeng Shi 2023-09-29 4119 if (!gdp) f9e2d95a4532185 Kemeng Shi 2023-09-29 4120 goto out_err; f9e2d95a4532185 Kemeng Shi 2023-09-29 4121 c431d3867e0a825 Kemeng Shi 2023-09-29 4122 if (handle) { c431d3867e0a825 Kemeng Shi 2023-09-29 4123 BUFFER_TRACE(gdp_bh, "get_write_access"); c431d3867e0a825 Kemeng Shi 2023-09-29 4124 err = ext4_journal_get_write_access(handle, sb, gdp_bh, c431d3867e0a825 Kemeng Shi 2023-09-29 4125 EXT4_JTR_NONE); c431d3867e0a825 Kemeng Shi 2023-09-29 4126 if (err) c431d3867e0a825 Kemeng Shi 2023-09-29 4127 goto out_err; c431d3867e0a825 Kemeng Shi 2023-09-29 4128 } c431d3867e0a825 Kemeng Shi 2023-09-29 4129 f9e2d95a4532185 Kemeng Shi 2023-09-29 4130 ext4_lock_group(sb, group); f9e2d95a4532185 Kemeng Shi 2023-09-29 4131 if (ext4_has_group_desc_csum(sb) && f9e2d95a4532185 Kemeng Shi 2023-09-29 4132 (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT))) { f9e2d95a4532185 Kemeng Shi 2023-09-29 4133 gdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT); f9e2d95a4532185 Kemeng Shi 2023-09-29 4134 ext4_free_group_clusters_set(sb, gdp, f9e2d95a4532185 Kemeng Shi 2023-09-29 4135 ext4_free_clusters_after_init(sb, group, gdp)); f9e2d95a4532185 Kemeng Shi 2023-09-29 4136 } f9e2d95a4532185 Kemeng Shi 2023-09-29 4137 c431d3867e0a825 Kemeng Shi 2023-09-29 4138 if (flags & EXT4_MB_BITMAP_MARKED_CHECK) { f9e2d95a4532185 Kemeng Shi 2023-09-29 4139 already = 0; f9e2d95a4532185 Kemeng Shi 2023-09-29 4140 for (i = 0; i < len; i++) f9e2d95a4532185 Kemeng Shi 2023-09-29 4141 if (mb_test_bit(blkoff + i, bitmap_bh->b_data) == f9e2d95a4532185 Kemeng Shi 2023-09-29 4142 state) f9e2d95a4532185 Kemeng Shi 2023-09-29 4143 already++; f9e2d95a4532185 Kemeng Shi 2023-09-29 4144 changed = len - already; c431d3867e0a825 Kemeng Shi 2023-09-29 4145 } f9e2d95a4532185 Kemeng Shi 2023-09-29 4146 f9e2d95a4532185 Kemeng Shi 2023-09-29 4147 if (state) { f9e2d95a4532185 Kemeng Shi 2023-09-29 4148 mb_set_bits(bitmap_bh->b_data, blkoff, len); f9e2d95a4532185 Kemeng Shi 2023-09-29 4149 ext4_free_group_clusters_set(sb, gdp, f9e2d95a4532185 Kemeng Shi 2023-09-29 4150 ext4_free_group_clusters(sb, gdp) - changed); f9e2d95a4532185 Kemeng Shi 2023-09-29 4151 } else { f9e2d95a4532185 Kemeng Shi 2023-09-29 4152 mb_clear_bits(bitmap_bh->b_data, blkoff, len); f9e2d95a4532185 Kemeng Shi 2023-09-29 4153 ext4_free_group_clusters_set(sb, gdp, f9e2d95a4532185 Kemeng Shi 2023-09-29 4154 ext4_free_group_clusters(sb, gdp) + changed); f9e2d95a4532185 Kemeng Shi 2023-09-29 4155 } f9e2d95a4532185 Kemeng Shi 2023-09-29 4156 f9e2d95a4532185 Kemeng Shi 2023-09-29 4157 ext4_block_bitmap_csum_set(sb, gdp, bitmap_bh); f9e2d95a4532185 Kemeng Shi 2023-09-29 4158 ext4_group_desc_csum_set(sb, group, gdp); f9e2d95a4532185 Kemeng Shi 2023-09-29 4159 ext4_unlock_group(sb, group); c431d3867e0a825 Kemeng Shi 2023-09-29 4160 if (ret_changed) c431d3867e0a825 Kemeng Shi 2023-09-29 4161 *ret_changed = changed; f9e2d95a4532185 Kemeng Shi 2023-09-29 4162 f9e2d95a4532185 Kemeng Shi 2023-09-29 4163 if (sbi->s_log_groups_per_flex) { f9e2d95a4532185 Kemeng Shi 2023-09-29 4164 ext4_group_t flex_group = ext4_flex_group(sbi, group); f9e2d95a4532185 Kemeng Shi 2023-09-29 4165 struct flex_groups *fg = sbi_array_rcu_deref(sbi, f9e2d95a4532185 Kemeng Shi 2023-09-29 4166 s_flex_groups, flex_group); f9e2d95a4532185 Kemeng Shi 2023-09-29 4167 f9e2d95a4532185 Kemeng Shi 2023-09-29 4168 if (state) f9e2d95a4532185 Kemeng Shi 2023-09-29 4169 atomic64_sub(changed, &fg->free_clusters); f9e2d95a4532185 Kemeng Shi 2023-09-29 4170 else f9e2d95a4532185 Kemeng Shi 2023-09-29 4171 atomic64_add(changed, &fg->free_clusters); f9e2d95a4532185 Kemeng Shi 2023-09-29 4172 } f9e2d95a4532185 Kemeng Shi 2023-09-29 4173 c431d3867e0a825 Kemeng Shi 2023-09-29 4174 err = ext4_handle_dirty_metadata(handle, NULL, bitmap_bh); f9e2d95a4532185 Kemeng Shi 2023-09-29 4175 if (err) f9e2d95a4532185 Kemeng Shi 2023-09-29 4176 goto out_err; c431d3867e0a825 Kemeng Shi 2023-09-29 4177 err = ext4_handle_dirty_metadata(handle, NULL, gdp_bh); f9e2d95a4532185 Kemeng Shi 2023-09-29 4178 if (err) f9e2d95a4532185 Kemeng Shi 2023-09-29 4179 goto out_err; f9e2d95a4532185 Kemeng Shi 2023-09-29 4180 c431d3867e0a825 Kemeng Shi 2023-09-29 4181 if (flags & EXT4_MB_SYNC_UPDATE) { f9e2d95a4532185 Kemeng Shi 2023-09-29 4182 sync_dirty_buffer(bitmap_bh); f9e2d95a4532185 Kemeng Shi 2023-09-29 4183 sync_dirty_buffer(gdp_bh); c431d3867e0a825 Kemeng Shi 2023-09-29 4184 } f9e2d95a4532185 Kemeng Shi 2023-09-29 4185 f9e2d95a4532185 Kemeng Shi 2023-09-29 4186 out_err: f9e2d95a4532185 Kemeng Shi 2023-09-29 4187 brelse(bitmap_bh); f9e2d95a4532185 Kemeng Shi 2023-09-29 4188 return err; f9e2d95a4532185 Kemeng Shi 2023-09-29 4189 } c9de560ded61faa Alex Tomas 2008-01-29 4190 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH -next 1/8] ext4: fix mballoc-test.c is not compiled when EXT4_KUNIT_TESTS=M 2026-03-10 13:04 ` [PATCH -next 1/8] ext4: fix mballoc-test.c is not compiled when EXT4_KUNIT_TESTS=M Ye Bin 2026-03-11 2:44 ` kernel test robot @ 2026-03-11 3:26 ` kernel test robot 1 sibling, 0 replies; 21+ messages in thread From: kernel test robot @ 2026-03-11 3:26 UTC (permalink / raw) To: Ye Bin, tytso, adilger.kernel, linux-ext4; +Cc: llvm, oe-kbuild-all, jack Hi Ye, kernel test robot noticed the following build warnings: [auto build test WARNING on next-20260309] url: https://github.com/intel-lab-lkp/linux/commits/Ye-Bin/ext4-fix-mballoc-test-c-is-not-compiled-when-EXT4_KUNIT_TESTS-M/20260310-225016 base: next-20260309 patch link: https://lore.kernel.org/r/20260310130412.3156753-2-yebin%40huaweicloud.com patch subject: [PATCH -next 1/8] ext4: fix mballoc-test.c is not compiled when EXT4_KUNIT_TESTS=M config: um-defconfig (https://download.01.org/0day-ci/archive/20260311/202603111133.Ll6eI2uT-lkp@intel.com/config) compiler: clang version 23.0.0git (https://github.com/llvm/llvm-project 7d47b695929cc7f85eeb0f87d0189adc04c1c629) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260311/202603111133.Ll6eI2uT-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202603111133.Ll6eI2uT-lkp@intel.com/ All warnings (new ones prefixed by >>): >> fs/ext4/mballoc.c:4088:1: warning: no previous prototype for function 'ext4_mb_mark_context' [-Wmissing-prototypes] 4088 | ext4_mb_mark_context(handle_t *handle, struct super_block *sb, bool state, | ^ fs/ext4/mballoc.c:4087:1: note: declare 'static' if the function is not intended to be used outside of this translation unit 4087 | int | ^ | static 1 warning generated. vim +/ext4_mb_mark_context +4088 fs/ext4/mballoc.c c9de560ded61faa Alex Tomas 2008-01-29 4084 c431d3867e0a825 Kemeng Shi 2023-09-29 4085 #define EXT4_MB_BITMAP_MARKED_CHECK 0x0001 c431d3867e0a825 Kemeng Shi 2023-09-29 4086 #define EXT4_MB_SYNC_UPDATE 0x0002 74bd22ec0285256 Ye Bin 2026-03-10 4087 int c431d3867e0a825 Kemeng Shi 2023-09-29 @4088 ext4_mb_mark_context(handle_t *handle, struct super_block *sb, bool state, c431d3867e0a825 Kemeng Shi 2023-09-29 4089 ext4_group_t group, ext4_grpblk_t blkoff, c431d3867e0a825 Kemeng Shi 2023-09-29 4090 ext4_grpblk_t len, int flags, ext4_grpblk_t *ret_changed) f9e2d95a4532185 Kemeng Shi 2023-09-29 4091 { f9e2d95a4532185 Kemeng Shi 2023-09-29 4092 struct ext4_sb_info *sbi = EXT4_SB(sb); f9e2d95a4532185 Kemeng Shi 2023-09-29 4093 struct buffer_head *bitmap_bh = NULL; f9e2d95a4532185 Kemeng Shi 2023-09-29 4094 struct ext4_group_desc *gdp; f9e2d95a4532185 Kemeng Shi 2023-09-29 4095 struct buffer_head *gdp_bh; f9e2d95a4532185 Kemeng Shi 2023-09-29 4096 int err; c431d3867e0a825 Kemeng Shi 2023-09-29 4097 unsigned int i, already, changed = len; bdefd689b7ff0ea Kemeng Shi 2023-09-29 4098 bdefd689b7ff0ea Kemeng Shi 2023-09-29 4099 KUNIT_STATIC_STUB_REDIRECT(ext4_mb_mark_context, bdefd689b7ff0ea Kemeng Shi 2023-09-29 4100 handle, sb, state, group, blkoff, len, bdefd689b7ff0ea Kemeng Shi 2023-09-29 4101 flags, ret_changed); f9e2d95a4532185 Kemeng Shi 2023-09-29 4102 c431d3867e0a825 Kemeng Shi 2023-09-29 4103 if (ret_changed) c431d3867e0a825 Kemeng Shi 2023-09-29 4104 *ret_changed = 0; f9e2d95a4532185 Kemeng Shi 2023-09-29 4105 bitmap_bh = ext4_read_block_bitmap(sb, group); f9e2d95a4532185 Kemeng Shi 2023-09-29 4106 if (IS_ERR(bitmap_bh)) f9e2d95a4532185 Kemeng Shi 2023-09-29 4107 return PTR_ERR(bitmap_bh); f9e2d95a4532185 Kemeng Shi 2023-09-29 4108 c431d3867e0a825 Kemeng Shi 2023-09-29 4109 if (handle) { c431d3867e0a825 Kemeng Shi 2023-09-29 4110 BUFFER_TRACE(bitmap_bh, "getting write access"); c431d3867e0a825 Kemeng Shi 2023-09-29 4111 err = ext4_journal_get_write_access(handle, sb, bitmap_bh, c431d3867e0a825 Kemeng Shi 2023-09-29 4112 EXT4_JTR_NONE); c431d3867e0a825 Kemeng Shi 2023-09-29 4113 if (err) c431d3867e0a825 Kemeng Shi 2023-09-29 4114 goto out_err; c431d3867e0a825 Kemeng Shi 2023-09-29 4115 } c431d3867e0a825 Kemeng Shi 2023-09-29 4116 f9e2d95a4532185 Kemeng Shi 2023-09-29 4117 err = -EIO; f9e2d95a4532185 Kemeng Shi 2023-09-29 4118 gdp = ext4_get_group_desc(sb, group, &gdp_bh); f9e2d95a4532185 Kemeng Shi 2023-09-29 4119 if (!gdp) f9e2d95a4532185 Kemeng Shi 2023-09-29 4120 goto out_err; f9e2d95a4532185 Kemeng Shi 2023-09-29 4121 c431d3867e0a825 Kemeng Shi 2023-09-29 4122 if (handle) { c431d3867e0a825 Kemeng Shi 2023-09-29 4123 BUFFER_TRACE(gdp_bh, "get_write_access"); c431d3867e0a825 Kemeng Shi 2023-09-29 4124 err = ext4_journal_get_write_access(handle, sb, gdp_bh, c431d3867e0a825 Kemeng Shi 2023-09-29 4125 EXT4_JTR_NONE); c431d3867e0a825 Kemeng Shi 2023-09-29 4126 if (err) c431d3867e0a825 Kemeng Shi 2023-09-29 4127 goto out_err; c431d3867e0a825 Kemeng Shi 2023-09-29 4128 } c431d3867e0a825 Kemeng Shi 2023-09-29 4129 f9e2d95a4532185 Kemeng Shi 2023-09-29 4130 ext4_lock_group(sb, group); f9e2d95a4532185 Kemeng Shi 2023-09-29 4131 if (ext4_has_group_desc_csum(sb) && f9e2d95a4532185 Kemeng Shi 2023-09-29 4132 (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT))) { f9e2d95a4532185 Kemeng Shi 2023-09-29 4133 gdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT); f9e2d95a4532185 Kemeng Shi 2023-09-29 4134 ext4_free_group_clusters_set(sb, gdp, f9e2d95a4532185 Kemeng Shi 2023-09-29 4135 ext4_free_clusters_after_init(sb, group, gdp)); f9e2d95a4532185 Kemeng Shi 2023-09-29 4136 } f9e2d95a4532185 Kemeng Shi 2023-09-29 4137 c431d3867e0a825 Kemeng Shi 2023-09-29 4138 if (flags & EXT4_MB_BITMAP_MARKED_CHECK) { f9e2d95a4532185 Kemeng Shi 2023-09-29 4139 already = 0; f9e2d95a4532185 Kemeng Shi 2023-09-29 4140 for (i = 0; i < len; i++) f9e2d95a4532185 Kemeng Shi 2023-09-29 4141 if (mb_test_bit(blkoff + i, bitmap_bh->b_data) == f9e2d95a4532185 Kemeng Shi 2023-09-29 4142 state) f9e2d95a4532185 Kemeng Shi 2023-09-29 4143 already++; f9e2d95a4532185 Kemeng Shi 2023-09-29 4144 changed = len - already; c431d3867e0a825 Kemeng Shi 2023-09-29 4145 } f9e2d95a4532185 Kemeng Shi 2023-09-29 4146 f9e2d95a4532185 Kemeng Shi 2023-09-29 4147 if (state) { f9e2d95a4532185 Kemeng Shi 2023-09-29 4148 mb_set_bits(bitmap_bh->b_data, blkoff, len); f9e2d95a4532185 Kemeng Shi 2023-09-29 4149 ext4_free_group_clusters_set(sb, gdp, f9e2d95a4532185 Kemeng Shi 2023-09-29 4150 ext4_free_group_clusters(sb, gdp) - changed); f9e2d95a4532185 Kemeng Shi 2023-09-29 4151 } else { f9e2d95a4532185 Kemeng Shi 2023-09-29 4152 mb_clear_bits(bitmap_bh->b_data, blkoff, len); f9e2d95a4532185 Kemeng Shi 2023-09-29 4153 ext4_free_group_clusters_set(sb, gdp, f9e2d95a4532185 Kemeng Shi 2023-09-29 4154 ext4_free_group_clusters(sb, gdp) + changed); f9e2d95a4532185 Kemeng Shi 2023-09-29 4155 } f9e2d95a4532185 Kemeng Shi 2023-09-29 4156 f9e2d95a4532185 Kemeng Shi 2023-09-29 4157 ext4_block_bitmap_csum_set(sb, gdp, bitmap_bh); f9e2d95a4532185 Kemeng Shi 2023-09-29 4158 ext4_group_desc_csum_set(sb, group, gdp); f9e2d95a4532185 Kemeng Shi 2023-09-29 4159 ext4_unlock_group(sb, group); c431d3867e0a825 Kemeng Shi 2023-09-29 4160 if (ret_changed) c431d3867e0a825 Kemeng Shi 2023-09-29 4161 *ret_changed = changed; f9e2d95a4532185 Kemeng Shi 2023-09-29 4162 f9e2d95a4532185 Kemeng Shi 2023-09-29 4163 if (sbi->s_log_groups_per_flex) { f9e2d95a4532185 Kemeng Shi 2023-09-29 4164 ext4_group_t flex_group = ext4_flex_group(sbi, group); f9e2d95a4532185 Kemeng Shi 2023-09-29 4165 struct flex_groups *fg = sbi_array_rcu_deref(sbi, f9e2d95a4532185 Kemeng Shi 2023-09-29 4166 s_flex_groups, flex_group); f9e2d95a4532185 Kemeng Shi 2023-09-29 4167 f9e2d95a4532185 Kemeng Shi 2023-09-29 4168 if (state) f9e2d95a4532185 Kemeng Shi 2023-09-29 4169 atomic64_sub(changed, &fg->free_clusters); f9e2d95a4532185 Kemeng Shi 2023-09-29 4170 else f9e2d95a4532185 Kemeng Shi 2023-09-29 4171 atomic64_add(changed, &fg->free_clusters); f9e2d95a4532185 Kemeng Shi 2023-09-29 4172 } f9e2d95a4532185 Kemeng Shi 2023-09-29 4173 c431d3867e0a825 Kemeng Shi 2023-09-29 4174 err = ext4_handle_dirty_metadata(handle, NULL, bitmap_bh); f9e2d95a4532185 Kemeng Shi 2023-09-29 4175 if (err) f9e2d95a4532185 Kemeng Shi 2023-09-29 4176 goto out_err; c431d3867e0a825 Kemeng Shi 2023-09-29 4177 err = ext4_handle_dirty_metadata(handle, NULL, gdp_bh); f9e2d95a4532185 Kemeng Shi 2023-09-29 4178 if (err) f9e2d95a4532185 Kemeng Shi 2023-09-29 4179 goto out_err; f9e2d95a4532185 Kemeng Shi 2023-09-29 4180 c431d3867e0a825 Kemeng Shi 2023-09-29 4181 if (flags & EXT4_MB_SYNC_UPDATE) { f9e2d95a4532185 Kemeng Shi 2023-09-29 4182 sync_dirty_buffer(bitmap_bh); f9e2d95a4532185 Kemeng Shi 2023-09-29 4183 sync_dirty_buffer(gdp_bh); c431d3867e0a825 Kemeng Shi 2023-09-29 4184 } f9e2d95a4532185 Kemeng Shi 2023-09-29 4185 f9e2d95a4532185 Kemeng Shi 2023-09-29 4186 out_err: f9e2d95a4532185 Kemeng Shi 2023-09-29 4187 brelse(bitmap_bh); f9e2d95a4532185 Kemeng Shi 2023-09-29 4188 return err; f9e2d95a4532185 Kemeng Shi 2023-09-29 4189 } c9de560ded61faa Alex Tomas 2008-01-29 4190 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki ^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH -next 2/8] ext4: introduce EXPORT_SYMBOL_FOR_EXT4_TEST() helper 2026-03-10 13:04 [PATCH -next 0/8] Fix some issues about ext4-test Ye Bin 2026-03-10 13:04 ` [PATCH -next 1/8] ext4: fix mballoc-test.c is not compiled when EXT4_KUNIT_TESTS=M Ye Bin @ 2026-03-10 13:04 ` Ye Bin 2026-03-10 13:04 ` [PATCH -next 3/8] ext4: fix extents-test.c is not compiled when EXT4_KUNIT_TESTS=M Ye Bin ` (6 subsequent siblings) 8 siblings, 0 replies; 21+ messages in thread From: Ye Bin @ 2026-03-10 13:04 UTC (permalink / raw) To: tytso, adilger.kernel, linux-ext4; +Cc: jack From: Ye Bin <yebin10@huawei.com> Introduce EXPORT_SYMBOL_FOR_EXT4_TEST() helper for kuint test. Signed-off-by: Ye Bin <yebin10@huawei.com> --- fs/ext4/ext4.h | 5 +++++ fs/ext4/mballoc.c | 3 --- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 4cb2345339ba..8bf2a2ac4787 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -3945,6 +3945,11 @@ static inline bool ext4_inode_can_atomic_write(struct inode *inode) extern int ext4_block_write_begin(handle_t *handle, struct folio *folio, loff_t pos, unsigned len, get_block_t *get_block); + +#if IS_ENABLED(CONFIG_EXT4_KUNIT_TESTS) +#define EXPORT_SYMBOL_FOR_EXT4_TEST(sym) \ + EXPORT_SYMBOL_FOR_MODULES(sym, "ext4-test") +#endif #endif /* __KERNEL__ */ #endif /* _EXT4_H */ diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 842a604ae5db..97b3f0e4c80b 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -7193,9 +7193,6 @@ ext4_mballoc_query_range( } #if IS_ENABLED(CONFIG_EXT4_KUNIT_TESTS) -#define EXPORT_SYMBOL_FOR_EXT4_TEST(sym) \ - EXPORT_SYMBOL_FOR_MODULES(sym, "ext4-test") - void mb_clear_bits_test(void *bm, int cur, int len) { mb_clear_bits(bm, cur, len); -- 2.34.1 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH -next 3/8] ext4: fix extents-test.c is not compiled when EXT4_KUNIT_TESTS=M 2026-03-10 13:04 [PATCH -next 0/8] Fix some issues about ext4-test Ye Bin 2026-03-10 13:04 ` [PATCH -next 1/8] ext4: fix mballoc-test.c is not compiled when EXT4_KUNIT_TESTS=M Ye Bin 2026-03-10 13:04 ` [PATCH -next 2/8] ext4: introduce EXPORT_SYMBOL_FOR_EXT4_TEST() helper Ye Bin @ 2026-03-10 13:04 ` Ye Bin 2026-03-11 6:32 ` kernel test robot 2026-03-10 13:04 ` [PATCH -next 4/8] ext4: fix miss unlock 'sb->s_umount' in extents_kunit_init() Ye Bin ` (5 subsequent siblings) 8 siblings, 1 reply; 21+ messages in thread From: Ye Bin @ 2026-03-10 13:04 UTC (permalink / raw) To: tytso, adilger.kernel, linux-ext4; +Cc: jack From: Ye Bin <yebin10@huawei.com> Now, only EXT4_KUNIT_TESTS=Y testcase will be compiled in 'extents.c'. To solve this issue, the ext4 test code needs to be decoupled. The 'extents-test' module is compiled into 'ext4-test' module. Fixes: cb1e0c1d1fad ("ext4: kunit tests for extent splitting and conversion") Signed-off-by: Ye Bin <yebin10@huawei.com> --- fs/ext4/Makefile | 3 ++- fs/ext4/ext4_extents.h | 12 ++++++++++++ fs/ext4/extents-test.c | 8 ++++---- fs/ext4/extents.c | 38 ++++++++++++++++++++++++++++++++------ 4 files changed, 50 insertions(+), 11 deletions(-) diff --git a/fs/ext4/Makefile b/fs/ext4/Makefile index d836c3fe311b..3baee4e7c1cf 100644 --- a/fs/ext4/Makefile +++ b/fs/ext4/Makefile @@ -14,7 +14,8 @@ ext4-y := balloc.o bitmap.o block_validity.o dir.o ext4_jbd2.o extents.o \ ext4-$(CONFIG_EXT4_FS_POSIX_ACL) += acl.o ext4-$(CONFIG_EXT4_FS_SECURITY) += xattr_security.o -ext4-test-objs += inode-test.o mballoc-test.o +ext4-test-objs += inode-test.o mballoc-test.o \ + extents-test.o obj-$(CONFIG_EXT4_KUNIT_TESTS) += ext4-test.o ext4-$(CONFIG_FS_VERITY) += verity.o ext4-$(CONFIG_FS_ENCRYPTION) += crypto.o diff --git a/fs/ext4/ext4_extents.h b/fs/ext4/ext4_extents.h index c484125d963f..8318e8d97074 100644 --- a/fs/ext4/ext4_extents.h +++ b/fs/ext4/ext4_extents.h @@ -264,5 +264,17 @@ static inline void ext4_idx_store_pblock(struct ext4_extent_idx *ix, 0xffff); } +#if IS_ENABLED(CONFIG_EXT4_KUNIT_TESTS) +extern int ext4_ext_space_root_idx_test(struct inode *inode, int check); +extern struct ext4_ext_path *ext4_split_convert_extents_test( + handle_t *handle, struct inode *inode, + struct ext4_map_blocks *map, + struct ext4_ext_path *path, + int flags, unsigned int *allocated); +extern int __ext4_ext_dirty(const char *where, unsigned int line, + handle_t *handle, struct inode *inode, + struct ext4_ext_path *path); +extern int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex); +#endif #endif /* _EXT4_EXTENTS */ diff --git a/fs/ext4/extents-test.c b/fs/ext4/extents-test.c index 7c4690eb7dad..9e055f399167 100644 --- a/fs/ext4/extents-test.c +++ b/fs/ext4/extents-test.c @@ -280,8 +280,8 @@ static int extents_kunit_init(struct kunit *test) eh->eh_depth = 0; eh->eh_entries = cpu_to_le16(1); eh->eh_magic = EXT4_EXT_MAGIC; - eh->eh_max = - cpu_to_le16(ext4_ext_space_root_idx(&k_ctx.k_ei->vfs_inode, 0)); + eh->eh_max = cpu_to_le16(ext4_ext_space_root_idx_test( + &k_ctx.k_ei->vfs_inode, 0)); eh->eh_generation = 0; /* @@ -384,8 +384,8 @@ static void test_split_convert(struct kunit *test) switch (param->type) { case TEST_SPLIT_CONVERT: - path = ext4_split_convert_extents(NULL, inode, &map, path, - param->split_flags, NULL); + path = ext4_split_convert_extents_test(NULL, inode, &map, + path, param->split_flags, NULL); break; case TEST_CREATE_BLOCKS: ext4_map_create_blocks_helper(test, inode, &map, param->split_flags); diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index ae3804f36535..0942d2ed4603 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -184,9 +184,9 @@ static int ext4_ext_get_access(handle_t *handle, struct inode *inode, * - ENOMEM * - EIO */ -static int __ext4_ext_dirty(const char *where, unsigned int line, - handle_t *handle, struct inode *inode, - struct ext4_ext_path *path) +int __ext4_ext_dirty(const char *where, unsigned int line, + handle_t *handle, struct inode *inode, + struct ext4_ext_path *path) { int err; @@ -3144,7 +3144,7 @@ static void ext4_zeroout_es(struct inode *inode, struct ext4_extent *ex) } /* FIXME!! we need to try to merge to left or right after zero-out */ -static int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex) +int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex) { ext4_fsblk_t ee_pblock; unsigned int ee_len; @@ -6238,6 +6238,32 @@ int ext4_ext_clear_bb(struct inode *inode) return 0; } -#ifdef CONFIG_EXT4_KUNIT_TESTS -#include "extents-test.c" +#if IS_ENABLED(CONFIG_EXT4_KUNIT_TESTS) +int ext4_ext_space_root_idx_test(struct inode *inode, int check) +{ + return ext4_ext_space_root_idx(inode, check); +} +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_ext_space_root_idx_test); + +struct ext4_ext_path *ext4_split_convert_extents_test(handle_t *handle, + struct inode *inode, struct ext4_map_blocks *map, + struct ext4_ext_path *path, int flags, + unsigned int *allocated) +{ + return ext4_split_convert_extents(handle, inode, map, path, + flags, allocated); +} +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_split_convert_extents_test); + +EXPORT_SYMBOL_FOR_EXT4_TEST(__ext4_ext_dirty); +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_ext_zeroout); +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_register_shrinker); +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_map_create_blocks); +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_init_tree); +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_lookup_extent); +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_insert_extent); +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_ext_insert_extent); +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_find_extent); +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_issue_zeroout); +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_map_query_blocks); #endif -- 2.34.1 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH -next 3/8] ext4: fix extents-test.c is not compiled when EXT4_KUNIT_TESTS=M 2026-03-10 13:04 ` [PATCH -next 3/8] ext4: fix extents-test.c is not compiled when EXT4_KUNIT_TESTS=M Ye Bin @ 2026-03-11 6:32 ` kernel test robot 0 siblings, 0 replies; 21+ messages in thread From: kernel test robot @ 2026-03-11 6:32 UTC (permalink / raw) To: Ye Bin, tytso, adilger.kernel, linux-ext4; +Cc: oe-kbuild-all, jack Hi Ye, kernel test robot noticed the following build warnings: [auto build test WARNING on next-20260309] url: https://github.com/intel-lab-lkp/linux/commits/Ye-Bin/ext4-fix-mballoc-test-c-is-not-compiled-when-EXT4_KUNIT_TESTS-M/20260310-225016 base: next-20260309 patch link: https://lore.kernel.org/r/20260310130412.3156753-4-yebin%40huaweicloud.com patch subject: [PATCH -next 3/8] ext4: fix extents-test.c is not compiled when EXT4_KUNIT_TESTS=M config: sh-defconfig (https://download.01.org/0day-ci/archive/20260311/202603111416.j2HqVIhj-lkp@intel.com/config) compiler: sh4-linux-gcc (GCC) 15.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260311/202603111416.j2HqVIhj-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202603111416.j2HqVIhj-lkp@intel.com/ All warnings (new ones prefixed by >>): >> fs/ext4/extents.c:187:5: warning: no previous prototype for '__ext4_ext_dirty' [-Wmissing-prototypes] 187 | int __ext4_ext_dirty(const char *where, unsigned int line, | ^~~~~~~~~~~~~~~~ >> fs/ext4/extents.c:3147:5: warning: no previous prototype for 'ext4_ext_zeroout' [-Wmissing-prototypes] 3147 | int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex) | ^~~~~~~~~~~~~~~~ vim +/__ext4_ext_dirty +187 fs/ext4/extents.c 180 181 /* 182 * could return: 183 * - EROFS 184 * - ENOMEM 185 * - EIO 186 */ > 187 int __ext4_ext_dirty(const char *where, unsigned int line, 188 handle_t *handle, struct inode *inode, 189 struct ext4_ext_path *path) 190 { 191 int err; 192 193 KUNIT_STATIC_STUB_REDIRECT(__ext4_ext_dirty, where, line, handle, inode, 194 path); 195 196 WARN_ON(!rwsem_is_locked(&EXT4_I(inode)->i_data_sem)); 197 if (path->p_bh) { 198 ext4_extent_block_csum_set(inode, ext_block_hdr(path->p_bh)); 199 /* path points to block */ 200 err = __ext4_handle_dirty_metadata(where, line, handle, 201 inode, path->p_bh); 202 /* Extents updating done, re-set verified flag */ 203 if (!err) 204 set_buffer_verified(path->p_bh); 205 } else { 206 /* path points to leaf/index in inode body */ 207 err = ext4_mark_inode_dirty(handle, inode); 208 } 209 return err; 210 } 211 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki ^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH -next 4/8] ext4: fix miss unlock 'sb->s_umount' in extents_kunit_init() 2026-03-10 13:04 [PATCH -next 0/8] Fix some issues about ext4-test Ye Bin ` (2 preceding siblings ...) 2026-03-10 13:04 ` [PATCH -next 3/8] ext4: fix extents-test.c is not compiled when EXT4_KUNIT_TESTS=M Ye Bin @ 2026-03-10 13:04 ` Ye Bin 2026-03-13 11:32 ` Ritesh Harjani 2026-03-10 13:04 ` [PATCH -next 5/8] ext4: fix miss free super_block in extents_kunit_exit() Ye Bin ` (4 subsequent siblings) 8 siblings, 1 reply; 21+ messages in thread From: Ye Bin @ 2026-03-10 13:04 UTC (permalink / raw) To: tytso, adilger.kernel, linux-ext4; +Cc: jack From: Ye Bin <yebin10@huawei.com> There's warning as follows when do ext4 kunit test: WARNING: kunit_try_catch/15923 still has locks held! 7.0.0-rc3-next-20260309-00028-g73f965a1bbb1-dirty #281 Tainted: G E N 1 lock held by kunit_try_catch/15923: #0: ffff888139f860e0 (&type->s_umount_key#70/1){+.+.}-{4:4}, at: alloc_super.constprop.0+0x172/0xa90 Call Trace: <TASK> dump_stack_lvl+0x180/0x1b0 debug_check_no_locks_held+0xc8/0xd0 do_exit+0x1502/0x2b20 kthread+0x3a9/0x540 ret_from_fork+0xa76/0xdf0 ret_from_fork_asm+0x1a/0x30 As sget() will return 'sb' which holds 's->s_umount' lock. However, "extents-test" miss unlock this lock. So unlock 's->s_umount' in the end of extents_kunit_init(). Fixes: cb1e0c1d1fad ("ext4: kunit tests for extent splitting and conversion") Signed-off-by: Ye Bin <yebin10@huawei.com> --- fs/ext4/extents-test.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/ext4/extents-test.c b/fs/ext4/extents-test.c index 9e055f399167..5a5016ea1ecc 100644 --- a/fs/ext4/extents-test.c +++ b/fs/ext4/extents-test.c @@ -307,6 +307,8 @@ static int extents_kunit_init(struct kunit *test) kunit_activate_static_stub(test, ext4_ext_zeroout, ext4_ext_zeroout_stub); kunit_activate_static_stub(test, ext4_issue_zeroout, ext4_issue_zeroout_stub); + up_write(&sb->s_umount); + return 0; } -- 2.34.1 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH -next 4/8] ext4: fix miss unlock 'sb->s_umount' in extents_kunit_init() 2026-03-10 13:04 ` [PATCH -next 4/8] ext4: fix miss unlock 'sb->s_umount' in extents_kunit_init() Ye Bin @ 2026-03-13 11:32 ` Ritesh Harjani 0 siblings, 0 replies; 21+ messages in thread From: Ritesh Harjani @ 2026-03-13 11:32 UTC (permalink / raw) To: Ye Bin, tytso, adilger.kernel, linux-ext4; +Cc: jack Ye Bin <yebin@huaweicloud.com> writes: > From: Ye Bin <yebin10@huawei.com> > > There's warning as follows when do ext4 kunit test: > WARNING: kunit_try_catch/15923 still has locks held! > 7.0.0-rc3-next-20260309-00028-g73f965a1bbb1-dirty #281 Tainted: G E N > 1 lock held by kunit_try_catch/15923: Strange lockdep didn't complaint this for me.. I had lockdep enabled in my config. > #0: ffff888139f860e0 (&type->s_umount_key#70/1){+.+.}-{4:4}, at: alloc_super.constprop.0+0x172/0xa90 > Call Trace: > <TASK> > dump_stack_lvl+0x180/0x1b0 > debug_check_no_locks_held+0xc8/0xd0 > do_exit+0x1502/0x2b20 > kthread+0x3a9/0x540 > ret_from_fork+0xa76/0xdf0 > ret_from_fork_asm+0x1a/0x30 > > As sget() will return 'sb' which holds 's->s_umount' lock. However, > "extents-test" miss unlock this lock. > So unlock 's->s_umount' in the end of extents_kunit_init(). > > Fixes: cb1e0c1d1fad ("ext4: kunit tests for extent splitting and conversion") > Signed-off-by: Ye Bin <yebin10@huawei.com> > --- > fs/ext4/extents-test.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/fs/ext4/extents-test.c b/fs/ext4/extents-test.c > index 9e055f399167..5a5016ea1ecc 100644 > --- a/fs/ext4/extents-test.c > +++ b/fs/ext4/extents-test.c > @@ -307,6 +307,8 @@ static int extents_kunit_init(struct kunit *test) > kunit_activate_static_stub(test, ext4_ext_zeroout, ext4_ext_zeroout_stub); > kunit_activate_static_stub(test, ext4_issue_zeroout, > ext4_issue_zeroout_stub); > + up_write(&sb->s_umount); > + Can we re-arrange these patches please? Let's bring the error handling fix first (I think i.e. patch-6 in this series) so that, s_umount lock also gets unlocked properly from the error handling paths as well. With that, I agree releasing the s_umount lock is the right thing to do here which is taken in: sget() alloc_super() down_write_nested(&s->s_umount, SINGLE_DEPTH_NESTING); So feel free to add: Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> -ritesh ^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH -next 5/8] ext4: fix miss free super_block in extents_kunit_exit() 2026-03-10 13:04 [PATCH -next 0/8] Fix some issues about ext4-test Ye Bin ` (3 preceding siblings ...) 2026-03-10 13:04 ` [PATCH -next 4/8] ext4: fix miss unlock 'sb->s_umount' in extents_kunit_init() Ye Bin @ 2026-03-10 13:04 ` Ye Bin 2026-03-13 12:03 ` Ritesh Harjani 2026-03-10 13:04 ` [PATCH -next 6/8] ext4: fix the error handling process in extents_kunit_init) Ye Bin ` (3 subsequent siblings) 8 siblings, 1 reply; 21+ messages in thread From: Ye Bin @ 2026-03-10 13:04 UTC (permalink / raw) To: tytso, adilger.kernel, linux-ext4; +Cc: jack From: Ye Bin <yebin10@huawei.com> There's issue as follows: ODEBUG: free active (active state 0) object: ffff88812f2d68a0 object type: percpu_counter hint: 0x0 <TASK> debug_check_no_obj_freed+0x3d9/0x4d0 kfree+0x2bb/0x6c0 extents_kunit_exit+0x65/0x90 [ext4_test] kunit_try_run_case_cleanup+0xbc/0x100 [kunit] kunit_generic_run_threadfn_adapter+0x89/0x100 [kunit] kthread+0x408/0x540 ret_from_fork+0xa76/0xdf0 ret_from_fork_asm+0x1a/0x30 The above issue was caused because the super_block cleanup process was not properly performed. Therefore, deactivate_super() is called in extents_kunit_exit() to cleanup the super_block. Fixes: cb1e0c1d1fad ("ext4: kunit tests for extent splitting and conversion") Signed-off-by: Ye Bin <yebin10@huawei.com> --- fs/ext4/extents-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ext4/extents-test.c b/fs/ext4/extents-test.c index 5a5016ea1ecc..70d84c0a18e2 100644 --- a/fs/ext4/extents-test.c +++ b/fs/ext4/extents-test.c @@ -144,7 +144,7 @@ static void extents_kunit_exit(struct kunit *test) { struct ext4_sb_info *sbi = k_ctx.k_ei->vfs_inode.i_sb->s_fs_info; - kfree(sbi); + deactivate_super(sbi->s_sb); kfree(k_ctx.k_ei); kfree(k_ctx.k_data); } -- 2.34.1 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH -next 5/8] ext4: fix miss free super_block in extents_kunit_exit() 2026-03-10 13:04 ` [PATCH -next 5/8] ext4: fix miss free super_block in extents_kunit_exit() Ye Bin @ 2026-03-13 12:03 ` Ritesh Harjani 2026-03-13 14:03 ` Ojaswin Mujoo 0 siblings, 1 reply; 21+ messages in thread From: Ritesh Harjani @ 2026-03-13 12:03 UTC (permalink / raw) To: Ye Bin, tytso, adilger.kernel, linux-ext4; +Cc: jack Ye Bin <yebin@huaweicloud.com> writes: > From: Ye Bin <yebin10@huawei.com> > > There's issue as follows: > ODEBUG: free active (active state 0) object: ffff88812f2d68a0 object type: percpu_counter hint: 0x0 > <TASK> > debug_check_no_obj_freed+0x3d9/0x4d0 > kfree+0x2bb/0x6c0 > extents_kunit_exit+0x65/0x90 [ext4_test] > kunit_try_run_case_cleanup+0xbc/0x100 [kunit] > kunit_generic_run_threadfn_adapter+0x89/0x100 [kunit] > kthread+0x408/0x540 > ret_from_fork+0xa76/0xdf0 > ret_from_fork_asm+0x1a/0x30 > > The above issue was caused because the super_block cleanup process > was not properly performed. > Therefore, deactivate_super() is called in extents_kunit_exit() to > cleanup the super_block. > > Fixes: cb1e0c1d1fad ("ext4: kunit tests for extent splitting and conversion") > Signed-off-by: Ye Bin <yebin10@huawei.com> > --- > fs/ext4/extents-test.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/fs/ext4/extents-test.c b/fs/ext4/extents-test.c > index 5a5016ea1ecc..70d84c0a18e2 100644 > --- a/fs/ext4/extents-test.c > +++ b/fs/ext4/extents-test.c > @@ -144,7 +144,7 @@ static void extents_kunit_exit(struct kunit *test) > { > struct ext4_sb_info *sbi = k_ctx.k_ei->vfs_inode.i_sb->s_fs_info; > > - kfree(sbi); > + deactivate_super(sbi->s_sb); This doesn't look correct. We don't have sbi->s_sb->s_op->put_super() registered, so kfree(sbi) never happens. Maybe it will be good to check with kmemleak too, that this could cause a memory leak. I think we can do: ext4_es_unregister_shrinker(sbi); // already taken care in [1] deactivate_super(sbi->s_sb) kfree(sbi); [1]: https://lore.kernel.org/linux-ext4/5bb9041471dab8ce870c191c19cbe4df57473be8.1772381213.git.ritesh.list@gmail.com/ -ritesh ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH -next 5/8] ext4: fix miss free super_block in extents_kunit_exit() 2026-03-13 12:03 ` Ritesh Harjani @ 2026-03-13 14:03 ` Ojaswin Mujoo 0 siblings, 0 replies; 21+ messages in thread From: Ojaswin Mujoo @ 2026-03-13 14:03 UTC (permalink / raw) To: Ritesh Harjani; +Cc: Ye Bin, tytso, adilger.kernel, linux-ext4, jack On Fri, Mar 13, 2026 at 05:33:15PM +0530, Ritesh Harjani wrote: > Ye Bin <yebin@huaweicloud.com> writes: > > > From: Ye Bin <yebin10@huawei.com> > > > > There's issue as follows: > > ODEBUG: free active (active state 0) object: ffff88812f2d68a0 object type: percpu_counter hint: 0x0 > > <TASK> > > debug_check_no_obj_freed+0x3d9/0x4d0 > > kfree+0x2bb/0x6c0 > > extents_kunit_exit+0x65/0x90 [ext4_test] > > kunit_try_run_case_cleanup+0xbc/0x100 [kunit] > > kunit_generic_run_threadfn_adapter+0x89/0x100 [kunit] > > kthread+0x408/0x540 > > ret_from_fork+0xa76/0xdf0 > > ret_from_fork_asm+0x1a/0x30 > > > > The above issue was caused because the super_block cleanup process > > was not properly performed. > > Therefore, deactivate_super() is called in extents_kunit_exit() to > > cleanup the super_block. > > > > Fixes: cb1e0c1d1fad ("ext4: kunit tests for extent splitting and conversion") > > Signed-off-by: Ye Bin <yebin10@huawei.com> > > --- > > fs/ext4/extents-test.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/fs/ext4/extents-test.c b/fs/ext4/extents-test.c > > index 5a5016ea1ecc..70d84c0a18e2 100644 > > --- a/fs/ext4/extents-test.c > > +++ b/fs/ext4/extents-test.c > > @@ -144,7 +144,7 @@ static void extents_kunit_exit(struct kunit *test) > > { > > struct ext4_sb_info *sbi = k_ctx.k_ei->vfs_inode.i_sb->s_fs_info; > > > > - kfree(sbi); > > + deactivate_super(sbi->s_sb); > > This doesn't look correct. We don't have sbi->s_sb->s_op->put_super() registered, so > kfree(sbi) never happens. Maybe it will be good to check with kmemleak > too, that this could cause a memory leak. > > I think we can do: > > ext4_es_unregister_shrinker(sbi); // already taken care in [1] > deactivate_super(sbi->s_sb) > kfree(sbi); I checked in my setup and can see that we don't have sb->s_op registered. @@ -149,6 +150,8 @@ static void extents_kunit_exit(struct kunit *test) sbi = k_ctx.k_ei->vfs_inode.i_sb->s_fs_info; deactivate_super(sbi->s_sb); + kunit_log(KERN_ALERT, test, + "sbi: %px sb->s_op: %pS", sbi, sbi->s_sb->s_op); kfree(k_ctx.k_ei); kfree(k_ctx.k_data); } Output: [ 12.176807] sbi: ffff8881089cc000 sb->s_op: default_op.3+0x0/0x100 So we are using the default noop s_ops. Regards, ojaswin > > [1]: https://lore.kernel.org/linux-ext4/5bb9041471dab8ce870c191c19cbe4df57473be8.1772381213.git.ritesh.list@gmail.com/ > > -ritesh ^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH -next 6/8] ext4: fix the error handling process in extents_kunit_init). 2026-03-10 13:04 [PATCH -next 0/8] Fix some issues about ext4-test Ye Bin ` (4 preceding siblings ...) 2026-03-10 13:04 ` [PATCH -next 5/8] ext4: fix miss free super_block in extents_kunit_exit() Ye Bin @ 2026-03-10 13:04 ` Ye Bin 2026-03-13 12:15 ` Ritesh Harjani 2026-03-10 13:04 ` [PATCH -next 7/8] ext4: fix possible null-ptr-deref in extents_kunit_exit() Ye Bin ` (2 subsequent siblings) 8 siblings, 1 reply; 21+ messages in thread From: Ye Bin @ 2026-03-10 13:04 UTC (permalink / raw) To: tytso, adilger.kernel, linux-ext4; +Cc: jack From: Ye Bin <yebin10@huawei.com> The error processing in extents_kunit_init() is improper, causing resource leakage. Reconstruct the error handling process to prevent potential resource leaks Fixes: cb1e0c1d1fad ("ext4: kunit tests for extent splitting and conversion") Signed-off-by: Ye Bin <yebin10@huawei.com> --- fs/ext4/extents-test.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/fs/ext4/extents-test.c b/fs/ext4/extents-test.c index 70d84c0a18e2..7e2796f72d45 100644 --- a/fs/ext4/extents-test.c +++ b/fs/ext4/extents-test.c @@ -222,33 +222,37 @@ static int extents_kunit_init(struct kunit *test) (struct kunit_ext_test_param *)(test->param_value); int err; - sb = sget(&ext_fs_type, NULL, ext_set, 0, NULL); - if (IS_ERR(sb)) - return PTR_ERR(sb); - - sb->s_blocksize = 4096; - sb->s_blocksize_bits = 12; - sbi = kzalloc_obj(struct ext4_sb_info); if (sbi == NULL) return -ENOMEM; + sb = sget(&ext_fs_type, NULL, ext_set, 0, NULL); + if (IS_ERR(sb)) { + kfree(sbi); + return PTR_ERR(sb); + } + sbi->s_sb = sb; sb->s_fs_info = sbi; + sb->s_blocksize = 4096; + sb->s_blocksize_bits = 12; + if (!param || !param->disable_zeroout) sbi->s_extent_max_zeroout_kb = 32; /* setup the mock inode */ k_ctx.k_ei = kzalloc_obj(struct ext4_inode_info); - if (k_ctx.k_ei == NULL) - return -ENOMEM; + if (k_ctx.k_ei == NULL) { + err = -ENOMEM; + goto out_deactivate; + } ei = k_ctx.k_ei; inode = &ei->vfs_inode; err = ext4_es_register_shrinker(sbi); if (err) - return err; + goto out_deactivate; ext4_es_init_tree(&ei->i_es_tree); rwlock_init(&ei->i_es_lock); @@ -264,8 +268,10 @@ static int extents_kunit_init(struct kunit *test) inode->i_sb = sb; k_ctx.k_data = kzalloc(EXT_DATA_LEN * 4096, GFP_KERNEL); - if (k_ctx.k_data == NULL) - return -ENOMEM; + if (k_ctx.k_data == NULL) { + err = -ENOMEM; + goto out_deactivate; + } /* * set the data area to a junk value @@ -310,6 +316,17 @@ static int extents_kunit_init(struct kunit *test) up_write(&sb->s_umount); return 0; + +out_deactivate: + kfree(k_ctx.k_ei); + k_ctx.k_ei = NULL; + + kfree(k_ctx.k_data); + k_ctx.k_data = NULL; + + deactivate_locked_super(sb); + + return err; } /* -- 2.34.1 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH -next 6/8] ext4: fix the error handling process in extents_kunit_init). 2026-03-10 13:04 ` [PATCH -next 6/8] ext4: fix the error handling process in extents_kunit_init) Ye Bin @ 2026-03-13 12:15 ` Ritesh Harjani 2026-03-14 2:21 ` yebin (H) 0 siblings, 1 reply; 21+ messages in thread From: Ritesh Harjani @ 2026-03-13 12:15 UTC (permalink / raw) To: Ye Bin, tytso, adilger.kernel, linux-ext4; +Cc: jack Ye Bin <yebin@huaweicloud.com> writes: > From: Ye Bin <yebin10@huawei.com> > > The error processing in extents_kunit_init() is improper, causing > resource leakage. > Reconstruct the error handling process to prevent potential resource > leaks > > Fixes: cb1e0c1d1fad ("ext4: kunit tests for extent splitting and conversion") > Signed-off-by: Ye Bin <yebin10@huawei.com> > --- > fs/ext4/extents-test.c | 41 +++++++++++++++++++++++++++++------------ > 1 file changed, 29 insertions(+), 12 deletions(-) > > diff --git a/fs/ext4/extents-test.c b/fs/ext4/extents-test.c > index 70d84c0a18e2..7e2796f72d45 100644 > --- a/fs/ext4/extents-test.c > +++ b/fs/ext4/extents-test.c > @@ -222,33 +222,37 @@ static int extents_kunit_init(struct kunit *test) > (struct kunit_ext_test_param *)(test->param_value); > int err; > > - sb = sget(&ext_fs_type, NULL, ext_set, 0, NULL); > - if (IS_ERR(sb)) > - return PTR_ERR(sb); > - > - sb->s_blocksize = 4096; > - sb->s_blocksize_bits = 12; > - > sbi = kzalloc_obj(struct ext4_sb_info); > if (sbi == NULL) > return -ENOMEM; > > + sb = sget(&ext_fs_type, NULL, ext_set, 0, NULL); > + if (IS_ERR(sb)) { > + kfree(sbi); > + return PTR_ERR(sb); > + } > + > sbi->s_sb = sb; > sb->s_fs_info = sbi; > > + sb->s_blocksize = 4096; > + sb->s_blocksize_bits = 12; > + > if (!param || !param->disable_zeroout) > sbi->s_extent_max_zeroout_kb = 32; > > /* setup the mock inode */ > k_ctx.k_ei = kzalloc_obj(struct ext4_inode_info); > - if (k_ctx.k_ei == NULL) > - return -ENOMEM; > + if (k_ctx.k_ei == NULL) { > + err = -ENOMEM; > + goto out_deactivate; > + } > ei = k_ctx.k_ei; > inode = &ei->vfs_inode; > > err = ext4_es_register_shrinker(sbi); > if (err) > - return err; > + goto out_deactivate; > > ext4_es_init_tree(&ei->i_es_tree); > rwlock_init(&ei->i_es_lock); > @@ -264,8 +268,10 @@ static int extents_kunit_init(struct kunit *test) > inode->i_sb = sb; > > k_ctx.k_data = kzalloc(EXT_DATA_LEN * 4096, GFP_KERNEL); > - if (k_ctx.k_data == NULL) > - return -ENOMEM; > + if (k_ctx.k_data == NULL) { > + err = -ENOMEM; > + goto out_deactivate; > + } > > /* > * set the data area to a junk value > @@ -310,6 +316,17 @@ static int extents_kunit_init(struct kunit *test) > up_write(&sb->s_umount); > > return 0; > + > +out_deactivate: > + kfree(k_ctx.k_ei); > + k_ctx.k_ei = NULL; > + > + kfree(k_ctx.k_data); > + k_ctx.k_data = NULL; > + > + deactivate_locked_super(sb); So I guess the right thing to do for now is, what Ojaswin also mentioned [1]. Let's go with patch [2], as is.. and we can fix all the remaining issues as part of this series. With that in mind, this patch series needs to be applid on top of [2]. So that means.. our error handling should also properly take care of unregister shrinker and freeing sbi.. [1]: https://lore.kernel.org/linux-ext4/abPh6GX0t22m628D@li-dc0c254c-257c-11b2-a85c-98b6c1322444.ibm.com/ [2]: https://lore.kernel.org/linux-ext4/5bb9041471dab8ce870c191c19cbe4df57473be8.1772381213.git.ritesh.list@gmail.com/#t -ritesh > + > + return err; > } > > /* > -- > 2.34.1 ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH -next 6/8] ext4: fix the error handling process in extents_kunit_init). 2026-03-13 12:15 ` Ritesh Harjani @ 2026-03-14 2:21 ` yebin (H) 0 siblings, 0 replies; 21+ messages in thread From: yebin (H) @ 2026-03-14 2:21 UTC (permalink / raw) To: Ritesh Harjani, Ye Bin, tytso, adilger.kernel, linux-ext4; +Cc: jack On 2026/3/13 20:15, Ritesh Harjani wrote: > Ye Bin <yebin@huaweicloud.com> writes: > >> From: Ye Bin <yebin10@huawei.com> >> >> The error processing in extents_kunit_init() is improper, causing >> resource leakage. >> Reconstruct the error handling process to prevent potential resource >> leaks >> >> Fixes: cb1e0c1d1fad ("ext4: kunit tests for extent splitting and conversion") >> Signed-off-by: Ye Bin <yebin10@huawei.com> >> --- >> fs/ext4/extents-test.c | 41 +++++++++++++++++++++++++++++------------ >> 1 file changed, 29 insertions(+), 12 deletions(-) >> >> diff --git a/fs/ext4/extents-test.c b/fs/ext4/extents-test.c >> index 70d84c0a18e2..7e2796f72d45 100644 >> --- a/fs/ext4/extents-test.c >> +++ b/fs/ext4/extents-test.c >> @@ -222,33 +222,37 @@ static int extents_kunit_init(struct kunit *test) >> (struct kunit_ext_test_param *)(test->param_value); >> int err; >> >> - sb = sget(&ext_fs_type, NULL, ext_set, 0, NULL); >> - if (IS_ERR(sb)) >> - return PTR_ERR(sb); >> - >> - sb->s_blocksize = 4096; >> - sb->s_blocksize_bits = 12; >> - >> sbi = kzalloc_obj(struct ext4_sb_info); >> if (sbi == NULL) >> return -ENOMEM; >> >> + sb = sget(&ext_fs_type, NULL, ext_set, 0, NULL); >> + if (IS_ERR(sb)) { >> + kfree(sbi); >> + return PTR_ERR(sb); >> + } >> + >> sbi->s_sb = sb; >> sb->s_fs_info = sbi; >> >> + sb->s_blocksize = 4096; >> + sb->s_blocksize_bits = 12; >> + >> if (!param || !param->disable_zeroout) >> sbi->s_extent_max_zeroout_kb = 32; >> >> /* setup the mock inode */ >> k_ctx.k_ei = kzalloc_obj(struct ext4_inode_info); >> - if (k_ctx.k_ei == NULL) >> - return -ENOMEM; >> + if (k_ctx.k_ei == NULL) { >> + err = -ENOMEM; >> + goto out_deactivate; >> + } >> ei = k_ctx.k_ei; >> inode = &ei->vfs_inode; >> >> err = ext4_es_register_shrinker(sbi); >> if (err) >> - return err; >> + goto out_deactivate; >> >> ext4_es_init_tree(&ei->i_es_tree); >> rwlock_init(&ei->i_es_lock); >> @@ -264,8 +268,10 @@ static int extents_kunit_init(struct kunit *test) >> inode->i_sb = sb; >> >> k_ctx.k_data = kzalloc(EXT_DATA_LEN * 4096, GFP_KERNEL); >> - if (k_ctx.k_data == NULL) >> - return -ENOMEM; >> + if (k_ctx.k_data == NULL) { >> + err = -ENOMEM; >> + goto out_deactivate; >> + } >> >> /* >> * set the data area to a junk value >> @@ -310,6 +316,17 @@ static int extents_kunit_init(struct kunit *test) >> up_write(&sb->s_umount); >> >> return 0; >> + >> +out_deactivate: >> + kfree(k_ctx.k_ei); >> + k_ctx.k_ei = NULL; >> + >> + kfree(k_ctx.k_data); >> + k_ctx.k_data = NULL; >> + >> + deactivate_locked_super(sb); > > So I guess the right thing to do for now is, what Ojaswin also mentioned > [1]. Let's go with patch [2], as is.. and we can fix all the remaining > issues as part of this series. With that in mind, this patch series > needs to be applid on top of [2]. So that means.. our error handling > should also properly take care of unregister shrinker and freeing sbi.. > > [1]: https://lore.kernel.org/linux-ext4/abPh6GX0t22m628D@li-dc0c254c-257c-11b2-a85c-98b6c1322444.ibm.com/ > [2]: https://lore.kernel.org/linux-ext4/5bb9041471dab8ce870c191c19cbe4df57473be8.1772381213.git.ritesh.list@gmail.com/#t > > -ritesh > I will base on your patch and then create a separate patchset for the fixes and send it. > >> + >> + return err; >> } >> >> /* >> -- >> 2.34.1 > > > . > ^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH -next 7/8] ext4: fix possible null-ptr-deref in extents_kunit_exit() 2026-03-10 13:04 [PATCH -next 0/8] Fix some issues about ext4-test Ye Bin ` (5 preceding siblings ...) 2026-03-10 13:04 ` [PATCH -next 6/8] ext4: fix the error handling process in extents_kunit_init) Ye Bin @ 2026-03-10 13:04 ` Ye Bin 2026-03-13 12:27 ` Ritesh Harjani 2026-03-10 13:04 ` [PATCH -next 8/8] ext4: fix possible null-ptr-deref in mbt_kunit_exit() Ye Bin 2026-03-13 7:16 ` [PATCH -next 0/8] Fix some issues about ext4-test Ojaswin Mujoo 8 siblings, 1 reply; 21+ messages in thread From: Ye Bin @ 2026-03-10 13:04 UTC (permalink / raw) To: tytso, adilger.kernel, linux-ext4; +Cc: jack From: Ye Bin <yebin10@huawei.com> There's issue as follows: KASAN: null-ptr-deref in range [0x00000000000002c0-0x00000000000002c7] Tainted: [E]=UNSIGNED_MODULE, [N]=TEST RIP: 0010:extents_kunit_exit+0x2e/0xc0 [ext4_test] Call Trace: <TASK> kunit_try_run_case_cleanup+0xbc/0x100 [kunit] kunit_generic_run_threadfn_adapter+0x89/0x100 [kunit] kthread+0x408/0x540 ret_from_fork+0xa76/0xdf0 ret_from_fork_asm+0x1a/0x30 Above issue happens as extents_kunit_init() init testcase failed. So test if testcase is inited success. Fixes: cb1e0c1d1fad ("ext4: kunit tests for extent splitting and conversion") Signed-off-by: Ye Bin <yebin10@huawei.com> --- fs/ext4/extents-test.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/ext4/extents-test.c b/fs/ext4/extents-test.c index 7e2796f72d45..b1ea37e74f12 100644 --- a/fs/ext4/extents-test.c +++ b/fs/ext4/extents-test.c @@ -142,8 +142,12 @@ static struct file_system_type ext_fs_type = { static void extents_kunit_exit(struct kunit *test) { - struct ext4_sb_info *sbi = k_ctx.k_ei->vfs_inode.i_sb->s_fs_info; + struct ext4_sb_info *sbi; + if (!k_ctx.k_ei) + return; + + sbi = k_ctx.k_ei->vfs_inode.i_sb->s_fs_info; deactivate_super(sbi->s_sb); kfree(k_ctx.k_ei); kfree(k_ctx.k_data); -- 2.34.1 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH -next 7/8] ext4: fix possible null-ptr-deref in extents_kunit_exit() 2026-03-10 13:04 ` [PATCH -next 7/8] ext4: fix possible null-ptr-deref in extents_kunit_exit() Ye Bin @ 2026-03-13 12:27 ` Ritesh Harjani 0 siblings, 0 replies; 21+ messages in thread From: Ritesh Harjani @ 2026-03-13 12:27 UTC (permalink / raw) To: Ye Bin, tytso, adilger.kernel, linux-ext4; +Cc: jack Ye Bin <yebin@huaweicloud.com> writes: > From: Ye Bin <yebin10@huawei.com> > > There's issue as follows: > KASAN: null-ptr-deref in range [0x00000000000002c0-0x00000000000002c7] > Tainted: [E]=UNSIGNED_MODULE, [N]=TEST > RIP: 0010:extents_kunit_exit+0x2e/0xc0 [ext4_test] > Call Trace: > <TASK> > kunit_try_run_case_cleanup+0xbc/0x100 [kunit] > kunit_generic_run_threadfn_adapter+0x89/0x100 [kunit] > kthread+0x408/0x540 > ret_from_fork+0xa76/0xdf0 > ret_from_fork_asm+0x1a/0x30 > > Above issue happens as extents_kunit_init() init testcase failed. > So test if testcase is inited success. > > Fixes: cb1e0c1d1fad ("ext4: kunit tests for extent splitting and conversion") > Signed-off-by: Ye Bin <yebin10@huawei.com> > --- > fs/ext4/extents-test.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/fs/ext4/extents-test.c b/fs/ext4/extents-test.c > index 7e2796f72d45..b1ea37e74f12 100644 > --- a/fs/ext4/extents-test.c > +++ b/fs/ext4/extents-test.c > @@ -142,8 +142,12 @@ static struct file_system_type ext_fs_type = { > > static void extents_kunit_exit(struct kunit *test) > { > - struct ext4_sb_info *sbi = k_ctx.k_ei->vfs_inode.i_sb->s_fs_info; > + struct ext4_sb_info *sbi; > > + if (!k_ctx.k_ei) > + return; > + Make sense to me. Feel free to add: Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> ^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH -next 8/8] ext4: fix possible null-ptr-deref in mbt_kunit_exit() 2026-03-10 13:04 [PATCH -next 0/8] Fix some issues about ext4-test Ye Bin ` (6 preceding siblings ...) 2026-03-10 13:04 ` [PATCH -next 7/8] ext4: fix possible null-ptr-deref in extents_kunit_exit() Ye Bin @ 2026-03-10 13:04 ` Ye Bin 2026-03-13 12:33 ` Ritesh Harjani 2026-03-13 7:16 ` [PATCH -next 0/8] Fix some issues about ext4-test Ojaswin Mujoo 8 siblings, 1 reply; 21+ messages in thread From: Ye Bin @ 2026-03-10 13:04 UTC (permalink / raw) To: tytso, adilger.kernel, linux-ext4; +Cc: jack From: Ye Bin <yebin10@huawei.com> There's issue as follows: # test_new_blocks_simple: failed to initialize: -12 KASAN: null-ptr-deref in range [0x0000000000000638-0x000000000000063f] Tainted: [E]=UNSIGNED_MODULE, [N]=TEST RIP: 0010:mbt_kunit_exit+0x5e/0x3e0 [ext4_test] Call Trace: <TASK> kunit_try_run_case_cleanup+0xbc/0x100 [kunit] kunit_generic_run_threadfn_adapter+0x89/0x100 [kunit] kthread+0x408/0x540 ret_from_fork+0xa76/0xdf0 ret_from_fork_asm+0x1a/0x30 If mbt_kunit_init() init testcase failed will lead to null-ptr-deref. So add test if 'sb' is inited success in mbt_kunit_exit(). Fixes: 7c9fa399a369 ("ext4: add first unit test for ext4_mb_new_blocks_simple in mballoc") Signed-off-by: Ye Bin <yebin10@huawei.com> --- fs/ext4/mballoc-test.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/ext4/mballoc-test.c b/fs/ext4/mballoc-test.c index c75b91ae0cf0..90ed505fa4b1 100644 --- a/fs/ext4/mballoc-test.c +++ b/fs/ext4/mballoc-test.c @@ -362,7 +362,6 @@ static int mbt_kunit_init(struct kunit *test) return ret; } - test->priv = sb; kunit_activate_static_stub(test, ext4_read_block_bitmap_nowait, ext4_read_block_bitmap_nowait_stub); @@ -383,6 +382,8 @@ static int mbt_kunit_init(struct kunit *test) return -ENOMEM; } + test->priv = sb; + return 0; } @@ -390,6 +391,9 @@ static void mbt_kunit_exit(struct kunit *test) { struct super_block *sb = (struct super_block *)test->priv; + if (!sb) + return; + mbt_mb_release(sb); mbt_ctx_release(sb); mbt_ext4_free_super_block(sb); -- 2.34.1 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH -next 8/8] ext4: fix possible null-ptr-deref in mbt_kunit_exit() 2026-03-10 13:04 ` [PATCH -next 8/8] ext4: fix possible null-ptr-deref in mbt_kunit_exit() Ye Bin @ 2026-03-13 12:33 ` Ritesh Harjani 0 siblings, 0 replies; 21+ messages in thread From: Ritesh Harjani @ 2026-03-13 12:33 UTC (permalink / raw) To: Ye Bin, tytso, adilger.kernel, linux-ext4; +Cc: jack Ye Bin <yebin@huaweicloud.com> writes: > From: Ye Bin <yebin10@huawei.com> > > There's issue as follows: > # test_new_blocks_simple: failed to initialize: -12 > KASAN: null-ptr-deref in range [0x0000000000000638-0x000000000000063f] > Tainted: [E]=UNSIGNED_MODULE, [N]=TEST > RIP: 0010:mbt_kunit_exit+0x5e/0x3e0 [ext4_test] > Call Trace: > <TASK> > kunit_try_run_case_cleanup+0xbc/0x100 [kunit] > kunit_generic_run_threadfn_adapter+0x89/0x100 [kunit] > kthread+0x408/0x540 > ret_from_fork+0xa76/0xdf0 > ret_from_fork_asm+0x1a/0x30 > > If mbt_kunit_init() init testcase failed will lead to null-ptr-deref. > So add test if 'sb' is inited success in mbt_kunit_exit(). > > Fixes: 7c9fa399a369 ("ext4: add first unit test for ext4_mb_new_blocks_simple in mballoc") > Signed-off-by: Ye Bin <yebin10@huawei.com> > --- > fs/ext4/mballoc-test.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/fs/ext4/mballoc-test.c b/fs/ext4/mballoc-test.c > index c75b91ae0cf0..90ed505fa4b1 100644 > --- a/fs/ext4/mballoc-test.c > +++ b/fs/ext4/mballoc-test.c > @@ -362,7 +362,6 @@ static int mbt_kunit_init(struct kunit *test) > return ret; > } > > - test->priv = sb; > kunit_activate_static_stub(test, > ext4_read_block_bitmap_nowait, > ext4_read_block_bitmap_nowait_stub); > @@ -383,6 +382,8 @@ static int mbt_kunit_init(struct kunit *test) > return -ENOMEM; > } > > + test->priv = sb; > + So, I see that "test" which is of "struct kunit" type, is always initialized locally on stack, so test->priv by default is always NULL. Hence this make sense to me. Feel free to add: Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> > return 0; > } > > @@ -390,6 +391,9 @@ static void mbt_kunit_exit(struct kunit *test) > { > struct super_block *sb = (struct super_block *)test->priv; > > + if (!sb) > + return; > + > mbt_mb_release(sb); > mbt_ctx_release(sb); > mbt_ext4_free_super_block(sb); > -- > 2.34.1 ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH -next 0/8] Fix some issues about ext4-test 2026-03-10 13:04 [PATCH -next 0/8] Fix some issues about ext4-test Ye Bin ` (7 preceding siblings ...) 2026-03-10 13:04 ` [PATCH -next 8/8] ext4: fix possible null-ptr-deref in mbt_kunit_exit() Ye Bin @ 2026-03-13 7:16 ` Ojaswin Mujoo 2026-03-13 10:34 ` Ojaswin Mujoo 8 siblings, 1 reply; 21+ messages in thread From: Ojaswin Mujoo @ 2026-03-13 7:16 UTC (permalink / raw) To: Ye Bin; +Cc: tytso, adilger.kernel, linux-ext4, jack On Tue, Mar 10, 2026 at 09:04:04PM +0800, Ye Bin wrote: > From: Ye Bin <yebin10@huawei.com> > > Patch [1]-[2]: > Decoupled mballoc-test and extents-test from ext4. Patch [1] does not > have any changes compared to the previously released version, so the > reviewed-by is added. > Patch [3-7]: > Bugfix for extents-test.c. > Patch [8]: > Bugfix for mballoc-test.c. > > Ye Bin (8): > ext4: fix mballoc-test.c is not compiled when EXT4_KUNIT_TESTS=M > ext4: introduce EXPORT_SYMBOL_FOR_EXT4_TEST() helper > ext4: fix extents-test.c is not compiled when EXT4_KUNIT_TESTS=M > ext4: fix miss unlock 'sb->s_umount' in extents_kunit_init() > ext4: fix miss free super_block in extents_kunit_exit() > ext4: fix the error handling process in extents_kunit_init). > ext4: fix possible null-ptr-deref in extents_kunit_exit() > ext4: fix possible null-ptr-deref in mbt_kunit_exit() > > fs/ext4/Makefile | 5 +- > fs/ext4/ext4.h | 5 ++ > fs/ext4/ext4_extents.h | 12 +++++ > fs/ext4/extents-test.c | 59 ++++++++++++++++-------- > fs/ext4/extents.c | 38 ++++++++++++--- > fs/ext4/mballoc-test.c | 87 ++++++++++++++++++----------------- > fs/ext4/mballoc.c | 102 +++++++++++++++++++++++++++++++++++++++-- > fs/ext4/mballoc.h | 30 ++++++++++++ > 8 files changed, 268 insertions(+), 70 deletions(-) Hi Ye, Thanks for the fixes, seems like I completely forgot cleaning up resources in extents-test.c so thanks for taking that up. Sadly, my UML kunit runs didn't catch any of this :/ Although the series look good to me, I have a request, can you please resend the fixes in patch 4 - 7 separate from patch 1 2 3. We need these fixes (specifically patch 4 and 5) to fix the breakage in linux-next [1], keeping them separate can help Ted just pickup the urgent fixes independent of patch 1,2,3. Also, for patch 5, it fixes an issue that Ritesh fixed in his patche [2]. I think your patch is a better approach since all cleanup is handled via deactivate_super(). However, his commit message better describes the issue. While resending, can you include his commit message as well. (I've checked with him so feel free to reuse it). Thanks again, Ojaswin [1] https://lore.kernel.org/all/0d21783c-5299-4488-9708-def0b1a4dcbe@sirena.org.uk/ [2] https://lore.kernel.org/linux-ext4/5bb9041471dab8ce870c191c19cbe4df57473be8.1772381213.git.ritesh.list@gmail.com/ > > -- > 2.34.1 > ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH -next 0/8] Fix some issues about ext4-test 2026-03-13 7:16 ` [PATCH -next 0/8] Fix some issues about ext4-test Ojaswin Mujoo @ 2026-03-13 10:34 ` Ojaswin Mujoo 0 siblings, 0 replies; 21+ messages in thread From: Ojaswin Mujoo @ 2026-03-13 10:34 UTC (permalink / raw) To: Ye Bin; +Cc: tytso, adilger.kernel, linux-ext4, jack On Fri, Mar 13, 2026 at 12:46:55PM +0530, Ojaswin Mujoo wrote: > On Tue, Mar 10, 2026 at 09:04:04PM +0800, Ye Bin wrote: > > From: Ye Bin <yebin10@huawei.com> > > > > Patch [1]-[2]: > > Decoupled mballoc-test and extents-test from ext4. Patch [1] does not > > have any changes compared to the previously released version, so the > > reviewed-by is added. > > Patch [3-7]: > > Bugfix for extents-test.c. > > Patch [8]: > > Bugfix for mballoc-test.c. > > > > Ye Bin (8): > > ext4: fix mballoc-test.c is not compiled when EXT4_KUNIT_TESTS=M > > ext4: introduce EXPORT_SYMBOL_FOR_EXT4_TEST() helper > > ext4: fix extents-test.c is not compiled when EXT4_KUNIT_TESTS=M > > ext4: fix miss unlock 'sb->s_umount' in extents_kunit_init() > > ext4: fix miss free super_block in extents_kunit_exit() > > ext4: fix the error handling process in extents_kunit_init). > > ext4: fix possible null-ptr-deref in extents_kunit_exit() > > ext4: fix possible null-ptr-deref in mbt_kunit_exit() > > > > fs/ext4/Makefile | 5 +- > > fs/ext4/ext4.h | 5 ++ > > fs/ext4/ext4_extents.h | 12 +++++ > > fs/ext4/extents-test.c | 59 ++++++++++++++++-------- > > fs/ext4/extents.c | 38 ++++++++++++--- > > fs/ext4/mballoc-test.c | 87 ++++++++++++++++++----------------- > > fs/ext4/mballoc.c | 102 +++++++++++++++++++++++++++++++++++++++-- > > fs/ext4/mballoc.h | 30 ++++++++++++ > > 8 files changed, 268 insertions(+), 70 deletions(-) > > Hi Ye, > > Thanks for the fixes, seems like I completely forgot cleaning up > resources in extents-test.c so thanks for taking that up. Sadly, my UML > kunit runs didn't catch any of this :/ > > Although the series look good to me, I have a request, can you please > resend the fixes in patch 4 - 7 separate from patch 1 2 3. We need > these fixes (specifically patch 4 and 5) to fix the breakage in > linux-next [1], keeping them separate can help Ted just pickup the > urgent fixes independent of patch 1,2,3. > > Also, for patch 5, it fixes an issue that Ritesh fixed in his patche > [2]. I think your patch is a better approach since all cleanup is > handled via deactivate_super(). However, his commit message better > describes the issue. While resending, can you include his commit message > as well. (I've checked with him so feel free to reuse it). Hey Ye, sorry for the confusion but you can ignore the above paragraph. We still need Ritesh's patches along with yours. More details here [1] That being said, I still feel the fixes here can go separately. I'll try to priortize the review of patch 4 - 7 so thaat we can get them in shape to be merged. [1] https://lore.kernel.org/linux-ext4/abPh6GX0t22m628D@li-dc0c254c-257c-11b2-a85c-98b6c1322444.ibm.com/ Regards, ojaswin > > Thanks again, > Ojaswin > > [1] https://lore.kernel.org/all/0d21783c-5299-4488-9708-def0b1a4dcbe@sirena.org.uk/ > [2] https://lore.kernel.org/linux-ext4/5bb9041471dab8ce870c191c19cbe4df57473be8.1772381213.git.ritesh.list@gmail.com/ > > > > > -- > > 2.34.1 > > ^ permalink raw reply [flat|nested] 21+ messages in thread
end of thread, other threads:[~2026-03-14 2:21 UTC | newest] Thread overview: 21+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-03-10 13:04 [PATCH -next 0/8] Fix some issues about ext4-test Ye Bin 2026-03-10 13:04 ` [PATCH -next 1/8] ext4: fix mballoc-test.c is not compiled when EXT4_KUNIT_TESTS=M Ye Bin 2026-03-11 2:44 ` kernel test robot 2026-03-11 3:26 ` kernel test robot 2026-03-10 13:04 ` [PATCH -next 2/8] ext4: introduce EXPORT_SYMBOL_FOR_EXT4_TEST() helper Ye Bin 2026-03-10 13:04 ` [PATCH -next 3/8] ext4: fix extents-test.c is not compiled when EXT4_KUNIT_TESTS=M Ye Bin 2026-03-11 6:32 ` kernel test robot 2026-03-10 13:04 ` [PATCH -next 4/8] ext4: fix miss unlock 'sb->s_umount' in extents_kunit_init() Ye Bin 2026-03-13 11:32 ` Ritesh Harjani 2026-03-10 13:04 ` [PATCH -next 5/8] ext4: fix miss free super_block in extents_kunit_exit() Ye Bin 2026-03-13 12:03 ` Ritesh Harjani 2026-03-13 14:03 ` Ojaswin Mujoo 2026-03-10 13:04 ` [PATCH -next 6/8] ext4: fix the error handling process in extents_kunit_init) Ye Bin 2026-03-13 12:15 ` Ritesh Harjani 2026-03-14 2:21 ` yebin (H) 2026-03-10 13:04 ` [PATCH -next 7/8] ext4: fix possible null-ptr-deref in extents_kunit_exit() Ye Bin 2026-03-13 12:27 ` Ritesh Harjani 2026-03-10 13:04 ` [PATCH -next 8/8] ext4: fix possible null-ptr-deref in mbt_kunit_exit() Ye Bin 2026-03-13 12:33 ` Ritesh Harjani 2026-03-13 7:16 ` [PATCH -next 0/8] Fix some issues about ext4-test Ojaswin Mujoo 2026-03-13 10:34 ` Ojaswin Mujoo
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox