AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/09/15 01:31 flow patch-triage
3m Args:
null

Results:
{
  "EnableConfigs": [
    "HFSPLUS_FS",
    "MISC_FILESYSTEMS",
    "BLOCK"
  ],
  "FocusSymbols": [
    "hfsplus_map_extent",
    "hfsplus_iomap_cont_expand",
    "hfsplus_write_iomap_end",
    "hfsplus_writeback_range",
    "hfsplus_file_write_iter",
    "hfsplus_file_read_iter",
    "hfsplus_file_llseek",
    "hfsplus_block_allocate",
    "hfsplus_block_free"
  ],
  "KMSANReasoning": "The patch migrates the HFS+ filesystem from legacy buffer_head-based file operations and direct I/O to the modern iomap infrastructure (iomap read/write/seek/writeback/swap).\n\nKey aspects evaluated for uninitialized memory risks:\n1. No kernel structures are copied or leaked to user space via copy_to_user, put_user, netlink, or ioctl.\n2. Local variables in the new and modified functions (such as `was_dirty`, `dblock`, `max_blocks`, `did_zero`, and `wpc`) are fully initialized before any read or conditional branch.\n3. Unallocated or extended file ranges are zeroed out via `iomap_zero_range()` and `iomap_truncate_page()`, preventing reading of uninitialized page/disk contents.\n4. The iomap core structures (`struct iomap`, `struct iomap_writepage_ctx`) are zero-initialized prior to being populated by the filesystem callbacks.\n\nThe potential bugs introduced by this transition (such as locking issues, writeback races, or buffer out-of-bounds accesses) are covered by KASAN and LOCKDEP. There are no uninitialized memory access risks or info-leaks that would require a dedicated KMSAN fuzzing session.",
  "NeedsKMSAN": false,
  "Reasoning": "The patch series converts the HFS+ regular file I/O path to use the iomap framework (for buffered reads/writes, direct I/O, writeback, and hole/data seeking), refactors extent allocation and mapping with hfsplus_map_extent(), and introduces page locking and writeback synchronization in the bitmap allocator. HFS+ filesystems are fully reachable in standard virtualized environments (e.g. via loop devices and mount). These structural changes in extent resolution, I/O paths, and locking warrant fuzzing for concurrency issues, assertion trips, and boundary corner cases.",
  "WorthFuzzing": true
}

1/1 2026/09/15 01:31 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit 39277fb8636d2c138333c48e03b8696b2d711648\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Tue Sep 15 01:31:24 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/fs/hfsplus/Kconfig b/fs/hfsplus/Kconfig\nindex ca8401cb6954d..b4432c64db3be 100644\n--- a/fs/hfsplus/Kconfig\n+++ b/fs/hfsplus/Kconfig\n@@ -5,7 +5,7 @@ config HFSPLUS_FS\n \tselect BUFFER_HEAD\n \tselect NLS\n \tselect NLS_UTF8\n-\tselect LEGACY_DIRECT_IO\n+\tselect FS_IOMAP\n \thelp\n \t  If you say Y here, you will be able to mount extended format\n \t  Macintosh-formatted hard drive partitions with full read-write access.\ndiff --git a/fs/hfsplus/Makefile b/fs/hfsplus/Makefile\nindex f2a9ae697e811..3ddea69a9c698 100644\n--- a/fs/hfsplus/Makefile\n+++ b/fs/hfsplus/Makefile\n@@ -5,8 +5,9 @@\n \n obj-$(CONFIG_HFSPLUS_FS) += hfsplus.o\n \n-hfsplus-objs := super.o options.o inode.o ioctl.o extents.o catalog.o dir.o btree.o \\\n-\t\tbnode.o brec.o bfind.o tables.o unicode.o wrapper.o bitmap.o part_tbl.o \\\n+hfsplus-objs := super.o options.o inode.o file.o iomap.o ioctl.o extents.o \\\n+\t\tcatalog.o dir.o btree.o bnode.o brec.o bfind.o tables.o \\\n+\t\tunicode.o wrapper.o bitmap.o part_tbl.o \\\n \t\tattributes.o xattr.o xattr_user.o xattr_security.o xattr_trusted.o\n \n # KUnit tests\ndiff --git a/fs/hfsplus/bitmap.c b/fs/hfsplus/bitmap.c\nindex 1b3af8c87cadb..30178ea473624 100644\n--- a/fs/hfsplus/bitmap.c\n+++ b/fs/hfsplus/bitmap.c\n@@ -39,6 +39,8 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size,\n \t\tstart = size;\n \t\tgoto out;\n \t}\n+\tlock_page(page);\n+\tfolio_wait_writeback(page_folio(page));\n \tpptr = kmap_local_page(page);\n \tcurr = pptr + (offset \u0026 (PAGE_CACHE_BITS - 1)) / 32;\n \ti = offset % 32;\n@@ -75,6 +77,7 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size,\n \t\t\tcurr++;\n \t\t}\n \t\tkunmap_local(pptr);\n+\t\tunlock_page(page);\n \t\toffset += PAGE_CACHE_BITS;\n \t\tif (offset \u003e= size)\n \t\t\tbreak;\n@@ -84,6 +87,8 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size,\n \t\t\tstart = size;\n \t\t\tgoto out;\n \t\t}\n+\t\tlock_page(page);\n+\t\tfolio_wait_writeback(page_folio(page));\n \t\tcurr = pptr = kmap_local_page(page);\n \t\tif ((size ^ offset) / PAGE_CACHE_BITS)\n \t\t\tend = pptr + PAGE_CACHE_BITS / 32;\n@@ -98,6 +103,9 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size,\n \tstart = offset + (curr - pptr) * 32 + i;\n \tif (start \u003e= size) {\n \t\thfs_dbg(\"bitmap full\\n\");\n+\t\tkunmap_local(pptr);\n+\t\tunlock_page(page);\n+\t\tstart = size;\n \t\tgoto out;\n \t}\n \t/* do any partial u32 at the start */\n@@ -128,6 +136,7 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size,\n \t\t}\n \t\tset_page_dirty(page);\n \t\tkunmap_local(pptr);\n+\t\tunlock_page(page);\n \t\toffset += PAGE_CACHE_BITS;\n \t\tpage = read_mapping_page(mapping, offset / PAGE_CACHE_BITS,\n \t\t\t\t\t NULL);\n@@ -135,6 +144,8 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size,\n \t\t\tstart = size;\n \t\t\tgoto out;\n \t\t}\n+\t\tlock_page(page);\n+\t\tfolio_wait_writeback(page_folio(page));\n \t\tpptr = kmap_local_page(page);\n \t\tcurr = pptr;\n \t\tend = pptr + PAGE_CACHE_BITS / 32;\n@@ -152,6 +163,7 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size,\n \t*curr = cpu_to_be32(n);\n \tset_page_dirty(page);\n \tkunmap_local(pptr);\n+\tunlock_page(page);\n \t*max = offset + (curr - pptr) * 32 + i - start;\n \tsbi-\u003efree_blocks -= *max;\n \thfsplus_mark_mdb_dirty(sb);\n@@ -185,6 +197,8 @@ int hfsplus_block_free(struct super_block *sb, u32 offset, u32 count)\n \tpage = read_mapping_page(mapping, pnr, NULL);\n \tif (IS_ERR(page))\n \t\tgoto kaboom;\n+\tlock_page(page);\n+\tfolio_wait_writeback(page_folio(page));\n \tpptr = kmap_local_page(page);\n \tcurr = pptr + (offset \u0026 (PAGE_CACHE_BITS - 1)) / 32;\n \tend = pptr + PAGE_CACHE_BITS / 32;\n@@ -216,9 +230,12 @@ int hfsplus_block_free(struct super_block *sb, u32 offset, u32 count)\n \t\t\tbreak;\n \t\tset_page_dirty(page);\n \t\tkunmap_local(pptr);\n+\t\tunlock_page(page);\n \t\tpage = read_mapping_page(mapping, ++pnr, NULL);\n \t\tif (IS_ERR(page))\n \t\t\tgoto kaboom;\n+\t\tlock_page(page);\n+\t\tfolio_wait_writeback(page_folio(page));\n \t\tpptr = kmap_local_page(page);\n \t\tcurr = pptr;\n \t\tend = pptr + PAGE_CACHE_BITS / 32;\n@@ -232,6 +249,7 @@ int hfsplus_block_free(struct super_block *sb, u32 offset, u32 count)\n out:\n \tset_page_dirty(page);\n \tkunmap_local(pptr);\n+\tunlock_page(page);\n \tsbi-\u003efree_blocks += len;\n \thfsplus_mark_mdb_dirty(sb);\n \tmutex_unlock(\u0026sbi-\u003ealloc_mutex);\ndiff --git a/fs/hfsplus/extents.c b/fs/hfsplus/extents.c\nindex eb7c11524d188..b724cc1ca3e1f 100644\n--- a/fs/hfsplus/extents.c\n+++ b/fs/hfsplus/extents.c\n@@ -15,6 +15,7 @@\n \n #include \"hfsplus_fs.h\"\n #include \"hfsplus_raw.h\"\n+#include \"iomap.h\"\n \n /* Compare two extents keys, returns 0 on same, pos/neg for difference */\n int hfsplus_ext_cmp_key(const hfsplus_btree_key *k1,\n@@ -48,18 +49,29 @@ static void hfsplus_ext_build_key(hfsplus_btree_key *key, u32 cnid,\n \tkey-\u003eext.pad = 0;\n }\n \n-static u32 hfsplus_ext_find_block(struct hfsplus_extent *ext, u32 off)\n+/*\n+ * hfsplus_ext_find_block() - find contiguous sequence of block\n+ *\n+ * Find the disk allocation block for 'off' within an 8-entry\n+ * extent record, and the number of further allocation blocks\n+ * that are contiguous with it in the same extent entry.\n+ */\n+static u32 hfsplus_ext_find_block(struct hfsplus_extent *ext, u32 off,\n+\t\t\t\t u32 *dblock)\n {\n \tint i;\n \tu32 count;\n \n-\tfor (i = 0; i \u003c 8; ext++, i++) {\n+\tfor (i = 0; i \u003c HFSPLUS_FORK_EXTENT_COUNT; ext++, i++) {\n \t\tcount = be32_to_cpu(ext-\u003eblock_count);\n-\t\tif (off \u003c count)\n-\t\t\treturn be32_to_cpu(ext-\u003estart_block) + off;\n+\t\tif (off \u003c count) {\n+\t\t\t*dblock = be32_to_cpu(ext-\u003estart_block) + off;\n+\t\t\treturn count - off;\n+\t\t}\n \t\toff -= count;\n \t}\n \t/* panic? */\n+\t*dblock = 0;\n \treturn 0;\n }\n \n@@ -68,7 +80,7 @@ static int hfsplus_ext_block_count(struct hfsplus_extent *ext)\n \tint i;\n \tu32 count = 0;\n \n-\tfor (i = 0; i \u003c 8; ext++, i++)\n+\tfor (i = 0; i \u003c HFSPLUS_FORK_EXTENT_COUNT; ext++, i++)\n \t\tcount += be32_to_cpu(ext-\u003eblock_count);\n \treturn count;\n }\n@@ -225,37 +237,48 @@ static int hfsplus_ext_read_extent(struct inode *inode, u32 block)\n \treturn res;\n }\n \n-/* Get a block at iblock for inode, possibly allocating if create */\n-int hfsplus_get_block(struct inode *inode, sector_t iblock,\n-\t\t      struct buffer_head *bh_result, int create)\n+/*\n+ * hfsplus_map_extent() - find or allocate a sequence of allocation blocks\n+ *\n+ * Looks up the allocation block at 'ablock' for inode, extending the\n+ * file (via hfsplus_file_extend(), in clump_blocks-sized chunks) when\n+ * 'create' is set and 'ablock' lies beyond the current allocation.\n+ *\n+ * On success, *dblock is the disk allocation block backing 'ablock',\n+ * and *max_blocks is the number of further allocation blocks that are\n+ * contiguous with it (i.e. the remaining length of the extent entry\n+ * that contains 'ablock'), which may be smaller than the whole file's\n+ * remaining allocation when the fork is fragmented across several\n+ * extent entries. If a new extent had to be allocated to satisfy the\n+ * request, *balloc (when non-NULL) is set to true.\n+ */\n+int hfsplus_map_extent(struct inode *inode, u32 ablock, int create,\n+\t\t\tu32 *dblock, u32 *max_blocks, bool *balloc)\n {\n-\tstruct super_block *sb = inode-\u003ei_sb;\n-\tstruct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);\n \tstruct hfsplus_inode_info *hip = HFSPLUS_I(inode);\n-\tint res = -EIO;\n-\tu32 ablock, dblock, mask;\n-\tsector_t sector;\n-\tint was_dirty = 0;\n+\tint was_dirty;\n+\tint res;\n \n-\t/* Convert inode block to disk allocation block */\n-\tablock = iblock \u003e\u003e sbi-\u003efs_shift;\n+\tif (balloc)\n+\t\t*balloc = false;\n \n-\tif (iblock \u003e= hip-\u003efs_blocks) {\n+\tif (ablock \u003e= hip-\u003ealloc_blocks) {\n \t\tif (!create)\n-\t\t\treturn 0;\n-\t\tif (iblock \u003e hip-\u003efs_blocks)\n \t\t\treturn -EIO;\n-\t\tif (ablock \u003e= hip-\u003ealloc_blocks) {\n-\t\t\tres = hfsplus_file_extend(inode, false);\n-\t\t\tif (res)\n-\t\t\t\treturn res;\n-\t\t}\n-\t} else\n-\t\tcreate = 0;\n+\t\tres = hfsplus_file_extend(inode, false);\n+\t\tif (res)\n+\t\t\treturn res;\n+\t\tif (balloc)\n+\t\t\t*balloc = true;\n+\t}\n \n \tif (ablock \u003c hip-\u003efirst_blocks) {\n-\t\tdblock = hfsplus_ext_find_block(hip-\u003efirst_extents, ablock);\n-\t\tgoto done;\n+\t\t*max_blocks = hfsplus_ext_find_block(hip-\u003efirst_extents,\n+\t\t\t\t\t\t     ablock,\n+\t\t\t\t\t\t     dblock);\n+\t\tif (!*max_blocks)\n+\t\t\treturn -EIO;\n+\t\treturn 0;\n \t}\n \n \tif (inode-\u003ei_ino == HFSPLUS_EXT_CNID)\n@@ -274,11 +297,47 @@ int hfsplus_get_block(struct inode *inode, sector_t iblock,\n \t\tmutex_unlock(\u0026hip-\u003eextents_lock);\n \t\treturn -EIO;\n \t}\n-\tdblock = hfsplus_ext_find_block(hip-\u003ecached_extents,\n-\t\t\t\t\tablock - hip-\u003ecached_start);\n+\t*max_blocks = hfsplus_ext_find_block(hip-\u003ecached_extents,\n+\t\t\t\t\t     ablock - hip-\u003ecached_start,\n+\t\t\t\t\t     dblock);\n \tmutex_unlock(\u0026hip-\u003eextents_lock);\n \n-done:\n+\tif (was_dirty)\n+\t\tmark_inode_dirty(inode);\n+\n+\tif (!*max_blocks)\n+\t\treturn -EIO;\n+\n+\treturn 0;\n+}\n+\n+/* Get a block at iblock for inode, possibly allocating if create */\n+int hfsplus_get_block(struct inode *inode, sector_t iblock,\n+\t\t      struct buffer_head *bh_result, int create)\n+{\n+\tstruct super_block *sb = inode-\u003ei_sb;\n+\tstruct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);\n+\tstruct hfsplus_inode_info *hip = HFSPLUS_I(inode);\n+\tu32 ablock, dblock, mask, max_blocks;\n+\tsector_t sector;\n+\tint res;\n+\n+\t/* Convert inode block to disk allocation block */\n+\tablock = iblock \u003e\u003e sbi-\u003efs_shift;\n+\n+\tif (iblock \u003e= hip-\u003efs_blocks) {\n+\t\tif (!create)\n+\t\t\treturn 0;\n+\t\tif (iblock \u003e hip-\u003efs_blocks)\n+\t\t\treturn -EIO;\n+\t} else\n+\t\tcreate = 0;\n+\n+\tres = hfsplus_map_extent(inode, ablock, create, \u0026dblock, \u0026max_blocks,\n+\t\t\t\t  NULL);\n+\tif (res)\n+\t\treturn res;\n+\n \thfs_dbg(\"ino %llu, iblock %llu - dblock %u\\n\",\n \t\tinode-\u003ei_ino, (long long)iblock, dblock);\n \n@@ -289,12 +348,11 @@ int hfsplus_get_block(struct inode *inode, sector_t iblock,\n \n \tif (create) {\n \t\tset_buffer_new(bh_result);\n-\t\thip-\u003ephys_size += sb-\u003es_blocksize;\n+\t\thip-\u003ephys_size = (loff_t)(iblock + 1) \u003c\u003c sb-\u003es_blocksize_bits;\n \t\thip-\u003efs_blocks++;\n \t\tinode_add_bytes(inode, sb-\u003es_blocksize);\n-\t}\n-\tif (create || was_dirty)\n \t\tmark_inode_dirty(inode);\n+\t}\n \treturn 0;\n }\n \n@@ -555,20 +613,33 @@ void hfsplus_file_truncate(struct inode *inode)\n \t\tinode-\u003ei_ino, (long long)hip-\u003ephys_size, inode-\u003ei_size);\n \n \tif (inode-\u003ei_size \u003e hip-\u003ephys_size) {\n-\t\tstruct address_space *mapping = inode-\u003ei_mapping;\n-\t\tstruct folio *folio;\n-\t\tvoid *fsdata = NULL;\n-\t\tloff_t size = inode-\u003ei_size;\n+\t\tif (S_ISREG(inode-\u003ei_mode)) {\n+\t\t\tres = hfsplus_iomap_cont_expand(inode, hip-\u003ephys_size,\n+\t\t\t\t\t\t\tinode-\u003ei_size);\n+\t\t\tif (res)\n+\t\t\t\treturn;\n+\n+\t\t\tmark_inode_dirty(inode);\n+\t\t} else {\n+\t\t\tstruct address_space *mapping = inode-\u003ei_mapping;\n+\t\t\tstruct folio *folio;\n+\t\t\tvoid *fsdata = NULL;\n+\n+\t\t\tres = hfsplus_write_begin(NULL, mapping,\n+\t\t\t\t\t\t  inode-\u003ei_size, 0,\n+\t\t\t\t\t\t  \u0026folio, \u0026fsdata);\n+\t\t\tif (res)\n+\t\t\t\treturn;\n+\n+\t\t\tres = generic_write_end(NULL, mapping,\n+\t\t\t\t\t\tinode-\u003ei_size, 0, 0,\n+\t\t\t\t\t\tfolio, fsdata);\n+\t\t\tif (res \u003c 0)\n+\t\t\t\treturn;\n+\n+\t\t\tmark_inode_dirty(inode);\n+\t\t}\n \n-\t\tres = hfsplus_write_begin(NULL, mapping, size, 0,\n-\t\t\t\t\t  \u0026folio, \u0026fsdata);\n-\t\tif (res)\n-\t\t\treturn;\n-\t\tres = generic_write_end(NULL, mapping, size, 0, 0,\n-\t\t\t\t\tfolio, fsdata);\n-\t\tif (res \u003c 0)\n-\t\t\treturn;\n-\t\tmark_inode_dirty(inode);\n \t\treturn;\n \t} else if (inode-\u003ei_size == hip-\u003ephys_size)\n \t\treturn;\ndiff --git a/fs/hfsplus/file.c b/fs/hfsplus/file.c\nnew file mode 100644\nindex 0000000000000..0b0ae6b6e307f\n--- /dev/null\n+++ b/fs/hfsplus/file.c\n@@ -0,0 +1,304 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * File operations: open/release/fsync and iomap-based read/write/seek\n+ */\n+\n+#include \u003clinux/fs.h\u003e\n+#include \u003clinux/uio.h\u003e\n+#include \u003clinux/mount.h\u003e\n+#include \u003clinux/iomap.h\u003e\n+\n+#include \"hfsplus_fs.h\"\n+#include \"hfsplus_raw.h\"\n+#include \"iomap.h\"\n+\n+static int hfsplus_file_open(struct inode *inode, struct file *file)\n+{\n+\tif (HFSPLUS_IS_RSRC(inode))\n+\t\tinode = HFSPLUS_I(inode)-\u003ersrc_inode;\n+\tif (!(file-\u003ef_flags \u0026 O_LARGEFILE) \u0026\u0026 i_size_read(inode) \u003e MAX_NON_LFS)\n+\t\treturn -EOVERFLOW;\n+\tatomic_inc(\u0026HFSPLUS_I(inode)-\u003eopencnt);\n+\tfile-\u003ef_mode |= FMODE_CAN_ODIRECT;\n+\treturn 0;\n+}\n+\n+static int hfsplus_file_release(struct inode *inode, struct file *file)\n+{\n+\tstruct super_block *sb = inode-\u003ei_sb;\n+\n+\tif (HFSPLUS_IS_RSRC(inode))\n+\t\tinode = HFSPLUS_I(inode)-\u003ersrc_inode;\n+\tif (atomic_dec_and_test(\u0026HFSPLUS_I(inode)-\u003eopencnt)) {\n+\t\tinode_lock(inode);\n+\t\thfsplus_file_truncate(inode);\n+\t\tif (inode-\u003ei_flags \u0026 S_DEAD) {\n+\t\t\thfsplus_delete_cat(inode-\u003ei_ino,\n+\t\t\t\t\t   HFSPLUS_SB(sb)-\u003ehidden_dir, NULL);\n+\t\t\thfsplus_delete_inode(inode);\n+\t\t}\n+\t\tinode_unlock(inode);\n+\t}\n+\treturn 0;\n+}\n+\n+int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,\n+\t\t       int datasync)\n+{\n+\tstruct inode *inode = file-\u003ef_mapping-\u003ehost;\n+\tstruct hfsplus_inode_info *hip = HFSPLUS_I(inode);\n+\tstruct super_block *sb = inode-\u003ei_sb;\n+\tstruct hfsplus_sb_info *sbi = HFSPLUS_SB(inode-\u003ei_sb);\n+\tstruct hfsplus_vh *vhdr = sbi-\u003es_vhdr;\n+\tint error = 0, error2;\n+\n+\thfs_dbg(\"inode-\u003ei_ino %llu, start %llu, end %llu\\n\",\n+\t\tinode-\u003ei_ino, start, end);\n+\n+\terror = file_write_and_wait_range(file, start, end);\n+\tif (error)\n+\t\treturn error;\n+\n+\t/*\n+\t * Sync inode metadata into the catalog and extent trees.\n+\t */\n+\tsync_inode_metadata(inode, 1);\n+\n+\t/*\n+\t * And explicitly write out the btrees.\n+\t */\n+\tif (test_and_clear_bit(HFSPLUS_I_CAT_DIRTY,\n+\t\t\t\t\u0026HFSPLUS_I(HFSPLUS_CAT_TREE_I(sb))-\u003eflags)) {\n+\t\tclear_bit(HFSPLUS_I_CAT_DIRTY, \u0026hip-\u003eflags);\n+\t\terror = filemap_write_and_wait(sbi-\u003ecat_tree-\u003einode-\u003ei_mapping);\n+\t}\n+\n+\tif (test_and_clear_bit(HFSPLUS_I_EXT_DIRTY,\n+\t\t\t\t\u0026HFSPLUS_I(HFSPLUS_EXT_TREE_I(sb))-\u003eflags)) {\n+\t\tclear_bit(HFSPLUS_I_EXT_DIRTY, \u0026hip-\u003eflags);\n+\t\terror2 =\n+\t\t\tfilemap_write_and_wait(sbi-\u003eext_tree-\u003einode-\u003ei_mapping);\n+\t\tif (!error)\n+\t\t\terror = error2;\n+\t}\n+\n+\tif (sbi-\u003eattr_tree) {\n+\t\tif (test_and_clear_bit(HFSPLUS_I_ATTR_DIRTY,\n+\t\t\t\t\u0026HFSPLUS_I(HFSPLUS_ATTR_TREE_I(sb))-\u003eflags)) {\n+\t\t\tclear_bit(HFSPLUS_I_ATTR_DIRTY, \u0026hip-\u003eflags);\n+\t\t\terror2 =\n+\t\t\t\tfilemap_write_and_wait(\n+\t\t\t\t\t    sbi-\u003eattr_tree-\u003einode-\u003ei_mapping);\n+\t\t\tif (!error)\n+\t\t\t\terror = error2;\n+\t\t}\n+\t} else {\n+\t\tif (test_and_clear_bit(HFSPLUS_I_ATTR_DIRTY, \u0026hip-\u003eflags))\n+\t\t\tpr_err(\"sync non-existent attributes tree\\n\");\n+\t}\n+\n+\tif (test_and_clear_bit(HFSPLUS_I_ALLOC_DIRTY,\n+\t\t\t\t\u0026HFSPLUS_I(sbi-\u003ealloc_file)-\u003eflags)) {\n+\t\tclear_bit(HFSPLUS_I_ALLOC_DIRTY, \u0026hip-\u003eflags);\n+\t\terror2 = filemap_write_and_wait(sbi-\u003ealloc_file-\u003ei_mapping);\n+\t\tif (!error)\n+\t\t\terror = error2;\n+\t}\n+\n+\tmutex_lock(\u0026sbi-\u003evh_mutex);\n+\thfsplus_prepare_volume_header_for_commit(vhdr);\n+\tmutex_unlock(\u0026sbi-\u003evh_mutex);\n+\n+\terror2 = hfsplus_commit_superblock(inode-\u003ei_sb);\n+\tif (!error)\n+\t\terror = error2;\n+\n+\tif (!test_bit(HFSPLUS_SB_NOBARRIER, \u0026sbi-\u003eflags))\n+\t\tblkdev_issue_flush(inode-\u003ei_sb-\u003es_bdev);\n+\n+\treturn error;\n+}\n+\n+/*\n+ * hfsplus_fallback_buffered_write() - fall back to buffered I/O for the\n+ * tail of a write that iomap_dio_rw() could not perform directly\n+ * (unaligned tail, or no blocks could be mapped without allocation\n+ * outside the direct path).\n+ */\n+static ssize_t hfsplus_fallback_buffered_write(struct kiocb *iocb,\n+\t\t\t\t\t\tstruct iov_iter *from)\n+{\n+\tloff_t offset = iocb-\u003eki_pos, end;\n+\tssize_t written;\n+\tint ret;\n+\n+\tiocb-\u003eki_flags \u0026= ~IOCB_DIRECT;\n+\n+\twritten = iomap_file_buffered_write(iocb, from,\n+\t\t\t\t\t    \u0026hfsplus_write_iomap_ops,\n+\t\t\t\t\t    NULL, NULL);\n+\tif (written \u003c 0)\n+\t\treturn written;\n+\n+\tend = iocb-\u003eki_pos + written - 1;\n+\tret = filemap_write_and_wait_range(iocb-\u003eki_filp-\u003ef_mapping,\n+\t\t\t\t\t   offset, end);\n+\tif (ret)\n+\t\treturn -EIO;\n+\n+\tinvalidate_mapping_pages(iocb-\u003eki_filp-\u003ef_mapping,\n+\t\t\t\t offset \u003e\u003e PAGE_SHIFT,\n+\t\t\t\t end \u003e\u003e PAGE_SHIFT);\n+\n+\treturn written;\n+}\n+\n+static ssize_t hfsplus_dio_write_iter(struct kiocb *iocb,\n+\t\t\t\t\tstruct iov_iter *from,\n+\t\t\t\t\tunsigned int dio_flags)\n+{\n+\tssize_t ret;\n+\n+\tret = iomap_dio_rw(iocb, from,\n+\t\t\t   \u0026hfsplus_write_iomap_ops,\n+\t\t\t   \u0026hfsplus_write_dio_ops,\n+\t\t\t   dio_flags, NULL, 0);\n+\tif (ret == -ENOTBLK)\n+\t\tret = 0;\n+\telse if (ret \u003c 0)\n+\t\treturn ret;\n+\n+\tif (iov_iter_count(from)) {\n+\t\tssize_t written;\n+\n+\t\twritten = hfsplus_fallback_buffered_write(iocb, from);\n+\t\tif (written \u003c 0)\n+\t\t\treturn written;\n+\t\tret += written;\n+\t}\n+\n+\treturn ret;\n+}\n+\n+static ssize_t hfsplus_file_write_iter(struct kiocb *iocb,\n+\t\t\t\t\tstruct iov_iter *iter)\n+{\n+\tstruct file *file = iocb-\u003eki_filp;\n+\tstruct inode *inode = file_inode(file);\n+\tstruct hfsplus_sb_info *sbi = HFSPLUS_SB(inode-\u003ei_sb);\n+\tloff_t total_capacity;\n+\tssize_t ret;\n+\tint err;\n+\n+\tinode_lock(inode);\n+\n+\tret = generic_write_checks(iocb, iter);\n+\tif (ret \u003c= 0)\n+\t\tgoto unlock;\n+\n+\ttotal_capacity = (loff_t)sbi-\u003etotal_blocks \u003c\u003c sbi-\u003ealloc_blksz_shift;\n+\tif (iocb-\u003eki_pos \u003e= total_capacity) {\n+\t\tret = -EFBIG;\n+\t\tgoto unlock;\n+\t}\n+\n+\terr = file_modified(file);\n+\tif (err) {\n+\t\tret = err;\n+\t\tgoto unlock;\n+\t}\n+\n+\tif (iocb-\u003eki_pos \u003e i_size_read(inode)) {\n+\t\tloff_t old_size = i_size_read(inode);\n+\n+\t\ti_size_write(inode, iocb-\u003eki_pos);\n+\t\terr = hfsplus_iomap_cont_expand(inode, old_size, iocb-\u003eki_pos);\n+\t\tif (err) {\n+\t\t\ti_size_write(inode, old_size);\n+\t\t\tret = err;\n+\t\t\tgoto unlock;\n+\t\t}\n+\t\tmark_inode_dirty(inode);\n+\t}\n+\n+\tif (iocb-\u003eki_flags \u0026 IOCB_DIRECT) {\n+\t\tunsigned int dio_flags = 0;\n+\n+\t\tif (iocb-\u003eki_pos + iov_iter_count(iter) \u003e\n+\t\t    HFSPLUS_I(inode)-\u003ephys_size)\n+\t\t\tdio_flags |= IOMAP_DIO_FORCE_WAIT;\n+\n+\t\tret = hfsplus_dio_write_iter(iocb, iter, dio_flags);\n+\t} else {\n+\t\tret = iomap_file_buffered_write(iocb, iter,\n+\t\t\t\t\t\t\u0026hfsplus_write_iomap_ops,\n+\t\t\t\t\t\tNULL, NULL);\n+\t}\n+\n+unlock:\n+\tinode_unlock(inode);\n+\n+\tif (ret \u003e 0)\n+\t\tret = generic_write_sync(iocb, ret);\n+\n+\treturn ret;\n+}\n+\n+static ssize_t hfsplus_file_read_iter(struct kiocb *iocb,\n+\t\t\t\t\tstruct iov_iter *iter)\n+{\n+\tstruct inode *inode = file_inode(iocb-\u003eki_filp);\n+\tssize_t ret;\n+\n+\tinode_lock_shared(inode);\n+\n+\tif (iocb-\u003eki_flags \u0026 IOCB_DIRECT) {\n+\t\tfile_accessed(iocb-\u003eki_filp);\n+\t\tret = iomap_dio_rw(iocb, iter,\n+\t\t\t\t   \u0026hfsplus_iomap_ops,\n+\t\t\t\t   NULL, 0, NULL, 0);\n+\t} else\n+\t\tret = generic_file_read_iter(iocb, iter);\n+\n+\tinode_unlock_shared(inode);\n+\n+\treturn ret;\n+}\n+\n+static loff_t hfsplus_file_llseek(struct file *file, loff_t offset, int whence)\n+{\n+\tstruct inode *inode = file-\u003ef_mapping-\u003ehost;\n+\n+\tswitch (whence) {\n+\tcase SEEK_HOLE:\n+\t\tinode_lock_shared(inode);\n+\t\toffset = iomap_seek_hole(inode, offset, \u0026hfsplus_iomap_ops);\n+\t\tinode_unlock_shared(inode);\n+\t\tbreak;\n+\tcase SEEK_DATA:\n+\t\tinode_lock_shared(inode);\n+\t\toffset = iomap_seek_data(inode, offset, \u0026hfsplus_iomap_ops);\n+\t\tinode_unlock_shared(inode);\n+\t\tbreak;\n+\tdefault:\n+\t\treturn generic_file_llseek(file, offset, whence);\n+\t}\n+\n+\tif (offset \u003c 0)\n+\t\treturn offset;\n+\n+\treturn vfs_setpos(file, offset, inode-\u003ei_sb-\u003es_maxbytes);\n+}\n+\n+const struct file_operations hfsplus_file_operations = {\n+\t.llseek\t\t= hfsplus_file_llseek,\n+\t.read_iter\t= hfsplus_file_read_iter,\n+\t.write_iter\t= hfsplus_file_write_iter,\n+\t.mmap_prepare\t= generic_file_mmap_prepare,\n+\t.splice_read\t= filemap_splice_read,\n+\t.splice_write\t= iter_file_splice_write,\n+\t.fsync\t\t= hfsplus_file_fsync,\n+\t.open\t\t= hfsplus_file_open,\n+\t.release\t= hfsplus_file_release,\n+\t.unlocked_ioctl = hfsplus_ioctl,\n+};\ndiff --git a/fs/hfsplus/hfsplus_fs.h b/fs/hfsplus/hfsplus_fs.h\nindex 1e5b58e6a13fc..844027679a750 100644\n--- a/fs/hfsplus/hfsplus_fs.h\n+++ b/fs/hfsplus/hfsplus_fs.h\n@@ -175,6 +175,22 @@ static inline struct hfsplus_sb_info *HFSPLUS_SB(struct super_block *sb)\n \treturn sb-\u003es_fs_info;\n }\n \n+/*\n+ * Physical byte offset of allocation block 'dblock' on the volume.\n+ */\n+static inline loff_t hfsplus_ablock_to_phys_bytes(struct super_block *sb,\n+\t\t\t\t\t\t  u32 dblock)\n+{\n+\tstruct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);\n+\tloff_t phys_bytes;\n+\n+\tphys_bytes = dblock;\n+\tphys_bytes \u003c\u003c= sbi-\u003efs_shift;\n+\tphys_bytes += sbi-\u003eblockoffset;\n+\tphys_bytes \u003c\u003c= sb-\u003es_blocksize_bits;\n+\n+\treturn phys_bytes;\n+}\n \n struct hfsplus_inode_info {\n \tatomic_t opencnt;\n@@ -430,12 +446,19 @@ int hfsplus_rename_cat(u32 cnid, struct inode *src_dir, const struct qstr *src_n\n extern const struct inode_operations hfsplus_dir_inode_operations;\n extern const struct file_operations hfsplus_dir_operations;\n \n+/* file.c */\n+extern const struct file_operations hfsplus_file_operations;\n+int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,\n+\t\t       int datasync);\n+\n /* extents.c */\n int hfsplus_ext_cmp_key(const hfsplus_btree_key *k1,\n \t\t\tconst hfsplus_btree_key *k2);\n int hfsplus_ext_write_extent(struct inode *inode);\n int hfsplus_get_block(struct inode *inode, sector_t iblock,\n \t\t      struct buffer_head *bh_result, int create);\n+int hfsplus_map_extent(struct inode *inode, u32 ablock, int create,\n+\t\t\tu32 *dblock, u32 *max_blocks, bool *balloc);\n int hfsplus_free_fork(struct super_block *sb, u32 cnid,\n \t\t      struct hfsplus_fork_raw *fork, int type);\n int hfsplus_file_extend(struct inode *inode, bool zeroout);\n@@ -443,6 +466,7 @@ void hfsplus_file_truncate(struct inode *inode);\n \n /* inode.c */\n extern const struct address_space_operations hfsplus_aops;\n+extern const struct address_space_operations hfsplus_symlink_aops;\n extern const struct address_space_operations hfsplus_btree_aops;\n extern const struct dentry_operations hfsplus_dentry_operations;\n \n@@ -462,8 +486,6 @@ int hfsplus_cat_write_inode(struct inode *inode);\n int hfsplus_getattr(struct mnt_idmap *idmap, const struct path *path,\n \t\t    struct kstat *stat, u32 request_mask,\n \t\t    unsigned int query_flags);\n-int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,\n-\t\t       int datasync);\n int hfsplus_fileattr_get(struct dentry *dentry, struct file_kattr *fa);\n int hfsplus_fileattr_set(struct mnt_idmap *idmap,\n \t\t\t struct dentry *dentry, struct file_kattr *fa);\ndiff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c\nindex 2ce6de574fa6e..1779061dcad5b 100644\n--- a/fs/hfsplus/inode.c\n+++ b/fs/hfsplus/inode.c\n@@ -18,15 +18,12 @@\n #include \u003clinux/cred.h\u003e\n #include \u003clinux/uio.h\u003e\n #include \u003clinux/fileattr.h\u003e\n+#include \u003clinux/iomap.h\u003e\n \n #include \"hfsplus_fs.h\"\n #include \"hfsplus_raw.h\"\n #include \"xattr.h\"\n-\n-static int hfsplus_read_folio(struct file *file, struct folio *folio)\n-{\n-\treturn block_read_full_folio(folio, hfsplus_get_block);\n-}\n+#include \"iomap.h\"\n \n static void hfsplus_write_failed(struct address_space *mapping, loff_t to)\n {\n@@ -128,67 +125,13 @@ static bool hfsplus_release_folio(struct folio *folio, gfp_t mask)\n \treturn res ? try_to_free_buffers(folio) : false;\n }\n \n-static ssize_t hfsplus_direct_IO(struct kiocb *iocb, struct iov_iter *iter)\n+static int hfsplus_btree_read_folio(struct file *file, struct folio *folio)\n {\n-\tstruct file *file = iocb-\u003eki_filp;\n-\tstruct address_space *mapping = file-\u003ef_mapping;\n-\tstruct inode *inode = mapping-\u003ehost;\n-\tloff_t isize;\n-\tsize_t count = iov_iter_count(iter);\n-\tloff_t end = iocb-\u003eki_pos + count;\n-\tssize_t ret;\n-\n-\t/*\n-\t * The hfsplus_get_block() only allows creating the next sequential block.\n-\t * For direct writes beyond EOF, expand the file first.\n-\t */\n-\tif (iov_iter_rw(iter) == WRITE \u0026\u0026 iocb-\u003eki_pos \u003e i_size_read(inode)) {\n-\t\tloff_t start_off, end_off;\n-\t\tloff_t start_page, end_page;\n-\n-\t\tisize = i_size_read(inode);\n-\n-\t\t/*\n-\t\t * Wait for any in-flight DIO on this inode to finish before\n-\t\t * calling generic_cont_expand_simple().\n-\t\t */\n-\t\tinode_dio_wait(inode);\n-\n-\t\tret = generic_cont_expand_simple(inode, iocb-\u003eki_pos);\n-\t\tif (ret)\n-\t\t\treturn ret;\n-\n-\t\tstart_off = isize;\n-\t\tend_off = (end \u003e 0) ? end - 1 : end;\n-\n-\t\tret = filemap_write_and_wait_range(mapping, start_off, end_off);\n-\t\tif (ret)\n-\t\t\treturn ret;\n-\n-\t\tstart_page = start_off \u003e\u003e PAGE_SHIFT;\n-\t\tend_page = end_off \u003e\u003e PAGE_SHIFT;\n-\n-\t\tinvalidate_inode_pages2_range(mapping, start_page, end_page);\n-\t}\n-\n-\tret = blockdev_direct_IO(iocb, inode, iter, hfsplus_get_block);\n-\n-\t/*\n-\t * In case of error extending write may have instantiated a few\n-\t * blocks outside i_size. Trim these off again.\n-\t */\n-\tif (unlikely(iov_iter_rw(iter) == WRITE \u0026\u0026 ret \u003c 0)) {\n-\t\tisize = i_size_read(inode);\n-\n-\t\tif (end \u003e isize)\n-\t\t\thfsplus_write_failed(mapping, end);\n-\t}\n-\n-\treturn ret;\n+\treturn block_read_full_folio(folio, hfsplus_get_block);\n }\n \n-static int hfsplus_writepages(struct address_space *mapping,\n-\t\t\t      struct writeback_control *wbc)\n+static int hfsplus_btree_writepages(struct address_space *mapping,\n+\t\t\t\t    struct writeback_control *wbc)\n {\n \treturn mpage_writepages(mapping, wbc, hfsplus_get_block);\n }\n@@ -196,8 +139,8 @@ static int hfsplus_writepages(struct address_space *mapping,\n const struct address_space_operations hfsplus_btree_aops = {\n \t.dirty_folio\t= block_dirty_folio,\n \t.invalidate_folio = block_invalidate_folio,\n-\t.read_folio\t= hfsplus_read_folio,\n-\t.writepages\t= hfsplus_writepages,\n+\t.read_folio\t= hfsplus_btree_read_folio,\n+\t.writepages\t= hfsplus_btree_writepages,\n \t.write_begin\t= hfsplus_write_begin,\n \t.write_end\t= generic_write_end,\n \t.migrate_folio\t= buffer_migrate_folio,\n@@ -205,18 +148,70 @@ const struct address_space_operations hfsplus_btree_aops = {\n \t.release_folio\t= hfsplus_release_folio,\n };\n \n-const struct address_space_operations hfsplus_aops = {\n+static int hfsplus_symlink_read_folio(struct file *file, struct folio *folio)\n+{\n+\treturn block_read_full_folio(folio, hfsplus_get_block);\n+}\n+\n+static int hfsplus_symlink_writepages(struct address_space *mapping,\n+\t\t\t\t      struct writeback_control *wbc)\n+{\n+\treturn mpage_writepages(mapping, wbc, hfsplus_get_block);\n+}\n+\n+const struct address_space_operations hfsplus_symlink_aops = {\n \t.dirty_folio\t= block_dirty_folio,\n \t.invalidate_folio = block_invalidate_folio,\n-\t.read_folio\t= hfsplus_read_folio,\n+\t.read_folio\t= hfsplus_symlink_read_folio,\n \t.write_begin\t= hfsplus_write_begin,\n \t.write_end\t= generic_write_end,\n \t.bmap\t\t= hfsplus_bmap,\n-\t.direct_IO\t= hfsplus_direct_IO,\n-\t.writepages\t= hfsplus_writepages,\n+\t.writepages\t= hfsplus_symlink_writepages,\n \t.migrate_folio\t= buffer_migrate_folio,\n };\n \n+static int hfsplus_read_folio(struct file *file, struct folio *folio)\n+{\n+\tiomap_bio_read_folio(folio, \u0026hfsplus_iomap_ops);\n+\treturn 0;\n+}\n+\n+static void hfsplus_readahead(struct readahead_control *rac)\n+{\n+\tiomap_bio_readahead(rac, \u0026hfsplus_iomap_ops);\n+}\n+\n+static int hfsplus_writepages(struct address_space *mapping,\n+\t\t\t      struct writeback_control *wbc)\n+{\n+\tstruct iomap_writepage_ctx wpc = {\n+\t\t.inode\t= mapping-\u003ehost,\n+\t\t.wbc\t= wbc,\n+\t\t.ops\t= \u0026hfsplus_writeback_ops,\n+\t};\n+\n+\treturn iomap_writepages(\u0026wpc);\n+}\n+\n+static sector_t hfsplus_aop_bmap(struct address_space *mapping, sector_t block)\n+{\n+\treturn iomap_bmap(mapping, block, \u0026hfsplus_iomap_ops);\n+}\n+\n+const struct address_space_operations hfsplus_aops = {\n+\t.read_folio\t\t= hfsplus_read_folio,\n+\t.readahead\t\t= hfsplus_readahead,\n+\t.writepages\t\t= hfsplus_writepages,\n+\t.dirty_folio\t\t= iomap_dirty_folio,\n+\t.bmap\t\t\t= hfsplus_aop_bmap,\n+\t.migrate_folio\t\t= filemap_migrate_folio,\n+\t.is_partially_uptodate\t= iomap_is_partially_uptodate,\n+\t.error_remove_folio\t= generic_error_remove_folio,\n+\t.release_folio\t\t= iomap_release_folio,\n+\t.invalidate_folio\t= iomap_invalidate_folio,\n+\t.swap_activate\t\t= hfsplus_iomap_swap_activate,\n+};\n+\n const struct dentry_operations hfsplus_dentry_operations = {\n \t.d_hash       = hfsplus_hash_dentry,\n \t.d_compare    = hfsplus_compare_dentry,\n@@ -276,35 +271,6 @@ static int hfsplus_get_perms(struct inode *inode,\n \treturn -EIO;\n }\n \n-static int hfsplus_file_open(struct inode *inode, struct file *file)\n-{\n-\tif (HFSPLUS_IS_RSRC(inode))\n-\t\tinode = HFSPLUS_I(inode)-\u003ersrc_inode;\n-\tif (!(file-\u003ef_flags \u0026 O_LARGEFILE) \u0026\u0026 i_size_read(inode) \u003e MAX_NON_LFS)\n-\t\treturn -EOVERFLOW;\n-\tatomic_inc(\u0026HFSPLUS_I(inode)-\u003eopencnt);\n-\treturn 0;\n-}\n-\n-static int hfsplus_file_release(struct inode *inode, struct file *file)\n-{\n-\tstruct super_block *sb = inode-\u003ei_sb;\n-\n-\tif (HFSPLUS_IS_RSRC(inode))\n-\t\tinode = HFSPLUS_I(inode)-\u003ersrc_inode;\n-\tif (atomic_dec_and_test(\u0026HFSPLUS_I(inode)-\u003eopencnt)) {\n-\t\tinode_lock(inode);\n-\t\thfsplus_file_truncate(inode);\n-\t\tif (inode-\u003ei_flags \u0026 S_DEAD) {\n-\t\t\thfsplus_delete_cat(inode-\u003ei_ino,\n-\t\t\t\t\t   HFSPLUS_SB(sb)-\u003ehidden_dir, NULL);\n-\t\t\thfsplus_delete_inode(inode);\n-\t\t}\n-\t\tinode_unlock(inode);\n-\t}\n-\treturn 0;\n-}\n-\n static int hfsplus_setattr(struct mnt_idmap *idmap,\n \t\t\t   struct dentry *dentry, struct iattr *attr)\n {\n@@ -319,13 +285,28 @@ static int hfsplus_setattr(struct mnt_idmap *idmap,\n \t    attr-\u003eia_size != i_size_read(inode)) {\n \t\tinode_dio_wait(inode);\n \t\tif (attr-\u003eia_size \u003e inode-\u003ei_size) {\n-\t\t\terror = generic_cont_expand_simple(inode,\n-\t\t\t\t\t\t\t   attr-\u003eia_size);\n+\t\t\tloff_t old_size = inode-\u003ei_size;\n+\n+\t\t\ti_size_write(inode, attr-\u003eia_size);\n+\t\t\terror = hfsplus_iomap_cont_expand(inode, old_size,\n+\t\t\t\t\t\t\t  attr-\u003eia_size);\n+\t\t\tif (error) {\n+\t\t\t\ti_size_write(inode, old_size);\n+\t\t\t\treturn error;\n+\t\t\t}\n+\t\t\ttruncate_setsize(inode, attr-\u003eia_size);\n+\t\t} else {\n+\t\t\tbool did_zero = false;\n+\n+\t\t\terror = iomap_truncate_page(inode, attr-\u003eia_size,\n+\t\t\t\t\t\t    \u0026did_zero,\n+\t\t\t\t\t\t    \u0026hfsplus_write_iomap_ops,\n+\t\t\t\t\t\t    NULL, NULL);\n \t\t\tif (error)\n \t\t\t\treturn error;\n+\t\t\ttruncate_setsize(inode, attr-\u003eia_size);\n+\t\t\thfsplus_file_truncate(inode);\n \t\t}\n-\t\ttruncate_setsize(inode, attr-\u003eia_size);\n-\t\thfsplus_file_truncate(inode);\n \t\tinode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));\n \t}\n \n@@ -361,86 +342,6 @@ int hfsplus_getattr(struct mnt_idmap *idmap, const struct path *path,\n \treturn 0;\n }\n \n-int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,\n-\t\t       int datasync)\n-{\n-\tstruct inode *inode = file-\u003ef_mapping-\u003ehost;\n-\tstruct hfsplus_inode_info *hip = HFSPLUS_I(inode);\n-\tstruct super_block *sb = inode-\u003ei_sb;\n-\tstruct hfsplus_sb_info *sbi = HFSPLUS_SB(inode-\u003ei_sb);\n-\tstruct hfsplus_vh *vhdr = sbi-\u003es_vhdr;\n-\tint error = 0, error2;\n-\n-\thfs_dbg(\"inode-\u003ei_ino %llu, start %llu, end %llu\\n\",\n-\t\tinode-\u003ei_ino, start, end);\n-\n-\terror = file_write_and_wait_range(file, start, end);\n-\tif (error)\n-\t\treturn error;\n-\tinode_lock(inode);\n-\n-\t/*\n-\t * Sync inode metadata into the catalog and extent trees.\n-\t */\n-\tsync_inode_metadata(inode, 1);\n-\n-\t/*\n-\t * And explicitly write out the btrees.\n-\t */\n-\tif (test_and_clear_bit(HFSPLUS_I_CAT_DIRTY,\n-\t\t\t\t\u0026HFSPLUS_I(HFSPLUS_CAT_TREE_I(sb))-\u003eflags)) {\n-\t\tclear_bit(HFSPLUS_I_CAT_DIRTY, \u0026hip-\u003eflags);\n-\t\terror = filemap_write_and_wait(sbi-\u003ecat_tree-\u003einode-\u003ei_mapping);\n-\t}\n-\n-\tif (test_and_clear_bit(HFSPLUS_I_EXT_DIRTY,\n-\t\t\t\t\u0026HFSPLUS_I(HFSPLUS_EXT_TREE_I(sb))-\u003eflags)) {\n-\t\tclear_bit(HFSPLUS_I_EXT_DIRTY, \u0026hip-\u003eflags);\n-\t\terror2 =\n-\t\t\tfilemap_write_and_wait(sbi-\u003eext_tree-\u003einode-\u003ei_mapping);\n-\t\tif (!error)\n-\t\t\terror = error2;\n-\t}\n-\n-\tif (sbi-\u003eattr_tree) {\n-\t\tif (test_and_clear_bit(HFSPLUS_I_ATTR_DIRTY,\n-\t\t\t\t\u0026HFSPLUS_I(HFSPLUS_ATTR_TREE_I(sb))-\u003eflags)) {\n-\t\t\tclear_bit(HFSPLUS_I_ATTR_DIRTY, \u0026hip-\u003eflags);\n-\t\t\terror2 =\n-\t\t\t\tfilemap_write_and_wait(\n-\t\t\t\t\t    sbi-\u003eattr_tree-\u003einode-\u003ei_mapping);\n-\t\t\tif (!error)\n-\t\t\t\terror = error2;\n-\t\t}\n-\t} else {\n-\t\tif (test_and_clear_bit(HFSPLUS_I_ATTR_DIRTY, \u0026hip-\u003eflags))\n-\t\t\tpr_err(\"sync non-existent attributes tree\\n\");\n-\t}\n-\n-\tif (test_and_clear_bit(HFSPLUS_I_ALLOC_DIRTY,\n-\t\t\t\t\u0026HFSPLUS_I(sbi-\u003ealloc_file)-\u003eflags)) {\n-\t\tclear_bit(HFSPLUS_I_ALLOC_DIRTY, \u0026hip-\u003eflags);\n-\t\terror2 = filemap_write_and_wait(sbi-\u003ealloc_file-\u003ei_mapping);\n-\t\tif (!error)\n-\t\t\terror = error2;\n-\t}\n-\n-\tmutex_lock(\u0026sbi-\u003evh_mutex);\n-\thfsplus_prepare_volume_header_for_commit(vhdr);\n-\tmutex_unlock(\u0026sbi-\u003evh_mutex);\n-\n-\terror2 = hfsplus_commit_superblock(inode-\u003ei_sb);\n-\tif (!error)\n-\t\terror = error2;\n-\n-\tif (!test_bit(HFSPLUS_SB_NOBARRIER, \u0026sbi-\u003eflags))\n-\t\tblkdev_issue_flush(inode-\u003ei_sb-\u003es_bdev);\n-\n-\tinode_unlock(inode);\n-\n-\treturn error;\n-}\n-\n static const struct inode_operations hfsplus_file_inode_operations = {\n \t.setattr\t= hfsplus_setattr,\n \t.getattr\t= hfsplus_getattr,\n@@ -462,19 +363,6 @@ static const struct inode_operations hfsplus_special_inode_operations = {\n \t.listxattr\t= hfsplus_listxattr,\n };\n \n-static const struct file_operations hfsplus_file_operations = {\n-\t.llseek\t\t= generic_file_llseek,\n-\t.read_iter\t= generic_file_read_iter,\n-\t.write_iter\t= generic_file_write_iter,\n-\t.mmap_prepare\t= generic_file_mmap_prepare,\n-\t.splice_read\t= filemap_splice_read,\n-\t.splice_write\t= iter_file_splice_write,\n-\t.fsync\t\t= hfsplus_file_fsync,\n-\t.open\t\t= hfsplus_file_open,\n-\t.release\t= hfsplus_file_release,\n-\t.unlocked_ioctl = hfsplus_ioctl,\n-};\n-\n struct inode *hfsplus_new_inode(struct super_block *sb, struct inode *dir,\n \t\t\t\tumode_t mode)\n {\n@@ -521,7 +409,7 @@ struct inode *hfsplus_new_inode(struct super_block *sb, struct inode *dir,\n \t\tsbi-\u003efile_count++;\n \t\tinode-\u003ei_op = \u0026hfsplus_symlink_inode_operations;\n \t\tinode_nohighmem(inode);\n-\t\tinode-\u003ei_mapping-\u003ea_ops = \u0026hfsplus_aops;\n+\t\tinode-\u003ei_mapping-\u003ea_ops = \u0026hfsplus_symlink_aops;\n \t\thip-\u003eclump_blocks = 1;\n \t} else if (S_ISCHR(inode-\u003ei_mode) || S_ISBLK(inode-\u003ei_mode) ||\n \t\t   S_ISFIFO(inode-\u003ei_mode) || S_ISSOCK(inode-\u003ei_mode)) {\n@@ -662,7 +550,7 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)\n \t\t} else if (S_ISLNK(inode-\u003ei_mode)) {\n \t\t\tinode-\u003ei_op = \u0026hfsplus_symlink_inode_operations;\n \t\t\tinode_nohighmem(inode);\n-\t\t\tinode-\u003ei_mapping-\u003ea_ops = \u0026hfsplus_aops;\n+\t\t\tinode-\u003ei_mapping-\u003ea_ops = \u0026hfsplus_symlink_aops;\n \t\t} else {\n \t\t\tinode-\u003ei_op = \u0026hfsplus_special_inode_operations;\n \t\t\tinit_special_inode(inode, inode-\u003ei_mode,\ndiff --git a/fs/hfsplus/iomap.c b/fs/hfsplus/iomap.c\nnew file mode 100644\nindex 0000000000000..0eb392789126d\n--- /dev/null\n+++ b/fs/hfsplus/iomap.c\n@@ -0,0 +1,190 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * iomap callback functions for the hfsplus filesystem\n+ */\n+\n+#include \u003clinux/iomap.h\u003e\n+#include \u003clinux/pagemap.h\u003e\n+\n+#include \"hfsplus_fs.h\"\n+#include \"hfsplus_raw.h\"\n+#include \"iomap.h\"\n+\n+static int __hfsplus_iomap_begin(struct inode *inode, loff_t offset,\n+\t\t\t\t loff_t length, unsigned int flags,\n+\t\t\t\t struct iomap *iomap, bool may_alloc)\n+{\n+\tstruct super_block *sb = inode-\u003ei_sb;\n+\tstruct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);\n+\tstruct hfsplus_inode_info *hip = HFSPLUS_I(inode);\n+\tu32 ablock, dblock, max_blocks;\n+\tloff_t ablock_offset, ablock_bytes;\n+\tloff_t block_start;\n+\tbool is_new;\n+\tint err;\n+\n+\tif (!may_alloc) {\n+\t\t/* Completely beyond EOF. Treat as hole */\n+\t\tif (i_size_read(inode) \u003c= offset) {\n+\t\t\tiomap-\u003etype = IOMAP_HOLE;\n+\t\t\tiomap-\u003eaddr = IOMAP_NULL_ADDR;\n+\t\t\tiomap-\u003eoffset = offset;\n+\t\t\tiomap-\u003elength = length;\n+\t\t\treturn 0;\n+\t\t}\n+\n+\t\t/* Clamp length if the requested range goes beyond i_size */\n+\t\tif (offset + length \u003e i_size_read(inode)) {\n+\t\t\tloff_t i_size = i_size_read(inode);\n+\t\t\tunsigned int blocksize = i_blocksize(inode);\n+\n+\t\t\tlength = round_up(i_size, blocksize) - offset;\n+\t\t}\n+\t}\n+\n+\tablock = offset \u003e\u003e sbi-\u003ealloc_blksz_shift;\n+\n+\terr = hfsplus_map_extent(inode, ablock, may_alloc, \u0026dblock,\n+\t\t\t\t \u0026max_blocks, NULL);\n+\tif (err)\n+\t\treturn err;\n+\n+\tablock_offset = offset \u0026 (sbi-\u003ealloc_blksz - 1);\n+\tablock_bytes = (loff_t)max_blocks \u003c\u003c sbi-\u003ealloc_blksz_shift;\n+\n+\tlength = min_t(loff_t, length, ablock_bytes - ablock_offset);\n+\tblock_start = round_down(offset, i_blocksize(inode));\n+\tis_new = may_alloc \u0026\u0026 block_start \u003e= hip-\u003ephys_size;\n+\tif (may_alloc \u0026\u0026 !is_new \u0026\u0026 offset \u003c hip-\u003ephys_size)\n+\t\tlength = min_t(loff_t, length, hip-\u003ephys_size - offset);\n+\n+\tiomap-\u003ebdev = sb-\u003es_bdev;\n+\tiomap-\u003eoffset = offset;\n+\tiomap-\u003elength = length;\n+\tiomap-\u003eaddr = hfsplus_ablock_to_phys_bytes(sb, dblock) + ablock_offset;\n+\tiomap-\u003etype = IOMAP_MAPPED;\n+\tiomap-\u003eflags = IOMAP_F_MERGED;\n+\n+\tif (is_new)\n+\t\tiomap-\u003eflags |= IOMAP_F_NEW;\n+\n+\treturn 0;\n+}\n+\n+static int hfsplus_iomap_begin(struct inode *inode, loff_t offset,\n+\t\t\t\tloff_t length, unsigned int flags,\n+\t\t\t\tstruct iomap *iomap, struct iomap *srcmap)\n+{\n+\treturn __hfsplus_iomap_begin(inode,\n+\t\t\t\t     offset, length, flags,\n+\t\t\t\t     iomap, false);\n+}\n+\n+static int hfsplus_write_iomap_begin(struct inode *inode, loff_t offset,\n+\t\t\t\t     loff_t length, unsigned int flags,\n+\t\t\t\t     struct iomap *iomap, struct iomap *srcmap)\n+{\n+\treturn __hfsplus_iomap_begin(inode,\n+\t\t\t\t     offset, length, flags,\n+\t\t\t\t     iomap, true);\n+}\n+\n+const struct iomap_ops hfsplus_iomap_ops = {\n+\t.iomap_begin = hfsplus_iomap_begin,\n+};\n+\n+/*\n+ * hfsplus_write_iomap_end()\n+ *\n+ * Advance the allocated-and-zeroed high-water mark\n+ * (hip-\u003ephys_size / hip-\u003efs_blocks) to cover the newly written range.\n+ */\n+static int hfsplus_write_iomap_end(struct inode *inode, loff_t pos,\n+\t\t\t\t   loff_t length, ssize_t written,\n+\t\t\t\t   unsigned int flags, struct iomap *iomap)\n+{\n+\tstruct hfsplus_inode_info *hip = HFSPLUS_I(inode);\n+\tstruct super_block *sb = inode-\u003ei_sb;\n+\tloff_t end;\n+\tbool dirtied = false;\n+\n+\tif (!written)\n+\t\treturn 0;\n+\n+\tend = pos + written;\n+\n+\tif (iomap-\u003eflags \u0026 IOMAP_F_NEW)\n+\t\tend = round_up(end, sb-\u003es_blocksize);\n+\n+\tif (hip-\u003ephys_size \u003c end) {\n+\t\tinode_add_bytes(inode, end - hip-\u003ephys_size);\n+\t\thip-\u003ephys_size = end;\n+\t\thip-\u003efs_blocks = end \u003e\u003e sb-\u003es_blocksize_bits;\n+\t\tdirtied = true;\n+\t}\n+\n+\tif (dirtied)\n+\t\tmark_inode_dirty(inode);\n+\n+\treturn written;\n+}\n+\n+const struct iomap_ops hfsplus_write_iomap_ops = {\n+\t.iomap_begin\t= hfsplus_write_iomap_begin,\n+\t.iomap_end\t= hfsplus_write_iomap_end,\n+};\n+\n+/*\n+ * hfsplus_iomap_cont_expand()\n+ *\n+ * Zero the byte range [from, to) of a file that is being extended, where\n+ * 'from' is the old end-of-file and 'to' the new one. Used by the extending\n+ * write path, hfsplus_setattr() (truncate up) and hfsplus_file_truncate().\n+ */\n+int hfsplus_iomap_cont_expand(struct inode *inode, loff_t from, loff_t to)\n+{\n+\tif (to \u003c= from)\n+\t\treturn 0;\n+\n+\treturn iomap_zero_range(inode, from, to - from, NULL,\n+\t\t\t\t\u0026hfsplus_write_iomap_ops, NULL, NULL);\n+}\n+\n+/*\n+ * hfsplus_writeback_range() - map folio during writeback\n+ *\n+ * Called for each folio during writeback. If the folio falls outside\n+ * the current iomap, remaps by calling __hfsplus_iomap_begin() again.\n+ */\n+static ssize_t hfsplus_writeback_range(struct iomap_writepage_ctx *wpc,\n+\t\t\t\t\tstruct folio *folio, u64 offset,\n+\t\t\t\t\tunsigned int len, u64 end_pos)\n+{\n+\tint err;\n+\n+\tif (offset \u003c wpc-\u003eiomap.offset ||\n+\t    offset \u003e= wpc-\u003eiomap.offset + wpc-\u003eiomap.length) {\n+\t\terr = __hfsplus_iomap_begin(wpc-\u003einode,\n+\t\t\t\t\t    offset, len, 0,\n+\t\t\t\t\t    \u0026wpc-\u003eiomap, false);\n+\t\tif (err)\n+\t\t\treturn err;\n+\t}\n+\n+\treturn iomap_add_to_ioend(wpc, folio, offset, end_pos, len);\n+}\n+\n+const struct iomap_writeback_ops hfsplus_writeback_ops = {\n+\t.writeback_range\t= hfsplus_writeback_range,\n+\t.writeback_submit\t= iomap_ioend_writeback_submit,\n+};\n+\n+const struct iomap_dio_ops hfsplus_write_dio_ops = {\n+\t.end_io\t\t= iomap_dio_end_io,\n+};\n+\n+int hfsplus_iomap_swap_activate(struct swap_info_struct *sis,\n+\t\t\t\t struct file *file, sector_t *span)\n+{\n+\treturn iomap_swapfile_activate(sis, file, span, \u0026hfsplus_iomap_ops);\n+}\ndiff --git a/fs/hfsplus/iomap.h b/fs/hfsplus/iomap.h\nnew file mode 100644\nindex 0000000000000..4dd4aca1804f8\n--- /dev/null\n+++ b/fs/hfsplus/iomap.h\n@@ -0,0 +1,18 @@\n+/* SPDX-License-Identifier: GPL-2.0 */\n+/*\n+ * iomap callback declarations for the hfsplus filesystem\n+ */\n+\n+#ifndef _LINUX_HFSPLUS_IOMAP_H\n+#define _LINUX_HFSPLUS_IOMAP_H\n+\n+extern const struct iomap_ops hfsplus_iomap_ops;\n+extern const struct iomap_ops hfsplus_write_iomap_ops;\n+extern const struct iomap_writeback_ops hfsplus_writeback_ops;\n+extern const struct iomap_dio_ops hfsplus_write_dio_ops;\n+\n+int hfsplus_iomap_cont_expand(struct inode *inode, loff_t from, loff_t to);\n+int hfsplus_iomap_swap_activate(struct swap_info_struct *sis,\n+\t\t\t\tstruct file *file, sector_t *span);\n+\n+#endif /* _LINUX_HFSPLUS_IOMAP_H */\ndiff --git a/include/linux/hfs_common.h b/include/linux/hfs_common.h\nindex d6a615e74b26e..8673933bbee56 100644\n--- a/include/linux/hfs_common.h\n+++ b/include/linux/hfs_common.h\n@@ -171,18 +171,22 @@ enum {\n \tHFS_XATTR_NAME,\n };\n \n+#define HFS_FORK_EXTENT_COUNT\t(3)\n+\n struct hfs_extent {\n \t__be16 block;\n \t__be16 count;\n };\n-typedef struct hfs_extent hfs_extent_rec[3];\n+typedef struct hfs_extent hfs_extent_rec[HFS_FORK_EXTENT_COUNT];\n+\n+#define HFSPLUS_FORK_EXTENT_COUNT\t(8)\n \n /* A single contiguous area of a file */\n struct hfsplus_extent {\n \t__be32 start_block;\n \t__be32 block_count;\n } __packed;\n-typedef struct hfsplus_extent hfsplus_extent_rec[8];\n+typedef struct hfsplus_extent hfsplus_extent_rec[HFSPLUS_FORK_EXTENT_COUNT];\n \n /* Information for a \"Fork\" in a file */\n struct hfsplus_fork_raw {\ndiff --git a/include/linux/iomap.h b/include/linux/iomap.h\nindex bc7ae6327dbf8..66a6389c9c74c 100644\n--- a/include/linux/iomap.h\n+++ b/include/linux/iomap.h\n@@ -636,6 +636,26 @@ struct iomap_dio_ops {\n \tstruct bio_set *bio_set;\n };\n \n+/*\n+ * Direct I/O completion handler\n+ */\n+static inline\n+int iomap_dio_end_io(struct kiocb *iocb, ssize_t size,\n+\t\t     int error, unsigned int flags)\n+{\n+\tstruct inode *inode = file_inode(iocb-\u003eki_filp);\n+\n+\tif (error)\n+\t\treturn error;\n+\n+\tif (size \u0026\u0026 i_size_read(inode) \u003c iocb-\u003eki_pos + size) {\n+\t\ti_size_write(inode, iocb-\u003eki_pos + size);\n+\t\tmark_inode_dirty(inode);\n+\t}\n+\n+\treturn 0;\n+}\n+\n /*\n  * Wait for the I/O to complete in iomap_dio_rw even if the kiocb is not\n  * synchronous.\n"
}

2/1 2026/09/15 01:31 agent patch-evaluator
1m Model:
core

Args:
null

Results:
{
  "EnableConfigs": [
    "HFSPLUS_FS",
    "MISC_FILESYSTEMS",
    "BLOCK"
  ],
  "FocusSymbols": [
    "hfsplus_map_extent",
    "hfsplus_iomap_cont_expand",
    "hfsplus_write_iomap_end",
    "hfsplus_writeback_range",
    "hfsplus_file_write_iter",
    "hfsplus_file_read_iter",
    "hfsplus_file_llseek",
    "hfsplus_block_allocate",
    "hfsplus_block_free"
  ],
  "Reasoning": "The patch series converts the HFS+ regular file I/O path to use the iomap framework (for buffered reads/writes, direct I/O, writeback, and hole/data seeking), refactors extent allocation and mapping with hfsplus_map_extent(), and introduces page locking and writeback synchronization in the bitmap allocator. HFS+ filesystems are fully reachable in standard virtualized environments (e.g. via loop devices and mount). These structural changes in extent resolution, I/O paths, and locking warrant fuzzing for concurrency issues, assertion trips, and boundary corner cases.",
  "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 39277fb8636d2c138333c48e03b8696b2d711648
Author: syz-cluster <triage@syzkaller.com>
Date:   Tue Sep 15 01:31:24 2026 +0000

    syz-cluster: applied patch under review

diff --git a/fs/hfsplus/Kconfig b/fs/hfsplus/Kconfig
index ca8401cb6954d..b4432c64db3be 100644
--- a/fs/hfsplus/Kconfig
+++ b/fs/hfsplus/Kconfig
@@ -5,7 +5,7 @@ config HFSPLUS_FS
 	select BUFFER_HEAD
 	select NLS
 	select NLS_UTF8
-	select LEGACY_DIRECT_IO
+	select FS_IOMAP
 	help
 	  If you say Y here, you will be able to mount extended format
 	  Macintosh-formatted hard drive partitions with full read-write access.
diff --git a/fs/hfsplus/Makefile b/fs/hfsplus/Makefile
index f2a9ae697e811..3ddea69a9c698 100644
--- a/fs/hfsplus/Makefile
+++ b/fs/hfsplus/Makefile
@@ -5,8 +5,9 @@
 
 obj-$(CONFIG_HFSPLUS_FS) += hfsplus.o
 
-hfsplus-objs := super.o options.o inode.o ioctl.o extents.o catalog.o dir.o btree.o \
-		bnode.o brec.o bfind.o tables.o unicode.o wrapper.o bitmap.o part_tbl.o \
+hfsplus-objs := super.o options.o inode.o file.o iomap.o ioctl.o extents.o \
+		catalog.o dir.o btree.o bnode.o brec.o bfind.o tables.o \
+		unicode.o wrapper.o bitmap.o part_tbl.o \
 		attributes.o xattr.o xattr_user.o xattr_security.o xattr_trusted.o
 
 # KUnit tests
diff --git a/fs/hfsplus/bitmap.c b/fs/hfsplus/bitmap.c
index 1b3af8c87cadb..30178ea473624 100644
--- a/fs/hfsplus/bitmap.c
+++ b/fs/hfsplus/bitmap.c
@@ -39,6 +39,8 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size,
 		start = size;
 		goto out;
 	}
+	lock_page(page);
+	folio_wait_writeback(page_folio(page));
 	pptr = kmap_local_page(page);
 	curr = pptr + (offset & (PAGE_CACHE_BITS - 1)) / 32;
 	i = offset % 32;
@@ -75,6 +77,7 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size,
 			curr++;
 		}
 		kunmap_local(pptr);
+		unlock_page(page);
 		offset += PAGE_CACHE_BITS;
 		if (offset >= size)
 			break;
@@ -84,6 +87,8 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size,
 			start = size;
 			goto out;
 		}
+		lock_page(page);
+		folio_wait_writeback(page_folio(page));
 		curr = pptr = kmap_local_page(page);
 		if ((size ^ offset) / PAGE_CACHE_BITS)
 			end = pptr + PAGE_CACHE_BITS / 32;
@@ -98,6 +103,9 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size,
 	start = offset + (curr - pptr) * 32 + i;
 	if (start >= size) {
 		hfs_dbg("bitmap full\n");
+		kunmap_local(pptr);
+		unlock_page(page);
+		start = size;
 		goto out;
 	}
 	/* do any partial u32 at the start */
@@ -128,6 +136,7 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size,
 		}
 		set_page_dirty(page);
 		kunmap_local(pptr);
+		unlock_page(page);
 		offset += PAGE_CACHE_BITS;
 		page = read_mapping_page(mapping, offset / PAGE_CACHE_BITS,
 					 NULL);
@@ -135,6 +144,8 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size,
 			start = size;
 			goto out;
 		}
+		lock_page(page);
+		folio_wait_writeback(page_folio(page));
 		pptr = kmap_local_page(page);
 		curr = pptr;
 		end = pptr + PAGE_CACHE_BITS / 32;
@@ -152,6 +163,7 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size,
 	*curr = cpu_to_be32(n);
 	set_page_dirty(page);
 	kunmap_local(pptr);
+	unlock_page(page);
 	*max = offset + (curr - pptr) * 32 + i - start;
 	sbi->free_blocks -= *max;
 	hfsplus_mark_mdb_dirty(sb);
@@ -185,6 +197,8 @@ int hfsplus_block_free(struct super_block *sb, u32 offset, u32 count)
 	page = read_mapping_page(mapping, pnr, NULL);
 	if (IS_ERR(page))
 		goto kaboom;
+	lock_page(page);
+	folio_wait_writeback(page_folio(page));
 	pptr = kmap_local_page(page);
 	curr = pptr + (offset & (PAGE_CACHE_BITS - 1)) / 32;
 	end = pptr + PAGE_CACHE_BITS / 32;
@@ -216,9 +230,12 @@ int hfsplus_block_free(struct super_block *sb, u32 offset, u32 count)
 			break;
 		set_page_dirty(page);
 		kunmap_local(pptr);
+		unlock_page(page);
 		page = read_mapping_page(mapping, ++pnr, NULL);
 		if (IS_ERR(page))
 			goto kaboom;
+		lock_page(page);
+		folio_wait_writeback(page_folio(page));
 		pptr = kmap_local_page(page);
 		curr = pptr;
 		end = pptr + PAGE_CACHE_BITS / 32;
@@ -232,6 +249,7 @@ int hfsplus_block_free(struct super_block *sb, u32 offset, u32 count)
 out:
 	set_page_dirty(page);
 	kunmap_local(pptr);
+	unlock_page(page);
 	sbi->free_blocks += len;
 	hfsplus_mark_mdb_dirty(sb);
 	mutex_unlock(&sbi->alloc_mutex);
diff --git a/fs/hfsplus/extents.c b/fs/hfsplus/extents.c
index eb7c11524d188..b724cc1ca3e1f 100644
--- a/fs/hfsplus/extents.c
+++ b/fs/hfsplus/extents.c
@@ -15,6 +15,7 @@
 
 #include "hfsplus_fs.h"
 #include "hfsplus_raw.h"
+#include "iomap.h"
 
 /* Compare two extents keys, returns 0 on same, pos/neg for difference */
 int hfsplus_ext_cmp_key(const hfsplus_btree_key *k1,
@@ -48,18 +49,29 @@ static void hfsplus_ext_build_key(hfsplus_btree_key *key, u32 cnid,
 	key->ext.pad = 0;
 }
 
-static u32 hfsplus_ext_find_block(struct hfsplus_extent *ext, u32 off)
+/*
+ * hfsplus_ext_find_block() - find contiguous sequence of block
+ *
+ * Find the disk allocation block for 'off' within an 8-entry
+ * extent record, and the number of further allocation blocks
+ * that are contiguous with it in the same extent entry.
+ */
+static u32 hfsplus_ext_find_block(struct hfsplus_extent *ext, u32 off,
+				 u32 *dblock)
 {
 	int i;
 	u32 count;
 
-	for (i = 0; i < 8; ext++, i++) {
+	for (i = 0; i < HFSPLUS_FORK_EXTENT_COUNT; ext++, i++) {
 		count = be32_to_cpu(ext->block_count);
-		if (off < count)
-			return be32_to_cpu(ext->start_block) + off;
+		if (off < count) {
+			*dblock = be32_to_cpu(ext->start_block) + off;
+			return count - off;
+		}
 		off -= count;
 	}
 	/* panic? */
+	*dblock = 0;
 	return 0;
 }
 
@@ -68,7 +80,7 @@ static int hfsplus_ext_block_count(struct hfsplus_extent *ext)
 	int i;
 	u32 count = 0;
 
-	for (i = 0; i < 8; ext++, i++)
+	for (i = 0; i < HFSPLUS_FORK_EXTENT_COUNT; ext++, i++)
 		count += be32_to_cpu(ext->block_count);
 	return count;
 }
@@ -225,37 +237,48 @@ static int hfsplus_ext_read_extent(struct inode *inode, u32 block)
 	return res;
 }
 
-/* Get a block at iblock for inode, possibly allocating if create */
-int hfsplus_get_block(struct inode *inode, sector_t iblock,
-		      struct buffer_head *bh_result, int create)
+/*
+ * hfsplus_map_extent() - find or allocate a sequence of allocation blocks
+ *
+ * Looks up the allocation block at 'ablock' for inode, extending the
+ * file (via hfsplus_file_extend(), in clump_blocks-sized chunks) when
+ * 'create' is set and 'ablock' lies beyond the current allocation.
+ *
+ * On success, *dblock is the disk allocation block backing 'ablock',
+ * and *max_blocks is the number of further allocation blocks that are
+ * contiguous with it (i.e. the remaining length of the extent entry
+ * that contains 'ablock'), which may be smaller than the whole file's
+ * remaining allocation when the fork is fragmented across several
+ * extent entries. If a new extent had to be allocated to satisfy the
+ * request, *balloc (when non-NULL) is set to true.
+ */
+int hfsplus_map_extent(struct inode *inode, u32 ablock, int create,
+			u32 *dblock, u32 *max_blocks, bool *balloc)
 {
-	struct super_block *sb = inode->i_sb;
-	struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
 	struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
-	int res = -EIO;
-	u32 ablock, dblock, mask;
-	sector_t sector;
-	int was_dirty = 0;
+	int was_dirty;
+	int res;
 
-	/* Convert inode block to disk allocation block */
-	ablock = iblock >> sbi->fs_shift;
+	if (balloc)
+		*balloc = false;
 
-	if (iblock >= hip->fs_blocks) {
+	if (ablock >= hip->alloc_blocks) {
 		if (!create)
-			return 0;
-		if (iblock > hip->fs_blocks)
 			return -EIO;
-		if (ablock >= hip->alloc_blocks) {
-			res = hfsplus_file_extend(inode, false);
-			if (res)
-				return res;
-		}
-	} else
-		create = 0;
+		res = hfsplus_file_extend(inode, false);
+		if (res)
+			return res;
+		if (balloc)
+			*balloc = true;
+	}
 
 	if (ablock < hip->first_blocks) {
-		dblock = hfsplus_ext_find_block(hip->first_extents, ablock);
-		goto done;
+		*max_blocks = hfsplus_ext_find_block(hip->first_extents,
+						     ablock,
+						     dblock);
+		if (!*max_blocks)
+			return -EIO;
+		return 0;
 	}
 
 	if (inode->i_ino == HFSPLUS_EXT_CNID)
@@ -274,11 +297,47 @@ int hfsplus_get_block(struct inode *inode, sector_t iblock,
 		mutex_unlock(&hip->extents_lock);
 		return -EIO;
 	}
-	dblock = hfsplus_ext_find_block(hip->cached_extents,
-					ablock - hip->cached_start);
+	*max_blocks = hfsplus_ext_find_block(hip->cached_extents,
+					     ablock - hip->cached_start,
+					     dblock);
 	mutex_unlock(&hip->extents_lock);
 
-done:
+	if (was_dirty)
+		mark_inode_dirty(inode);
+
+	if (!*max_blocks)
+		return -EIO;
+
+	return 0;
+}
+
+/* Get a block at iblock for inode, possibly allocating if create */
+int hfsplus_get_block(struct inode *inode, sector_t iblock,
+		      struct buffer_head *bh_result, int create)
+{
+	struct super_block *sb = inode->i_sb;
+	struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
+	struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
+	u32 ablock, dblock, mask, max_blocks;
+	sector_t sector;
+	int res;
+
+	/* Convert inode block to disk allocation block */
+	ablock = iblock >> sbi->fs_shift;
+
+	if (iblock >= hip->fs_blocks) {
+		if (!create)
+			return 0;
+		if (iblock > hip->fs_blocks)
+			return -EIO;
+	} else
+		create = 0;
+
+	res = hfsplus_map_extent(inode, ablock, create, &dblock, &max_blocks,
+				  NULL);
+	if (res)
+		return res;
+
 	hfs_dbg("ino %llu, iblock %llu - dblock %u\n",
 		inode->i_ino, (long long)iblock, dblock);
 
@@ -289,12 +348,11 @@ int hfsplus_get_block(struct inode *inode, sector_t iblock,
 
 	if (create) {
 		set_buffer_new(bh_result);
-		hip->phys_size += sb->s_blocksize;
+		hip->phys_size = (loff_t)(iblock + 1) << sb->s_blocksize_bits;
 		hip->fs_blocks++;
 		inode_add_bytes(inode, sb->s_blocksize);
-	}
-	if (create || was_dirty)
 		mark_inode_dirty(inode);
+	}
 	return 0;
 }
 
@@ -555,20 +613,33 @@ void hfsplus_file_truncate(struct inode *inode)
 		inode->i_ino, (long long)hip->phys_size, inode->i_size);
 
 	if (inode->i_size > hip->phys_size) {
-		struct address_space *mapping = inode->i_mapping;
-		struct folio *folio;
-		void *fsdata = NULL;
-		loff_t size = inode->i_size;
+		if (S_ISREG(inode->i_mode)) {
+			res = hfsplus_iomap_cont_expand(inode, hip->phys_size,
+							inode->i_size);
+			if (res)
+				return;
+
+			mark_inode_dirty(inode);
+		} else {
+			struct address_space *mapping = inode->i_mapping;
+			struct folio *folio;
+			void *fsdata = NULL;
+
+			res = hfsplus_write_begin(NULL, mapping,
+						  inode->i_size, 0,
+						  &folio, &fsdata);
+			if (res)
+				return;
+
+			res = generic_write_end(NULL, mapping,
+						inode->i_size, 0, 0,
+						folio, fsdata);
+			if (res < 0)
+				return;
+
+			mark_inode_dirty(inode);
+		}
 
-		res = hfsplus_write_begin(NULL, mapping, size, 0,
-					  &folio, &fsdata);
-		if (res)
-			return;
-		res = generic_write_end(NULL, mapping, size, 0, 0,
-					folio, fsdata);
-		if (res < 0)
-			return;
-		mark_inode_dirty(inode);
 		return;
 	} else if (inode->i_size == hip->phys_size)
 		return;
diff --git a/fs/hfsplus/file.c b/fs/hfsplus/file.c
new file mode 100644
index 0000000000000..0b0ae6b6e307f
--- /dev/null
+++ b/fs/hfsplus/file.c
@@ -0,0 +1,304 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * File operations: open/release/fsync and iomap-based read/write/seek
+ */
+
+#include <linux/fs.h>
+#include <linux/uio.h>
+#include <linux/mount.h>
+#include <linux/iomap.h>
+
+#include "hfsplus_fs.h"
+#include "hfsplus_raw.h"
+#include "iomap.h"
+
+static int hfsplus_file_open(struct inode *inode, struct file *file)
+{
+	if (HFSPLUS_IS_RSRC(inode))
+		inode = HFSPLUS_I(inode)->rsrc_inode;
+	if (!(file->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS)
+		return -EOVERFLOW;
+	atomic_inc(&HFSPLUS_I(inode)->opencnt);
+	file->f_mode |= FMODE_CAN_ODIRECT;
+	return 0;
+}
+
+static int hfsplus_file_release(struct inode *inode, struct file *file)
+{
+	struct super_block *sb = inode->i_sb;
+
+	if (HFSPLUS_IS_RSRC(inode))
+		inode = HFSPLUS_I(inode)->rsrc_inode;
+	if (atomic_dec_and_test(&HFSPLUS_I(inode)->opencnt)) {
+		inode_lock(inode);
+		hfsplus_file_truncate(inode);
+		if (inode->i_flags & S_DEAD) {
+			hfsplus_delete_cat(inode->i_ino,
+					   HFSPLUS_SB(sb)->hidden_dir, NULL);
+			hfsplus_delete_inode(inode);
+		}
+		inode_unlock(inode);
+	}
+	return 0;
+}
+
+int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,
+		       int datasync)
+{
+	struct inode *inode = file->f_mapping->host;
+	struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
+	struct super_block *sb = inode->i_sb;
+	struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
+	struct hfsplus_vh *vhdr = sbi->s_vhdr;
+	int error = 0, error2;
+
+	hfs_dbg("inode->i_ino %llu, start %llu, end %llu\n",
+		inode->i_ino, start, end);
+
+	error = file_write_and_wait_range(file, start, end);
+	if (error)
+		return error;
+
+	/*
+	 * Sync inode metadata into the catalog and extent trees.
+	 */
+	sync_inode_metadata(inode, 1);
+
+	/*
+	 * And explicitly write out the btrees.
+	 */
+	if (test_and_clear_bit(HFSPLUS_I_CAT_DIRTY,
+				&HFSPLUS_I(HFSPLUS_CAT_TREE_I(sb))->flags)) {
+		clear_bit(HFSPLUS_I_CAT_DIRTY, &hip->flags);
+		error = filemap_write_and_wait(sbi->cat_tree->inode->i_mapping);
+	}
+
+	if (test_and_clear_bit(HFSPLUS_I_EXT_DIRTY,
+				&HFSPLUS_I(HFSPLUS_EXT_TREE_I(sb))->flags)) {
+		clear_bit(HFSPLUS_I_EXT_DIRTY, &hip->flags);
+		error2 =
+			filemap_write_and_wait(sbi->ext_tree->inode->i_mapping);
+		if (!error)
+			error = error2;
+	}
+
+	if (sbi->attr_tree) {
+		if (test_and_clear_bit(HFSPLUS_I_ATTR_DIRTY,
+				&HFSPLUS_I(HFSPLUS_ATTR_TREE_I(sb))->flags)) {
+			clear_bit(HFSPLUS_I_ATTR_DIRTY, &hip->flags);
+			error2 =
+				filemap_write_and_wait(
+					    sbi->attr_tree->inode->i_mapping);
+			if (!error)
+				error = error2;
+		}
+	} else {
+		if (test_and_clear_bit(HFSPLUS_I_ATTR_DIRTY, &hip->flags))
+			pr_err("sync non-existent attributes tree\n");
+	}
+
+	if (test_and_clear_bit(HFSPLUS_I_ALLOC_DIRTY,
+				&HFSPLUS_I(sbi->alloc_file)->flags)) {
+		clear_bit(HFSPLUS_I_ALLOC_DIRTY, &hip->flags);
+		error2 = filemap_write_and_wait(sbi->alloc_file->i_mapping);
+		if (!error)
+			error = error2;
+	}
+
+	mutex_lock(&sbi->vh_mutex);
+	hfsplus_prepare_volume_header_for_commit(vhdr);
+	mutex_unlock(&sbi->vh_mutex);
+
+	error2 = hfsplus_commit_superblock(inode->i_sb);
+	if (!error)
+		error = error2;
+
+	if (!test_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags))
+		blkdev_issue_flush(inode->i_sb->s_bdev);
+
+	return error;
+}
+
+/*
+ * hfsplus_fallback_buffered_write() - fall back to buffered I/O for the
+ * tail of a write that iomap_dio_rw() could not perform directly
+ * (unaligned tail, or no blocks could be mapped without allocation
+ * outside the direct path).
+ */
+static ssize_t hfsplus_fallback_buffered_write(struct kiocb *iocb,
+						struct iov_iter *from)
+{
+	loff_t offset = iocb->ki_pos, end;
+	ssize_t written;
+	int ret;
+
+	iocb->ki_flags &= ~IOCB_DIRECT;
+
+	written = iomap_file_buffered_write(iocb, from,
+					    &hfsplus_write_iomap_ops,
+					    NULL, NULL);
+	if (written < 0)
+		return written;
+
+	end = iocb->ki_pos + written - 1;
+	ret = filemap_write_and_wait_range(iocb->ki_filp->f_mapping,
+					   offset, end);
+	if (ret)
+		return -EIO;
+
+	invalidate_mapping_pages(iocb->ki_filp->f_mapping,
+				 offset >> PAGE_SHIFT,
+				 end >> PAGE_SHIFT);
+
+	return written;
+}
+
+static ssize_t hfsplus_dio_write_iter(struct kiocb *iocb,
+					struct iov_iter *from,
+					unsigned int dio_flags)
+{
+	ssize_t ret;
+
+	ret = iomap_dio_rw(iocb, from,
+			   &hfsplus_write_iomap_ops,
+			   &hfsplus_write_dio_ops,
+			   dio_flags, NULL, 0);
+	if (ret == -ENOTBLK)
+		ret = 0;
+	else if (ret < 0)
+		return ret;
+
+	if (iov_iter_count(from)) {
+		ssize_t written;
+
+		written = hfsplus_fallback_buffered_write(iocb, from);
+		if (written < 0)
+			return written;
+		ret += written;
+	}
+
+	return ret;
+}
+
+static ssize_t hfsplus_file_write_iter(struct kiocb *iocb,
+					struct iov_iter *iter)
+{
+	struct file *file = iocb->ki_filp;
+	struct inode *inode = file_inode(file);
+	struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
+	loff_t total_capacity;
+	ssize_t ret;
+	int err;
+
+	inode_lock(inode);
+
+	ret = generic_write_checks(iocb, iter);
+	if (ret <= 0)
+		goto unlock;
+
+	total_capacity = (loff_t)sbi->total_blocks << sbi->alloc_blksz_shift;
+	if (iocb->ki_pos >= total_capacity) {
+		ret = -EFBIG;
+		goto unlock;
+	}
+
+	err = file_modified(file);
+	if (err) {
+		ret = err;
+		goto unlock;
+	}
+
+	if (iocb->ki_pos > i_size_read(inode)) {
+		loff_t old_size = i_size_read(inode);
+
+		i_size_write(inode, iocb->ki_pos);
+		err = hfsplus_iomap_cont_expand(inode, old_size, iocb->ki_pos);
+		if (err) {
+			i_size_write(inode, old_size);
+			ret = err;
+			goto unlock;
+		}
+		mark_inode_dirty(inode);
+	}
+
+	if (iocb->ki_flags & IOCB_DIRECT) {
+		unsigned int dio_flags = 0;
+
+		if (iocb->ki_pos + iov_iter_count(iter) >
+		    HFSPLUS_I(inode)->phys_size)
+			dio_flags |= IOMAP_DIO_FORCE_WAIT;
+
+		ret = hfsplus_dio_write_iter(iocb, iter, dio_flags);
+	} else {
+		ret = iomap_file_buffered_write(iocb, iter,
+						&hfsplus_write_iomap_ops,
+						NULL, NULL);
+	}
+
+unlock:
+	inode_unlock(inode);
+
+	if (ret > 0)
+		ret = generic_write_sync(iocb, ret);
+
+	return ret;
+}
+
+static ssize_t hfsplus_file_read_iter(struct kiocb *iocb,
+					struct iov_iter *iter)
+{
+	struct inode *inode = file_inode(iocb->ki_filp);
+	ssize_t ret;
+
+	inode_lock_shared(inode);
+
+	if (iocb->ki_flags & IOCB_DIRECT) {
+		file_accessed(iocb->ki_filp);
+		ret = iomap_dio_rw(iocb, iter,
+				   &hfsplus_iomap_ops,
+				   NULL, 0, NULL, 0);
+	} else
+		ret = generic_file_read_iter(iocb, iter);
+
+	inode_unlock_shared(inode);
+
+	return ret;
+}
+
+static loff_t hfsplus_file_llseek(struct file *file, loff_t offset, int whence)
+{
+	struct inode *inode = file->f_mapping->host;
+
+	switch (whence) {
+	case SEEK_HOLE:
+		inode_lock_shared(inode);
+		offset = iomap_seek_hole(inode, offset, &hfsplus_iomap_ops);
+		inode_unlock_shared(inode);
+		break;
+	case SEEK_DATA:
+		inode_lock_shared(inode);
+		offset = iomap_seek_data(inode, offset, &hfsplus_iomap_ops);
+		inode_unlock_shared(inode);
+		break;
+	default:
+		return generic_file_llseek(file, offset, whence);
+	}
+
+	if (offset < 0)
+		return offset;
+
+	return vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
+}
+
+const struct file_operations hfsplus_file_operations = {
+	.llseek		= hfsplus_file_llseek,
+	.read_iter	= hfsplus_file_read_iter,
+	.write_iter	= hfsplus_file_write_iter,
+	.mmap_prepare	= generic_file_mmap_prepare,
+	.splice_read	= filemap_splice_read,
+	.splice_write	= iter_file_splice_write,
+	.fsync		= hfsplus_file_fsync,
+	.open		= hfsplus_file_open,
+	.release	= hfsplus_file_release,
+	.unlocked_ioctl = hfsplus_ioctl,
+};
diff --git a/fs/hfsplus/hfsplus_fs.h b/fs/hfsplus/hfsplus_fs.h
index 1e5b58e6a13fc..844027679a750 100644
--- a/fs/hfsplus/hfsplus_fs.h
+++ b/fs/hfsplus/hfsplus_fs.h
@@ -175,6 +175,22 @@ static inline struct hfsplus_sb_info *HFSPLUS_SB(struct super_block *sb)
 	return sb->s_fs_info;
 }
 
+/*
+ * Physical byte offset of allocation block 'dblock' on the volume.
+ */
+static inline loff_t hfsplus_ablock_to_phys_bytes(struct super_block *sb,
+						  u32 dblock)
+{
+	struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
+	loff_t phys_bytes;
+
+	phys_bytes = dblock;
+	phys_bytes <<= sbi->fs_shift;
+	phys_bytes += sbi->blockoffset;
+	phys_bytes <<= sb->s_blocksize_bits;
+
+	return phys_bytes;
+}
 
 struct hfsplus_inode_info {
 	atomic_t opencnt;
@@ -430,12 +446,19 @@ int hfsplus_rename_cat(u32 cnid, struct inode *src_dir, const struct qstr *src_n
 extern const struct inode_operations hfsplus_dir_inode_operations;
 extern const struct file_operations hfsplus_dir_operations;
 
+/* file.c */
+extern const struct file_operations hfsplus_file_operations;
+int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,
+		       int datasync);
+
 /* extents.c */
 int hfsplus_ext_cmp_key(const hfsplus_btree_key *k1,
 			const hfsplus_btree_key *k2);
 int hfsplus_ext_write_extent(struct inode *inode);
 int hfsplus_get_block(struct inode *inode, sector_t iblock,
 		      struct buffer_head *bh_result, int create);
+int hfsplus_map_extent(struct inode *inode, u32 ablock, int create,
+			u32 *dblock, u32 *max_blocks, bool *balloc);
 int hfsplus_free_fork(struct super_block *sb, u32 cnid,
 		      struct hfsplus_fork_raw *fork, int type);
 int hfsplus_file_extend(struct inode *inode, bool zeroout);
@@ -443,6 +466,7 @@ void hfsplus_file_truncate(struct inode *inode);
 
 /* inode.c */
 extern const struct address_space_operations hfsplus_aops;
+extern const struct address_space_operations hfsplus_symlink_aops;
 extern const struct address_space_operations hfsplus_btree_aops;
 extern const struct dentry_operations hfsplus_dentry_operations;
 
@@ -462,8 +486,6 @@ int hfsplus_cat_write_inode(struct inode *inode);
 int hfsplus_getattr(struct mnt_idmap *idmap, const struct path *path,
 		    struct kstat *stat, u32 request_mask,
 		    unsigned int query_flags);
-int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,
-		       int datasync);
 int hfsplus_fileattr_get(struct dentry *dentry, struct file_kattr *fa);
 int hfsplus_fileattr_set(struct mnt_idmap *idmap,
 			 struct dentry *dentry, struct file_kattr *fa);
diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
index 2ce6de574fa6e..1779061dcad5b 100644
--- a/fs/hfsplus/inode.c
+++ b/fs/hfsplus/inode.c
@@ -18,15 +18,12 @@
 #include <linux/cred.h>
 #include <linux/uio.h>
 #include <linux/fileattr.h>
+#include <linux/iomap.h>
 
 #include "hfsplus_fs.h"
 #include "hfsplus_raw.h"
 #include "xattr.h"
-
-static int hfsplus_read_folio(struct file *file, struct folio *folio)
-{
-	return block_read_full_folio(folio, hfsplus_get_block);
-}
+#include "iomap.h"
 
 static void hfsplus_write_failed(struct address_space *mapping, loff_t to)
 {
@@ -128,67 +125,13 @@ static bool hfsplus_release_folio(struct folio *folio, gfp_t mask)
 	return res ? try_to_free_buffers(folio) : false;
 }
 
-static ssize_t hfsplus_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
+static int hfsplus_btree_read_folio(struct file *file, struct folio *folio)
 {
-	struct file *file = iocb->ki_filp;
-	struct address_space *mapping = file->f_mapping;
-	struct inode *inode = mapping->host;
-	loff_t isize;
-	size_t count = iov_iter_count(iter);
-	loff_t end = iocb->ki_pos + count;
-	ssize_t ret;
-
-	/*
-	 * The hfsplus_get_block() only allows creating the next sequential block.
-	 * For direct writes beyond EOF, expand the file first.
-	 */
-	if (iov_iter_rw(iter) == WRITE && iocb->ki_pos > i_size_read(inode)) {
-		loff_t start_off, end_off;
-		loff_t start_page, end_page;
-
-		isize = i_size_read(inode);
-
-		/*
-		 * Wait for any in-flight DIO on this inode to finish before
-		 * calling generic_cont_expand_simple().
-		 */
-		inode_dio_wait(inode);
-
-		ret = generic_cont_expand_simple(inode, iocb->ki_pos);
-		if (ret)
-			return ret;
-
-		start_off = isize;
-		end_off = (end > 0) ? end - 1 : end;
-
-		ret = filemap_write_and_wait_range(mapping, start_off, end_off);
-		if (ret)
-			return ret;
-
-		start_page = start_off >> PAGE_SHIFT;
-		end_page = end_off >> PAGE_SHIFT;
-
-		invalidate_inode_pages2_range(mapping, start_page, end_page);
-	}
-
-	ret = blockdev_direct_IO(iocb, inode, iter, hfsplus_get_block);
-
-	/*
-	 * In case of error extending write may have instantiated a few
-	 * blocks outside i_size. Trim these off again.
-	 */
-	if (unlikely(iov_iter_rw(iter) == WRITE && ret < 0)) {
-		isize = i_size_read(inode);
-
-		if (end > isize)
-			hfsplus_write_failed(mapping, end);
-	}
-
-	return ret;
+	return block_read_full_folio(folio, hfsplus_get_block);
 }
 
-static int hfsplus_writepages(struct address_space *mapping,
-			      struct writeback_control *wbc)
+static int hfsplus_btree_writepages(struct address_space *mapping,
+				    struct writeback_control *wbc)
 {
 	return mpage_writepages(mapping, wbc, hfsplus_get_block);
 }
@@ -196,8 +139,8 @@ static int hfsplus_writepages(struct address_space *mapping,
 const struct address_space_operations hfsplus_btree_aops = {
 	.dirty_folio	= block_dirty_folio,
 	.invalidate_folio = block_invalidate_folio,
-	.read_folio	= hfsplus_read_folio,
-	.writepages	= hfsplus_writepages,
+	.read_folio	= hfsplus_btree_read_folio,
+	.writepages	= hfsplus_btree_writepages,
 	.write_begin	= hfsplus_write_begin,
 	.write_end	= generic_write_end,
 	.migrate_folio	= buffer_migrate_folio,
@@ -205,18 +148,70 @@ const struct address_space_operations hfsplus_btree_aops = {
 	.release_folio	= hfsplus_release_folio,
 };
 
-const struct address_space_operations hfsplus_aops = {
+static int hfsplus_symlink_read_folio(struct file *file, struct folio *folio)
+{
+	return block_read_full_folio(folio, hfsplus_get_block);
+}
+
+static int hfsplus_symlink_writepages(struct address_space *mapping,
+				      struct writeback_control *wbc)
+{
+	return mpage_writepages(mapping, wbc, hfsplus_get_block);
+}
+
+const struct address_space_operations hfsplus_symlink_aops = {
 	.dirty_folio	= block_dirty_folio,
 	.invalidate_folio = block_invalidate_folio,
-	.read_folio	= hfsplus_read_folio,
+	.read_folio	= hfsplus_symlink_read_folio,
 	.write_begin	= hfsplus_write_begin,
 	.write_end	= generic_write_end,
 	.bmap		= hfsplus_bmap,
-	.direct_IO	= hfsplus_direct_IO,
-	.writepages	= hfsplus_writepages,
+	.writepages	= hfsplus_symlink_writepages,
 	.migrate_folio	= buffer_migrate_folio,
 };
 
+static int hfsplus_read_folio(struct file *file, struct folio *folio)
+{
+	iomap_bio_read_folio(folio, &hfsplus_iomap_ops);
+	return 0;
+}
+
+static void hfsplus_readahead(struct readahead_control *rac)
+{
+	iomap_bio_readahead(rac, &hfsplus_iomap_ops);
+}
+
+static int hfsplus_writepages(struct address_space *mapping,
+			      struct writeback_control *wbc)
+{
+	struct iomap_writepage_ctx wpc = {
+		.inode	= mapping->host,
+		.wbc	= wbc,
+		.ops	= &hfsplus_writeback_ops,
+	};
+
+	return iomap_writepages(&wpc);
+}
+
+static sector_t hfsplus_aop_bmap(struct address_space *mapping, sector_t block)
+{
+	return iomap_bmap(mapping, block, &hfsplus_iomap_ops);
+}
+
+const struct address_space_operations hfsplus_aops = {
+	.read_folio		= hfsplus_read_folio,
+	.readahead		= hfsplus_readahead,
+	.writepages		= hfsplus_writepages,
+	.dirty_folio		= iomap_dirty_folio,
+	.bmap			= hfsplus_aop_bmap,
+	.migrate_folio		= filemap_migrate_folio,
+	.is_partially_uptodate	= iomap_is_partially_uptodate,
+	.error_remove_folio	= generic_error_remove_folio,
+	.release_folio		= iomap_release_folio,
+	.invalidate_folio	= iomap_invalidate_folio,
+	.swap_activate		= hfsplus_iomap_swap_activate,
+};
+
 const struct dentry_operations hfsplus_dentry_operations = {
 	.d_hash       = hfsplus_hash_dentry,
 	.d_compare    = hfsplus_compare_dentry,
@@ -276,35 +271,6 @@ static int hfsplus_get_perms(struct inode *inode,
 	return -EIO;
 }
 
-static int hfsplus_file_open(struct inode *inode, struct file *file)
-{
-	if (HFSPLUS_IS_RSRC(inode))
-		inode = HFSPLUS_I(inode)->rsrc_inode;
-	if (!(file->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS)
-		return -EOVERFLOW;
-	atomic_inc(&HFSPLUS_I(inode)->opencnt);
-	return 0;
-}
-
-static int hfsplus_file_release(struct inode *inode, struct file *file)
-{
-	struct super_block *sb = inode->i_sb;
-
-	if (HFSPLUS_IS_RSRC(inode))
-		inode = HFSPLUS_I(inode)->rsrc_inode;
-	if (atomic_dec_and_test(&HFSPLUS_I(inode)->opencnt)) {
-		inode_lock(inode);
-		hfsplus_file_truncate(inode);
-		if (inode->i_flags & S_DEAD) {
-			hfsplus_delete_cat(inode->i_ino,
-					   HFSPLUS_SB(sb)->hidden_dir, NULL);
-			hfsplus_delete_inode(inode);
-		}
-		inode_unlock(inode);
-	}
-	return 0;
-}
-
 static int hfsplus_setattr(struct mnt_idmap *idmap,
 			   struct dentry *dentry, struct iattr *attr)
 {
@@ -319,13 +285,28 @@ static int hfsplus_setattr(struct mnt_idmap *idmap,
 	    attr->ia_size != i_size_read(inode)) {
 		inode_dio_wait(inode);
 		if (attr->ia_size > inode->i_size) {
-			error = generic_cont_expand_simple(inode,
-							   attr->ia_size);
+			loff_t old_size = inode->i_size;
+
+			i_size_write(inode, attr->ia_size);
+			error = hfsplus_iomap_cont_expand(inode, old_size,
+							  attr->ia_size);
+			if (error) {
+				i_size_write(inode, old_size);
+				return error;
+			}
+			truncate_setsize(inode, attr->ia_size);
+		} else {
+			bool did_zero = false;
+
+			error = iomap_truncate_page(inode, attr->ia_size,
+						    &did_zero,
+						    &hfsplus_write_iomap_ops,
+						    NULL, NULL);
 			if (error)
 				return error;
+			truncate_setsize(inode, attr->ia_size);
+			hfsplus_file_truncate(inode);
 		}
-		truncate_setsize(inode, attr->ia_size);
-		hfsplus_file_truncate(inode);
 		inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
 	}
 
@@ -361,86 +342,6 @@ int hfsplus_getattr(struct mnt_idmap *idmap, const struct path *path,
 	return 0;
 }
 
-int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,
-		       int datasync)
-{
-	struct inode *inode = file->f_mapping->host;
-	struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
-	struct super_block *sb = inode->i_sb;
-	struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
-	struct hfsplus_vh *vhdr = sbi->s_vhdr;
-	int error = 0, error2;
-
-	hfs_dbg("inode->i_ino %llu, start %llu, end %llu\n",
-		inode->i_ino, start, end);
-
-	error = file_write_and_wait_range(file, start, end);
-	if (error)
-		return error;
-	inode_lock(inode);
-
-	/*
-	 * Sync inode metadata into the catalog and extent trees.
-	 */
-	sync_inode_metadata(inode, 1);
-
-	/*
-	 * And explicitly write out the btrees.
-	 */
-	if (test_and_clear_bit(HFSPLUS_I_CAT_DIRTY,
-				&HFSPLUS_I(HFSPLUS_CAT_TREE_I(sb))->flags)) {
-		clear_bit(HFSPLUS_I_CAT_DIRTY, &hip->flags);
-		error = filemap_write_and_wait(sbi->cat_tree->inode->i_mapping);
-	}
-
-	if (test_and_clear_bit(HFSPLUS_I_EXT_DIRTY,
-				&HFSPLUS_I(HFSPLUS_EXT_TREE_I(sb))->flags)) {
-		clear_bit(HFSPLUS_I_EXT_DIRTY, &hip->flags);
-		error2 =
-			filemap_write_and_wait(sbi->ext_tree->inode->i_mapping);
-		if (!error)
-			error = error2;
-	}
-
-	if (sbi->attr_tree) {
-		if (test_and_clear_bit(HFSPLUS_I_ATTR_DIRTY,
-				&HFSPLUS_I(HFSPLUS_ATTR_TREE_I(sb))->flags)) {
-			clear_bit(HFSPLUS_I_ATTR_DIRTY, &hip->flags);
-			error2 =
-				filemap_write_and_wait(
-					    sbi->attr_tree->inode->i_mapping);
-			if (!error)
-				error = error2;
-		}
-	} else {
-		if (test_and_clear_bit(HFSPLUS_I_ATTR_DIRTY, &hip->flags))
-			pr_err("sync non-existent attributes tree\n");
-	}
-
-	if (test_and_clear_bit(HFSPLUS_I_ALLOC_DIRTY,
-				&HFSPLUS_I(sbi->alloc_file)->flags)) {
-		clear_bit(HFSPLUS_I_ALLOC_DIRTY, &hip->flags);
-		error2 = filemap_write_and_wait(sbi->alloc_file->i_mapping);
-		if (!error)
-			error = error2;
-	}
-
-	mutex_lock(&sbi->vh_mutex);
-	hfsplus_prepare_volume_header_for_commit(vhdr);
-	mutex_unlock(&sbi->vh_mutex);
-
-	error2 = hfsplus_commit_superblock(inode->i_sb);
-	if (!error)
-		error = error2;
-
-	if (!test_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags))
-		blkdev_issue_flush(inode->i_sb->s_bdev);
-
-	inode_unlock(inode);
-
-	return error;
-}
-
 static const struct inode_operations hfsplus_file_inode_operations = {
 	.setattr	= hfsplus_setattr,
 	.getattr	= hfsplus_getattr,
@@ -462,19 +363,6 @@ static const struct inode_operations hfsplus_special_inode_operations = {
 	.listxattr	= hfsplus_listxattr,
 };
 
-static const struct file_operations hfsplus_file_operations = {
-	.llseek		= generic_file_llseek,
-	.read_iter	= generic_file_read_iter,
-	.write_iter	= generic_file_write_iter,
-	.mmap_prepare	= generic_file_mmap_prepare,
-	.splice_read	= filemap_splice_read,
-	.splice_write	= iter_file_splice_write,
-	.fsync		= hfsplus_file_fsync,
-	.open		= hfsplus_file_open,
-	.release	= hfsplus_file_release,
-	.unlocked_ioctl = hfsplus_ioctl,
-};
-
 struct inode *hfsplus_new_inode(struct super_block *sb, struct inode *dir,
 				umode_t mode)
 {
@@ -521,7 +409,7 @@ struct inode *hfsplus_new_inode(struct super_block *sb, struct inode *dir,
 		sbi->file_count++;
 		inode->i_op = &hfsplus_symlink_inode_operations;
 		inode_nohighmem(inode);
-		inode->i_mapping->a_ops = &hfsplus_aops;
+		inode->i_mapping->a_ops = &hfsplus_symlink_aops;
 		hip->clump_blocks = 1;
 	} else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
 		   S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
@@ -662,7 +550,7 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
 		} else if (S_ISLNK(inode->i_mode)) {
 			inode->i_op = &hfsplus_symlink_inode_operations;
 			inode_nohighmem(inode);
-			inode->i_mapping->a_ops = &hfsplus_aops;
+			inode->i_mapping->a_ops = &hfsplus_symlink_aops;
 		} else {
 			inode->i_op = &hfsplus_special_inode_operations;
 			init_special_inode(inode, inode->i_mode,
diff --git a/fs/hfsplus/iomap.c b/fs/hfsplus/iomap.c
new file mode 100644
index 0000000000000..0eb392789126d
--- /dev/null
+++ b/fs/hfsplus/iomap.c
@@ -0,0 +1,190 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * iomap callback functions for the hfsplus filesystem
+ */
+
+#include <linux/iomap.h>
+#include <linux/pagemap.h>
+
+#include "hfsplus_fs.h"
+#include "hfsplus_raw.h"
+#include "iomap.h"
+
+static int __hfsplus_iomap_begin(struct inode *inode, loff_t offset,
+				 loff_t length, unsigned int flags,
+				 struct iomap *iomap, bool may_alloc)
+{
+	struct super_block *sb = inode->i_sb;
+	struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
+	struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
+	u32 ablock, dblock, max_blocks;
+	loff_t ablock_offset, ablock_bytes;
+	loff_t block_start;
+	bool is_new;
+	int err;
+
+	if (!may_alloc) {
+		/* Completely beyond EOF. Treat as hole */
+		if (i_size_read(inode) <= offset) {
+			iomap->type = IOMAP_HOLE;
+			iomap->addr = IOMAP_NULL_ADDR;
+			iomap->offset = offset;
+			iomap->length = length;
+			return 0;
+		}
+
+		/* Clamp length if the requested range goes beyond i_size */
+		if (offset + length > i_size_read(inode)) {
+			loff_t i_size = i_size_read(inode);
+			unsigned int blocksize = i_blocksize(inode);
+
+			length = round_up(i_size, blocksize) - offset;
+		}
+	}
+
+	ablock = offset >> sbi->alloc_blksz_shift;
+
+	err = hfsplus_map_extent(inode, ablock, may_alloc, &dblock,
+				 &max_blocks, NULL);
+	if (err)
+		return err;
+
+	ablock_offset = offset & (sbi->alloc_blksz - 1);
+	ablock_bytes = (loff_t)max_blocks << sbi->alloc_blksz_shift;
+
+	length = min_t(loff_t, length, ablock_bytes - ablock_offset);
+	block_start = round_down(offset, i_blocksize(inode));
+	is_new = may_alloc && block_start >= hip->phys_size;
+	if (may_alloc && !is_new && offset < hip->phys_size)
+		length = min_t(loff_t, length, hip->phys_size - offset);
+
+	iomap->bdev = sb->s_bdev;
+	iomap->offset = offset;
+	iomap->length = length;
+	iomap->addr = hfsplus_ablock_to_phys_bytes(sb, dblock) + ablock_offset;
+	iomap->type = IOMAP_MAPPED;
+	iomap->flags = IOMAP_F_MERGED;
+
+	if (is_new)
+		iomap->flags |= IOMAP_F_NEW;
+
+	return 0;
+}
+
+static int hfsplus_iomap_begin(struct inode *inode, loff_t offset,
+				loff_t length, unsigned int flags,
+				struct iomap *iomap, struct iomap *srcmap)
+{
+	return __hfsplus_iomap_begin(inode,
+				     offset, length, flags,
+				     iomap, false);
+}
+
+static int hfsplus_write_iomap_begin(struct inode *inode, loff_t offset,
+				     loff_t length, unsigned int flags,
+				     struct iomap *iomap, struct iomap *srcmap)
+{
+	return __hfsplus_iomap_begin(inode,
+				     offset, length, flags,
+				     iomap, true);
+}
+
+const struct iomap_ops hfsplus_iomap_ops = {
+	.iomap_begin = hfsplus_iomap_begin,
+};
+
+/*
+ * hfsplus_write_iomap_end()
+ *
+ * Advance the allocated-and-zeroed high-water mark
+ * (hip->phys_size / hip->fs_blocks) to cover the newly written range.
+ */
+static int hfsplus_write_iomap_end(struct inode *inode, loff_t pos,
+				   loff_t length, ssize_t written,
+				   unsigned int flags, struct iomap *iomap)
+{
+	struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
+	struct super_block *sb = inode->i_sb;
+	loff_t end;
+	bool dirtied = false;
+
+	if (!written)
+		return 0;
+
+	end = pos + written;
+
+	if (iomap->flags & IOMAP_F_NEW)
+		end = round_up(end, sb->s_blocksize);
+
+	if (hip->phys_size < end) {
+		inode_add_bytes(inode, end - hip->phys_size);
+		hip->phys_size = end;
+		hip->fs_blocks = end >> sb->s_blocksize_bits;
+		dirtied = true;
+	}
+
+	if (dirtied)
+		mark_inode_dirty(inode);
+
+	return written;
+}
+
+const struct iomap_ops hfsplus_write_iomap_ops = {
+	.iomap_begin	= hfsplus_write_iomap_begin,
+	.iomap_end	= hfsplus_write_iomap_end,
+};
+
+/*
+ * hfsplus_iomap_cont_expand()
+ *
+ * Zero the byte range [from, to) of a file that is being extended, where
+ * 'from' is the old end-of-file and 'to' the new one. Used by the extending
+ * write path, hfsplus_setattr() (truncate up) and hfsplus_file_truncate().
+ */
+int hfsplus_iomap_cont_expand(struct inode *inode, loff_t from, loff_t to)
+{
+	if (to <= from)
+		return 0;
+
+	return iomap_zero_range(inode, from, to - from, NULL,
+				&hfsplus_write_iomap_ops, NULL, NULL);
+}
+
+/*
+ * hfsplus_writeback_range() - map folio during writeback
+ *
+ * Called for each folio during writeback. If the folio falls outside
+ * the current iomap, remaps by calling __hfsplus_iomap_begin() again.
+ */
+static ssize_t hfsplus_writeback_range(struct iomap_writepage_ctx *wpc,
+					struct folio *folio, u64 offset,
+					unsigned int len, u64 end_pos)
+{
+	int err;
+
+	if (offset < wpc->iomap.offset ||
+	    offset >= wpc->iomap.offset + wpc->iomap.length) {
+		err = __hfsplus_iomap_begin(wpc->inode,
+					    offset, len, 0,
+					    &wpc->iomap, false);
+		if (err)
+			return err;
+	}
+
+	return iomap_add_to_ioend(wpc, folio, offset, end_pos, len);
+}
+
+const struct iomap_writeback_ops hfsplus_writeback_ops = {
+	.writeback_range	= hfsplus_writeback_range,
+	.writeback_submit	= iomap_ioend_writeback_submit,
+};
+
+const struct iomap_dio_ops hfsplus_write_dio_ops = {
+	.end_io		= iomap_dio_end_io,
+};
+
+int hfsplus_iomap_swap_activate(struct swap_info_struct *sis,
+				 struct file *file, sector_t *span)
+{
+	return iomap_swapfile_activate(sis, file, span, &hfsplus_iomap_ops);
+}
diff --git a/fs/hfsplus/iomap.h b/fs/hfsplus/iomap.h
new file mode 100644
index 0000000000000..4dd4aca1804f8
--- /dev/null
+++ b/fs/hfsplus/iomap.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * iomap callback declarations for the hfsplus filesystem
+ */
+
+#ifndef _LINUX_HFSPLUS_IOMAP_H
+#define _LINUX_HFSPLUS_IOMAP_H
+
+extern const struct iomap_ops hfsplus_iomap_ops;
+extern const struct iomap_ops hfsplus_write_iomap_ops;
+extern const struct iomap_writeback_ops hfsplus_writeback_ops;
+extern const struct iomap_dio_ops hfsplus_write_dio_ops;
+
+int hfsplus_iomap_cont_expand(struct inode *inode, loff_t from, loff_t to);
+int hfsplus_iomap_swap_activate(struct swap_info_struct *sis,
+				struct file *file, sector_t *span);
+
+#endif /* _LINUX_HFSPLUS_IOMAP_H */
diff --git a/include/linux/hfs_common.h b/include/linux/hfs_common.h
index d6a615e74b26e..8673933bbee56 100644
--- a/include/linux/hfs_common.h
+++ b/include/linux/hfs_common.h
@@ -171,18 +171,22 @@ enum {
 	HFS_XATTR_NAME,
 };
 
+#define HFS_FORK_EXTENT_COUNT	(3)
+
 struct hfs_extent {
 	__be16 block;
 	__be16 count;
 };
-typedef struct hfs_extent hfs_extent_rec[3];
+typedef struct hfs_extent hfs_extent_rec[HFS_FORK_EXTENT_COUNT];
+
+#define HFSPLUS_FORK_EXTENT_COUNT	(8)
 
 /* A single contiguous area of a file */
 struct hfsplus_extent {
 	__be32 start_block;
 	__be32 block_count;
 } __packed;
-typedef struct hfsplus_extent hfsplus_extent_rec[8];
+typedef struct hfsplus_extent hfsplus_extent_rec[HFSPLUS_FORK_EXTENT_COUNT];
 
 /* Information for a "Fork" in a file */
 struct hfsplus_fork_raw {
diff --git a/include/linux/iomap.h b/include/linux/iomap.h
index bc7ae6327dbf8..66a6389c9c74c 100644
--- a/include/linux/iomap.h
+++ b/include/linux/iomap.h
@@ -636,6 +636,26 @@ struct iomap_dio_ops {
 	struct bio_set *bio_set;
 };
 
+/*
+ * Direct I/O completion handler
+ */
+static inline
+int iomap_dio_end_io(struct kiocb *iocb, ssize_t size,
+		     int error, unsigned int flags)
+{
+	struct inode *inode = file_inode(iocb->ki_filp);
+
+	if (error)
+		return error;
+
+	if (size && i_size_read(inode) < iocb->ki_pos + size) {
+		i_size_write(inode, iocb->ki_pos + size);
+		mark_inode_dirty(inode);
+	}
+
+	return 0;
+}
+
 /*
  * Wait for the I/O to complete in iomap_dio_rw even if the kiocb is not
  * synchronous.

3/2 2026/09/15 01:31 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 19884
							output: 34
							thoughts: 879
						

Thoughts:
**HFS+ iomap Conversion Patch Series: Expert Review & Fuzzing Evaluation**

Okay, so I've got a patch series here that looks pretty significant for the HFS+ filesystem. My initial thought is that I need to give this a thorough expert review, and a fuzzing evaluation is definitely in order. Let's break down what's happening.

This series is focused on updating HFS+ to use iomap for regular files. Looking at the commit details, it's a deep dive: they're touching `fs/hfsplus` extensively. There's a `Kconfig` change selecting `FS_IOMAP`, which is a good indicator of what's happening. The `Makefile` is updated to include new objects related to iomap, and the `bitmap.c` is being modified to implement page locking to ensure safe concurrent access. The `extents.c` looks like it's been heavily refactored, which is expected with an I/O mapping change.

A brand-new `file.c` is being added. This is a big one. This means new file operations are being implemented for HFS+, which is a major signal. I'm seeing `hfsplus_file_open`, `hfsplus_file_release`, `hfsplus_file_fsync`, buffered writes, direct I/O, `read_iter`, `write_iter`, `llseek`, the works. It's the full filesystem file operation implementation, updated for the new iomap strategy. The `inode.c` is ditching the legacy address space operations and adopting iomap-based aops. That's a major shift. The series is even updating `hfsplus_setattr` to leverage iomap's truncate and cont_expand.

Then, there's `iomap.c` and `iomap.h`, which are the real meat of the conversion. They're implementing the iomap interface for HFS+, including crucial functions like `hfsplus_iomap_begin`, `hfsplus_write_iomap_begin`, `hfsplus_iomap_cont_expand`, all the way to `hfsplus_writeback_range`, the critical pieces for making this work. They are also adding inline support, and updating headers to define some new extent count information.

Now, the question is, is this worth fuzzing? Absolutely, without a doubt, YES! This is a massive filesystem rework. It's a fundamental change from buffer_head/mpage/direct_IO to iomap. Any change like this is a goldmine for fuzzing. Syzkaller already heavily tests hfsplus, and this touches all the sensitive spots: extent mapping, iomap callbacks, truncate, writeback, DIO, concurrency with `lock_page`/`unlock_page`. These are all prime targets for races, deadlocks, boundary issues, and assertion failures. I need to make sure I check the Kconfig options to be sure everything is enabled, but as long as `CONFIG_HFSPLUS_FS` is enabled, this is going to be high value. I know Syzkaller can mount HFS+ images on loop devices and should be able to cover this with no problem. I'll need to double check the configuration using `read-file` or `grepper` on the Kconfig file, but otherwise I should be able to begin fuzzing immediately.



4/2 2026/09/15 01:31 tool read-file
0m Args:
{
  "File": "fs/hfsplus/Kconfig",
  "FirstLine": 1,
  "LineCount": 50
}

Results:
{
  "Contents": "   1:\t# SPDX-License-Identifier: GPL-2.0-only\n   2:\tconfig HFSPLUS_FS\n   3:\t\ttristate \"Apple Extended HFS file system support\"\n   4:\t\tdepends on BLOCK\n   5:\t\tselect BUFFER_HEAD\n   6:\t\tselect NLS\n   7:\t\tselect NLS_UTF8\n   8:\t\tselect FS_IOMAP\n   9:\t\thelp\n  10:\t\t  If you say Y here, you will be able to mount extended format\n  11:\t\t  Macintosh-formatted hard drive partitions with full read-write access.\n  12:\t\n  13:\t\t  This file system is often called HFS+ and was introduced with\n  14:\t\t  MacOS 8. It includes all Mac specific filesystem data such as\n  15:\t\t  data forks and creator codes, but it also has several UNIX\n  16:\t\t  style features such as file ownership and permissions.\n  17:\t\n  18:\tconfig HFSPLUS_KUNIT_TEST\n  19:\t\ttristate \"KUnit tests for HFS+ filesystem\" if !KUNIT_ALL_TESTS\n  20:\t\tdepends on HFSPLUS_FS \u0026\u0026 KUNIT\n  21:\t\tdefault KUNIT_ALL_TESTS\n  22:\t\thelp\n  23:\t\t  This builds KUnit tests for the HFS+ filesystem.\n  24:\t\n  25:\t\t  KUnit tests run during boot and output the results to the debug\n  26:\t\t  log in TAP format (https://testanything.org/). Only useful for\n  27:\t\t  kernel devs running KUnit test harness and are not for inclusion\n  28:\t\t  into a production build.\n  29:\t\n  30:\t\t  For more information on KUnit and unit tests in general please\n  31:\t\t  refer to the KUnit documentation in Documentation/dev-tools/kunit/.\n"
}

5/2 2026/09/15 01:31 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 22006
							output: 21
							thoughts: 91
						

Thoughts:
Okay, here's my breakdown of what I'm looking at, from my expert perspective:

**Investigating HFS+ Filesystem Configuration**

Right, so I'm digging into how HFS+ is configured within the kernel. My initial thought is that `HFSPLUS_FS` relies on `BLOCK`, which is pretty standard for filesystems. Now, the key question is, does enabling `HFSPLUS_FS` automatically select `FS_IOMAP`? Ah, yes, line 8 confirms that – `FS_IOMAP` *is* selected. Excellent.

Now, I need to make sure I've got the whole picture of what's *actually* required for a complete configuration of the HFS+ filesystem. Are there other dependencies or sub-options in `fs/hfsplus` beyond just `HFSPLUS_FS`? It's a good practice to check, so I can be sure that enabling `HFSPLUS_FS` provides all the features and sub-dependencies the HFS+ filesystem needs. I'll need to double check any extra config options in there.

To be thorough, I'm also going to examine `fs/Kconfig` where `fs/hfsplus` is sourced. This will give me a broader view of the dependencies and potential interactions with other kernel components. That'll expose any hidden dependencies, conditional compilation paths, or potential conflicts I need to keep in mind.



6/2 2026/09/15 01:32 tool grepper
0m Args:
{
  "Expression": "source.*fs/hfsplus"
}

Results:
{
  "Output": "Documentation/filesystems/hfsplus.rst=56=References\n--\nDocumentation/filesystems/hfsplus.rst-58-\nDocumentation/filesystems/hfsplus.rst:59:kernel source:\t\t\u003cfile:fs/hfsplus\u003e\nDocumentation/filesystems/hfsplus.rst-60-\n--\nfs/Kconfig=314=source \"fs/hfs/Kconfig\"\nfs/Kconfig:315:source \"fs/hfsplus/Kconfig\"\nfs/Kconfig-316-source \"fs/befs/Kconfig\"\n"
}

7/2 2026/09/15 01:32 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 22576
							output: 32
							thoughts: 28
						

Thoughts:
Here's my summary, as if I were thinking these thoughts:

**Analyzing the Kconfig for Conditional Logic**

Okay, so I need to understand the configuration dependencies around a specific feature in the filesystem. My first move is to go straight to `fs/Kconfig`. I know that's where the core configuration options are defined for the file system. And, given that this is a feature I'm trying to understand, my best bet is to look around line 315. I'm guessing there's likely an `if` statement or possibly even a more complex `menu` structure defined in that region that controls whether or not the feature is enabled. I need to quickly identify those surrounding conditions, because understanding them is the key to understanding how this part of the filesystem behaves, and how it's activated, or deactivated.



8/2 2026/09/15 01:32 tool read-file
0m Args:
{
  "File": "fs/Kconfig",
  "FirstLine": 300,
  "LineCount": 30
}

Results:
{
  "Contents": " 300:\t\t  filesystems, such as filesystems that came from other\n 301:\t\t  operating systems.\n 302:\t\n 303:\t\t  This option alone does not add any kernel code.\n 304:\t\n 305:\t\t  If you say N, all options in this submenu will be skipped and\n 306:\t\t  disabled; if unsure, say Y here.\n 307:\t\n 308:\tif MISC_FILESYSTEMS\n 309:\t\n 310:\tsource \"fs/orangefs/Kconfig\"\n 311:\tsource \"fs/adfs/Kconfig\"\n 312:\tsource \"fs/affs/Kconfig\"\n 313:\tsource \"fs/ecryptfs/Kconfig\"\n 314:\tsource \"fs/hfs/Kconfig\"\n 315:\tsource \"fs/hfsplus/Kconfig\"\n 316:\tsource \"fs/befs/Kconfig\"\n 317:\tsource \"fs/jffs2/Kconfig\"\n 318:\t# UBIFS File system configuration\n 319:\tsource \"fs/ubifs/Kconfig\"\n 320:\tsource \"fs/cramfs/Kconfig\"\n 321:\tsource \"fs/squashfs/Kconfig\"\n 322:\tsource \"fs/minix/Kconfig\"\n 323:\tsource \"fs/omfs/Kconfig\"\n 324:\tsource \"fs/hpfs/Kconfig\"\n 325:\tsource \"fs/qnx4/Kconfig\"\n 326:\tsource \"fs/qnx6/Kconfig\"\n 327:\tsource \"fs/resctrl/Kconfig\"\n 328:\tsource \"fs/romfs/Kconfig\"\n 329:\tsource \"fs/pstore/Kconfig\"\n"
}

9/2 2026/09/15 01:32 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 23298
							output: 20
							thoughts: 91
						

Thoughts:
**Analyzing the HFS+ Filesystem Configuration**

Okay, so I'm diving into the kernel configuration files. Right, `fs/hfsplus/Kconfig` is nested under `if MISC_FILESYSTEMS`. Straightforward enough. And, logically, `HFSPLUS_FS` depends on `BLOCK`. That makes sense - you need block device support for a filesystem to do its job. So, the dependencies are clear: `MISC_FILESYSTEMS`, `BLOCK`, and then `HFSPLUS_FS` itself. Now, before I move on, I want to double-check something, just for due diligence. I need to see if `FS_IOMAP` has any dependencies itself, or if it's merely a selected option, and where it's even defined in the first place, just to be sure there's no subtle interactions I'm missing.



10/2 2026/09/15 01:32 tool grepper
0m Args:
{
  "Expression": "config FS_IOMAP"
}

Results:
{
  "Output": "fs/Kconfig=12=config VALIDATE_FS_PARSER\n--\nfs/Kconfig-17-\nfs/Kconfig:18:config FS_IOMAP\nfs/Kconfig-19-\tbool\n"
}

11/2 2026/09/15 01:32 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 23666
							output: 278
							thoughts: 2098
						

Thoughts:
**Focus Symbol Selection for HFS+ I/O and IOMAP Integration**

Okay, so the task is to pinpoint the most effective kernel functions to fuzz, given that we're dealing with the HFS+ filesystem and a patch series that integrates IOMAP. `config FS_IOMAP` is just a straightforward boolean; no dependencies there. The real work lies in understanding the patch's impact.

I've examined the changes. I've got a handle on the file modifications. `fs/hfsplus/bitmap.c` now includes page locking and writeback handling within the block allocation/freeing functions. `fs/hfsplus/extents.c` introduces `hfsplus_map_extent`, a crucial new mapping function, and also modifies other functions to call it. `fs/hfsplus/file.c` sees numerous functions touched, from opening and releasing files to write and read iterations. `fs/hfsplus/inode.c` deals with folio operations, `setattr` updates.  And of course, `fs/hfsplus/iomap.c` is heavily modified, with the introduction of new `iomap` functions.

I've also reviewed the FocusSymbol rules. We need to avoid generic, ubiquitous functions and instead target specific feature logic and entrypoints. We also need to understand how static inline functions are handled.

Now, let's identify the specific functions that fit the bill within `fs/hfsplus`.  I'm focusing on non-static, non-ubiquitous symbols. Looking at `iomap.c`, `hfsplus_iomap_cont_expand`, `hfsplus_iomap_swap_activate`, `hfsplus_write_iomap_end`, `hfsplus_writeback_range`, are all candidates. In `extents.c`,  `hfsplus_map_extent`, `hfsplus_file_truncate`, `hfsplus_get_block` are definitely interesting. In `bitmap.c`, we have `hfsplus_block_allocate` and `hfsplus_block_free`. In `file.c`, functions called by `file_operations` such as `hfsplus_file_write_iter`, `hfsplus_file_read_iter`, `hfsplus_file_llseek` are crucial, and also `hfsplus_file_fsync`. In `inode.c`, the AOPs and IOPS are not the primary focus, the patch changes are related to iomap.

I'm double-checking the static functions that are referenced by function pointers. The compiler cannot inline functions whose addresses are taken; those will be distinct symbols. Therefore `hfsplus_file_write_iter`, `hfsplus_file_read_iter`, `hfsplus_file_llseek`, `hfsplus_write_iomap_end`, `hfsplus_writeback_range` can be targeted as individual symbols, and these are important.

I confirm that the proposed symbols - `hfsplus_map_extent`, `hfsplus_iomap_cont_expand`, `hfsplus_file_write_iter`, `hfsplus_file_read_iter`, `hfsplus_file_llseek`, `hfsplus_write_iomap_end`, `hfsplus_writeback_range`, `hfsplus_block_allocate`, and `hfsplus_block_free` - are all specific to the HFS+ subsystem, and are not ubiquitous. They are core functions that were added or modified by this patch set.  These functions are the key to fuzzing this integration.

Regarding configurations, `HFSPLUS_FS`, `BLOCK`, and `MISC_FILESYSTEMS` are required to enable HFS+.  `FS_IOMAP` is automatically selected by `HFSPLUS_FS`.

In conclusion, this patch introduces significant changes to HFS+ file I/O, including integration of the iomap infrastructure, new extent mapping logic, and updated block operations. Fuzzing these functions is essential to detect any potential regressions, data corruption, deadlocks, and crashes, given the complexity of the changes. The selected FocusSymbols are accurate and specifically target the areas of major modification, allowing for robust and focused fuzzing of this HFS+ integration.



12/2 2026/09/15 01:32 tool set-results
0m Args:
{
  "EnableConfigs": [
    "HFSPLUS_FS",
    "MISC_FILESYSTEMS",
    "BLOCK"
  ],
  "FocusSymbols": [
    "hfsplus_map_extent",
    "hfsplus_iomap_cont_expand",
    "hfsplus_write_iomap_end",
    "hfsplus_writeback_range",
    "hfsplus_file_write_iter",
    "hfsplus_file_read_iter",
    "hfsplus_file_llseek",
    "hfsplus_block_allocate",
    "hfsplus_block_free"
  ],
  "Reasoning": "The patch series converts the HFS+ regular file I/O path to use the iomap framework (for buffered reads/writes, direct I/O, writeback, and hole/data seeking), refactors extent allocation and mapping with hfsplus_map_extent(), and introduces page locking and writeback synchronization in the bitmap allocator. HFS+ filesystems are fully reachable in standard virtualized environments (e.g. via loop devices and mount). These structural changes in extent resolution, I/O paths, and locking warrant fuzzing for concurrency issues, assertion trips, and boundary corner cases.",
  "WorthFuzzing": true
}

Results:
{
  "EnableConfigs": [
    "HFSPLUS_FS",
    "MISC_FILESYSTEMS",
    "BLOCK"
  ],
  "FocusSymbols": [
    "hfsplus_map_extent",
    "hfsplus_iomap_cont_expand",
    "hfsplus_write_iomap_end",
    "hfsplus_writeback_range",
    "hfsplus_file_write_iter",
    "hfsplus_file_read_iter",
    "hfsplus_file_llseek",
    "hfsplus_block_allocate",
    "hfsplus_block_free"
  ],
  "Reasoning": "The patch series converts the HFS+ regular file I/O path to use the iomap framework (for buffered reads/writes, direct I/O, writeback, and hole/data seeking), refactors extent allocation and mapping with hfsplus_map_extent(), and introduces page locking and writeback synchronization in the bitmap allocator. HFS+ filesystems are fully reachable in standard virtualized environments (e.g. via loop devices and mount). These structural changes in extent resolution, I/O paths, and locking warrant fuzzing for concurrency issues, assertion trips, and boundary corner cases.",
  "WorthFuzzing": true
}

13/1 2026/09/15 01:32 action If
2m Args:
{
  "WorthFuzzing": true
}

Results:
null

14/2 2026/09/15 01:32 agent kmsan-evaluator
2m Model:
core

Args:
null

Results:
{
  "KMSANReasoning": "The patch migrates the HFS+ filesystem from legacy buffer_head-based file operations and direct I/O to the modern iomap infrastructure (iomap read/write/seek/writeback/swap).\n\nKey aspects evaluated for uninitialized memory risks:\n1. No kernel structures are copied or leaked to user space via copy_to_user, put_user, netlink, or ioctl.\n2. Local variables in the new and modified functions (such as `was_dirty`, `dblock`, `max_blocks`, `did_zero`, and `wpc`) are fully initialized before any read or conditional branch.\n3. Unallocated or extended file ranges are zeroed out via `iomap_zero_range()` and `iomap_truncate_page()`, preventing reading of uninitialized page/disk contents.\n4. The iomap core structures (`struct iomap`, `struct iomap_writepage_ctx`) are zero-initialized prior to being populated by the filesystem callbacks.\n\nThe potential bugs introduced by this transition (such as locking issues, writeback races, or buffer out-of-bounds accesses) are covered by KASAN and LOCKDEP. There are no uninitialized memory access risks or info-leaks that would require a dedicated KMSAN fuzzing session.",
  "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 39277fb8636d2c138333c48e03b8696b2d711648
Author: syz-cluster <triage@syzkaller.com>
Date:   Tue Sep 15 01:31:24 2026 +0000

    syz-cluster: applied patch under review

diff --git a/fs/hfsplus/Kconfig b/fs/hfsplus/Kconfig
index ca8401cb6954d..b4432c64db3be 100644
--- a/fs/hfsplus/Kconfig
+++ b/fs/hfsplus/Kconfig
@@ -5,7 +5,7 @@ config HFSPLUS_FS
 	select BUFFER_HEAD
 	select NLS
 	select NLS_UTF8
-	select LEGACY_DIRECT_IO
+	select FS_IOMAP
 	help
 	  If you say Y here, you will be able to mount extended format
 	  Macintosh-formatted hard drive partitions with full read-write access.
diff --git a/fs/hfsplus/Makefile b/fs/hfsplus/Makefile
index f2a9ae697e811..3ddea69a9c698 100644
--- a/fs/hfsplus/Makefile
+++ b/fs/hfsplus/Makefile
@@ -5,8 +5,9 @@
 
 obj-$(CONFIG_HFSPLUS_FS) += hfsplus.o
 
-hfsplus-objs := super.o options.o inode.o ioctl.o extents.o catalog.o dir.o btree.o \
-		bnode.o brec.o bfind.o tables.o unicode.o wrapper.o bitmap.o part_tbl.o \
+hfsplus-objs := super.o options.o inode.o file.o iomap.o ioctl.o extents.o \
+		catalog.o dir.o btree.o bnode.o brec.o bfind.o tables.o \
+		unicode.o wrapper.o bitmap.o part_tbl.o \
 		attributes.o xattr.o xattr_user.o xattr_security.o xattr_trusted.o
 
 # KUnit tests
diff --git a/fs/hfsplus/bitmap.c b/fs/hfsplus/bitmap.c
index 1b3af8c87cadb..30178ea473624 100644
--- a/fs/hfsplus/bitmap.c
+++ b/fs/hfsplus/bitmap.c
@@ -39,6 +39,8 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size,
 		start = size;
 		goto out;
 	}
+	lock_page(page);
+	folio_wait_writeback(page_folio(page));
 	pptr = kmap_local_page(page);
 	curr = pptr + (offset & (PAGE_CACHE_BITS - 1)) / 32;
 	i = offset % 32;
@@ -75,6 +77,7 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size,
 			curr++;
 		}
 		kunmap_local(pptr);
+		unlock_page(page);
 		offset += PAGE_CACHE_BITS;
 		if (offset >= size)
 			break;
@@ -84,6 +87,8 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size,
 			start = size;
 			goto out;
 		}
+		lock_page(page);
+		folio_wait_writeback(page_folio(page));
 		curr = pptr = kmap_local_page(page);
 		if ((size ^ offset) / PAGE_CACHE_BITS)
 			end = pptr + PAGE_CACHE_BITS / 32;
@@ -98,6 +103,9 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size,
 	start = offset + (curr - pptr) * 32 + i;
 	if (start >= size) {
 		hfs_dbg("bitmap full\n");
+		kunmap_local(pptr);
+		unlock_page(page);
+		start = size;
 		goto out;
 	}
 	/* do any partial u32 at the start */
@@ -128,6 +136,7 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size,
 		}
 		set_page_dirty(page);
 		kunmap_local(pptr);
+		unlock_page(page);
 		offset += PAGE_CACHE_BITS;
 		page = read_mapping_page(mapping, offset / PAGE_CACHE_BITS,
 					 NULL);
@@ -135,6 +144,8 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size,
 			start = size;
 			goto out;
 		}
+		lock_page(page);
+		folio_wait_writeback(page_folio(page));
 		pptr = kmap_local_page(page);
 		curr = pptr;
 		end = pptr + PAGE_CACHE_BITS / 32;
@@ -152,6 +163,7 @@ int hfsplus_block_allocate(struct super_block *sb, u32 size,
 	*curr = cpu_to_be32(n);
 	set_page_dirty(page);
 	kunmap_local(pptr);
+	unlock_page(page);
 	*max = offset + (curr - pptr) * 32 + i - start;
 	sbi->free_blocks -= *max;
 	hfsplus_mark_mdb_dirty(sb);
@@ -185,6 +197,8 @@ int hfsplus_block_free(struct super_block *sb, u32 offset, u32 count)
 	page = read_mapping_page(mapping, pnr, NULL);
 	if (IS_ERR(page))
 		goto kaboom;
+	lock_page(page);
+	folio_wait_writeback(page_folio(page));
 	pptr = kmap_local_page(page);
 	curr = pptr + (offset & (PAGE_CACHE_BITS - 1)) / 32;
 	end = pptr + PAGE_CACHE_BITS / 32;
@@ -216,9 +230,12 @@ int hfsplus_block_free(struct super_block *sb, u32 offset, u32 count)
 			break;
 		set_page_dirty(page);
 		kunmap_local(pptr);
+		unlock_page(page);
 		page = read_mapping_page(mapping, ++pnr, NULL);
 		if (IS_ERR(page))
 			goto kaboom;
+		lock_page(page);
+		folio_wait_writeback(page_folio(page));
 		pptr = kmap_local_page(page);
 		curr = pptr;
 		end = pptr + PAGE_CACHE_BITS / 32;
@@ -232,6 +249,7 @@ int hfsplus_block_free(struct super_block *sb, u32 offset, u32 count)
 out:
 	set_page_dirty(page);
 	kunmap_local(pptr);
+	unlock_page(page);
 	sbi->free_blocks += len;
 	hfsplus_mark_mdb_dirty(sb);
 	mutex_unlock(&sbi->alloc_mutex);
diff --git a/fs/hfsplus/extents.c b/fs/hfsplus/extents.c
index eb7c11524d188..b724cc1ca3e1f 100644
--- a/fs/hfsplus/extents.c
+++ b/fs/hfsplus/extents.c
@@ -15,6 +15,7 @@
 
 #include "hfsplus_fs.h"
 #include "hfsplus_raw.h"
+#include "iomap.h"
 
 /* Compare two extents keys, returns 0 on same, pos/neg for difference */
 int hfsplus_ext_cmp_key(const hfsplus_btree_key *k1,
@@ -48,18 +49,29 @@ static void hfsplus_ext_build_key(hfsplus_btree_key *key, u32 cnid,
 	key->ext.pad = 0;
 }
 
-static u32 hfsplus_ext_find_block(struct hfsplus_extent *ext, u32 off)
+/*
+ * hfsplus_ext_find_block() - find contiguous sequence of block
+ *
+ * Find the disk allocation block for 'off' within an 8-entry
+ * extent record, and the number of further allocation blocks
+ * that are contiguous with it in the same extent entry.
+ */
+static u32 hfsplus_ext_find_block(struct hfsplus_extent *ext, u32 off,
+				 u32 *dblock)
 {
 	int i;
 	u32 count;
 
-	for (i = 0; i < 8; ext++, i++) {
+	for (i = 0; i < HFSPLUS_FORK_EXTENT_COUNT; ext++, i++) {
 		count = be32_to_cpu(ext->block_count);
-		if (off < count)
-			return be32_to_cpu(ext->start_block) + off;
+		if (off < count) {
+			*dblock = be32_to_cpu(ext->start_block) + off;
+			return count - off;
+		}
 		off -= count;
 	}
 	/* panic? */
+	*dblock = 0;
 	return 0;
 }
 
@@ -68,7 +80,7 @@ static int hfsplus_ext_block_count(struct hfsplus_extent *ext)
 	int i;
 	u32 count = 0;
 
-	for (i = 0; i < 8; ext++, i++)
+	for (i = 0; i < HFSPLUS_FORK_EXTENT_COUNT; ext++, i++)
 		count += be32_to_cpu(ext->block_count);
 	return count;
 }
@@ -225,37 +237,48 @@ static int hfsplus_ext_read_extent(struct inode *inode, u32 block)
 	return res;
 }
 
-/* Get a block at iblock for inode, possibly allocating if create */
-int hfsplus_get_block(struct inode *inode, sector_t iblock,
-		      struct buffer_head *bh_result, int create)
+/*
+ * hfsplus_map_extent() - find or allocate a sequence of allocation blocks
+ *
+ * Looks up the allocation block at 'ablock' for inode, extending the
+ * file (via hfsplus_file_extend(), in clump_blocks-sized chunks) when
+ * 'create' is set and 'ablock' lies beyond the current allocation.
+ *
+ * On success, *dblock is the disk allocation block backing 'ablock',
+ * and *max_blocks is the number of further allocation blocks that are
+ * contiguous with it (i.e. the remaining length of the extent entry
+ * that contains 'ablock'), which may be smaller than the whole file's
+ * remaining allocation when the fork is fragmented across several
+ * extent entries. If a new extent had to be allocated to satisfy the
+ * request, *balloc (when non-NULL) is set to true.
+ */
+int hfsplus_map_extent(struct inode *inode, u32 ablock, int create,
+			u32 *dblock, u32 *max_blocks, bool *balloc)
 {
-	struct super_block *sb = inode->i_sb;
-	struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
 	struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
-	int res = -EIO;
-	u32 ablock, dblock, mask;
-	sector_t sector;
-	int was_dirty = 0;
+	int was_dirty;
+	int res;
 
-	/* Convert inode block to disk allocation block */
-	ablock = iblock >> sbi->fs_shift;
+	if (balloc)
+		*balloc = false;
 
-	if (iblock >= hip->fs_blocks) {
+	if (ablock >= hip->alloc_blocks) {
 		if (!create)
-			return 0;
-		if (iblock > hip->fs_blocks)
 			return -EIO;
-		if (ablock >= hip->alloc_blocks) {
-			res = hfsplus_file_extend(inode, false);
-			if (res)
-				return res;
-		}
-	} else
-		create = 0;
+		res = hfsplus_file_extend(inode, false);
+		if (res)
+			return res;
+		if (balloc)
+			*balloc = true;
+	}
 
 	if (ablock < hip->first_blocks) {
-		dblock = hfsplus_ext_find_block(hip->first_extents, ablock);
-		goto done;
+		*max_blocks = hfsplus_ext_find_block(hip->first_extents,
+						     ablock,
+						     dblock);
+		if (!*max_blocks)
+			return -EIO;
+		return 0;
 	}
 
 	if (inode->i_ino == HFSPLUS_EXT_CNID)
@@ -274,11 +297,47 @@ int hfsplus_get_block(struct inode *inode, sector_t iblock,
 		mutex_unlock(&hip->extents_lock);
 		return -EIO;
 	}
-	dblock = hfsplus_ext_find_block(hip->cached_extents,
-					ablock - hip->cached_start);
+	*max_blocks = hfsplus_ext_find_block(hip->cached_extents,
+					     ablock - hip->cached_start,
+					     dblock);
 	mutex_unlock(&hip->extents_lock);
 
-done:
+	if (was_dirty)
+		mark_inode_dirty(inode);
+
+	if (!*max_blocks)
+		return -EIO;
+
+	return 0;
+}
+
+/* Get a block at iblock for inode, possibly allocating if create */
+int hfsplus_get_block(struct inode *inode, sector_t iblock,
+		      struct buffer_head *bh_result, int create)
+{
+	struct super_block *sb = inode->i_sb;
+	struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
+	struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
+	u32 ablock, dblock, mask, max_blocks;
+	sector_t sector;
+	int res;
+
+	/* Convert inode block to disk allocation block */
+	ablock = iblock >> sbi->fs_shift;
+
+	if (iblock >= hip->fs_blocks) {
+		if (!create)
+			return 0;
+		if (iblock > hip->fs_blocks)
+			return -EIO;
+	} else
+		create = 0;
+
+	res = hfsplus_map_extent(inode, ablock, create, &dblock, &max_blocks,
+				  NULL);
+	if (res)
+		return res;
+
 	hfs_dbg("ino %llu, iblock %llu - dblock %u\n",
 		inode->i_ino, (long long)iblock, dblock);
 
@@ -289,12 +348,11 @@ int hfsplus_get_block(struct inode *inode, sector_t iblock,
 
 	if (create) {
 		set_buffer_new(bh_result);
-		hip->phys_size += sb->s_blocksize;
+		hip->phys_size = (loff_t)(iblock + 1) << sb->s_blocksize_bits;
 		hip->fs_blocks++;
 		inode_add_bytes(inode, sb->s_blocksize);
-	}
-	if (create || was_dirty)
 		mark_inode_dirty(inode);
+	}
 	return 0;
 }
 
@@ -555,20 +613,33 @@ void hfsplus_file_truncate(struct inode *inode)
 		inode->i_ino, (long long)hip->phys_size, inode->i_size);
 
 	if (inode->i_size > hip->phys_size) {
-		struct address_space *mapping = inode->i_mapping;
-		struct folio *folio;
-		void *fsdata = NULL;
-		loff_t size = inode->i_size;
+		if (S_ISREG(inode->i_mode)) {
+			res = hfsplus_iomap_cont_expand(inode, hip->phys_size,
+							inode->i_size);
+			if (res)
+				return;
+
+			mark_inode_dirty(inode);
+		} else {
+			struct address_space *mapping = inode->i_mapping;
+			struct folio *folio;
+			void *fsdata = NULL;
+
+			res = hfsplus_write_begin(NULL, mapping,
+						  inode->i_size, 0,
+						  &folio, &fsdata);
+			if (res)
+				return;
+
+			res = generic_write_end(NULL, mapping,
+						inode->i_size, 0, 0,
+						folio, fsdata);
+			if (res < 0)
+				return;
+
+			mark_inode_dirty(inode);
+		}
 
-		res = hfsplus_write_begin(NULL, mapping, size, 0,
-					  &folio, &fsdata);
-		if (res)
-			return;
-		res = generic_write_end(NULL, mapping, size, 0, 0,
-					folio, fsdata);
-		if (res < 0)
-			return;
-		mark_inode_dirty(inode);
 		return;
 	} else if (inode->i_size == hip->phys_size)
 		return;
diff --git a/fs/hfsplus/file.c b/fs/hfsplus/file.c
new file mode 100644
index 0000000000000..0b0ae6b6e307f
--- /dev/null
+++ b/fs/hfsplus/file.c
@@ -0,0 +1,304 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * File operations: open/release/fsync and iomap-based read/write/seek
+ */
+
+#include <linux/fs.h>
+#include <linux/uio.h>
+#include <linux/mount.h>
+#include <linux/iomap.h>
+
+#include "hfsplus_fs.h"
+#include "hfsplus_raw.h"
+#include "iomap.h"
+
+static int hfsplus_file_open(struct inode *inode, struct file *file)
+{
+	if (HFSPLUS_IS_RSRC(inode))
+		inode = HFSPLUS_I(inode)->rsrc_inode;
+	if (!(file->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS)
+		return -EOVERFLOW;
+	atomic_inc(&HFSPLUS_I(inode)->opencnt);
+	file->f_mode |= FMODE_CAN_ODIRECT;
+	return 0;
+}
+
+static int hfsplus_file_release(struct inode *inode, struct file *file)
+{
+	struct super_block *sb = inode->i_sb;
+
+	if (HFSPLUS_IS_RSRC(inode))
+		inode = HFSPLUS_I(inode)->rsrc_inode;
+	if (atomic_dec_and_test(&HFSPLUS_I(inode)->opencnt)) {
+		inode_lock(inode);
+		hfsplus_file_truncate(inode);
+		if (inode->i_flags & S_DEAD) {
+			hfsplus_delete_cat(inode->i_ino,
+					   HFSPLUS_SB(sb)->hidden_dir, NULL);
+			hfsplus_delete_inode(inode);
+		}
+		inode_unlock(inode);
+	}
+	return 0;
+}
+
+int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,
+		       int datasync)
+{
+	struct inode *inode = file->f_mapping->host;
+	struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
+	struct super_block *sb = inode->i_sb;
+	struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
+	struct hfsplus_vh *vhdr = sbi->s_vhdr;
+	int error = 0, error2;
+
+	hfs_dbg("inode->i_ino %llu, start %llu, end %llu\n",
+		inode->i_ino, start, end);
+
+	error = file_write_and_wait_range(file, start, end);
+	if (error)
+		return error;
+
+	/*
+	 * Sync inode metadata into the catalog and extent trees.
+	 */
+	sync_inode_metadata(inode, 1);
+
+	/*
+	 * And explicitly write out the btrees.
+	 */
+	if (test_and_clear_bit(HFSPLUS_I_CAT_DIRTY,
+				&HFSPLUS_I(HFSPLUS_CAT_TREE_I(sb))->flags)) {
+		clear_bit(HFSPLUS_I_CAT_DIRTY, &hip->flags);
+		error = filemap_write_and_wait(sbi->cat_tree->inode->i_mapping);
+	}
+
+	if (test_and_clear_bit(HFSPLUS_I_EXT_DIRTY,
+				&HFSPLUS_I(HFSPLUS_EXT_TREE_I(sb))->flags)) {
+		clear_bit(HFSPLUS_I_EXT_DIRTY, &hip->flags);
+		error2 =
+			filemap_write_and_wait(sbi->ext_tree->inode->i_mapping);
+		if (!error)
+			error = error2;
+	}
+
+	if (sbi->attr_tree) {
+		if (test_and_clear_bit(HFSPLUS_I_ATTR_DIRTY,
+				&HFSPLUS_I(HFSPLUS_ATTR_TREE_I(sb))->flags)) {
+			clear_bit(HFSPLUS_I_ATTR_DIRTY, &hip->flags);
+			error2 =
+				filemap_write_and_wait(
+					    sbi->attr_tree->inode->i_mapping);
+			if (!error)
+				error = error2;
+		}
+	} else {
+		if (test_and_clear_bit(HFSPLUS_I_ATTR_DIRTY, &hip->flags))
+			pr_err("sync non-existent attributes tree\n");
+	}
+
+	if (test_and_clear_bit(HFSPLUS_I_ALLOC_DIRTY,
+				&HFSPLUS_I(sbi->alloc_file)->flags)) {
+		clear_bit(HFSPLUS_I_ALLOC_DIRTY, &hip->flags);
+		error2 = filemap_write_and_wait(sbi->alloc_file->i_mapping);
+		if (!error)
+			error = error2;
+	}
+
+	mutex_lock(&sbi->vh_mutex);
+	hfsplus_prepare_volume_header_for_commit(vhdr);
+	mutex_unlock(&sbi->vh_mutex);
+
+	error2 = hfsplus_commit_superblock(inode->i_sb);
+	if (!error)
+		error = error2;
+
+	if (!test_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags))
+		blkdev_issue_flush(inode->i_sb->s_bdev);
+
+	return error;
+}
+
+/*
+ * hfsplus_fallback_buffered_write() - fall back to buffered I/O for the
+ * tail of a write that iomap_dio_rw() could not perform directly
+ * (unaligned tail, or no blocks could be mapped without allocation
+ * outside the direct path).
+ */
+static ssize_t hfsplus_fallback_buffered_write(struct kiocb *iocb,
+						struct iov_iter *from)
+{
+	loff_t offset = iocb->ki_pos, end;
+	ssize_t written;
+	int ret;
+
+	iocb->ki_flags &= ~IOCB_DIRECT;
+
+	written = iomap_file_buffered_write(iocb, from,
+					    &hfsplus_write_iomap_ops,
+					    NULL, NULL);
+	if (written < 0)
+		return written;
+
+	end = iocb->ki_pos + written - 1;
+	ret = filemap_write_and_wait_range(iocb->ki_filp->f_mapping,
+					   offset, end);
+	if (ret)
+		return -EIO;
+
+	invalidate_mapping_pages(iocb->ki_filp->f_mapping,
+				 offset >> PAGE_SHIFT,
+				 end >> PAGE_SHIFT);
+
+	return written;
+}
+
+static ssize_t hfsplus_dio_write_iter(struct kiocb *iocb,
+					struct iov_iter *from,
+					unsigned int dio_flags)
+{
+	ssize_t ret;
+
+	ret = iomap_dio_rw(iocb, from,
+			   &hfsplus_write_iomap_ops,
+			   &hfsplus_write_dio_ops,
+			   dio_flags, NULL, 0);
+	if (ret == -ENOTBLK)
+		ret = 0;
+	else if (ret < 0)
+		return ret;
+
+	if (iov_iter_count(from)) {
+		ssize_t written;
+
+		written = hfsplus_fallback_buffered_write(iocb, from);
+		if (written < 0)
+			return written;
+		ret += written;
+	}
+
+	return ret;
+}
+
+static ssize_t hfsplus_file_write_iter(struct kiocb *iocb,
+					struct iov_iter *iter)
+{
+	struct file *file = iocb->ki_filp;
+	struct inode *inode = file_inode(file);
+	struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
+	loff_t total_capacity;
+	ssize_t ret;
+	int err;
+
+	inode_lock(inode);
+
+	ret = generic_write_checks(iocb, iter);
+	if (ret <= 0)
+		goto unlock;
+
+	total_capacity = (loff_t)sbi->total_blocks << sbi->alloc_blksz_shift;
+	if (iocb->ki_pos >= total_capacity) {
+		ret = -EFBIG;
+		goto unlock;
+	}
+
+	err = file_modified(file);
+	if (err) {
+		ret = err;
+		goto unlock;
+	}
+
+	if (iocb->ki_pos > i_size_read(inode)) {
+		loff_t old_size = i_size_read(inode);
+
+		i_size_write(inode, iocb->ki_pos);
+		err = hfsplus_iomap_cont_expand(inode, old_size, iocb->ki_pos);
+		if (err) {
+			i_size_write(inode, old_size);
+			ret = err;
+			goto unlock;
+		}
+		mark_inode_dirty(inode);
+	}
+
+	if (iocb->ki_flags & IOCB_DIRECT) {
+		unsigned int dio_flags = 0;
+
+		if (iocb->ki_pos + iov_iter_count(iter) >
+		    HFSPLUS_I(inode)->phys_size)
+			dio_flags |= IOMAP_DIO_FORCE_WAIT;
+
+		ret = hfsplus_dio_write_iter(iocb, iter, dio_flags);
+	} else {
+		ret = iomap_file_buffered_write(iocb, iter,
+						&hfsplus_write_iomap_ops,
+						NULL, NULL);
+	}
+
+unlock:
+	inode_unlock(inode);
+
+	if (ret > 0)
+		ret = generic_write_sync(iocb, ret);
+
+	return ret;
+}
+
+static ssize_t hfsplus_file_read_iter(struct kiocb *iocb,
+					struct iov_iter *iter)
+{
+	struct inode *inode = file_inode(iocb->ki_filp);
+	ssize_t ret;
+
+	inode_lock_shared(inode);
+
+	if (iocb->ki_flags & IOCB_DIRECT) {
+		file_accessed(iocb->ki_filp);
+		ret = iomap_dio_rw(iocb, iter,
+				   &hfsplus_iomap_ops,
+				   NULL, 0, NULL, 0);
+	} else
+		ret = generic_file_read_iter(iocb, iter);
+
+	inode_unlock_shared(inode);
+
+	return ret;
+}
+
+static loff_t hfsplus_file_llseek(struct file *file, loff_t offset, int whence)
+{
+	struct inode *inode = file->f_mapping->host;
+
+	switch (whence) {
+	case SEEK_HOLE:
+		inode_lock_shared(inode);
+		offset = iomap_seek_hole(inode, offset, &hfsplus_iomap_ops);
+		inode_unlock_shared(inode);
+		break;
+	case SEEK_DATA:
+		inode_lock_shared(inode);
+		offset = iomap_seek_data(inode, offset, &hfsplus_iomap_ops);
+		inode_unlock_shared(inode);
+		break;
+	default:
+		return generic_file_llseek(file, offset, whence);
+	}
+
+	if (offset < 0)
+		return offset;
+
+	return vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
+}
+
+const struct file_operations hfsplus_file_operations = {
+	.llseek		= hfsplus_file_llseek,
+	.read_iter	= hfsplus_file_read_iter,
+	.write_iter	= hfsplus_file_write_iter,
+	.mmap_prepare	= generic_file_mmap_prepare,
+	.splice_read	= filemap_splice_read,
+	.splice_write	= iter_file_splice_write,
+	.fsync		= hfsplus_file_fsync,
+	.open		= hfsplus_file_open,
+	.release	= hfsplus_file_release,
+	.unlocked_ioctl = hfsplus_ioctl,
+};
diff --git a/fs/hfsplus/hfsplus_fs.h b/fs/hfsplus/hfsplus_fs.h
index 1e5b58e6a13fc..844027679a750 100644
--- a/fs/hfsplus/hfsplus_fs.h
+++ b/fs/hfsplus/hfsplus_fs.h
@@ -175,6 +175,22 @@ static inline struct hfsplus_sb_info *HFSPLUS_SB(struct super_block *sb)
 	return sb->s_fs_info;
 }
 
+/*
+ * Physical byte offset of allocation block 'dblock' on the volume.
+ */
+static inline loff_t hfsplus_ablock_to_phys_bytes(struct super_block *sb,
+						  u32 dblock)
+{
+	struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
+	loff_t phys_bytes;
+
+	phys_bytes = dblock;
+	phys_bytes <<= sbi->fs_shift;
+	phys_bytes += sbi->blockoffset;
+	phys_bytes <<= sb->s_blocksize_bits;
+
+	return phys_bytes;
+}
 
 struct hfsplus_inode_info {
 	atomic_t opencnt;
@@ -430,12 +446,19 @@ int hfsplus_rename_cat(u32 cnid, struct inode *src_dir, const struct qstr *src_n
 extern const struct inode_operations hfsplus_dir_inode_operations;
 extern const struct file_operations hfsplus_dir_operations;
 
+/* file.c */
+extern const struct file_operations hfsplus_file_operations;
+int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,
+		       int datasync);
+
 /* extents.c */
 int hfsplus_ext_cmp_key(const hfsplus_btree_key *k1,
 			const hfsplus_btree_key *k2);
 int hfsplus_ext_write_extent(struct inode *inode);
 int hfsplus_get_block(struct inode *inode, sector_t iblock,
 		      struct buffer_head *bh_result, int create);
+int hfsplus_map_extent(struct inode *inode, u32 ablock, int create,
+			u32 *dblock, u32 *max_blocks, bool *balloc);
 int hfsplus_free_fork(struct super_block *sb, u32 cnid,
 		      struct hfsplus_fork_raw *fork, int type);
 int hfsplus_file_extend(struct inode *inode, bool zeroout);
@@ -443,6 +466,7 @@ void hfsplus_file_truncate(struct inode *inode);
 
 /* inode.c */
 extern const struct address_space_operations hfsplus_aops;
+extern const struct address_space_operations hfsplus_symlink_aops;
 extern const struct address_space_operations hfsplus_btree_aops;
 extern const struct dentry_operations hfsplus_dentry_operations;
 
@@ -462,8 +486,6 @@ int hfsplus_cat_write_inode(struct inode *inode);
 int hfsplus_getattr(struct mnt_idmap *idmap, const struct path *path,
 		    struct kstat *stat, u32 request_mask,
 		    unsigned int query_flags);
-int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,
-		       int datasync);
 int hfsplus_fileattr_get(struct dentry *dentry, struct file_kattr *fa);
 int hfsplus_fileattr_set(struct mnt_idmap *idmap,
 			 struct dentry *dentry, struct file_kattr *fa);
diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
index 2ce6de574fa6e..1779061dcad5b 100644
--- a/fs/hfsplus/inode.c
+++ b/fs/hfsplus/inode.c
@@ -18,15 +18,12 @@
 #include <linux/cred.h>
 #include <linux/uio.h>
 #include <linux/fileattr.h>
+#include <linux/iomap.h>
 
 #include "hfsplus_fs.h"
 #include "hfsplus_raw.h"
 #include "xattr.h"
-
-static int hfsplus_read_folio(struct file *file, struct folio *folio)
-{
-	return block_read_full_folio(folio, hfsplus_get_block);
-}
+#include "iomap.h"
 
 static void hfsplus_write_failed(struct address_space *mapping, loff_t to)
 {
@@ -128,67 +125,13 @@ static bool hfsplus_release_folio(struct folio *folio, gfp_t mask)
 	return res ? try_to_free_buffers(folio) : false;
 }
 
-static ssize_t hfsplus_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
+static int hfsplus_btree_read_folio(struct file *file, struct folio *folio)
 {
-	struct file *file = iocb->ki_filp;
-	struct address_space *mapping = file->f_mapping;
-	struct inode *inode = mapping->host;
-	loff_t isize;
-	size_t count = iov_iter_count(iter);
-	loff_t end = iocb->ki_pos + count;
-	ssize_t ret;
-
-	/*
-	 * The hfsplus_get_block() only allows creating the next sequential block.
-	 * For direct writes beyond EOF, expand the file first.
-	 */
-	if (iov_iter_rw(iter) == WRITE && iocb->ki_pos > i_size_read(inode)) {
-		loff_t start_off, end_off;
-		loff_t start_page, end_page;
-
-		isize = i_size_read(inode);
-
-		/*
-		 * Wait for any in-flight DIO on this inode to finish before
-		 * calling generic_cont_expand_simple().
-		 */
-		inode_dio_wait(inode);
-
-		ret = generic_cont_expand_simple(inode, iocb->ki_pos);
-		if (ret)
-			return ret;
-
-		start_off = isize;
-		end_off = (end > 0) ? end - 1 : end;
-
-		ret = filemap_write_and_wait_range(mapping, start_off, end_off);
-		if (ret)
-			return ret;
-
-		start_page = start_off >> PAGE_SHIFT;
-		end_page = end_off >> PAGE_SHIFT;
-
-		invalidate_inode_pages2_range(mapping, start_page, end_page);
-	}
-
-	ret = blockdev_direct_IO(iocb, inode, iter, hfsplus_get_block);
-
-	/*
-	 * In case of error extending write may have instantiated a few
-	 * blocks outside i_size. Trim these off again.
-	 */
-	if (unlikely(iov_iter_rw(iter) == WRITE && ret < 0)) {
-		isize = i_size_read(inode);
-
-		if (end > isize)
-			hfsplus_write_failed(mapping, end);
-	}
-
-	return ret;
+	return block_read_full_folio(folio, hfsplus_get_block);
 }
 
-static int hfsplus_writepages(struct address_space *mapping,
-			      struct writeback_control *wbc)
+static int hfsplus_btree_writepages(struct address_space *mapping,
+				    struct writeback_control *wbc)
 {
 	return mpage_writepages(mapping, wbc, hfsplus_get_block);
 }
@@ -196,8 +139,8 @@ static int hfsplus_writepages(struct address_space *mapping,
 const struct address_space_operations hfsplus_btree_aops = {
 	.dirty_folio	= block_dirty_folio,
 	.invalidate_folio = block_invalidate_folio,
-	.read_folio	= hfsplus_read_folio,
-	.writepages	= hfsplus_writepages,
+	.read_folio	= hfsplus_btree_read_folio,
+	.writepages	= hfsplus_btree_writepages,
 	.write_begin	= hfsplus_write_begin,
 	.write_end	= generic_write_end,
 	.migrate_folio	= buffer_migrate_folio,
@@ -205,18 +148,70 @@ const struct address_space_operations hfsplus_btree_aops = {
 	.release_folio	= hfsplus_release_folio,
 };
 
-const struct address_space_operations hfsplus_aops = {
+static int hfsplus_symlink_read_folio(struct file *file, struct folio *folio)
+{
+	return block_read_full_folio(folio, hfsplus_get_block);
+}
+
+static int hfsplus_symlink_writepages(struct address_space *mapping,
+				      struct writeback_control *wbc)
+{
+	return mpage_writepages(mapping, wbc, hfsplus_get_block);
+}
+
+const struct address_space_operations hfsplus_symlink_aops = {
 	.dirty_folio	= block_dirty_folio,
 	.invalidate_folio = block_invalidate_folio,
-	.read_folio	= hfsplus_read_folio,
+	.read_folio	= hfsplus_symlink_read_folio,
 	.write_begin	= hfsplus_write_begin,
 	.write_end	= generic_write_end,
 	.bmap		= hfsplus_bmap,
-	.direct_IO	= hfsplus_direct_IO,
-	.writepages	= hfsplus_writepages,
+	.writepages	= hfsplus_symlink_writepages,
 	.migrate_folio	= buffer_migrate_folio,
 };
 
+static int hfsplus_read_folio(struct file *file, struct folio *folio)
+{
+	iomap_bio_read_folio(folio, &hfsplus_iomap_ops);
+	return 0;
+}
+
+static void hfsplus_readahead(struct readahead_control *rac)
+{
+	iomap_bio_readahead(rac, &hfsplus_iomap_ops);
+}
+
+static int hfsplus_writepages(struct address_space *mapping,
+			      struct writeback_control *wbc)
+{
+	struct iomap_writepage_ctx wpc = {
+		.inode	= mapping->host,
+		.wbc	= wbc,
+		.ops	= &hfsplus_writeback_ops,
+	};
+
+	return iomap_writepages(&wpc);
+}
+
+static sector_t hfsplus_aop_bmap(struct address_space *mapping, sector_t block)
+{
+	return iomap_bmap(mapping, block, &hfsplus_iomap_ops);
+}
+
+const struct address_space_operations hfsplus_aops = {
+	.read_folio		= hfsplus_read_folio,
+	.readahead		= hfsplus_readahead,
+	.writepages		= hfsplus_writepages,
+	.dirty_folio		= iomap_dirty_folio,
+	.bmap			= hfsplus_aop_bmap,
+	.migrate_folio		= filemap_migrate_folio,
+	.is_partially_uptodate	= iomap_is_partially_uptodate,
+	.error_remove_folio	= generic_error_remove_folio,
+	.release_folio		= iomap_release_folio,
+	.invalidate_folio	= iomap_invalidate_folio,
+	.swap_activate		= hfsplus_iomap_swap_activate,
+};
+
 const struct dentry_operations hfsplus_dentry_operations = {
 	.d_hash       = hfsplus_hash_dentry,
 	.d_compare    = hfsplus_compare_dentry,
@@ -276,35 +271,6 @@ static int hfsplus_get_perms(struct inode *inode,
 	return -EIO;
 }
 
-static int hfsplus_file_open(struct inode *inode, struct file *file)
-{
-	if (HFSPLUS_IS_RSRC(inode))
-		inode = HFSPLUS_I(inode)->rsrc_inode;
-	if (!(file->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS)
-		return -EOVERFLOW;
-	atomic_inc(&HFSPLUS_I(inode)->opencnt);
-	return 0;
-}
-
-static int hfsplus_file_release(struct inode *inode, struct file *file)
-{
-	struct super_block *sb = inode->i_sb;
-
-	if (HFSPLUS_IS_RSRC(inode))
-		inode = HFSPLUS_I(inode)->rsrc_inode;
-	if (atomic_dec_and_test(&HFSPLUS_I(inode)->opencnt)) {
-		inode_lock(inode);
-		hfsplus_file_truncate(inode);
-		if (inode->i_flags & S_DEAD) {
-			hfsplus_delete_cat(inode->i_ino,
-					   HFSPLUS_SB(sb)->hidden_dir, NULL);
-			hfsplus_delete_inode(inode);
-		}
-		inode_unlock(inode);
-	}
-	return 0;
-}
-
 static int hfsplus_setattr(struct mnt_idmap *idmap,
 			   struct dentry *dentry, struct iattr *attr)
 {
@@ -319,13 +285,28 @@ static int hfsplus_setattr(struct mnt_idmap *idmap,
 	    attr->ia_size != i_size_read(inode)) {
 		inode_dio_wait(inode);
 		if (attr->ia_size > inode->i_size) {
-			error = generic_cont_expand_simple(inode,
-							   attr->ia_size);
+			loff_t old_size = inode->i_size;
+
+			i_size_write(inode, attr->ia_size);
+			error = hfsplus_iomap_cont_expand(inode, old_size,
+							  attr->ia_size);
+			if (error) {
+				i_size_write(inode, old_size);
+				return error;
+			}
+			truncate_setsize(inode, attr->ia_size);
+		} else {
+			bool did_zero = false;
+
+			error = iomap_truncate_page(inode, attr->ia_size,
+						    &did_zero,
+						    &hfsplus_write_iomap_ops,
+						    NULL, NULL);
 			if (error)
 				return error;
+			truncate_setsize(inode, attr->ia_size);
+			hfsplus_file_truncate(inode);
 		}
-		truncate_setsize(inode, attr->ia_size);
-		hfsplus_file_truncate(inode);
 		inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
 	}
 
@@ -361,86 +342,6 @@ int hfsplus_getattr(struct mnt_idmap *idmap, const struct path *path,
 	return 0;
 }
 
-int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,
-		       int datasync)
-{
-	struct inode *inode = file->f_mapping->host;
-	struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
-	struct super_block *sb = inode->i_sb;
-	struct hfsplus_sb_info *sbi = HFSPLUS_SB(inode->i_sb);
-	struct hfsplus_vh *vhdr = sbi->s_vhdr;
-	int error = 0, error2;
-
-	hfs_dbg("inode->i_ino %llu, start %llu, end %llu\n",
-		inode->i_ino, start, end);
-
-	error = file_write_and_wait_range(file, start, end);
-	if (error)
-		return error;
-	inode_lock(inode);
-
-	/*
-	 * Sync inode metadata into the catalog and extent trees.
-	 */
-	sync_inode_metadata(inode, 1);
-
-	/*
-	 * And explicitly write out the btrees.
-	 */
-	if (test_and_clear_bit(HFSPLUS_I_CAT_DIRTY,
-				&HFSPLUS_I(HFSPLUS_CAT_TREE_I(sb))->flags)) {
-		clear_bit(HFSPLUS_I_CAT_DIRTY, &hip->flags);
-		error = filemap_write_and_wait(sbi->cat_tree->inode->i_mapping);
-	}
-
-	if (test_and_clear_bit(HFSPLUS_I_EXT_DIRTY,
-				&HFSPLUS_I(HFSPLUS_EXT_TREE_I(sb))->flags)) {
-		clear_bit(HFSPLUS_I_EXT_DIRTY, &hip->flags);
-		error2 =
-			filemap_write_and_wait(sbi->ext_tree->inode->i_mapping);
-		if (!error)
-			error = error2;
-	}
-
-	if (sbi->attr_tree) {
-		if (test_and_clear_bit(HFSPLUS_I_ATTR_DIRTY,
-				&HFSPLUS_I(HFSPLUS_ATTR_TREE_I(sb))->flags)) {
-			clear_bit(HFSPLUS_I_ATTR_DIRTY, &hip->flags);
-			error2 =
-				filemap_write_and_wait(
-					    sbi->attr_tree->inode->i_mapping);
-			if (!error)
-				error = error2;
-		}
-	} else {
-		if (test_and_clear_bit(HFSPLUS_I_ATTR_DIRTY, &hip->flags))
-			pr_err("sync non-existent attributes tree\n");
-	}
-
-	if (test_and_clear_bit(HFSPLUS_I_ALLOC_DIRTY,
-				&HFSPLUS_I(sbi->alloc_file)->flags)) {
-		clear_bit(HFSPLUS_I_ALLOC_DIRTY, &hip->flags);
-		error2 = filemap_write_and_wait(sbi->alloc_file->i_mapping);
-		if (!error)
-			error = error2;
-	}
-
-	mutex_lock(&sbi->vh_mutex);
-	hfsplus_prepare_volume_header_for_commit(vhdr);
-	mutex_unlock(&sbi->vh_mutex);
-
-	error2 = hfsplus_commit_superblock(inode->i_sb);
-	if (!error)
-		error = error2;
-
-	if (!test_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags))
-		blkdev_issue_flush(inode->i_sb->s_bdev);
-
-	inode_unlock(inode);
-
-	return error;
-}
-
 static const struct inode_operations hfsplus_file_inode_operations = {
 	.setattr	= hfsplus_setattr,
 	.getattr	= hfsplus_getattr,
@@ -462,19 +363,6 @@ static const struct inode_operations hfsplus_special_inode_operations = {
 	.listxattr	= hfsplus_listxattr,
 };
 
-static const struct file_operations hfsplus_file_operations = {
-	.llseek		= generic_file_llseek,
-	.read_iter	= generic_file_read_iter,
-	.write_iter	= generic_file_write_iter,
-	.mmap_prepare	= generic_file_mmap_prepare,
-	.splice_read	= filemap_splice_read,
-	.splice_write	= iter_file_splice_write,
-	.fsync		= hfsplus_file_fsync,
-	.open		= hfsplus_file_open,
-	.release	= hfsplus_file_release,
-	.unlocked_ioctl = hfsplus_ioctl,
-};
-
 struct inode *hfsplus_new_inode(struct super_block *sb, struct inode *dir,
 				umode_t mode)
 {
@@ -521,7 +409,7 @@ struct inode *hfsplus_new_inode(struct super_block *sb, struct inode *dir,
 		sbi->file_count++;
 		inode->i_op = &hfsplus_symlink_inode_operations;
 		inode_nohighmem(inode);
-		inode->i_mapping->a_ops = &hfsplus_aops;
+		inode->i_mapping->a_ops = &hfsplus_symlink_aops;
 		hip->clump_blocks = 1;
 	} else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
 		   S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
@@ -662,7 +550,7 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
 		} else if (S_ISLNK(inode->i_mode)) {
 			inode->i_op = &hfsplus_symlink_inode_operations;
 			inode_nohighmem(inode);
-			inode->i_mapping->a_ops = &hfsplus_aops;
+			inode->i_mapping->a_ops = &hfsplus_symlink_aops;
 		} else {
 			inode->i_op = &hfsplus_special_inode_operations;
 			init_special_inode(inode, inode->i_mode,
diff --git a/fs/hfsplus/iomap.c b/fs/hfsplus/iomap.c
new file mode 100644
index 0000000000000..0eb392789126d
--- /dev/null
+++ b/fs/hfsplus/iomap.c
@@ -0,0 +1,190 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * iomap callback functions for the hfsplus filesystem
+ */
+
+#include <linux/iomap.h>
+#include <linux/pagemap.h>
+
+#include "hfsplus_fs.h"
+#include "hfsplus_raw.h"
+#include "iomap.h"
+
+static int __hfsplus_iomap_begin(struct inode *inode, loff_t offset,
+				 loff_t length, unsigned int flags,
+				 struct iomap *iomap, bool may_alloc)
+{
+	struct super_block *sb = inode->i_sb;
+	struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
+	struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
+	u32 ablock, dblock, max_blocks;
+	loff_t ablock_offset, ablock_bytes;
+	loff_t block_start;
+	bool is_new;
+	int err;
+
+	if (!may_alloc) {
+		/* Completely beyond EOF. Treat as hole */
+		if (i_size_read(inode) <= offset) {
+			iomap->type = IOMAP_HOLE;
+			iomap->addr = IOMAP_NULL_ADDR;
+			iomap->offset = offset;
+			iomap->length = length;
+			return 0;
+		}
+
+		/* Clamp length if the requested range goes beyond i_size */
+		if (offset + length > i_size_read(inode)) {
+			loff_t i_size = i_size_read(inode);
+			unsigned int blocksize = i_blocksize(inode);
+
+			length = round_up(i_size, blocksize) - offset;
+		}
+	}
+
+	ablock = offset >> sbi->alloc_blksz_shift;
+
+	err = hfsplus_map_extent(inode, ablock, may_alloc, &dblock,
+				 &max_blocks, NULL);
+	if (err)
+		return err;
+
+	ablock_offset = offset & (sbi->alloc_blksz - 1);
+	ablock_bytes = (loff_t)max_blocks << sbi->alloc_blksz_shift;
+
+	length = min_t(loff_t, length, ablock_bytes - ablock_offset);
+	block_start = round_down(offset, i_blocksize(inode));
+	is_new = may_alloc && block_start >= hip->phys_size;
+	if (may_alloc && !is_new && offset < hip->phys_size)
+		length = min_t(loff_t, length, hip->phys_size - offset);
+
+	iomap->bdev = sb->s_bdev;
+	iomap->offset = offset;
+	iomap->length = length;
+	iomap->addr = hfsplus_ablock_to_phys_bytes(sb, dblock) + ablock_offset;
+	iomap->type = IOMAP_MAPPED;
+	iomap->flags = IOMAP_F_MERGED;
+
+	if (is_new)
+		iomap->flags |= IOMAP_F_NEW;
+
+	return 0;
+}
+
+static int hfsplus_iomap_begin(struct inode *inode, loff_t offset,
+				loff_t length, unsigned int flags,
+				struct iomap *iomap, struct iomap *srcmap)
+{
+	return __hfsplus_iomap_begin(inode,
+				     offset, length, flags,
+				     iomap, false);
+}
+
+static int hfsplus_write_iomap_begin(struct inode *inode, loff_t offset,
+				     loff_t length, unsigned int flags,
+				     struct iomap *iomap, struct iomap *srcmap)
+{
+	return __hfsplus_iomap_begin(inode,
+				     offset, length, flags,
+				     iomap, true);
+}
+
+const struct iomap_ops hfsplus_iomap_ops = {
+	.iomap_begin = hfsplus_iomap_begin,
+};
+
+/*
+ * hfsplus_write_iomap_end()
+ *
+ * Advance the allocated-and-zeroed high-water mark
+ * (hip->phys_size / hip->fs_blocks) to cover the newly written range.
+ */
+static int hfsplus_write_iomap_end(struct inode *inode, loff_t pos,
+				   loff_t length, ssize_t written,
+				   unsigned int flags, struct iomap *iomap)
+{
+	struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
+	struct super_block *sb = inode->i_sb;
+	loff_t end;
+	bool dirtied = false;
+
+	if (!written)
+		return 0;
+
+	end = pos + written;
+
+	if (iomap->flags & IOMAP_F_NEW)
+		end = round_up(end, sb->s_blocksize);
+
+	if (hip->phys_size < end) {
+		inode_add_bytes(inode, end - hip->phys_size);
+		hip->phys_size = end;
+		hip->fs_blocks = end >> sb->s_blocksize_bits;
+		dirtied = true;
+	}
+
+	if (dirtied)
+		mark_inode_dirty(inode);
+
+	return written;
+}
+
+const struct iomap_ops hfsplus_write_iomap_ops = {
+	.iomap_begin	= hfsplus_write_iomap_begin,
+	.iomap_end	= hfsplus_write_iomap_end,
+};
+
+/*
+ * hfsplus_iomap_cont_expand()
+ *
+ * Zero the byte range [from, to) of a file that is being extended, where
+ * 'from' is the old end-of-file and 'to' the new one. Used by the extending
+ * write path, hfsplus_setattr() (truncate up) and hfsplus_file_truncate().
+ */
+int hfsplus_iomap_cont_expand(struct inode *inode, loff_t from, loff_t to)
+{
+	if (to <= from)
+		return 0;
+
+	return iomap_zero_range(inode, from, to - from, NULL,
+				&hfsplus_write_iomap_ops, NULL, NULL);
+}
+
+/*
+ * hfsplus_writeback_range() - map folio during writeback
+ *
+ * Called for each folio during writeback. If the folio falls outside
+ * the current iomap, remaps by calling __hfsplus_iomap_begin() again.
+ */
+static ssize_t hfsplus_writeback_range(struct iomap_writepage_ctx *wpc,
+					struct folio *folio, u64 offset,
+					unsigned int len, u64 end_pos)
+{
+	int err;
+
+	if (offset < wpc->iomap.offset ||
+	    offset >= wpc->iomap.offset + wpc->iomap.length) {
+		err = __hfsplus_iomap_begin(wpc->inode,
+					    offset, len, 0,
+					    &wpc->iomap, false);
+		if (err)
+			return err;
+	}
+
+	return iomap_add_to_ioend(wpc, folio, offset, end_pos, len);
+}
+
+const struct iomap_writeback_ops hfsplus_writeback_ops = {
+	.writeback_range	= hfsplus_writeback_range,
+	.writeback_submit	= iomap_ioend_writeback_submit,
+};
+
+const struct iomap_dio_ops hfsplus_write_dio_ops = {
+	.end_io		= iomap_dio_end_io,
+};
+
+int hfsplus_iomap_swap_activate(struct swap_info_struct *sis,
+				 struct file *file, sector_t *span)
+{
+	return iomap_swapfile_activate(sis, file, span, &hfsplus_iomap_ops);
+}
diff --git a/fs/hfsplus/iomap.h b/fs/hfsplus/iomap.h
new file mode 100644
index 0000000000000..4dd4aca1804f8
--- /dev/null
+++ b/fs/hfsplus/iomap.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * iomap callback declarations for the hfsplus filesystem
+ */
+
+#ifndef _LINUX_HFSPLUS_IOMAP_H
+#define _LINUX_HFSPLUS_IOMAP_H
+
+extern const struct iomap_ops hfsplus_iomap_ops;
+extern const struct iomap_ops hfsplus_write_iomap_ops;
+extern const struct iomap_writeback_ops hfsplus_writeback_ops;
+extern const struct iomap_dio_ops hfsplus_write_dio_ops;
+
+int hfsplus_iomap_cont_expand(struct inode *inode, loff_t from, loff_t to);
+int hfsplus_iomap_swap_activate(struct swap_info_struct *sis,
+				struct file *file, sector_t *span);
+
+#endif /* _LINUX_HFSPLUS_IOMAP_H */
diff --git a/include/linux/hfs_common.h b/include/linux/hfs_common.h
index d6a615e74b26e..8673933bbee56 100644
--- a/include/linux/hfs_common.h
+++ b/include/linux/hfs_common.h
@@ -171,18 +171,22 @@ enum {
 	HFS_XATTR_NAME,
 };
 
+#define HFS_FORK_EXTENT_COUNT	(3)
+
 struct hfs_extent {
 	__be16 block;
 	__be16 count;
 };
-typedef struct hfs_extent hfs_extent_rec[3];
+typedef struct hfs_extent hfs_extent_rec[HFS_FORK_EXTENT_COUNT];
+
+#define HFSPLUS_FORK_EXTENT_COUNT	(8)
 
 /* A single contiguous area of a file */
 struct hfsplus_extent {
 	__be32 start_block;
 	__be32 block_count;
 } __packed;
-typedef struct hfsplus_extent hfsplus_extent_rec[8];
+typedef struct hfsplus_extent hfsplus_extent_rec[HFSPLUS_FORK_EXTENT_COUNT];
 
 /* Information for a "Fork" in a file */
 struct hfsplus_fork_raw {
diff --git a/include/linux/iomap.h b/include/linux/iomap.h
index bc7ae6327dbf8..66a6389c9c74c 100644
--- a/include/linux/iomap.h
+++ b/include/linux/iomap.h
@@ -636,6 +636,26 @@ struct iomap_dio_ops {
 	struct bio_set *bio_set;
 };
 
+/*
+ * Direct I/O completion handler
+ */
+static inline
+int iomap_dio_end_io(struct kiocb *iocb, ssize_t size,
+		     int error, unsigned int flags)
+{
+	struct inode *inode = file_inode(iocb->ki_filp);
+
+	if (error)
+		return error;
+
+	if (size && i_size_read(inode) < iocb->ki_pos + size) {
+		i_size_write(inode, iocb->ki_pos + size);
+		mark_inode_dirty(inode);
+	}
+
+	return 0;
+}
+
 /*
  * Wait for the I/O to complete in iomap_dio_rw even if the kiocb is not
  * synchronous.

15/3 2026/09/15 01:32 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 19096
							output: 32
							thoughts: 2580
						

Thoughts:
**KMSAN Assessment of HFS+ IOMAP Conversion**

Alright, let's dissect this patch. It's moving the HFS+ filesystem to iomap, ditching the legacy direct I/O and buffer head-based operations. My immediate focus, given my expertise, is on potential uninitialized memory risks. We have a clear mandate: KMSAN only if KASAN, LOCKDEP, or standard bug detectors won't catch it. KMSAN is expensive, so let's be judicious.

The patch is a massive overhaul, touching a lot of code. I see changes in `Kconfig`, `Makefile`, `bitmap.c`, `extents.c`, `file.c`, `hfsplus_fs.h`, `inode.c`, `iomap.c`, and `iomap.h`. I need to ensure this iomap implementation doesn't introduce a way to leak uninitialized memory to user space, or use it in a conditional or calculation.

My strategy is to target the critical functions directly: `__hfsplus_iomap_begin` and `hfsplus_map_extent` since those are core iomap entry points. I'm going to carefully read every variable declaration, assignment, and use within these functions.

Okay, let's start with `__hfsplus_iomap_begin`.  It seems reasonable, with some clamping logic in place for out-of-bounds reads.  The important call here is `hfsplus_map_extent`.  Time to drill down.

Now, `hfsplus_map_extent`. I see `int was_dirty;`.  Hold on a second... is that *uninitialized*?  The code reads:

```c
	int was_dirty;
	int res;
...
	if (was_dirty)
		mark_inode_dirty(inode);
```

There's no assignment to `was_dirty` before its use in that `if` statement! This is a classic potential uninitialized memory read! This is a major concern, because the value of was_dirty determines whether inode is marked dirty or not! That could have serious filesystem integrity implications! I need to be *sure* about this! I must verify that this code path is reachable.

I need to compare the code *before* and *after* the patch to confirm. I will go line by line through `hfsplus_get_block`, which `hfsplus_map_extent` replaces.

Bingo! The original code used `int was_dirty = 0;`. The patch *removes* the initialization! This is a definite regression. That "was_dirty" is potentially uninitialized. KMSAN is definitely needed here.

So, I'm going to set `NeedsKMSAN = true` because this patch exposes a clear risk of reading uninitialized memory, precisely the kind of issue that KMSAN is designed to detect. This is not something that would be caught by standard debuggers. This uninitialized variable potentially affects filesystem data and I need to ensure this is fixed!



16/3 2026/09/15 01:33 tool grepper
0m Args:
{
  "Expression": "hfsplus_map_extent",
  "PathPrefix": "fs/hfsplus"
}

Results:
{
  "Output": "fs/hfsplus/extents.c=222=static int hfsplus_ext_read_extent(struct inode *inode, u32 block)\n--\nfs/hfsplus/extents.c-240-/*\nfs/hfsplus/extents.c:241: * hfsplus_map_extent() - find or allocate a sequence of allocation blocks\nfs/hfsplus/extents.c-242- *\n--\nfs/hfsplus/extents.c-254- */\nfs/hfsplus/extents.c:255:int hfsplus_map_extent(struct inode *inode, u32 ablock, int create,\nfs/hfsplus/extents.c-256-\t\t\tu32 *dblock, u32 *max_blocks, bool *balloc)\n--\nfs/hfsplus/extents.c=315=int hfsplus_get_block(struct inode *inode, sector_t iblock,\n--\nfs/hfsplus/extents.c-335-\nfs/hfsplus/extents.c:336:\tres = hfsplus_map_extent(inode, ablock, create, \u0026dblock, \u0026max_blocks,\nfs/hfsplus/extents.c-337-\t\t\t\t  NULL);\n--\nfs/hfsplus/hfsplus_fs.h=458=int hfsplus_get_block(struct inode *inode, sector_t iblock,\nfs/hfsplus/hfsplus_fs.h-459-\t\t      struct buffer_head *bh_result, int create);\nfs/hfsplus/hfsplus_fs.h:460:int hfsplus_map_extent(struct inode *inode, u32 ablock, int create,\nfs/hfsplus/hfsplus_fs.h-461-\t\t\tu32 *dblock, u32 *max_blocks, bool *balloc);\n--\nfs/hfsplus/iomap.c=13=static int __hfsplus_iomap_begin(struct inode *inode, loff_t offset,\n--\nfs/hfsplus/iomap.c-46-\nfs/hfsplus/iomap.c:47:\terr = hfsplus_map_extent(inode, ablock, may_alloc, \u0026dblock,\nfs/hfsplus/iomap.c-48-\t\t\t\t \u0026max_blocks, NULL);\n"
}

17/3 2026/09/15 01:33 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 22984
							output: 38
							thoughts: 41
						

Thoughts:
Okay, let's dive into this. Here's my take on those lines of code:

**Analyzing the `hfsplus_map_extent` Function in `fs/hfsplus/extents.c`**

Alright, I'm going to take a look at lines 240-320 of `fs/hfsplus/extents.c`, specifically focusing on the `hfsplus_map_extent` function. I need to understand how this function handles mapping logical blocks to physical blocks within an HFS+ volume, particularly as it relates to extent management. I'm already pretty familiar with the overall HFS+ structure, but a refresher on the finer points of extent mapping is always worthwhile, and I'm interested to see the low-level implementation. I want to see how this function is dealing with situations where the requested logical block range doesn't map directly to a single contiguous extent. How is it handling extent fragmentation and allocation within the HFS+ filesystem? I'm hoping to get a clear picture of its error handling too – particularly its behavior when encountering issues like out-of-space conditions, or corrupted extent records. I'm expecting to see a lot of bitwise operations and potentially a good deal of pointer manipulation since we're working at a fairly low level. This is where the rubber meets the road, where the theoretical models of the filesystem translate into concrete operations on the disk. Let's see how it's done...



18/3 2026/09/15 01:33 tool read-file
0m Args:
{
  "File": "fs/hfsplus/extents.c",
  "FirstLine": 250,
  "LineCount": 70
}

Results:
{
  "Contents": " 250:\t * that contains 'ablock'), which may be smaller than the whole file's\n 251:\t * remaining allocation when the fork is fragmented across several\n 252:\t * extent entries. If a new extent had to be allocated to satisfy the\n 253:\t * request, *balloc (when non-NULL) is set to true.\n 254:\t */\n 255:\tint hfsplus_map_extent(struct inode *inode, u32 ablock, int create,\n 256:\t\t\t\tu32 *dblock, u32 *max_blocks, bool *balloc)\n 257:\t{\n 258:\t\tstruct hfsplus_inode_info *hip = HFSPLUS_I(inode);\n 259:\t\tint was_dirty;\n 260:\t\tint res;\n 261:\t\n 262:\t\tif (balloc)\n 263:\t\t\t*balloc = false;\n 264:\t\n 265:\t\tif (ablock \u003e= hip-\u003ealloc_blocks) {\n 266:\t\t\tif (!create)\n 267:\t\t\t\treturn -EIO;\n 268:\t\t\tres = hfsplus_file_extend(inode, false);\n 269:\t\t\tif (res)\n 270:\t\t\t\treturn res;\n 271:\t\t\tif (balloc)\n 272:\t\t\t\t*balloc = true;\n 273:\t\t}\n 274:\t\n 275:\t\tif (ablock \u003c hip-\u003efirst_blocks) {\n 276:\t\t\t*max_blocks = hfsplus_ext_find_block(hip-\u003efirst_extents,\n 277:\t\t\t\t\t\t\t     ablock,\n 278:\t\t\t\t\t\t\t     dblock);\n 279:\t\t\tif (!*max_blocks)\n 280:\t\t\t\treturn -EIO;\n 281:\t\t\treturn 0;\n 282:\t\t}\n 283:\t\n 284:\t\tif (inode-\u003ei_ino == HFSPLUS_EXT_CNID)\n 285:\t\t\treturn -EIO;\n 286:\t\n 287:\t\tmutex_lock(\u0026hip-\u003eextents_lock);\n 288:\t\n 289:\t\t/*\n 290:\t\t * hfsplus_ext_read_extent will write out a cached extent into\n 291:\t\t * the extents btree.  In that case we may have to mark the inode\n 292:\t\t * dirty even for a pure read of an extent here.\n 293:\t\t */\n 294:\t\twas_dirty = (hip-\u003eextent_state \u0026 HFSPLUS_EXT_DIRTY);\n 295:\t\tres = hfsplus_ext_read_extent(inode, ablock);\n 296:\t\tif (res) {\n 297:\t\t\tmutex_unlock(\u0026hip-\u003eextents_lock);\n 298:\t\t\treturn -EIO;\n 299:\t\t}\n 300:\t\t*max_blocks = hfsplus_ext_find_block(hip-\u003ecached_extents,\n 301:\t\t\t\t\t\t     ablock - hip-\u003ecached_start,\n 302:\t\t\t\t\t\t     dblock);\n 303:\t\tmutex_unlock(\u0026hip-\u003eextents_lock);\n 304:\t\n 305:\t\tif (was_dirty)\n 306:\t\t\tmark_inode_dirty(inode);\n 307:\t\n 308:\t\tif (!*max_blocks)\n 309:\t\t\treturn -EIO;\n 310:\t\n 311:\t\treturn 0;\n 312:\t}\n 313:\t\n 314:\t/* Get a block at iblock for inode, possibly allocating if create */\n 315:\tint hfsplus_get_block(struct inode *inode, sector_t iblock,\n 316:\t\t\t      struct buffer_head *bh_result, int create)\n 317:\t{\n 318:\t\tstruct super_block *sb = inode-\u003ei_sb;\n 319:\t\tstruct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);\n"
}

19/3 2026/09/15 01:33 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 24432
							output: 34
							thoughts: 1689
						

Thoughts:
**Analyzing the Data Block Mapping Logic**

Okay, let's break this down systematically. I'm focusing on the interaction between extent mapping and dirty inode handling within this HFS+ implementation.

First, I noticed the `was_dirty` variable, and its use around line 305. The code initializes `was_dirty` at line 294:

```c
was_dirty = (hip->extent_state & HFSPLUS_EXT_DIRTY);
```

Then uses it later. My concern was, are there any paths to this that don't initialize `was_dirty`? Looking at the code for early returns shows that in all the paths, line 294 is reached. So `was_dirty` will have been assigned.

Next, I'm checking the values of `dblock` and `max_blocks`. The code calls `hfsplus_map_extent`, which initializes these variables:

```c
err = hfsplus_map_extent(inode, ablock, may_alloc, &dblock, &max_blocks, NULL);
if (err)
	return err;
```

I'm thinking, does `hfsplus_map_extent` *always* initialize both when returning 0?

I look into `hfsplus_map_extent` function and see how it works. I see it has two main paths to return 0. In both paths, `hfsplus_ext_find_block` is called. Let's look at `hfsplus_ext_find_block` to make sure!
```c
static u32 hfsplus_ext_find_block(struct hfsplus_extent *ext, u32 off,
				 u32 *dblock)
{
	int i;
	u32 count;

	for (i = 0; i < HFSPLUS_FORK_EXTENT_COUNT; ext++, i++) {
		count = be32_to_cpu(ext->block_count);
		if (off < count) {
			*dblock = be32_to_cpu(ext->start_block) + off;
			return count - off;
		}
		off -= count;
	}
	/* panic? */
	*dblock = 0;
	return 0;
}
```

Okay, the `dblock` is assigned to a value, and it returns a block count if it succeeds. So if `hfsplus_map_extent` returns 0, then `dblock` is set and `max_blocks > 0`. I check this again for both paths in `hfsplus_map_extent`.

I want to see how `hfsplus_get_block` is called. It also passes `dblock` to `hfsplus_map_extent`. So the same logic applies here too.

Finally I check `__hfsplus_iomap_begin`, and the `struct iomap` passed. I want to know, is `dblock` used and properly assigned. It seems to be, in the case of `IOMAP_MAPPED` type.

The overall concern is to make sure that these variables are always properly initialized, and assigned a value before use. It looks like it is, so far.



20/3 2026/09/15 01:33 tool grepper
0m Args:
{
  "Expression": "struct iomap \\{",
  "PathPrefix": "include/linux/iomap.h"
}

Results:
{
  "Output": "include/linux/iomap.h=26=struct vm_fault;\n--\ninclude/linux/iomap.h-129-\ninclude/linux/iomap.h:130:struct iomap {\ninclude/linux/iomap.h-131-\tu64\t\t\taddr; /* disk offset of mapping, bytes */\n"
}

21/3 2026/09/15 01:33 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 26981
							output: 37
							thoughts: 22
						

Thoughts:
Here's my summary, as if I were thinking these thoughts:

**Diving into the iomap Header**

Okay, time to dig into the `include/linux/iomap.h` file. I'm specifically interested in line 130 and the surrounding code. My initial thought is probably about the low-level I/O mapping functionality. I bet there's some crucial data structures or function prototypes related to how the kernel handles direct I/O and buffered I/O, how they interact, or how file data is mapped into the page cache for fast access. It's likely that section touches upon the intricacies of dealing with different block sizes, caching strategies, or maybe even direct access to hardware resources. Let's see what gems are waiting to be uncovered!



22/3 2026/09/15 01:33 tool read-file
0m Args:
{
  "File": "include/linux/iomap.h",
  "FirstLine": 129,
  "LineCount": 40
}

Results:
{
  "Contents": " 129:\t\n 130:\tstruct iomap {\n 131:\t\tu64\t\t\taddr; /* disk offset of mapping, bytes */\n 132:\t\tloff_t\t\t\toffset;\t/* file offset of mapping, bytes */\n 133:\t\tu64\t\t\tlength;\t/* length of mapping, bytes */\n 134:\t\tu16\t\t\ttype;\t/* type of mapping */\n 135:\t\tu16\t\t\tflags;\t/* flags for mapping */\n 136:\t\tstruct block_device\t*bdev;\t/* block device for I/O */\n 137:\t\tstruct dax_device\t*dax_dev; /* dax_dev for dax operations */\n 138:\t\tvoid\t\t\t*inline_data;\n 139:\t\tvoid\t\t\t*private; /* filesystem private */\n 140:\t\tu64\t\t\tvalidity_cookie; /* used with .iomap_valid() */\n 141:\t};\n 142:\t\n 143:\tstatic inline sector_t iomap_sector(const struct iomap *iomap, loff_t pos)\n 144:\t{\n 145:\t\tif (iomap-\u003eflags \u0026 IOMAP_F_ANON_WRITE)\n 146:\t\t\treturn U64_MAX; /* invalid */\n 147:\t\treturn (iomap-\u003eaddr + pos - iomap-\u003eoffset) \u003e\u003e SECTOR_SHIFT;\n 148:\t}\n 149:\t\n 150:\t/*\n 151:\t * Returns the inline data pointer for logical offset @pos.\n 152:\t */\n 153:\tstatic inline void *iomap_inline_data(const struct iomap *iomap, loff_t pos)\n 154:\t{\n 155:\t\treturn iomap-\u003einline_data + pos - iomap-\u003eoffset;\n 156:\t}\n 157:\t\n 158:\t/*\n 159:\t * When get_folio succeeds, put_folio will always be called to do any\n 160:\t * cleanup work necessary.  put_folio is responsible for unlocking and putting\n 161:\t * @folio.\n 162:\t */\n 163:\tstruct iomap_write_ops {\n 164:\t\tstruct folio *(*get_folio)(struct iomap_iter *iter, loff_t pos,\n 165:\t\t\t\tunsigned len);\n 166:\t\tvoid (*put_folio)(struct inode *inode, loff_t pos, unsigned copied,\n 167:\t\t\t\tstruct folio *folio);\n 168:\t\n"
}

23/3 2026/09/15 01:33 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 27887
							output: 30
							thoughts: 57
						

Thoughts:
**Investigating the iomap Allocation**

Okay, so I'm trying to trace the lifecycle of a `struct iomap` before its `.iomap_begin` method is called. That's the crucial point where the I/O mapping begins, and understanding how the `iomap` structure is set up before that is key to, well, everything. Where is this memory allocated and initialized? Hmm, let's start by looking at `iomap_iter` as that seems like a likely candidate to be responsible. Then, I'll need to look at how we get to `iomap_begin`. I'll do a quick grep through the `fs/iomap/` directory for any calls to `ops->iomap_begin`. That should highlight the code paths that are involved. With that, I should be able to track the `struct iomap` from its conception.



24/3 2026/09/15 01:33 tool grepper
0m Args:
{
  "Expression": "iomap_begin",
  "PathPrefix": "fs/iomap"
}

Results:
{
  "Output": "fs/iomap/buffered-io.c=1419=static void iomap_write_delalloc_scan(struct inode *inode,\n--\nfs/iomap/buffered-io.c-1446- * When a short write occurs, the filesystem might need to use -\u003eiomap_end\nfs/iomap/buffered-io.c:1447: * to remove space reservations created in -\u003eiomap_begin.\nfs/iomap/buffered-io.c-1448- *\n--\nfs/iomap/iter.c=115=int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops)\n--\nfs/iomap/iter.c-124-\t\tret = iomap_iter_next(iter, \u0026iter-\u003eiomap, \u0026iter-\u003esrcmap,\nfs/iomap/iter.c:125:\t\t\t\tops-\u003eiomap_begin, ops-\u003eiomap_end);\nfs/iomap/iter.c-126-\n"
}

25/3 2026/09/15 01:33 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 28441
							output: 36
							thoughts: 25
						

Thoughts:
Here's my take on the thought process, as requested:

**Diving into `iomap_iter_next`**

Okay, time to dig into this. I need to get a clear picture of how `fs/iomap/iter.c` handles the next iteration. Specifically, I want to refresh my memory on the workings around the `iomap_iter_next` function. I know this is a core piece, and understanding its logic is crucial for whatever I'm troubleshooting or analyzing right now. Let's see what the code's doing there and how it affects the flow of data. I want to see how the iterator progresses and what state it maintains to continue properly through an I/O operation.



26/3 2026/09/15 01:33 tool read-file
0m Args:
{
  "File": "fs/iomap/iter.c",
  "FirstLine": 15,
  "LineCount": 40
}

Results:
{
  "Contents": "  15:\t{\n  16:\t\tif (!iter-\u003efbatch)\n  17:\t\t\treturn;\n  18:\t\tiomap-\u003eflags \u0026= ~IOMAP_F_FOLIO_BATCH;\n  19:\t\tif (folio_batch_count(iter-\u003efbatch)) {\n  20:\t\t\tfolio_batch_release(iter-\u003efbatch);\n  21:\t\t\tfolio_batch_reinit(iter-\u003efbatch);\n  22:\t\t}\n  23:\t}\n  24:\t\n  25:\t/* Advance the current iterator position and decrement the remaining length */\n  26:\tint iomap_iter_advance(struct iomap_iter *iter, u64 count)\n  27:\t{\n  28:\t\tif (WARN_ON_ONCE(count \u003e iomap_length(iter)))\n  29:\t\t\treturn -EIO;\n  30:\t\titer-\u003epos += count;\n  31:\t\titer-\u003elen -= count;\n  32:\t\treturn 0;\n  33:\t}\n  34:\t\n  35:\tstatic inline void iomap_iter_done(struct iomap_iter *iter)\n  36:\t{\n  37:\t\tWARN_ON_ONCE(iter-\u003eiomap.offset \u003e iter-\u003epos);\n  38:\t\tWARN_ON_ONCE(iter-\u003eiomap.length == 0);\n  39:\t\tWARN_ON_ONCE(iter-\u003eiomap.offset + iter-\u003eiomap.length \u003c= iter-\u003epos);\n  40:\t\tWARN_ON_ONCE(iter-\u003eiomap.flags \u0026 IOMAP_F_STALE);\n  41:\t\n  42:\t\titer-\u003eiter_start_pos = iter-\u003epos;\n  43:\t\n  44:\t\ttrace_iomap_iter_dstmap(iter-\u003einode, \u0026iter-\u003eiomap);\n  45:\t\tif (iter-\u003esrcmap.type != IOMAP_HOLE)\n  46:\t\t\ttrace_iomap_iter_srcmap(iter-\u003einode, \u0026iter-\u003esrcmap);\n  47:\t}\n  48:\t\n  49:\t/**\n  50:\t * iomap_iter_continue - decide whether iteration should continue\n  51:\t * @iter: iteration structure\n  52:\t * @iomap: the mapping that was just processed\n  53:\t * @srcmap: the source mapping that was just processed\n  54:\t *\n"
}

27/3 2026/09/15 01:33 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 29281
							output: 36
							thoughts: 24
						

Thoughts:
Here's my summary, as if I were the one thinking these thoughts, targeting an expert audience:

**Diving into `fs/iomap/iter.c`**

Okay, I need to understand how this I/O mapping iteration works, so let's zero in on lines 55 through 100 of `fs/iomap/iter.c`. This section should reveal the core loop, the fundamental logic of how we traverse and process the I/O map entries. I'm expecting to see the handling of the various `iomap` flags, the `mapping` structures, and how they relate to the underlying block devices and their extents. I'm also curious about the error handling within this loop, especially how it deals with partial mappings or unexpected inconsistencies. I hope it clarifies how the iterator interacts with the `iomap_ops` to perform the actual I/O operations - is it a direct call, or is there an indirection here? I'm anticipating some intricate pointer manipulation, and hoping that it is logically organized to be digestible. Let's see if this code answers these questions.



28/3 2026/09/15 01:33 tool read-file
0m Args:
{
  "File": "fs/iomap/iter.c",
  "FirstLine": 55,
  "LineCount": 45
}

Results:
{
  "Contents": "  55:\t * Helper normally called via iomap_iter_next(). Called after the previous\n  56:\t * mapping has been finished to determine whether there is more of the file\n  57:\t * range left to process.\n  58:\t *\n  59:\t * Returns 1 if there is more work to do, in which case @iomap and @srcmap are\n  60:\t * cleared so the caller can produce the next mapping; zero if the range is\n  61:\t * fully consumed; or a negative errno on error.\n  62:\t */\n  63:\tint iomap_iter_continue(const struct iomap_iter *iter, struct iomap *iomap,\n  64:\t\t\tstruct iomap *srcmap, int ret)\n  65:\t{\n  66:\t\tconst bool stale = iomap-\u003eflags \u0026 IOMAP_F_STALE;\n  67:\t\tconst ssize_t advanced = iter-\u003epos - iter-\u003eiter_start_pos;\n  68:\t\n  69:\t\tif (ret \u003c 0 \u0026\u0026 !advanced)\n  70:\t\t\treturn ret;\n  71:\t\n  72:\t\t/*\n  73:\t\t * Use iter-\u003elen to determine whether to continue onto the next mapping.\n  74:\t\t * Explicitly terminate on error status or if the current iter has not\n  75:\t\t * advanced at all (i.e. no work was done for some reason) unless the\n  76:\t\t * mapping has been marked stale and needs to be reprocessed.\n  77:\t\t */\n  78:\t\tif (WARN_ON_ONCE(iter-\u003estatus \u003e 0))\n  79:\t\t\t/* detect old return semantics where this would advance */\n  80:\t\t\tret = -EIO;\n  81:\t\telse if (iter-\u003estatus \u003c 0)\n  82:\t\t\tret = iter-\u003estatus;\n  83:\t\telse if (iter-\u003elen == 0 || (!advanced \u0026\u0026 !stale))\n  84:\t\t\tret = 0;\n  85:\t\telse\n  86:\t\t\tret = 1;\n  87:\t\n  88:\t\tiomap_iter_clean_fbatch(iter, iomap);\n  89:\t\n  90:\t\tif (ret \u003c= 0)\n  91:\t\t\treturn ret;\n  92:\t\n  93:\t\tmemset(iomap, 0, sizeof(*iomap));\n  94:\t\tmemset(srcmap, 0, sizeof(*srcmap));\n  95:\t\n  96:\t\treturn ret;\n  97:\t}\n  98:\tEXPORT_SYMBOL_GPL(iomap_iter_continue);\n  99:\t\n"
}

29/3 2026/09/15 01:33 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 30257
							output: 32
							thoughts: 1754
						

Thoughts:
**Uninitialized Memory Analysis in HFS+ iomap Implementation**

Okay, let's break this down systematically. I'm focusing on potential uninitialized memory reads in the HFS+ iomap implementation, particularly concerning the `iomap_writepage_ctx` and its interaction with the iomap core.

My initial observation is about zero-initialization. I noticed that `memset` is used to initialize the `iomap` structures in several places, like `iomap_iter_continue` and in the initialization of the iterator itself. This seems deliberate.  I checked how `hfsplus_writepage_ctx` is created and found that the relevant context, `wpc`, is initialized using a designated initializer: `struct iomap_writepage_ctx wpc = { .inode = ..., ... };` C designated initializers ensure that unspecified members are zeroed. So, `wpc.iomap` starts with all fields set to zero. This is standard C behavior (C99 and C11 standards). This means we're safe initially.

However, `__hfsplus_iomap_begin` is used in a writeback context. I examined the `hfsplus_writeback_range` function and the way it calls `__hfsplus_iomap_begin`, and the potential reuse of `wpc->iomap`. If `offset` falls outside the current extent, `__hfsplus_iomap_begin` is called which conditionally sets `iomap->type = IOMAP_HOLE` if we're beyond the end of file (EOF). Although this might override values from the previously initialized structure, I confirmed that `wpc` itself is zero-initialized and thus no "uninitialized" memory is passed around.

I considered what happens if the code encounters a hole during writeback. I thought about the flags in `iomap` in this scenario, as I recognized that they could potentially retain previous values if not explicitly set. However, the stack allocation combined with the usage of designated initializers still keeps the structure zeroed.

I then went through my usual checklist for uninitialized memory risks.  I evaluated whether the patch exposes any of the common risks (kernel structures to userspace, conditional logic using uninitialized variables, complex data structure initialization, and bounds checks that could lead to reads of uninitialized memory). The zero-initialization in the contexts where I'm examining this code eliminates these risks.

My next line of investigation took me to disk I/O. I was considering if iomap could inadvertently read uninitialized data from the disk. This prompted me to re-examine the `hfsplus_file_truncate` and `hfsplus_iomap_cont_expand` code where zeroing the extent with `iomap_zero_range` is performed. This is crucial for handling truncation and file extension as it makes sure to prevent potential information leakage in these cases.

My last thought was that `hfsplus_map_extent` might allocate new blocks and expose uninitialized memory. I noted that `hfsplus_map_extent` calls `hfsplus_file_extend`. I focused on the `balloc` flag that is passed as `NULL` in the call to  `hfsplus_map_extent` but isn't used after that.
I then checked the use of the `IOMAP_F_NEW` flag. The `is_new` flag, set when new blocks are allocated, sets the `IOMAP_F_NEW` flag in the iomap. The code explicitly checks this flag in `hfsplus_write_iomap_end`, rounding the end extent to a block boundary, and expanding the file, so it is handled correctly. I noted that the code appears to handle this correctly as the size is always expanded to the end. I will check the usage of  `IOMAP_F_NEW` in the iomap core to be sure.

In summary, based on this analysis, I don't see any obvious uninitialized memory risks. The initial zero-initialization of key structures, coupled with the explicit zeroing in critical path, and the handling of new block allocations, seem robust enough to prevent the exposure of uninitialized data to userspace or other parts of the kernel.



30/3 2026/09/15 01:33 tool grepper
0m Args:
{
  "Expression": "IOMAP_F_NEW",
  "PathPrefix": "fs/iomap"
}

Results:
{
  "Output": "fs/iomap/buffered-io.c=382=static inline bool iomap_block_needs_zeroing(const struct iomap_iter *iter,\n--\nfs/iomap/buffered-io.c-395-\t */\nfs/iomap/buffered-io.c:396:\tif (srcmap-\u003eflags \u0026 IOMAP_F_NEW)\nfs/iomap/buffered-io.c-397-\t\treturn true;\n--\nfs/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-478-\nfs/iomap/direct-io.c:479:\t\tif (iomap-\u003eflags \u0026 IOMAP_F_NEW) {\nfs/iomap/direct-io.c-480-\t\t\t/*\n--\nfs/iomap/trace.h=87=DEFINE_RANGE_EVENT(iomap_zero_iter);\n--\nfs/iomap/trace.h-109-#define IOMAP_F_FLAGS_STRINGS \\\nfs/iomap/trace.h:110:\t{ IOMAP_F_NEW,\t\t\"NEW\" }, \\\nfs/iomap/trace.h-111-\t{ IOMAP_F_DIRTY,\t\"DIRTY\" }, \\\n"
}

31/3 2026/09/15 01:33 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 33341
							output: 39
							thoughts: 141
						

Thoughts:
**Analyzing the Zeroing Logic in IOMAP Direct I/O**

Okay, so I'm diving into the `iomap` code again, specifically looking at how zeroing is handled. I remember `iomap_block_needs_zeroing` is the key, and it checks `srcmap->flags & IOMAP_F_NEW`.  Right, that makes sense. It means the block is new, so it needs to be zeroed before use.

But hang on, let me quickly refresh my memory of `iomap_iter_init`. Ah, yes, if `srcmap` isn't explicitly set, it defaults to the `iomap` itself. So, in many cases, this check is effectively done against the `iomap` structure directly. I need to keep that in mind.

Now, let's go deeper and verify the logic. I should check `iomap_dio_bio_iter` to see where this flag gets set and used in the context of direct I/O. I'm going to jump straight to line 479. Yes, there it is! 

```c
		if (iomap->flags & IOMAP_F_NEW) {
			/* ... */
		}
```

Okay, the code is checking the same flag there as I thought. Now I want to get the bigger picture. I should check the direct I/O file directly to see how this flag is set. Okay, let's open `fs/iomap/direct-io.c` and go to lines 475 to 500. This should give me some context on how this flag is set. It seems this code snippet is part of the logic that handles a direct I/O operation.



32/3 2026/09/15 01:33 tool read-file
0m Args:
{
  "File": "fs/iomap/direct-io.c",
  "FirstLine": 475,
  "LineCount": 30
}

Results:
{
  "Contents": " 475:\t\t\t\tneed_completion_work = true;\n 476:\t\t\t\tdio-\u003eflags |= IOMAP_DIO_COW;\n 477:\t\t\t}\n 478:\t\n 479:\t\t\tif (iomap-\u003eflags \u0026 IOMAP_F_NEW) {\n 480:\t\t\t\t/*\n 481:\t\t\t\t * Newly allocated blocks might need recording in\n 482:\t\t\t\t * metadata at I/O completion time.\n 483:\t\t\t\t */\n 484:\t\t\t\tneed_completion_work = true;\n 485:\t\t\t\tneed_zeroout = true;\n 486:\t\t\t}\n 487:\t\n 488:\t\t\t/*\n 489:\t\t\t * Use a FUA write if we need datasync semantics and this is a\n 490:\t\t\t * pure overwrite that doesn't require any metadata updates.\n 491:\t\t\t *\n 492:\t\t\t * This allows us to avoid cache flushes on I/O completion.\n 493:\t\t\t */\n 494:\t\t\tif (dio-\u003eflags \u0026 IOMAP_DIO_WRITE_THROUGH) {\n 495:\t\t\t\tif (!need_completion_work \u0026\u0026\n 496:\t\t\t\t    !(iomap-\u003eflags \u0026 IOMAP_F_DIRTY) \u0026\u0026\n 497:\t\t\t\t    (!bdev_write_cache(iomap-\u003ebdev) ||\n 498:\t\t\t\t     bdev_fua(iomap-\u003ebdev)))\n 499:\t\t\t\t\tbio_opf |= REQ_FUA;\n 500:\t\t\t\telse\n 501:\t\t\t\t\tdio-\u003eflags \u0026= ~IOMAP_DIO_WRITE_THROUGH;\n 502:\t\t\t}\n 503:\t\n 504:\t\t\t/*\n"
}

33/3 2026/09/15 01:33 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 34353
							output: 34
							thoughts: 553
						

Thoughts:
**My Thoughts on Direct I/O and HFS+ Reading**

Okay, let's break this down. First, I'm looking at `iomap_dio_end_io`. This is the direct I/O completion handler. If there's no error, and the size of the read is valid and extends the file size, I update the inode size and mark it dirty. Standard stuff for direct I/O completion.

Now, I'm jumping into `file.c` to look at `hfsplus_file_read_iter`. This function handles reads for the HFS+ filesystem. I see that if `IOCB_DIRECT` is set (direct I/O), it calls `iomap_dio_rw` with `hfsplus_iomap_ops`. Otherwise, it uses `generic_file_read_iter`. So, the direct I/O path is being routed through `iomap`, which is good. We are hitting iomap for the DIO path.

Wait a second, what about the buffered reads? I see `hfsplus_read_folio` and `hfsplus_readahead`. It appears they're using `iomap_bio_read_folio` and `iomap_bio_readahead`, respectively, also with `hfsplus_iomap_ops`. So, both direct I/O and buffered I/O are leveraging the `iomap` infrastructure. This is what I expect to see.

Now, a critical question arises: What about holes? When `iomap_bio_read_folio` encounters a hole, which is entirely possible in HFS+ files, how is that handled? I need to check the internals of `iomap_read_folio_iter` to see how it deals with holes. I need to understand what's happening at that level to ensure data integrity and avoid unexpected behavior.



34/3 2026/09/15 01:33 tool grepper
0m Args:
{
  "Expression": "iomap_bio_read_folio",
  "PathPrefix": "fs/iomap"
}

Results:
{
  "Output": "fs/iomap/bio.c=108=static void iomap_read_alloc_bio(const struct iomap_iter *iter,\n--\nfs/iomap/bio.c-145-\nfs/iomap/bio.c:146:int iomap_bio_read_folio_range(const struct iomap_iter *iter,\nfs/iomap/bio.c-147-\t\tstruct iomap_read_folio_ctx *ctx, size_t plen)\n--\nfs/iomap/bio.c-158-}\nfs/iomap/bio.c:159:EXPORT_SYMBOL_GPL(iomap_bio_read_folio_range);\nfs/iomap/bio.c-160-\nfs/iomap/bio.c=161=const struct iomap_read_ops iomap_bio_read_ops = {\nfs/iomap/bio.c:162:\t.read_folio_range\t= iomap_bio_read_folio_range,\nfs/iomap/bio.c-163-\t.submit_read\t\t= iomap_bio_submit_read,\n--\nfs/iomap/bio.c=165=EXPORT_SYMBOL_GPL(iomap_bio_read_ops);\nfs/iomap/bio.c-166-\nfs/iomap/bio.c:167:int iomap_bio_read_folio_range_sync(const struct iomap_iter *iter,\nfs/iomap/bio.c-168-\t\tstruct folio *folio, loff_t pos, size_t len)\n--\nfs/iomap/buffered-io.c=875=static int __iomap_write_begin(const struct iomap_iter *iter,\n--\nfs/iomap/buffered-io.c-934-\t\t\telse\nfs/iomap/buffered-io.c:935:\t\t\t\tstatus = iomap_bio_read_folio_range_sync(iter,\nfs/iomap/buffered-io.c-936-\t\t\t\t\t\tfolio, block_start, plen);\n--\nfs/iomap/internal.h=21=u32 iomap_finish_ioend_direct(struct iomap_ioend *ioend);\n--\nfs/iomap/internal.h-23-#ifdef CONFIG_BLOCK\nfs/iomap/internal.h:24:int iomap_bio_read_folio_range_sync(const struct iomap_iter *iter,\nfs/iomap/internal.h-25-\t\tstruct folio *folio, loff_t pos, size_t len);\nfs/iomap/internal.h-26-#else\nfs/iomap/internal.h:27:static inline int iomap_bio_read_folio_range_sync(const struct iomap_iter *iter,\nfs/iomap/internal.h-28-\t\tstruct folio *folio, loff_t pos, size_t len)\n"
}

35/3 2026/09/15 01:33 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 36119
							output: 39
							thoughts: 19
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Tracing `iomap_bio_read_folio`**

Alright, let's dive into this. I need to understand where `iomap_bio_read_folio` is defined. This likely means I'm trying to trace its implementation and understand its role within the larger I/O context. This could be for debugging, performance analysis, or perhaps even for modifying its behavior or integrating it with a different file system. The name suggests it deals with reading data through the `bio` structure and interacts with folios, so it's probably deeply involved in the page cache and direct I/O path. Time to jump into the code and see what we're working with.



36/3 2026/09/15 01:33 tool grepper
0m Args:
{
  "Expression": "iomap_bio_read_folio\\(",
  "PathPrefix": "include/linux/iomap.h"
}

Results:
{
  "Output": "include/linux/iomap.h=789=extern const struct iomap_read_ops iomap_bio_read_ops;\ninclude/linux/iomap.h-790-\ninclude/linux/iomap.h:791:static inline void iomap_bio_read_folio(struct folio *folio,\ninclude/linux/iomap.h-792-\t\tconst struct iomap_ops *ops)\n"
}

37/3 2026/09/15 01:33 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 36461
							output: 37
							thoughts: 25
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Diving into the iomap.h details**

Okay, time to get my hands dirty and delve into the specifics of I/O mapping. My immediate focus is on `include/linux/iomap.h`, and specifically, lines 790 through 820. I'm guessing that area will probably illuminate something about a particular data structure or a specific function dealing with I/O mapping that I'm currently working with, considering the broader context of my current project. I'm keen to dissect the definitions and how they interact with related components of the VFS or block layer. I need to understand the exact mechanics behind some implementation I'm reviewing. Let's see what's in store.



38/3 2026/09/15 01:33 tool read-file
0m Args:
{
  "File": "include/linux/iomap.h",
  "FirstLine": 790,
  "LineCount": 30
}

Results:
{
  "Contents": " 790:\t\n 791:\tstatic inline void iomap_bio_read_folio(struct folio *folio,\n 792:\t\t\tconst struct iomap_ops *ops)\n 793:\t{\n 794:\t\tstruct iomap_read_folio_ctx ctx = {\n 795:\t\t\t.ops\t\t= \u0026iomap_bio_read_ops,\n 796:\t\t\t.cur_folio\t= folio,\n 797:\t\t};\n 798:\t\n 799:\t\tiomap_read_folio(ops, \u0026ctx, NULL);\n 800:\t}\n 801:\t\n 802:\tstatic inline void iomap_bio_readahead(struct readahead_control *rac,\n 803:\t\t\tconst struct iomap_ops *ops)\n 804:\t{\n 805:\t\tstruct iomap_read_folio_ctx ctx = {\n 806:\t\t\t.ops\t\t= \u0026iomap_bio_read_ops,\n 807:\t\t\t.rac\t\t= rac,\n 808:\t\t};\n 809:\t\n 810:\t\tiomap_readahead(ops, \u0026ctx, NULL);\n 811:\t}\n 812:\t#endif /* CONFIG_BLOCK */\n 813:\t\n 814:\t#endif /* LINUX_IOMAP_H */\n"
}

39/3 2026/09/15 01:33 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 37065
							output: 33
							thoughts: 29
						

Thoughts:
Okay, let's dive into this. I'm going to take a look at the `iomap_read_folio` function, specifically within `fs/iomap/buffered-io.c`. I need to understand exactly how the I/O mapping layer handles read operations for buffered I/O, particularly how it works on the folio level. I'm expecting to see the core logic for translating a logical offset and length into physical extents, handling potential I/O errors, and managing page faulting if necessary. I'll be looking for things like how it interacts with the underlying block device, and if it implements any read-ahead or caching strategies, and how it handles different scenarios like partial block reads or reads across extent boundaries. I'll need to pay close attention to the error handling within the function. I would be looking for any hints on how it's optimized for performance and how it integrates into the rest of the I/O stack. The goal is to fully grasp its role in enabling efficient, consistent, and safe buffered I/O.



40/3 2026/09/15 01:33 tool grepper
0m Args:
{
  "Expression": "iomap_read_folio\\(",
  "PathPrefix": "fs/iomap"
}

Results:
{
  "Output": "fs/iomap/buffered-io.c=557=static int iomap_read_folio_iter(struct iomap_iter *iter,\n--\nfs/iomap/buffered-io.c-650-\nfs/iomap/buffered-io.c:651:void iomap_read_folio(const struct iomap_ops *ops,\nfs/iomap/buffered-io.c-652-\t\tstruct iomap_read_folio_ctx *ctx, void *private)\n"
}

41/3 2026/09/15 01:33 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 37490
							output: 39
							thoughts: 36
						

Thoughts:
Here's my take on the thought process, as requested:

**Diving into Buffered I/O**

Alright, let's get down to brass tacks. I need to understand the buffered I/O implementation in the kernel, specifically how it handles reads. To do that, the `iomap_read_folio_iter` function within `fs/iomap/buffered-io.c` is the logical place to start. I'm going to jump straight to around line 557. That's usually a good spot to begin looking at the core read iteration logic. I need to refresh my understanding of how IOMAP interacts with folios during buffered reads. Hopefully, that location will provide the high-level flow, or a starting point for more detailed investigation.



42/3 2026/09/15 01:33 tool read-file
0m Args:
{
  "File": "fs/iomap/buffered-io.c",
  "FirstLine": 557,
  "LineCount": 40
}

Results:
{
  "Contents": " 557:\tstatic int iomap_read_folio_iter(struct iomap_iter *iter,\n 558:\t\t\tstruct iomap_read_folio_ctx *ctx, size_t *bytes_submitted)\n 559:\t{\n 560:\t\tconst struct iomap *iomap = \u0026iter-\u003eiomap;\n 561:\t\tloff_t pos = iter-\u003epos;\n 562:\t\tloff_t length = iomap_length(iter);\n 563:\t\tstruct folio *folio = ctx-\u003ecur_folio;\n 564:\t\tsize_t folio_len = folio_size(folio);\n 565:\t\tstruct iomap_folio_state *ifs;\n 566:\t\tsize_t poff, plen;\n 567:\t\tloff_t pos_diff;\n 568:\t\tint ret;\n 569:\t\n 570:\t\tif (iomap-\u003etype == IOMAP_INLINE) {\n 571:\t\t\tret = iomap_read_inline_data(iter, folio);\n 572:\t\t\tif (ret)\n 573:\t\t\t\treturn ret;\n 574:\t\t\treturn iomap_iter_advance(iter, length);\n 575:\t\t}\n 576:\t\n 577:\t\tifs = ifs_alloc(iter-\u003einode, folio, iter-\u003eflags);\n 578:\t\n 579:\t\tlength = min_t(loff_t, length, folio_len - offset_in_folio(folio, pos));\n 580:\t\twhile (length) {\n 581:\t\t\tiomap_adjust_read_range(iter-\u003einode, folio, \u0026pos, length, \u0026poff,\n 582:\t\t\t\t\t\u0026plen);\n 583:\t\n 584:\t\t\tpos_diff = pos - iter-\u003epos;\n 585:\t\t\tif (WARN_ON_ONCE(pos_diff + plen \u003e length))\n 586:\t\t\t\treturn -EIO;\n 587:\t\n 588:\t\t\tret = iomap_iter_advance(iter, pos_diff);\n 589:\t\t\tif (ret)\n 590:\t\t\t\treturn ret;\n 591:\t\n 592:\t\t\tif (plen == 0)\n 593:\t\t\t\treturn 0;\n 594:\t\n 595:\t\t\t/*\n 596:\t\t\t * Handling of fsverity \"holes\". We hit this for two case:\n"
}

43/3 2026/09/15 01:33 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 38373
							output: 39
							thoughts: 18
						

Thoughts:
Okay, here's my attempt at summarizing the thought process, as if it were my own, assuming I'm an expert in the field and have just encountered a request to summarize the rest of `iomap_read_folio_iter`:

**Diving Back into `iomap_read_folio_iter`**

Alright, so the task is to summarize the remainder of the `iomap_read_folio_iter` function. I've probably already got a decent grasp of the overall purpose, likely dealing with iterating through folios for a read operation within the iomap framework. Now, let's see what the *rest* of it's doing. What are the key internal steps that contribute to a read operation? I'm anticipating some logic around handling error conditions, possibly some optimizations for contiguous reads, and of course, the actual data transfer from the storage medium.

I'll be looking for things like:

*   **Error Handling:** Are there checks for read errors, and if so, how are they handled? Is there any retry logic?
*   **Folio Iteration Mechanics:** How is the iteration controlled? Is it based on a precomputed list of folios, or is it dynamically computed based on the requested read size and file layout?
*   **Data Transfer:** What's the actual mechanism for the data transfer itself? Is it using direct I/O, buffered I/O, or a combination? Are there any data copying operations?
*   **Performance Considerations:** Are there any obvious optimizations, such as read-ahead, merging reads, or handling of aligned reads?
*   **Synchronization:** How are the reads synchronized in this function, in a multi-threaded or concurrent context? Are there any locking or atomic operations?
*   **Completion Handling:** How is the read operation signaled as complete? Are there any completion callbacks or other mechanisms involved?

I'll keep a sharp eye out for any unusual or clever tricks used to achieve high performance and efficient memory usage. It's likely that a good portion of the remaining code will handle the edge cases and boundary conditions that are common in file system read operations. Knowing this function is crucial for high performance IO; so, I'll pay close attention to any details around memory alignment or data copy strategies, since it's common for inefficiencies to sneak in. Let's see what gems are buried in the rest of this code.



44/3 2026/09/15 01:33 tool read-file
0m Args:
{
  "File": "fs/iomap/buffered-io.c",
  "FirstLine": 597,
  "LineCount": 40
}

Results:
{
  "Contents": " 597:\t\t\t *   1. No need to go further, the hole after fsverity\n 598:\t\t\t *\tdescriptor is the end of the fsverity metadata.\n 599:\t\t\t *\n 600:\t\t\t *   2. This folio contains merkle tree blocks which need to be\n 601:\t\t\t *\tsynthesized. If we already have fsverity info (ctx-\u003evi)\n 602:\t\t\t *\tsynthesize these blocks.\n 603:\t\t\t */\n 604:\t\t\tif ((iomap-\u003eflags \u0026 IOMAP_F_FSVERITY) \u0026\u0026\n 605:\t\t\t    iomap-\u003etype == IOMAP_HOLE) {\n 606:\t\t\t\tif (ctx-\u003evi)\n 607:\t\t\t\t\tfsverity_fill_zerohash(folio, poff, plen,\n 608:\t\t\t\t\t\t\t       ctx-\u003evi);\n 609:\t\t\t\tiomap_set_range_uptodate(folio, poff, plen);\n 610:\t\t\t} else if (iomap_block_needs_zeroing(iter, pos)) {\n 611:\t\t\t\t/* zero post-eof blocks as the page may be mapped */\n 612:\t\t\t\tfolio_zero_range(folio, poff, plen);\n 613:\t\t\t\tif (ctx-\u003evi \u0026\u0026\n 614:\t\t\t\t    !fsverity_verify_blocks(ctx-\u003evi, folio, plen, poff))\n 615:\t\t\t\t\treturn -EIO;\n 616:\t\t\t\tiomap_set_range_uptodate(folio, poff, plen);\n 617:\t\t\t} else {\n 618:\t\t\t\tif (!*bytes_submitted)\n 619:\t\t\t\t\tiomap_read_init(folio);\n 620:\t\t\t\tret = ctx-\u003eops-\u003eread_folio_range(iter, ctx, plen);\n 621:\t\t\t\tif (ret \u003c 0)\n 622:\t\t\t\t\tfserror_report_io(iter-\u003einode,\n 623:\t\t\t\t\t\t\t  FSERR_BUFFERED_READ, pos,\n 624:\t\t\t\t\t\t\t  plen, ret, GFP_NOFS);\n 625:\t\t\t\tif (ret)\n 626:\t\t\t\t\treturn ret;\n 627:\t\n 628:\t\t\t\t*bytes_submitted += plen;\n 629:\t\t\t\t/*\n 630:\t\t\t\t * Hand off folio ownership to the IO helper when:\n 631:\t\t\t\t * 1) The entire folio has been submitted for IO, or\n 632:\t\t\t\t * 2) There is no ifs attached to the folio\n 633:\t\t\t\t *\n 634:\t\t\t\t * Case (2) occurs when 1 \u003c\u003c i_blkbits matches the folio\n 635:\t\t\t\t * size but the underlying filesystem or block device\n 636:\t\t\t\t * uses a smaller granularity for IO.\n"
}

45/3 2026/09/15 01:33 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 39646
							output: 39
							thoughts: 111
						

Thoughts:
**Analyzing Block Zeroing in I/O Operations**

Okay, so I'm looking at this bit of code, specifically `iomap_block_needs_zeroing`. Interesting, it appears to be handling the situation where we need to zero out some blocks, particularly those that come *after* the end of the file. The comment implies there's a reason for this, something to do with pages possibly being mapped. I'd like to understand the *why* of this, so let's dig into that `iomap_block_needs_zeroing` function itself. Where is that defined? Ah, line 382 of `fs/iomap/buffered-io.c`. Let's see what that function does and then we can get a handle on the rationale of the code.



46/3 2026/09/15 01:33 tool read-file
0m Args:
{
  "File": "fs/iomap/buffered-io.c",
  "FirstLine": 380,
  "LineCount": 25
}

Results:
{
  "Contents": " 380:\t}\n 381:\t\n 382:\tstatic inline bool iomap_block_needs_zeroing(const struct iomap_iter *iter,\n 383:\t\t\tloff_t pos)\n 384:\t{\n 385:\t\tconst struct iomap *srcmap = iomap_iter_srcmap(iter);\n 386:\t\n 387:\t\t/*\n 388:\t\t * If this block has not been written, there's nothing to read\n 389:\t\t */\n 390:\t\tif (srcmap-\u003etype != IOMAP_MAPPED)\n 391:\t\t\treturn true;\n 392:\t\n 393:\t\t/*\n 394:\t\t * Newly allocated blocks have not been written\n 395:\t\t */\n 396:\t\tif (srcmap-\u003eflags \u0026 IOMAP_F_NEW)\n 397:\t\t\treturn true;\n 398:\t\n 399:\t\t/*\n 400:\t\t * fsverity metadata is stored past i_size, we need to read it instead\n 401:\t\t * of zeroing\n 402:\t\t */\n 403:\t\tif (srcmap-\u003eflags \u0026 IOMAP_F_FSVERITY)\n 404:\t\t\treturn false;\n"
}

47/3 2026/09/15 01:33 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 40314
							output: 304
							thoughts: 8682
						

Thoughts:
**Analysis of HFS+ Filesystem Iomap Conversion Patch**

Okay, so I've gone through this patch with a fine-tooth comb. My initial concern was about that `was_dirty` variable in `hfsplus_map_extent`. It *looked* uninitialized at first, a classic KMSAN red flag. However, after tracing the execution paths, it's clear that the logic *always* sets `was_dirty` before it's used. The original code had a `goto done;` that bypassed the setting in one particular branch, but the patch removes this `goto` and instead uses `return;` causing that specific branch to initialize `was_dirty`. All other local variables, struct members, etc., are initialized before usage or are otherwise handled correctly.

The patch itself is a significant change: moving the HFS+ filesystem from the legacy buffer-head/direct_IO infrastructure to the `iomap` infrastructure. This involves modifying bitmap allocation, extent mapping, and file operations (read, write, seek, fsync).

Here's the breakdown of my analysis:

*   **Initialization and Zeroing:** All significant data structures and local variables are properly initialized *before* any reads or uses. There are no dangling pointers or uninitialized data being propagated or accessed. Any allocation or zeroing occurs at the appropriate places. The old code used `= 0;`, the new code doesn't require this because the code flow handles the logic better.
*   **Memory Safety:** The patch modifies how data is handled with page locking, I/O mapping, and extent information; however, it *correctly* utilizes functions like `iomap_zero_range`, `folio_zero_range`, and `iomap_truncate_page` to prevent reading/writing to unallocated or deallocated pages.
*   **Concurrency:** There are additional page locks, which handle concurrent access correctly. Concurrency and locking issues are detectable by KASAN and LOCKDEP in standard testing.
*   **Information Leakage:** No kernel structures or data are leaked to user space via copy operations, IOCTL/socket output, or anything else. There are no user-space arguments or structures that would leak kernel memory.
*   **No Uninitialized Memory Risk:** Based on this careful examination, there are *no* situations where uninitialized memory poses a risk.

In short, there are no uninitialized memory risks that would only be caught by KMSAN, as opposed to KASAN, LOCKDEP or other standard bug detectors. Given this detailed examination, there is no need to run KMSAN for this patch. I'm confident in setting `NeedsKMSAN=false`.



48/3 2026/09/15 01:34 tool set-results
0m Args:
{
  "KMSANReasoning": "The patch migrates the HFS+ filesystem from legacy buffer_head-based file operations and direct I/O to the modern iomap infrastructure (iomap read/write/seek/writeback/swap).\n\nKey aspects evaluated for uninitialized memory risks:\n1. No kernel structures are copied or leaked to user space via copy_to_user, put_user, netlink, or ioctl.\n2. Local variables in the new and modified functions (such as `was_dirty`, `dblock`, `max_blocks`, `did_zero`, and `wpc`) are fully initialized before any read or conditional branch.\n3. Unallocated or extended file ranges are zeroed out via `iomap_zero_range()` and `iomap_truncate_page()`, preventing reading of uninitialized page/disk contents.\n4. The iomap core structures (`struct iomap`, `struct iomap_writepage_ctx`) are zero-initialized prior to being populated by the filesystem callbacks.\n\nThe potential bugs introduced by this transition (such as locking issues, writeback races, or buffer out-of-bounds accesses) are covered by KASAN and LOCKDEP. There are no uninitialized memory access risks or info-leaks that would require a dedicated KMSAN fuzzing session.",
  "NeedsKMSAN": false
}

Results:
{
  "KMSANReasoning": "The patch migrates the HFS+ filesystem from legacy buffer_head-based file operations and direct I/O to the modern iomap infrastructure (iomap read/write/seek/writeback/swap).\n\nKey aspects evaluated for uninitialized memory risks:\n1. No kernel structures are copied or leaked to user space via copy_to_user, put_user, netlink, or ioctl.\n2. Local variables in the new and modified functions (such as `was_dirty`, `dblock`, `max_blocks`, `did_zero`, and `wpc`) are fully initialized before any read or conditional branch.\n3. Unallocated or extended file ranges are zeroed out via `iomap_zero_range()` and `iomap_truncate_page()`, preventing reading of uninitialized page/disk contents.\n4. The iomap core structures (`struct iomap`, `struct iomap_writepage_ctx`) are zero-initialized prior to being populated by the filesystem callbacks.\n\nThe potential bugs introduced by this transition (such as locking issues, writeback races, or buffer out-of-bounds accesses) are covered by KASAN and LOCKDEP. There are no uninitialized memory access risks or info-leaks that would require a dedicated KMSAN fuzzing session.",
  "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)