| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/10/21 12:48 | flow | patch-triage |
3mArgs:null Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"KMSANReasoning": "",
"NeedsKMSAN": false,
"Reasoning": "The patch adds a new KUnit test suite (fs/ext4/extents_status-test.c) and associated test plumbing (EXPORT_SYMBOL_FOR_EXT4_TEST exports and KUNIT_STATIC_STUB_REDIRECT hooks in fs/ext4/inode.c, fs/ext4/extents.c, and fs/ext4/extents_status.c). No functional kernel logic, data structures, or runtime assertions in ext4 production code are modified. During normal execution and fuzzing, KUNIT_STATIC_STUB_REDIRECT is a no-op because kunit_get_current_test() returns NULL. KUnit unit tests run non-interactively at boot or via test harnesses and are not reachable or exercisable via syzkaller syscall fuzzing. Therefore, the changes do not warrant fuzzing.",
"WorthFuzzing": false
} |
| 1/1 | 2026/10/21 12:48 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 7544e1de9c4172decede10968365499730f237d5\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Wed Oct 21 12:48:10 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/fs/ext4/Makefile b/fs/ext4/Makefile\nindex 3f9fc0eb8ecad..74b485dbb229b 100644\n--- a/fs/ext4/Makefile\n+++ b/fs/ext4/Makefile\n@@ -15,7 +15,8 @@ ext4-y\t:= balloc.o bitmap.o block_validity.o dir.o ext4_jbd2.o extents.o \\\n ext4-$(CONFIG_EXT4_FS_POSIX_ACL)\t+= acl.o\n ext4-$(CONFIG_EXT4_FS_SECURITY)\t\t+= xattr_security.o\n ext4-test-objs\t\t\t\t+= inode-test.o mballoc-test.o \\\n-\t\t\t\t\t extents-test.o hash-test.o\n+\t\t\t\t\t extents-test.o hash-test.o \\\n+\t\t\t\t\t extents_status-test.o\n obj-$(CONFIG_EXT4_KUNIT_TESTS)\t\t+= ext4-test.o\n ext4-$(CONFIG_FS_VERITY)\t\t+= verity.o\n ext4-$(CONFIG_FS_ENCRYPTION)\t\t+= crypto.o\ndiff --git a/fs/ext4/extents.c b/fs/ext4/extents.c\nindex 76038b6c36552..6c018bcc01187 100644\n--- a/fs/ext4/extents.c\n+++ b/fs/ext4/extents.c\n@@ -6407,12 +6407,7 @@ EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_split_convert_extents_test);\n \n EXPORT_SYMBOL_FOR_EXT4_TEST(__ext4_ext_dirty);\n EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_ext_zeroout);\n-EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_register_shrinker);\n-EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_unregister_shrinker);\n EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_map_create_blocks);\n-EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_init_tree);\n-EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_lookup_extent);\n-EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_insert_extent);\n EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_ext_insert_extent);\n EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_find_extent);\n EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_issue_zeroout);\ndiff --git a/fs/ext4/extents_status-test.c b/fs/ext4/extents_status-test.c\nnew file mode 100644\nindex 0000000000000..59eaac464bdce\n--- /dev/null\n+++ b/fs/ext4/extents_status-test.c\n@@ -0,0 +1,1640 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * KUnit tests for ext4 extents status tree and bigalloc pending reservations.\n+ */\n+\n+#include \u003ckunit/test.h\u003e\n+#include \u003ckunit/test-bug.h\u003e\n+#include \u003ckunit/static_stub.h\u003e\n+#include \u003clinux/fs_context.h\u003e\n+#include \u003clinux/seq_file.h\u003e\n+\n+#include \"ext4.h\"\n+#include \"ext4_extents.h\"\n+\n+#define ES_MAX_EXPECTED_EXTENTS 8\n+\n+struct es_test_ctx {\n+\tstruct super_block *sb;\n+\tstruct ext4_sb_info *sbi;\n+\tstruct ext4_inode_info *ei;\n+\n+\t/*\n+\t * Saved shrinker callbacks so the registered shrinker can be\n+\t * replaced with no-op stubs to prevent asynchronous background\n+\t * reclaim (kswapd / direct reclaim) from touching mock extents.\n+\t */\n+\tunsigned long (*shrinker_count)(struct shrinker *shrink,\n+\t\t\t\t\tstruct shrink_control *sc);\n+\tunsigned long (*shrinker_scan)(struct shrinker *shrink,\n+\t\t\t\t struct shrink_control *sc);\n+\n+\t/* Tracking for stubbed delalloc reservation callbacks */\n+\tint da_update_calls;\n+\tint last_da_used;\n+\tint total_da_used;\n+\tint last_da_quota_claim;\n+\n+\tint da_release_calls;\n+\tint last_da_released;\n+\tint total_da_released;\n+};\n+\n+struct expected_es {\n+\text4_lblk_t lblk;\n+\text4_lblk_t len;\n+\text4_fsblk_t pblk;\n+\tunsigned int type;\n+};\n+\n+static void reset_da_stub_stats(struct es_test_ctx *ctx)\n+{\n+\tctx-\u003eda_update_calls = 0;\n+\tctx-\u003elast_da_used = 0;\n+\tctx-\u003etotal_da_used = 0;\n+\tctx-\u003elast_da_quota_claim = 0;\n+\n+\tctx-\u003eda_release_calls = 0;\n+\tctx-\u003elast_da_released = 0;\n+\tctx-\u003etotal_da_released = 0;\n+}\n+\n+static void ext4_da_update_reserve_space_stub(struct inode *inode,\n+\t\t\t\t\t int used, int quota_claim)\n+{\n+\tstruct kunit *test = kunit_get_current_test();\n+\tstruct es_test_ctx *ctx;\n+\n+\tif (!test || !test-\u003epriv)\n+\t\treturn;\n+\n+\tctx = test-\u003epriv;\n+\tctx-\u003eda_update_calls++;\n+\tctx-\u003elast_da_used = used;\n+\tctx-\u003etotal_da_used += used;\n+\tctx-\u003elast_da_quota_claim = quota_claim;\n+}\n+\n+static void ext4_da_release_space_stub(struct inode *inode, int to_free)\n+{\n+\tstruct kunit *test = kunit_get_current_test();\n+\tstruct es_test_ctx *ctx;\n+\n+\tif (!to_free || !test || !test-\u003epriv)\n+\t\treturn;\n+\n+\tctx = test-\u003epriv;\n+\tctx-\u003eda_release_calls++;\n+\tctx-\u003elast_da_released = to_free;\n+\tctx-\u003etotal_da_released += to_free;\n+}\n+\n+static struct ext4_ext_path *\n+ext4_find_extent_stub(struct inode *inode, ext4_lblk_t block,\n+\t\t struct ext4_ext_path *path, int flags)\n+{\n+\treturn ERR_PTR(-EOPNOTSUPP);\n+}\n+\n+static unsigned long es_dummy_shrinker_count(struct shrinker *shrink,\n+\t\t\t\t\t struct shrink_control *sc)\n+{\n+\treturn 0;\n+}\n+\n+static unsigned long es_dummy_shrinker_scan(struct shrinker *shrink,\n+\t\t\t\t\t struct shrink_control *sc)\n+{\n+\treturn SHRINK_STOP;\n+}\n+\n+static unsigned long es_shrinker_count(struct es_test_ctx *ctx,\n+\t\t\t\t struct shrink_control *sc)\n+{\n+\treturn ctx-\u003eshrinker_count(ctx-\u003esbi-\u003es_es_shrinker, sc);\n+}\n+\n+static unsigned long es_shrinker_scan(struct es_test_ctx *ctx,\n+\t\t\t\t struct shrink_control *sc)\n+{\n+\treturn ctx-\u003eshrinker_scan(ctx-\u003esbi-\u003es_es_shrinker, sc);\n+}\n+\n+static void es_insert_extent(struct inode *inode, ext4_lblk_t lblk,\n+\t\t\t ext4_lblk_t len, ext4_fsblk_t pblk,\n+\t\t\t unsigned int status, bool delalloc_reserve_used)\n+{\n+\tdown_write(\u0026EXT4_I(inode)-\u003ei_data_sem);\n+\text4_es_insert_extent(inode, lblk, len, pblk, status,\n+\t\t\t delalloc_reserve_used);\n+\tup_write(\u0026EXT4_I(inode)-\u003ei_data_sem);\n+}\n+\n+static void es_insert_delayed_extent(struct inode *inode, ext4_lblk_t lblk,\n+\t\t\t\t ext4_lblk_t len, bool lclu_allocated,\n+\t\t\t\t bool end_allocated)\n+{\n+\tdown_write(\u0026EXT4_I(inode)-\u003ei_data_sem);\n+\text4_es_insert_delayed_extent(inode, lblk, len, lclu_allocated,\n+\t\t\t\t end_allocated);\n+\tup_write(\u0026EXT4_I(inode)-\u003ei_data_sem);\n+}\n+\n+static void es_cache_extent(struct inode *inode, ext4_lblk_t lblk,\n+\t\t\t ext4_lblk_t len, ext4_fsblk_t pblk,\n+\t\t\t unsigned int status)\n+{\n+\tdown_read(\u0026EXT4_I(inode)-\u003ei_data_sem);\n+\text4_es_cache_extent(inode, lblk, len, pblk, status);\n+\tup_read(\u0026EXT4_I(inode)-\u003ei_data_sem);\n+}\n+\n+static void es_remove_extent(struct inode *inode, ext4_lblk_t lblk,\n+\t\t\t ext4_lblk_t len)\n+{\n+\tdown_write(\u0026EXT4_I(inode)-\u003ei_data_sem);\n+\text4_es_remove_extent(inode, lblk, len);\n+\tup_write(\u0026EXT4_I(inode)-\u003ei_data_sem);\n+}\n+\n+static int es_init_fs_context(struct fs_context *fc)\n+{\n+\treturn 0;\n+}\n+\n+static int es_set_anon(struct super_block *sb, struct fs_context *fc)\n+{\n+\treturn set_anon_super_fc(sb, fc);\n+}\n+\n+static struct file_system_type es_fs_type = {\n+\t.name\t\t = \"extents_status test\",\n+\t.init_fs_context = es_init_fs_context,\n+\t.kill_sb\t = kill_anon_super,\n+};\n+\n+static void es_init_mock_inode(struct ext4_inode_info *ei,\n+\t\t\t struct super_block *sb, unsigned long ino)\n+{\n+\tstruct inode *inode = \u0026ei-\u003evfs_inode;\n+\n+\tmemset(ei, 0, sizeof(*ei));\n+\tinode-\u003ei_sb = sb;\n+\tinode-\u003ei_ino = ino;\n+\tinode-\u003ei_blkbits = sb-\u003es_blocksize_bits;\n+\n+\text4_es_init_tree(\u0026ei-\u003ei_es_tree);\n+\text4_init_pending_tree(\u0026ei-\u003ei_pending_tree);\n+\trwlock_init(\u0026ei-\u003ei_es_lock);\n+\tINIT_LIST_HEAD(\u0026ei-\u003ei_es_list);\n+\tinit_rwsem(\u0026ei-\u003ei_data_sem);\n+\tspin_lock_init(\u0026ei-\u003ei_block_reservation_lock);\n+\text4_set_inode_flag(inode, EXT4_INODE_EXTENTS);\n+}\n+\n+static void es_cleanup_inode(struct inode *inode)\n+{\n+\tstruct ext4_inode_info *ei = EXT4_I(inode);\n+\tstruct ext4_sb_info *sbi = EXT4_SB(inode-\u003ei_sb);\n+\tstruct rb_node *node;\n+\n+\tsbi-\u003es_mount_state \u0026= ~EXT4_FC_REPLAY;\n+\tes_remove_extent(inode, 0, EXT_MAX_BLOCKS);\n+\n+\twhile ((node = rb_first(\u0026ei-\u003ei_pending_tree.root)) != NULL) {\n+\t\tstruct pending_reservation *pr;\n+\n+\t\tpr = rb_entry(node, struct pending_reservation, rb_node);\n+\t\text4_remove_pending(inode, EXT4_C2B(sbi, pr-\u003elclu));\n+\t}\n+}\n+\n+KUNIT_DEFINE_ACTION_WRAPPER(es_cleanup_inode_action, es_cleanup_inode,\n+\t\t\t struct inode *);\n+KUNIT_DEFINE_ACTION_WRAPPER(es_unregister_shrinker_action,\n+\t\t\t ext4_es_unregister_shrinker,\n+\t\t\t struct ext4_sb_info *);\n+KUNIT_DEFINE_ACTION_WRAPPER(es_deactivate_super_action, deactivate_super,\n+\t\t\t struct super_block *);\n+\n+static struct inode *es_alloc_test_inode(struct kunit *test,\n+\t\t\t\t\t struct super_block *sb,\n+\t\t\t\t\t unsigned long ino)\n+{\n+\tstruct ext4_inode_info *ei;\n+\tint ret;\n+\n+\tei = kunit_kzalloc(test, sizeof(*ei), GFP_KERNEL);\n+\tKUNIT_ASSERT_NOT_NULL(test, ei);\n+\tes_init_mock_inode(ei, sb, ino);\n+\n+\tret = kunit_add_action_or_reset(test, es_cleanup_inode_action,\n+\t\t\t\t\t\u0026ei-\u003evfs_inode);\n+\tKUNIT_ASSERT_EQ(test, ret, 0);\n+\n+\treturn \u0026ei-\u003evfs_inode;\n+}\n+\n+static void es_set_cluster_bits(struct super_block *sb,\n+\t\t\t\tunsigned int cluster_bits)\n+{\n+\tstruct ext4_sb_info *sbi = EXT4_SB(sb);\n+\n+\tsbi-\u003es_cluster_bits = cluster_bits;\n+\tsbi-\u003es_cluster_ratio = 1U \u003c\u003c cluster_bits;\n+}\n+\n+/*\n+ * All test resources and deferred cleanup actions are registered with KUnit's\n+ * resource stack (test-\u003eresources), which unwinds in strict LIFO order after\n+ * each test case completes (or aborts).\n+ *\n+ * The registration order below (and in helpers like es_alloc_test_inode())\n+ * MUST be preserved when modifying these tests so that teardown happens in the\n+ * reverse order:\n+ * 1. kunit_kzalloc() of ctx, sbi, and ctx-\u003eei (freed last)\n+ * 2. es_deactivate_super_action(sb) (superblock deactivated after shrinker\n+ * and all inodes are torn down)\n+ * 3. es_unregister_shrinker_action(sbi) (shrinker and s_es_stats per-CPU\n+ * counters destroyed after all inode extent trees are emptied)\n+ * 4. kunit_activate_static_stub() for ext4_da_update_reserve_space,\n+ * ext4_da_release_space, and ext4_find_extent (stubs must remain active\n+ * while es_cleanup_inode() removes delayed extents via\n+ * ext4_es_remove_extent())\n+ * 5. es_cleanup_inode_action() for ctx-\u003eei and any additional test inodes\n+ * allocated via es_alloc_test_inode() (run first during teardown; inside\n+ * es_alloc_test_inode(), kunit_kzalloc() must precede\n+ * kunit_add_action_or_reset() so the inode is cleaned up before freed)\n+ */\n+static int es_kunit_init(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx;\n+\tstruct ext4_sb_info *sbi;\n+\tstruct super_block *sb;\n+\tstruct fs_context *fc;\n+\tint err;\n+\n+\tctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);\n+\tif (!ctx)\n+\t\treturn -ENOMEM;\n+\n+\tsbi = kunit_kzalloc(test, sizeof(*sbi), GFP_KERNEL);\n+\tif (!sbi)\n+\t\treturn -ENOMEM;\n+\n+\tctx-\u003eei = kunit_kzalloc(test, sizeof(*ctx-\u003eei), GFP_KERNEL);\n+\tif (!ctx-\u003eei)\n+\t\treturn -ENOMEM;\n+\n+\tfc = fs_context_for_mount(\u0026es_fs_type, 0);\n+\tif (IS_ERR(fc))\n+\t\treturn PTR_ERR(fc);\n+\n+\tsb = sget_fc(fc, NULL, es_set_anon);\n+\tput_fs_context(fc);\n+\tif (IS_ERR(sb))\n+\t\treturn PTR_ERR(sb);\n+\n+\tsbi-\u003es_sb = sb;\n+\tsb-\u003es_fs_info = sbi;\n+\tsb-\u003es_blocksize = 4096;\n+\tsb-\u003es_blocksize_bits = 12;\n+\tstrscpy(sb-\u003es_id, \"es_kunit\", sizeof(sb-\u003es_id));\n+\n+\tes_set_cluster_bits(sb, 0);\n+\tset_opt(sb, DELALLOC);\n+\tratelimit_state_init(\u0026sbi-\u003es_warning_ratelimit_state,\n+\t\t\t DEFAULT_RATELIMIT_INTERVAL,\n+\t\t\t DEFAULT_RATELIMIT_BURST);\n+\tup_write(\u0026sb-\u003es_umount);\n+\n+\terr = kunit_add_action_or_reset(test, es_deactivate_super_action, sb);\n+\tif (err)\n+\t\treturn err;\n+\n+\terr = ext4_es_register_shrinker(sbi);\n+\tif (err)\n+\t\treturn err;\n+\n+\t/*\n+\t * Detach the real callbacks from the globally registered shrinker\n+\t * before any extents are inserted so background kswapd / direct\n+\t * reclaim cannot asynchronously evict mock extents during a test.\n+\t */\n+\tctx-\u003eshrinker_count = sbi-\u003es_es_shrinker-\u003ecount_objects;\n+\tctx-\u003eshrinker_scan = sbi-\u003es_es_shrinker-\u003escan_objects;\n+\tWRITE_ONCE(sbi-\u003es_es_shrinker-\u003ecount_objects, es_dummy_shrinker_count);\n+\tWRITE_ONCE(sbi-\u003es_es_shrinker-\u003escan_objects, es_dummy_shrinker_scan);\n+\n+\terr = kunit_add_action_or_reset(test, es_unregister_shrinker_action,\n+\t\t\t\t\tsbi);\n+\tif (err)\n+\t\treturn err;\n+\n+\tctx-\u003esb = sb;\n+\tctx-\u003esbi = sbi;\n+\ttest-\u003epriv = ctx;\n+\n+\tkunit_activate_static_stub(test, ext4_da_update_reserve_space,\n+\t\t\t\t ext4_da_update_reserve_space_stub);\n+\tkunit_activate_static_stub(test, ext4_da_release_space,\n+\t\t\t\t ext4_da_release_space_stub);\n+\tkunit_activate_static_stub(test, ext4_find_extent,\n+\t\t\t\t ext4_find_extent_stub);\n+\n+\tes_init_mock_inode(ctx-\u003eei, sb, 12);\n+\terr = kunit_add_action_or_reset(test, es_cleanup_inode_action,\n+\t\t\t\t\t\u0026ctx-\u003eei-\u003evfs_inode);\n+\tif (err)\n+\t\treturn err;\n+\n+\treturn 0;\n+}\n+\n+static void assert_es_tree(struct kunit *test, struct inode *inode,\n+\t\t\t const struct expected_es *exp, unsigned int nr_exp)\n+{\n+\tstruct ext4_inode_info *ei = EXT4_I(inode);\n+\tstruct extent_status found[ES_MAX_EXPECTED_EXTENTS];\n+\tstruct rb_node *node;\n+\tunsigned int nr_found = 0;\n+\tunsigned int all_nr;\n+\tunsigned int i;\n+\text4_lblk_t prev_end = 0;\n+\n+\tKUNIT_ASSERT_LE(test, nr_exp, (unsigned int)ARRAY_SIZE(found));\n+\n+\t/*\n+\t * Snapshot the tree under i_es_lock and release the lock before\n+\t * running any KUnit assertions or expectations. KUNIT_ASSERT_*\n+\t * aborts the test kthread on failure (which would leak i_es_lock\n+\t * and deadlock es_cleanup_inode()), and KUNIT_EXPECT_* allocates\n+\t * failure logs with GFP_KERNEL.\n+\t */\n+\tread_lock(\u0026ei-\u003ei_es_lock);\n+\tfor (node = rb_first(\u0026ei-\u003ei_es_tree.root); node; node = rb_next(node)) {\n+\t\tstruct extent_status *es =\n+\t\t\trb_entry(node, struct extent_status, rb_node);\n+\n+\t\tif (nr_found \u003c ARRAY_SIZE(found))\n+\t\t\tfound[nr_found] = *es;\n+\t\tnr_found++;\n+\t}\n+\tall_nr = ei-\u003ei_es_all_nr;\n+\tread_unlock(\u0026ei-\u003ei_es_lock);\n+\n+\tfor (i = 0; i \u003c nr_found; i++) {\n+\t\tstruct extent_status *es = \u0026found[min(i,\n+\t\t\t\t(unsigned int)ARRAY_SIZE(found) - 1)];\n+\n+\t\tKUNIT_ASSERT_LT_MSG(test, i, nr_exp,\n+\t\t\t\t \"unexpected extra extent [%u/%u) type 0x%x\",\n+\t\t\t\t es-\u003ees_lblk, es-\u003ees_len, ext4_es_type(es));\n+\n+\t\tif (i \u003e 0)\n+\t\t\tKUNIT_EXPECT_GT_MSG(test, es-\u003ees_lblk, prev_end,\n+\t\t\t\t\t \"extent %u not strictly ordered\",\n+\t\t\t\t\t i);\n+\n+\t\tKUNIT_EXPECT_EQ_MSG(test, es-\u003ees_lblk, exp[i].lblk,\n+\t\t\t\t \"extent %u lblk mismatch\", i);\n+\t\tKUNIT_EXPECT_EQ_MSG(test, es-\u003ees_len, exp[i].len,\n+\t\t\t\t \"extent %u len mismatch\", i);\n+\t\tKUNIT_EXPECT_EQ_MSG(test, ext4_es_type(es), exp[i].type,\n+\t\t\t\t \"extent %u type mismatch\", i);\n+\n+\t\tif (exp[i].type \u0026 (EXTENT_STATUS_WRITTEN |\n+\t\t\t\t EXTENT_STATUS_UNWRITTEN))\n+\t\t\tKUNIT_EXPECT_EQ_MSG(test, ext4_es_pblock(es),\n+\t\t\t\t\t exp[i].pblk,\n+\t\t\t\t\t \"extent %u pblk mismatch\", i);\n+\n+\t\tprev_end = es-\u003ees_lblk + es-\u003ees_len - 1;\n+\t}\n+\n+\tKUNIT_EXPECT_EQ(test, nr_found, nr_exp);\n+\tKUNIT_EXPECT_EQ(test, all_nr, nr_exp);\n+}\n+\n+/*\n+ * Group 1: Bitfield Encoding \u0026 Inline Helpers\n+ */\n+static void test_es_bitfield_written_and_unwritten_encoding(struct kunit *test)\n+{\n+\tstruct extent_status es = {};\n+\tconst ext4_fsblk_t sample_pblk = 0x123456789abcULL;\n+\n+\text4_es_store_pblock_status(\u0026es, sample_pblk, EXTENT_STATUS_WRITTEN);\n+\tKUNIT_EXPECT_EQ(test, ext4_es_pblock(\u0026es), sample_pblk);\n+\tKUNIT_EXPECT_EQ(test, ext4_es_show_pblock(\u0026es), sample_pblk);\n+\tKUNIT_EXPECT_EQ(test, ext4_es_type(\u0026es), EXTENT_STATUS_WRITTEN);\n+\tKUNIT_EXPECT_EQ(test, ext4_es_status(\u0026es), EXTENT_STATUS_WRITTEN);\n+\tKUNIT_EXPECT_TRUE(test, ext4_es_is_written(\u0026es));\n+\tKUNIT_EXPECT_FALSE(test, ext4_es_is_unwritten(\u0026es));\n+\tKUNIT_EXPECT_FALSE(test, ext4_es_is_delayed(\u0026es));\n+\tKUNIT_EXPECT_FALSE(test, ext4_es_is_hole(\u0026es));\n+\tKUNIT_EXPECT_TRUE(test, ext4_es_is_mapped(\u0026es));\n+\tKUNIT_EXPECT_FALSE(test, ext4_es_is_referenced(\u0026es));\n+\n+\text4_es_store_pblock_status(\u0026es, sample_pblk, EXTENT_STATUS_UNWRITTEN);\n+\tKUNIT_EXPECT_EQ(test, ext4_es_pblock(\u0026es), sample_pblk);\n+\tKUNIT_EXPECT_TRUE(test, ext4_es_is_unwritten(\u0026es));\n+\tKUNIT_EXPECT_TRUE(test, ext4_es_is_mapped(\u0026es));\n+\tKUNIT_EXPECT_FALSE(test, ext4_es_is_written(\u0026es));\n+}\n+\n+static void test_es_bitfield_delayed_and_hole_encoding(struct kunit *test)\n+{\n+\tstruct extent_status es = {};\n+\t/* 59-bit physical block field (64 - 5 status bits) all ones */\n+\tconst ext4_fsblk_t max_59bit_pblk = 0x07ffffffffffffffULL;\n+\n+\text4_es_store_pblock_status(\u0026es, ~0ULL, EXTENT_STATUS_DELAYED);\n+\tKUNIT_EXPECT_TRUE(test, ext4_es_is_delayed(\u0026es));\n+\tKUNIT_EXPECT_FALSE(test, ext4_es_is_mapped(\u0026es));\n+\tKUNIT_EXPECT_EQ(test, ext4_es_pblock(\u0026es), max_59bit_pblk);\n+\tKUNIT_EXPECT_EQ(test, ext4_es_show_pblock(\u0026es), 0ULL);\n+\n+\text4_es_store_pblock_status(\u0026es, 0ULL, EXTENT_STATUS_HOLE);\n+\tKUNIT_EXPECT_TRUE(test, ext4_es_is_hole(\u0026es));\n+\tKUNIT_EXPECT_FALSE(test, ext4_es_is_mapped(\u0026es));\n+\tKUNIT_EXPECT_EQ(test, ext4_es_pblock(\u0026es), 0ULL);\n+}\n+\n+static void\n+test_es_bitfield_referenced_and_pblock_update_preserve_state(struct kunit *test)\n+{\n+\tstruct extent_status es = {};\n+\tconst ext4_fsblk_t initial_pblk = 0x123456789abcULL;\n+\tconst ext4_fsblk_t updated_pblk = 0x07ffffffffffffffULL;\n+\n+\text4_es_store_pblock_status(\u0026es, initial_pblk, EXTENT_STATUS_WRITTEN);\n+\n+\t/* Setting referenced bit preserves pblk and type */\n+\text4_es_set_referenced(\u0026es);\n+\tKUNIT_EXPECT_TRUE(test, ext4_es_is_referenced(\u0026es));\n+\tKUNIT_EXPECT_EQ(test, ext4_es_type(\u0026es), EXTENT_STATUS_WRITTEN);\n+\tKUNIT_EXPECT_EQ(test, ext4_es_pblock(\u0026es), initial_pblk);\n+\tKUNIT_EXPECT_EQ(test, ext4_es_status(\u0026es),\n+\t\t\tEXTENT_STATUS_WRITTEN | EXTENT_STATUS_REFERENCED);\n+\n+\t/* Updating pblock preserves status and referenced bit */\n+\text4_es_store_pblock(\u0026es, updated_pblk);\n+\tKUNIT_EXPECT_EQ(test, ext4_es_pblock(\u0026es), updated_pblk);\n+\tKUNIT_EXPECT_EQ(test, ext4_es_type(\u0026es), EXTENT_STATUS_WRITTEN);\n+\tKUNIT_EXPECT_TRUE(test, ext4_es_is_referenced(\u0026es));\n+\n+\t/* Clearing referenced bit preserves updated pblk and type */\n+\text4_es_clear_referenced(\u0026es);\n+\tKUNIT_EXPECT_FALSE(test, ext4_es_is_referenced(\u0026es));\n+\tKUNIT_EXPECT_EQ(test, ext4_es_pblock(\u0026es), updated_pblk);\n+\tKUNIT_EXPECT_EQ(test, ext4_es_type(\u0026es), EXTENT_STATUS_WRITTEN);\n+}\n+\n+/*\n+ * Group 2: Insertion, Lookup, Sequence Numbers, and Merging\n+ */\n+static void test_es_lookup_empty_tree_returns_miss(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\tstruct extent_status es;\n+\text4_lblk_t next_lblk = 0xdead;\n+\ts64 misses_before;\n+\tint ret;\n+\n+\tmisses_before = percpu_counter_sum_positive(\n+\t\t\u0026ctx-\u003esbi-\u003es_es_stats.es_stats_cache_misses);\n+\tret = ext4_es_lookup_extent(inode, 10, \u0026next_lblk, \u0026es, NULL);\n+\tKUNIT_EXPECT_EQ(test, ret, 0);\n+\tKUNIT_EXPECT_EQ(test, percpu_counter_sum_positive(\n+\t\t\u0026ctx-\u003esbi-\u003es_es_stats.es_stats_cache_misses),\n+\t\tmisses_before + 1);\n+}\n+\n+static void test_es_insert_zero_len_is_noop(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\n+\tes_insert_extent(inode, 10, 0, 100, EXTENT_STATUS_WRITTEN, false);\n+\tes_insert_delayed_extent(inode, 20, 0, false, false);\n+\tes_cache_extent(inode, 30, 0, 300, EXTENT_STATUS_WRITTEN);\n+\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003eei-\u003ei_es_all_nr, 0U);\n+\tKUNIT_EXPECT_TRUE(test, RB_EMPTY_ROOT(\u0026ctx-\u003eei-\u003ei_es_tree.root));\n+}\n+\n+static void\n+test_es_lookup_hits_cache_and_rbtree_with_next_lblk(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\tstruct extent_status es;\n+\text4_lblk_t next_lblk = 0xdead;\n+\tu64 seq_after_first, seq_after_second, lookup_seq = 0;\n+\ts64 hits_before;\n+\tint ret;\n+\n+\tes_insert_extent(inode, 10, 5, 100, EXTENT_STATUS_WRITTEN, false);\n+\tseq_after_first = ctx-\u003eei-\u003ei_es_seq;\n+\tes_insert_extent(inode, 20, 5, 200, EXTENT_STATUS_UNWRITTEN, false);\n+\tseq_after_second = ctx-\u003eei-\u003ei_es_seq;\n+\tKUNIT_EXPECT_GT(test, seq_after_second, seq_after_first);\n+\n+\t/*\n+\t * Right after inserting [20, 5), tree-\u003ecache_es points to [20, 5).\n+\t * Looking up lblk 22 hits cache_es and sets next_lblk to 0 because\n+\t * [20, 5) is the last extent in the tree.\n+\t */\n+\thits_before = percpu_counter_sum_positive(\n+\t\t\u0026ctx-\u003esbi-\u003es_es_stats.es_stats_cache_hits);\n+\n+\tret = ext4_es_lookup_extent(inode, 22, \u0026next_lblk, \u0026es, \u0026lookup_seq);\n+\tKUNIT_EXPECT_EQ(test, ret, 1);\n+\tKUNIT_EXPECT_EQ(test, es.es_lblk, 20U);\n+\tKUNIT_EXPECT_EQ(test, es.es_len, 5U);\n+\tKUNIT_EXPECT_EQ(test, ext4_es_pblock(\u0026es), 200ULL);\n+\tKUNIT_EXPECT_TRUE(test, ext4_es_is_unwritten(\u0026es));\n+\tKUNIT_EXPECT_EQ(test, next_lblk, 0U);\n+\tKUNIT_EXPECT_EQ(test, lookup_seq, seq_after_second);\n+\n+\t/* Lookup start, middle, and end of first extent [10, 5) via rb-tree */\n+\tret = ext4_es_lookup_extent(inode, 10, \u0026next_lblk, \u0026es, NULL);\n+\tKUNIT_EXPECT_EQ(test, ret, 1);\n+\tKUNIT_EXPECT_EQ(test, es.es_lblk, 10U);\n+\tKUNIT_EXPECT_EQ(test, next_lblk, 20U);\n+\n+\tret = ext4_es_lookup_extent(inode, 12, \u0026next_lblk, \u0026es, NULL);\n+\tKUNIT_EXPECT_EQ(test, ret, 1);\n+\tKUNIT_EXPECT_EQ(test, es.es_lblk, 10U);\n+\tKUNIT_EXPECT_EQ(test, next_lblk, 20U);\n+\n+\tret = ext4_es_lookup_extent(inode, 14, \u0026next_lblk, \u0026es, NULL);\n+\tKUNIT_EXPECT_EQ(test, ret, 1);\n+\tKUNIT_EXPECT_EQ(test, es.es_lblk, 10U);\n+\tKUNIT_EXPECT_EQ(test, next_lblk, 20U);\n+\n+\tKUNIT_EXPECT_EQ(test, percpu_counter_sum_positive(\n+\t\t\u0026ctx-\u003esbi-\u003es_es_stats.es_stats_cache_hits),\n+\t\thits_before + 4);\n+\n+\t/* Lookup in gap [15..19] returns 0 */\n+\tret = ext4_es_lookup_extent(inode, 15, \u0026next_lblk, \u0026es, NULL);\n+\tKUNIT_EXPECT_EQ(test, ret, 0);\n+}\n+\n+static void test_es_fc_replay_bypasses_tree_operations(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\tstruct extent_status es;\n+\tstatic const struct expected_es expected[] = {\n+\t\t{ .lblk = 10, .len = 5, .pblk = 100,\n+\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t};\n+\n+\tes_insert_extent(inode, 10, 5, 100, EXTENT_STATUS_WRITTEN, false);\n+\n+\tctx-\u003esbi-\u003es_mount_state |= EXT4_FC_REPLAY;\n+\tKUNIT_EXPECT_EQ(test,\n+\t\t\text4_es_lookup_extent(inode, 10, NULL, \u0026es, NULL), 0);\n+\text4_es_find_extent_range(inode, ext4_es_is_written, 0, 20, \u0026es);\n+\tKUNIT_EXPECT_EQ(test, es.es_len, 0U);\n+\tKUNIT_EXPECT_FALSE(test,\n+\t\t\t ext4_es_scan_range(inode, ext4_es_is_written,\n+\t\t\t\t\t 0, 20));\n+\tKUNIT_EXPECT_FALSE(test,\n+\t\t\t ext4_es_scan_clu(inode, ext4_es_is_written, 10));\n+\n+\tes_insert_extent(inode, 30, 5, 300, EXTENT_STATUS_WRITTEN, false);\n+\tes_cache_extent(inode, 40, 5, 400, EXTENT_STATUS_WRITTEN);\n+\tes_insert_delayed_extent(inode, 50, 5, false, false);\n+\tes_remove_extent(inode, 10, 5);\n+\tctx-\u003esbi-\u003es_mount_state \u0026= ~EXT4_FC_REPLAY;\n+\n+\tassert_es_tree(test, inode, expected, ARRAY_SIZE(expected));\n+}\n+\n+struct es_merge_test_param {\n+\tconst char *desc;\n+\tunsigned int nr_inserts;\n+\tstruct expected_es inserts[3];\n+\tunsigned int nr_expected;\n+\tstruct expected_es expected[3];\n+};\n+\n+static const struct es_merge_test_param es_merge_params[] = {\n+\t{\n+\t\t.desc = \"left merge contiguous written extents\",\n+\t\t.nr_inserts = 2,\n+\t\t.inserts = {\n+\t\t\t{ .lblk = 10, .len = 5, .pblk = 100,\n+\t\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t\t{ .lblk = 15, .len = 5, .pblk = 105,\n+\t\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t},\n+\t\t.nr_expected = 1,\n+\t\t.expected = {\n+\t\t\t{ .lblk = 10, .len = 10, .pblk = 100,\n+\t\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t},\n+\t},\n+\t{\n+\t\t.desc = \"right merge contiguous written extents\",\n+\t\t.nr_inserts = 2,\n+\t\t.inserts = {\n+\t\t\t{ .lblk = 15, .len = 5, .pblk = 105,\n+\t\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t\t{ .lblk = 10, .len = 5, .pblk = 100,\n+\t\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t},\n+\t\t.nr_expected = 1,\n+\t\t.expected = {\n+\t\t\t{ .lblk = 10, .len = 10, .pblk = 100,\n+\t\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t},\n+\t},\n+\t{\n+\t\t.desc = \"three-way bridge merge via try_to_merge_right\",\n+\t\t.nr_inserts = 3,\n+\t\t.inserts = {\n+\t\t\t{ .lblk = 10, .len = 5, .pblk = 100,\n+\t\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t\t{ .lblk = 20, .len = 5, .pblk = 110,\n+\t\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t\t{ .lblk = 15, .len = 5, .pblk = 105,\n+\t\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t},\n+\t\t.nr_expected = 1,\n+\t\t.expected = {\n+\t\t\t{ .lblk = 10, .len = 15, .pblk = 100,\n+\t\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t},\n+\t},\n+\t{\n+\t\t.desc = \"three-way bridge merge via try_to_merge_left\",\n+\t\t.nr_inserts = 3,\n+\t\t.inserts = {\n+\t\t\t{ .lblk = 20, .len = 5, .pblk = 110,\n+\t\t\t .type = EXTENT_STATUS_UNWRITTEN },\n+\t\t\t{ .lblk = 10, .len = 5, .pblk = 100,\n+\t\t\t .type = EXTENT_STATUS_UNWRITTEN },\n+\t\t\t{ .lblk = 15, .len = 5, .pblk = 105,\n+\t\t\t .type = EXTENT_STATUS_UNWRITTEN },\n+\t\t},\n+\t\t.nr_expected = 1,\n+\t\t.expected = {\n+\t\t\t{ .lblk = 10, .len = 15, .pblk = 100,\n+\t\t\t .type = EXTENT_STATUS_UNWRITTEN },\n+\t\t},\n+\t},\n+\t{\n+\t\t.desc = \"adjacent hole extents merge\",\n+\t\t.nr_inserts = 2,\n+\t\t.inserts = {\n+\t\t\t{ .lblk = 10, .len = 5, .pblk = 0,\n+\t\t\t .type = EXTENT_STATUS_HOLE },\n+\t\t\t{ .lblk = 15, .len = 5, .pblk = 0,\n+\t\t\t .type = EXTENT_STATUS_HOLE },\n+\t\t},\n+\t\t.nr_expected = 1,\n+\t\t.expected = {\n+\t\t\t{ .lblk = 10, .len = 10, .pblk = 0,\n+\t\t\t .type = EXTENT_STATUS_HOLE },\n+\t\t},\n+\t},\n+\t{\n+\t\t.desc = \"discontiguous physical blocks do not merge\",\n+\t\t.nr_inserts = 2,\n+\t\t.inserts = {\n+\t\t\t{ .lblk = 10, .len = 5, .pblk = 100,\n+\t\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t\t{ .lblk = 15, .len = 5, .pblk = 200,\n+\t\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t},\n+\t\t.nr_expected = 2,\n+\t\t.expected = {\n+\t\t\t{ .lblk = 10, .len = 5, .pblk = 100,\n+\t\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t\t{ .lblk = 15, .len = 5, .pblk = 200,\n+\t\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t},\n+\t},\n+\t{\n+\t\t.desc = \"different status types with contiguous pblk do not merge\",\n+\t\t.nr_inserts = 2,\n+\t\t.inserts = {\n+\t\t\t{ .lblk = 10, .len = 5, .pblk = 100,\n+\t\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t\t{ .lblk = 15, .len = 5, .pblk = 105,\n+\t\t\t .type = EXTENT_STATUS_UNWRITTEN },\n+\t\t},\n+\t\t.nr_expected = 2,\n+\t\t.expected = {\n+\t\t\t{ .lblk = 10, .len = 5, .pblk = 100,\n+\t\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t\t{ .lblk = 15, .len = 5, .pblk = 105,\n+\t\t\t .type = EXTENT_STATUS_UNWRITTEN },\n+\t\t},\n+\t},\n+\t{\n+\t\t.desc = \"logically separated extents with 1-block gap do not merge\",\n+\t\t.nr_inserts = 2,\n+\t\t.inserts = {\n+\t\t\t{ .lblk = 10, .len = 5, .pblk = 100,\n+\t\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t\t{ .lblk = 16, .len = 5, .pblk = 106,\n+\t\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t},\n+\t\t.nr_expected = 2,\n+\t\t.expected = {\n+\t\t\t{ .lblk = 10, .len = 5, .pblk = 100,\n+\t\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t\t{ .lblk = 16, .len = 5, .pblk = 106,\n+\t\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t},\n+\t},\n+};\n+\n+static void es_merge_get_desc(const struct es_merge_test_param *param,\n+\t\t\t char *desc)\n+{\n+\tstrscpy(desc, param-\u003edesc, KUNIT_PARAM_DESC_SIZE);\n+}\n+KUNIT_ARRAY_PARAM(es_merge, es_merge_params, es_merge_get_desc);\n+\n+static void test_es_merge_cases(struct kunit *test)\n+{\n+\tconst struct es_merge_test_param *param = test-\u003eparam_value;\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\tunsigned int i;\n+\n+\tfor (i = 0; i \u003c param-\u003enr_inserts; i++) {\n+\t\tconst struct expected_es *ins = \u0026param-\u003einserts[i];\n+\n+\t\tes_insert_extent(inode, ins-\u003elblk, ins-\u003elen,\n+\t\t\t\t ins-\u003epblk, ins-\u003etype, false);\n+\t}\n+\n+\tassert_es_tree(test, inode, param-\u003eexpected, param-\u003enr_expected);\n+}\n+\n+static void test_es_insert_adjacent_delayed_extents_merges(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\tstatic const struct expected_es expected[] = {\n+\t\t{ .lblk = 10, .len = 10, .pblk = 0,\n+\t\t .type = EXTENT_STATUS_DELAYED },\n+\t};\n+\n+\tes_insert_delayed_extent(inode, 10, 5, false, false);\n+\tes_insert_delayed_extent(inode, 15, 5, false, false);\n+\n+\tassert_es_tree(test, inode, expected, ARRAY_SIZE(expected));\n+}\n+\n+static void test_es_merge_preserves_referenced(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\tstruct extent_status es;\n+\tstruct rb_node *node;\n+\tbool is_ref = false;\n+\n+\t/*\n+\t * Insert [10, 5) and [20, 5), mark [20, 5) referenced via lookup,\n+\t * then bridge [15, 5) so [20, 5) is merged into [10, 10) via\n+\t * ext4_es_try_to_merge_right().\n+\t */\n+\tes_insert_extent(inode, 10, 5, 100, EXTENT_STATUS_WRITTEN, false);\n+\tes_insert_extent(inode, 20, 5, 110, EXTENT_STATUS_WRITTEN, false);\n+\tKUNIT_ASSERT_EQ(test,\n+\t\t\text4_es_lookup_extent(inode, 20, NULL, \u0026es, NULL), 1);\n+\n+\tes_insert_extent(inode, 15, 5, 105, EXTENT_STATUS_WRITTEN, false);\n+\tKUNIT_ASSERT_EQ(test, ctx-\u003eei-\u003ei_es_all_nr, 1U);\n+\n+\tread_lock(\u0026ctx-\u003eei-\u003ei_es_lock);\n+\tnode = rb_first(\u0026ctx-\u003eei-\u003ei_es_tree.root);\n+\tif (node)\n+\t\tis_ref = ext4_es_is_referenced(rb_entry(node,\n+\t\t\t\t\t\t\tstruct extent_status,\n+\t\t\t\t\t\t\trb_node));\n+\tread_unlock(\u0026ctx-\u003eei-\u003ei_es_lock);\n+\n+\tKUNIT_ASSERT_NOT_NULL(test, node);\n+\tKUNIT_EXPECT_TRUE(test, is_ref);\n+}\n+\n+static void\n+test_es_merge_at_max_blocks_boundary_succeeds(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\tstatic const struct expected_es expected[] = {\n+\t\t{ .lblk = 0, .len = EXT_MAX_BLOCKS, .pblk = 100,\n+\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t};\n+\n+\tes_insert_extent(inode, 0, 0x80000000U, 100,\n+\t\t\t EXTENT_STATUS_WRITTEN, false);\n+\tes_insert_extent(inode, 0x80000000U, 0x7fffffffU,\n+\t\t\t 100ULL + 0x80000000ULL,\n+\t\t\t EXTENT_STATUS_WRITTEN, false);\n+\n+\tassert_es_tree(test, inode, expected, ARRAY_SIZE(expected));\n+}\n+\n+/*\n+ * Group 3: Removal, Trimming, Splitting, and Overwrites\n+ */\n+struct es_remove_test_param {\n+\tconst char *desc;\n+\text4_lblk_t rem_lblk;\n+\text4_lblk_t rem_len;\n+\tunsigned int nr_expected;\n+\tstruct expected_es expected[2];\n+};\n+\n+static const struct es_remove_test_param es_remove_params[] = {\n+\t{\n+\t\t.desc = \"remove range before extent\",\n+\t\t.rem_lblk = 0,\n+\t\t.rem_len = 5,\n+\t\t.nr_expected = 1,\n+\t\t.expected = {\n+\t\t\t{ .lblk = 10, .len = 10, .pblk = 100,\n+\t\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t},\n+\t},\n+\t{\n+\t\t.desc = \"remove range after extent\",\n+\t\t.rem_lblk = 20,\n+\t\t.rem_len = 5,\n+\t\t.nr_expected = 1,\n+\t\t.expected = {\n+\t\t\t{ .lblk = 10, .len = 10, .pblk = 100,\n+\t\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t},\n+\t},\n+\t{\n+\t\t.desc = \"remove exact extent range\",\n+\t\t.rem_lblk = 10,\n+\t\t.rem_len = 10,\n+\t\t.nr_expected = 0,\n+\t},\n+\t{\n+\t\t.desc = \"remove superset of extent range\",\n+\t\t.rem_lblk = 5,\n+\t\t.rem_len = 20,\n+\t\t.nr_expected = 0,\n+\t},\n+\t{\n+\t\t.desc = \"prefix trim of extent\",\n+\t\t.rem_lblk = 10,\n+\t\t.rem_len = 4,\n+\t\t.nr_expected = 1,\n+\t\t.expected = {\n+\t\t\t{ .lblk = 14, .len = 6, .pblk = 104,\n+\t\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t},\n+\t},\n+\t{\n+\t\t.desc = \"suffix trim of extent\",\n+\t\t.rem_lblk = 16,\n+\t\t.rem_len = 4,\n+\t\t.nr_expected = 1,\n+\t\t.expected = {\n+\t\t\t{ .lblk = 10, .len = 6, .pblk = 100,\n+\t\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t},\n+\t},\n+\t{\n+\t\t.desc = \"middle split of extent into two\",\n+\t\t.rem_lblk = 13,\n+\t\t.rem_len = 4,\n+\t\t.nr_expected = 2,\n+\t\t.expected = {\n+\t\t\t{ .lblk = 10, .len = 3, .pblk = 100,\n+\t\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t\t{ .lblk = 17, .len = 3, .pblk = 107,\n+\t\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t},\n+\t},\n+};\n+\n+static void es_remove_get_desc(const struct es_remove_test_param *param,\n+\t\t\t char *desc)\n+{\n+\tstrscpy(desc, param-\u003edesc, KUNIT_PARAM_DESC_SIZE);\n+}\n+KUNIT_ARRAY_PARAM(es_remove, es_remove_params, es_remove_get_desc);\n+\n+static void test_es_remove_geometries(struct kunit *test)\n+{\n+\tconst struct es_remove_test_param *param = test-\u003eparam_value;\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\n+\tes_insert_extent(inode, 10, 10, 100, EXTENT_STATUS_WRITTEN, false);\n+\tes_remove_extent(inode, param-\u003erem_lblk, param-\u003erem_len);\n+\n+\tassert_es_tree(test, inode, param-\u003eexpected, param-\u003enr_expected);\n+}\n+\n+static void\n+test_es_remove_multi_extent_span_trims_and_deletes(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\tstatic const struct expected_es expected[] = {\n+\t\t{ .lblk = 10, .len = 2, .pblk = 100,\n+\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t{ .lblk = 43, .len = 2, .pblk = 403,\n+\t\t .type = EXTENT_STATUS_UNWRITTEN },\n+\t};\n+\n+\tes_insert_extent(inode, 10, 5, 100, EXTENT_STATUS_WRITTEN, false);\n+\tes_insert_extent(inode, 20, 5, 200, EXTENT_STATUS_HOLE, false);\n+\tes_insert_extent(inode, 30, 5, 300, EXTENT_STATUS_WRITTEN, false);\n+\tes_insert_extent(inode, 40, 5, 400, EXTENT_STATUS_UNWRITTEN, false);\n+\n+\t/*\n+\t * Remove [12, 31) covering lblks 12..42 inclusive:\n+\t * - trims suffix of [10, 5) -\u003e [10, 2)\n+\t * - completely removes [20, 5) and [30, 5)\n+\t * - trims prefix of [40, 5) -\u003e [43, 2)\n+\t */\n+\tes_remove_extent(inode, 12, 31);\n+\tassert_es_tree(test, inode, expected, ARRAY_SIZE(expected));\n+}\n+\n+static void test_es_insert_overwrite_split_and_remerge(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\tstatic const struct expected_es split_exp[] = {\n+\t\t{ .lblk = 10, .len = 3, .pblk = 100,\n+\t\t .type = EXTENT_STATUS_UNWRITTEN },\n+\t\t{ .lblk = 13, .len = 4, .pblk = 103,\n+\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t{ .lblk = 17, .len = 3, .pblk = 107,\n+\t\t .type = EXTENT_STATUS_UNWRITTEN },\n+\t};\n+\tstatic const struct expected_es merged_exp[] = {\n+\t\t{ .lblk = 10, .len = 10, .pblk = 100,\n+\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t};\n+\n+\tes_insert_extent(inode, 10, 10, 100, EXTENT_STATUS_UNWRITTEN, false);\n+\tes_insert_extent(inode, 13, 4, 103, EXTENT_STATUS_WRITTEN, false);\n+\tassert_es_tree(test, inode, split_exp, ARRAY_SIZE(split_exp));\n+\n+\t/* Convert the remaining prefix and suffix to WRITTEN; all 3 merge */\n+\tes_insert_extent(inode, 10, 3, 100, EXTENT_STATUS_WRITTEN, false);\n+\tes_insert_extent(inode, 17, 3, 107, EXTENT_STATUS_WRITTEN, false);\n+\tassert_es_tree(test, inode, merged_exp, ARRAY_SIZE(merged_exp));\n+}\n+\n+/*\n+ * Group 4: On-Disk Caching \u0026 Conflict Detection (ext4_es_cache_extent)\n+ */\n+static void\n+test_es_cache_extent_inserts_and_coalesces_same_status(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\tstatic const struct expected_es initial_exp[] = {\n+\t\t{ .lblk = 10, .len = 5, .pblk = 100,\n+\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t};\n+\tstatic const struct expected_es coalesced_exp[] = {\n+\t\t{ .lblk = 8, .len = 10, .pblk = 98,\n+\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t};\n+\tint warnings_before;\n+\n+\twarnings_before = atomic_read(\u0026ctx-\u003esbi-\u003es_warning_count);\n+\n+\t/* Cache into empty tree */\n+\tes_cache_extent(inode, 10, 5, 100, EXTENT_STATUS_WRITTEN);\n+\tassert_es_tree(test, inode, initial_exp, ARRAY_SIZE(initial_exp));\n+\n+\t/* Caching sub-range with identical status is a no-op */\n+\tes_cache_extent(inode, 11, 2, 101, EXTENT_STATUS_WRITTEN);\n+\tassert_es_tree(test, inode, initial_exp, ARRAY_SIZE(initial_exp));\n+\n+\t/* Caching larger covering range with same status coalesces */\n+\tes_cache_extent(inode, 8, 10, 98, EXTENT_STATUS_WRITTEN);\n+\tKUNIT_EXPECT_EQ(test, atomic_read(\u0026ctx-\u003esbi-\u003es_warning_count),\n+\t\t\twarnings_before);\n+\tassert_es_tree(test, inode, coalesced_exp, ARRAY_SIZE(coalesced_exp));\n+}\n+\n+static void\n+test_es_cache_extent_conflict_covered_range_warns(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\tstatic const struct expected_es expected[] = {\n+\t\t{ .lblk = 8, .len = 10, .pblk = 98,\n+\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t};\n+\tint warnings_before;\n+\n+\tes_cache_extent(inode, 8, 10, 98, EXTENT_STATUS_WRITTEN);\n+\twarnings_before = atomic_read(\u0026ctx-\u003esbi-\u003es_warning_count);\n+\n+\t/* Sub-range [10, 4) covered by [8, 10) with conflicting status */\n+\tes_cache_extent(inode, 10, 4, 500, EXTENT_STATUS_UNWRITTEN);\n+\tKUNIT_EXPECT_EQ(test, atomic_read(\u0026ctx-\u003esbi-\u003es_warning_count),\n+\t\t\twarnings_before + 1);\n+\tassert_es_tree(test, inode, expected, ARRAY_SIZE(expected));\n+}\n+\n+static void\n+test_es_cache_extent_conflict_partial_overlap_warns(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\tstatic const struct expected_es expected[] = {\n+\t\t{ .lblk = 10, .len = 5, .pblk = 100,\n+\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t};\n+\tint warnings_before;\n+\n+\tes_cache_extent(inode, 10, 5, 100, EXTENT_STATUS_WRITTEN);\n+\twarnings_before = atomic_read(\u0026ctx-\u003esbi-\u003es_warning_count);\n+\n+\t/*\n+\t * Range [8, 10) is not covered by [10, 5), so ext4_es_cache_extent()\n+\t * enters __es_remove_extent() which detects the status conflict and\n+\t * returns -EINVAL without modifying [10, 5).\n+\t */\n+\tes_cache_extent(inode, 8, 10, 500, EXTENT_STATUS_UNWRITTEN);\n+\tKUNIT_EXPECT_EQ(test, atomic_read(\u0026ctx-\u003esbi-\u003es_warning_count),\n+\t\t\twarnings_before + 1);\n+\tassert_es_tree(test, inode, expected, ARRAY_SIZE(expected));\n+}\n+\n+static void\n+test_es_cache_extent_hole_over_delayed_does_not_warn(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\tstatic const struct expected_es expected[] = {\n+\t\t{ .lblk = 30, .len = 5, .pblk = 0,\n+\t\t .type = EXTENT_STATUS_DELAYED },\n+\t};\n+\tint warnings_before;\n+\n+\tes_insert_delayed_extent(inode, 30, 5, false, false);\n+\twarnings_before = atomic_read(\u0026ctx-\u003esbi-\u003es_warning_count);\n+\n+\tes_cache_extent(inode, 30, 5, 0, EXTENT_STATUS_HOLE);\n+\tKUNIT_EXPECT_EQ(test, atomic_read(\u0026ctx-\u003esbi-\u003es_warning_count),\n+\t\t\twarnings_before);\n+\tassert_es_tree(test, inode, expected, ARRAY_SIZE(expected));\n+}\n+\n+/*\n+ * Group 5: Range Search \u0026 Cluster Scanning\n+ */\n+static void\n+test_es_find_extent_range_skips_nonmatching_and_finds_next(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\tstruct extent_status es;\n+\n+\tes_insert_extent(inode, 10, 5, 100, EXTENT_STATUS_WRITTEN, false);\n+\tes_insert_delayed_extent(inode, 20, 5, false, false);\n+\tes_insert_extent(inode, 30, 5, 300, EXTENT_STATUS_UNWRITTEN, false);\n+\n+\t/*\n+\t * Prime cache_es to [10, 5) WRITTEN, then search [10, 25] for DELAYED:\n+\t * cache_es is hit at lblk 10, fails matching_fn(ext4_es_is_delayed),\n+\t * and walks rb_next to find [20, 5) DELAYED.\n+\t */\n+\tKUNIT_ASSERT_EQ(test,\n+\t\t\text4_es_lookup_extent(inode, 10, NULL, \u0026es, NULL), 1);\n+\text4_es_find_extent_range(inode, ext4_es_is_delayed, 10, 25, \u0026es);\n+\tKUNIT_EXPECT_EQ(test, es.es_lblk, 20U);\n+\tKUNIT_EXPECT_EQ(test, es.es_len, 5U);\n+\tKUNIT_EXPECT_TRUE(test, ext4_es_is_delayed(\u0026es));\n+\n+\t/* Search [10, 18] for DELAYED when starting inside [10, 5) returns 0 */\n+\tKUNIT_ASSERT_EQ(test,\n+\t\t\text4_es_lookup_extent(inode, 10, NULL, \u0026es, NULL), 1);\n+\text4_es_find_extent_range(inode, ext4_es_is_delayed, 10, 18, \u0026es);\n+\tKUNIT_EXPECT_EQ(test, es.es_len, 0U);\n+\n+\t/*\n+\t * Search [16, 18] in gap before [20, 5): __es_tree_search(16) returns\n+\t * the next extent [20, 5) following the range.\n+\t */\n+\text4_es_find_extent_range(inode, ext4_es_is_delayed, 16, 18, \u0026es);\n+\tKUNIT_EXPECT_EQ(test, es.es_lblk, 20U);\n+\tKUNIT_EXPECT_EQ(test, es.es_len, 5U);\n+}\n+\n+static void\n+test_es_scan_range_matches_only_overlapping_extents(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\n+\tes_insert_delayed_extent(inode, 20, 5, false, false);\n+\tes_insert_extent(inode, 30, 5, 300, EXTENT_STATUS_UNWRITTEN, false);\n+\n+\t/* Gap [16, 18] before [20, 5) does not overlap */\n+\tKUNIT_EXPECT_FALSE(test,\n+\t\t\t ext4_es_scan_range(inode, ext4_es_is_delayed,\n+\t\t\t\t\t 16, 18));\n+\n+\t/* Ranges overlapping [20, 5) or [30, 5) return true */\n+\tKUNIT_EXPECT_TRUE(test,\n+\t\t\t ext4_es_scan_range(inode, ext4_es_is_delayed,\n+\t\t\t\t\t 16, 20));\n+\tKUNIT_EXPECT_TRUE(test,\n+\t\t\t ext4_es_scan_range(inode, ext4_es_is_delayed,\n+\t\t\t\t\t 22, 23));\n+\tKUNIT_EXPECT_TRUE(test,\n+\t\t\t ext4_es_scan_range(inode, ext4_es_is_mapped,\n+\t\t\t\t\t 34, 40));\n+\n+\t/* Range [35, 40] after [30, 5) does not overlap */\n+\tKUNIT_EXPECT_FALSE(test,\n+\t\t\t ext4_es_scan_range(inode, ext4_es_is_mapped,\n+\t\t\t\t\t 35, 40));\n+}\n+\n+static void test_es_scan_clu_matches_extent_in_same_cluster(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\n+\t/* Configure cluster size = 16 blocks (cluster_bits = 4) */\n+\tes_set_cluster_bits(ctx-\u003esb, 4);\n+\n+\t/* Insert delayed block at the very end of cluster 0 (lblk 15) */\n+\tes_insert_delayed_extent(inode, 15, 1, false, false);\n+\n+\tKUNIT_EXPECT_TRUE(test,\n+\t\t\t ext4_es_scan_clu(inode, ext4_es_is_delayed, 0));\n+\tKUNIT_EXPECT_TRUE(test,\n+\t\t\t ext4_es_scan_clu(inode, ext4_es_is_delayed, 8));\n+\tKUNIT_EXPECT_TRUE(test,\n+\t\t\t ext4_es_scan_clu(inode, ext4_es_is_delayed, 15));\n+\tKUNIT_EXPECT_FALSE(test,\n+\t\t\t ext4_es_scan_clu(inode, ext4_es_is_delayed, 16));\n+\tKUNIT_EXPECT_FALSE(test,\n+\t\t\t ext4_es_scan_clu(inode, ext4_es_is_mapped, 0));\n+}\n+\n+/*\n+ * Group 6: Delayed Allocation \u0026 Bigalloc Pending Reservations\n+ */\n+static void\n+test_es_delalloc_remove_and_overwrite_account_reserved_blocks(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\tstatic const struct expected_es after_rem_exp[] = {\n+\t\t{ .lblk = 10, .len = 2, .pblk = 0,\n+\t\t .type = EXTENT_STATUS_DELAYED },\n+\t\t{ .lblk = 15, .len = 5, .pblk = 0,\n+\t\t .type = EXTENT_STATUS_DELAYED },\n+\t};\n+\tstatic const struct expected_es after_ins_exp[] = {\n+\t\t{ .lblk = 10, .len = 6, .pblk = 100,\n+\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t{ .lblk = 16, .len = 4, .pblk = 0,\n+\t\t .type = EXTENT_STATUS_DELAYED },\n+\t};\n+\n+\t/* Delayed extents are must-keep: i_es_shk_nr remains 0 */\n+\tes_insert_delayed_extent(inode, 10, 10, false, false);\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003eei-\u003ei_es_all_nr, 1U);\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003eei-\u003ei_es_shk_nr, 0U);\n+\tKUNIT_EXPECT_TRUE(test, list_empty(\u0026ctx-\u003eei-\u003ei_es_list));\n+\n+\t/* Removing 3 delayed blocks [12, 3) releases 3 reserved blocks */\n+\treset_da_stub_stats(ctx);\n+\tes_remove_extent(inode, 12, 3);\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003eda_release_calls, 1);\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003elast_da_released, 3);\n+\tassert_es_tree(test, inode, after_rem_exp, ARRAY_SIZE(after_rem_exp));\n+\n+\t/*\n+\t * Inserting WRITTEN [10, 6) overwrites [10, 2) delayed, [12, 3) gap,\n+\t * and [15, 1) delayed -\u003e claims 3 delayed blocks of reservation.\n+\t */\n+\treset_da_stub_stats(ctx);\n+\tes_insert_extent(inode, 10, 6, 100, EXTENT_STATUS_WRITTEN, true);\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003eda_update_calls, 1);\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003elast_da_used, 3);\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003elast_da_quota_claim, 1);\n+\tassert_es_tree(test, inode, after_ins_exp, ARRAY_SIZE(after_ins_exp));\n+}\n+\n+static void\n+test_es_bigalloc_insert_delayed_creates_and_removes_pending(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\n+\t/* Cluster size = 16 blocks: clu 0=[0..15], clu 1=[16..31], clu 2=[32..47] */\n+\tes_set_cluster_bits(ctx-\u003esb, 4);\n+\n+\t/* Single cluster with lclu_allocated = true */\n+\tes_insert_delayed_extent(inode, 2, 4, true, false);\n+\tKUNIT_EXPECT_TRUE(test, ext4_is_pending(inode, 0));\n+\tKUNIT_EXPECT_TRUE(test, ext4_is_pending(inode, 15));\n+\tKUNIT_EXPECT_FALSE(test, ext4_is_pending(inode, 16));\n+\n+\t/* Multi-cluster [20, 20) spanning clusters 1 and 2, both allocated */\n+\tes_insert_delayed_extent(inode, 20, 20, true, true);\n+\tKUNIT_EXPECT_TRUE(test, ext4_is_pending(inode, 16));\n+\tKUNIT_EXPECT_TRUE(test, ext4_is_pending(inode, 32));\n+\tKUNIT_EXPECT_FALSE(test, ext4_is_pending(inode, 48));\n+\n+\t/* Duplicate pending insertion on cluster 0 is idempotent */\n+\tes_insert_delayed_extent(inode, 8, 2, true, false);\n+\tKUNIT_EXPECT_TRUE(test, ext4_is_pending(inode, 0));\n+\n+\t/* Explicit removal of pending reservation */\n+\text4_remove_pending(inode, 16);\n+\tKUNIT_EXPECT_FALSE(test, ext4_is_pending(inode, 16));\n+\tKUNIT_EXPECT_TRUE(test, ext4_is_pending(inode, 32));\n+}\n+\n+static void\n+test_es_bigalloc_revise_pending_single_cluster_halves(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\n+\t/* Cluster size = 16 blocks */\n+\tes_set_cluster_bits(ctx-\u003esb, 4);\n+\n+\t/* Insert delayed extent [0, 32) covering clusters 0 and 1 */\n+\tes_insert_delayed_extent(inode, 0, 32, false, false);\n+\n+\t/*\n+\t * 1. Allocate first half of cluster 0: [0, 8) -\u003e WRITTEN.\n+\t * Delayed blocks [8, 8) remain after [0, 8) in cluster 0 (l_del=true):\n+\t * __revise_pending inserts pending on cluster 0 and claims 1 cluster.\n+\t */\n+\treset_da_stub_stats(ctx);\n+\tes_insert_extent(inode, 0, 8, 100, EXTENT_STATUS_WRITTEN, true);\n+\tKUNIT_EXPECT_TRUE(test, ext4_is_pending(inode, 0));\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003eda_update_calls, 1);\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003elast_da_used, 1);\n+\n+\t/*\n+\t * 2. Allocate second half of cluster 0: [8, 8) -\u003e WRITTEN.\n+\t * No delayed blocks remain in cluster 0; pending reservation on\n+\t * cluster 0 is removed and 0 additional clusters are claimed.\n+\t */\n+\treset_da_stub_stats(ctx);\n+\tes_insert_extent(inode, 8, 8, 108, EXTENT_STATUS_WRITTEN, true);\n+\tKUNIT_EXPECT_FALSE(test, ext4_is_pending(inode, 0));\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003eda_update_calls, 0);\n+\n+\t/*\n+\t * 3. Allocate second half of cluster 1 first: [24, 8) -\u003e WRITTEN while\n+\t * [16, 8) remains delayed before it in cluster 1 (f_del=true branch in\n+\t * __revise_pending): inserts pending on cluster 1 and claims 1 cluster.\n+\t */\n+\treset_da_stub_stats(ctx);\n+\tes_insert_extent(inode, 24, 8, 224, EXTENT_STATUS_WRITTEN, true);\n+\tKUNIT_EXPECT_TRUE(test, ext4_is_pending(inode, 16));\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003eda_update_calls, 1);\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003elast_da_used, 1);\n+}\n+\n+static void\n+test_es_bigalloc_revise_pending_multi_cluster_span(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\n+\t/* Cluster size = 16 blocks */\n+\tes_set_cluster_bits(ctx-\u003esb, 4);\n+\n+\t/*\n+\t * Insert delayed [16, 32) across cluster 1 [16..31] and cluster 2\n+\t * [32..47], then allocate [20, 24) (lblks 20..43), leaving delayed\n+\t * [16, 4) in cluster 1 and delayed [44, 4) in cluster 2. Both clusters\n+\t * get pending reservations and 2 clusters are claimed.\n+\t */\n+\tes_insert_delayed_extent(inode, 16, 32, false, false);\n+\treset_da_stub_stats(ctx);\n+\tes_insert_extent(inode, 20, 24, 220, EXTENT_STATUS_WRITTEN, true);\n+\tKUNIT_EXPECT_TRUE(test, ext4_is_pending(inode, 16));\n+\tKUNIT_EXPECT_TRUE(test, ext4_is_pending(inode, 32));\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003eda_update_calls, 1);\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003elast_da_used, 2);\n+}\n+\n+static void\n+test_es_bigalloc_remove_partial_cluster_holds_rsvd_until_empty(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\n+\t/* Cluster size = 16 blocks */\n+\tes_set_cluster_bits(ctx-\u003esb, 4);\n+\n+\tes_insert_delayed_extent(inode, 0, 16, false, false);\n+\treset_da_stub_stats(ctx);\n+\n+\tes_remove_extent(inode, 0, 4);\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003eda_release_calls, 0);\n+\n+\tes_remove_extent(inode, 12, 4);\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003eda_release_calls, 0);\n+\n+\tes_remove_extent(inode, 4, 8);\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003eda_release_calls, 1);\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003elast_da_released, 1);\n+}\n+\n+static void\n+test_es_bigalloc_remove_fragmented_cluster_releases_once(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\n+\t/* Cluster size = 16 blocks */\n+\tes_set_cluster_bits(ctx-\u003esb, 4);\n+\n+\t/*\n+\t * Two fragmented delayed extents within cluster 0 ([2, 3) and [10, 3))\n+\t * share a single cluster reservation and must release 1 cluster, not 2.\n+\t */\n+\tes_insert_delayed_extent(inode, 2, 3, false, false);\n+\tes_insert_delayed_extent(inode, 10, 3, false, false);\n+\treset_da_stub_stats(ctx);\n+\n+\tes_remove_extent(inode, 0, 16);\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003eda_release_calls, 1);\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003elast_da_released, 1);\n+}\n+\n+static void\n+test_es_bigalloc_remove_pending_cluster_cancels_pending_only(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\n+\t/* Cluster size = 16 blocks */\n+\tes_set_cluster_bits(ctx-\u003esb, 4);\n+\n+\t/*\n+\t * Removing a delayed extent in a cluster with a pending reservation\n+\t * cancels the pending reservation and releases 0 clusters (because the\n+\t * cluster reservation was already claimed when allocated).\n+\t */\n+\tes_insert_delayed_extent(inode, 16, 8, true, false);\n+\tKUNIT_ASSERT_TRUE(test, ext4_is_pending(inode, 16));\n+\treset_da_stub_stats(ctx);\n+\n+\tes_remove_extent(inode, 16, 8);\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003eda_release_calls, 0);\n+\tKUNIT_EXPECT_FALSE(test, ext4_is_pending(inode, 16));\n+}\n+\n+/*\n+ * Group 7: Shrinker, Referenced Aging, and Cache Clearing\n+ */\n+static void\n+test_es_clear_inode_es_retains_only_delayed_extents(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\tstatic const struct expected_es only_delayed_exp[] = {\n+\t\t{ .lblk = 40, .len = 5, .pblk = 0,\n+\t\t .type = EXTENT_STATUS_DELAYED },\n+\t};\n+\n+\tes_insert_extent(inode, 10, 5, 100, EXTENT_STATUS_WRITTEN, false);\n+\tes_insert_extent(inode, 20, 5, 200, EXTENT_STATUS_UNWRITTEN, false);\n+\tes_insert_extent(inode, 30, 5, 0, EXTENT_STATUS_HOLE, false);\n+\tes_insert_delayed_extent(inode, 40, 5, false, false);\n+\text4_set_inode_state(inode, EXT4_STATE_EXT_PRECACHED);\n+\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003eei-\u003ei_es_all_nr, 4U);\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003eei-\u003ei_es_shk_nr, 3U);\n+\n+\text4_clear_inode_es(inode);\n+\n+\tKUNIT_EXPECT_FALSE(test,\n+\t\t\t ext4_test_inode_state(inode,\n+\t\t\t\t\t\t EXT4_STATE_EXT_PRECACHED));\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003eei-\u003ei_es_shk_nr, 0U);\n+\tKUNIT_EXPECT_TRUE(test, list_empty(\u0026ctx-\u003eei-\u003ei_es_list));\n+\tassert_es_tree(test, inode, only_delayed_exp,\n+\t\t ARRAY_SIZE(only_delayed_exp));\n+}\n+\n+static void\n+test_es_shrinker_ages_referenced_and_keeps_delayed(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\tstruct percpu_counter *shk_cnt = \u0026ctx-\u003esbi-\u003es_es_stats.es_stats_shk_cnt;\n+\tstruct shrink_control sc = { .nr_to_scan = 0 };\n+\tstruct extent_status es;\n+\tunsigned long count, shrunk;\n+\tstatic const struct expected_es after_first_scan[] = {\n+\t\t{ .lblk = 10, .len = 2, .pblk = 100,\n+\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t{ .lblk = 30, .len = 2, .pblk = 300,\n+\t\t .type = EXTENT_STATUS_WRITTEN },\n+\t\t{ .lblk = 50, .len = 2, .pblk = 0,\n+\t\t .type = EXTENT_STATUS_DELAYED },\n+\t};\n+\tstatic const struct expected_es after_second_scan[] = {\n+\t\t{ .lblk = 50, .len = 2, .pblk = 0,\n+\t\t .type = EXTENT_STATUS_DELAYED },\n+\t};\n+\n+\t/* Insert 4 reclaimable WRITTEN extents and 1 non-reclaimable DELAYED */\n+\tes_insert_extent(inode, 10, 2, 100, EXTENT_STATUS_WRITTEN, false);\n+\tes_insert_extent(inode, 20, 2, 200, EXTENT_STATUS_WRITTEN, false);\n+\tes_insert_extent(inode, 30, 2, 300, EXTENT_STATUS_WRITTEN, false);\n+\tes_insert_extent(inode, 40, 2, 400, EXTENT_STATUS_WRITTEN, false);\n+\tes_insert_delayed_extent(inode, 50, 2, false, false);\n+\n+\t/* Mark [10, 2) and [30, 2) as EXTENT_STATUS_REFERENCED via lookup */\n+\tKUNIT_ASSERT_EQ(test,\n+\t\t\text4_es_lookup_extent(inode, 10, NULL, \u0026es, NULL), 1);\n+\tKUNIT_ASSERT_EQ(test,\n+\t\t\text4_es_lookup_extent(inode, 30, NULL, \u0026es, NULL), 1);\n+\n+\t/*\n+\t * Fold per-CPU counter deltas into the central count so count_objects\n+\t * (which uses percpu_counter_read_positive) sees all 4 extents on SMP.\n+\t */\n+\tpercpu_counter_set(shk_cnt, percpu_counter_sum_positive(shk_cnt));\n+\tcount = es_shrinker_count(ctx, \u0026sc);\n+\tKUNIT_EXPECT_EQ(test, count, 4UL);\n+\n+\t/*\n+\t * First scan (nr_to_scan = 5):\n+\t * - [20, 2) and [40, 2) are unreferenced and reclaimed (shrunk = 2)\n+\t * - [10, 2) and [30, 2) have REFERENCED cleared and survive\n+\t * - [50, 2) is DELAYED (must_keep) and survives\n+\t */\n+\tsc.nr_to_scan = 5;\n+\tshrunk = es_shrinker_scan(ctx, \u0026sc);\n+\tKUNIT_EXPECT_EQ(test, shrunk, 2UL);\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003eei-\u003ei_es_shk_nr, 2U);\n+\tassert_es_tree(test, inode, after_first_scan,\n+\t\t ARRAY_SIZE(after_first_scan));\n+\n+\t/*\n+\t * Second scan (nr_to_scan = 5):\n+\t * - [10, 2) and [30, 2) are now unreferenced and reclaimed (shrunk = 2)\n+\t * - Only [50, 2) DELAYED remains; inode is removed from s_es_list\n+\t */\n+\tsc.nr_to_scan = 5;\n+\tshrunk = es_shrinker_scan(ctx, \u0026sc);\n+\tKUNIT_EXPECT_EQ(test, shrunk, 2UL);\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003eei-\u003ei_es_shk_nr, 0U);\n+\tKUNIT_EXPECT_TRUE(test, list_empty(\u0026ctx-\u003eei-\u003ei_es_list));\n+\tassert_es_tree(test, inode, after_second_scan,\n+\t\t ARRAY_SIZE(after_second_scan));\n+}\n+\n+static void\n+test_es_shrinker_cursor_advances_and_wraps_around(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\tstruct shrink_control sc = {};\n+\tunsigned long shrunk;\n+\n+\tes_insert_extent(inode, 10, 2, 100, EXTENT_STATUS_WRITTEN, false);\n+\tes_insert_extent(inode, 20, 2, 200, EXTENT_STATUS_WRITTEN, false);\n+\tes_insert_extent(inode, 30, 2, 300, EXTENT_STATUS_WRITTEN, false);\n+\n+\tsc.nr_to_scan = 1;\n+\tshrunk = es_shrinker_scan(ctx, \u0026sc);\n+\tKUNIT_EXPECT_EQ(test, shrunk, 1UL);\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003eei-\u003ei_es_shrink_lblk, 20U);\n+\n+\t/* Re-insert [10, 2) behind the shrink cursor; next scan wraps to it */\n+\tes_insert_extent(inode, 10, 2, 100, EXTENT_STATUS_WRITTEN, false);\n+\tsc.nr_to_scan = 3;\n+\tshrunk = es_shrinker_scan(ctx, \u0026sc);\n+\tKUNIT_EXPECT_EQ(test, shrunk, 3UL);\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003eei-\u003ei_es_all_nr, 0U);\n+}\n+\n+static void\n+test_es_shrinker_skips_precached_inode_until_last_resort(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode1 = \u0026ctx-\u003eei-\u003evfs_inode;\n+\tstruct inode *inode2;\n+\tstruct shrink_control sc = {};\n+\tunsigned long shrunk;\n+\n+\tinode2 = es_alloc_test_inode(test, ctx-\u003esb, 13);\n+\n+\tes_insert_extent(inode1, 10, 2, 100, EXTENT_STATUS_WRITTEN, false);\n+\text4_set_inode_state(inode1, EXT4_STATE_EXT_PRECACHED);\n+\tes_insert_extent(inode2, 10, 2, 200, EXTENT_STATUS_WRITTEN, false);\n+\n+\t/* First scan skips precached inode1 and reclaims from inode2 */\n+\tsc.nr_to_scan = 1;\n+\tshrunk = es_shrinker_scan(ctx, \u0026sc);\n+\tKUNIT_EXPECT_EQ(test, shrunk, 1UL);\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003eei-\u003ei_es_shk_nr, 1U);\n+\tKUNIT_EXPECT_EQ(test, EXT4_I(inode2)-\u003ei_es_shk_nr, 0U);\n+\n+\t/*\n+\t * Now only precached inode1 remains on s_es_list; shrinker retries\n+\t * and reclaims from inode1 as a last resort.\n+\t */\n+\tsc.nr_to_scan = 1;\n+\tshrunk = es_shrinker_scan(ctx, \u0026sc);\n+\tKUNIT_EXPECT_EQ(test, shrunk, 1UL);\n+\tKUNIT_EXPECT_EQ(test, ctx-\u003eei-\u003ei_es_shk_nr, 0U);\n+}\n+\n+static void test_es_seq_shrinker_info_show_formats_stats(struct kunit *test)\n+{\n+\tstruct es_test_ctx *ctx = test-\u003epriv;\n+\tstruct inode *inode = \u0026ctx-\u003eei-\u003evfs_inode;\n+\tstruct seq_file seq = {};\n+\tchar *buf;\n+\n+\tes_insert_extent(inode, 10, 2, 100, EXTENT_STATUS_WRITTEN, false);\n+\n+\tbuf = kunit_kzalloc(test, PAGE_SIZE, GFP_KERNEL);\n+\tKUNIT_ASSERT_NOT_NULL(test, buf);\n+\tseq.buf = buf;\n+\tseq.size = PAGE_SIZE;\n+\tseq.private = ctx-\u003esb;\n+\n+\tKUNIT_EXPECT_EQ(test,\n+\t\t\text4_seq_es_shrinker_info_show(\u0026seq, SEQ_START_TOKEN),\n+\t\t\t0);\n+\tKUNIT_EXPECT_GT(test, seq.count, 0UL);\n+\tKUNIT_EXPECT_NOT_NULL(test, strstr(buf, \"reclaimable objects\"));\n+}\n+\n+static struct kunit_case extents_status_test_cases[] = {\n+\tKUNIT_CASE(test_es_bitfield_written_and_unwritten_encoding),\n+\tKUNIT_CASE(test_es_bitfield_delayed_and_hole_encoding),\n+\tKUNIT_CASE(test_es_bitfield_referenced_and_pblock_update_preserve_state),\n+\tKUNIT_CASE(test_es_lookup_empty_tree_returns_miss),\n+\tKUNIT_CASE(test_es_insert_zero_len_is_noop),\n+\tKUNIT_CASE(test_es_lookup_hits_cache_and_rbtree_with_next_lblk),\n+\tKUNIT_CASE(test_es_fc_replay_bypasses_tree_operations),\n+\tKUNIT_CASE_PARAM(test_es_merge_cases, es_merge_gen_params),\n+\tKUNIT_CASE(test_es_insert_adjacent_delayed_extents_merges),\n+\tKUNIT_CASE(test_es_merge_preserves_referenced),\n+\tKUNIT_CASE(test_es_merge_at_max_blocks_boundary_succeeds),\n+\tKUNIT_CASE_PARAM(test_es_remove_geometries, es_remove_gen_params),\n+\tKUNIT_CASE(test_es_remove_multi_extent_span_trims_and_deletes),\n+\tKUNIT_CASE(test_es_insert_overwrite_split_and_remerge),\n+\tKUNIT_CASE(test_es_cache_extent_inserts_and_coalesces_same_status),\n+\tKUNIT_CASE(test_es_cache_extent_conflict_covered_range_warns),\n+\tKUNIT_CASE(test_es_cache_extent_conflict_partial_overlap_warns),\n+\tKUNIT_CASE(test_es_cache_extent_hole_over_delayed_does_not_warn),\n+\tKUNIT_CASE(test_es_find_extent_range_skips_nonmatching_and_finds_next),\n+\tKUNIT_CASE(test_es_scan_range_matches_only_overlapping_extents),\n+\tKUNIT_CASE(test_es_scan_clu_matches_extent_in_same_cluster),\n+\tKUNIT_CASE(test_es_delalloc_remove_and_overwrite_account_reserved_blocks),\n+\tKUNIT_CASE(test_es_bigalloc_insert_delayed_creates_and_removes_pending),\n+\tKUNIT_CASE(test_es_bigalloc_revise_pending_single_cluster_halves),\n+\tKUNIT_CASE(test_es_bigalloc_revise_pending_multi_cluster_span),\n+\tKUNIT_CASE(test_es_bigalloc_remove_partial_cluster_holds_rsvd_until_empty),\n+\tKUNIT_CASE(test_es_bigalloc_remove_fragmented_cluster_releases_once),\n+\tKUNIT_CASE(test_es_bigalloc_remove_pending_cluster_cancels_pending_only),\n+\tKUNIT_CASE(test_es_clear_inode_es_retains_only_delayed_extents),\n+\tKUNIT_CASE(test_es_shrinker_ages_referenced_and_keeps_delayed),\n+\tKUNIT_CASE(test_es_shrinker_cursor_advances_and_wraps_around),\n+\tKUNIT_CASE(test_es_shrinker_skips_precached_inode_until_last_resort),\n+\tKUNIT_CASE(test_es_seq_shrinker_info_show_formats_stats),\n+\t{}\n+};\n+\n+static struct kunit_suite extents_status_test_suite = {\n+\t.name = \"ext4_extents_status_test\",\n+\t.init = es_kunit_init,\n+\t.test_cases = extents_status_test_cases,\n+};\n+\n+kunit_test_suites(\u0026extents_status_test_suite);\n+\n+MODULE_DESCRIPTION(\"KUnit tests for ext4 extents status tree and pending reservations\");\n+MODULE_LICENSE(\"GPL\");\ndiff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c\nindex 6e4a191e82191..64bac0c4c1fa0 100644\n--- a/fs/ext4/extents_status.c\n+++ b/fs/ext4/extents_status.c\n@@ -2390,3 +2390,22 @@ static int __revise_pending(struct inode *inode, ext4_lblk_t lblk,\n out:\n \treturn (ret \u003c 0) ? ret : pendings;\n }\n+\n+#if IS_ENABLED(CONFIG_EXT4_KUNIT_TESTS)\n+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_init_tree);\n+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_insert_extent);\n+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_cache_extent);\n+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_remove_extent);\n+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_find_extent_range);\n+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_lookup_extent);\n+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_scan_range);\n+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_scan_clu);\n+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_register_shrinker);\n+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_unregister_shrinker);\n+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_seq_es_shrinker_info_show);\n+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_init_pending_tree);\n+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_remove_pending);\n+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_is_pending);\n+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_insert_delayed_extent);\n+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_clear_inode_es);\n+#endif\ndiff --git a/fs/ext4/inode.c b/fs/ext4/inode.c\nindex 26f0f9714f03c..966a760f64e69 100644\n--- a/fs/ext4/inode.c\n+++ b/fs/ext4/inode.c\n@@ -350,6 +350,9 @@ void ext4_da_update_reserve_space(struct inode *inode,\n \tstruct ext4_sb_info *sbi = EXT4_SB(inode-\u003ei_sb);\n \tstruct ext4_inode_info *ei = EXT4_I(inode);\n \n+\tKUNIT_STATIC_STUB_REDIRECT(ext4_da_update_reserve_space,\n+\t\t\t\t inode, used, quota_claim);\n+\n \tspin_lock(\u0026ei-\u003ei_block_reservation_lock);\n \ttrace_ext4_da_update_reserve_space(inode, used, quota_claim);\n \tif (unlikely(used \u003e ei-\u003ei_reserved_data_blocks)) {\n@@ -1646,6 +1649,8 @@ void ext4_da_release_space(struct inode *inode, int to_free)\n \tstruct ext4_sb_info *sbi = EXT4_SB(inode-\u003ei_sb);\n \tstruct ext4_inode_info *ei = EXT4_I(inode);\n \n+\tKUNIT_STATIC_STUB_REDIRECT(ext4_da_release_space, inode, to_free);\n+\n \tif (!to_free)\n \t\treturn;\t\t/* Nothing to release, exit */\n \n@@ -6973,3 +6978,8 @@ vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf)\n \tsb_end_pagefault(inode-\u003ei_sb);\n \treturn ret;\n }\n+\n+#if IS_ENABLED(CONFIG_EXT4_KUNIT_TESTS)\n+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_da_update_reserve_space);\n+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_da_release_space);\n+#endif\n"
} |
| 2/1 | 2026/10/21 12:48 | agent | patch-evaluator |
3mModel:core Args: null Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"Reasoning": "The patch adds a new KUnit test suite (fs/ext4/extents_status-test.c) and associated test plumbing (EXPORT_SYMBOL_FOR_EXT4_TEST exports and KUNIT_STATIC_STUB_REDIRECT hooks in fs/ext4/inode.c, fs/ext4/extents.c, and fs/ext4/extents_status.c). No functional kernel logic, data structures, or runtime assertions in ext4 production code are modified. During normal execution and fuzzing, KUNIT_STATIC_STUB_REDIRECT is a no-op because kunit_get_current_test() returns NULL. KUnit unit tests run non-interactively at boot or via test harnesses and are not reachable or exercisable via syzkaller syscall fuzzing. Therefore, the changes do not warrant fuzzing.",
"WorthFuzzing": false
}Instruction: You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.
IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.
================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.
- REACHABILITY IS THE PRIMARY GATE:
Fuzzing can only discover bugs in code that can actually execute in standard virtualized
environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
regardless of whether it adds assertions or complex logic.
- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
Patch authors routinely label changes as "cleanups", "refactorings", or state
"No functional change intended". Do NOT take these claims at face value.
Code refactorings that rearrange logic, introduce helper functions, or alter state management
in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
If reachable executable code is modified or refactored, it MUST be fuzzed.
- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
Even if the author believes the invariant always holds, fuzzing is essential to verify whether
an unusual sequence of operations can violate it.
================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:
- Non-kernel and non-executable changes:
* Modifications to Documentation/, comments, or spelling fixes.
* User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
that do not affect the compiled kernel image (vmlinux) or kernel modules.
* Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
that do not alter control flow or data structures.
* Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
* Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
* Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
physical PCI hot-unplug or manual sysfs driver unbinding.
* Code paths exclusive to architectures other than the target architecture.
================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
* Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
* Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
* Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
* Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).
================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:
- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
Do NOT list generic, ubiquitous functions called by almost every program in the corpus
(including, but not limited to: general memory allocators and deallocators, page fault
and trap handlers, or core synchronization primitives; this is not an exhaustive list).
Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
which severely dilutes fuzzing effort away from the actual changes.
- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
List functions that specifically implement the logic being added or altered, or direct API entrypoints
for the subsystem feature under review.
- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).
================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 7544e1de9c4172decede10968365499730f237d5
Author: syz-cluster <triage@syzkaller.com>
Date: Wed Oct 21 12:48:10 2026 +0000
syz-cluster: applied patch under review
diff --git a/fs/ext4/Makefile b/fs/ext4/Makefile
index 3f9fc0eb8ecad..74b485dbb229b 100644
--- a/fs/ext4/Makefile
+++ b/fs/ext4/Makefile
@@ -15,7 +15,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 \
- extents-test.o hash-test.o
+ extents-test.o hash-test.o \
+ extents_status-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/extents.c b/fs/ext4/extents.c
index 76038b6c36552..6c018bcc01187 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -6407,12 +6407,7 @@ 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_es_unregister_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);
diff --git a/fs/ext4/extents_status-test.c b/fs/ext4/extents_status-test.c
new file mode 100644
index 0000000000000..59eaac464bdce
--- /dev/null
+++ b/fs/ext4/extents_status-test.c
@@ -0,0 +1,1640 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * KUnit tests for ext4 extents status tree and bigalloc pending reservations.
+ */
+
+#include <kunit/test.h>
+#include <kunit/test-bug.h>
+#include <kunit/static_stub.h>
+#include <linux/fs_context.h>
+#include <linux/seq_file.h>
+
+#include "ext4.h"
+#include "ext4_extents.h"
+
+#define ES_MAX_EXPECTED_EXTENTS 8
+
+struct es_test_ctx {
+ struct super_block *sb;
+ struct ext4_sb_info *sbi;
+ struct ext4_inode_info *ei;
+
+ /*
+ * Saved shrinker callbacks so the registered shrinker can be
+ * replaced with no-op stubs to prevent asynchronous background
+ * reclaim (kswapd / direct reclaim) from touching mock extents.
+ */
+ unsigned long (*shrinker_count)(struct shrinker *shrink,
+ struct shrink_control *sc);
+ unsigned long (*shrinker_scan)(struct shrinker *shrink,
+ struct shrink_control *sc);
+
+ /* Tracking for stubbed delalloc reservation callbacks */
+ int da_update_calls;
+ int last_da_used;
+ int total_da_used;
+ int last_da_quota_claim;
+
+ int da_release_calls;
+ int last_da_released;
+ int total_da_released;
+};
+
+struct expected_es {
+ ext4_lblk_t lblk;
+ ext4_lblk_t len;
+ ext4_fsblk_t pblk;
+ unsigned int type;
+};
+
+static void reset_da_stub_stats(struct es_test_ctx *ctx)
+{
+ ctx->da_update_calls = 0;
+ ctx->last_da_used = 0;
+ ctx->total_da_used = 0;
+ ctx->last_da_quota_claim = 0;
+
+ ctx->da_release_calls = 0;
+ ctx->last_da_released = 0;
+ ctx->total_da_released = 0;
+}
+
+static void ext4_da_update_reserve_space_stub(struct inode *inode,
+ int used, int quota_claim)
+{
+ struct kunit *test = kunit_get_current_test();
+ struct es_test_ctx *ctx;
+
+ if (!test || !test->priv)
+ return;
+
+ ctx = test->priv;
+ ctx->da_update_calls++;
+ ctx->last_da_used = used;
+ ctx->total_da_used += used;
+ ctx->last_da_quota_claim = quota_claim;
+}
+
+static void ext4_da_release_space_stub(struct inode *inode, int to_free)
+{
+ struct kunit *test = kunit_get_current_test();
+ struct es_test_ctx *ctx;
+
+ if (!to_free || !test || !test->priv)
+ return;
+
+ ctx = test->priv;
+ ctx->da_release_calls++;
+ ctx->last_da_released = to_free;
+ ctx->total_da_released += to_free;
+}
+
+static struct ext4_ext_path *
+ext4_find_extent_stub(struct inode *inode, ext4_lblk_t block,
+ struct ext4_ext_path *path, int flags)
+{
+ return ERR_PTR(-EOPNOTSUPP);
+}
+
+static unsigned long es_dummy_shrinker_count(struct shrinker *shrink,
+ struct shrink_control *sc)
+{
+ return 0;
+}
+
+static unsigned long es_dummy_shrinker_scan(struct shrinker *shrink,
+ struct shrink_control *sc)
+{
+ return SHRINK_STOP;
+}
+
+static unsigned long es_shrinker_count(struct es_test_ctx *ctx,
+ struct shrink_control *sc)
+{
+ return ctx->shrinker_count(ctx->sbi->s_es_shrinker, sc);
+}
+
+static unsigned long es_shrinker_scan(struct es_test_ctx *ctx,
+ struct shrink_control *sc)
+{
+ return ctx->shrinker_scan(ctx->sbi->s_es_shrinker, sc);
+}
+
+static void es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
+ ext4_lblk_t len, ext4_fsblk_t pblk,
+ unsigned int status, bool delalloc_reserve_used)
+{
+ down_write(&EXT4_I(inode)->i_data_sem);
+ ext4_es_insert_extent(inode, lblk, len, pblk, status,
+ delalloc_reserve_used);
+ up_write(&EXT4_I(inode)->i_data_sem);
+}
+
+static void es_insert_delayed_extent(struct inode *inode, ext4_lblk_t lblk,
+ ext4_lblk_t len, bool lclu_allocated,
+ bool end_allocated)
+{
+ down_write(&EXT4_I(inode)->i_data_sem);
+ ext4_es_insert_delayed_extent(inode, lblk, len, lclu_allocated,
+ end_allocated);
+ up_write(&EXT4_I(inode)->i_data_sem);
+}
+
+static void es_cache_extent(struct inode *inode, ext4_lblk_t lblk,
+ ext4_lblk_t len, ext4_fsblk_t pblk,
+ unsigned int status)
+{
+ down_read(&EXT4_I(inode)->i_data_sem);
+ ext4_es_cache_extent(inode, lblk, len, pblk, status);
+ up_read(&EXT4_I(inode)->i_data_sem);
+}
+
+static void es_remove_extent(struct inode *inode, ext4_lblk_t lblk,
+ ext4_lblk_t len)
+{
+ down_write(&EXT4_I(inode)->i_data_sem);
+ ext4_es_remove_extent(inode, lblk, len);
+ up_write(&EXT4_I(inode)->i_data_sem);
+}
+
+static int es_init_fs_context(struct fs_context *fc)
+{
+ return 0;
+}
+
+static int es_set_anon(struct super_block *sb, struct fs_context *fc)
+{
+ return set_anon_super_fc(sb, fc);
+}
+
+static struct file_system_type es_fs_type = {
+ .name = "extents_status test",
+ .init_fs_context = es_init_fs_context,
+ .kill_sb = kill_anon_super,
+};
+
+static void es_init_mock_inode(struct ext4_inode_info *ei,
+ struct super_block *sb, unsigned long ino)
+{
+ struct inode *inode = &ei->vfs_inode;
+
+ memset(ei, 0, sizeof(*ei));
+ inode->i_sb = sb;
+ inode->i_ino = ino;
+ inode->i_blkbits = sb->s_blocksize_bits;
+
+ ext4_es_init_tree(&ei->i_es_tree);
+ ext4_init_pending_tree(&ei->i_pending_tree);
+ rwlock_init(&ei->i_es_lock);
+ INIT_LIST_HEAD(&ei->i_es_list);
+ init_rwsem(&ei->i_data_sem);
+ spin_lock_init(&ei->i_block_reservation_lock);
+ ext4_set_inode_flag(inode, EXT4_INODE_EXTENTS);
+}
+
+static void es_cleanup_inode(struct inode *inode)
+{
+ struct ext4_inode_info *ei = EXT4_I(inode);
+ struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
+ struct rb_node *node;
+
+ sbi->s_mount_state &= ~EXT4_FC_REPLAY;
+ es_remove_extent(inode, 0, EXT_MAX_BLOCKS);
+
+ while ((node = rb_first(&ei->i_pending_tree.root)) != NULL) {
+ struct pending_reservation *pr;
+
+ pr = rb_entry(node, struct pending_reservation, rb_node);
+ ext4_remove_pending(inode, EXT4_C2B(sbi, pr->lclu));
+ }
+}
+
+KUNIT_DEFINE_ACTION_WRAPPER(es_cleanup_inode_action, es_cleanup_inode,
+ struct inode *);
+KUNIT_DEFINE_ACTION_WRAPPER(es_unregister_shrinker_action,
+ ext4_es_unregister_shrinker,
+ struct ext4_sb_info *);
+KUNIT_DEFINE_ACTION_WRAPPER(es_deactivate_super_action, deactivate_super,
+ struct super_block *);
+
+static struct inode *es_alloc_test_inode(struct kunit *test,
+ struct super_block *sb,
+ unsigned long ino)
+{
+ struct ext4_inode_info *ei;
+ int ret;
+
+ ei = kunit_kzalloc(test, sizeof(*ei), GFP_KERNEL);
+ KUNIT_ASSERT_NOT_NULL(test, ei);
+ es_init_mock_inode(ei, sb, ino);
+
+ ret = kunit_add_action_or_reset(test, es_cleanup_inode_action,
+ &ei->vfs_inode);
+ KUNIT_ASSERT_EQ(test, ret, 0);
+
+ return &ei->vfs_inode;
+}
+
+static void es_set_cluster_bits(struct super_block *sb,
+ unsigned int cluster_bits)
+{
+ struct ext4_sb_info *sbi = EXT4_SB(sb);
+
+ sbi->s_cluster_bits = cluster_bits;
+ sbi->s_cluster_ratio = 1U << cluster_bits;
+}
+
+/*
+ * All test resources and deferred cleanup actions are registered with KUnit's
+ * resource stack (test->resources), which unwinds in strict LIFO order after
+ * each test case completes (or aborts).
+ *
+ * The registration order below (and in helpers like es_alloc_test_inode())
+ * MUST be preserved when modifying these tests so that teardown happens in the
+ * reverse order:
+ * 1. kunit_kzalloc() of ctx, sbi, and ctx->ei (freed last)
+ * 2. es_deactivate_super_action(sb) (superblock deactivated after shrinker
+ * and all inodes are torn down)
+ * 3. es_unregister_shrinker_action(sbi) (shrinker and s_es_stats per-CPU
+ * counters destroyed after all inode extent trees are emptied)
+ * 4. kunit_activate_static_stub() for ext4_da_update_reserve_space,
+ * ext4_da_release_space, and ext4_find_extent (stubs must remain active
+ * while es_cleanup_inode() removes delayed extents via
+ * ext4_es_remove_extent())
+ * 5. es_cleanup_inode_action() for ctx->ei and any additional test inodes
+ * allocated via es_alloc_test_inode() (run first during teardown; inside
+ * es_alloc_test_inode(), kunit_kzalloc() must precede
+ * kunit_add_action_or_reset() so the inode is cleaned up before freed)
+ */
+static int es_kunit_init(struct kunit *test)
+{
+ struct es_test_ctx *ctx;
+ struct ext4_sb_info *sbi;
+ struct super_block *sb;
+ struct fs_context *fc;
+ int err;
+
+ ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
+ if (!ctx)
+ return -ENOMEM;
+
+ sbi = kunit_kzalloc(test, sizeof(*sbi), GFP_KERNEL);
+ if (!sbi)
+ return -ENOMEM;
+
+ ctx->ei = kunit_kzalloc(test, sizeof(*ctx->ei), GFP_KERNEL);
+ if (!ctx->ei)
+ return -ENOMEM;
+
+ fc = fs_context_for_mount(&es_fs_type, 0);
+ if (IS_ERR(fc))
+ return PTR_ERR(fc);
+
+ sb = sget_fc(fc, NULL, es_set_anon);
+ put_fs_context(fc);
+ if (IS_ERR(sb))
+ return PTR_ERR(sb);
+
+ sbi->s_sb = sb;
+ sb->s_fs_info = sbi;
+ sb->s_blocksize = 4096;
+ sb->s_blocksize_bits = 12;
+ strscpy(sb->s_id, "es_kunit", sizeof(sb->s_id));
+
+ es_set_cluster_bits(sb, 0);
+ set_opt(sb, DELALLOC);
+ ratelimit_state_init(&sbi->s_warning_ratelimit_state,
+ DEFAULT_RATELIMIT_INTERVAL,
+ DEFAULT_RATELIMIT_BURST);
+ up_write(&sb->s_umount);
+
+ err = kunit_add_action_or_reset(test, es_deactivate_super_action, sb);
+ if (err)
+ return err;
+
+ err = ext4_es_register_shrinker(sbi);
+ if (err)
+ return err;
+
+ /*
+ * Detach the real callbacks from the globally registered shrinker
+ * before any extents are inserted so background kswapd / direct
+ * reclaim cannot asynchronously evict mock extents during a test.
+ */
+ ctx->shrinker_count = sbi->s_es_shrinker->count_objects;
+ ctx->shrinker_scan = sbi->s_es_shrinker->scan_objects;
+ WRITE_ONCE(sbi->s_es_shrinker->count_objects, es_dummy_shrinker_count);
+ WRITE_ONCE(sbi->s_es_shrinker->scan_objects, es_dummy_shrinker_scan);
+
+ err = kunit_add_action_or_reset(test, es_unregister_shrinker_action,
+ sbi);
+ if (err)
+ return err;
+
+ ctx->sb = sb;
+ ctx->sbi = sbi;
+ test->priv = ctx;
+
+ kunit_activate_static_stub(test, ext4_da_update_reserve_space,
+ ext4_da_update_reserve_space_stub);
+ kunit_activate_static_stub(test, ext4_da_release_space,
+ ext4_da_release_space_stub);
+ kunit_activate_static_stub(test, ext4_find_extent,
+ ext4_find_extent_stub);
+
+ es_init_mock_inode(ctx->ei, sb, 12);
+ err = kunit_add_action_or_reset(test, es_cleanup_inode_action,
+ &ctx->ei->vfs_inode);
+ if (err)
+ return err;
+
+ return 0;
+}
+
+static void assert_es_tree(struct kunit *test, struct inode *inode,
+ const struct expected_es *exp, unsigned int nr_exp)
+{
+ struct ext4_inode_info *ei = EXT4_I(inode);
+ struct extent_status found[ES_MAX_EXPECTED_EXTENTS];
+ struct rb_node *node;
+ unsigned int nr_found = 0;
+ unsigned int all_nr;
+ unsigned int i;
+ ext4_lblk_t prev_end = 0;
+
+ KUNIT_ASSERT_LE(test, nr_exp, (unsigned int)ARRAY_SIZE(found));
+
+ /*
+ * Snapshot the tree under i_es_lock and release the lock before
+ * running any KUnit assertions or expectations. KUNIT_ASSERT_*
+ * aborts the test kthread on failure (which would leak i_es_lock
+ * and deadlock es_cleanup_inode()), and KUNIT_EXPECT_* allocates
+ * failure logs with GFP_KERNEL.
+ */
+ read_lock(&ei->i_es_lock);
+ for (node = rb_first(&ei->i_es_tree.root); node; node = rb_next(node)) {
+ struct extent_status *es =
+ rb_entry(node, struct extent_status, rb_node);
+
+ if (nr_found < ARRAY_SIZE(found))
+ found[nr_found] = *es;
+ nr_found++;
+ }
+ all_nr = ei->i_es_all_nr;
+ read_unlock(&ei->i_es_lock);
+
+ for (i = 0; i < nr_found; i++) {
+ struct extent_status *es = &found[min(i,
+ (unsigned int)ARRAY_SIZE(found) - 1)];
+
+ KUNIT_ASSERT_LT_MSG(test, i, nr_exp,
+ "unexpected extra extent [%u/%u) type 0x%x",
+ es->es_lblk, es->es_len, ext4_es_type(es));
+
+ if (i > 0)
+ KUNIT_EXPECT_GT_MSG(test, es->es_lblk, prev_end,
+ "extent %u not strictly ordered",
+ i);
+
+ KUNIT_EXPECT_EQ_MSG(test, es->es_lblk, exp[i].lblk,
+ "extent %u lblk mismatch", i);
+ KUNIT_EXPECT_EQ_MSG(test, es->es_len, exp[i].len,
+ "extent %u len mismatch", i);
+ KUNIT_EXPECT_EQ_MSG(test, ext4_es_type(es), exp[i].type,
+ "extent %u type mismatch", i);
+
+ if (exp[i].type & (EXTENT_STATUS_WRITTEN |
+ EXTENT_STATUS_UNWRITTEN))
+ KUNIT_EXPECT_EQ_MSG(test, ext4_es_pblock(es),
+ exp[i].pblk,
+ "extent %u pblk mismatch", i);
+
+ prev_end = es->es_lblk + es->es_len - 1;
+ }
+
+ KUNIT_EXPECT_EQ(test, nr_found, nr_exp);
+ KUNIT_EXPECT_EQ(test, all_nr, nr_exp);
+}
+
+/*
+ * Group 1: Bitfield Encoding & Inline Helpers
+ */
+static void test_es_bitfield_written_and_unwritten_encoding(struct kunit *test)
+{
+ struct extent_status es = {};
+ const ext4_fsblk_t sample_pblk = 0x123456789abcULL;
+
+ ext4_es_store_pblock_status(&es, sample_pblk, EXTENT_STATUS_WRITTEN);
+ KUNIT_EXPECT_EQ(test, ext4_es_pblock(&es), sample_pblk);
+ KUNIT_EXPECT_EQ(test, ext4_es_show_pblock(&es), sample_pblk);
+ KUNIT_EXPECT_EQ(test, ext4_es_type(&es), EXTENT_STATUS_WRITTEN);
+ KUNIT_EXPECT_EQ(test, ext4_es_status(&es), EXTENT_STATUS_WRITTEN);
+ KUNIT_EXPECT_TRUE(test, ext4_es_is_written(&es));
+ KUNIT_EXPECT_FALSE(test, ext4_es_is_unwritten(&es));
+ KUNIT_EXPECT_FALSE(test, ext4_es_is_delayed(&es));
+ KUNIT_EXPECT_FALSE(test, ext4_es_is_hole(&es));
+ KUNIT_EXPECT_TRUE(test, ext4_es_is_mapped(&es));
+ KUNIT_EXPECT_FALSE(test, ext4_es_is_referenced(&es));
+
+ ext4_es_store_pblock_status(&es, sample_pblk, EXTENT_STATUS_UNWRITTEN);
+ KUNIT_EXPECT_EQ(test, ext4_es_pblock(&es), sample_pblk);
+ KUNIT_EXPECT_TRUE(test, ext4_es_is_unwritten(&es));
+ KUNIT_EXPECT_TRUE(test, ext4_es_is_mapped(&es));
+ KUNIT_EXPECT_FALSE(test, ext4_es_is_written(&es));
+}
+
+static void test_es_bitfield_delayed_and_hole_encoding(struct kunit *test)
+{
+ struct extent_status es = {};
+ /* 59-bit physical block field (64 - 5 status bits) all ones */
+ const ext4_fsblk_t max_59bit_pblk = 0x07ffffffffffffffULL;
+
+ ext4_es_store_pblock_status(&es, ~0ULL, EXTENT_STATUS_DELAYED);
+ KUNIT_EXPECT_TRUE(test, ext4_es_is_delayed(&es));
+ KUNIT_EXPECT_FALSE(test, ext4_es_is_mapped(&es));
+ KUNIT_EXPECT_EQ(test, ext4_es_pblock(&es), max_59bit_pblk);
+ KUNIT_EXPECT_EQ(test, ext4_es_show_pblock(&es), 0ULL);
+
+ ext4_es_store_pblock_status(&es, 0ULL, EXTENT_STATUS_HOLE);
+ KUNIT_EXPECT_TRUE(test, ext4_es_is_hole(&es));
+ KUNIT_EXPECT_FALSE(test, ext4_es_is_mapped(&es));
+ KUNIT_EXPECT_EQ(test, ext4_es_pblock(&es), 0ULL);
+}
+
+static void
+test_es_bitfield_referenced_and_pblock_update_preserve_state(struct kunit *test)
+{
+ struct extent_status es = {};
+ const ext4_fsblk_t initial_pblk = 0x123456789abcULL;
+ const ext4_fsblk_t updated_pblk = 0x07ffffffffffffffULL;
+
+ ext4_es_store_pblock_status(&es, initial_pblk, EXTENT_STATUS_WRITTEN);
+
+ /* Setting referenced bit preserves pblk and type */
+ ext4_es_set_referenced(&es);
+ KUNIT_EXPECT_TRUE(test, ext4_es_is_referenced(&es));
+ KUNIT_EXPECT_EQ(test, ext4_es_type(&es), EXTENT_STATUS_WRITTEN);
+ KUNIT_EXPECT_EQ(test, ext4_es_pblock(&es), initial_pblk);
+ KUNIT_EXPECT_EQ(test, ext4_es_status(&es),
+ EXTENT_STATUS_WRITTEN | EXTENT_STATUS_REFERENCED);
+
+ /* Updating pblock preserves status and referenced bit */
+ ext4_es_store_pblock(&es, updated_pblk);
+ KUNIT_EXPECT_EQ(test, ext4_es_pblock(&es), updated_pblk);
+ KUNIT_EXPECT_EQ(test, ext4_es_type(&es), EXTENT_STATUS_WRITTEN);
+ KUNIT_EXPECT_TRUE(test, ext4_es_is_referenced(&es));
+
+ /* Clearing referenced bit preserves updated pblk and type */
+ ext4_es_clear_referenced(&es);
+ KUNIT_EXPECT_FALSE(test, ext4_es_is_referenced(&es));
+ KUNIT_EXPECT_EQ(test, ext4_es_pblock(&es), updated_pblk);
+ KUNIT_EXPECT_EQ(test, ext4_es_type(&es), EXTENT_STATUS_WRITTEN);
+}
+
+/*
+ * Group 2: Insertion, Lookup, Sequence Numbers, and Merging
+ */
+static void test_es_lookup_empty_tree_returns_miss(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+ struct extent_status es;
+ ext4_lblk_t next_lblk = 0xdead;
+ s64 misses_before;
+ int ret;
+
+ misses_before = percpu_counter_sum_positive(
+ &ctx->sbi->s_es_stats.es_stats_cache_misses);
+ ret = ext4_es_lookup_extent(inode, 10, &next_lblk, &es, NULL);
+ KUNIT_EXPECT_EQ(test, ret, 0);
+ KUNIT_EXPECT_EQ(test, percpu_counter_sum_positive(
+ &ctx->sbi->s_es_stats.es_stats_cache_misses),
+ misses_before + 1);
+}
+
+static void test_es_insert_zero_len_is_noop(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+
+ es_insert_extent(inode, 10, 0, 100, EXTENT_STATUS_WRITTEN, false);
+ es_insert_delayed_extent(inode, 20, 0, false, false);
+ es_cache_extent(inode, 30, 0, 300, EXTENT_STATUS_WRITTEN);
+
+ KUNIT_EXPECT_EQ(test, ctx->ei->i_es_all_nr, 0U);
+ KUNIT_EXPECT_TRUE(test, RB_EMPTY_ROOT(&ctx->ei->i_es_tree.root));
+}
+
+static void
+test_es_lookup_hits_cache_and_rbtree_with_next_lblk(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+ struct extent_status es;
+ ext4_lblk_t next_lblk = 0xdead;
+ u64 seq_after_first, seq_after_second, lookup_seq = 0;
+ s64 hits_before;
+ int ret;
+
+ es_insert_extent(inode, 10, 5, 100, EXTENT_STATUS_WRITTEN, false);
+ seq_after_first = ctx->ei->i_es_seq;
+ es_insert_extent(inode, 20, 5, 200, EXTENT_STATUS_UNWRITTEN, false);
+ seq_after_second = ctx->ei->i_es_seq;
+ KUNIT_EXPECT_GT(test, seq_after_second, seq_after_first);
+
+ /*
+ * Right after inserting [20, 5), tree->cache_es points to [20, 5).
+ * Looking up lblk 22 hits cache_es and sets next_lblk to 0 because
+ * [20, 5) is the last extent in the tree.
+ */
+ hits_before = percpu_counter_sum_positive(
+ &ctx->sbi->s_es_stats.es_stats_cache_hits);
+
+ ret = ext4_es_lookup_extent(inode, 22, &next_lblk, &es, &lookup_seq);
+ KUNIT_EXPECT_EQ(test, ret, 1);
+ KUNIT_EXPECT_EQ(test, es.es_lblk, 20U);
+ KUNIT_EXPECT_EQ(test, es.es_len, 5U);
+ KUNIT_EXPECT_EQ(test, ext4_es_pblock(&es), 200ULL);
+ KUNIT_EXPECT_TRUE(test, ext4_es_is_unwritten(&es));
+ KUNIT_EXPECT_EQ(test, next_lblk, 0U);
+ KUNIT_EXPECT_EQ(test, lookup_seq, seq_after_second);
+
+ /* Lookup start, middle, and end of first extent [10, 5) via rb-tree */
+ ret = ext4_es_lookup_extent(inode, 10, &next_lblk, &es, NULL);
+ KUNIT_EXPECT_EQ(test, ret, 1);
+ KUNIT_EXPECT_EQ(test, es.es_lblk, 10U);
+ KUNIT_EXPECT_EQ(test, next_lblk, 20U);
+
+ ret = ext4_es_lookup_extent(inode, 12, &next_lblk, &es, NULL);
+ KUNIT_EXPECT_EQ(test, ret, 1);
+ KUNIT_EXPECT_EQ(test, es.es_lblk, 10U);
+ KUNIT_EXPECT_EQ(test, next_lblk, 20U);
+
+ ret = ext4_es_lookup_extent(inode, 14, &next_lblk, &es, NULL);
+ KUNIT_EXPECT_EQ(test, ret, 1);
+ KUNIT_EXPECT_EQ(test, es.es_lblk, 10U);
+ KUNIT_EXPECT_EQ(test, next_lblk, 20U);
+
+ KUNIT_EXPECT_EQ(test, percpu_counter_sum_positive(
+ &ctx->sbi->s_es_stats.es_stats_cache_hits),
+ hits_before + 4);
+
+ /* Lookup in gap [15..19] returns 0 */
+ ret = ext4_es_lookup_extent(inode, 15, &next_lblk, &es, NULL);
+ KUNIT_EXPECT_EQ(test, ret, 0);
+}
+
+static void test_es_fc_replay_bypasses_tree_operations(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+ struct extent_status es;
+ static const struct expected_es expected[] = {
+ { .lblk = 10, .len = 5, .pblk = 100,
+ .type = EXTENT_STATUS_WRITTEN },
+ };
+
+ es_insert_extent(inode, 10, 5, 100, EXTENT_STATUS_WRITTEN, false);
+
+ ctx->sbi->s_mount_state |= EXT4_FC_REPLAY;
+ KUNIT_EXPECT_EQ(test,
+ ext4_es_lookup_extent(inode, 10, NULL, &es, NULL), 0);
+ ext4_es_find_extent_range(inode, ext4_es_is_written, 0, 20, &es);
+ KUNIT_EXPECT_EQ(test, es.es_len, 0U);
+ KUNIT_EXPECT_FALSE(test,
+ ext4_es_scan_range(inode, ext4_es_is_written,
+ 0, 20));
+ KUNIT_EXPECT_FALSE(test,
+ ext4_es_scan_clu(inode, ext4_es_is_written, 10));
+
+ es_insert_extent(inode, 30, 5, 300, EXTENT_STATUS_WRITTEN, false);
+ es_cache_extent(inode, 40, 5, 400, EXTENT_STATUS_WRITTEN);
+ es_insert_delayed_extent(inode, 50, 5, false, false);
+ es_remove_extent(inode, 10, 5);
+ ctx->sbi->s_mount_state &= ~EXT4_FC_REPLAY;
+
+ assert_es_tree(test, inode, expected, ARRAY_SIZE(expected));
+}
+
+struct es_merge_test_param {
+ const char *desc;
+ unsigned int nr_inserts;
+ struct expected_es inserts[3];
+ unsigned int nr_expected;
+ struct expected_es expected[3];
+};
+
+static const struct es_merge_test_param es_merge_params[] = {
+ {
+ .desc = "left merge contiguous written extents",
+ .nr_inserts = 2,
+ .inserts = {
+ { .lblk = 10, .len = 5, .pblk = 100,
+ .type = EXTENT_STATUS_WRITTEN },
+ { .lblk = 15, .len = 5, .pblk = 105,
+ .type = EXTENT_STATUS_WRITTEN },
+ },
+ .nr_expected = 1,
+ .expected = {
+ { .lblk = 10, .len = 10, .pblk = 100,
+ .type = EXTENT_STATUS_WRITTEN },
+ },
+ },
+ {
+ .desc = "right merge contiguous written extents",
+ .nr_inserts = 2,
+ .inserts = {
+ { .lblk = 15, .len = 5, .pblk = 105,
+ .type = EXTENT_STATUS_WRITTEN },
+ { .lblk = 10, .len = 5, .pblk = 100,
+ .type = EXTENT_STATUS_WRITTEN },
+ },
+ .nr_expected = 1,
+ .expected = {
+ { .lblk = 10, .len = 10, .pblk = 100,
+ .type = EXTENT_STATUS_WRITTEN },
+ },
+ },
+ {
+ .desc = "three-way bridge merge via try_to_merge_right",
+ .nr_inserts = 3,
+ .inserts = {
+ { .lblk = 10, .len = 5, .pblk = 100,
+ .type = EXTENT_STATUS_WRITTEN },
+ { .lblk = 20, .len = 5, .pblk = 110,
+ .type = EXTENT_STATUS_WRITTEN },
+ { .lblk = 15, .len = 5, .pblk = 105,
+ .type = EXTENT_STATUS_WRITTEN },
+ },
+ .nr_expected = 1,
+ .expected = {
+ { .lblk = 10, .len = 15, .pblk = 100,
+ .type = EXTENT_STATUS_WRITTEN },
+ },
+ },
+ {
+ .desc = "three-way bridge merge via try_to_merge_left",
+ .nr_inserts = 3,
+ .inserts = {
+ { .lblk = 20, .len = 5, .pblk = 110,
+ .type = EXTENT_STATUS_UNWRITTEN },
+ { .lblk = 10, .len = 5, .pblk = 100,
+ .type = EXTENT_STATUS_UNWRITTEN },
+ { .lblk = 15, .len = 5, .pblk = 105,
+ .type = EXTENT_STATUS_UNWRITTEN },
+ },
+ .nr_expected = 1,
+ .expected = {
+ { .lblk = 10, .len = 15, .pblk = 100,
+ .type = EXTENT_STATUS_UNWRITTEN },
+ },
+ },
+ {
+ .desc = "adjacent hole extents merge",
+ .nr_inserts = 2,
+ .inserts = {
+ { .lblk = 10, .len = 5, .pblk = 0,
+ .type = EXTENT_STATUS_HOLE },
+ { .lblk = 15, .len = 5, .pblk = 0,
+ .type = EXTENT_STATUS_HOLE },
+ },
+ .nr_expected = 1,
+ .expected = {
+ { .lblk = 10, .len = 10, .pblk = 0,
+ .type = EXTENT_STATUS_HOLE },
+ },
+ },
+ {
+ .desc = "discontiguous physical blocks do not merge",
+ .nr_inserts = 2,
+ .inserts = {
+ { .lblk = 10, .len = 5, .pblk = 100,
+ .type = EXTENT_STATUS_WRITTEN },
+ { .lblk = 15, .len = 5, .pblk = 200,
+ .type = EXTENT_STATUS_WRITTEN },
+ },
+ .nr_expected = 2,
+ .expected = {
+ { .lblk = 10, .len = 5, .pblk = 100,
+ .type = EXTENT_STATUS_WRITTEN },
+ { .lblk = 15, .len = 5, .pblk = 200,
+ .type = EXTENT_STATUS_WRITTEN },
+ },
+ },
+ {
+ .desc = "different status types with contiguous pblk do not merge",
+ .nr_inserts = 2,
+ .inserts = {
+ { .lblk = 10, .len = 5, .pblk = 100,
+ .type = EXTENT_STATUS_WRITTEN },
+ { .lblk = 15, .len = 5, .pblk = 105,
+ .type = EXTENT_STATUS_UNWRITTEN },
+ },
+ .nr_expected = 2,
+ .expected = {
+ { .lblk = 10, .len = 5, .pblk = 100,
+ .type = EXTENT_STATUS_WRITTEN },
+ { .lblk = 15, .len = 5, .pblk = 105,
+ .type = EXTENT_STATUS_UNWRITTEN },
+ },
+ },
+ {
+ .desc = "logically separated extents with 1-block gap do not merge",
+ .nr_inserts = 2,
+ .inserts = {
+ { .lblk = 10, .len = 5, .pblk = 100,
+ .type = EXTENT_STATUS_WRITTEN },
+ { .lblk = 16, .len = 5, .pblk = 106,
+ .type = EXTENT_STATUS_WRITTEN },
+ },
+ .nr_expected = 2,
+ .expected = {
+ { .lblk = 10, .len = 5, .pblk = 100,
+ .type = EXTENT_STATUS_WRITTEN },
+ { .lblk = 16, .len = 5, .pblk = 106,
+ .type = EXTENT_STATUS_WRITTEN },
+ },
+ },
+};
+
+static void es_merge_get_desc(const struct es_merge_test_param *param,
+ char *desc)
+{
+ strscpy(desc, param->desc, KUNIT_PARAM_DESC_SIZE);
+}
+KUNIT_ARRAY_PARAM(es_merge, es_merge_params, es_merge_get_desc);
+
+static void test_es_merge_cases(struct kunit *test)
+{
+ const struct es_merge_test_param *param = test->param_value;
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+ unsigned int i;
+
+ for (i = 0; i < param->nr_inserts; i++) {
+ const struct expected_es *ins = ¶m->inserts[i];
+
+ es_insert_extent(inode, ins->lblk, ins->len,
+ ins->pblk, ins->type, false);
+ }
+
+ assert_es_tree(test, inode, param->expected, param->nr_expected);
+}
+
+static void test_es_insert_adjacent_delayed_extents_merges(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+ static const struct expected_es expected[] = {
+ { .lblk = 10, .len = 10, .pblk = 0,
+ .type = EXTENT_STATUS_DELAYED },
+ };
+
+ es_insert_delayed_extent(inode, 10, 5, false, false);
+ es_insert_delayed_extent(inode, 15, 5, false, false);
+
+ assert_es_tree(test, inode, expected, ARRAY_SIZE(expected));
+}
+
+static void test_es_merge_preserves_referenced(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+ struct extent_status es;
+ struct rb_node *node;
+ bool is_ref = false;
+
+ /*
+ * Insert [10, 5) and [20, 5), mark [20, 5) referenced via lookup,
+ * then bridge [15, 5) so [20, 5) is merged into [10, 10) via
+ * ext4_es_try_to_merge_right().
+ */
+ es_insert_extent(inode, 10, 5, 100, EXTENT_STATUS_WRITTEN, false);
+ es_insert_extent(inode, 20, 5, 110, EXTENT_STATUS_WRITTEN, false);
+ KUNIT_ASSERT_EQ(test,
+ ext4_es_lookup_extent(inode, 20, NULL, &es, NULL), 1);
+
+ es_insert_extent(inode, 15, 5, 105, EXTENT_STATUS_WRITTEN, false);
+ KUNIT_ASSERT_EQ(test, ctx->ei->i_es_all_nr, 1U);
+
+ read_lock(&ctx->ei->i_es_lock);
+ node = rb_first(&ctx->ei->i_es_tree.root);
+ if (node)
+ is_ref = ext4_es_is_referenced(rb_entry(node,
+ struct extent_status,
+ rb_node));
+ read_unlock(&ctx->ei->i_es_lock);
+
+ KUNIT_ASSERT_NOT_NULL(test, node);
+ KUNIT_EXPECT_TRUE(test, is_ref);
+}
+
+static void
+test_es_merge_at_max_blocks_boundary_succeeds(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+ static const struct expected_es expected[] = {
+ { .lblk = 0, .len = EXT_MAX_BLOCKS, .pblk = 100,
+ .type = EXTENT_STATUS_WRITTEN },
+ };
+
+ es_insert_extent(inode, 0, 0x80000000U, 100,
+ EXTENT_STATUS_WRITTEN, false);
+ es_insert_extent(inode, 0x80000000U, 0x7fffffffU,
+ 100ULL + 0x80000000ULL,
+ EXTENT_STATUS_WRITTEN, false);
+
+ assert_es_tree(test, inode, expected, ARRAY_SIZE(expected));
+}
+
+/*
+ * Group 3: Removal, Trimming, Splitting, and Overwrites
+ */
+struct es_remove_test_param {
+ const char *desc;
+ ext4_lblk_t rem_lblk;
+ ext4_lblk_t rem_len;
+ unsigned int nr_expected;
+ struct expected_es expected[2];
+};
+
+static const struct es_remove_test_param es_remove_params[] = {
+ {
+ .desc = "remove range before extent",
+ .rem_lblk = 0,
+ .rem_len = 5,
+ .nr_expected = 1,
+ .expected = {
+ { .lblk = 10, .len = 10, .pblk = 100,
+ .type = EXTENT_STATUS_WRITTEN },
+ },
+ },
+ {
+ .desc = "remove range after extent",
+ .rem_lblk = 20,
+ .rem_len = 5,
+ .nr_expected = 1,
+ .expected = {
+ { .lblk = 10, .len = 10, .pblk = 100,
+ .type = EXTENT_STATUS_WRITTEN },
+ },
+ },
+ {
+ .desc = "remove exact extent range",
+ .rem_lblk = 10,
+ .rem_len = 10,
+ .nr_expected = 0,
+ },
+ {
+ .desc = "remove superset of extent range",
+ .rem_lblk = 5,
+ .rem_len = 20,
+ .nr_expected = 0,
+ },
+ {
+ .desc = "prefix trim of extent",
+ .rem_lblk = 10,
+ .rem_len = 4,
+ .nr_expected = 1,
+ .expected = {
+ { .lblk = 14, .len = 6, .pblk = 104,
+ .type = EXTENT_STATUS_WRITTEN },
+ },
+ },
+ {
+ .desc = "suffix trim of extent",
+ .rem_lblk = 16,
+ .rem_len = 4,
+ .nr_expected = 1,
+ .expected = {
+ { .lblk = 10, .len = 6, .pblk = 100,
+ .type = EXTENT_STATUS_WRITTEN },
+ },
+ },
+ {
+ .desc = "middle split of extent into two",
+ .rem_lblk = 13,
+ .rem_len = 4,
+ .nr_expected = 2,
+ .expected = {
+ { .lblk = 10, .len = 3, .pblk = 100,
+ .type = EXTENT_STATUS_WRITTEN },
+ { .lblk = 17, .len = 3, .pblk = 107,
+ .type = EXTENT_STATUS_WRITTEN },
+ },
+ },
+};
+
+static void es_remove_get_desc(const struct es_remove_test_param *param,
+ char *desc)
+{
+ strscpy(desc, param->desc, KUNIT_PARAM_DESC_SIZE);
+}
+KUNIT_ARRAY_PARAM(es_remove, es_remove_params, es_remove_get_desc);
+
+static void test_es_remove_geometries(struct kunit *test)
+{
+ const struct es_remove_test_param *param = test->param_value;
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+
+ es_insert_extent(inode, 10, 10, 100, EXTENT_STATUS_WRITTEN, false);
+ es_remove_extent(inode, param->rem_lblk, param->rem_len);
+
+ assert_es_tree(test, inode, param->expected, param->nr_expected);
+}
+
+static void
+test_es_remove_multi_extent_span_trims_and_deletes(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+ static const struct expected_es expected[] = {
+ { .lblk = 10, .len = 2, .pblk = 100,
+ .type = EXTENT_STATUS_WRITTEN },
+ { .lblk = 43, .len = 2, .pblk = 403,
+ .type = EXTENT_STATUS_UNWRITTEN },
+ };
+
+ es_insert_extent(inode, 10, 5, 100, EXTENT_STATUS_WRITTEN, false);
+ es_insert_extent(inode, 20, 5, 200, EXTENT_STATUS_HOLE, false);
+ es_insert_extent(inode, 30, 5, 300, EXTENT_STATUS_WRITTEN, false);
+ es_insert_extent(inode, 40, 5, 400, EXTENT_STATUS_UNWRITTEN, false);
+
+ /*
+ * Remove [12, 31) covering lblks 12..42 inclusive:
+ * - trims suffix of [10, 5) -> [10, 2)
+ * - completely removes [20, 5) and [30, 5)
+ * - trims prefix of [40, 5) -> [43, 2)
+ */
+ es_remove_extent(inode, 12, 31);
+ assert_es_tree(test, inode, expected, ARRAY_SIZE(expected));
+}
+
+static void test_es_insert_overwrite_split_and_remerge(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+ static const struct expected_es split_exp[] = {
+ { .lblk = 10, .len = 3, .pblk = 100,
+ .type = EXTENT_STATUS_UNWRITTEN },
+ { .lblk = 13, .len = 4, .pblk = 103,
+ .type = EXTENT_STATUS_WRITTEN },
+ { .lblk = 17, .len = 3, .pblk = 107,
+ .type = EXTENT_STATUS_UNWRITTEN },
+ };
+ static const struct expected_es merged_exp[] = {
+ { .lblk = 10, .len = 10, .pblk = 100,
+ .type = EXTENT_STATUS_WRITTEN },
+ };
+
+ es_insert_extent(inode, 10, 10, 100, EXTENT_STATUS_UNWRITTEN, false);
+ es_insert_extent(inode, 13, 4, 103, EXTENT_STATUS_WRITTEN, false);
+ assert_es_tree(test, inode, split_exp, ARRAY_SIZE(split_exp));
+
+ /* Convert the remaining prefix and suffix to WRITTEN; all 3 merge */
+ es_insert_extent(inode, 10, 3, 100, EXTENT_STATUS_WRITTEN, false);
+ es_insert_extent(inode, 17, 3, 107, EXTENT_STATUS_WRITTEN, false);
+ assert_es_tree(test, inode, merged_exp, ARRAY_SIZE(merged_exp));
+}
+
+/*
+ * Group 4: On-Disk Caching & Conflict Detection (ext4_es_cache_extent)
+ */
+static void
+test_es_cache_extent_inserts_and_coalesces_same_status(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+ static const struct expected_es initial_exp[] = {
+ { .lblk = 10, .len = 5, .pblk = 100,
+ .type = EXTENT_STATUS_WRITTEN },
+ };
+ static const struct expected_es coalesced_exp[] = {
+ { .lblk = 8, .len = 10, .pblk = 98,
+ .type = EXTENT_STATUS_WRITTEN },
+ };
+ int warnings_before;
+
+ warnings_before = atomic_read(&ctx->sbi->s_warning_count);
+
+ /* Cache into empty tree */
+ es_cache_extent(inode, 10, 5, 100, EXTENT_STATUS_WRITTEN);
+ assert_es_tree(test, inode, initial_exp, ARRAY_SIZE(initial_exp));
+
+ /* Caching sub-range with identical status is a no-op */
+ es_cache_extent(inode, 11, 2, 101, EXTENT_STATUS_WRITTEN);
+ assert_es_tree(test, inode, initial_exp, ARRAY_SIZE(initial_exp));
+
+ /* Caching larger covering range with same status coalesces */
+ es_cache_extent(inode, 8, 10, 98, EXTENT_STATUS_WRITTEN);
+ KUNIT_EXPECT_EQ(test, atomic_read(&ctx->sbi->s_warning_count),
+ warnings_before);
+ assert_es_tree(test, inode, coalesced_exp, ARRAY_SIZE(coalesced_exp));
+}
+
+static void
+test_es_cache_extent_conflict_covered_range_warns(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+ static const struct expected_es expected[] = {
+ { .lblk = 8, .len = 10, .pblk = 98,
+ .type = EXTENT_STATUS_WRITTEN },
+ };
+ int warnings_before;
+
+ es_cache_extent(inode, 8, 10, 98, EXTENT_STATUS_WRITTEN);
+ warnings_before = atomic_read(&ctx->sbi->s_warning_count);
+
+ /* Sub-range [10, 4) covered by [8, 10) with conflicting status */
+ es_cache_extent(inode, 10, 4, 500, EXTENT_STATUS_UNWRITTEN);
+ KUNIT_EXPECT_EQ(test, atomic_read(&ctx->sbi->s_warning_count),
+ warnings_before + 1);
+ assert_es_tree(test, inode, expected, ARRAY_SIZE(expected));
+}
+
+static void
+test_es_cache_extent_conflict_partial_overlap_warns(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+ static const struct expected_es expected[] = {
+ { .lblk = 10, .len = 5, .pblk = 100,
+ .type = EXTENT_STATUS_WRITTEN },
+ };
+ int warnings_before;
+
+ es_cache_extent(inode, 10, 5, 100, EXTENT_STATUS_WRITTEN);
+ warnings_before = atomic_read(&ctx->sbi->s_warning_count);
+
+ /*
+ * Range [8, 10) is not covered by [10, 5), so ext4_es_cache_extent()
+ * enters __es_remove_extent() which detects the status conflict and
+ * returns -EINVAL without modifying [10, 5).
+ */
+ es_cache_extent(inode, 8, 10, 500, EXTENT_STATUS_UNWRITTEN);
+ KUNIT_EXPECT_EQ(test, atomic_read(&ctx->sbi->s_warning_count),
+ warnings_before + 1);
+ assert_es_tree(test, inode, expected, ARRAY_SIZE(expected));
+}
+
+static void
+test_es_cache_extent_hole_over_delayed_does_not_warn(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+ static const struct expected_es expected[] = {
+ { .lblk = 30, .len = 5, .pblk = 0,
+ .type = EXTENT_STATUS_DELAYED },
+ };
+ int warnings_before;
+
+ es_insert_delayed_extent(inode, 30, 5, false, false);
+ warnings_before = atomic_read(&ctx->sbi->s_warning_count);
+
+ es_cache_extent(inode, 30, 5, 0, EXTENT_STATUS_HOLE);
+ KUNIT_EXPECT_EQ(test, atomic_read(&ctx->sbi->s_warning_count),
+ warnings_before);
+ assert_es_tree(test, inode, expected, ARRAY_SIZE(expected));
+}
+
+/*
+ * Group 5: Range Search & Cluster Scanning
+ */
+static void
+test_es_find_extent_range_skips_nonmatching_and_finds_next(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+ struct extent_status es;
+
+ es_insert_extent(inode, 10, 5, 100, EXTENT_STATUS_WRITTEN, false);
+ es_insert_delayed_extent(inode, 20, 5, false, false);
+ es_insert_extent(inode, 30, 5, 300, EXTENT_STATUS_UNWRITTEN, false);
+
+ /*
+ * Prime cache_es to [10, 5) WRITTEN, then search [10, 25] for DELAYED:
+ * cache_es is hit at lblk 10, fails matching_fn(ext4_es_is_delayed),
+ * and walks rb_next to find [20, 5) DELAYED.
+ */
+ KUNIT_ASSERT_EQ(test,
+ ext4_es_lookup_extent(inode, 10, NULL, &es, NULL), 1);
+ ext4_es_find_extent_range(inode, ext4_es_is_delayed, 10, 25, &es);
+ KUNIT_EXPECT_EQ(test, es.es_lblk, 20U);
+ KUNIT_EXPECT_EQ(test, es.es_len, 5U);
+ KUNIT_EXPECT_TRUE(test, ext4_es_is_delayed(&es));
+
+ /* Search [10, 18] for DELAYED when starting inside [10, 5) returns 0 */
+ KUNIT_ASSERT_EQ(test,
+ ext4_es_lookup_extent(inode, 10, NULL, &es, NULL), 1);
+ ext4_es_find_extent_range(inode, ext4_es_is_delayed, 10, 18, &es);
+ KUNIT_EXPECT_EQ(test, es.es_len, 0U);
+
+ /*
+ * Search [16, 18] in gap before [20, 5): __es_tree_search(16) returns
+ * the next extent [20, 5) following the range.
+ */
+ ext4_es_find_extent_range(inode, ext4_es_is_delayed, 16, 18, &es);
+ KUNIT_EXPECT_EQ(test, es.es_lblk, 20U);
+ KUNIT_EXPECT_EQ(test, es.es_len, 5U);
+}
+
+static void
+test_es_scan_range_matches_only_overlapping_extents(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+
+ es_insert_delayed_extent(inode, 20, 5, false, false);
+ es_insert_extent(inode, 30, 5, 300, EXTENT_STATUS_UNWRITTEN, false);
+
+ /* Gap [16, 18] before [20, 5) does not overlap */
+ KUNIT_EXPECT_FALSE(test,
+ ext4_es_scan_range(inode, ext4_es_is_delayed,
+ 16, 18));
+
+ /* Ranges overlapping [20, 5) or [30, 5) return true */
+ KUNIT_EXPECT_TRUE(test,
+ ext4_es_scan_range(inode, ext4_es_is_delayed,
+ 16, 20));
+ KUNIT_EXPECT_TRUE(test,
+ ext4_es_scan_range(inode, ext4_es_is_delayed,
+ 22, 23));
+ KUNIT_EXPECT_TRUE(test,
+ ext4_es_scan_range(inode, ext4_es_is_mapped,
+ 34, 40));
+
+ /* Range [35, 40] after [30, 5) does not overlap */
+ KUNIT_EXPECT_FALSE(test,
+ ext4_es_scan_range(inode, ext4_es_is_mapped,
+ 35, 40));
+}
+
+static void test_es_scan_clu_matches_extent_in_same_cluster(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+
+ /* Configure cluster size = 16 blocks (cluster_bits = 4) */
+ es_set_cluster_bits(ctx->sb, 4);
+
+ /* Insert delayed block at the very end of cluster 0 (lblk 15) */
+ es_insert_delayed_extent(inode, 15, 1, false, false);
+
+ KUNIT_EXPECT_TRUE(test,
+ ext4_es_scan_clu(inode, ext4_es_is_delayed, 0));
+ KUNIT_EXPECT_TRUE(test,
+ ext4_es_scan_clu(inode, ext4_es_is_delayed, 8));
+ KUNIT_EXPECT_TRUE(test,
+ ext4_es_scan_clu(inode, ext4_es_is_delayed, 15));
+ KUNIT_EXPECT_FALSE(test,
+ ext4_es_scan_clu(inode, ext4_es_is_delayed, 16));
+ KUNIT_EXPECT_FALSE(test,
+ ext4_es_scan_clu(inode, ext4_es_is_mapped, 0));
+}
+
+/*
+ * Group 6: Delayed Allocation & Bigalloc Pending Reservations
+ */
+static void
+test_es_delalloc_remove_and_overwrite_account_reserved_blocks(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+ static const struct expected_es after_rem_exp[] = {
+ { .lblk = 10, .len = 2, .pblk = 0,
+ .type = EXTENT_STATUS_DELAYED },
+ { .lblk = 15, .len = 5, .pblk = 0,
+ .type = EXTENT_STATUS_DELAYED },
+ };
+ static const struct expected_es after_ins_exp[] = {
+ { .lblk = 10, .len = 6, .pblk = 100,
+ .type = EXTENT_STATUS_WRITTEN },
+ { .lblk = 16, .len = 4, .pblk = 0,
+ .type = EXTENT_STATUS_DELAYED },
+ };
+
+ /* Delayed extents are must-keep: i_es_shk_nr remains 0 */
+ es_insert_delayed_extent(inode, 10, 10, false, false);
+ KUNIT_EXPECT_EQ(test, ctx->ei->i_es_all_nr, 1U);
+ KUNIT_EXPECT_EQ(test, ctx->ei->i_es_shk_nr, 0U);
+ KUNIT_EXPECT_TRUE(test, list_empty(&ctx->ei->i_es_list));
+
+ /* Removing 3 delayed blocks [12, 3) releases 3 reserved blocks */
+ reset_da_stub_stats(ctx);
+ es_remove_extent(inode, 12, 3);
+ KUNIT_EXPECT_EQ(test, ctx->da_release_calls, 1);
+ KUNIT_EXPECT_EQ(test, ctx->last_da_released, 3);
+ assert_es_tree(test, inode, after_rem_exp, ARRAY_SIZE(after_rem_exp));
+
+ /*
+ * Inserting WRITTEN [10, 6) overwrites [10, 2) delayed, [12, 3) gap,
+ * and [15, 1) delayed -> claims 3 delayed blocks of reservation.
+ */
+ reset_da_stub_stats(ctx);
+ es_insert_extent(inode, 10, 6, 100, EXTENT_STATUS_WRITTEN, true);
+ KUNIT_EXPECT_EQ(test, ctx->da_update_calls, 1);
+ KUNIT_EXPECT_EQ(test, ctx->last_da_used, 3);
+ KUNIT_EXPECT_EQ(test, ctx->last_da_quota_claim, 1);
+ assert_es_tree(test, inode, after_ins_exp, ARRAY_SIZE(after_ins_exp));
+}
+
+static void
+test_es_bigalloc_insert_delayed_creates_and_removes_pending(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+
+ /* Cluster size = 16 blocks: clu 0=[0..15], clu 1=[16..31], clu 2=[32..47] */
+ es_set_cluster_bits(ctx->sb, 4);
+
+ /* Single cluster with lclu_allocated = true */
+ es_insert_delayed_extent(inode, 2, 4, true, false);
+ KUNIT_EXPECT_TRUE(test, ext4_is_pending(inode, 0));
+ KUNIT_EXPECT_TRUE(test, ext4_is_pending(inode, 15));
+ KUNIT_EXPECT_FALSE(test, ext4_is_pending(inode, 16));
+
+ /* Multi-cluster [20, 20) spanning clusters 1 and 2, both allocated */
+ es_insert_delayed_extent(inode, 20, 20, true, true);
+ KUNIT_EXPECT_TRUE(test, ext4_is_pending(inode, 16));
+ KUNIT_EXPECT_TRUE(test, ext4_is_pending(inode, 32));
+ KUNIT_EXPECT_FALSE(test, ext4_is_pending(inode, 48));
+
+ /* Duplicate pending insertion on cluster 0 is idempotent */
+ es_insert_delayed_extent(inode, 8, 2, true, false);
+ KUNIT_EXPECT_TRUE(test, ext4_is_pending(inode, 0));
+
+ /* Explicit removal of pending reservation */
+ ext4_remove_pending(inode, 16);
+ KUNIT_EXPECT_FALSE(test, ext4_is_pending(inode, 16));
+ KUNIT_EXPECT_TRUE(test, ext4_is_pending(inode, 32));
+}
+
+static void
+test_es_bigalloc_revise_pending_single_cluster_halves(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+
+ /* Cluster size = 16 blocks */
+ es_set_cluster_bits(ctx->sb, 4);
+
+ /* Insert delayed extent [0, 32) covering clusters 0 and 1 */
+ es_insert_delayed_extent(inode, 0, 32, false, false);
+
+ /*
+ * 1. Allocate first half of cluster 0: [0, 8) -> WRITTEN.
+ * Delayed blocks [8, 8) remain after [0, 8) in cluster 0 (l_del=true):
+ * __revise_pending inserts pending on cluster 0 and claims 1 cluster.
+ */
+ reset_da_stub_stats(ctx);
+ es_insert_extent(inode, 0, 8, 100, EXTENT_STATUS_WRITTEN, true);
+ KUNIT_EXPECT_TRUE(test, ext4_is_pending(inode, 0));
+ KUNIT_EXPECT_EQ(test, ctx->da_update_calls, 1);
+ KUNIT_EXPECT_EQ(test, ctx->last_da_used, 1);
+
+ /*
+ * 2. Allocate second half of cluster 0: [8, 8) -> WRITTEN.
+ * No delayed blocks remain in cluster 0; pending reservation on
+ * cluster 0 is removed and 0 additional clusters are claimed.
+ */
+ reset_da_stub_stats(ctx);
+ es_insert_extent(inode, 8, 8, 108, EXTENT_STATUS_WRITTEN, true);
+ KUNIT_EXPECT_FALSE(test, ext4_is_pending(inode, 0));
+ KUNIT_EXPECT_EQ(test, ctx->da_update_calls, 0);
+
+ /*
+ * 3. Allocate second half of cluster 1 first: [24, 8) -> WRITTEN while
+ * [16, 8) remains delayed before it in cluster 1 (f_del=true branch in
+ * __revise_pending): inserts pending on cluster 1 and claims 1 cluster.
+ */
+ reset_da_stub_stats(ctx);
+ es_insert_extent(inode, 24, 8, 224, EXTENT_STATUS_WRITTEN, true);
+ KUNIT_EXPECT_TRUE(test, ext4_is_pending(inode, 16));
+ KUNIT_EXPECT_EQ(test, ctx->da_update_calls, 1);
+ KUNIT_EXPECT_EQ(test, ctx->last_da_used, 1);
+}
+
+static void
+test_es_bigalloc_revise_pending_multi_cluster_span(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+
+ /* Cluster size = 16 blocks */
+ es_set_cluster_bits(ctx->sb, 4);
+
+ /*
+ * Insert delayed [16, 32) across cluster 1 [16..31] and cluster 2
+ * [32..47], then allocate [20, 24) (lblks 20..43), leaving delayed
+ * [16, 4) in cluster 1 and delayed [44, 4) in cluster 2. Both clusters
+ * get pending reservations and 2 clusters are claimed.
+ */
+ es_insert_delayed_extent(inode, 16, 32, false, false);
+ reset_da_stub_stats(ctx);
+ es_insert_extent(inode, 20, 24, 220, EXTENT_STATUS_WRITTEN, true);
+ KUNIT_EXPECT_TRUE(test, ext4_is_pending(inode, 16));
+ KUNIT_EXPECT_TRUE(test, ext4_is_pending(inode, 32));
+ KUNIT_EXPECT_EQ(test, ctx->da_update_calls, 1);
+ KUNIT_EXPECT_EQ(test, ctx->last_da_used, 2);
+}
+
+static void
+test_es_bigalloc_remove_partial_cluster_holds_rsvd_until_empty(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+
+ /* Cluster size = 16 blocks */
+ es_set_cluster_bits(ctx->sb, 4);
+
+ es_insert_delayed_extent(inode, 0, 16, false, false);
+ reset_da_stub_stats(ctx);
+
+ es_remove_extent(inode, 0, 4);
+ KUNIT_EXPECT_EQ(test, ctx->da_release_calls, 0);
+
+ es_remove_extent(inode, 12, 4);
+ KUNIT_EXPECT_EQ(test, ctx->da_release_calls, 0);
+
+ es_remove_extent(inode, 4, 8);
+ KUNIT_EXPECT_EQ(test, ctx->da_release_calls, 1);
+ KUNIT_EXPECT_EQ(test, ctx->last_da_released, 1);
+}
+
+static void
+test_es_bigalloc_remove_fragmented_cluster_releases_once(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+
+ /* Cluster size = 16 blocks */
+ es_set_cluster_bits(ctx->sb, 4);
+
+ /*
+ * Two fragmented delayed extents within cluster 0 ([2, 3) and [10, 3))
+ * share a single cluster reservation and must release 1 cluster, not 2.
+ */
+ es_insert_delayed_extent(inode, 2, 3, false, false);
+ es_insert_delayed_extent(inode, 10, 3, false, false);
+ reset_da_stub_stats(ctx);
+
+ es_remove_extent(inode, 0, 16);
+ KUNIT_EXPECT_EQ(test, ctx->da_release_calls, 1);
+ KUNIT_EXPECT_EQ(test, ctx->last_da_released, 1);
+}
+
+static void
+test_es_bigalloc_remove_pending_cluster_cancels_pending_only(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+
+ /* Cluster size = 16 blocks */
+ es_set_cluster_bits(ctx->sb, 4);
+
+ /*
+ * Removing a delayed extent in a cluster with a pending reservation
+ * cancels the pending reservation and releases 0 clusters (because the
+ * cluster reservation was already claimed when allocated).
+ */
+ es_insert_delayed_extent(inode, 16, 8, true, false);
+ KUNIT_ASSERT_TRUE(test, ext4_is_pending(inode, 16));
+ reset_da_stub_stats(ctx);
+
+ es_remove_extent(inode, 16, 8);
+ KUNIT_EXPECT_EQ(test, ctx->da_release_calls, 0);
+ KUNIT_EXPECT_FALSE(test, ext4_is_pending(inode, 16));
+}
+
+/*
+ * Group 7: Shrinker, Referenced Aging, and Cache Clearing
+ */
+static void
+test_es_clear_inode_es_retains_only_delayed_extents(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+ static const struct expected_es only_delayed_exp[] = {
+ { .lblk = 40, .len = 5, .pblk = 0,
+ .type = EXTENT_STATUS_DELAYED },
+ };
+
+ es_insert_extent(inode, 10, 5, 100, EXTENT_STATUS_WRITTEN, false);
+ es_insert_extent(inode, 20, 5, 200, EXTENT_STATUS_UNWRITTEN, false);
+ es_insert_extent(inode, 30, 5, 0, EXTENT_STATUS_HOLE, false);
+ es_insert_delayed_extent(inode, 40, 5, false, false);
+ ext4_set_inode_state(inode, EXT4_STATE_EXT_PRECACHED);
+
+ KUNIT_EXPECT_EQ(test, ctx->ei->i_es_all_nr, 4U);
+ KUNIT_EXPECT_EQ(test, ctx->ei->i_es_shk_nr, 3U);
+
+ ext4_clear_inode_es(inode);
+
+ KUNIT_EXPECT_FALSE(test,
+ ext4_test_inode_state(inode,
+ EXT4_STATE_EXT_PRECACHED));
+ KUNIT_EXPECT_EQ(test, ctx->ei->i_es_shk_nr, 0U);
+ KUNIT_EXPECT_TRUE(test, list_empty(&ctx->ei->i_es_list));
+ assert_es_tree(test, inode, only_delayed_exp,
+ ARRAY_SIZE(only_delayed_exp));
+}
+
+static void
+test_es_shrinker_ages_referenced_and_keeps_delayed(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+ struct percpu_counter *shk_cnt = &ctx->sbi->s_es_stats.es_stats_shk_cnt;
+ struct shrink_control sc = { .nr_to_scan = 0 };
+ struct extent_status es;
+ unsigned long count, shrunk;
+ static const struct expected_es after_first_scan[] = {
+ { .lblk = 10, .len = 2, .pblk = 100,
+ .type = EXTENT_STATUS_WRITTEN },
+ { .lblk = 30, .len = 2, .pblk = 300,
+ .type = EXTENT_STATUS_WRITTEN },
+ { .lblk = 50, .len = 2, .pblk = 0,
+ .type = EXTENT_STATUS_DELAYED },
+ };
+ static const struct expected_es after_second_scan[] = {
+ { .lblk = 50, .len = 2, .pblk = 0,
+ .type = EXTENT_STATUS_DELAYED },
+ };
+
+ /* Insert 4 reclaimable WRITTEN extents and 1 non-reclaimable DELAYED */
+ es_insert_extent(inode, 10, 2, 100, EXTENT_STATUS_WRITTEN, false);
+ es_insert_extent(inode, 20, 2, 200, EXTENT_STATUS_WRITTEN, false);
+ es_insert_extent(inode, 30, 2, 300, EXTENT_STATUS_WRITTEN, false);
+ es_insert_extent(inode, 40, 2, 400, EXTENT_STATUS_WRITTEN, false);
+ es_insert_delayed_extent(inode, 50, 2, false, false);
+
+ /* Mark [10, 2) and [30, 2) as EXTENT_STATUS_REFERENCED via lookup */
+ KUNIT_ASSERT_EQ(test,
+ ext4_es_lookup_extent(inode, 10, NULL, &es, NULL), 1);
+ KUNIT_ASSERT_EQ(test,
+ ext4_es_lookup_extent(inode, 30, NULL, &es, NULL), 1);
+
+ /*
+ * Fold per-CPU counter deltas into the central count so count_objects
+ * (which uses percpu_counter_read_positive) sees all 4 extents on SMP.
+ */
+ percpu_counter_set(shk_cnt, percpu_counter_sum_positive(shk_cnt));
+ count = es_shrinker_count(ctx, &sc);
+ KUNIT_EXPECT_EQ(test, count, 4UL);
+
+ /*
+ * First scan (nr_to_scan = 5):
+ * - [20, 2) and [40, 2) are unreferenced and reclaimed (shrunk = 2)
+ * - [10, 2) and [30, 2) have REFERENCED cleared and survive
+ * - [50, 2) is DELAYED (must_keep) and survives
+ */
+ sc.nr_to_scan = 5;
+ shrunk = es_shrinker_scan(ctx, &sc);
+ KUNIT_EXPECT_EQ(test, shrunk, 2UL);
+ KUNIT_EXPECT_EQ(test, ctx->ei->i_es_shk_nr, 2U);
+ assert_es_tree(test, inode, after_first_scan,
+ ARRAY_SIZE(after_first_scan));
+
+ /*
+ * Second scan (nr_to_scan = 5):
+ * - [10, 2) and [30, 2) are now unreferenced and reclaimed (shrunk = 2)
+ * - Only [50, 2) DELAYED remains; inode is removed from s_es_list
+ */
+ sc.nr_to_scan = 5;
+ shrunk = es_shrinker_scan(ctx, &sc);
+ KUNIT_EXPECT_EQ(test, shrunk, 2UL);
+ KUNIT_EXPECT_EQ(test, ctx->ei->i_es_shk_nr, 0U);
+ KUNIT_EXPECT_TRUE(test, list_empty(&ctx->ei->i_es_list));
+ assert_es_tree(test, inode, after_second_scan,
+ ARRAY_SIZE(after_second_scan));
+}
+
+static void
+test_es_shrinker_cursor_advances_and_wraps_around(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+ struct shrink_control sc = {};
+ unsigned long shrunk;
+
+ es_insert_extent(inode, 10, 2, 100, EXTENT_STATUS_WRITTEN, false);
+ es_insert_extent(inode, 20, 2, 200, EXTENT_STATUS_WRITTEN, false);
+ es_insert_extent(inode, 30, 2, 300, EXTENT_STATUS_WRITTEN, false);
+
+ sc.nr_to_scan = 1;
+ shrunk = es_shrinker_scan(ctx, &sc);
+ KUNIT_EXPECT_EQ(test, shrunk, 1UL);
+ KUNIT_EXPECT_EQ(test, ctx->ei->i_es_shrink_lblk, 20U);
+
+ /* Re-insert [10, 2) behind the shrink cursor; next scan wraps to it */
+ es_insert_extent(inode, 10, 2, 100, EXTENT_STATUS_WRITTEN, false);
+ sc.nr_to_scan = 3;
+ shrunk = es_shrinker_scan(ctx, &sc);
+ KUNIT_EXPECT_EQ(test, shrunk, 3UL);
+ KUNIT_EXPECT_EQ(test, ctx->ei->i_es_all_nr, 0U);
+}
+
+static void
+test_es_shrinker_skips_precached_inode_until_last_resort(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode1 = &ctx->ei->vfs_inode;
+ struct inode *inode2;
+ struct shrink_control sc = {};
+ unsigned long shrunk;
+
+ inode2 = es_alloc_test_inode(test, ctx->sb, 13);
+
+ es_insert_extent(inode1, 10, 2, 100, EXTENT_STATUS_WRITTEN, false);
+ ext4_set_inode_state(inode1, EXT4_STATE_EXT_PRECACHED);
+ es_insert_extent(inode2, 10, 2, 200, EXTENT_STATUS_WRITTEN, false);
+
+ /* First scan skips precached inode1 and reclaims from inode2 */
+ sc.nr_to_scan = 1;
+ shrunk = es_shrinker_scan(ctx, &sc);
+ KUNIT_EXPECT_EQ(test, shrunk, 1UL);
+ KUNIT_EXPECT_EQ(test, ctx->ei->i_es_shk_nr, 1U);
+ KUNIT_EXPECT_EQ(test, EXT4_I(inode2)->i_es_shk_nr, 0U);
+
+ /*
+ * Now only precached inode1 remains on s_es_list; shrinker retries
+ * and reclaims from inode1 as a last resort.
+ */
+ sc.nr_to_scan = 1;
+ shrunk = es_shrinker_scan(ctx, &sc);
+ KUNIT_EXPECT_EQ(test, shrunk, 1UL);
+ KUNIT_EXPECT_EQ(test, ctx->ei->i_es_shk_nr, 0U);
+}
+
+static void test_es_seq_shrinker_info_show_formats_stats(struct kunit *test)
+{
+ struct es_test_ctx *ctx = test->priv;
+ struct inode *inode = &ctx->ei->vfs_inode;
+ struct seq_file seq = {};
+ char *buf;
+
+ es_insert_extent(inode, 10, 2, 100, EXTENT_STATUS_WRITTEN, false);
+
+ buf = kunit_kzalloc(test, PAGE_SIZE, GFP_KERNEL);
+ KUNIT_ASSERT_NOT_NULL(test, buf);
+ seq.buf = buf;
+ seq.size = PAGE_SIZE;
+ seq.private = ctx->sb;
+
+ KUNIT_EXPECT_EQ(test,
+ ext4_seq_es_shrinker_info_show(&seq, SEQ_START_TOKEN),
+ 0);
+ KUNIT_EXPECT_GT(test, seq.count, 0UL);
+ KUNIT_EXPECT_NOT_NULL(test, strstr(buf, "reclaimable objects"));
+}
+
+static struct kunit_case extents_status_test_cases[] = {
+ KUNIT_CASE(test_es_bitfield_written_and_unwritten_encoding),
+ KUNIT_CASE(test_es_bitfield_delayed_and_hole_encoding),
+ KUNIT_CASE(test_es_bitfield_referenced_and_pblock_update_preserve_state),
+ KUNIT_CASE(test_es_lookup_empty_tree_returns_miss),
+ KUNIT_CASE(test_es_insert_zero_len_is_noop),
+ KUNIT_CASE(test_es_lookup_hits_cache_and_rbtree_with_next_lblk),
+ KUNIT_CASE(test_es_fc_replay_bypasses_tree_operations),
+ KUNIT_CASE_PARAM(test_es_merge_cases, es_merge_gen_params),
+ KUNIT_CASE(test_es_insert_adjacent_delayed_extents_merges),
+ KUNIT_CASE(test_es_merge_preserves_referenced),
+ KUNIT_CASE(test_es_merge_at_max_blocks_boundary_succeeds),
+ KUNIT_CASE_PARAM(test_es_remove_geometries, es_remove_gen_params),
+ KUNIT_CASE(test_es_remove_multi_extent_span_trims_and_deletes),
+ KUNIT_CASE(test_es_insert_overwrite_split_and_remerge),
+ KUNIT_CASE(test_es_cache_extent_inserts_and_coalesces_same_status),
+ KUNIT_CASE(test_es_cache_extent_conflict_covered_range_warns),
+ KUNIT_CASE(test_es_cache_extent_conflict_partial_overlap_warns),
+ KUNIT_CASE(test_es_cache_extent_hole_over_delayed_does_not_warn),
+ KUNIT_CASE(test_es_find_extent_range_skips_nonmatching_and_finds_next),
+ KUNIT_CASE(test_es_scan_range_matches_only_overlapping_extents),
+ KUNIT_CASE(test_es_scan_clu_matches_extent_in_same_cluster),
+ KUNIT_CASE(test_es_delalloc_remove_and_overwrite_account_reserved_blocks),
+ KUNIT_CASE(test_es_bigalloc_insert_delayed_creates_and_removes_pending),
+ KUNIT_CASE(test_es_bigalloc_revise_pending_single_cluster_halves),
+ KUNIT_CASE(test_es_bigalloc_revise_pending_multi_cluster_span),
+ KUNIT_CASE(test_es_bigalloc_remove_partial_cluster_holds_rsvd_until_empty),
+ KUNIT_CASE(test_es_bigalloc_remove_fragmented_cluster_releases_once),
+ KUNIT_CASE(test_es_bigalloc_remove_pending_cluster_cancels_pending_only),
+ KUNIT_CASE(test_es_clear_inode_es_retains_only_delayed_extents),
+ KUNIT_CASE(test_es_shrinker_ages_referenced_and_keeps_delayed),
+ KUNIT_CASE(test_es_shrinker_cursor_advances_and_wraps_around),
+ KUNIT_CASE(test_es_shrinker_skips_precached_inode_until_last_resort),
+ KUNIT_CASE(test_es_seq_shrinker_info_show_formats_stats),
+ {}
+};
+
+static struct kunit_suite extents_status_test_suite = {
+ .name = "ext4_extents_status_test",
+ .init = es_kunit_init,
+ .test_cases = extents_status_test_cases,
+};
+
+kunit_test_suites(&extents_status_test_suite);
+
+MODULE_DESCRIPTION("KUnit tests for ext4 extents status tree and pending reservations");
+MODULE_LICENSE("GPL");
diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c
index 6e4a191e82191..64bac0c4c1fa0 100644
--- a/fs/ext4/extents_status.c
+++ b/fs/ext4/extents_status.c
@@ -2390,3 +2390,22 @@ static int __revise_pending(struct inode *inode, ext4_lblk_t lblk,
out:
return (ret < 0) ? ret : pendings;
}
+
+#if IS_ENABLED(CONFIG_EXT4_KUNIT_TESTS)
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_init_tree);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_insert_extent);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_cache_extent);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_remove_extent);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_find_extent_range);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_lookup_extent);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_scan_range);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_scan_clu);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_register_shrinker);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_unregister_shrinker);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_seq_es_shrinker_info_show);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_init_pending_tree);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_remove_pending);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_is_pending);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_insert_delayed_extent);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_clear_inode_es);
+#endif
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 26f0f9714f03c..966a760f64e69 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -350,6 +350,9 @@ void ext4_da_update_reserve_space(struct inode *inode,
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
struct ext4_inode_info *ei = EXT4_I(inode);
+ KUNIT_STATIC_STUB_REDIRECT(ext4_da_update_reserve_space,
+ inode, used, quota_claim);
+
spin_lock(&ei->i_block_reservation_lock);
trace_ext4_da_update_reserve_space(inode, used, quota_claim);
if (unlikely(used > ei->i_reserved_data_blocks)) {
@@ -1646,6 +1649,8 @@ void ext4_da_release_space(struct inode *inode, int to_free)
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
struct ext4_inode_info *ei = EXT4_I(inode);
+ KUNIT_STATIC_STUB_REDIRECT(ext4_da_release_space, inode, to_free);
+
if (!to_free)
return; /* Nothing to release, exit */
@@ -6973,3 +6978,8 @@ vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf)
sb_end_pagefault(inode->i_sb);
return ret;
}
+
+#if IS_ENABLED(CONFIG_EXT4_KUNIT_TESTS)
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_da_update_reserve_space);
+EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_da_release_space);
+#endif
|
| 3/2 | 2026/10/21 12:48 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 28279 output: 25 thoughts: 895 Thoughts: **Analyzing the Patch for Fuzzing Eligibility** Okay, so I'm looking at this patch and my initial thought is, "what's the fuzzing impact here?". The patch description says it adds KUnit tests for ext4 extents status tree and bigalloc pending reservations, along with some export symbol additions for ext4 tests and the insertion of `KUNIT_STATIC_STUB_REDIRECT` macros in `ext4_da_update_reserve_space` and `ext4_da_release_space`. First, I need to consult those negative criteria rules. Specifically sections 2 and 3 of the instructions which define when we can immediately disregard a patch for fuzzing. Section 2 says we can return `WorthFuzzing=false` if the code falls strictly into one or more of these categories, and in my mind the question is if the KUnit test additions fall under the exclusion. We have to be very careful to evaluate what is changed. My first thought is, are KUnit tests treated as fuzzable code? Or are they considered unit tests, self-tests? The instructions say "User-space directories, self-tests, samples, or scripts... that do not affect the compiled kernel image (vmlinux) or kernel modules" are excluded. But hold on, KUnit tests are **in-kernel**. The patch shows `ext4-test-objs += extents_status-test.o`. That means they're compiled into the kernel. So, the question remains: does this affect the compiled kernel image? Now, let's break down the actual code changes. I'm going to look at the diffs. 1. In `fs/ext4/Makefile`, a new object file `extents_status-test.o` is added to the `ext4-test-objs` list. That's a clear indication that this test is now compiled into the kernel if `CONFIG_EXT4_KUNIT_TESTS` is enabled. 2. `fs/ext4/extents.c` has moved some EXPORT\_SYMBOL\_FOR\_EXT4\_TEST calls to `extents_status.c` because they logically belong there. The patch is moving them around, not fundamentally changing the behavior, but it is moving some definitions around. 3. `fs/ext4/extents_status-test.c` is the new KUnit test file. This is the new code that is added to the kernel. 4. In `fs/ext4/extents_status.c`, there are now `EXPORT_SYMBOL_FOR_EXT4_TEST` calls, but only under `#if IS_ENABLED(CONFIG_EXT4_KUNIT_TESTS)`. 5. In `fs/ext4/inode.c`, the patch adds `KUNIT_STATIC_STUB_REDIRECT` to `ext4_da_update_reserve_space` and `ext4_da_release_space`. Now, I need to know what `KUNIT_STATIC_STUB_REDIRECT` actually *does*. I'll need to use `grep` to understand the impact of this macro. I will search for the definition of that macro in the source code to get a good understanding of what it does. Alright, that's the full picture. The key is to understand if those `KUNIT_STATIC_STUB_REDIRECT` changes affect control flow or data structures in a way that opens up new fuzzing paths. We are adding new KUnit tests and new symbols that may lead to changes in control or data. This requires further investigation to decide if this patch has a worth fuzzing value. |
| 4/2 | 2026/10/21 12:48 | tool | grepper |
0mArgs:{
"Expression": "#define KUNIT_STATIC_STUB_REDIRECT"
}Results: {
"Output": "include/kunit/static_stub.h-13-/* If CONFIG_KUNIT is not enabled, these stubs quietly disappear. */\ninclude/kunit/static_stub.h:14:#define KUNIT_STATIC_STUB_REDIRECT(real_fn_name, args...) do {} while (0)\ninclude/kunit/static_stub.h-15-\n--\ninclude/kunit/static_stub.h-58- */\ninclude/kunit/static_stub.h:59:#define KUNIT_STATIC_STUB_REDIRECT(real_fn_name, args...)\t\t\\\ninclude/kunit/static_stub.h-60-do {\t\t\t\t\t\t\t\t\t\\\n"
} |
| 5/2 | 2026/10/21 12:48 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 30152 output: 37 thoughts: 25 Thoughts: Here's my analysis of the provided text, delivered as a first-person perspective, with the assumption I'm speaking to a fellow expert: **Diving into `kunit/static_stub.h` - Lines 50-90** Alright, let's zero in on lines 50 through 90 of `include/kunit/static_stub.h`. I'm guessing this section is where they're handling the core mechanics of KUnit's static stub implementation. Based on the file name and the general context, I'm expecting to see definitions for how stubs are declared, possibly how they're replaced, and likely some crucial macro magic. I anticipate this is where the *real* work is happening in terms of the preprocessor tricks. I need to understand how the compiler is being manipulated to create the illusion of a stubbed function. Are they using function pointers? Or inline assembly? Maybe some clever use of weak symbols? The goal, of course, is to be able to seamlessly insert test code in place of actual kernel functions without disrupting the rest of the kernel's structure. Understanding this mechanism is vital, so I'm paying close attention to any uses of `#define`, `#ifdef`, or potentially complex macro expansions. This is where the magic happens, and these lines are key to the runtime behavior of KUnit. This section should clarify how they're managing symbol visibility during the test process. |
| 6/2 | 2026/10/21 12:48 | tool | read-file |
0mArgs:{
"File": "include/kunit/static_stub.h",
"FirstLine": 50,
"LineCount": 40
}Results: {
"Contents": " 50:\t *\t}\n 51:\t *\n 52:\t *\tvoid example_test(struct kunit *test)\n 53:\t *\t{\n 54:\t *\t\tkunit_activate_static_stub(test, real_func, replacement_func);\n 55:\t *\t\tKUNIT_EXPECT_EQ(test, real_func(1), 42);\n 56:\t *\t}\n 57:\t *\n 58:\t */\n 59:\t#define KUNIT_STATIC_STUB_REDIRECT(real_fn_name, args...)\t\t\\\n 60:\tdo {\t\t\t\t\t\t\t\t\t\\\n 61:\t\ttypeof(\u0026real_fn_name) replacement;\t\t\t\t\\\n 62:\t\tstruct kunit *current_test = kunit_get_current_test();\t\t\\\n 63:\t\t\t\t\t\t\t\t\t\t\\\n 64:\t\tif (likely(!current_test))\t\t\t\t\t\\\n 65:\t\t\tbreak;\t\t\t\t\t\t\t\\\n 66:\t\t\t\t\t\t\t\t\t\t\\\n 67:\t\treplacement = kunit_hooks.get_static_stub_address(current_test,\t\\\n 68:\t\t\t\t\t\t\t\t\u0026real_fn_name);\t\\\n 69:\t\t\t\t\t\t\t\t\t\t\\\n 70:\t\tif (unlikely(replacement))\t\t\t\t\t\\\n 71:\t\t\treturn replacement(args);\t\t\t\t\\\n 72:\t} while (0)\n 73:\t\n 74:\t/* Helper function for kunit_activate_static_stub(). The macro does\n 75:\t * typechecking, so use it instead.\n 76:\t */\n 77:\tvoid __kunit_activate_static_stub(struct kunit *test,\n 78:\t\t\t\t\t void *real_fn_addr,\n 79:\t\t\t\t\t void *replacement_addr);\n 80:\t\n 81:\t/**\n 82:\t * kunit_activate_static_stub() - replace a function using static stubs.\n 83:\t * @test: A pointer to the 'struct kunit' test context for the current test.\n 84:\t * @real_fn_addr: The address of the function to replace.\n 85:\t * @replacement_addr: The address of the function to replace it with.\n 86:\t *\n 87:\t * When activated, calls to real_fn_addr from within this test (even if called\n 88:\t * indirectly) will instead call replacement_addr. The function pointed to by\n 89:\t * real_fn_addr must begin with the static stub prologue in\n"
} |
| 7/2 | 2026/10/21 12:48 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 31141 output: 27 thoughts: 1142 Thoughts: **Fuzzing Applicability: KUnit and Ext4 Test Symbol Export** Okay, let's break this down. First, this `KUNIT_STATIC_STUB_REDIRECT` thing is a no-op if KUnit isn't enabled, but if it *is* enabled, it calls `kunit_get_current_test()`. The question is, can Syzkaller, which is what we are using to test for issues, fuzz KUnit tests? My initial thought is no, because KUnit tests are typically run at boot, module load, or through debugfs. They aren't designed to be run from userspace in the same way as regular unit tests. Syzkaller, in contrast, targets user-space accessible functionality. Is it worth fuzzing? Let's carefully check the guidelines. The core principle for patch fuzzing is reachability. If the code is not in the execution path, it is not worth fuzzing. The key is to find crashes, regressions, exposed latent bugs, and newly triggered assertions. Even "no functional change" is not taken for granted as code refactoring can uncover latent kernel bugs. *Especially* with assertions, we need to fuzz. If the modified code is reachable, it must be fuzzed, particularly if it involves assertions or refactorings. So, when do we return `WorthFuzzing=false`? Mainly when the change is non-executable or unreachable. That includes things like documentation, user-space tools, logging that doesn't affect control flow, build system changes, and, crucially, structurally unreachable hardware or execution paths that can't be reached in standard QEMU environments. When do we return `WorthFuzzing=true`? This is our key: we fuzz whenever we touch reachable executable code. This includes core subsystems, refactorings, runtime assertions, and accessible drivers. Now, let's look at the actual patch. What's changed? We have `ext4-test-objs += extents_status-test.o` and `EXPORT_SYMBOL_FOR_EXT4_TEST` in `fs/ext4/extents.c` and `fs/ext4/extents_status.c`. The first change adds an object file, which is a new test. The latter is a symbol export specifically for ext4 tests. This seems to be adding test functionality, specifically related to the ext4 file system. I need to grep for `EXPORT_SYMBOL_FOR_EXT4_TEST` to know its use. The question is: is this test code *reachable*? Is it part of the normal execution path, or is it only accessible via specific debug interfaces or at boot? If the change modifies a reachable execution path, it's worth fuzzing based on the criteria. This is particularly relevant if the test touches kernel internals that are exposed through the `EXPORT_SYMBOL` macro. |
| 8/2 | 2026/10/21 12:49 | tool | grepper |
0mArgs:{
"Expression": "#define EXPORT_SYMBOL_FOR_EXT4_TEST"
}Results: {
"Output": "fs/ext4/ext4.h=4068=extern int ext4_block_write_begin(handle_t *handle, struct folio *folio,\n--\nfs/ext4/ext4.h-4072-#if IS_ENABLED(CONFIG_EXT4_KUNIT_TESTS)\nfs/ext4/ext4.h:4073:#define EXPORT_SYMBOL_FOR_EXT4_TEST(sym) \\\nfs/ext4/ext4.h-4074-\tEXPORT_SYMBOL_FOR_MODULES(sym, \"ext4-test\")\n"
} |
| 9/2 | 2026/10/21 12:49 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 33071 output: 24 thoughts: 511 Thoughts: **Analyzing a KUnit Test Integration**
Okay, so `EXPORT_SYMBOL_FOR_EXT4_TEST` is clearly just about exporting symbols for a test module – that's straightforward. Then I see these `KUNIT_STATIC_STUB_REDIRECT` macros applied to `ext4_da_update_reserve_space` and `ext4_da_release_space` in `fs/ext4/inode.c`. My immediate thought is, "Wait, is this monkey-patching the core logic of those functions?"
But then I remember that `KUNIT_STATIC_STUB_REDIRECT` is for KUnit static stubs. Ah, right. It's a KUnit hook. And when the kernel runs normally – say, under syzkaller exercising syscalls – `kunit_get_current_test()` returns `NULL`. That macro short-circuits the redirection if `current_test` is `NULL`. The code clearly shows the early exit:
```c
#define KUNIT_STATIC_STUB_REDIRECT(real_fn_name, args...) \
do { \
typeof(&real_fn_name) replacement; \
struct kunit *current_test = kunit_get_current_test(); \
\
if (likely(!current_test)) \
break; \
...
```
So, this looks like it *is* setting up a KUnit test suite. The patch title, "syz-cluster: applied patch under review", reinforces this suspicion. And bingo! It's adding `fs/ext4/extents_status-test.c` – a whopping 1640 lines of KUnit tests! Plus, the necessary exports and static stub redirects to enable mocking and stubbing of functions for testing.
Now, the important question...is KUnit test code *itself* being fuzzed by syzkaller? Can syzkaller execute KUnit test suites? I need to think carefully here:
1. Are KUnit tests *intended* to be fuzzed by syzkaller?
Syzkaller is all about fuzzing kernel syscalls, right? From user-space. Does syzkaller even have a mechanism to run KUnit tests? I need to check how `kunit` is integrated, and whether it's triggered from syzkaller. Does `/sys/kernel/debug/kunit/<suite>/run` exist in debugfs? I should check syzkaller or kernel source for `kunit`.
|
| 10/2 | 2026/10/21 12:49 | tool | grepper |
0mArgs:{
"Expression": "kunit_debugfs|/kunit/"
}Results: {
"Output": "\nFull output is too long, showing 200 out of 1194 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (89 files in total):\nDocumentation/crypto/libcrypto.rst:3\nDocumentation/dev-tools/container.rst:1\nDocumentation/dev-tools/kasan.rst:2\nDocumentation/dev-tools/kmsan.rst:6\nDocumentation/dev-tools/ktap.rst:1\nDocumentation/dev-tools/kunit/api/functionredirection.rst:1\nDocumentation/dev-tools/kunit/api/index.rst:6\nDocumentation/dev-tools/kunit/api/of.rst:1\nDocumentation/dev-tools/kunit/api/platformdevice.rst:1\nDocumentation/dev-tools/kunit/api/resource.rst:2\nDocumentation/dev-tools/kunit/api/test.rst:1\nDocumentation/dev-tools/kunit/architecture.rst:9\nDocumentation/dev-tools/kunit/faq.rst:4\nDocumentation/dev-tools/kunit/index.rst:4\nDocumentation/dev-tools/kunit/run_manual.rst:3\nDocumentation/dev-tools/kunit/run_wrapper.rst:24\nDocumentation/dev-tools/kunit/running_tips.rst:14\nDocumentation/dev-tools/kunit/start.rst:12\nDocumentation/dev-tools/kunit/style.rst:1\nDocumentation/dev-tools/kunit/usage.rst:8\nDocumentation/dev-tools/testing-overview.rst:2\nDocumentation/driver-api/generic_pt.rst:1\nDocumentation/gpu/drm-internals.rst:2\nDocumentation/gpu/todo.rst:1\nDocumentation/gpu/vc4.rst:1\nDocumentation/gpu/vkms.rst:2\nDocumentation/rust/testing.rst:3\nDocumentation/translations/zh_CN/dev-tools/kasan.rst:2\nDocumentation/translations/zh_CN/dev-tools/kmsan.rst:6\nDocumentation/translations/zh_CN/dev-tools/testing-overview.rst:2\nDocumentation/translations/zh_CN/rust/testing.rst:3\nDocumentation/translations/zh_TW/dev-tools/kasan.rst:2\nDocumentation/translations/zh_TW/dev-tools/testing-overview.rst:2\nMAINTAINERS:4\narch/riscv/kernel/tests/Kconfig.debug:1\ndrivers/firewire/Kconfig:6\ndrivers/firmware/cirrus/Kconfig:1\ndrivers/fpga/tests/Kconfig:1\ndrivers/gpu/drm/Kconfig.debug:1\ndrivers/gpu/drm/amd/display/Kconfig:1\ndrivers/gpu/drm/amd/display/amdgpu_dm/tests/.kunitconfig:1\ndrivers/gpu/drm/ci/kunit.sh:1\ndrivers/gpu/drm/display/drm_hdmi_state_helper.c:1\ndrivers/gpu/drm/vc4/Kconfig:1\ndrivers/gpu/drm/vkms/Kconfig:1\ndrivers/hid/Kconfig:1\ndrivers/iio/test/Kconfig:4\ndrivers/net/ethernet/ibm/Kconfig:1\ndrivers/net/ethernet/microchip/vcap/Kconfig:1\ndrivers/phy/Kconfig:1\n... and 39 more files\n\nDocumentation/crypto/libcrypto.rst=127=KUnit tests, they are included in the set of tests that is run by\nDocumentation/crypto/libcrypto.rst:128:``tools/testing/kunit/kunit.py run --alltests``.\nDocumentation/crypto/libcrypto.rst-129-\n--\nDocumentation/crypto/libcrypto.rst=131=For example, here's how to run them in user-mode Linux:\n--\nDocumentation/crypto/libcrypto.rst-134-\nDocumentation/crypto/libcrypto.rst:135: tools/testing/kunit/kunit.py run --kunitconfig=lib/crypto/\nDocumentation/crypto/libcrypto.rst-136-\n--\nDocumentation/crypto/libcrypto.rst=139=either in QEMU or on appropriate hardware. Here's one example with QEMU:\n--\nDocumentation/crypto/libcrypto.rst-142-\nDocumentation/crypto/libcrypto.rst:143: tools/testing/kunit/kunit.py run --kunitconfig=lib/crypto/ --arch=arm64 --make_options LLVM=1\nDocumentation/crypto/libcrypto.rst-144-\n--\nDocumentation/dev-tools/container.rst=212=To run KUnit in an interactive shell and get the full output::\n--\nDocumentation/dev-tools/container.rst-214- scripts/container -s -i kernel.org/gcc:kunit -- \\\nDocumentation/dev-tools/container.rst:215: tools/testing/kunit/kunit.py \\\nDocumentation/dev-tools/container.rst-216- run \\\n--\nDocumentation/dev-tools/kasan.rst=548=There are a few ways to run the KASAN tests.\n--\nDocumentation/dev-tools/kasan.rst-564- readable way. This will not print the KASAN reports of the tests that passed.\nDocumentation/dev-tools/kasan.rst:565: See `KUnit documentation \u003chttps://www.kernel.org/doc/html/latest/dev-tools/kunit/index.html\u003e`_\nDocumentation/dev-tools/kasan.rst-566- for more up-to-date information on ``kunit_tool``.\nDocumentation/dev-tools/kasan.rst-567-\nDocumentation/dev-tools/kasan.rst:568:.. _KUnit: https://www.kernel.org/doc/html/latest/dev-tools/kunit/index.html\n--\nDocumentation/dev-tools/kmsan.rst=29=Here is an example of a KMSAN report::\n--\nDocumentation/dev-tools/kmsan.rst-33- test_uninit_kmsan_check_memory+0x1be/0x380 mm/kmsan/kmsan_test.c:273\nDocumentation/dev-tools/kmsan.rst:34: kunit_run_case_internal lib/kunit/test.c:333\nDocumentation/dev-tools/kmsan.rst:35: kunit_try_run_case+0x206/0x420 lib/kunit/test.c:374\nDocumentation/dev-tools/kmsan.rst:36: kunit_generic_run_threadfn_adapter+0x6d/0xc0 lib/kunit/try-catch.c:28\nDocumentation/dev-tools/kmsan.rst-37- kthread+0x721/0x850 kernel/kthread.c:327\n--\nDocumentation/dev-tools/kmsan.rst-42- test_uninit_kmsan_check_memory+0x1a2/0x380 mm/kmsan/kmsan_test.c:271\nDocumentation/dev-tools/kmsan.rst:43: kunit_run_case_internal lib/kunit/test.c:333\nDocumentation/dev-tools/kmsan.rst:44: kunit_try_run_case+0x206/0x420 lib/kunit/test.c:374\nDocumentation/dev-tools/kmsan.rst:45: kunit_generic_run_threadfn_adapter+0x6d/0xc0 lib/kunit/try-catch.c:28\nDocumentation/dev-tools/kmsan.rst-46- kthread+0x721/0x850 kernel/kthread.c:327\n--\nDocumentation/dev-tools/ktap.rst=304=See also:\n--\nDocumentation/dev-tools/ktap.rst-313-- The KUnit documentation:\nDocumentation/dev-tools/ktap.rst:314: Documentation/dev-tools/kunit/index.rst\n--\nDocumentation/dev-tools/kunit/api/functionredirection.rst=158=API Reference\n--\nDocumentation/dev-tools/kunit/api/functionredirection.rst-160-\nDocumentation/dev-tools/kunit/api/functionredirection.rst:161:.. kernel-doc:: include/kunit/static_stub.h\nDocumentation/dev-tools/kunit/api/functionredirection.rst-162- :internal:\n--\nDocumentation/dev-tools/kunit/api/index.rst=20=Core KUnit API\n--\nDocumentation/dev-tools/kunit/api/index.rst-22-\nDocumentation/dev-tools/kunit/api/index.rst:23:Documentation/dev-tools/kunit/api/test.rst\nDocumentation/dev-tools/kunit/api/index.rst-24-\n--\nDocumentation/dev-tools/kunit/api/index.rst-26-\nDocumentation/dev-tools/kunit/api/index.rst:27:Documentation/dev-tools/kunit/api/resource.rst\nDocumentation/dev-tools/kunit/api/index.rst-28-\n--\nDocumentation/dev-tools/kunit/api/index.rst-30-\nDocumentation/dev-tools/kunit/api/index.rst:31:Documentation/dev-tools/kunit/api/functionredirection.rst\nDocumentation/dev-tools/kunit/api/index.rst-32-\n--\nDocumentation/dev-tools/kunit/api/index.rst=35=Driver KUnit API\n--\nDocumentation/dev-tools/kunit/api/index.rst-37-\nDocumentation/dev-tools/kunit/api/index.rst:38:Documentation/dev-tools/kunit/api/clk.rst\nDocumentation/dev-tools/kunit/api/index.rst-39-\n--\nDocumentation/dev-tools/kunit/api/index.rst-41-\nDocumentation/dev-tools/kunit/api/index.rst:42:Documentation/dev-tools/kunit/api/of.rst\nDocumentation/dev-tools/kunit/api/index.rst-43-\n--\nDocumentation/dev-tools/kunit/api/index.rst-45-\nDocumentation/dev-tools/kunit/api/index.rst:46:Documentation/dev-tools/kunit/api/platformdevice.rst\nDocumentation/dev-tools/kunit/api/index.rst-47-\n--\nDocumentation/dev-tools/kunit/api/of.rst=7=The KUnit device tree API is used to test device tree (of_*) dependent code.\nDocumentation/dev-tools/kunit/api/of.rst-8-\nDocumentation/dev-tools/kunit/api/of.rst:9:.. kernel-doc:: include/kunit/of.h\nDocumentation/dev-tools/kunit/api/of.rst-10- :internal:\n--\nDocumentation/dev-tools/kunit/api/platformdevice.rst=7=The KUnit platform device API is used to test platform devices.\nDocumentation/dev-tools/kunit/api/platformdevice.rst-8-\nDocumentation/dev-tools/kunit/api/platformdevice.rst:9:.. kernel-doc:: lib/kunit/platform.c\nDocumentation/dev-tools/kunit/api/platformdevice.rst-10- :export:\n--\nDocumentation/dev-tools/kunit/api/resource.rst=10=state on a per-test basis, register custom cleanup actions, and more.\nDocumentation/dev-tools/kunit/api/resource.rst-11-\nDocumentation/dev-tools/kunit/api/resource.rst:12:.. kernel-doc:: include/kunit/resource.h\nDocumentation/dev-tools/kunit/api/resource.rst-13- :internal:\n--\nDocumentation/dev-tools/kunit/api/resource.rst=19=Include ``kunit/device.h`` to use these.\nDocumentation/dev-tools/kunit/api/resource.rst-20-\nDocumentation/dev-tools/kunit/api/resource.rst:21:.. kernel-doc:: include/kunit/device.h\nDocumentation/dev-tools/kunit/api/resource.rst-22- :internal:\n--\nDocumentation/dev-tools/kunit/api/test.rst=7=This file documents all of the standard testing API.\nDocumentation/dev-tools/kunit/api/test.rst-8-\nDocumentation/dev-tools/kunit/api/test.rst:9:.. kernel-doc:: include/kunit/test.h\nDocumentation/dev-tools/kunit/api/test.rst-10- :internal:\n--\nDocumentation/dev-tools/kunit/architecture.rst=94=executor, see\nDocumentation/dev-tools/kunit/architecture.rst:95:`lib/kunit/executor.c \u003chttps://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/lib/kunit/executor.c\u003e`_.\nDocumentation/dev-tools/kunit/architecture.rst-96-When built as a module, the ``kunit_test_suites()`` macro defines a\n--\nDocumentation/dev-tools/kunit/architecture.rst=102=context. See the ``kunit_try_catch_run()`` function in\nDocumentation/dev-tools/kunit/architecture.rst:103:`lib/kunit/try-catch.c \u003chttps://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/lib/kunit/try-catch.c?h=v5.15#n58\u003e`_.\nDocumentation/dev-tools/kunit/architecture.rst-104-\n--\nDocumentation/dev-tools/kunit/architecture.rst=156=kunit_tool (Command-line Test Harness)\n--\nDocumentation/dev-tools/kunit/architecture.rst-158-\nDocumentation/dev-tools/kunit/architecture.rst:159:``kunit_tool`` is a Python script, found in ``tools/testing/kunit/kunit.py``. It\nDocumentation/dev-tools/kunit/architecture.rst-160-is used to configure, build, execute, parse test results and run all of the\n--\nDocumentation/dev-tools/kunit/architecture.rst=163=enabled and manually parse the results (see\nDocumentation/dev-tools/kunit/architecture.rst:164:Documentation/dev-tools/kunit/run_manual.rst) or use ``kunit_tool``\nDocumentation/dev-tools/kunit/architecture.rst:165:(see Documentation/dev-tools/kunit/run_wrapper.rst).\nDocumentation/dev-tools/kunit/architecture.rst-166-\n--\nDocumentation/dev-tools/kunit/architecture.rst-169- The Python scripts available in ``qemu_configs`` folder\nDocumentation/dev-tools/kunit/architecture.rst:170: (for example, ``tools/testing/kunit/qemu configs/powerpc.py``) contains\nDocumentation/dev-tools/kunit/architecture.rst-171- additional configuration options for specific architectures.\n--\nDocumentation/dev-tools/kunit/architecture.rst-179- ``kunit_kernel.py`` script. You can invoke this command through:\nDocumentation/dev-tools/kunit/architecture.rst:180: ``./tools/testing/kunit/kunit.py config`` and\nDocumentation/dev-tools/kunit/architecture.rst-181- generate a ``.config`` file.\n--\nDocumentation/dev-tools/kunit/architecture.rst-185- To build a KUnit kernel from the current ``.config``, you can use the\nDocumentation/dev-tools/kunit/architecture.rst:186: ``build`` argument: ``./tools/testing/kunit/kunit.py build``.\nDocumentation/dev-tools/kunit/architecture.rst-187-- ``exec`` command executes kernel results either directly (using\n--\nDocumentation/dev-tools/kunit/architecture.rst-192- you can run the kernel and display the test results with the ``exec``\nDocumentation/dev-tools/kunit/architecture.rst:193: argument: ``./tools/testing/kunit/kunit.py exec``.\nDocumentation/dev-tools/kunit/architecture.rst-194-- ``parse`` extracts the KTAP output from a kernel log, parses\n--\nDocumentation/dev-tools/kunit/faq.rst=32=enabling ``CONFIG_KUNIT=y`` and booting the kernel.\nDocumentation/dev-tools/kunit/faq.rst:33:See Documentation/dev-tools/kunit/run_manual.rst for more details.\nDocumentation/dev-tools/kunit/faq.rst-34-\n--\nDocumentation/dev-tools/kunit/faq.rst=73=things to try.\nDocumentation/dev-tools/kunit/faq.rst-74-\nDocumentation/dev-tools/kunit/faq.rst:75:1. Run ``./tools/testing/kunit/kunit.py run`` with the ``--raw_output``\nDocumentation/dev-tools/kunit/faq.rst-76- parameter. This might show details or error messages hidden by the kunit_tool\n--\nDocumentation/dev-tools/kunit/faq.rst-103- modules will automatically execute associated tests when loaded. Test results\nDocumentation/dev-tools/kunit/faq.rst:104: can be collected from ``/sys/kernel/debug/kunit/\u003ctest suite\u003e/results``, and\nDocumentation/dev-tools/kunit/faq.rst-105- can be parsed with ``kunit.py parse``. For more details, see\nDocumentation/dev-tools/kunit/faq.rst:106: Documentation/dev-tools/kunit/run_manual.rst\nDocumentation/dev-tools/kunit/faq.rst-107-\n--\nDocumentation/dev-tools/kunit/index.rst=44=restricted to things exposed to user-space.\nDocumentation/dev-tools/kunit/index.rst-45-\nDocumentation/dev-tools/kunit/index.rst:46:In addition, KUnit has kunit_tool, a script (``tools/testing/kunit/kunit.py``)\nDocumentation/dev-tools/kunit/index.rst-47-that configures the Linux kernel, runs KUnit tests under QEMU or UML\n--\nDocumentation/dev-tools/kunit/index.rst=102=You can find a step-by-step guide to writing and running KUnit tests in\nDocumentation/dev-tools/kunit/index.rst:103:Documentation/dev-tools/kunit/start.rst\nDocumentation/dev-tools/kunit/index.rst-104-\nDocumentation/dev-tools/kunit/index.rst=105=Alternatively, feel free to look through the rest of the KUnit documentation,\nDocumentation/dev-tools/kunit/index.rst:106:or to experiment with tools/testing/kunit/kunit.py and the example test under\nDocumentation/dev-tools/kunit/index.rst:107:lib/kunit/kunit-example-test.c\nDocumentation/dev-tools/kunit/index.rst-108-\n--\nDocumentation/dev-tools/kunit/run_manual.rst=72=accessible from the debugfs filesystem in the following read-only file:\n--\nDocumentation/dev-tools/kunit/run_manual.rst-75-\nDocumentation/dev-tools/kunit/run_manual.rst:76:\t/sys/kernel/debug/kunit/\u003ctest_suite\u003e/results\nDocumentation/dev-tools/kunit/run_manual.rst-77-\n--\nDocumentation/dev-tools/kunit/run_manual.rst=85=boot. To run the test suite, you can use the following command to write to\nDocumentation/dev-tools/kunit/run_manual.rst:86:the ``/sys/kernel/debug/kunit/\u003ctest_suite\u003e/run`` file:\nDocumentation/dev-tools/kunit/run_manual.rst-87-\n--\nDocumentation/dev-tools/kunit/run_manual.rst-89-\nDocumentation/dev-tools/kunit/run_manual.rst:90:\techo \"any string\" \u003e /sys/kernel/debugfs/kunit/\u003ctest_suite\u003e/run\nDocumentation/dev-tools/kunit/run_manual.rst-91-\n--\nDocumentation/dev-tools/kunit/run_wrapper.rst=8=manually, and then use kunit_tool to parse the results. To run tests\nDocumentation/dev-tools/kunit/run_wrapper.rst:9:manually, see: Documentation/dev-tools/kunit/run_manual.rst.\nDocumentation/dev-tools/kunit/run_wrapper.rst-10-As long as we can build the kernel, we can run KUnit.\n--\nDocumentation/dev-tools/kunit/run_wrapper.rst=15=Run command:\n--\nDocumentation/dev-tools/kunit/run_wrapper.rst-18-\nDocumentation/dev-tools/kunit/run_wrapper.rst:19:\t./tools/testing/kunit/kunit.py run\nDocumentation/dev-tools/kunit/run_wrapper.rst-20-\n--\nDocumentation/dev-tools/kunit/run_wrapper.rst=29=We may want to use the following options:\n--\nDocumentation/dev-tools/kunit/run_wrapper.rst-32-\nDocumentation/dev-tools/kunit/run_wrapper.rst:33:\t./tools/testing/kunit/kunit.py run --timeout=30 --jobs=`nproc --all`\nDocumentation/dev-tools/kunit/run_wrapper.rst-34-\n\n"
} |
| 11/2 | 2026/10/21 12:49 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 39503 output: 35 thoughts: 930 Thoughts: **Analyzing the Triage Prompt: A Deep Dive** Okay, let's break this down. First, I need to make absolutely sure I understand the triage prompt instructions, particularly focusing on the "reachability" aspect – that's the primary gate. The goal here, as I see it, is to uncover crashes, regressions, latent bugs, and new assertion triggers introduced by the patch series. It's all about finding issues in code that *can* actually run in a standard virtualized environment. Anything unreachable is out, no matter how tempting a new assertion might look. Now, that brings me to the critical part about not blindly trusting claims of "No Functional Change" or refactoring. I've learned that refactorings can be sneaky. Changing logic, introducing helpers, or tweaking state management – these can easily introduce subtle shifts or uncover kernel bugs. So, if the code is reachable and executable, I *must* fuzz it, regardless of the author's intentions. And new or modified assertions in reachable code are a *huge* red flag. Even if the author is sure it holds, fuzzing is essential to confirm whether an unusual sequence can violate it. Alright, now to the "negative criteria." I need to determine when to return `WorthFuzzing=false`. The prompt lays it out explicitly: non-kernel/non-executable changes, structurally unreachable hardware, and unreachable execution paths. This seems straightforward, but I have to be precise. I'm now thinking specifically about unit tests, like the KUnit tests. Are these considered "non-kernel and non-executable"? Or are they part of the "self-tests, samples, or scripts" category? The text states, "that do not affect the compiled kernel image (vmlinux) or kernel modules". So, let's take a look at the file path given `fs/ext4/extents_status-test.c` specifically. Does it affect the kernel image, or is it a separate thing? I should also check the associated Kconfig entry. The `obj-$(CONFIG_EXT4_KUNIT_TESTS) += ext4-test.o` and `ext4-test-objs += ... extents_status-test.o` make me wonder if `ext4-test` is compiled into the kernel or is a module. I need to get to the bottom of this; it's a key distinction to make. This determination is crucial for my triage decision. |
| 12/2 | 2026/10/21 12:49 | tool | grepper |
0mArgs:{
"Expression": "config EXT4_KUNIT_TESTS",
"PathPrefixes": [
"fs/ext4/"
]
}Results: {
"Output": "fs/ext4/Kconfig=68=config EXT4_DEBUG\n--\nfs/ext4/Kconfig-76-\nfs/ext4/Kconfig:77:config EXT4_KUNIT_TESTS\nfs/ext4/Kconfig-78-\ttristate \"KUnit tests for ext4\" if !KUNIT_ALL_TESTS\n"
} |
| 13/2 | 2026/10/21 12:49 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 41084 output: 34 thoughts: 19 Thoughts: Here's a summary of my thought process: **Diving into the ext4 Kconfig** Okay, so I need to understand something about the configuration options for the ext4 filesystem. Let's see... the `fs/ext4/Kconfig` file is the obvious place to start. I'm going to jump straight to around line 77. That seems like a good place to begin my exploration and see if there are any hints or clues to address whatever is on my mind. I'm expecting to find some crucial defaults or relevant dependencies around that section. Let's get reading! |
| 14/2 | 2026/10/21 12:49 | tool | read-file |
0mArgs:{
"File": "fs/ext4/Kconfig",
"FirstLine": 70,
"LineCount": 30
}Results: {
"Contents": " 70:\t\tdepends on EXT4_FS\n 71:\t\thelp\n 72:\t\t Enables run-time debugging support for the ext4 filesystem.\n 73:\t\n 74:\t\t If you select Y here, then you will be able to turn on debugging\n 75:\t\t using dynamic debug control for mb_debug() / ext_debug() msgs.\n 76:\t\n 77:\tconfig EXT4_KUNIT_TESTS\n 78:\t\ttristate \"KUnit tests for ext4\" if !KUNIT_ALL_TESTS\n 79:\t\tdepends on EXT4_FS \u0026\u0026 KUNIT\n 80:\t\tdefault KUNIT_ALL_TESTS\n 81:\t\thelp\n 82:\t\t This builds the ext4 KUnit tests.\n 83:\t\n 84:\t\t KUnit tests run during boot and output the results to the debug log\n 85:\t\t in TAP format (https://testanything.org/). Only useful for kernel devs\n 86:\t\t running KUnit test harness and are not for inclusion into a production\n 87:\t\t build.\n 88:\t\n 89:\t\t For more information on KUnit and unit tests in general please refer\n 90:\t\t to the KUnit documentation in Documentation/dev-tools/kunit/.\n 91:\t\n 92:\t\t If unsure, say N.\n"
} |
| 15/2 | 2026/10/21 12:49 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 41613 output: 22 thoughts: 3522 Thoughts: **Analyzing the KUnit Patch for Syzkaller Fuzzing Relevance** Okay, let's break this down. My initial thought was: "Can syzkaller fuzz KUnit tests directly?" But then I remembered syzkaller is a coverage-guided *syscall* fuzzer, generating sequences of system calls to trigger kernel bugs. It's not designed to run unit tests. KUnit tests, from my understanding, are kernel unit tests, executed during boot or via the `kunit.py` script or through the debugfs interface, and are reported via KTAP output on dmesg. They are not part of the standard syscall path that syzkaller targets. So, the next question is: Does this patch introduce changes that could affect *how syzkaller fuzzes ext4*? I need to go deeper into the code changes. I saw this patch introduces `extents_status-test.c` and exports certain symbols for testing. More importantly, I saw additions of `KUNIT_STATIC_STUB_REDIRECT` and `EXPORT_SYMBOL_FOR_EXT4_TEST` macros. Crucially, the `KUNIT_STATIC_STUB_REDIRECT` macro usage in `ext4_da_update_reserve_space` and `ext4_da_release_space` is important. This is a very clear indication to short-circuit the function call if we are running in a kunit testing context via `kunit_get_current_test()`. But when syzkaller is fuzzing with syscalls, `kunit_get_current_test()` will return `NULL`. This means that if these functions are reached by a syzkaller fuzzed call, the KUnit check is skipped. This is a NO-OP when not running under kunit context! Since the KUnit code is fundamentally separate from the path syzkaller uses (syscall execution), the changes do not impact syzkaller's reachability. The addition of `extents_status-test.c` and the exported symbols are intended for in-kernel unit testing, not syscall fuzzing. Thus, based on my understanding of both KUnit and syzkaller, this patch doesn't necessitate fuzzing via syzkaller, because the code path changes only affect KUnit test execution and do not change the code ext4 code that syzkaller interacts with during fuzzing. The patch is, in essence, a "non-functional change" in terms of syzkaller reachability. |
| 16/2 | 2026/10/21 12:50 | tool | grepper |
0mArgs:{
"Expression": "kunit_get_current_test"
}Results: {
"Output": "\nFull output is too long, showing 200 out of 637 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (42 files in total):\nDocumentation/dev-tools/kunit/api/functionredirection.rst:2\nDocumentation/dev-tools/kunit/usage.rst:4\ndrivers/firewire/node-tree-test.c:1\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c:7\ndrivers/gpu/drm/vc4/vc4_hvs.c:1\ndrivers/gpu/drm/xe/tests/xe_bo.c:3\ndrivers/gpu/drm/xe/tests/xe_dma_buf.c:2\ndrivers/gpu/drm/xe/tests/xe_gt_sriov_pf_config_kunit.c:4\ndrivers/gpu/drm/xe/tests/xe_guc_buf_kunit.c:1\ndrivers/gpu/drm/xe/tests/xe_guc_g2g_test.c:3\ndrivers/gpu/drm/xe/tests/xe_guc_klv_helpers_kunit.c:1\ndrivers/gpu/drm/xe/tests/xe_guc_relay_test.c:3\ndrivers/gpu/drm/xe/tests/xe_kunit_helpers.c:1\ndrivers/gpu/drm/xe/tests/xe_migrate.c:2\ndrivers/gpu/drm/xe/tests/xe_mocs.c:4\ndrivers/gpu/drm/xe/tests/xe_pci.c:1\ndrivers/gpu/drm/xe/tests/xe_test.h:2\ndrivers/gpu/drm/xe/xe_guc_relay.c:2\ndrivers/net/wireless/intel/iwlwifi/mld/tests/agg.c:4\ndrivers/net/wireless/intel/iwlwifi/mld/tests/link-selection.c:3\ndrivers/net/wireless/intel/iwlwifi/mld/tests/rx.c:1\ndrivers/net/wireless/intel/iwlwifi/mld/tests/utils.c:18\nfs/ext4/extents-test.c:3\nfs/ext4/extents_status-test.c:2\ninclude/kunit/static_stub.h:1\ninclude/kunit/test-bug.h:3\ninclude/rv/kunit.h:1\nkernel/trace/rv/rv_monitors_test.c:2\nlib/kunit/kunit-example-test.c:1\nlib/kunit/kunit-test.c:4\nlib/kunit/string-stream-test.c:1\nlib/tests/fortify_kunit.c:1\nmm/slub.c:2\nnet/mac80211/tests/util.c:1\nnet/mctp/test/sock-test.c:1\nnet/wireless/tests/util.c:1\nrust/helpers/kunit.c:2\nrust/kernel/kunit.rs:4\nscripts/rustdoc_test_gen.rs:1\nsound/soc/codecs/cs-amp-lib-test.c:14\nsound/soc/codecs/cs35l56-test.c:3\nsound/soc/codecs/wm_adsp_fw_find_test.c:2\n\nDocumentation/dev-tools/kunit/api/functionredirection.rst=46=Using static stubs is pretty straightforward:\n--\nDocumentation/dev-tools/kunit/api/functionredirection.rst-68- In the event they need to access or modify test-specific state, they can use\nDocumentation/dev-tools/kunit/api/functionredirection.rst:69: kunit_get_current_test() to get a struct kunit pointer. This can then\nDocumentation/dev-tools/kunit/api/functionredirection.rst-70- be passed to the expectation/assertion macros, or used to look up KUnit\n--\nDocumentation/dev-tools/kunit/api/functionredirection.rst-78-\t{\nDocumentation/dev-tools/kunit/api/functionredirection.rst:79:\t\tstruct kunit *test = kunit_get_current_test();\nDocumentation/dev-tools/kunit/api/functionredirection.rst-80-\t\tKUNIT_EXPECT_STREQ(test, str, \"Hello World!\");\n--\nDocumentation/dev-tools/kunit/usage.rst=1125=We can do this via the ``kunit_test`` field in ``task_struct``, which we can\nDocumentation/dev-tools/kunit/usage.rst:1126:access using the ``kunit_get_current_test()`` function in ``kunit/test-bug.h``.\nDocumentation/dev-tools/kunit/usage.rst-1127-\nDocumentation/dev-tools/kunit/usage.rst:1128:``kunit_get_current_test()`` is safe to call even if KUnit is not enabled. If\nDocumentation/dev-tools/kunit/usage.rst-1129-KUnit is not enabled, or if no test is running in the current task, it will\n--\nDocumentation/dev-tools/kunit/usage.rst=1133=The example below uses this to implement a \"mock\" implementation of a function, ``foo``:\n--\nDocumentation/dev-tools/kunit/usage.rst-1136-\nDocumentation/dev-tools/kunit/usage.rst:1137:\t#include \u003ckunit/test-bug.h\u003e /* for kunit_get_current_test */\nDocumentation/dev-tools/kunit/usage.rst-1138-\n--\nDocumentation/dev-tools/kunit/usage.rst-1145-\t{\nDocumentation/dev-tools/kunit/usage.rst:1146:\t\tstruct kunit *test = kunit_get_current_test();\nDocumentation/dev-tools/kunit/usage.rst-1147-\t\tstruct test_data *test_data = test-\u003epriv;\n--\ndrivers/firewire/node-tree-test.c=45=static void release_fw_node(struct fw_card *card, struct fw_node *node, struct fw_node *parent)\ndrivers/firewire/node-tree-test.c-46-{\ndrivers/firewire/node-tree-test.c:47:\tstruct private_data *data = kunit_get_current_test()-\u003epriv;\ndrivers/firewire/node-tree-test.c-48-\n--\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c=66=static int cs_dsp_test_control_add_callback(struct cs_dsp_coeff_ctl *ctl)\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c-67-{\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c:68:\tstruct kunit *test = kunit_get_current_test();\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c-69-\tstruct cs_dsp_test *priv = test-\u003epriv;\n--\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c=78=static void cs_dsp_test_control_remove_callback(struct cs_dsp_coeff_ctl *ctl)\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c-79-{\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c:80:\tstruct kunit *test = kunit_get_current_test();\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c-81-\tstruct cs_dsp_test *priv = test-\u003epriv;\n--\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c=88=static int cs_dsp_test_pre_run_callback(struct cs_dsp *dsp)\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c-89-{\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c:90:\tstruct kunit *test = kunit_get_current_test();\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c-91-\tstruct cs_dsp_test *priv = test-\u003epriv;\n--\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c=100=static int cs_dsp_test_post_run_callback(struct cs_dsp *dsp)\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c-101-{\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c:102:\tstruct kunit *test = kunit_get_current_test();\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c-103-\tstruct cs_dsp_test *priv = test-\u003epriv;\n--\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c=112=static void cs_dsp_test_pre_stop_callback(struct cs_dsp *dsp)\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c-113-{\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c:114:\tstruct kunit *test = kunit_get_current_test();\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c-115-\tstruct cs_dsp_test *priv = test-\u003epriv;\n--\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c=122=static void cs_dsp_test_post_stop_callback(struct cs_dsp *dsp)\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c-123-{\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c:124:\tstruct kunit *test = kunit_get_current_test();\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c-125-\tstruct cs_dsp_test *priv = test-\u003epriv;\n--\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c=132=static void cs_dsp_test_watchdog_expired_callback(struct cs_dsp *dsp)\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c-133-{\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c:134:\tstruct kunit *test = kunit_get_current_test();\ndrivers/firmware/cirrus/test/cs_dsp_test_callbacks.c-135-\tstruct cs_dsp_test *priv = test-\u003epriv;\n--\ndrivers/gpu/drm/vc4/vc4_hvs.c=1189=struct vc4_hvs *__vc4_hvs_alloc(struct vc4_dev *vc4,\n--\ndrivers/gpu/drm/vc4/vc4_hvs.c-1230-\t\t */\ndrivers/gpu/drm/vc4/vc4_hvs.c:1231:\t\tif (!kunit_get_current_test())\ndrivers/gpu/drm/vc4/vc4_hvs.c-1232-\t\t\tdlist_size = HVS_READ(SCALER6_CXM_SIZE);\n--\ndrivers/gpu/drm/xe/tests/xe_bo.c=397=static int ccs_test_run_device(struct xe_device *xe)\ndrivers/gpu/drm/xe/tests/xe_bo.c-398-{\ndrivers/gpu/drm/xe/tests/xe_bo.c:399:\tstruct kunit *test = kunit_get_current_test();\ndrivers/gpu/drm/xe/tests/xe_bo.c-400-\tstruct xe_tile *tile;\n--\ndrivers/gpu/drm/xe/tests/xe_bo.c=571=static int evict_test_run_device(struct xe_device *xe)\ndrivers/gpu/drm/xe/tests/xe_bo.c-572-{\ndrivers/gpu/drm/xe/tests/xe_bo.c:573:\tstruct kunit *test = kunit_get_current_test();\ndrivers/gpu/drm/xe/tests/xe_bo.c-574-\tstruct xe_tile *tile;\n--\ndrivers/gpu/drm/xe/tests/xe_bo.c=666=static int shrink_test_run_device(struct xe_device *xe)\ndrivers/gpu/drm/xe/tests/xe_bo.c-667-{\ndrivers/gpu/drm/xe/tests/xe_bo.c:668:\tstruct kunit *test = kunit_get_current_test();\ndrivers/gpu/drm/xe/tests/xe_bo.c-669-\tLIST_HEAD(bos);\n--\ndrivers/gpu/drm/xe/tests/xe_dma_buf.c=109=static void xe_test_dmabuf_import_same_driver(struct xe_device *xe)\ndrivers/gpu/drm/xe/tests/xe_dma_buf.c-110-{\ndrivers/gpu/drm/xe/tests/xe_dma_buf.c:111:\tstruct kunit *test = kunit_get_current_test();\ndrivers/gpu/drm/xe/tests/xe_dma_buf.c-112-\tstruct dma_buf_test_params *params = to_dma_buf_test_params(test-\u003epriv);\n--\ndrivers/gpu/drm/xe/tests/xe_dma_buf.c=263=static int dma_buf_run_device(struct xe_device *xe)\n--\ndrivers/gpu/drm/xe/tests/xe_dma_buf.c-265-\tconst struct dma_buf_test_params *params;\ndrivers/gpu/drm/xe/tests/xe_dma_buf.c:266:\tstruct kunit *test = kunit_get_current_test();\ndrivers/gpu/drm/xe/tests/xe_dma_buf.c-267-\n--\ndrivers/gpu/drm/xe/tests/xe_gt_sriov_pf_config_kunit.c=26=static void pf_set_admin_mode(struct xe_device *xe, bool enable)\n--\ndrivers/gpu/drm/xe/tests/xe_gt_sriov_pf_config_kunit.c-31-\ndrivers/gpu/drm/xe/tests/xe_gt_sriov_pf_config_kunit.c:32:\tkunit_activate_static_stub(kunit_get_current_test(),\ndrivers/gpu/drm/xe/tests/xe_gt_sriov_pf_config_kunit.c-33-\t\t\t\t xe_device_is_admin_only,\n--\ndrivers/gpu/drm/xe/tests/xe_gt_sriov_pf_config_kunit.c-35-\ndrivers/gpu/drm/xe/tests/xe_gt_sriov_pf_config_kunit.c:36:\tKUNIT_EXPECT_EQ(kunit_get_current_test(), enable, xe_sriov_pf_admin_only(xe));\ndrivers/gpu/drm/xe/tests/xe_gt_sriov_pf_config_kunit.c:37:\tKUNIT_EXPECT_EQ(kunit_get_current_test(), enable, xe_device_is_admin_only(xe));\ndrivers/gpu/drm/xe/tests/xe_gt_sriov_pf_config_kunit.c-38-}\n--\ndrivers/gpu/drm/xe/tests/xe_gt_sriov_pf_config_kunit.c=40=static void pf_set_usable_vram(struct xe_device *xe, u64 usable)\n--\ndrivers/gpu/drm/xe/tests/xe_gt_sriov_pf_config_kunit.c-42-\tstruct xe_tile *tile = xe_device_get_root_tile(xe);\ndrivers/gpu/drm/xe/tests/xe_gt_sriov_pf_config_kunit.c:43:\tstruct kunit *test = kunit_get_current_test();\ndrivers/gpu/drm/xe/tests/xe_gt_sriov_pf_config_kunit.c-44-\n--\ndrivers/gpu/drm/xe/tests/xe_guc_buf_kunit.c=19=static struct xe_bo *replacement_xe_managed_bo_create_pin_map(struct xe_device *xe,\n--\ndrivers/gpu/drm/xe/tests/xe_guc_buf_kunit.c-22-{\ndrivers/gpu/drm/xe/tests/xe_guc_buf_kunit.c:23:\tstruct kunit *test = kunit_get_current_test();\ndrivers/gpu/drm/xe/tests/xe_guc_buf_kunit.c-24-\tstruct xe_bo *bo;\n--\ndrivers/gpu/drm/xe/tests/xe_guc_g2g_test.c=51=static int slot_index_from_gts(struct xe_gt *tx_gt, struct xe_gt *rx_gt)\n--\ndrivers/gpu/drm/xe/tests/xe_guc_g2g_test.c-55-\tstruct xe_gt *gt;\ndrivers/gpu/drm/xe/tests/xe_guc_g2g_test.c:56:\tstruct kunit *test = kunit_get_current_test();\ndrivers/gpu/drm/xe/tests/xe_guc_g2g_test.c-57-\n--\ndrivers/gpu/drm/xe/tests/xe_guc_g2g_test.c=273=static void g2g_wait_for_complete(void *_xe)\n--\ndrivers/gpu/drm/xe/tests/xe_guc_g2g_test.c-275-\tstruct xe_device *xe = (struct xe_device *)_xe;\ndrivers/gpu/drm/xe/tests/xe_guc_g2g_test.c:276:\tstruct kunit *test = kunit_get_current_test();\ndrivers/gpu/drm/xe/tests/xe_guc_g2g_test.c-277-\tint wait = 0;\n--\ndrivers/gpu/drm/xe/tests/xe_guc_g2g_test.c=703=static void g2g_recreate_ctb(void *_xe)\n--\ndrivers/gpu/drm/xe/tests/xe_guc_g2g_test.c-705-\tstruct xe_device *xe = (struct xe_device *)_xe;\ndrivers/gpu/drm/xe/tests/xe_guc_g2g_test.c:706:\tstruct kunit *test = kunit_get_current_test();\ndrivers/gpu/drm/xe/tests/xe_guc_g2g_test.c-707-\n--\ndrivers/gpu/drm/xe/tests/xe_guc_klv_helpers_kunit.c=383=static struct drm_printer drm_kunit_printer(void)\n--\ndrivers/gpu/drm/xe/tests/xe_guc_klv_helpers_kunit.c-386-\t\t.printfn = __drm_printfn_kunit,\ndrivers/gpu/drm/xe/tests/xe_guc_klv_helpers_kunit.c:387:\t\t.arg = kunit_get_current_test(),\ndrivers/gpu/drm/xe/tests/xe_guc_klv_helpers_kunit.c-388-\t};\n--\ndrivers/gpu/drm/xe/tests/xe_guc_relay_test.c=61=static int replacement_xe_guc_ct_send_recv_always_fails(struct xe_guc_ct *ct,\n--\ndrivers/gpu/drm/xe/tests/xe_guc_relay_test.c-64-{\ndrivers/gpu/drm/xe/tests/xe_guc_relay_test.c:65:\tstruct kunit *test = kunit_get_current_test();\ndrivers/gpu/drm/xe/tests/xe_guc_relay_test.c-66-\n--\ndrivers/gpu/drm/xe/tests/xe_guc_relay_test.c=74=static int replacement_xe_guc_ct_send_recv_expects_pf2guc_relay(struct xe_guc_ct *ct,\n--\ndrivers/gpu/drm/xe/tests/xe_guc_relay_test.c-77-{\ndrivers/gpu/drm/xe/tests/xe_guc_relay_test.c:78:\tstruct kunit *test = kunit_get_current_test();\ndrivers/gpu/drm/xe/tests/xe_guc_relay_test.c-79-\n--\ndrivers/gpu/drm/xe/tests/xe_guc_relay_test.c=222=static int replacement_xe_guc_ct_send_recv_loopback_relay(struct xe_guc_ct *ct,\n--\ndrivers/gpu/drm/xe/tests/xe_guc_relay_test.c-225-{\ndrivers/gpu/drm/xe/tests/xe_guc_relay_test.c:226:\tstruct kunit *test = kunit_get_current_test();\ndrivers/gpu/drm/xe/tests/xe_guc_relay_test.c-227-\tstruct xe_guc_relay *relay = test-\u003epriv;\n--\ndrivers/gpu/drm/xe/tests/xe_kunit_helpers.c=46=static void kunit_action_restore_priv(void *priv)\ndrivers/gpu/drm/xe/tests/xe_kunit_helpers.c-47-{\ndrivers/gpu/drm/xe/tests/xe_kunit_helpers.c:48:\tstruct kunit *test = kunit_get_current_test();\ndrivers/gpu/drm/xe/tests/xe_kunit_helpers.c-49-\n--\ndrivers/gpu/drm/xe/tests/xe_migrate.c=341=static int migrate_test_run_device(struct xe_device *xe)\ndrivers/gpu/drm/xe/tests/xe_migrate.c-342-{\ndrivers/gpu/drm/xe/tests/xe_migrate.c:343:\tstruct kunit *test = kunit_get_current_test();\ndrivers/gpu/drm/xe/tests/xe_migrate.c-344-\tstruct xe_tile *tile;\n--\ndrivers/gpu/drm/xe/tests/xe_migrate.c=743=static int validate_ccs_test_run_device(struct xe_device *xe)\ndrivers/gpu/drm/xe/tests/xe_migrate.c-744-{\ndrivers/gpu/drm/xe/tests/xe_migrate.c:745:\tstruct kunit *test = kunit_get_current_test();\ndrivers/gpu/drm/xe/tests/xe_migrate.c-746-\tstruct xe_tile *tile;\n--\ndrivers/gpu/drm/xe/tests/xe_mocs.c=23=static int live_mocs_init(struct live_mocs *arg, struct xe_gt *gt)\n--\ndrivers/gpu/drm/xe/tests/xe_mocs.c-25-\tunsigned int flags;\ndrivers/gpu/drm/xe/tests/xe_mocs.c:26:\tstruct kunit *test = kunit_get_current_test();\ndrivers/gpu/drm/xe/tests/xe_mocs.c-27-\n--\ndrivers/gpu/drm/xe/tests/xe_mocs.c=41=static void read_l3cc_table(struct xe_gt *gt,\n--\ndrivers/gpu/drm/xe/tests/xe_mocs.c-43-{\ndrivers/gpu/drm/xe/tests/xe_mocs.c:44:\tstruct kunit *test = kunit_get_current_test();\ndrivers/gpu/drm/xe/tests/xe_mocs.c-45-\tu32 l3cc, l3cc_expected;\n--\ndrivers/gpu/drm/xe/tests/xe_mocs.c=77=static void read_mocs_table(struct xe_gt *gt,\n--\ndrivers/gpu/drm/xe/tests/xe_mocs.c-79-{\ndrivers/gpu/drm/xe/tests/xe_mocs.c:80:\tstruct kunit *test = kunit_get_current_test();\ndrivers/gpu/drm/xe/tests/xe_mocs.c-81-\tu32 mocs, mocs_expected;\n--\ndrivers/gpu/drm/xe/tests/xe_mocs.c=140=static int mocs_reset_test_run_device(struct xe_device *xe)\n--\ndrivers/gpu/drm/xe/tests/xe_mocs.c-147-\tint id;\ndrivers/gpu/drm/xe/tests/xe_mocs.c:148:\tstruct kunit *test = kunit_get_current_test();\n\n"
} |
| 17/2 | 2026/10/21 12:50 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 51942 output: 40 thoughts: 7337 Thoughts: **Analysis of the Ext4 KUnit Test Patch** Okay, let's break this down. My initial thought is to go through the changes, line by line, to see what's actually being modified. The documentation suggests that `kunit_get_current_test()` returns `NULL` during normal kernel operation, meaning any `KUNIT_STATIC_STUB_REDIRECT` macro will effectively be a no-op during fuzzing. I can verify that no actual core logic in `ext4_da_update_reserve_space` or `ext4_da_release_space` is changed. The patch includes adding `extents_status-test.o` to the Makefile, some symbol exports, and the test file itself. Then, there's the `KUNIT_STATIC_STUB_REDIRECT` macro in `inode.c`. The core question here is whether this patch falls under the "Non-kernel and non-executable changes" category, particularly the bit about "self-tests" that "do not affect the compiled kernel image or kernel modules." That's the crux of this. My intuition is that KUnit tests are technically "self-tests," but they *do* get compiled into either the kernel image (`vmlinux`) or a module (`ext4-test.ko`). So, does the `ext4-test.o` file affect `vmlinux` or not? Yes, if `CONFIG_EXT4_KUNIT_TESTS` is enabled as "y", it becomes part of the kernel image; if it's "m", it becomes a module. I need to know WHEN the test suites run. At boot time! Or, if built as a module, when it's loaded. The critical question now becomes: *Can syzkaller fuzz these KUnit test suites?* Absolutely not. Syzkaller focuses on syscalls, and user-space accessible paths. It generates inputs for syscalls. It *cannot* mutate the fixed inputs within a compiled C file. I need to consider that, at all times, the unit tests have hardcoded inputs. A fuzzer operates on syscall arguments. It *cannot* change hardcoded values in a unit test. Okay, let's step back, and analyze the prompt's negative criteria. It says fuzzing is only valuable on "reachable executable code". The patch *doesn't* touch any logic in ext4, apart from the test scaffolding. It adds a unit test suite and a stub redirection that *only* does something during a KUnit test. Now, let's review the changes outside the test file: The Makefile just includes the test object; `extents.c` moves `EXPORT_SYMBOL_FOR_EXT4_TEST`s; `extents_status.c` *adds* `EXPORT_SYMBOL_FOR_EXT4_TEST`s, but under `CONFIG_EXT4_KUNIT_TESTS`, so it’s conditional. In `inode.c`, only the macro is added, which is a no-op without KUnit enabled. Let's re-read the triage prompts *very carefully*. If *nothing* is reachable by standard fuzzing, there is no value. The prompt is all about reachability. Syzkaller cannot execute `extents_status_test_suite`. Syzkaller can't mutate the internal C code of the unit test! Now, does adding a KUnit test fall under "User-space directories, self-tests, samples, or scripts"? Yes, it's a self-test, but it's in a kernel directory, which brings us to the key. Does it "affect the compiled kernel image (vmlinux) or kernel modules."? Yes, it *is* compiled in, but only when configured. However, since the test cases themselves have hardcoded inputs, even if one can *run* these tests, there's no way to fuzz them! Looking at the Positive Criteria in section 3. This patch doesn't meet *any* of those criteria. This is NOT a logic modification, NOT a refactoring, NOT a new assertion, and NOT a reachable driver or protocol. I need to be absolutely sure that the goal is to *discover* bugs in executable code via fuzzing. My conclusion? The key is structural unreachability. These tests are *not* reachable by the fuzzer. Adding a KUnit test is a "non-executable change" from the perspective of fuzzing. There is no fuzzing value! Thus the answer is: `WorthFuzzing=false`. |
| 18/2 | 2026/10/21 12:50 | tool | grepper |
0mArgs:{
"Expression": "kunit_test_suites",
"PathPrefixes": [
"include/kunit/",
"lib/kunit/"
]
}Results: {
"Output": "include/kunit/test.h=387=void kunit_free_suite_set(struct kunit_suite_set suite_set);\ninclude/kunit/test.h-388-\ninclude/kunit/test.h:389:int __kunit_test_suites_init(struct kunit_suite * const * const suites, int num_suites,\ninclude/kunit/test.h-390-\t\t\t bool run_tests);\ninclude/kunit/test.h-391-\ninclude/kunit/test.h:392:void __kunit_test_suites_exit(struct kunit_suite **suites, int num_suites);\ninclude/kunit/test.h-393-\n--\ninclude/kunit/test.h=405=static inline int kunit_run_all_tests(void)\n--\ninclude/kunit/test.h-410-\ninclude/kunit/test.h:411:#define __kunit_test_suites(unique_array, ...)\t\t\t\t \\\ninclude/kunit/test.h-412-\tstatic struct kunit_suite *unique_array[]\t\t\t \\\ninclude/kunit/test.h-413-\t__aligned(sizeof(struct kunit_suite *))\t\t\t\t \\\ninclude/kunit/test.h:414:\t__used __section(\".kunit_test_suites\") = { __VA_ARGS__ }\ninclude/kunit/test.h-415-\ninclude/kunit/test.h-416-/**\ninclude/kunit/test.h:417: * kunit_test_suites() - used to register one or more \u0026struct kunit_suite\ninclude/kunit/test.h-418- *\t\t\t with KUnit.\n--\ninclude/kunit/test.h-423- * This is done by placing the array of struct kunit_suite * in the\ninclude/kunit/test.h:424: * .kunit_test_suites ELF section.\ninclude/kunit/test.h-425- *\n--\ninclude/kunit/test.h-429- */\ninclude/kunit/test.h:430:#define kunit_test_suites(__suites...)\t\t\t\t\t\t\\\ninclude/kunit/test.h:431:\t__kunit_test_suites(__UNIQUE_ID(array),\t\t\t\t\\\ninclude/kunit/test.h-432-\t\t\t ##__suites)\ninclude/kunit/test.h-433-\ninclude/kunit/test.h:434:#define kunit_test_suite(suite)\tkunit_test_suites(\u0026suite)\ninclude/kunit/test.h-435-\n--\ninclude/kunit/test.h-447- *\ninclude/kunit/test.h:448: * This functions similar to kunit_test_suites() except that it compiles the\ninclude/kunit/test.h-449- * list of suites during init phase.\n--\nlib/kunit/assert_test.c=383=static struct kunit_suite assert_test_suite = {\n--\nlib/kunit/assert_test.c-387-\nlib/kunit/assert_test.c:388:kunit_test_suites(\u0026assert_test_suite);\n--\nlib/kunit/backtrace-suppression-test.c=191=static struct kunit_suite backtrace_suppression_test_suite = {\n--\nlib/kunit/backtrace-suppression-test.c-194-};\nlib/kunit/backtrace-suppression-test.c:195:kunit_test_suites(\u0026backtrace_suppression_test_suite);\nlib/kunit/backtrace-suppression-test.c-196-\n--\nlib/kunit/debugfs.c=154=static ssize_t debugfs_run(struct file *file,\n--\nlib/kunit/debugfs.c-159-\nlib/kunit/debugfs.c:160:\t__kunit_test_suites_init(\u0026suite, 1, true);\nlib/kunit/debugfs.c-161-\n--\nlib/kunit/executor.c-9-/*\nlib/kunit/executor.c:10: * These symbols point to the .kunit_test_suites section and are defined in\nlib/kunit/executor.c-11- * include/asm-generic/vmlinux.lds.h, and consequently must be extern.\n--\nlib/kunit/executor.c=288=void kunit_exec_run_tests(struct kunit_suite_set *suite_set, bool builtin)\n--\nlib/kunit/executor.c-297-\nlib/kunit/executor.c:298:\t__kunit_test_suites_init(suite_set-\u003estart, num_suites, autorun);\nlib/kunit/executor.c-299-}\n--\nlib/kunit/executor_test.c=250=static struct kunit_suite executor_test_suite = {\n--\nlib/kunit/executor_test.c-254-\nlib/kunit/executor_test.c:255:kunit_test_suites(\u0026executor_test_suite);\nlib/kunit/executor_test.c-256-\n--\nlib/kunit/kunit-example-test.c=542=static struct kunit_suite example_test_suite = {\n--\nlib/kunit/kunit-example-test.c-554- */\nlib/kunit/kunit-example-test.c:555:kunit_test_suites(\u0026example_test_suite);\nlib/kunit/kunit-example-test.c-556-\n--\nlib/kunit/kunit-test.c=912=static struct kunit_suite kunit_stub_test_suite = {\n--\nlib/kunit/kunit-test.c-916-\nlib/kunit/kunit-test.c:917:kunit_test_suites(\u0026kunit_try_catch_test_suite, \u0026kunit_resource_test_suite,\nlib/kunit/kunit-test.c-918-\t\t \u0026kunit_log_test_suite, \u0026kunit_status_test_suite,\n--\nlib/kunit/platform-test.c=213=static struct kunit_suite kunit_platform_driver_suite = {\n--\nlib/kunit/platform-test.c-217-\nlib/kunit/platform-test.c:218:kunit_test_suites(\nlib/kunit/platform-test.c-219-\t\u0026kunit_platform_device_suite,\n--\nlib/kunit/string-stream-test.c=532=static struct kunit_suite string_stream_test_suite = {\n--\nlib/kunit/string-stream-test.c-536-};\nlib/kunit/string-stream-test.c:537:kunit_test_suites(\u0026string_stream_test_suite);\n--\nlib/kunit/test.c=848=bool kunit_enabled(void)\n--\nlib/kunit/test.c-852-\nlib/kunit/test.c:853:int __kunit_test_suites_init(struct kunit_suite * const * const suites, int num_suites,\nlib/kunit/test.c-854-\t\t\t bool run_tests)\n--\nlib/kunit/test.c-884-}\nlib/kunit/test.c:885:EXPORT_SYMBOL_GPL(__kunit_test_suites_init);\nlib/kunit/test.c-886-\nlib/kunit/test.c=887=static void kunit_exit_suite(struct kunit_suite *suite)\n--\nlib/kunit/test.c-891-\nlib/kunit/test.c:892:void __kunit_test_suites_exit(struct kunit_suite **suites, int num_suites)\nlib/kunit/test.c-893-{\n--\nlib/kunit/test.c-901-}\nlib/kunit/test.c:902:EXPORT_SYMBOL_GPL(__kunit_test_suites_exit);\nlib/kunit/test.c-903-\n--\nlib/kunit/test.c=944=static void kunit_module_exit(struct module *mod)\n--\nlib/kunit/test.c-959-\tif (!action)\nlib/kunit/test.c:960:\t\t__kunit_test_suites_exit(mod-\u003ekunit_suites,\nlib/kunit/test.c-961-\t\t\t\t\t mod-\u003enum_kunit_suites);\n"
} |
| 19/2 | 2026/10/21 12:50 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 62483 output: 208 thoughts: 2400 Thoughts: **Analysis of the WorthFuzzing=false Decision for an ext4 KUnit Test Patch** Okay, let's break this down. We have a patch adding KUnit tests to the ext4 filesystem. The key question is whether this merits fuzzing with syzkaller. My initial instinct is *no*, and the reasoning is pretty straightforward. First, I need to understand where the KUnit tests are placed in the kernel execution flow. They're in sections executed at boot or module load. They are self-tests; they run and then are done. Now, let’s consider the relevant guidance: This looks like a situation described in Section 2, the "Non-kernel and non-executable changes" - namely "User-space directories, self-tests, samples, or scripts...that do not affect the compiled kernel image (vmlinux) or kernel modules". It also mentions changes that "do not alter control flow or data structures," or "Build system or Kconfig changes that do not alter compiled C logic." This seems to apply, but let's be sure. The KUnit configuration itself, as seen in `fs/ext4/Kconfig`, explicitly states that these tests are for kernel developers running the KUnit test harness and are *not* intended for production builds. This reinforces that these are isolated unit tests. Now, I need to rigorously analyze the changes to *production* code. In `fs/ext4/inode.c`, we see `KUNIT_STATIC_STUB_REDIRECT`. Crucially, this only activates if we're *already* running a KUnit test (which syzkaller definitely is not). Outside of the KUnit context, the redirect is a no-op, quickly exiting because `current->kunit_test` will always be NULL in a syzkaller environment. The same is true for the `EXPORT_SYMBOL_FOR_EXT4_TEST` changes. Let me also clarify, could there be a logic change? No. The changes are all test-related. There's no modification of algorithms, data structures, or control flow within any reachable paths. This is important to verify line by line. So, according to Section 3, these changes do not meet any of the "positive criteria" for WorthFuzzing=true. There are no logic modifications, no restructuring of data structures, and no changes to assertions in *reachable* code. The primary "gate" is *reachability* (Section 1). These changes are structurally unreachable by fuzzing. Syzkaller generates system calls, and KUnit tests are not reachable this way. Let’s think about downstream impacts. If we marked this as `WorthFuzzing=true`, the syzkaller instance would be configured with symbols from these KUnit tests. It will waste resources trying to hit those symbols. Syzkaller does not provide inputs to KUnit tests. Even if `FocusSymbols` included the modified production functions, syzkaller would only be testing a NULL pointer check, which is completely useless. Therefore, `WorthFuzzing = false` is the correct decision. `FocusSymbols` and `EnableConfigs` should be empty because we are not fuzzing, and the `Reasoning` should make this logic clear. * `WorthFuzzing`: false * `FocusSymbols`: \[\] * `EnableConfigs`: \[\] * `Reasoning`: The patch adds a KUnit unit test suite (`extents_status-test.c`) for ext4 extent status tree operations. The only changes to production kernel files (`fs/ext4/inode.c`, `fs/ext4/extents_status.c`, `fs/ext4/extents.c`) are symbol exports for tests (`EXPORT_SYMBOL_FOR_EXT4_TEST`) and KUnit static stub redirection macros (`KUNIT_STATIC_STUB_REDIRECT`). In normal execution and syzkaller fuzzing environments, `kunit_get_current_test()` returns NULL, making the static stub redirect a no-op with zero functional or algorithmic logic change. KUnit test suites execute self-contained unit tests at boot or via the KUnit test harness, not via user-space syscall fuzzing paths, and take no user-controlled input. Thus, there is no modified reachable production code worth fuzzing. |
| 20/2 | 2026/10/21 12:51 | tool | set-results |
0mArgs:{
"EnableConfigs": [],
"FocusSymbols": [],
"Reasoning": "The patch adds a new KUnit test suite (fs/ext4/extents_status-test.c) and associated test plumbing (EXPORT_SYMBOL_FOR_EXT4_TEST exports and KUNIT_STATIC_STUB_REDIRECT hooks in fs/ext4/inode.c, fs/ext4/extents.c, and fs/ext4/extents_status.c). No functional kernel logic, data structures, or runtime assertions in ext4 production code are modified. During normal execution and fuzzing, KUNIT_STATIC_STUB_REDIRECT is a no-op because kunit_get_current_test() returns NULL. KUnit unit tests run non-interactively at boot or via test harnesses and are not reachable or exercisable via syzkaller syscall fuzzing. Therefore, the changes do not warrant fuzzing.",
"WorthFuzzing": false
}Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"Reasoning": "The patch adds a new KUnit test suite (fs/ext4/extents_status-test.c) and associated test plumbing (EXPORT_SYMBOL_FOR_EXT4_TEST exports and KUNIT_STATIC_STUB_REDIRECT hooks in fs/ext4/inode.c, fs/ext4/extents.c, and fs/ext4/extents_status.c). No functional kernel logic, data structures, or runtime assertions in ext4 production code are modified. During normal execution and fuzzing, KUNIT_STATIC_STUB_REDIRECT is a no-op because kunit_get_current_test() returns NULL. KUnit unit tests run non-interactively at boot or via test harnesses and are not reachable or exercisable via syzkaller syscall fuzzing. Therefore, the changes do not warrant fuzzing.",
"WorthFuzzing": false
} |
| 21/1 | 2026/10/21 12:51 | action | If |
0mArgs:{
"WorthFuzzing": false
}Results: null |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|