AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/11/03 10:33 flow patch-triage
10m Args:
null

Results:
{
  "EnableConfigs": [
    "EXT4_FS"
  ],
  "FocusSymbols": [
    "ext4_convert_unwritten_extents",
    "ext4_convert_unwritten_io_end_vec",
    "ext4_conv_pending_inc",
    "ext4_conv_pending_dec",
    "ext4_split_extent_zeroout",
    "ext4_ext_convert_to_initialized",
    "ext4_dio_write_end_io",
    "ext4_iomap_finish_ioend"
  ],
  "KMSANReasoning": "The patch introduces an in-flight IO tracking mechanism (using `i_conv_pending_ios` and `i_conv_pending_sem` on `struct ext4_inode_info`) to prevent ext4's fallback zeroout logic from racing with and overwriting data from concurrent IOs pending unwritten-to-written extent conversion.\n\nAnalysis of memory safety and sanitizer applicability:\n1. No uninitialized memory or info-leaks:\n   - All newly added struct members (`ei-\u003ei_conv_pending_ios`, `ei-\u003ei_conv_pending_sem`) are properly initialized in `ext4_alloc_inode()` and `extents_kunit_init()`.\n   - Local variables (e.g., `bool conv_pending_inc = false;` in `ext4_dio_write_iter()`, `int n = 0;` in `ext4_convert_unwritten_io_end_vec()`, `int err = 0;` in `ext4_split_extent_zeroout()`) are explicitly initialized before use.\n   - No kernel data structures or uninitialized memory are copied or exposed to userspace.\n2. Failure modes:\n   - Potential risks in this patch are synchronization issues, counter imbalance (e.g. leaking counts causing the WARN_ON_ONCE in `ext4_destroy_inode`), lock contention or deadlocks on `i_conv_pending_sem`, and filesystem error returns.\n   - Deadlocks and locking bugs are detected by LOCKDEP. Memory lifecycle issues (use-after-free, out-of-bounds) are detected by KASAN.\n   - KMSAN is not applicable as there are no uninitialized heap/stack memory reads or kernel-to-user info-leak vectors.",
  "NeedsKMSAN": false,
  "Reasoning": "The patch modifies ext4 core extent conversion and zeroout handling by introducing an in-flight IO tracking mechanism (i_conv_pending_ios counter and i_conv_pending_sem rwsem) to avoid data corruption when zeroing out unwritten extents during fallback. This changes direct I/O submission/completion, buffered writeback finish, and extent splitting/conversion paths, and adds runtime assertions (WARN_ON_ONCE). These paths are reachable via standard filesystem operations (fallocate, direct I/O writes to unwritten extents, buffered writeback).",
  "WorthFuzzing": true
}

1/1 2026/11/03 10:33 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit 1851ff6f52e314e00cbb635ae636c24fdb4f5632\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Tue Nov 3 10:33:31 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h\nindex 8d3af062a83068..44cd9f12d35043 100644\n--- a/fs/ext4/ext4.h\n+++ b/fs/ext4/ext4.h\n@@ -736,6 +736,11 @@ enum {\n  * Look EXT4_MAP_QUERY_LAST_IN_LEAF.\n  */\n #define EXT4_GET_BLOCKS_QUERY_LAST_IN_LEAF\t0x1000\n+/*\n+ * Caller may convert an unwritten extent (possibly zeroing parts of it)\n+ * without elevating the i_conv_pending_ios count to account for itself.\n+ */\n+#define EXT4_GET_BLOCKS_NO_CONV_ACC\t\t0x2000\n \n /*\n  * The bit position of these flags must not overlap with any of the\n@@ -1235,6 +1240,15 @@ struct ext4_inode_info {\n #ifdef CONFIG_FS_ENCRYPTION\n \tstruct fscrypt_inode_info *i_crypt_info;\n #endif\n+\t/*\n+\t * Number of in-flight IOs pending unwritten-\u003ewritten conversion. Used\n+\t * by the zeroout fallback to avoid zeroing out data of such IOs.\n+\t * Incrementing needs down_read(i_conv_pending_sem), zeroout needs\n+\t * down_write(i_conv_pending_sem), decrementing needs no lock. See\n+\t * comment above ext4_conv_pending_inc().\n+\t */\n+\tatomic_t i_conv_pending_ios;\n+\tstruct rw_semaphore i_conv_pending_sem;\n };\n \n /*\n@@ -3971,7 +3985,8 @@ extern long ext4_fallocate(struct file *file, int mode, loff_t offset,\n \t\t\t  loff_t len);\n extern int ext4_convert_unwritten_extents(handle_t *handle, struct inode *inode,\n \t\t\t\t\t  loff_t offset, ssize_t len,\n-\t\t\t\t\t  ext4_lblk_t *converted);\n+\t\t\t\t\t  ext4_lblk_t *converted,\n+\t\t\t\t\t  int extra_flags);\n extern int ext4_convert_unwritten_extents_atomic(handle_t *handle,\n \t\t\tstruct inode *inode, loff_t offset, ssize_t len);\n extern int ext4_convert_unwritten_io_end_vec(handle_t *handle,\n@@ -3982,6 +3997,11 @@ extern int ext4_map_query_blocks(handle_t *handle, struct inode *inode,\n \t\t\t\t  struct ext4_map_blocks *map, int flags);\n extern int ext4_map_create_blocks(handle_t *handle, struct inode *inode,\n \t\t\t\t  struct ext4_map_blocks *map, int flags);\n+extern void ext4_conv_pending_inc(struct inode *inode);\n+extern void ext4_conv_pending_sum(struct inode *inode, int n);\n+extern int ext4_conv_pending_inc_trylock(struct inode *inode);\n+extern void ext4_conv_pending_dec(struct inode *inode);\n+extern void ext4_conv_pending_sub(struct inode *inode, int n);\n extern int ext4_ext_calc_credits_for_single_extent(struct inode *inode,\n \t\t\t\t\t\t   int num,\n \t\t\t\t\t\t   struct ext4_ext_path *path);\n@@ -4093,14 +4113,15 @@ extern int ext4_resize_end(struct super_block *sb, bool update_backups);\n \n static inline void ext4_set_io_unwritten_flag(struct ext4_io_end *io_end)\n {\n-\tif (!(io_end-\u003eflag \u0026 EXT4_IO_END_UNWRITTEN))\n+\tif (!(io_end-\u003eflag \u0026 EXT4_IO_END_UNWRITTEN)) {\n \t\tio_end-\u003eflag |= EXT4_IO_END_UNWRITTEN;\n+\t\text4_conv_pending_inc(io_end-\u003einode);\n+\t}\n }\n \n static inline void ext4_clear_io_unwritten_flag(ext4_io_end_t *io_end)\n {\n-\tif (io_end-\u003eflag \u0026 EXT4_IO_END_UNWRITTEN)\n-\t\tio_end-\u003eflag \u0026= ~EXT4_IO_END_UNWRITTEN;\n+\tio_end-\u003eflag \u0026= ~EXT4_IO_END_UNWRITTEN;\n }\n \n extern const struct iomap_ops ext4_iomap_ops;\ndiff --git a/fs/ext4/extents-test.c b/fs/ext4/extents-test.c\nindex c3836ecb89f9cc..4d63c20501355b 100644\n--- a/fs/ext4/extents-test.c\n+++ b/fs/ext4/extents-test.c\n@@ -271,6 +271,8 @@ static int extents_kunit_init(struct kunit *test)\n \n \text4_es_init_tree(\u0026ei-\u003ei_es_tree);\n \trwlock_init(\u0026ei-\u003ei_es_lock);\n+\tatomic_set(\u0026ei-\u003ei_conv_pending_ios, 0);\n+\tinit_rwsem(\u0026ei-\u003ei_conv_pending_sem);\n \tINIT_LIST_HEAD(\u0026ei-\u003ei_es_list);\n \tei-\u003ei_es_all_nr = 0;\n \tei-\u003ei_es_shk_nr = 0;\ndiff --git a/fs/ext4/extents.c b/fs/ext4/extents.c\nindex 7193429a05e1f4..3150754b976617 100644\n--- a/fs/ext4/extents.c\n+++ b/fs/ext4/extents.c\n@@ -3311,6 +3311,41 @@ static struct ext4_ext_path *ext4_split_extent_at(handle_t *handle,\n \treturn path;\n }\n \n+/*\n+ * Returns true with i_conv_pending_sem held for write if it's safe to zeroout,\n+ * else drops the lock and returns false. The caller must call\n+ * ext4_conv_pending_zeroout_unlock() once the zeroout IO is complete.\n+ *\n+ * Callers are expected to have elevated i_conv_pending_ios to account for\n+ * themselves, so a count of 1 is their own. Callers that haven't must pass\n+ * EXT4_GET_BLOCKS_NO_CONV_ACC in flags, in which case any count is another IO.\n+ *\n+ * Refer to comment above ext4_conv_pending_inc() for details.\n+ */\n+static bool ext4_conv_pending_zeroout_lock(struct inode *inode, int flags)\n+{\n+\tstruct ext4_inode_info *ei = EXT4_I(inode);\n+\tint pending, thresh;\n+\n+\tthresh = (flags \u0026 EXT4_GET_BLOCKS_NO_CONV_ACC) ? 0 : 1;\n+\n+\tdown_write(\u0026ei-\u003ei_conv_pending_sem);\n+\tpending = atomic_read(\u0026ei-\u003ei_conv_pending_ios);\n+\n+\tWARN_ON_ONCE(pending \u003c 0);\n+\tif (pending \u003e thresh || pending \u003c 0) {\n+\t\tup_write(\u0026ei-\u003ei_conv_pending_sem);\n+\t\treturn false;\n+\t}\n+\n+\treturn true;\n+}\n+\n+static void ext4_conv_pending_zeroout_unlock(struct inode *inode)\n+{\n+\tup_write(\u0026EXT4_I(inode)-\u003ei_conv_pending_sem);\n+}\n+\n static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,\n \t\t\t\t     struct ext4_ext_path *path,\n \t\t\t\t     struct ext4_map_blocks *map, int flags)\n@@ -3328,6 +3363,9 @@ static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,\n \tee_len = ext4_ext_get_actual_len(ex);\n \tis_unwrit = ext4_ext_is_unwritten(ex);\n \n+\tif (!ext4_conv_pending_zeroout_lock(inode, flags))\n+\t\treturn -EINVAL;\n+\n \tif (flags \u0026 EXT4_GET_BLOCKS_CONVERT) {\n \t\t/*\n \t\t * EXT4_GET_BLOCKS_CONVERT: Caller wants the range specified by\n@@ -3338,9 +3376,11 @@ static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,\n \t\tloff_t map_end = (loff_t) map-\u003em_lblk + map-\u003em_len;\n \t\tloff_t ex_end = (loff_t) ee_block + ee_len;\n \n-\t\tif (!is_unwrit)\n+\t\tif (!is_unwrit) {\n \t\t\t/* Shouldn't happen. Just exit */\n-\t\t\treturn -EINVAL;\n+\t\t\terr = -EINVAL;\n+\t\t\tgoto out_unlock;\n+\t\t}\n \n \t\t/* zeroout left */\n \t\tif (map-\u003em_lblk \u003e ee_block) {\n@@ -3350,7 +3390,7 @@ static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,\n \t\t\terr = ext4_issue_zeroout(inode, lblk, pblk, len);\n \t\t\tif (err)\n \t\t\t\t/* ZEROOUT failed, just return original error */\n-\t\t\t\treturn err;\n+\t\t\t\tgoto out_unlock;\n \t\t}\n \n \t\t/* zeroout right */\n@@ -3361,7 +3401,7 @@ static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,\n \t\t\terr = ext4_issue_zeroout(inode, lblk, pblk, len);\n \t\t\tif (err)\n \t\t\t\t/* ZEROOUT failed, just return original error */\n-\t\t\t\treturn err;\n+\t\t\t\tgoto out_unlock;\n \t\t}\n \t} else if (flags \u0026 EXT4_GET_BLOCKS_CONVERT_UNWRITTEN) {\n \t\t/*\n@@ -3370,9 +3410,11 @@ static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,\n \t\t * Zeroout the map range leaving rest as it is.\n \t\t */\n \n-\t\tif (is_unwrit)\n+\t\tif (is_unwrit) {\n \t\t\t/* Shouldn't happen. Just exit */\n-\t\t\treturn -EINVAL;\n+\t\t\terr = -EINVAL;\n+\t\t\tgoto out_unlock;\n+\t\t}\n \n \t\tlblk = map-\u003em_lblk;\n \t\tlen = map-\u003em_len;\n@@ -3380,16 +3422,23 @@ static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,\n \t\terr = ext4_issue_zeroout(inode, lblk, pblk, len);\n \t\tif (err)\n \t\t\t/* ZEROOUT failed, just return original error */\n-\t\t\treturn err;\n+\t\t\tgoto out_unlock;\n \t} else {\n \t\t/*\n \t\t * We no longer perform unwritten to unwritten splits in IO paths.\n \t\t * Hence this should not happen.\n \t\t */\n \t\tWARN_ON_ONCE(true);\n-\t\treturn -EINVAL;\n+\t\terr = -EINVAL;\n+\t\tgoto out_unlock;\n \t}\n \n+\t/*\n+\t * The zeroout IO is done, no need to hold off new unwritten IOs while we\n+\t * update the extent tree.\n+\t */\n+\text4_conv_pending_zeroout_unlock(inode);\n+\n \terr = ext4_ext_get_access(handle, inode, path + depth);\n \tif (err)\n \t\treturn err;\n@@ -3401,6 +3450,10 @@ static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,\n \t\treturn err;\n \n \treturn 0;\n+\n+out_unlock:\n+\text4_conv_pending_zeroout_unlock(inode);\n+\treturn err;\n }\n \n /*\n@@ -3743,7 +3796,8 @@ ext4_ext_convert_to_initialized(handle_t *handle, struct inode *inode,\n \tsplit_map.m_lblk = map-\u003em_lblk;\n \tsplit_map.m_len = map-\u003em_len;\n \n-\tif (max_zeroout \u0026\u0026 (*allocated \u003e split_map.m_len)) {\n+\tif (max_zeroout \u0026\u0026 (*allocated \u003e split_map.m_len) \u0026\u0026\n+\t    ext4_conv_pending_zeroout_lock(inode, flags)) {\n \t\tif (*allocated \u003c= max_zeroout) {\n \t\t\t/* case 3 or 5 */\n \t\t\tzero_ex1.ee_block =\n@@ -3756,7 +3810,7 @@ ext4_ext_convert_to_initialized(handle_t *handle, struct inode *inode,\n \t\t\t\tsplit_map.m_len - ee_block);\n \t\t\terr = ext4_ext_zeroout(inode, \u0026zero_ex1);\n \t\t\tif (err)\n-\t\t\t\tgoto fallback;\n+\t\t\t\tgoto zeroout_unlock;\n \t\t\tsplit_map.m_len = *allocated;\n \t\t}\n \t\tif (split_map.m_lblk - ee_block + split_map.m_len \u003c\n@@ -3770,16 +3824,17 @@ ext4_ext_convert_to_initialized(handle_t *handle, struct inode *inode,\n \t\t\t\t\t\t      ext4_ext_pblock(ex));\n \t\t\t\terr = ext4_ext_zeroout(inode, \u0026zero_ex2);\n \t\t\t\tif (err)\n-\t\t\t\t\tgoto fallback;\n+\t\t\t\t\tgoto zeroout_unlock;\n \t\t\t}\n \n \t\t\tsplit_map.m_len += split_map.m_lblk - ee_block;\n \t\t\tsplit_map.m_lblk = ee_block;\n \t\t\t*allocated = map-\u003em_len;\n \t\t}\n+zeroout_unlock:\n+\t\text4_conv_pending_zeroout_unlock(inode);\n \t}\n \n-fallback:\n \tpath = ext4_split_convert_extents(handle, inode, \u0026split_map, path,\n \t\t\t\t\t  flags | EXT4_GET_BLOCKS_CONVERT, NULL);\n \tif (IS_ERR(path))\n@@ -4056,7 +4111,8 @@ ext4_ext_handle_unwritten_extents(handle_t *handle, struct inode *inode,\n \t * discovered unwritten extent to written.\n \t */\n \tpath = ext4_ext_convert_to_initialized(handle, inode, map, path,\n-\t\t\t\t\t       flags, allocated);\n+\t\t\t\t\t       flags | EXT4_GET_BLOCKS_NO_CONV_ACC,\n+\t\t\t\t\t       allocated);\n \tif (IS_ERR(path))\n \t\treturn path;\n \text4_update_inode_fsync_trans(handle, inode, 1);\n@@ -4704,7 +4760,7 @@ static int ext4_alloc_file_blocks(struct file *file, loff_t offset, loff_t len,\n \t\t\tret = ext4_convert_unwritten_extents(handle,\n \t\t\t\t\tinode, (loff_t)map.m_lblk \u003c\u003c blkbits,\n \t\t\t\t\t(loff_t)map.m_len \u003c\u003c blkbits,\n-\t\t\t\t\t\u0026converted);\n+\t\t\t\t\t\u0026converted, EXT4_GET_BLOCKS_NO_CONV_ACC);\n \t\t\tif (ret)\n \t\t\t\tmap.m_len = converted;\n \n@@ -5152,7 +5208,7 @@ int ext4_convert_unwritten_extents_atomic(handle_t *handle, struct inode *inode,\n  */\n int ext4_convert_unwritten_extents(handle_t *handle, struct inode *inode,\n \t\t\t\t   loff_t offset, ssize_t len,\n-\t\t\t\t   ext4_lblk_t *converted)\n+\t\t\t\t   ext4_lblk_t *converted, int extra_flags)\n {\n \text4_lblk_t max_blocks, conv_blocks = 0;\n \tint ret = 0, ret2 = 0, ret3 = 0;\n@@ -5195,7 +5251,7 @@ int ext4_convert_unwritten_extents(handle_t *handle, struct inode *inode,\n \t\t */\n \t\tret = ext4_map_blocks(handle, inode, \u0026map,\n \t\t\t\t      EXT4_GET_BLOCKS_IO_CONVERT_EXT |\n-\t\t\t\t      EXT4_EX_NOCACHE);\n+\t\t\t\t      EXT4_EX_NOCACHE | extra_flags);\n \t\tif (ret \u003c= 0) {\n \t\t\text4_warning(inode-\u003ei_sb,\n \t\t\t\t     \"inode #%llu: block %u: len %u: ext4_map_blocks returned %d\",\n@@ -5232,6 +5288,19 @@ int ext4_convert_unwritten_io_end_vec(handle_t *handle, ext4_io_end_t *io_end)\n {\n \tint ret = 0, err = 0;\n \tstruct ext4_io_end_vec *io_end_vec;\n+\tint n = 0;\n+\n+\t/*\n+\t * We take a single i_conv_pending_ios count for every unwritten io_end\n+\t * however each io_vec also needs its count to prevent a neighboring\n+\t * io_end_vec zeroing its data. This can't be accurately done during\n+\t * submission so do it here.\n+\t */\n+\tlist_for_each_entry(io_end_vec, \u0026io_end-\u003elist_vec, list)\n+\t\tn++;\n+\n+\tif (n \u003e 1)\n+\t\text4_conv_pending_sum(io_end-\u003einode, n - 1);\n \n \t/*\n \t * This is somewhat ugly but the idea is clear: When transaction is\n@@ -5241,16 +5310,20 @@ int ext4_convert_unwritten_io_end_vec(handle_t *handle, ext4_io_end_t *io_end)\n \tif (handle) {\n \t\thandle = ext4_journal_start_reserved(handle,\n \t\t\t\t\t\t     EXT4_HT_EXT_CONVERT);\n-\t\tif (IS_ERR(handle))\n+\t\tif (IS_ERR(handle)) {\n+\t\t\text4_conv_pending_sub(io_end-\u003einode, n);\n \t\t\treturn PTR_ERR(handle);\n+\t\t}\n \t}\n \n \tlist_for_each_entry(io_end_vec, \u0026io_end-\u003elist_vec, list) {\n-\t\tret = ext4_convert_unwritten_extents(handle, io_end-\u003einode,\n-\t\t\t\t\t\t     io_end_vec-\u003eoffset,\n-\t\t\t\t\t\t     io_end_vec-\u003esize, NULL);\n-\t\tif (ret)\n-\t\t\tbreak;\n+\t\tif (!ret)\n+\t\t\tret = ext4_convert_unwritten_extents(handle,\n+\t\t\t\t\t\t\t     io_end-\u003einode,\n+\t\t\t\t\t\t\t     io_end_vec-\u003eoffset,\n+\t\t\t\t\t\t\t     io_end_vec-\u003esize,\n+\t\t\t\t\t\t\t     NULL, 0);\n+\t\text4_conv_pending_dec(io_end-\u003einode);\n \t}\n \n \tif (handle)\ndiff --git a/fs/ext4/file.c b/fs/ext4/file.c\nindex 50d3c92709c8b8..52b1fb99484d21 100644\n--- a/fs/ext4/file.c\n+++ b/fs/ext4/file.c\n@@ -457,7 +457,16 @@ static int ext4_dio_write_end_io(struct kiocb *iocb, ssize_t size,\n \t\t\t\t\t\t\t      size);\n \telse if (!error \u0026\u0026 size \u0026\u0026 flags \u0026 IOMAP_DIO_UNWRITTEN)\n \t\terror = ext4_convert_unwritten_extents(NULL, inode, pos, size,\n-\t\t\t\t\t\t       NULL);\n+\t\t\t\t\t\t       NULL, 0);\n+\n+\t/*\n+\t * If this dio covered an unwritten extent, we would have incremented\n+\t * i_conv_pending_ios in ext4_iomap_next(). Decrement it now that\n+\t * the conversion has completed (or failed).\n+\t */\n+\tif (flags \u0026 IOMAP_DIO_UNWRITTEN)\n+\t\text4_conv_pending_dec(inode);\n+\n \tif (error)\n \t\treturn error;\n \t/*\n@@ -599,6 +608,7 @@ static ssize_t ext4_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)\n \tsize_t count = iov_iter_count(from);\n \tbool extend = false;\n \tbool ilock_shared = true;\n+\tbool conv_pending_inc = false;\n \tint dio_flags = 0;\n \n \t/*\n@@ -664,7 +674,7 @@ static ssize_t ext4_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)\n \t}\n \n \tret = iomap_dio_rw(iocb, from, \u0026ext4_iomap_ops, \u0026ext4_dio_write_ops,\n-\t\t\t   dio_flags, NULL, 0);\n+\t\t\t   dio_flags, \u0026conv_pending_inc, 0);\n \tif (ret == -ENOTBLK)\n \t\tret = 0;\n \tif (extend) {\ndiff --git a/fs/ext4/inode.c b/fs/ext4/inode.c\nindex 6ede3644a738be..46f91d6d8ed5ef 100644\n--- a/fs/ext4/inode.c\n+++ b/fs/ext4/inode.c\n@@ -669,6 +669,107 @@ int ext4_map_query_blocks(handle_t *handle, struct inode *inode,\n \treturn retval;\n }\n \n+static void _ext4_conv_pending_mod(struct inode *inode, int n)\n+{\n+\tstruct ext4_inode_info *ei = EXT4_I(inode);\n+\n+\t/*\n+\t * Only use the full ordering variant when tracing is needed.\n+\t */\n+\tif (trace_ext4_conv_pending_ios_enabled()) {\n+\t\tint new_ios = atomic_add_return(n, \u0026ei-\u003ei_conv_pending_ios);\n+\n+\t\ttrace_ext4_conv_pending_ios(inode, n \u003e 0, new_ios - n, new_ios);\n+\t} else {\n+\t\tatomic_add(n, \u0026ei-\u003ei_conv_pending_ios);\n+\t}\n+}\n+\n+/*\n+ * In case endio conversion fails due to factors like ENOSPC or ENOMEM, ext4\n+ * uses a fallback where we zeroout the unwritten extents instead of splitting.\n+ * However, not all unwritten extents can be zeroed out unconditionally as\n+ * they might have data underneath which is pending endio conversion. Zeroing\n+ * out such an extent can cause silent corruption.\n+ *\n+ * To fix this we track the IOs which are about to undergo conversion in\n+ * ei-\u003ei_conv_pending_ios. The zeroout code then uses this counter to\n+ * determine if it's safe to zeroout.\n+ *\n+ * Design Notes:\n+ *\n+ * **Locking**\n+ *\n+ * The only mutual exclusion we need is between an IO that is about to be\n+ * submitted over an unwritten extent and zeroout. This is done using a\n+ * dedicated rwsem, ei-\u003ei_conv_pending_sem with the following rules:\n+ *\n+ * 1. Incrementing the counter must down_read(i_conv_pending_sem).\n+ * 2. A zeroout must check the counter and zero data under\n+ *    down_write(i_conv_pending_sem)\n+ * 3. Decrementing the counter needs no lock. At worst, this makes zeroout bail\n+ *    out due to a stale, elevated counter value, which is acceptable\n+ * 4. Changes to i_conv_pending_ios should use atomic helpers.\n+ *\n+ * This design provides us the required exclusion while ensuring that fast paths\n+ * don't see any heavy lock contention. Atomic counters help parallel\n+ * modifications to be serialized.\n+ *\n+ * ** Tolerance for false positives **\n+ *\n+ * We trade false positives for simplicity of implementation because having a\n+ * false positive here will just error the endio which is still better than\n+ * silently corrupting the data. We can always optimize our tracking to make it\n+ * more accurate in the future.\n+ */\n+void ext4_conv_pending_inc(struct inode *inode)\n+{\n+\tstruct ext4_inode_info *ei = EXT4_I(inode);\n+\n+\tdown_read(\u0026ei-\u003ei_conv_pending_sem);\n+\t_ext4_conv_pending_mod(inode, 1);\n+\tup_read(\u0026ei-\u003ei_conv_pending_sem);\n+}\n+\n+void ext4_conv_pending_sum(struct inode *inode, int n)\n+{\n+\tstruct ext4_inode_info *ei = EXT4_I(inode);\n+\n+\tdown_read(\u0026ei-\u003ei_conv_pending_sem);\n+\t_ext4_conv_pending_mod(inode, n);\n+\tup_read(\u0026ei-\u003ei_conv_pending_sem);\n+}\n+\n+/*\n+ * Same as ext4_conv_pending_inc() but doesn't sleep if a zeroout is in\n+ * progress. Returns -EAGAIN and leaves the counter untouched in that case.\n+ */\n+int ext4_conv_pending_inc_trylock(struct inode *inode)\n+{\n+\tstruct ext4_inode_info *ei = EXT4_I(inode);\n+\n+\tif (!down_read_trylock(\u0026ei-\u003ei_conv_pending_sem))\n+\t\treturn -EAGAIN;\n+\n+\t_ext4_conv_pending_mod(inode, 1);\n+\tup_read(\u0026ei-\u003ei_conv_pending_sem);\n+\treturn 0;\n+}\n+\n+void ext4_conv_pending_dec(struct inode *inode)\n+{\n+\t_ext4_conv_pending_mod(inode, -1);\n+}\n+\n+void ext4_conv_pending_sub(struct inode *inode, int n)\n+{\n+\tstruct ext4_inode_info *ei = EXT4_I(inode);\n+\n+\tdown_read(\u0026ei-\u003ei_conv_pending_sem);\n+\t_ext4_conv_pending_mod(inode, -n);\n+\tup_read(\u0026ei-\u003ei_conv_pending_sem);\n+}\n+\n int ext4_map_create_blocks(handle_t *handle, struct inode *inode,\n \t\t\t   struct ext4_map_blocks *map, int flags)\n {\n@@ -3994,7 +4095,47 @@ int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,\n \treturn 0;\n }\n \n-static DEFINE_IOMAP_ITER_NEXT(ext4_iomap_next, ext4_iomap_begin);\n+static int ext4_iomap_next(const struct iomap_iter *iter, struct iomap *iomap,\n+\t\t\t   struct iomap *srcmap)\n+{\n+\tint ret = iomap_iter_next(iter, iomap, srcmap, ext4_iomap_begin, NULL);\n+\n+\t/*\n+\t * For dio, increment i_conv_pending_ios the first time we see an\n+\t * unwritten mapping for this IO, so that it cleanly balances with the\n+\t * single endio call. We use iter-\u003eprivate to track state to ensure we\n+\t * only increment once per dio regardless of how many extents it spans.\n+\t * The decrement happens in ext4_dio_write_end_io() if\n+\t * IOMAP_DIO_UNWRITTEN is set.\n+\t *\n+\t * Hack alert: iomap_dio_bio_iter() fails a misaligned mapping with\n+\t * -EINVAL before it sets IOMAP_DIO_UNWRITTEN, so endio would skip the\n+\t * decrement. Don't increment for such a mapping. The alignment check\n+\t * mirrors the one in iomap_dio_bio_iter()\n+\t */\n+\tif (ret \u003e 0 \u0026\u0026 iter-\u003eprivate \u0026\u0026\n+\t    (iter-\u003eflags \u0026 IOMAP_WRITE) \u0026\u0026 (iomap-\u003etype == IOMAP_UNWRITTEN) \u0026\u0026\n+\t    IS_ALIGNED(iter-\u003epos | iomap_length(iter),\n+\t\t       bdev_logical_block_size(iomap-\u003ebdev))) {\n+\t\tbool *inc_done = (bool *)iter-\u003eprivate;\n+\n+\t\tif (!*inc_done) {\n+\t\t\t/* NOWAIT dio must not sleep on i_conv_pending_sem */\n+\t\t\tif (iter-\u003eflags \u0026 IOMAP_NOWAIT) {\n+\t\t\t\tint err;\n+\n+\t\t\t\terr = ext4_conv_pending_inc_trylock(iter-\u003einode);\n+\t\t\t\tif (err)\n+\t\t\t\t\treturn err;\n+\t\t\t} else {\n+\t\t\t\text4_conv_pending_inc(iter-\u003einode);\n+\t\t\t}\n+\t\t\t*inc_done = true;\n+\t\t}\n+\t}\n+\n+\treturn ret;\n+}\n \n const struct iomap_ops ext4_iomap_ops = {\n \t.iomap_next\t\t= ext4_iomap_next,\n@@ -4447,6 +4588,9 @@ static int ext4_iomap_writeback_submit(struct iomap_writepage_ctx *wpc,\n \tif (ioend-\u003eio_bio.bi_end_io)\n \t\tbio_clear_flag(\u0026ioend-\u003eio_bio, BIO_COMPLETE_IN_TASK);\n \n+\tif (ioend-\u003eio_flags \u0026 IOMAP_IOEND_UNWRITTEN)\n+\t\text4_conv_pending_inc(inode);\n+\n \treturn iomap_ioend_writeback_submit(wpc, error);\n }\n \ndiff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c\nindex 734d856a6d4784..e99816017a18da 100644\n--- a/fs/ext4/page-io.c\n+++ b/fs/ext4/page-io.c\n@@ -190,6 +190,12 @@ static int ext4_end_io_end(ext4_io_end_t *io_end)\n \n \t\tif (test_opt(sb, DATA_ERR_ABORT))\n \t\t\tjbd2_journal_abort(EXT4_SB(sb)-\u003es_journal, ret);\n+\n+\t\t/*\n+\t\t * Conversion was skipped so drop the count that submission took\n+\t\t */\n+\t\tif (io_end-\u003eflag \u0026 EXT4_IO_END_UNWRITTEN)\n+\t\t\text4_conv_pending_dec(inode);\n \t} else {\n \t\tret = ext4_convert_unwritten_io_end_vec(handle, io_end);\n \t}\n@@ -646,6 +652,21 @@ static void ext4_iomap_finish_ioend(struct iomap_ioend *ioend)\n \tint credits;\n \tint ret, err;\n \n+\t/*\n+\t * We increment conv_pending for each IO we submit but endio might have\n+\t * merged them into a single ioend. The data of all merged sub-ioends is\n+\t * covered by a single conversion, so drop their counts keeping just\n+\t * the one count for the single ioend we will try to convert.\n+\t */\n+\tif (ioend-\u003eio_flags \u0026 IOMAP_IOEND_UNWRITTEN) {\n+\t\tstruct iomap_ioend *sub;\n+\n+\t\tlist_for_each_entry(sub, \u0026ioend-\u003eio_list, io_list) {\n+\t\t\tif (sub-\u003eio_flags \u0026 IOMAP_IOEND_UNWRITTEN)\n+\t\t\t\text4_conv_pending_dec(inode);\n+\t\t}\n+\t}\n+\n \tret = blk_status_to_errno(ioend-\u003eio_bio.bi_status);\n \tif (is_disksize_grow)\n \t\ttrace_ext4_iomap_wb_disksize_pending_complete(ioend-\u003eio_inode,\n@@ -685,7 +706,7 @@ static void ext4_iomap_finish_ioend(struct iomap_ioend *ioend)\n \n \tif (ioend-\u003eio_flags \u0026 IOMAP_IOEND_UNWRITTEN)\n \t\tret = ext4_convert_unwritten_extents(handle, inode, pos,\n-\t\t\t\t\t\t     size, NULL);\n+\t\t\t\t\t\t     size, NULL, 0);\n \n out_journal:\n \terr = ext4_journal_stop(handle);\n@@ -698,6 +719,10 @@ static void ext4_iomap_finish_ioend(struct iomap_ioend *ioend)\n \t\t\t inode-\u003ei_ino, ret);\n \t}\n out:\n+\t/* Drop the count of the head ioend now that conversion is done. */\n+\tif (ioend-\u003eio_flags \u0026 IOMAP_IOEND_UNWRITTEN)\n+\t\text4_conv_pending_dec(inode);\n+\n \tiomap_finish_ioends(ioend, ret);\n }\n \ndiff --git a/fs/ext4/super.c b/fs/ext4/super.c\nindex 7d8aedfbbb87f1..866a6a70535e9d 100644\n--- a/fs/ext4/super.c\n+++ b/fs/ext4/super.c\n@@ -1429,6 +1429,8 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)\n \tei-\u003ei_es_shrink_lblk = 0;\n \tei-\u003ei_es_seq = 0;\n \tei-\u003ei_reserved_data_blocks = 0;\n+\tatomic_set(\u0026ei-\u003ei_conv_pending_ios, 0);\n+\tinit_rwsem(\u0026ei-\u003ei_conv_pending_sem);\n \tspin_lock_init(\u0026(ei-\u003ei_block_reservation_lock));\n \text4_init_pending_tree(\u0026ei-\u003ei_pending_tree);\n #ifdef CONFIG_QUOTA\n@@ -1505,6 +1507,16 @@ static void ext4_destroy_inode(struct inode *inode)\n \t\text4_msg(inode-\u003ei_sb, KERN_ERR,\n \t\t\t \"Inode %llu (%p): EXT4_STATE_DISKSIZE_GROW_PENDING not cleared!\",\n \t\t\t inode-\u003ei_ino, EXT4_I(inode));\n+\n+\tif (!(EXT4_SB(inode-\u003ei_sb)-\u003es_mount_state \u0026 EXT4_ERROR_FS) \u0026\u0026\n+\t    !ext4_emergency_state(inode-\u003ei_sb)) {\n+\t\tint pending = atomic_read(\u0026EXT4_I(inode)-\u003ei_conv_pending_ios);\n+\n+\t\tif (WARN_ON_ONCE(pending))\n+\t\t\text4_msg(inode-\u003ei_sb, KERN_ERR,\n+\t\t\t\t \"Inode %llu (%p): i_conv_pending_ios (%d) not cleared!\",\n+\t\t\t\t inode-\u003ei_ino, EXT4_I(inode), pending);\n+\t}\n }\n \n static void ext4_shutdown(struct super_block *sb)\ndiff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h\nindex 92048da9dae43b..f1754b2e836ca3 100644\n--- a/include/trace/events/ext4.h\n+++ b/include/trace/events/ext4.h\n@@ -43,6 +43,7 @@ struct partial_cluster;\n \t{ EXT4_GET_BLOCKS_CONVERT,\t\t\"CONVERT\" },\t\t\\\n \t{ EXT4_GET_BLOCKS_METADATA_NOFAIL,\t\"METADATA_NOFAIL\" },\t\\\n \t{ EXT4_GET_BLOCKS_NO_NORMALIZE,\t\t\"NO_NORMALIZE\" },\t\\\n+\t{ EXT4_GET_BLOCKS_NO_CONV_ACC,\t\t\"NO_CONV_ACC\" },\t\\\n \t{ EXT4_GET_BLOCKS_CONVERT_UNWRITTEN,\t\"CONVERT_UNWRITTEN\" },  \\\n \t{ EXT4_GET_BLOCKS_ZERO,\t\t\t\"ZERO\" },\t\t\\\n \t{ EXT4_GET_BLOCKS_IO_SUBMIT,\t\t\"IO_SUBMIT\" },\t\t\\\n@@ -3366,6 +3367,30 @@ TRACE_EVENT(ext4_block_zero_eof,\n \t\t  __entry-\u003ei_disksize, __entry-\u003edid_zero, __entry-\u003ezero_written)\n );\n \n+/* i_conv_pending_ios accounting tracepoint */\n+TRACE_EVENT(ext4_conv_pending_ios,\n+\tTP_PROTO(struct inode *inode, bool add, int old_ios, int new_ios),\n+\tTP_ARGS(inode, add, old_ios, new_ios),\n+\tTP_STRUCT__entry(\n+\t\t__field(dev_t, dev)\n+\t\t__field(u64, ino)\n+\t\t__field(bool, add)\n+\t\t__field(int, old_ios)\n+\t\t__field(int, new_ios)\n+\t),\n+\tTP_fast_assign(\n+\t\t__entry-\u003edev = inode-\u003ei_sb-\u003es_dev;\n+\t\t__entry-\u003eino = inode-\u003ei_ino;\n+\t\t__entry-\u003eadd = add;\n+\t\t__entry-\u003eold_ios = old_ios;\n+\t\t__entry-\u003enew_ios = new_ios;\n+\t),\n+\tTP_printk(\"dev %d:%d ino %llu %s i_conv_pending_ios %d -\u003e %d\",\n+\t\t  MAJOR(__entry-\u003edev), MINOR(__entry-\u003edev), __entry-\u003eino,\n+\t\t  __entry-\u003eadd ? \"inc\" : \"dec\",\n+\t\t  __entry-\u003eold_ios, __entry-\u003enew_ios)\n+);\n+\n #endif /* _TRACE_EXT4_H */\n \n /* This part must be outside protection */\n"
}

2/1 2026/11/03 10:33 agent patch-evaluator
2m Model:
core

Args:
null

Results:
{
  "EnableConfigs": [
    "EXT4_FS"
  ],
  "FocusSymbols": [
    "ext4_convert_unwritten_extents",
    "ext4_convert_unwritten_io_end_vec",
    "ext4_conv_pending_inc",
    "ext4_conv_pending_dec",
    "ext4_split_extent_zeroout",
    "ext4_ext_convert_to_initialized",
    "ext4_dio_write_end_io",
    "ext4_iomap_finish_ioend"
  ],
  "Reasoning": "The patch modifies ext4 core extent conversion and zeroout handling by introducing an in-flight IO tracking mechanism (i_conv_pending_ios counter and i_conv_pending_sem rwsem) to avoid data corruption when zeroing out unwritten extents during fallback. This changes direct I/O submission/completion, buffered writeback finish, and extent splitting/conversion paths, and adds runtime assertions (WARN_ON_ONCE). These paths are reachable via standard filesystem operations (fallocate, direct I/O writes to unwritten extents, buffered writeback).",
  "WorthFuzzing": true
}

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 1851ff6f52e314e00cbb635ae636c24fdb4f5632
Author: syz-cluster <triage@syzkaller.com>
Date:   Tue Nov 3 10:33:31 2026 +0000

    syz-cluster: applied patch under review

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 8d3af062a83068..44cd9f12d35043 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -736,6 +736,11 @@ enum {
  * Look EXT4_MAP_QUERY_LAST_IN_LEAF.
  */
 #define EXT4_GET_BLOCKS_QUERY_LAST_IN_LEAF	0x1000
+/*
+ * Caller may convert an unwritten extent (possibly zeroing parts of it)
+ * without elevating the i_conv_pending_ios count to account for itself.
+ */
+#define EXT4_GET_BLOCKS_NO_CONV_ACC		0x2000
 
 /*
  * The bit position of these flags must not overlap with any of the
@@ -1235,6 +1240,15 @@ struct ext4_inode_info {
 #ifdef CONFIG_FS_ENCRYPTION
 	struct fscrypt_inode_info *i_crypt_info;
 #endif
+	/*
+	 * Number of in-flight IOs pending unwritten->written conversion. Used
+	 * by the zeroout fallback to avoid zeroing out data of such IOs.
+	 * Incrementing needs down_read(i_conv_pending_sem), zeroout needs
+	 * down_write(i_conv_pending_sem), decrementing needs no lock. See
+	 * comment above ext4_conv_pending_inc().
+	 */
+	atomic_t i_conv_pending_ios;
+	struct rw_semaphore i_conv_pending_sem;
 };
 
 /*
@@ -3971,7 +3985,8 @@ extern long ext4_fallocate(struct file *file, int mode, loff_t offset,
 			  loff_t len);
 extern int ext4_convert_unwritten_extents(handle_t *handle, struct inode *inode,
 					  loff_t offset, ssize_t len,
-					  ext4_lblk_t *converted);
+					  ext4_lblk_t *converted,
+					  int extra_flags);
 extern int ext4_convert_unwritten_extents_atomic(handle_t *handle,
 			struct inode *inode, loff_t offset, ssize_t len);
 extern int ext4_convert_unwritten_io_end_vec(handle_t *handle,
@@ -3982,6 +3997,11 @@ extern int ext4_map_query_blocks(handle_t *handle, struct inode *inode,
 				  struct ext4_map_blocks *map, int flags);
 extern int ext4_map_create_blocks(handle_t *handle, struct inode *inode,
 				  struct ext4_map_blocks *map, int flags);
+extern void ext4_conv_pending_inc(struct inode *inode);
+extern void ext4_conv_pending_sum(struct inode *inode, int n);
+extern int ext4_conv_pending_inc_trylock(struct inode *inode);
+extern void ext4_conv_pending_dec(struct inode *inode);
+extern void ext4_conv_pending_sub(struct inode *inode, int n);
 extern int ext4_ext_calc_credits_for_single_extent(struct inode *inode,
 						   int num,
 						   struct ext4_ext_path *path);
@@ -4093,14 +4113,15 @@ extern int ext4_resize_end(struct super_block *sb, bool update_backups);
 
 static inline void ext4_set_io_unwritten_flag(struct ext4_io_end *io_end)
 {
-	if (!(io_end->flag & EXT4_IO_END_UNWRITTEN))
+	if (!(io_end->flag & EXT4_IO_END_UNWRITTEN)) {
 		io_end->flag |= EXT4_IO_END_UNWRITTEN;
+		ext4_conv_pending_inc(io_end->inode);
+	}
 }
 
 static inline void ext4_clear_io_unwritten_flag(ext4_io_end_t *io_end)
 {
-	if (io_end->flag & EXT4_IO_END_UNWRITTEN)
-		io_end->flag &= ~EXT4_IO_END_UNWRITTEN;
+	io_end->flag &= ~EXT4_IO_END_UNWRITTEN;
 }
 
 extern const struct iomap_ops ext4_iomap_ops;
diff --git a/fs/ext4/extents-test.c b/fs/ext4/extents-test.c
index c3836ecb89f9cc..4d63c20501355b 100644
--- a/fs/ext4/extents-test.c
+++ b/fs/ext4/extents-test.c
@@ -271,6 +271,8 @@ static int extents_kunit_init(struct kunit *test)
 
 	ext4_es_init_tree(&ei->i_es_tree);
 	rwlock_init(&ei->i_es_lock);
+	atomic_set(&ei->i_conv_pending_ios, 0);
+	init_rwsem(&ei->i_conv_pending_sem);
 	INIT_LIST_HEAD(&ei->i_es_list);
 	ei->i_es_all_nr = 0;
 	ei->i_es_shk_nr = 0;
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 7193429a05e1f4..3150754b976617 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -3311,6 +3311,41 @@ static struct ext4_ext_path *ext4_split_extent_at(handle_t *handle,
 	return path;
 }
 
+/*
+ * Returns true with i_conv_pending_sem held for write if it's safe to zeroout,
+ * else drops the lock and returns false. The caller must call
+ * ext4_conv_pending_zeroout_unlock() once the zeroout IO is complete.
+ *
+ * Callers are expected to have elevated i_conv_pending_ios to account for
+ * themselves, so a count of 1 is their own. Callers that haven't must pass
+ * EXT4_GET_BLOCKS_NO_CONV_ACC in flags, in which case any count is another IO.
+ *
+ * Refer to comment above ext4_conv_pending_inc() for details.
+ */
+static bool ext4_conv_pending_zeroout_lock(struct inode *inode, int flags)
+{
+	struct ext4_inode_info *ei = EXT4_I(inode);
+	int pending, thresh;
+
+	thresh = (flags & EXT4_GET_BLOCKS_NO_CONV_ACC) ? 0 : 1;
+
+	down_write(&ei->i_conv_pending_sem);
+	pending = atomic_read(&ei->i_conv_pending_ios);
+
+	WARN_ON_ONCE(pending < 0);
+	if (pending > thresh || pending < 0) {
+		up_write(&ei->i_conv_pending_sem);
+		return false;
+	}
+
+	return true;
+}
+
+static void ext4_conv_pending_zeroout_unlock(struct inode *inode)
+{
+	up_write(&EXT4_I(inode)->i_conv_pending_sem);
+}
+
 static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,
 				     struct ext4_ext_path *path,
 				     struct ext4_map_blocks *map, int flags)
@@ -3328,6 +3363,9 @@ static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,
 	ee_len = ext4_ext_get_actual_len(ex);
 	is_unwrit = ext4_ext_is_unwritten(ex);
 
+	if (!ext4_conv_pending_zeroout_lock(inode, flags))
+		return -EINVAL;
+
 	if (flags & EXT4_GET_BLOCKS_CONVERT) {
 		/*
 		 * EXT4_GET_BLOCKS_CONVERT: Caller wants the range specified by
@@ -3338,9 +3376,11 @@ static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,
 		loff_t map_end = (loff_t) map->m_lblk + map->m_len;
 		loff_t ex_end = (loff_t) ee_block + ee_len;
 
-		if (!is_unwrit)
+		if (!is_unwrit) {
 			/* Shouldn't happen. Just exit */
-			return -EINVAL;
+			err = -EINVAL;
+			goto out_unlock;
+		}
 
 		/* zeroout left */
 		if (map->m_lblk > ee_block) {
@@ -3350,7 +3390,7 @@ static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,
 			err = ext4_issue_zeroout(inode, lblk, pblk, len);
 			if (err)
 				/* ZEROOUT failed, just return original error */
-				return err;
+				goto out_unlock;
 		}
 
 		/* zeroout right */
@@ -3361,7 +3401,7 @@ static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,
 			err = ext4_issue_zeroout(inode, lblk, pblk, len);
 			if (err)
 				/* ZEROOUT failed, just return original error */
-				return err;
+				goto out_unlock;
 		}
 	} else if (flags & EXT4_GET_BLOCKS_CONVERT_UNWRITTEN) {
 		/*
@@ -3370,9 +3410,11 @@ static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,
 		 * Zeroout the map range leaving rest as it is.
 		 */
 
-		if (is_unwrit)
+		if (is_unwrit) {
 			/* Shouldn't happen. Just exit */
-			return -EINVAL;
+			err = -EINVAL;
+			goto out_unlock;
+		}
 
 		lblk = map->m_lblk;
 		len = map->m_len;
@@ -3380,16 +3422,23 @@ static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,
 		err = ext4_issue_zeroout(inode, lblk, pblk, len);
 		if (err)
 			/* ZEROOUT failed, just return original error */
-			return err;
+			goto out_unlock;
 	} else {
 		/*
 		 * We no longer perform unwritten to unwritten splits in IO paths.
 		 * Hence this should not happen.
 		 */
 		WARN_ON_ONCE(true);
-		return -EINVAL;
+		err = -EINVAL;
+		goto out_unlock;
 	}
 
+	/*
+	 * The zeroout IO is done, no need to hold off new unwritten IOs while we
+	 * update the extent tree.
+	 */
+	ext4_conv_pending_zeroout_unlock(inode);
+
 	err = ext4_ext_get_access(handle, inode, path + depth);
 	if (err)
 		return err;
@@ -3401,6 +3450,10 @@ static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,
 		return err;
 
 	return 0;
+
+out_unlock:
+	ext4_conv_pending_zeroout_unlock(inode);
+	return err;
 }
 
 /*
@@ -3743,7 +3796,8 @@ ext4_ext_convert_to_initialized(handle_t *handle, struct inode *inode,
 	split_map.m_lblk = map->m_lblk;
 	split_map.m_len = map->m_len;
 
-	if (max_zeroout && (*allocated > split_map.m_len)) {
+	if (max_zeroout && (*allocated > split_map.m_len) &&
+	    ext4_conv_pending_zeroout_lock(inode, flags)) {
 		if (*allocated <= max_zeroout) {
 			/* case 3 or 5 */
 			zero_ex1.ee_block =
@@ -3756,7 +3810,7 @@ ext4_ext_convert_to_initialized(handle_t *handle, struct inode *inode,
 				split_map.m_len - ee_block);
 			err = ext4_ext_zeroout(inode, &zero_ex1);
 			if (err)
-				goto fallback;
+				goto zeroout_unlock;
 			split_map.m_len = *allocated;
 		}
 		if (split_map.m_lblk - ee_block + split_map.m_len <
@@ -3770,16 +3824,17 @@ ext4_ext_convert_to_initialized(handle_t *handle, struct inode *inode,
 						      ext4_ext_pblock(ex));
 				err = ext4_ext_zeroout(inode, &zero_ex2);
 				if (err)
-					goto fallback;
+					goto zeroout_unlock;
 			}
 
 			split_map.m_len += split_map.m_lblk - ee_block;
 			split_map.m_lblk = ee_block;
 			*allocated = map->m_len;
 		}
+zeroout_unlock:
+		ext4_conv_pending_zeroout_unlock(inode);
 	}
 
-fallback:
 	path = ext4_split_convert_extents(handle, inode, &split_map, path,
 					  flags | EXT4_GET_BLOCKS_CONVERT, NULL);
 	if (IS_ERR(path))
@@ -4056,7 +4111,8 @@ ext4_ext_handle_unwritten_extents(handle_t *handle, struct inode *inode,
 	 * discovered unwritten extent to written.
 	 */
 	path = ext4_ext_convert_to_initialized(handle, inode, map, path,
-					       flags, allocated);
+					       flags | EXT4_GET_BLOCKS_NO_CONV_ACC,
+					       allocated);
 	if (IS_ERR(path))
 		return path;
 	ext4_update_inode_fsync_trans(handle, inode, 1);
@@ -4704,7 +4760,7 @@ static int ext4_alloc_file_blocks(struct file *file, loff_t offset, loff_t len,
 			ret = ext4_convert_unwritten_extents(handle,
 					inode, (loff_t)map.m_lblk << blkbits,
 					(loff_t)map.m_len << blkbits,
-					&converted);
+					&converted, EXT4_GET_BLOCKS_NO_CONV_ACC);
 			if (ret)
 				map.m_len = converted;
 
@@ -5152,7 +5208,7 @@ int ext4_convert_unwritten_extents_atomic(handle_t *handle, struct inode *inode,
  */
 int ext4_convert_unwritten_extents(handle_t *handle, struct inode *inode,
 				   loff_t offset, ssize_t len,
-				   ext4_lblk_t *converted)
+				   ext4_lblk_t *converted, int extra_flags)
 {
 	ext4_lblk_t max_blocks, conv_blocks = 0;
 	int ret = 0, ret2 = 0, ret3 = 0;
@@ -5195,7 +5251,7 @@ int ext4_convert_unwritten_extents(handle_t *handle, struct inode *inode,
 		 */
 		ret = ext4_map_blocks(handle, inode, &map,
 				      EXT4_GET_BLOCKS_IO_CONVERT_EXT |
-				      EXT4_EX_NOCACHE);
+				      EXT4_EX_NOCACHE | extra_flags);
 		if (ret <= 0) {
 			ext4_warning(inode->i_sb,
 				     "inode #%llu: block %u: len %u: ext4_map_blocks returned %d",
@@ -5232,6 +5288,19 @@ int ext4_convert_unwritten_io_end_vec(handle_t *handle, ext4_io_end_t *io_end)
 {
 	int ret = 0, err = 0;
 	struct ext4_io_end_vec *io_end_vec;
+	int n = 0;
+
+	/*
+	 * We take a single i_conv_pending_ios count for every unwritten io_end
+	 * however each io_vec also needs its count to prevent a neighboring
+	 * io_end_vec zeroing its data. This can't be accurately done during
+	 * submission so do it here.
+	 */
+	list_for_each_entry(io_end_vec, &io_end->list_vec, list)
+		n++;
+
+	if (n > 1)
+		ext4_conv_pending_sum(io_end->inode, n - 1);
 
 	/*
 	 * This is somewhat ugly but the idea is clear: When transaction is
@@ -5241,16 +5310,20 @@ int ext4_convert_unwritten_io_end_vec(handle_t *handle, ext4_io_end_t *io_end)
 	if (handle) {
 		handle = ext4_journal_start_reserved(handle,
 						     EXT4_HT_EXT_CONVERT);
-		if (IS_ERR(handle))
+		if (IS_ERR(handle)) {
+			ext4_conv_pending_sub(io_end->inode, n);
 			return PTR_ERR(handle);
+		}
 	}
 
 	list_for_each_entry(io_end_vec, &io_end->list_vec, list) {
-		ret = ext4_convert_unwritten_extents(handle, io_end->inode,
-						     io_end_vec->offset,
-						     io_end_vec->size, NULL);
-		if (ret)
-			break;
+		if (!ret)
+			ret = ext4_convert_unwritten_extents(handle,
+							     io_end->inode,
+							     io_end_vec->offset,
+							     io_end_vec->size,
+							     NULL, 0);
+		ext4_conv_pending_dec(io_end->inode);
 	}
 
 	if (handle)
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 50d3c92709c8b8..52b1fb99484d21 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -457,7 +457,16 @@ static int ext4_dio_write_end_io(struct kiocb *iocb, ssize_t size,
 							      size);
 	else if (!error && size && flags & IOMAP_DIO_UNWRITTEN)
 		error = ext4_convert_unwritten_extents(NULL, inode, pos, size,
-						       NULL);
+						       NULL, 0);
+
+	/*
+	 * If this dio covered an unwritten extent, we would have incremented
+	 * i_conv_pending_ios in ext4_iomap_next(). Decrement it now that
+	 * the conversion has completed (or failed).
+	 */
+	if (flags & IOMAP_DIO_UNWRITTEN)
+		ext4_conv_pending_dec(inode);
+
 	if (error)
 		return error;
 	/*
@@ -599,6 +608,7 @@ static ssize_t ext4_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)
 	size_t count = iov_iter_count(from);
 	bool extend = false;
 	bool ilock_shared = true;
+	bool conv_pending_inc = false;
 	int dio_flags = 0;
 
 	/*
@@ -664,7 +674,7 @@ static ssize_t ext4_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)
 	}
 
 	ret = iomap_dio_rw(iocb, from, &ext4_iomap_ops, &ext4_dio_write_ops,
-			   dio_flags, NULL, 0);
+			   dio_flags, &conv_pending_inc, 0);
 	if (ret == -ENOTBLK)
 		ret = 0;
 	if (extend) {
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 6ede3644a738be..46f91d6d8ed5ef 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -669,6 +669,107 @@ int ext4_map_query_blocks(handle_t *handle, struct inode *inode,
 	return retval;
 }
 
+static void _ext4_conv_pending_mod(struct inode *inode, int n)
+{
+	struct ext4_inode_info *ei = EXT4_I(inode);
+
+	/*
+	 * Only use the full ordering variant when tracing is needed.
+	 */
+	if (trace_ext4_conv_pending_ios_enabled()) {
+		int new_ios = atomic_add_return(n, &ei->i_conv_pending_ios);
+
+		trace_ext4_conv_pending_ios(inode, n > 0, new_ios - n, new_ios);
+	} else {
+		atomic_add(n, &ei->i_conv_pending_ios);
+	}
+}
+
+/*
+ * In case endio conversion fails due to factors like ENOSPC or ENOMEM, ext4
+ * uses a fallback where we zeroout the unwritten extents instead of splitting.
+ * However, not all unwritten extents can be zeroed out unconditionally as
+ * they might have data underneath which is pending endio conversion. Zeroing
+ * out such an extent can cause silent corruption.
+ *
+ * To fix this we track the IOs which are about to undergo conversion in
+ * ei->i_conv_pending_ios. The zeroout code then uses this counter to
+ * determine if it's safe to zeroout.
+ *
+ * Design Notes:
+ *
+ * **Locking**
+ *
+ * The only mutual exclusion we need is between an IO that is about to be
+ * submitted over an unwritten extent and zeroout. This is done using a
+ * dedicated rwsem, ei->i_conv_pending_sem with the following rules:
+ *
+ * 1. Incrementing the counter must down_read(i_conv_pending_sem).
+ * 2. A zeroout must check the counter and zero data under
+ *    down_write(i_conv_pending_sem)
+ * 3. Decrementing the counter needs no lock. At worst, this makes zeroout bail
+ *    out due to a stale, elevated counter value, which is acceptable
+ * 4. Changes to i_conv_pending_ios should use atomic helpers.
+ *
+ * This design provides us the required exclusion while ensuring that fast paths
+ * don't see any heavy lock contention. Atomic counters help parallel
+ * modifications to be serialized.
+ *
+ * ** Tolerance for false positives **
+ *
+ * We trade false positives for simplicity of implementation because having a
+ * false positive here will just error the endio which is still better than
+ * silently corrupting the data. We can always optimize our tracking to make it
+ * more accurate in the future.
+ */
+void ext4_conv_pending_inc(struct inode *inode)
+{
+	struct ext4_inode_info *ei = EXT4_I(inode);
+
+	down_read(&ei->i_conv_pending_sem);
+	_ext4_conv_pending_mod(inode, 1);
+	up_read(&ei->i_conv_pending_sem);
+}
+
+void ext4_conv_pending_sum(struct inode *inode, int n)
+{
+	struct ext4_inode_info *ei = EXT4_I(inode);
+
+	down_read(&ei->i_conv_pending_sem);
+	_ext4_conv_pending_mod(inode, n);
+	up_read(&ei->i_conv_pending_sem);
+}
+
+/*
+ * Same as ext4_conv_pending_inc() but doesn't sleep if a zeroout is in
+ * progress. Returns -EAGAIN and leaves the counter untouched in that case.
+ */
+int ext4_conv_pending_inc_trylock(struct inode *inode)
+{
+	struct ext4_inode_info *ei = EXT4_I(inode);
+
+	if (!down_read_trylock(&ei->i_conv_pending_sem))
+		return -EAGAIN;
+
+	_ext4_conv_pending_mod(inode, 1);
+	up_read(&ei->i_conv_pending_sem);
+	return 0;
+}
+
+void ext4_conv_pending_dec(struct inode *inode)
+{
+	_ext4_conv_pending_mod(inode, -1);
+}
+
+void ext4_conv_pending_sub(struct inode *inode, int n)
+{
+	struct ext4_inode_info *ei = EXT4_I(inode);
+
+	down_read(&ei->i_conv_pending_sem);
+	_ext4_conv_pending_mod(inode, -n);
+	up_read(&ei->i_conv_pending_sem);
+}
+
 int ext4_map_create_blocks(handle_t *handle, struct inode *inode,
 			   struct ext4_map_blocks *map, int flags)
 {
@@ -3994,7 +4095,47 @@ int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
 	return 0;
 }
 
-static DEFINE_IOMAP_ITER_NEXT(ext4_iomap_next, ext4_iomap_begin);
+static int ext4_iomap_next(const struct iomap_iter *iter, struct iomap *iomap,
+			   struct iomap *srcmap)
+{
+	int ret = iomap_iter_next(iter, iomap, srcmap, ext4_iomap_begin, NULL);
+
+	/*
+	 * For dio, increment i_conv_pending_ios the first time we see an
+	 * unwritten mapping for this IO, so that it cleanly balances with the
+	 * single endio call. We use iter->private to track state to ensure we
+	 * only increment once per dio regardless of how many extents it spans.
+	 * The decrement happens in ext4_dio_write_end_io() if
+	 * IOMAP_DIO_UNWRITTEN is set.
+	 *
+	 * Hack alert: iomap_dio_bio_iter() fails a misaligned mapping with
+	 * -EINVAL before it sets IOMAP_DIO_UNWRITTEN, so endio would skip the
+	 * decrement. Don't increment for such a mapping. The alignment check
+	 * mirrors the one in iomap_dio_bio_iter()
+	 */
+	if (ret > 0 && iter->private &&
+	    (iter->flags & IOMAP_WRITE) && (iomap->type == IOMAP_UNWRITTEN) &&
+	    IS_ALIGNED(iter->pos | iomap_length(iter),
+		       bdev_logical_block_size(iomap->bdev))) {
+		bool *inc_done = (bool *)iter->private;
+
+		if (!*inc_done) {
+			/* NOWAIT dio must not sleep on i_conv_pending_sem */
+			if (iter->flags & IOMAP_NOWAIT) {
+				int err;
+
+				err = ext4_conv_pending_inc_trylock(iter->inode);
+				if (err)
+					return err;
+			} else {
+				ext4_conv_pending_inc(iter->inode);
+			}
+			*inc_done = true;
+		}
+	}
+
+	return ret;
+}
 
 const struct iomap_ops ext4_iomap_ops = {
 	.iomap_next		= ext4_iomap_next,
@@ -4447,6 +4588,9 @@ static int ext4_iomap_writeback_submit(struct iomap_writepage_ctx *wpc,
 	if (ioend->io_bio.bi_end_io)
 		bio_clear_flag(&ioend->io_bio, BIO_COMPLETE_IN_TASK);
 
+	if (ioend->io_flags & IOMAP_IOEND_UNWRITTEN)
+		ext4_conv_pending_inc(inode);
+
 	return iomap_ioend_writeback_submit(wpc, error);
 }
 
diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c
index 734d856a6d4784..e99816017a18da 100644
--- a/fs/ext4/page-io.c
+++ b/fs/ext4/page-io.c
@@ -190,6 +190,12 @@ static int ext4_end_io_end(ext4_io_end_t *io_end)
 
 		if (test_opt(sb, DATA_ERR_ABORT))
 			jbd2_journal_abort(EXT4_SB(sb)->s_journal, ret);
+
+		/*
+		 * Conversion was skipped so drop the count that submission took
+		 */
+		if (io_end->flag & EXT4_IO_END_UNWRITTEN)
+			ext4_conv_pending_dec(inode);
 	} else {
 		ret = ext4_convert_unwritten_io_end_vec(handle, io_end);
 	}
@@ -646,6 +652,21 @@ static void ext4_iomap_finish_ioend(struct iomap_ioend *ioend)
 	int credits;
 	int ret, err;
 
+	/*
+	 * We increment conv_pending for each IO we submit but endio might have
+	 * merged them into a single ioend. The data of all merged sub-ioends is
+	 * covered by a single conversion, so drop their counts keeping just
+	 * the one count for the single ioend we will try to convert.
+	 */
+	if (ioend->io_flags & IOMAP_IOEND_UNWRITTEN) {
+		struct iomap_ioend *sub;
+
+		list_for_each_entry(sub, &ioend->io_list, io_list) {
+			if (sub->io_flags & IOMAP_IOEND_UNWRITTEN)
+				ext4_conv_pending_dec(inode);
+		}
+	}
+
 	ret = blk_status_to_errno(ioend->io_bio.bi_status);
 	if (is_disksize_grow)
 		trace_ext4_iomap_wb_disksize_pending_complete(ioend->io_inode,
@@ -685,7 +706,7 @@ static void ext4_iomap_finish_ioend(struct iomap_ioend *ioend)
 
 	if (ioend->io_flags & IOMAP_IOEND_UNWRITTEN)
 		ret = ext4_convert_unwritten_extents(handle, inode, pos,
-						     size, NULL);
+						     size, NULL, 0);
 
 out_journal:
 	err = ext4_journal_stop(handle);
@@ -698,6 +719,10 @@ static void ext4_iomap_finish_ioend(struct iomap_ioend *ioend)
 			 inode->i_ino, ret);
 	}
 out:
+	/* Drop the count of the head ioend now that conversion is done. */
+	if (ioend->io_flags & IOMAP_IOEND_UNWRITTEN)
+		ext4_conv_pending_dec(inode);
+
 	iomap_finish_ioends(ioend, ret);
 }
 
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 7d8aedfbbb87f1..866a6a70535e9d 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -1429,6 +1429,8 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)
 	ei->i_es_shrink_lblk = 0;
 	ei->i_es_seq = 0;
 	ei->i_reserved_data_blocks = 0;
+	atomic_set(&ei->i_conv_pending_ios, 0);
+	init_rwsem(&ei->i_conv_pending_sem);
 	spin_lock_init(&(ei->i_block_reservation_lock));
 	ext4_init_pending_tree(&ei->i_pending_tree);
 #ifdef CONFIG_QUOTA
@@ -1505,6 +1507,16 @@ static void ext4_destroy_inode(struct inode *inode)
 		ext4_msg(inode->i_sb, KERN_ERR,
 			 "Inode %llu (%p): EXT4_STATE_DISKSIZE_GROW_PENDING not cleared!",
 			 inode->i_ino, EXT4_I(inode));
+
+	if (!(EXT4_SB(inode->i_sb)->s_mount_state & EXT4_ERROR_FS) &&
+	    !ext4_emergency_state(inode->i_sb)) {
+		int pending = atomic_read(&EXT4_I(inode)->i_conv_pending_ios);
+
+		if (WARN_ON_ONCE(pending))
+			ext4_msg(inode->i_sb, KERN_ERR,
+				 "Inode %llu (%p): i_conv_pending_ios (%d) not cleared!",
+				 inode->i_ino, EXT4_I(inode), pending);
+	}
 }
 
 static void ext4_shutdown(struct super_block *sb)
diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h
index 92048da9dae43b..f1754b2e836ca3 100644
--- a/include/trace/events/ext4.h
+++ b/include/trace/events/ext4.h
@@ -43,6 +43,7 @@ struct partial_cluster;
 	{ EXT4_GET_BLOCKS_CONVERT,		"CONVERT" },		\
 	{ EXT4_GET_BLOCKS_METADATA_NOFAIL,	"METADATA_NOFAIL" },	\
 	{ EXT4_GET_BLOCKS_NO_NORMALIZE,		"NO_NORMALIZE" },	\
+	{ EXT4_GET_BLOCKS_NO_CONV_ACC,		"NO_CONV_ACC" },	\
 	{ EXT4_GET_BLOCKS_CONVERT_UNWRITTEN,	"CONVERT_UNWRITTEN" },  \
 	{ EXT4_GET_BLOCKS_ZERO,			"ZERO" },		\
 	{ EXT4_GET_BLOCKS_IO_SUBMIT,		"IO_SUBMIT" },		\
@@ -3366,6 +3367,30 @@ TRACE_EVENT(ext4_block_zero_eof,
 		  __entry->i_disksize, __entry->did_zero, __entry->zero_written)
 );
 
+/* i_conv_pending_ios accounting tracepoint */
+TRACE_EVENT(ext4_conv_pending_ios,
+	TP_PROTO(struct inode *inode, bool add, int old_ios, int new_ios),
+	TP_ARGS(inode, add, old_ios, new_ios),
+	TP_STRUCT__entry(
+		__field(dev_t, dev)
+		__field(u64, ino)
+		__field(bool, add)
+		__field(int, old_ios)
+		__field(int, new_ios)
+	),
+	TP_fast_assign(
+		__entry->dev = inode->i_sb->s_dev;
+		__entry->ino = inode->i_ino;
+		__entry->add = add;
+		__entry->old_ios = old_ios;
+		__entry->new_ios = new_ios;
+	),
+	TP_printk("dev %d:%d ino %llu %s i_conv_pending_ios %d -> %d",
+		  MAJOR(__entry->dev), MINOR(__entry->dev), __entry->ino,
+		  __entry->add ? "inc" : "dec",
+		  __entry->old_ios, __entry->new_ios)
+);
+
 #endif /* _TRACE_EXT4_H */
 
 /* This part must be outside protection */

3/2 2026/11/03 10:33 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 12541
							output: 33
							thoughts: 634
						

Thoughts:
**Analyzing a Recent ext4 Patch for Fuzzing Potential**

Okay, so this patch is touching a significant chunk of the ext4 filesystem code. I see it's modifying a slew of files within `fs/ext4/`, including critical headers like `ext4.h`, and functions related to extents, file handling, and inode operations. Specifically, my focus is drawn to the addition of `i_conv_pending_ios` and `i_conv_pending_sem` within the `ext4_inode_info` struct. This suggests they are tracking in-flight I/Os related to unwritten-to-written conversion, likely to handle zeroout fallbacks more gracefully. Clever.

New functions like `ext4_conv_pending_inc`, `ext4_conv_pending_sum`, and friends are obviously integral to this tracking mechanism. I'm noting the modifications to `ext4_split_extent_zeroout`, `ext4_ext_convert_to_initialized`, and the slew of other functions, which points to significant changes in how unwritten extents are managed, especially during conversion and I/O operations.

Then there are the `WARN_ON_ONCE` assertions. A negative `pending` count in `ext4_conv_pending_zeroout_lock` and a non-zero `pending` count in `ext4_destroy_inode` are both concerning, suggesting potential race conditions or logic errors around the conversion tracking. These are prime targets for fuzzing.

My core triage philosophy dictates that this is prime fuzzing material. `fs/ext4` is a core filesystem, frequently tested by syzkaller. The code touches key areas like extent conversion, zeroout, direct I/O, and buffered writeback, all areas easily triggered by standard syscalls like `mount`, `open`, `write`, `fallocate`, and even `io_uring`. The modifications are in executable code and the assertions further indicate potential vulnerabilities. It's a clear 'WorthFuzzing = true' situation.

I'll need to confirm that `CONFIG_EXT4_FS` is enabled, and then I'll look into `Kconfig` for the specifics.



4/2 2026/11/03 10:34 tool grepper
0m Args:
{
  "Expression": "config EXT4_FS",
  "PathPrefixes": [
    "fs/ext4/Kconfig"
  ]
}

Results:
{
  "Output": "fs/ext4/Kconfig-1-# SPDX-License-Identifier: GPL-2.0-only\nfs/ext4/Kconfig:2:config EXT4_FS\nfs/ext4/Kconfig-3-\ttristate \"The Extended 4 (ext4) filesystem\"\n--\nfs/ext4/Kconfig=35=config EXT4_USE_FOR_EXT2\n--\nfs/ext4/Kconfig-45-\nfs/ext4/Kconfig:46:config EXT4_FS_POSIX_ACL\nfs/ext4/Kconfig-47-\tbool \"Ext4 POSIX Access Control Lists\"\n--\nfs/ext4/Kconfig-55-\nfs/ext4/Kconfig:56:config EXT4_FS_SECURITY\nfs/ext4/Kconfig-57-\tbool \"Ext4 Security Labels\"\n"
}

5/2 2026/11/03 10:34 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 13886
							output: 33
							thoughts: 31
						

Thoughts:
Here's my thought process, as if I were considering this patch:

**Checking the Configuration Landscape for Ext4 Implementation**

Okay, so this patch touches on extents or related features within the ext4 filesystem. Before I dive deep into the code, I need to make sure I'm not missing any critical configuration dependencies. The *fs/ext4/Kconfig* file is the logical place to start. It's the central repository for ext4-specific kernel configuration options. I'll need to scrutinize that Kconfig file thoroughly. I'll be looking for any specific flags or settings that are required for enabling the functionality introduced or modified by this patch – things like enabling extent support directly, or possibly enabling related feature flags like large allocation size or certain block group optimizations. I want to make sure the build environment is set up correctly, that all the necessary prerequisites are in place, and that there are no obvious configuration conflicts. Any related Kconfig options would also be important to understand here. This quick check will give me a valuable high-level understanding of any configuration constraints and let me start with the right mindset.



6/2 2026/11/03 10:34 tool read-file
0m Args:
{
  "File": "fs/ext4/Kconfig",
  "FirstLine": 1,
  "LineCount": 50
}

Results:
{
  "Contents": "   1:\t# SPDX-License-Identifier: GPL-2.0-only\n   2:\tconfig EXT4_FS\n   3:\t\ttristate \"The Extended 4 (ext4) filesystem\"\n   4:\t\tselect BUFFER_HEAD\n   5:\t\tselect JBD2\n   6:\t\tselect CRC16\n   7:\t\tselect CRC32\n   8:\t\tselect FS_IOMAP\n   9:\t\tselect FS_ENCRYPTION_ALGS if FS_ENCRYPTION\n  10:\t\thelp\n  11:\t\t  This is the next generation of the ext3 filesystem.\n  12:\t\n  13:\t\t  Unlike the change from ext2 filesystem to ext3 filesystem,\n  14:\t\t  the on-disk format of ext4 is not forwards compatible with\n  15:\t\t  ext3; it is based on extent maps and it supports 48-bit\n  16:\t\t  physical block numbers.  The ext4 filesystem also supports delayed\n  17:\t\t  allocation, persistent preallocation, high resolution time stamps,\n  18:\t\t  and a number of other features to improve performance and speed\n  19:\t\t  up fsck time.  For more information, please see the web pages at\n  20:\t\t  http://ext4.wiki.kernel.org.\n  21:\t\n  22:\t\t  The ext4 filesystem supports mounting an ext3 filesystem; while there\n  23:\t\t  are some performance gains from the delayed allocation and inode\n  24:\t\t  table readahead, the best performance gains require enabling ext4\n  25:\t\t  features in the filesystem using tune2fs, or formatting a new\n  26:\t\t  filesystem as an ext4 filesystem initially. Without explicit enabling\n  27:\t\t  of ext4 features, the on disk filesystem format stays fully backward\n  28:\t\t  compatible.\n  29:\t\n  30:\t\t  To compile this file system support as a module, choose M here. The\n  31:\t\t  module will be called ext4.\n  32:\t\n  33:\t\t  If unsure, say N.\n  34:\t\n  35:\tconfig EXT4_USE_FOR_EXT2\n  36:\t\tbool \"Use ext4 for ext2 file systems\"\n  37:\t\tdepends on EXT4_FS\n  38:\t\tdepends on EXT2_FS=n\n  39:\t\tdefault y\n  40:\t\thelp\n  41:\t\t  Allow the ext4 file system driver code to be used for ext2\n  42:\t\t  file system mounts.  This allows users to reduce their\n  43:\t\t  compiled kernel size by using one file system driver for\n  44:\t\t  ext2, ext3, and ext4 file systems.\n  45:\t\n  46:\tconfig EXT4_FS_POSIX_ACL\n  47:\t\tbool \"Ext4 POSIX Access Control Lists\"\n  48:\t\tdepends on EXT4_FS\n  49:\t\tselect FS_POSIX_ACL\n  50:\t\thelp\n"
}

7/2 2026/11/03 10:34 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 14914
							output: 31
							thoughts: 75
						

Thoughts:
Here's my take on the thought process:

**Focussing in on Extent Testing for Fuzzing**

Okay, so `extents-test.c` is a KUnit test, meaning `EXT4_KUNIT_TESTS` is defined. But, hang on... we're fuzzing here, and KUnit isn't really relevant for that. Fuzzing's meant to put the code itself through its paces, not necessarily verifying high-level abstractions as a kunit test might. We need to get down to the bare metal here. So, the more appropriate code is the primary focus.

Let's check `fs/ext4/Makefile`. That's where the build system likely defines the compilation rules, linking dependencies, and any relevant flags. If we need to modify build options to control how extent-related code is linked and compiled, this is likely where that happens, as `extents.c`, `inode.c`, `page-io.c`, and `file.c` all seem like the key files to focus on.



8/2 2026/11/03 10:34 tool grepper
0m Args:
{
  "Expression": "extents\\.o",
  "PathPrefixes": [
    "fs/ext4/Makefile"
  ]
}

Results:
{
  "Output": "fs/ext4/Makefile=6=obj-$(CONFIG_EXT4_FS) += ext4.o\nfs/ext4/Makefile-7-\nfs/ext4/Makefile:8:ext4-y\t:= balloc.o bitmap.o block_validity.o dir.o ext4_jbd2.o extents.o \\\nfs/ext4/Makefile-9-\t\textents_status.o file.o fsmap.o fsync.o hash.o ialloc.o \\\n"
}

9/2 2026/11/03 10:34 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 15376
							output: 36
							thoughts: 1249
						

Thoughts:
**Focus Symbol Selection for Ext4 Unwritten Extent Conversion**

Okay, so I'm looking at this patch and my initial thought is, "Right, `CONFIG_EXT4_FS` is the config to enable this." I'll also double-check, are there any other related configs, specifically, does `FS_IOMAP` get automatically selected? Yes, it does. What about `TRACEPOINTS`? Not required unless we're tracing; the code compiles fine without it, as the tracepoint is guarded.

Now, I need to zero in on the appropriate `FocusSymbols`. Let's break down what's been added or modified in this patch. I see:

*   In `fs/ext4/ext4.h`, we've got inlines for setting/clearing the unwritten flag, which are not relevant.
*   In `fs/ext4/inode.c`, we've got a mix: static internal function `_ext4_conv_pending_mod`, and then some externally visible functions like `ext4_conv_pending_inc`, `ext4_conv_pending_sum`, `ext4_conv_pending_inc_trylock`, `ext4_conv_pending_dec`, `ext4_conv_pending_sub` -- all related to pending conversion counters -- plus `ext4_iomap_next`, another internal function. There is `ext4_iomap_writeback_submit`, which has been modified.
*   `fs/ext4/extents.c` has `ext4_conv_pending_zeroout_lock`, `ext4_conv_pending_zeroout_unlock`, internal functions and the modified functions `ext4_split_extent_zeroout`, `ext4_ext_convert_to_initialized`, and `ext4_ext_handle_unwritten_extents`. There's also `ext4_convert_unwritten_extents` and `ext4_convert_unwritten_io_end_vec`, which are extern (non-static) and modified.
*   `fs/ext4/file.c` has modified static functions: `ext4_dio_write_end_io`, `ext4_dio_write_iter`.
*   `fs/ext4/page-io.c` has modified static functions: `ext4_end_io_end`, `ext4_iomap_finish_ioend`.
*   And finally, in `fs/ext4/super.c`, we have `ext4_alloc_inode` (static) and `ext4_destroy_inode` (static, and modified with a `WARN_ON_ONCE`).

Now, according to the guideline in Section 4, I need to extract kernel functions into FocusSymbols: Avoid ubiquitous hot-paths, and target specific feature logic and entrypoints.

So, I need to check: are they non-static, or static symbols in vmlinux? Looking at the list, I see `ext4_convert_unwritten_extents`, `ext4_convert_unwritten_io_end_vec`, `ext4_conv_pending_inc`, `ext4_conv_pending_dec`, `ext4_split_extent_zeroout`, `ext4_dio_write_end_io`, `ext4_iomap_finish_ioend`, `ext4_ext_convert_to_initialized`, and `ext4_destroy_inode` are the candidates.

Wait, should I include `ext4_destroy_inode`? Doesn't every inode destruction call this? When ext4 is unmounted or inodes are evicted, it will be called. It is ubiquitous if ext4 is in use. It is called if any ext4 file is opened/closed. But is it ubiquitous across *all* syscalls? Only when ext4 is used. But wait, this feature is unwritten extent conversion and zeroout!

So, which functions *specifically* exercise this feature? I need to focus on those: `ext4_convert_unwritten_extents`, `ext4_convert_unwritten_io_end_vec`, `ext4_split_extent_zeroout`, `ext4_ext_convert_to_initialized`, `ext4_conv_pending_inc`, `ext4_conv_pending_dec`, `ext4_dio_write_end_io`, and `ext4_iomap_finish_ioend`. I need to now check the callers of `ext4_convert_unwritten_extents`.



10/2 2026/11/03 10:34 tool grepper
0m Args:
{
  "Expression": "ext4_convert_unwritten_extents",
  "PathPrefixes": [
    "fs/ext4/"
  ]
}

Results:
{
  "Output": "fs/ext4/ext4.h=3984=extern long ext4_fallocate(struct file *file, int mode, loff_t offset,\nfs/ext4/ext4.h-3985-\t\t\t  loff_t len);\nfs/ext4/ext4.h:3986:extern int ext4_convert_unwritten_extents(handle_t *handle, struct inode *inode,\nfs/ext4/ext4.h-3987-\t\t\t\t\t  loff_t offset, ssize_t len,\n--\nfs/ext4/ext4.h-3989-\t\t\t\t\t  int extra_flags);\nfs/ext4/ext4.h:3990:extern int ext4_convert_unwritten_extents_atomic(handle_t *handle,\nfs/ext4/ext4.h-3991-\t\t\tstruct inode *inode, loff_t offset, ssize_t len);\n--\nfs/ext4/extents.c=3618=ext4_ext_convert_to_initialized(handle_t *handle, struct inode *inode,\n--\nfs/ext4/extents.c-3872- * being filled will be convert to initialized by the end_io callback function\nfs/ext4/extents.c:3873: * via ext4_convert_unwritten_extents().\nfs/ext4/extents.c-3874- *\n--\nfs/ext4/extents.c=3976=static struct ext4_ext_path *\nfs/ext4/extents.c:3977:ext4_convert_unwritten_extents_endio(handle_t *handle, struct inode *inode,\nfs/ext4/extents.c-3978-\t\t\t\t     struct ext4_map_blocks *map,\n--\nfs/ext4/extents.c=4055=ext4_ext_handle_unwritten_extents(handle_t *handle, struct inode *inode,\n--\nfs/ext4/extents.c-4077-\tif (flags \u0026 EXT4_GET_BLOCKS_CONVERT) {\nfs/ext4/extents.c:4078:\t\tpath = ext4_convert_unwritten_extents_endio(handle, inode,\nfs/ext4/extents.c-4079-\t\t\t\t\t\t\t    map, path, flags);\n--\nfs/ext4/extents.c=4654=static int ext4_alloc_file_blocks(struct file *file, loff_t offset, loff_t len,\n--\nfs/ext4/extents.c-4759-\nfs/ext4/extents.c:4760:\t\t\tret = ext4_convert_unwritten_extents(handle,\nfs/ext4/extents.c-4761-\t\t\t\t\tinode, (loff_t)map.m_lblk \u003c\u003c blkbits,\n--\nfs/ext4/extents.c=5026=long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)\n--\nfs/ext4/extents.c-5130- */\nfs/ext4/extents.c:5131:int ext4_convert_unwritten_extents_atomic(handle_t *handle, struct inode *inode,\nfs/ext4/extents.c-5132-\t\t\t\t\t  loff_t offset, ssize_t len)\n--\nfs/ext4/extents.c-5208- */\nfs/ext4/extents.c:5209:int ext4_convert_unwritten_extents(handle_t *handle, struct inode *inode,\nfs/ext4/extents.c-5210-\t\t\t\t   loff_t offset, ssize_t len,\n--\nfs/ext4/extents.c=5287=int ext4_convert_unwritten_io_end_vec(handle_t *handle, ext4_io_end_t *io_end)\n--\nfs/ext4/extents.c-5320-\t\tif (!ret)\nfs/ext4/extents.c:5321:\t\t\tret = ext4_convert_unwritten_extents(handle,\nfs/ext4/extents.c-5322-\t\t\t\t\t\t\t     io_end-\u003einode,\n--\nfs/ext4/file.c=447=static int ext4_dio_write_end_io(struct kiocb *iocb, ssize_t size,\n--\nfs/ext4/file.c-455-\t\t\t(iocb-\u003eki_flags \u0026 IOCB_ATOMIC))\nfs/ext4/file.c:456:\t\terror = ext4_convert_unwritten_extents_atomic(NULL, inode, pos,\nfs/ext4/file.c-457-\t\t\t\t\t\t\t      size);\nfs/ext4/file.c-458-\telse if (!error \u0026\u0026 size \u0026\u0026 flags \u0026 IOMAP_DIO_UNWRITTEN)\nfs/ext4/file.c:459:\t\terror = ext4_convert_unwritten_extents(NULL, inode, pos, size,\nfs/ext4/file.c-460-\t\t\t\t\t\t       NULL, 0);\n--\nfs/ext4/page-io.c=642=static void ext4_iomap_finish_ioend(struct iomap_ioend *ioend)\n--\nfs/ext4/page-io.c-707-\tif (ioend-\u003eio_flags \u0026 IOMAP_IOEND_UNWRITTEN)\nfs/ext4/page-io.c:708:\t\tret = ext4_convert_unwritten_extents(handle, inode, pos,\nfs/ext4/page-io.c-709-\t\t\t\t\t\t     size, NULL, 0);\n"
}

11/2 2026/11/03 10:34 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 19081
							output: 33
							thoughts: 14
						

Thoughts:
Here's a summary of my thought process, as requested:

**Checking `ext4_conv_pending_inc`**

Okay, let's dive into this. The task at hand is clearly to investigate, understand, and likely troubleshoot something related to `ext4_conv_pending_inc`. My initial thought is to figure out the context. Where does this function fit within the ext4 filesystem structure? Is it related to conversion routines, journaling, metadata updates, or something else entirely? The name itself suggests that it deals with incrementing something related to pending conversions, but I'll need more information to confirm this.

My first line of inquiry will be the source code. I need to understand its parameters, return values, and what it's actually *doing* inside. Is it atomic? Does it take locks? What are its dependencies? I'll probably look for cross-references to see how and where this function is called. Understanding the calling contexts will provide further clues about its purpose and potential areas of concern. Specifically, I'll be looking for potential race conditions, locking issues, or any unexpected behavior that could arise during concurrent access or under heavy load. The goal is to develop a complete picture of its behavior and ensure it's functioning as expected, or to identify potential issues if I'm troubleshooting a specific problem. Knowing the intricacies of this code will also help pinpoint the root cause of any observed issues quickly and efficiently.



12/2 2026/11/03 10:35 tool grepper
0m Args:
{
  "Expression": "ext4_conv_pending_",
  "PathPrefixes": [
    "fs/ext4/"
  ]
}

Results:
{
  "Output": "fs/ext4/ext4.h=1053=struct ext4_inode_info {\n--\nfs/ext4/ext4.h-1247-\t * down_write(i_conv_pending_sem), decrementing needs no lock. See\nfs/ext4/ext4.h:1248:\t * comment above ext4_conv_pending_inc().\nfs/ext4/ext4.h-1249-\t */\n--\nfs/ext4/ext4.h=3998=extern int ext4_map_create_blocks(handle_t *handle, struct inode *inode,\nfs/ext4/ext4.h-3999-\t\t\t\t  struct ext4_map_blocks *map, int flags);\nfs/ext4/ext4.h:4000:extern void ext4_conv_pending_inc(struct inode *inode);\nfs/ext4/ext4.h:4001:extern void ext4_conv_pending_sum(struct inode *inode, int n);\nfs/ext4/ext4.h:4002:extern int ext4_conv_pending_inc_trylock(struct inode *inode);\nfs/ext4/ext4.h:4003:extern void ext4_conv_pending_dec(struct inode *inode);\nfs/ext4/ext4.h:4004:extern void ext4_conv_pending_sub(struct inode *inode, int n);\nfs/ext4/ext4.h-4005-extern int ext4_ext_calc_credits_for_single_extent(struct inode *inode,\n--\nfs/ext4/ext4.h=4114=static inline void ext4_set_io_unwritten_flag(struct ext4_io_end *io_end)\n--\nfs/ext4/ext4.h-4117-\t\tio_end-\u003eflag |= EXT4_IO_END_UNWRITTEN;\nfs/ext4/ext4.h:4118:\t\text4_conv_pending_inc(io_end-\u003einode);\nfs/ext4/ext4.h-4119-\t}\n--\nfs/ext4/extents.c=3199=static struct ext4_ext_path *ext4_split_extent_at(handle_t *handle,\n--\nfs/ext4/extents.c-3316- * else drops the lock and returns false. The caller must call\nfs/ext4/extents.c:3317: * ext4_conv_pending_zeroout_unlock() once the zeroout IO is complete.\nfs/ext4/extents.c-3318- *\n--\nfs/ext4/extents.c-3322- *\nfs/ext4/extents.c:3323: * Refer to comment above ext4_conv_pending_inc() for details.\nfs/ext4/extents.c-3324- */\nfs/ext4/extents.c:3325:static bool ext4_conv_pending_zeroout_lock(struct inode *inode, int flags)\nfs/ext4/extents.c-3326-{\n--\nfs/ext4/extents.c-3343-\nfs/ext4/extents.c:3344:static void ext4_conv_pending_zeroout_unlock(struct inode *inode)\nfs/ext4/extents.c-3345-{\n--\nfs/ext4/extents.c=3349=static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,\n--\nfs/ext4/extents.c-3365-\nfs/ext4/extents.c:3366:\tif (!ext4_conv_pending_zeroout_lock(inode, flags))\nfs/ext4/extents.c-3367-\t\treturn -EINVAL;\n--\nfs/ext4/extents.c-3439-\t */\nfs/ext4/extents.c:3440:\text4_conv_pending_zeroout_unlock(inode);\nfs/ext4/extents.c-3441-\n--\nfs/ext4/extents.c-3454-out_unlock:\nfs/ext4/extents.c:3455:\text4_conv_pending_zeroout_unlock(inode);\nfs/ext4/extents.c-3456-\treturn err;\n--\nfs/ext4/extents.c=3618=ext4_ext_convert_to_initialized(handle_t *handle, struct inode *inode,\n--\nfs/ext4/extents.c-3799-\tif (max_zeroout \u0026\u0026 (*allocated \u003e split_map.m_len) \u0026\u0026\nfs/ext4/extents.c:3800:\t    ext4_conv_pending_zeroout_lock(inode, flags)) {\nfs/ext4/extents.c-3801-\t\tif (*allocated \u003c= max_zeroout) {\n--\nfs/ext4/extents.c-3834-zeroout_unlock:\nfs/ext4/extents.c:3835:\t\text4_conv_pending_zeroout_unlock(inode);\nfs/ext4/extents.c-3836-\t}\n--\nfs/ext4/extents.c=5287=int ext4_convert_unwritten_io_end_vec(handle_t *handle, ext4_io_end_t *io_end)\n--\nfs/ext4/extents.c-5302-\tif (n \u003e 1)\nfs/ext4/extents.c:5303:\t\text4_conv_pending_sum(io_end-\u003einode, n - 1);\nfs/ext4/extents.c-5304-\n--\nfs/ext4/extents.c-5313-\t\tif (IS_ERR(handle)) {\nfs/ext4/extents.c:5314:\t\t\text4_conv_pending_sub(io_end-\u003einode, n);\nfs/ext4/extents.c-5315-\t\t\treturn PTR_ERR(handle);\n--\nfs/ext4/extents.c-5325-\t\t\t\t\t\t\t     NULL, 0);\nfs/ext4/extents.c:5326:\t\text4_conv_pending_dec(io_end-\u003einode);\nfs/ext4/extents.c-5327-\t}\n--\nfs/ext4/file.c=447=static int ext4_dio_write_end_io(struct kiocb *iocb, ssize_t size,\n--\nfs/ext4/file.c-467-\tif (flags \u0026 IOMAP_DIO_UNWRITTEN)\nfs/ext4/file.c:468:\t\text4_conv_pending_dec(inode);\nfs/ext4/file.c-469-\n--\nfs/ext4/inode.c=625=int ext4_map_query_blocks(handle_t *handle, struct inode *inode,\n--\nfs/ext4/inode.c-671-\nfs/ext4/inode.c:672:static void _ext4_conv_pending_mod(struct inode *inode, int n)\nfs/ext4/inode.c-673-{\n--\nfs/ext4/inode.c-678-\t */\nfs/ext4/inode.c:679:\tif (trace_ext4_conv_pending_ios_enabled()) {\nfs/ext4/inode.c-680-\t\tint new_ios = atomic_add_return(n, \u0026ei-\u003ei_conv_pending_ios);\nfs/ext4/inode.c-681-\nfs/ext4/inode.c:682:\t\ttrace_ext4_conv_pending_ios(inode, n \u003e 0, new_ios - n, new_ios);\nfs/ext4/inode.c-683-\t} else {\n--\nfs/ext4/inode.c-724- */\nfs/ext4/inode.c:725:void ext4_conv_pending_inc(struct inode *inode)\nfs/ext4/inode.c-726-{\n--\nfs/ext4/inode.c-729-\tdown_read(\u0026ei-\u003ei_conv_pending_sem);\nfs/ext4/inode.c:730:\t_ext4_conv_pending_mod(inode, 1);\nfs/ext4/inode.c-731-\tup_read(\u0026ei-\u003ei_conv_pending_sem);\n--\nfs/ext4/inode.c-733-\nfs/ext4/inode.c:734:void ext4_conv_pending_sum(struct inode *inode, int n)\nfs/ext4/inode.c-735-{\n--\nfs/ext4/inode.c-738-\tdown_read(\u0026ei-\u003ei_conv_pending_sem);\nfs/ext4/inode.c:739:\t_ext4_conv_pending_mod(inode, n);\nfs/ext4/inode.c-740-\tup_read(\u0026ei-\u003ei_conv_pending_sem);\n--\nfs/ext4/inode.c-743-/*\nfs/ext4/inode.c:744: * Same as ext4_conv_pending_inc() but doesn't sleep if a zeroout is in\nfs/ext4/inode.c-745- * progress. Returns -EAGAIN and leaves the counter untouched in that case.\nfs/ext4/inode.c-746- */\nfs/ext4/inode.c:747:int ext4_conv_pending_inc_trylock(struct inode *inode)\nfs/ext4/inode.c-748-{\n--\nfs/ext4/inode.c-753-\nfs/ext4/inode.c:754:\t_ext4_conv_pending_mod(inode, 1);\nfs/ext4/inode.c-755-\tup_read(\u0026ei-\u003ei_conv_pending_sem);\n--\nfs/ext4/inode.c-758-\nfs/ext4/inode.c:759:void ext4_conv_pending_dec(struct inode *inode)\nfs/ext4/inode.c-760-{\nfs/ext4/inode.c:761:\t_ext4_conv_pending_mod(inode, -1);\nfs/ext4/inode.c-762-}\nfs/ext4/inode.c-763-\nfs/ext4/inode.c:764:void ext4_conv_pending_sub(struct inode *inode, int n)\nfs/ext4/inode.c-765-{\n--\nfs/ext4/inode.c-768-\tdown_read(\u0026ei-\u003ei_conv_pending_sem);\nfs/ext4/inode.c:769:\t_ext4_conv_pending_mod(inode, -n);\nfs/ext4/inode.c-770-\tup_read(\u0026ei-\u003ei_conv_pending_sem);\n--\nfs/ext4/inode.c=4098=static int ext4_iomap_next(const struct iomap_iter *iter, struct iomap *iomap,\n--\nfs/ext4/inode.c-4126-\nfs/ext4/inode.c:4127:\t\t\t\terr = ext4_conv_pending_inc_trylock(iter-\u003einode);\nfs/ext4/inode.c-4128-\t\t\t\tif (err)\n--\nfs/ext4/inode.c-4130-\t\t\t} else {\nfs/ext4/inode.c:4131:\t\t\t\text4_conv_pending_inc(iter-\u003einode);\nfs/ext4/inode.c-4132-\t\t\t}\n--\nfs/ext4/inode.c=4543=static int ext4_iomap_writeback_submit(struct iomap_writepage_ctx *wpc,\n--\nfs/ext4/inode.c-4591-\tif (ioend-\u003eio_flags \u0026 IOMAP_IOEND_UNWRITTEN)\nfs/ext4/inode.c:4592:\t\text4_conv_pending_inc(inode);\nfs/ext4/inode.c-4593-\n--\nfs/ext4/page-io.c=170=static int ext4_end_io_end(ext4_io_end_t *io_end)\n--\nfs/ext4/page-io.c-197-\t\tif (io_end-\u003eflag \u0026 EXT4_IO_END_UNWRITTEN)\nfs/ext4/page-io.c:198:\t\t\text4_conv_pending_dec(inode);\nfs/ext4/page-io.c-199-\t} else {\n--\nfs/ext4/page-io.c=642=static void ext4_iomap_finish_ioend(struct iomap_ioend *ioend)\n--\nfs/ext4/page-io.c-665-\t\t\tif (sub-\u003eio_flags \u0026 IOMAP_IOEND_UNWRITTEN)\nfs/ext4/page-io.c:666:\t\t\t\text4_conv_pending_dec(inode);\nfs/ext4/page-io.c-667-\t\t}\n--\nfs/ext4/page-io.c-723-\tif (ioend-\u003eio_flags \u0026 IOMAP_IOEND_UNWRITTEN)\nfs/ext4/page-io.c:724:\t\text4_conv_pending_dec(inode);\nfs/ext4/page-io.c-725-\n"
}

13/2 2026/11/03 10:35 llm patch-evaluator
1m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 22842
							output: 256
							thoughts: 1177
						

Thoughts:
**Fuzzing Target: Ext4 Unwritten Extent Conversion and Synchronization**

Okay, let's break this down. My analysis indicates a compelling case for fuzzing a specific area within the ext4 filesystem: the handling of unwritten extent conversions, particularly concerning race conditions and synchronization mechanisms. I've been reviewing the modifications made and identified the critical functions to target.

First, I need to pinpoint the key functions involved. Based on my review, the following functions have been modified or are new: `ext4_convert_unwritten_extents`, `ext4_convert_unwritten_io_end_vec`, `ext4_conv_pending_inc`, `ext4_conv_pending_dec`, `ext4_split_extent_zeroout`, `ext4_ext_convert_to_initialized`, `ext4_dio_write_end_io`, and `ext4_iomap_finish_ioend`. I verified their scope. I made sure to note which are extern/static and that they are all important.

Now, why these functions? They are directly related to the core logic for converting unwritten extents, a process that touches direct I/O writes, buffered writeback, and zeroout fallback. This makes these prime targets for race conditions. The commit introduces atomic tracking (`i_conv_pending_ios`) and synchronization (`i_conv_pending_sem`) to prevent silent data corruption, which signals a critical area worth further scrutiny. Additionally, there are assertions (`WARN_ON_ONCE`) designed to catch potential issues during runtime, increasing the likelihood of uncovering problems through fuzzing.

To ensure the fuzzing environment is appropriately configured, I verified that the EXT4_FS configuration option is enabled and that it doesn't have any unusual dependencies that could complicate the testing.

The functions are called during a variety of common filesystem operations, which adds to the fuzzing case.

Therefore, the fuzzing rationale is clear: the changes involve intricate synchronization and race condition handling between various I/O paths (direct I/O, buffered writeback, and zeroout fallback) concerning unwritten extent conversions. This is an ideal scenario for fuzzing due to the potential for data corruption and the introduction of new synchronization primitives. This is something that syzkaller can easily and effectively stress. The direct reachability through common filesystem operations and the added runtime assertions further solidify this as a high-value target.

So, here's my recommended set-results:

*   `WorthFuzzing`: `true`
*   `Reasoning`: Ext4 filesystem modifications dealing with race condition handling between unwritten extent conversions, direct I/O, buffered writeback, and zeroout fallback. Adds atomic tracking (`i_conv_pending_ios`) and synchronization (`i_conv_pending_sem`) to prevent silent data corruption when zeroing out unwritten extents. Adds runtime assertions (`WARN_ON_ONCE(pending < 0)` and `WARN_ON_ONCE(pending)` in `ext4_destroy_inode`). Directly reachable through normal filesystem I/O operations (fallocate, unwritten extent direct I/O, async writeback, etc.).
*   `FocusSymbols`: `ext4_convert_unwritten_extents`, `ext4_convert_unwritten_io_end_vec`, `ext4_conv_pending_inc`, `ext4_conv_pending_dec`, `ext4_split_extent_zeroout`, `ext4_ext_convert_to_initialized`, `ext4_dio_write_end_io`, `ext4_iomap_finish_ioend`
*   `EnableConfigs`: `EXT4_FS`

This should provide syzkaller with the necessary information to effectively target this crucial area of the ext4 filesystem.



14/2 2026/11/03 10:36 tool set-results
0m Args:
{
  "EnableConfigs": [
    "EXT4_FS"
  ],
  "FocusSymbols": [
    "ext4_convert_unwritten_extents",
    "ext4_convert_unwritten_io_end_vec",
    "ext4_conv_pending_inc",
    "ext4_conv_pending_dec",
    "ext4_split_extent_zeroout",
    "ext4_ext_convert_to_initialized",
    "ext4_dio_write_end_io",
    "ext4_iomap_finish_ioend"
  ],
  "Reasoning": "The patch modifies ext4 core extent conversion and zeroout handling by introducing an in-flight IO tracking mechanism (i_conv_pending_ios counter and i_conv_pending_sem rwsem) to avoid data corruption when zeroing out unwritten extents during fallback. This changes direct I/O submission/completion, buffered writeback finish, and extent splitting/conversion paths, and adds runtime assertions (WARN_ON_ONCE). These paths are reachable via standard filesystem operations (fallocate, direct I/O writes to unwritten extents, buffered writeback).",
  "WorthFuzzing": true
}

Results:
{
  "EnableConfigs": [
    "EXT4_FS"
  ],
  "FocusSymbols": [
    "ext4_convert_unwritten_extents",
    "ext4_convert_unwritten_io_end_vec",
    "ext4_conv_pending_inc",
    "ext4_conv_pending_dec",
    "ext4_split_extent_zeroout",
    "ext4_ext_convert_to_initialized",
    "ext4_dio_write_end_io",
    "ext4_iomap_finish_ioend"
  ],
  "Reasoning": "The patch modifies ext4 core extent conversion and zeroout handling by introducing an in-flight IO tracking mechanism (i_conv_pending_ios counter and i_conv_pending_sem rwsem) to avoid data corruption when zeroing out unwritten extents during fallback. This changes direct I/O submission/completion, buffered writeback finish, and extent splitting/conversion paths, and adds runtime assertions (WARN_ON_ONCE). These paths are reachable via standard filesystem operations (fallocate, direct I/O writes to unwritten extents, buffered writeback).",
  "WorthFuzzing": true
}

15/1 2026/11/03 10:36 action If
7m Args:
{
  "WorthFuzzing": true
}

Results:
null

16/2 2026/11/03 10:36 agent kmsan-evaluator
7m Model:
core

Args:
null

Results:
{
  "KMSANReasoning": "The patch introduces an in-flight IO tracking mechanism (using `i_conv_pending_ios` and `i_conv_pending_sem` on `struct ext4_inode_info`) to prevent ext4's fallback zeroout logic from racing with and overwriting data from concurrent IOs pending unwritten-to-written extent conversion.\n\nAnalysis of memory safety and sanitizer applicability:\n1. No uninitialized memory or info-leaks:\n   - All newly added struct members (`ei-\u003ei_conv_pending_ios`, `ei-\u003ei_conv_pending_sem`) are properly initialized in `ext4_alloc_inode()` and `extents_kunit_init()`.\n   - Local variables (e.g., `bool conv_pending_inc = false;` in `ext4_dio_write_iter()`, `int n = 0;` in `ext4_convert_unwritten_io_end_vec()`, `int err = 0;` in `ext4_split_extent_zeroout()`) are explicitly initialized before use.\n   - No kernel data structures or uninitialized memory are copied or exposed to userspace.\n2. Failure modes:\n   - Potential risks in this patch are synchronization issues, counter imbalance (e.g. leaking counts causing the WARN_ON_ONCE in `ext4_destroy_inode`), lock contention or deadlocks on `i_conv_pending_sem`, and filesystem error returns.\n   - Deadlocks and locking bugs are detected by LOCKDEP. Memory lifecycle issues (use-after-free, out-of-bounds) are detected by KASAN.\n   - KMSAN is not applicable as there are no uninitialized heap/stack memory reads or kernel-to-user info-leak vectors.",
  "NeedsKMSAN": false
}

Instruction:
You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.

CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
  a comprehensive suite of debugging tools and sanitizers, including KASAN
  (out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
  (locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
  or page allocations) and kernel-to-user memory info-leaks.

Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.

Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.

Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
   attributes, ioctl output arguments, socket options, or BPF buffers) where fields
   or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
   or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
   could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
   uninitialized bytes of existing buffers.

Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
  dereferences, locking deadlocks, or use-after-free bugs (these are already caught
  by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
  or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.

Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
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 1851ff6f52e314e00cbb635ae636c24fdb4f5632
Author: syz-cluster <triage@syzkaller.com>
Date:   Tue Nov 3 10:33:31 2026 +0000

    syz-cluster: applied patch under review

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 8d3af062a83068..44cd9f12d35043 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -736,6 +736,11 @@ enum {
  * Look EXT4_MAP_QUERY_LAST_IN_LEAF.
  */
 #define EXT4_GET_BLOCKS_QUERY_LAST_IN_LEAF	0x1000
+/*
+ * Caller may convert an unwritten extent (possibly zeroing parts of it)
+ * without elevating the i_conv_pending_ios count to account for itself.
+ */
+#define EXT4_GET_BLOCKS_NO_CONV_ACC		0x2000
 
 /*
  * The bit position of these flags must not overlap with any of the
@@ -1235,6 +1240,15 @@ struct ext4_inode_info {
 #ifdef CONFIG_FS_ENCRYPTION
 	struct fscrypt_inode_info *i_crypt_info;
 #endif
+	/*
+	 * Number of in-flight IOs pending unwritten->written conversion. Used
+	 * by the zeroout fallback to avoid zeroing out data of such IOs.
+	 * Incrementing needs down_read(i_conv_pending_sem), zeroout needs
+	 * down_write(i_conv_pending_sem), decrementing needs no lock. See
+	 * comment above ext4_conv_pending_inc().
+	 */
+	atomic_t i_conv_pending_ios;
+	struct rw_semaphore i_conv_pending_sem;
 };
 
 /*
@@ -3971,7 +3985,8 @@ extern long ext4_fallocate(struct file *file, int mode, loff_t offset,
 			  loff_t len);
 extern int ext4_convert_unwritten_extents(handle_t *handle, struct inode *inode,
 					  loff_t offset, ssize_t len,
-					  ext4_lblk_t *converted);
+					  ext4_lblk_t *converted,
+					  int extra_flags);
 extern int ext4_convert_unwritten_extents_atomic(handle_t *handle,
 			struct inode *inode, loff_t offset, ssize_t len);
 extern int ext4_convert_unwritten_io_end_vec(handle_t *handle,
@@ -3982,6 +3997,11 @@ extern int ext4_map_query_blocks(handle_t *handle, struct inode *inode,
 				  struct ext4_map_blocks *map, int flags);
 extern int ext4_map_create_blocks(handle_t *handle, struct inode *inode,
 				  struct ext4_map_blocks *map, int flags);
+extern void ext4_conv_pending_inc(struct inode *inode);
+extern void ext4_conv_pending_sum(struct inode *inode, int n);
+extern int ext4_conv_pending_inc_trylock(struct inode *inode);
+extern void ext4_conv_pending_dec(struct inode *inode);
+extern void ext4_conv_pending_sub(struct inode *inode, int n);
 extern int ext4_ext_calc_credits_for_single_extent(struct inode *inode,
 						   int num,
 						   struct ext4_ext_path *path);
@@ -4093,14 +4113,15 @@ extern int ext4_resize_end(struct super_block *sb, bool update_backups);
 
 static inline void ext4_set_io_unwritten_flag(struct ext4_io_end *io_end)
 {
-	if (!(io_end->flag & EXT4_IO_END_UNWRITTEN))
+	if (!(io_end->flag & EXT4_IO_END_UNWRITTEN)) {
 		io_end->flag |= EXT4_IO_END_UNWRITTEN;
+		ext4_conv_pending_inc(io_end->inode);
+	}
 }
 
 static inline void ext4_clear_io_unwritten_flag(ext4_io_end_t *io_end)
 {
-	if (io_end->flag & EXT4_IO_END_UNWRITTEN)
-		io_end->flag &= ~EXT4_IO_END_UNWRITTEN;
+	io_end->flag &= ~EXT4_IO_END_UNWRITTEN;
 }
 
 extern const struct iomap_ops ext4_iomap_ops;
diff --git a/fs/ext4/extents-test.c b/fs/ext4/extents-test.c
index c3836ecb89f9cc..4d63c20501355b 100644
--- a/fs/ext4/extents-test.c
+++ b/fs/ext4/extents-test.c
@@ -271,6 +271,8 @@ static int extents_kunit_init(struct kunit *test)
 
 	ext4_es_init_tree(&ei->i_es_tree);
 	rwlock_init(&ei->i_es_lock);
+	atomic_set(&ei->i_conv_pending_ios, 0);
+	init_rwsem(&ei->i_conv_pending_sem);
 	INIT_LIST_HEAD(&ei->i_es_list);
 	ei->i_es_all_nr = 0;
 	ei->i_es_shk_nr = 0;
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 7193429a05e1f4..3150754b976617 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -3311,6 +3311,41 @@ static struct ext4_ext_path *ext4_split_extent_at(handle_t *handle,
 	return path;
 }
 
+/*
+ * Returns true with i_conv_pending_sem held for write if it's safe to zeroout,
+ * else drops the lock and returns false. The caller must call
+ * ext4_conv_pending_zeroout_unlock() once the zeroout IO is complete.
+ *
+ * Callers are expected to have elevated i_conv_pending_ios to account for
+ * themselves, so a count of 1 is their own. Callers that haven't must pass
+ * EXT4_GET_BLOCKS_NO_CONV_ACC in flags, in which case any count is another IO.
+ *
+ * Refer to comment above ext4_conv_pending_inc() for details.
+ */
+static bool ext4_conv_pending_zeroout_lock(struct inode *inode, int flags)
+{
+	struct ext4_inode_info *ei = EXT4_I(inode);
+	int pending, thresh;
+
+	thresh = (flags & EXT4_GET_BLOCKS_NO_CONV_ACC) ? 0 : 1;
+
+	down_write(&ei->i_conv_pending_sem);
+	pending = atomic_read(&ei->i_conv_pending_ios);
+
+	WARN_ON_ONCE(pending < 0);
+	if (pending > thresh || pending < 0) {
+		up_write(&ei->i_conv_pending_sem);
+		return false;
+	}
+
+	return true;
+}
+
+static void ext4_conv_pending_zeroout_unlock(struct inode *inode)
+{
+	up_write(&EXT4_I(inode)->i_conv_pending_sem);
+}
+
 static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,
 				     struct ext4_ext_path *path,
 				     struct ext4_map_blocks *map, int flags)
@@ -3328,6 +3363,9 @@ static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,
 	ee_len = ext4_ext_get_actual_len(ex);
 	is_unwrit = ext4_ext_is_unwritten(ex);
 
+	if (!ext4_conv_pending_zeroout_lock(inode, flags))
+		return -EINVAL;
+
 	if (flags & EXT4_GET_BLOCKS_CONVERT) {
 		/*
 		 * EXT4_GET_BLOCKS_CONVERT: Caller wants the range specified by
@@ -3338,9 +3376,11 @@ static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,
 		loff_t map_end = (loff_t) map->m_lblk + map->m_len;
 		loff_t ex_end = (loff_t) ee_block + ee_len;
 
-		if (!is_unwrit)
+		if (!is_unwrit) {
 			/* Shouldn't happen. Just exit */
-			return -EINVAL;
+			err = -EINVAL;
+			goto out_unlock;
+		}
 
 		/* zeroout left */
 		if (map->m_lblk > ee_block) {
@@ -3350,7 +3390,7 @@ static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,
 			err = ext4_issue_zeroout(inode, lblk, pblk, len);
 			if (err)
 				/* ZEROOUT failed, just return original error */
-				return err;
+				goto out_unlock;
 		}
 
 		/* zeroout right */
@@ -3361,7 +3401,7 @@ static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,
 			err = ext4_issue_zeroout(inode, lblk, pblk, len);
 			if (err)
 				/* ZEROOUT failed, just return original error */
-				return err;
+				goto out_unlock;
 		}
 	} else if (flags & EXT4_GET_BLOCKS_CONVERT_UNWRITTEN) {
 		/*
@@ -3370,9 +3410,11 @@ static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,
 		 * Zeroout the map range leaving rest as it is.
 		 */
 
-		if (is_unwrit)
+		if (is_unwrit) {
 			/* Shouldn't happen. Just exit */
-			return -EINVAL;
+			err = -EINVAL;
+			goto out_unlock;
+		}
 
 		lblk = map->m_lblk;
 		len = map->m_len;
@@ -3380,16 +3422,23 @@ static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,
 		err = ext4_issue_zeroout(inode, lblk, pblk, len);
 		if (err)
 			/* ZEROOUT failed, just return original error */
-			return err;
+			goto out_unlock;
 	} else {
 		/*
 		 * We no longer perform unwritten to unwritten splits in IO paths.
 		 * Hence this should not happen.
 		 */
 		WARN_ON_ONCE(true);
-		return -EINVAL;
+		err = -EINVAL;
+		goto out_unlock;
 	}
 
+	/*
+	 * The zeroout IO is done, no need to hold off new unwritten IOs while we
+	 * update the extent tree.
+	 */
+	ext4_conv_pending_zeroout_unlock(inode);
+
 	err = ext4_ext_get_access(handle, inode, path + depth);
 	if (err)
 		return err;
@@ -3401,6 +3450,10 @@ static int ext4_split_extent_zeroout(handle_t *handle, struct inode *inode,
 		return err;
 
 	return 0;
+
+out_unlock:
+	ext4_conv_pending_zeroout_unlock(inode);
+	return err;
 }
 
 /*
@@ -3743,7 +3796,8 @@ ext4_ext_convert_to_initialized(handle_t *handle, struct inode *inode,
 	split_map.m_lblk = map->m_lblk;
 	split_map.m_len = map->m_len;
 
-	if (max_zeroout && (*allocated > split_map.m_len)) {
+	if (max_zeroout && (*allocated > split_map.m_len) &&
+	    ext4_conv_pending_zeroout_lock(inode, flags)) {
 		if (*allocated <= max_zeroout) {
 			/* case 3 or 5 */
 			zero_ex1.ee_block =
@@ -3756,7 +3810,7 @@ ext4_ext_convert_to_initialized(handle_t *handle, struct inode *inode,
 				split_map.m_len - ee_block);
 			err = ext4_ext_zeroout(inode, &zero_ex1);
 			if (err)
-				goto fallback;
+				goto zeroout_unlock;
 			split_map.m_len = *allocated;
 		}
 		if (split_map.m_lblk - ee_block + split_map.m_len <
@@ -3770,16 +3824,17 @@ ext4_ext_convert_to_initialized(handle_t *handle, struct inode *inode,
 						      ext4_ext_pblock(ex));
 				err = ext4_ext_zeroout(inode, &zero_ex2);
 				if (err)
-					goto fallback;
+					goto zeroout_unlock;
 			}
 
 			split_map.m_len += split_map.m_lblk - ee_block;
 			split_map.m_lblk = ee_block;
 			*allocated = map->m_len;
 		}
+zeroout_unlock:
+		ext4_conv_pending_zeroout_unlock(inode);
 	}
 
-fallback:
 	path = ext4_split_convert_extents(handle, inode, &split_map, path,
 					  flags | EXT4_GET_BLOCKS_CONVERT, NULL);
 	if (IS_ERR(path))
@@ -4056,7 +4111,8 @@ ext4_ext_handle_unwritten_extents(handle_t *handle, struct inode *inode,
 	 * discovered unwritten extent to written.
 	 */
 	path = ext4_ext_convert_to_initialized(handle, inode, map, path,
-					       flags, allocated);
+					       flags | EXT4_GET_BLOCKS_NO_CONV_ACC,
+					       allocated);
 	if (IS_ERR(path))
 		return path;
 	ext4_update_inode_fsync_trans(handle, inode, 1);
@@ -4704,7 +4760,7 @@ static int ext4_alloc_file_blocks(struct file *file, loff_t offset, loff_t len,
 			ret = ext4_convert_unwritten_extents(handle,
 					inode, (loff_t)map.m_lblk << blkbits,
 					(loff_t)map.m_len << blkbits,
-					&converted);
+					&converted, EXT4_GET_BLOCKS_NO_CONV_ACC);
 			if (ret)
 				map.m_len = converted;
 
@@ -5152,7 +5208,7 @@ int ext4_convert_unwritten_extents_atomic(handle_t *handle, struct inode *inode,
  */
 int ext4_convert_unwritten_extents(handle_t *handle, struct inode *inode,
 				   loff_t offset, ssize_t len,
-				   ext4_lblk_t *converted)
+				   ext4_lblk_t *converted, int extra_flags)
 {
 	ext4_lblk_t max_blocks, conv_blocks = 0;
 	int ret = 0, ret2 = 0, ret3 = 0;
@@ -5195,7 +5251,7 @@ int ext4_convert_unwritten_extents(handle_t *handle, struct inode *inode,
 		 */
 		ret = ext4_map_blocks(handle, inode, &map,
 				      EXT4_GET_BLOCKS_IO_CONVERT_EXT |
-				      EXT4_EX_NOCACHE);
+				      EXT4_EX_NOCACHE | extra_flags);
 		if (ret <= 0) {
 			ext4_warning(inode->i_sb,
 				     "inode #%llu: block %u: len %u: ext4_map_blocks returned %d",
@@ -5232,6 +5288,19 @@ int ext4_convert_unwritten_io_end_vec(handle_t *handle, ext4_io_end_t *io_end)
 {
 	int ret = 0, err = 0;
 	struct ext4_io_end_vec *io_end_vec;
+	int n = 0;
+
+	/*
+	 * We take a single i_conv_pending_ios count for every unwritten io_end
+	 * however each io_vec also needs its count to prevent a neighboring
+	 * io_end_vec zeroing its data. This can't be accurately done during
+	 * submission so do it here.
+	 */
+	list_for_each_entry(io_end_vec, &io_end->list_vec, list)
+		n++;
+
+	if (n > 1)
+		ext4_conv_pending_sum(io_end->inode, n - 1);
 
 	/*
 	 * This is somewhat ugly but the idea is clear: When transaction is
@@ -5241,16 +5310,20 @@ int ext4_convert_unwritten_io_end_vec(handle_t *handle, ext4_io_end_t *io_end)
 	if (handle) {
 		handle = ext4_journal_start_reserved(handle,
 						     EXT4_HT_EXT_CONVERT);
-		if (IS_ERR(handle))
+		if (IS_ERR(handle)) {
+			ext4_conv_pending_sub(io_end->inode, n);
 			return PTR_ERR(handle);
+		}
 	}
 
 	list_for_each_entry(io_end_vec, &io_end->list_vec, list) {
-		ret = ext4_convert_unwritten_extents(handle, io_end->inode,
-						     io_end_vec->offset,
-						     io_end_vec->size, NULL);
-		if (ret)
-			break;
+		if (!ret)
+			ret = ext4_convert_unwritten_extents(handle,
+							     io_end->inode,
+							     io_end_vec->offset,
+							     io_end_vec->size,
+							     NULL, 0);
+		ext4_conv_pending_dec(io_end->inode);
 	}
 
 	if (handle)
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 50d3c92709c8b8..52b1fb99484d21 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -457,7 +457,16 @@ static int ext4_dio_write_end_io(struct kiocb *iocb, ssize_t size,
 							      size);
 	else if (!error && size && flags & IOMAP_DIO_UNWRITTEN)
 		error = ext4_convert_unwritten_extents(NULL, inode, pos, size,
-						       NULL);
+						       NULL, 0);
+
+	/*
+	 * If this dio covered an unwritten extent, we would have incremented
+	 * i_conv_pending_ios in ext4_iomap_next(). Decrement it now that
+	 * the conversion has completed (or failed).
+	 */
+	if (flags & IOMAP_DIO_UNWRITTEN)
+		ext4_conv_pending_dec(inode);
+
 	if (error)
 		return error;
 	/*
@@ -599,6 +608,7 @@ static ssize_t ext4_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)
 	size_t count = iov_iter_count(from);
 	bool extend = false;
 	bool ilock_shared = true;
+	bool conv_pending_inc = false;
 	int dio_flags = 0;
 
 	/*
@@ -664,7 +674,7 @@ static ssize_t ext4_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)
 	}
 
 	ret = iomap_dio_rw(iocb, from, &ext4_iomap_ops, &ext4_dio_write_ops,
-			   dio_flags, NULL, 0);
+			   dio_flags, &conv_pending_inc, 0);
 	if (ret == -ENOTBLK)
 		ret = 0;
 	if (extend) {
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 6ede3644a738be..46f91d6d8ed5ef 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -669,6 +669,107 @@ int ext4_map_query_blocks(handle_t *handle, struct inode *inode,
 	return retval;
 }
 
+static void _ext4_conv_pending_mod(struct inode *inode, int n)
+{
+	struct ext4_inode_info *ei = EXT4_I(inode);
+
+	/*
+	 * Only use the full ordering variant when tracing is needed.
+	 */
+	if (trace_ext4_conv_pending_ios_enabled()) {
+		int new_ios = atomic_add_return(n, &ei->i_conv_pending_ios);
+
+		trace_ext4_conv_pending_ios(inode, n > 0, new_ios - n, new_ios);
+	} else {
+		atomic_add(n, &ei->i_conv_pending_ios);
+	}
+}
+
+/*
+ * In case endio conversion fails due to factors like ENOSPC or ENOMEM, ext4
+ * uses a fallback where we zeroout the unwritten extents instead of splitting.
+ * However, not all unwritten extents can be zeroed out unconditionally as
+ * they might have data underneath which is pending endio conversion. Zeroing
+ * out such an extent can cause silent corruption.
+ *
+ * To fix this we track the IOs which are about to undergo conversion in
+ * ei->i_conv_pending_ios. The zeroout code then uses this counter to
+ * determine if it's safe to zeroout.
+ *
+ * Design Notes:
+ *
+ * **Locking**
+ *
+ * The only mutual exclusion we need is between an IO that is about to be
+ * submitted over an unwritten extent and zeroout. This is done using a
+ * dedicated rwsem, ei->i_conv_pending_sem with the following rules:
+ *
+ * 1. Incrementing the counter must down_read(i_conv_pending_sem).
+ * 2. A zeroout must check the counter and zero data under
+ *    down_write(i_conv_pending_sem)
+ * 3. Decrementing the counter needs no lock. At worst, this makes zeroout bail
+ *    out due to a stale, elevated counter value, which is acceptable
+ * 4. Changes to i_conv_pending_ios should use atomic helpers.
+ *
+ * This design provides us the required exclusion while ensuring that fast paths
+ * don't see any heavy lock contention. Atomic counters help parallel
+ * modifications to be serialized.
+ *
+ * ** Tolerance for false positives **
+ *
+ * We trade false positives for simplicity of implementation because having a
+ * false positive here will just error the endio which is still better than
+ * silently corrupting the data. We can always optimize our tracking to make it
+ * more accurate in the future.
+ */
+void ext4_conv_pending_inc(struct inode *inode)
+{
+	struct ext4_inode_info *ei = EXT4_I(inode);
+
+	down_read(&ei->i_conv_pending_sem);
+	_ext4_conv_pending_mod(inode, 1);
+	up_read(&ei->i_conv_pending_sem);
+}
+
+void ext4_conv_pending_sum(struct inode *inode, int n)
+{
+	struct ext4_inode_info *ei = EXT4_I(inode);
+
+	down_read(&ei->i_conv_pending_sem);
+	_ext4_conv_pending_mod(inode, n);
+	up_read(&ei->i_conv_pending_sem);
+}
+
+/*
+ * Same as ext4_conv_pending_inc() but doesn't sleep if a zeroout is in
+ * progress. Returns -EAGAIN and leaves the counter untouched in that case.
+ */
+int ext4_conv_pending_inc_trylock(struct inode *inode)
+{
+	struct ext4_inode_info *ei = EXT4_I(inode);
+
+	if (!down_read_trylock(&ei->i_conv_pending_sem))
+		return -EAGAIN;
+
+	_ext4_conv_pending_mod(inode, 1);
+	up_read(&ei->i_conv_pending_sem);
+	return 0;
+}
+
+void ext4_conv_pending_dec(struct inode *inode)
+{
+	_ext4_conv_pending_mod(inode, -1);
+}
+
+void ext4_conv_pending_sub(struct inode *inode, int n)
+{
+	struct ext4_inode_info *ei = EXT4_I(inode);
+
+	down_read(&ei->i_conv_pending_sem);
+	_ext4_conv_pending_mod(inode, -n);
+	up_read(&ei->i_conv_pending_sem);
+}
+
 int ext4_map_create_blocks(handle_t *handle, struct inode *inode,
 			   struct ext4_map_blocks *map, int flags)
 {
@@ -3994,7 +4095,47 @@ int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
 	return 0;
 }
 
-static DEFINE_IOMAP_ITER_NEXT(ext4_iomap_next, ext4_iomap_begin);
+static int ext4_iomap_next(const struct iomap_iter *iter, struct iomap *iomap,
+			   struct iomap *srcmap)
+{
+	int ret = iomap_iter_next(iter, iomap, srcmap, ext4_iomap_begin, NULL);
+
+	/*
+	 * For dio, increment i_conv_pending_ios the first time we see an
+	 * unwritten mapping for this IO, so that it cleanly balances with the
+	 * single endio call. We use iter->private to track state to ensure we
+	 * only increment once per dio regardless of how many extents it spans.
+	 * The decrement happens in ext4_dio_write_end_io() if
+	 * IOMAP_DIO_UNWRITTEN is set.
+	 *
+	 * Hack alert: iomap_dio_bio_iter() fails a misaligned mapping with
+	 * -EINVAL before it sets IOMAP_DIO_UNWRITTEN, so endio would skip the
+	 * decrement. Don't increment for such a mapping. The alignment check
+	 * mirrors the one in iomap_dio_bio_iter()
+	 */
+	if (ret > 0 && iter->private &&
+	    (iter->flags & IOMAP_WRITE) && (iomap->type == IOMAP_UNWRITTEN) &&
+	    IS_ALIGNED(iter->pos | iomap_length(iter),
+		       bdev_logical_block_size(iomap->bdev))) {
+		bool *inc_done = (bool *)iter->private;
+
+		if (!*inc_done) {
+			/* NOWAIT dio must not sleep on i_conv_pending_sem */
+			if (iter->flags & IOMAP_NOWAIT) {
+				int err;
+
+				err = ext4_conv_pending_inc_trylock(iter->inode);
+				if (err)
+					return err;
+			} else {
+				ext4_conv_pending_inc(iter->inode);
+			}
+			*inc_done = true;
+		}
+	}
+
+	return ret;
+}
 
 const struct iomap_ops ext4_iomap_ops = {
 	.iomap_next		= ext4_iomap_next,
@@ -4447,6 +4588,9 @@ static int ext4_iomap_writeback_submit(struct iomap_writepage_ctx *wpc,
 	if (ioend->io_bio.bi_end_io)
 		bio_clear_flag(&ioend->io_bio, BIO_COMPLETE_IN_TASK);
 
+	if (ioend->io_flags & IOMAP_IOEND_UNWRITTEN)
+		ext4_conv_pending_inc(inode);
+
 	return iomap_ioend_writeback_submit(wpc, error);
 }
 
diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c
index 734d856a6d4784..e99816017a18da 100644
--- a/fs/ext4/page-io.c
+++ b/fs/ext4/page-io.c
@@ -190,6 +190,12 @@ static int ext4_end_io_end(ext4_io_end_t *io_end)
 
 		if (test_opt(sb, DATA_ERR_ABORT))
 			jbd2_journal_abort(EXT4_SB(sb)->s_journal, ret);
+
+		/*
+		 * Conversion was skipped so drop the count that submission took
+		 */
+		if (io_end->flag & EXT4_IO_END_UNWRITTEN)
+			ext4_conv_pending_dec(inode);
 	} else {
 		ret = ext4_convert_unwritten_io_end_vec(handle, io_end);
 	}
@@ -646,6 +652,21 @@ static void ext4_iomap_finish_ioend(struct iomap_ioend *ioend)
 	int credits;
 	int ret, err;
 
+	/*
+	 * We increment conv_pending for each IO we submit but endio might have
+	 * merged them into a single ioend. The data of all merged sub-ioends is
+	 * covered by a single conversion, so drop their counts keeping just
+	 * the one count for the single ioend we will try to convert.
+	 */
+	if (ioend->io_flags & IOMAP_IOEND_UNWRITTEN) {
+		struct iomap_ioend *sub;
+
+		list_for_each_entry(sub, &ioend->io_list, io_list) {
+			if (sub->io_flags & IOMAP_IOEND_UNWRITTEN)
+				ext4_conv_pending_dec(inode);
+		}
+	}
+
 	ret = blk_status_to_errno(ioend->io_bio.bi_status);
 	if (is_disksize_grow)
 		trace_ext4_iomap_wb_disksize_pending_complete(ioend->io_inode,
@@ -685,7 +706,7 @@ static void ext4_iomap_finish_ioend(struct iomap_ioend *ioend)
 
 	if (ioend->io_flags & IOMAP_IOEND_UNWRITTEN)
 		ret = ext4_convert_unwritten_extents(handle, inode, pos,
-						     size, NULL);
+						     size, NULL, 0);
 
 out_journal:
 	err = ext4_journal_stop(handle);
@@ -698,6 +719,10 @@ static void ext4_iomap_finish_ioend(struct iomap_ioend *ioend)
 			 inode->i_ino, ret);
 	}
 out:
+	/* Drop the count of the head ioend now that conversion is done. */
+	if (ioend->io_flags & IOMAP_IOEND_UNWRITTEN)
+		ext4_conv_pending_dec(inode);
+
 	iomap_finish_ioends(ioend, ret);
 }
 
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 7d8aedfbbb87f1..866a6a70535e9d 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -1429,6 +1429,8 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)
 	ei->i_es_shrink_lblk = 0;
 	ei->i_es_seq = 0;
 	ei->i_reserved_data_blocks = 0;
+	atomic_set(&ei->i_conv_pending_ios, 0);
+	init_rwsem(&ei->i_conv_pending_sem);
 	spin_lock_init(&(ei->i_block_reservation_lock));
 	ext4_init_pending_tree(&ei->i_pending_tree);
 #ifdef CONFIG_QUOTA
@@ -1505,6 +1507,16 @@ static void ext4_destroy_inode(struct inode *inode)
 		ext4_msg(inode->i_sb, KERN_ERR,
 			 "Inode %llu (%p): EXT4_STATE_DISKSIZE_GROW_PENDING not cleared!",
 			 inode->i_ino, EXT4_I(inode));
+
+	if (!(EXT4_SB(inode->i_sb)->s_mount_state & EXT4_ERROR_FS) &&
+	    !ext4_emergency_state(inode->i_sb)) {
+		int pending = atomic_read(&EXT4_I(inode)->i_conv_pending_ios);
+
+		if (WARN_ON_ONCE(pending))
+			ext4_msg(inode->i_sb, KERN_ERR,
+				 "Inode %llu (%p): i_conv_pending_ios (%d) not cleared!",
+				 inode->i_ino, EXT4_I(inode), pending);
+	}
 }
 
 static void ext4_shutdown(struct super_block *sb)
diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h
index 92048da9dae43b..f1754b2e836ca3 100644
--- a/include/trace/events/ext4.h
+++ b/include/trace/events/ext4.h
@@ -43,6 +43,7 @@ struct partial_cluster;
 	{ EXT4_GET_BLOCKS_CONVERT,		"CONVERT" },		\
 	{ EXT4_GET_BLOCKS_METADATA_NOFAIL,	"METADATA_NOFAIL" },	\
 	{ EXT4_GET_BLOCKS_NO_NORMALIZE,		"NO_NORMALIZE" },	\
+	{ EXT4_GET_BLOCKS_NO_CONV_ACC,		"NO_CONV_ACC" },	\
 	{ EXT4_GET_BLOCKS_CONVERT_UNWRITTEN,	"CONVERT_UNWRITTEN" },  \
 	{ EXT4_GET_BLOCKS_ZERO,			"ZERO" },		\
 	{ EXT4_GET_BLOCKS_IO_SUBMIT,		"IO_SUBMIT" },		\
@@ -3366,6 +3367,30 @@ TRACE_EVENT(ext4_block_zero_eof,
 		  __entry->i_disksize, __entry->did_zero, __entry->zero_written)
 );
 
+/* i_conv_pending_ios accounting tracepoint */
+TRACE_EVENT(ext4_conv_pending_ios,
+	TP_PROTO(struct inode *inode, bool add, int old_ios, int new_ios),
+	TP_ARGS(inode, add, old_ios, new_ios),
+	TP_STRUCT__entry(
+		__field(dev_t, dev)
+		__field(u64, ino)
+		__field(bool, add)
+		__field(int, old_ios)
+		__field(int, new_ios)
+	),
+	TP_fast_assign(
+		__entry->dev = inode->i_sb->s_dev;
+		__entry->ino = inode->i_ino;
+		__entry->add = add;
+		__entry->old_ios = old_ios;
+		__entry->new_ios = new_ios;
+	),
+	TP_printk("dev %d:%d ino %llu %s i_conv_pending_ios %d -> %d",
+		  MAJOR(__entry->dev), MINOR(__entry->dev), __entry->ino,
+		  __entry->add ? "inc" : "dec",
+		  __entry->old_ios, __entry->new_ios)
+);
+
 #endif /* _TRACE_EXT4_H */
 
 /* This part must be outside protection */

17/3 2026/11/03 10:36 llm kmsan-evaluator
4m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 11753
							output: 22
							thoughts: 2930
						

Thoughts:
**KMSAN Fuzzing Session Justification: ext4 Unwritten Extent Conversion**

Alright, let's break this down. My goal is to determine if this ext4 patch requires a dedicated KMSAN fuzzing session. The patch introduces tracking for in-flight IOs related to the conversion of unwritten extents to written extents. The core issue is preventing data corruption during the fallback zeroing-out of unwritten extents if a conversion fails. The added `i_conv_pending_ios` (atomic counter) and `i_conv_pending_sem` (read-write semaphore) within the `ext4_inode_info` structure are key to the fix.

The rules are clear: avoid redundant KMSAN testing. KASAN already handles out-of-bounds, use-after-free, double-free, and invalid-free errors. LOCKDEP manages locking and potential deadlock situations, UBSAN covers undefined behavior and memory corruption, and standard bug detectors are included. KMSAN's purpose is to detect reads of *uninitialized* memory within the kernel address space, including stack, heap, and page allocations, *and* prevent kernel-to-user memory info-leaks.

I'm checking if the patch introduces or modifies these specific risk areas:
1.  Kernel structures sent to userspace (via copy_to_user, etc.).
2.  Conditional logic based on potentially uninitialized variables.
3.  Complex data structure initialization with later uninitialized reads.
4.  Bounds checks that could lead to uninitialized byte access.

So, let's evaluate:

*   **Structure Exposure to Userspace**: The patch doesn't involve any `copy_to_user`, `put_user`, netlink, ioctl, etc. There's no direct exposure of kernel structures to user space.

*   **Uninitialized Variables**: I need to check all local variables. In `ext4_split_extent_zeroout` `err = 0;`, `ee_len` and `len` are initialized before use, and `is_unwrit` is initialized via a function call. Similarly, `ext4_convert_unwritten_io_end_vec`'s `n = 0;`, `ext4_conv_pending_zeroout_lock`, `pending` and `thresh` are assigned. And `ext4_dio_write_iter`, `bool conv_pending_inc = false;` and `ext4_iomap_next` use values which are explicitly initialized.

*   **Data Structure Initialization**: The new `i_conv_pending_ios` and `i_conv_pending_sem` are initialized in `ext4_alloc_inode()` and `extents_kunit_init()`.

*   **Uninitialized Bytes**: All variables appear to be correctly initialized. The code *tracks* pending IOs; it doesn't create new risks related to uninitialized buffers. The "unwritten extent" concept in ext4 is for *pre*-allocation, and the kernel guarantees it's zero-filled when read by userspace (so no information leakage occurs). The patch fixes the fact that a racing write-conversion might not protect the data on disk, leading to *corruption* (data being overwritten).

*   **The Zeroing-Out Fallback**: This patch avoids *overwriting* already-written data on the disk via a racing IO. This isn't KMSAN's domain (KMSAN tests CPU/RAM memory writes). Locking (atomic counter and rwsem) will prevent data corruption. LOCKDEP already identifies potential race conditions, deadlocks, and locking order violations. KASAN helps identify memory safety bugs.

**KMSAN Risk Assessment**: Given this analysis, I'm concluding that this ext4 patch does *not* introduce new risks of uninitialized memory usage or data leaks. The changes are primarily focused on locking, synchronization, and avoiding data corruption on disk, which are already handled by KASAN and LOCKDEP. So, **NeedsKMSAN = false**.



18/3 2026/11/03 10:41 tool grepper
0m Args:
{
  "Expression": "ext4_iomap_ops"
}

Results:
{
  "Output": "fs/ext4/ext4.h=4122=static inline void ext4_clear_io_unwritten_flag(ext4_io_end_t *io_end)\n--\nfs/ext4/ext4.h-4126-\nfs/ext4/ext4.h:4127:extern const struct iomap_ops ext4_iomap_ops;\nfs/ext4/ext4.h-4128-extern const struct iomap_ops ext4_iomap_report_ops;\n--\nfs/ext4/file.c=69=static ssize_t ext4_dio_read_iter(struct kiocb *iocb, struct iov_iter *to)\n--\nfs/ext4/file.c-95-\tif (ret == -ENOTBLK)\nfs/ext4/file.c:96:\t\tret = iomap_dio_rw(iocb, to, \u0026ext4_iomap_ops, NULL, 0, NULL, 0);\nfs/ext4/file.c-97-\tinode_unlock_shared(inode);\n--\nfs/ext4/file.c=104=static ssize_t ext4_dax_read_iter(struct kiocb *iocb, struct iov_iter *to)\n--\nfs/ext4/file.c-123-\t}\nfs/ext4/file.c:124:\tret = dax_iomap_rw(iocb, to, \u0026ext4_iomap_ops);\nfs/ext4/file.c-125-\tinode_unlock_shared(inode);\n--\nfs/ext4/file.c=602=static ssize_t ext4_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)\n--\nfs/ext4/file.c-675-\nfs/ext4/file.c:676:\tret = iomap_dio_rw(iocb, from, \u0026ext4_iomap_ops, \u0026ext4_dio_write_ops,\nfs/ext4/file.c-677-\t\t\t   dio_flags, \u0026conv_pending_inc, 0);\n--\nfs/ext4/file.c=735=ext4_dax_write_iter(struct kiocb *iocb, struct iov_iter *from)\n--\nfs/ext4/file.c-779-\nfs/ext4/file.c:780:\tret = dax_iomap_rw(iocb, from, \u0026ext4_iomap_ops);\nfs/ext4/file.c-781-\n--\nfs/ext4/file.c=828=static vm_fault_t ext4_dax_huge_fault(struct vm_fault *vmf, unsigned int order)\n--\nfs/ext4/file.c-867-\t}\nfs/ext4/file.c:868:\tresult = dax_iomap_fault(vmf, order, \u0026pfn, \u0026error, \u0026ext4_iomap_ops);\nfs/ext4/file.c-869-\tif (write) {\n--\nfs/ext4/inode.c=3600=static sector_t ext4_bmap(struct address_space *mapping, sector_t block)\n--\nfs/ext4/inode.c-3622-\nfs/ext4/inode.c:3623:\tret = iomap_bmap(mapping, block, \u0026ext4_iomap_ops);\nfs/ext4/inode.c-3624-\n--\nfs/ext4/inode.c=4098=static int ext4_iomap_next(const struct iomap_iter *iter, struct iomap *iomap,\n--\nfs/ext4/inode.c-4139-\nfs/ext4/inode.c:4140:const struct iomap_ops ext4_iomap_ops = {\nfs/ext4/inode.c-4141-\t.iomap_next\t\t= ext4_iomap_next,\n--\nfs/ext4/inode.c=4997=static int ext4_block_zero_range(struct inode *inode,\n--\nfs/ext4/inode.c-5012-\t\treturn dax_zero_range(inode, from, length, did_zero,\nfs/ext4/inode.c:5013:\t\t\t\t      \u0026ext4_iomap_ops);\nfs/ext4/inode.c-5014-\t} else if (ext4_should_journal_data(inode)) {\n"
}

19/3 2026/11/03 10:41 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 16730
							output: 36
							thoughts: 221
						

Thoughts:
**Analyzing the Iterator's Private Data in I/O Operations**

Okay, let's break this down. I'm seeing a pattern here with how we're handling the `iter->private` field within these I/O operations, specifically in the context of EXT4 and its IOMAP implementation. I notice that in other calls, `iter->private` is either NULL or not initialized as a boolean, which is the first thing I need to keep in mind.

Now, focusing on `ext4_iomap_next`, there's this critical check: `if (ret > 0 && iter->private && (iter->flags & IOMAP_WRITE) && (iomap->type == IOMAP_UNWRITTEN) && IS_ALIGNED(iter->pos | iomap_length(iter), bdev_logical_block_size(iomap->bdev)))`. This is where `iter->private` comes into play. If `iter->private` *is* NULL, that conditional short-circuits, preventing a potential dereference of a null pointer, meaning `inc_done` doesn't get touched. This is good defensive programming, but I need to understand the scenarios where `iter->private` is *not* NULL.

The next step is to see how this private data is used. I see `iomap_dio_rw` is called, and the `private` argument passed to the iterator is `&conv_pending_inc`, which makes the iterator's private data a pointer to a boolean. Now I need to see how the code sets this `iter.private`. Let's trace it and ensure we have all the bases covered.



20/3 2026/11/03 10:41 tool grepper
0m Args:
{
  "Expression": "iter-\u003eprivate =|iter\\.private =",
  "PathPrefixes": [
    "fs/iomap/"
  ]
}

Results:
{
  "Output": "no matches"
}

21/3 2026/11/03 10:41 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 17365
							output: 34
							thoughts: 27
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Diving into `iomap_dio_rw`**

Alright, time to dig into the guts of direct I/O. I'm thinking we should start by focusing on `iomap_dio_rw` in `fs/iomap/direct-io.c`. This is the core function where the rubber meets the road, as far as direct I/O operations are concerned. We need to dissect how it interacts with the I/O mapping layer. It's crucial to understand how it handles the different scenarios: the alignment checks, whether we're dealing with buffered or unbuffered data, the caching behavior, how it interacts with the block device layer, and how it handles error recovery. I need to refresh my understanding of how IOMAP interacts with other parts of the filesystem stack; specifically, how it interfaces with the generic block layer. I want to see if there are any subtle optimization opportunities within the function. I'm going to pay close attention to the lock acquisition and release patterns too, as these can easily become bottlenecks or sources of contention in a parallel I/O environment. Let's see what's changed since the last major kernel version, too; there may be relevant tweaks or performance improvements I've missed.



22/3 2026/11/03 10:41 tool grepper
0m Args:
{
  "Expression": "iomap_dio_rw",
  "PathPrefixes": [
    "fs/iomap/"
  ]
}

Results:
{
  "Output": "fs/iomap/direct-io.c=416=static int iomap_dio_bio_iter(struct iomap_iter *iter, struct iomap_dio *dio)\n--\nfs/iomap/direct-io.c-511-\t\t * Writes that extend i_size are also not supported, but this is\nfs/iomap/direct-io.c:512:\t\t * handled in __iomap_dio_rw().\nfs/iomap/direct-io.c-513-\t\t */\n--\nfs/iomap/direct-io.c=638=static int iomap_dio_iter(struct iomap_iter *iter, struct iomap_dio *dio)\n--\nfs/iomap/direct-io.c-669-/*\nfs/iomap/direct-io.c:670: * iomap_dio_rw() always completes O_[D]SYNC writes regardless of whether the IO\nfs/iomap/direct-io.c-671- * is being issued as AIO or not.  This allows us to optimise pure data writes\n--\nfs/iomap/direct-io.c-678- * When page faults are disabled and @dio_flags includes IOMAP_DIO_PARTIAL,\nfs/iomap/direct-io.c:679: * __iomap_dio_rw can return a partial result if it encounters a non-resident\nfs/iomap/direct-io.c-680- * page in @iter after preparing a transfer.  In that case, the non-resident\n--\nfs/iomap/direct-io.c=689=struct iomap_dio *\nfs/iomap/direct-io.c:690:__iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,\nfs/iomap/direct-io.c-691-\t\tconst struct iomap_ops *ops, const struct iomap_dio_ops *dops,\n--\nfs/iomap/direct-io.c-707-\nfs/iomap/direct-io.c:708:\ttrace_iomap_dio_rw_begin(iocb, iter, dio_flags, done_before);\nfs/iomap/direct-io.c-709-\n--\nfs/iomap/direct-io.c-878-\t\tif (!wait_for_completion) {\nfs/iomap/direct-io.c:879:\t\t\ttrace_iomap_dio_rw_queued(inode, iomi.pos, iomi.len);\nfs/iomap/direct-io.c-880-\t\t\treturn ERR_PTR(-EIOCBQUEUED);\n--\nfs/iomap/direct-io.c-900-}\nfs/iomap/direct-io.c:901:EXPORT_SYMBOL_GPL(__iomap_dio_rw);\nfs/iomap/direct-io.c-902-\nfs/iomap/direct-io.c=903=ssize_t\nfs/iomap/direct-io.c:904:iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,\nfs/iomap/direct-io.c-905-\t\tconst struct iomap_ops *ops, const struct iomap_dio_ops *dops,\n--\nfs/iomap/direct-io.c-909-\nfs/iomap/direct-io.c:910:\tdio = __iomap_dio_rw(iocb, iter, ops, dops, dio_flags, private,\nfs/iomap/direct-io.c-911-\t\t\t     done_before);\n--\nfs/iomap/direct-io.c-915-}\nfs/iomap/direct-io.c:916:EXPORT_SYMBOL_GPL(iomap_dio_rw);\nfs/iomap/direct-io.c-917-\n--\nfs/iomap/direct-io.c=992=ssize_t __iomap_dio_read_simple(struct kiocb *iocb, struct iov_iter *iter,\n--\nfs/iomap/direct-io.c-1020-\nfs/iomap/direct-io.c:1021:\ttrace_iomap_dio_rw_begin(iocb, iter, 0, 0);\nfs/iomap/direct-io.c-1022-\n--\nfs/iomap/direct-io.c-1068-\tsubmit_bio(bio);\nfs/iomap/direct-io.c:1069:\ttrace_iomap_dio_rw_queued(iomi-\u003einode, iocb-\u003eki_pos, iomi-\u003elen);\nfs/iomap/direct-io.c-1070-\treturn -EIOCBQUEUED;\n--\nfs/iomap/trace.h=85=DEFINE_RANGE_EVENT(iomap_dio_invalidate_fail);\nfs/iomap/trace.h:86:DEFINE_RANGE_EVENT(iomap_dio_rw_queued);\nfs/iomap/trace.h-87-DEFINE_RANGE_EVENT(iomap_zero_iter);\n--\nfs/iomap/trace.h=220=TRACE_EVENT(iomap_iter,\n--\nfs/iomap/trace.h-255-\nfs/iomap/trace.h:256:TRACE_EVENT(iomap_dio_rw_begin,\nfs/iomap/trace.h-257-\tTP_PROTO(struct kiocb *iocb, struct iov_iter *iter,\n"
}

23/3 2026/11/03 10:41 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 19150
							output: 39
							thoughts: 34
						

Thoughts:
Okay, let's dive into this. Here's my thought process on this specific code snippet:

**Debugging `__iomap_dio_rw` in `fs/iomap/direct-io.c`**

Alright, I need to get my bearings. Let me go straight to the heart of the matter – `__iomap_dio_rw`. I know that function is a key player in handling direct I/O within the iomap framework. Specifically, I need to look around line 710 in `fs/iomap/direct-io.c`. That's likely where the core logic or some important conditional path within the function resides, and probably where the behavior I'm interested in analyzing is implemented. I'm expecting to find something fundamental related to the I/O operation here: it might be how the function is dealing with buffer management, or maybe the specific handling of scatter-gather lists. It could even be how errors are being handled, or how the I/O is scheduled. Either way, this line is my target.



24/3 2026/11/03 10:42 tool read-file
0m Args:
{
  "File": "fs/iomap/direct-io.c",
  "FirstLine": 700,
  "LineCount": 40
}

Results:
{
  "Contents": " 700:\t\t\t.private\t= private,\n 701:\t\t};\n 702:\t\tbool wait_for_completion =\n 703:\t\t\tis_sync_kiocb(iocb) || (dio_flags \u0026 IOMAP_DIO_FORCE_WAIT);\n 704:\t\tstruct blk_plug plug;\n 705:\t\tstruct iomap_dio *dio;\n 706:\t\tloff_t ret = 0;\n 707:\t\n 708:\t\ttrace_iomap_dio_rw_begin(iocb, iter, dio_flags, done_before);\n 709:\t\n 710:\t\tif (!iomi.len)\n 711:\t\t\treturn NULL;\n 712:\t\n 713:\t\tdio = kmalloc_obj(*dio);\n 714:\t\tif (!dio)\n 715:\t\t\treturn ERR_PTR(-ENOMEM);\n 716:\t\n 717:\t\tdio-\u003eiocb = iocb;\n 718:\t\tatomic_set(\u0026dio-\u003eref, 1);\n 719:\t\tdio-\u003esize = 0;\n 720:\t\tdio-\u003ei_size = i_size_read(inode);\n 721:\t\tdio-\u003edops = dops;\n 722:\t\tdio-\u003eerror = 0;\n 723:\t\tdio-\u003eflags = dio_flags \u0026 (IOMAP_DIO_FSBLOCK_ALIGNED | IOMAP_DIO_BOUNCE);\n 724:\t\tdio-\u003edone_before = done_before;\n 725:\t\n 726:\t\tdio-\u003esubmit.iter = iter;\n 727:\t\tdio-\u003esubmit.waiter = current;\n 728:\t\n 729:\t\tif (iocb-\u003eki_flags \u0026 IOCB_NOWAIT)\n 730:\t\t\tiomi.flags |= IOMAP_NOWAIT;\n 731:\t\n 732:\t\tif (iov_iter_rw(iter) == READ) {\n 733:\t\t\tif (iomi.pos \u003e= dio-\u003ei_size)\n 734:\t\t\t\tgoto out_free_dio;\n 735:\t\n 736:\t\t\tif (user_backed_iter(iter))\n 737:\t\t\t\tdio-\u003eflags |= IOMAP_DIO_USER_BACKED;\n 738:\t\n 739:\t\t\tret = kiocb_write_and_wait(iocb, iomi.len);\n"
}

25/3 2026/11/03 10:42 llm kmsan-evaluator
1m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 20088
							output: 409
							thoughts: 578
						

Thoughts:
**KMSAN Assessment: No Uninitialized Memory Risks**

Okay, let's break this down. My initial thought process is to look for potential uninitialized memory vulnerabilities introduced by this patch. I see that `iomi.private` is initialized with `private`, and that `iter->private` is correctly pointing to `conv_pending_inc`, which is initialized to `false`. So far, so good – everything seems properly initialized.

Now, I'm systematically going through the potential areas where uninitialized memory could become an issue. First, I'm checking if the changes expose kernel structures to user space. Nope, that's not the case here. This patch mainly modifies extent conversion logic, direct I/O completion, buffered writeback completion, zeroout locking, and tracepoints.

Next, I'm looking for uninitialized variables or struct fields being used in conditional logic or branching. Again, a clean bill of health: `conv_pending_inc` is `false`, the atomic `i_conv_pending_ios` is initialized to 0, `err` is 0, `n` is 0, etc. No issues there.

Are there complex data structures allocated or initialized in a way that uninitialized fields could be read later? No, inode initialization in `ext4_alloc_inode` properly initializes `i_conv_pending_ios` and `i_conv_pending_sem`.

Then, I'm scrutinizing bounds checks, lengths, or logic that could lead to accessing uninitialized bytes of existing buffers. No, that's not a concern here either. This code is about tracking in-flight IOs related to extent conversion to prevent zeroout from overwriting pending data. It's focused on data integrity and doesn't manipulate buffer lengths or copy uninitialized memory.

Finally, I'm considering the *kinds* of bugs the code *could* introduce. I see the potential for deadlocks or lock inversions on `i_conv_pending_sem`, race conditions on `i_conv_pending_ios`, or -EAGAIN on NOWAIT. The patch is covered by LOCKDEP to help identify lock deadlocks and KASAN for memory safety issues. KMSAN doesn't have a value here since no uninitialized memory is read or exposed.

Therefore, because this code doesn't introduce or expose uninitialized memory risks that would be uniquely detectable by KMSAN, `NeedsKMSAN` should be `false`. I've checked all the requirements and confirmed that we're adhering to the rule that KMSAN should not be used if other bug detectors can catch the issue. We're ready to write the reasoning and call set-results.



26/3 2026/11/03 10:43 tool set-results
0m Args:
{
  "KMSANReasoning": "The patch introduces an in-flight IO tracking mechanism (using `i_conv_pending_ios` and `i_conv_pending_sem` on `struct ext4_inode_info`) to prevent ext4's fallback zeroout logic from racing with and overwriting data from concurrent IOs pending unwritten-to-written extent conversion.\n\nAnalysis of memory safety and sanitizer applicability:\n1. No uninitialized memory or info-leaks:\n   - All newly added struct members (`ei-\u003ei_conv_pending_ios`, `ei-\u003ei_conv_pending_sem`) are properly initialized in `ext4_alloc_inode()` and `extents_kunit_init()`.\n   - Local variables (e.g., `bool conv_pending_inc = false;` in `ext4_dio_write_iter()`, `int n = 0;` in `ext4_convert_unwritten_io_end_vec()`, `int err = 0;` in `ext4_split_extent_zeroout()`) are explicitly initialized before use.\n   - No kernel data structures or uninitialized memory are copied or exposed to userspace.\n2. Failure modes:\n   - Potential risks in this patch are synchronization issues, counter imbalance (e.g. leaking counts causing the WARN_ON_ONCE in `ext4_destroy_inode`), lock contention or deadlocks on `i_conv_pending_sem`, and filesystem error returns.\n   - Deadlocks and locking bugs are detected by LOCKDEP. Memory lifecycle issues (use-after-free, out-of-bounds) are detected by KASAN.\n   - KMSAN is not applicable as there are no uninitialized heap/stack memory reads or kernel-to-user info-leak vectors.",
  "NeedsKMSAN": false
}

Results:
{
  "KMSANReasoning": "The patch introduces an in-flight IO tracking mechanism (using `i_conv_pending_ios` and `i_conv_pending_sem` on `struct ext4_inode_info`) to prevent ext4's fallback zeroout logic from racing with and overwriting data from concurrent IOs pending unwritten-to-written extent conversion.\n\nAnalysis of memory safety and sanitizer applicability:\n1. No uninitialized memory or info-leaks:\n   - All newly added struct members (`ei-\u003ei_conv_pending_ios`, `ei-\u003ei_conv_pending_sem`) are properly initialized in `ext4_alloc_inode()` and `extents_kunit_init()`.\n   - Local variables (e.g., `bool conv_pending_inc = false;` in `ext4_dio_write_iter()`, `int n = 0;` in `ext4_convert_unwritten_io_end_vec()`, `int err = 0;` in `ext4_split_extent_zeroout()`) are explicitly initialized before use.\n   - No kernel data structures or uninitialized memory are copied or exposed to userspace.\n2. Failure modes:\n   - Potential risks in this patch are synchronization issues, counter imbalance (e.g. leaking counts causing the WARN_ON_ONCE in `ext4_destroy_inode`), lock contention or deadlocks on `i_conv_pending_sem`, and filesystem error returns.\n   - Deadlocks and locking bugs are detected by LOCKDEP. Memory lifecycle issues (use-after-free, out-of-bounds) are detected by KASAN.\n   - KMSAN is not applicable as there are no uninitialized heap/stack memory reads or kernel-to-user info-leak vectors.",
  "NeedsKMSAN": false
}

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)