AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/09/05 04:02 flow patch-triage
0m Args:
null

Results:
{
  "EnableConfigs": [
    "XFS_FS"
  ],
  "FocusSymbols": [
    "iomap_dirty_folio_range",
    "iomap_page_mkwrite",
    "folio_mark_dirty_range",
    "folio_mkclean_dirtymap",
    "folio_clear_dirty_for_io"
  ],
  "KMSANReasoning": "The patch introduces range-based dirty tracking for large folios in the memory management subsystem and iomap (specifically `dirty_folio_range`, `folio_mark_dirty_range`, and `folio_mkclean_dirtymap`).\n\n1. KMSAN applicability: The changes do not introduce or modify any data structures exposed or copied to user space, nor do they introduce uninitialized stack or heap variables. All new local variables (`dirty_off`, `dirty_len`, `state`, and stack bitmap `map` in `folio_mkclean_for_io`) are properly initialized before use (`bitmap_zero`, designated initializer, etc.). There are no info-leak or uninitialized memory read vectors.\n2. KASAN / standard detectors applicability: Potential bugs arising from range calculations, bitmask operations, or page table walks would be out-of-bounds accesses, assertions/locking issues, or logic errors, which are covered by KASAN, LOCKDEP, and existing kernel debug checks.\n\nTherefore, a dedicated KMSAN session is not warranted.",
  "NeedsKMSAN": false,
  "Reasoning": "The patch series introduces sub-folio range dirtying via -\u003edirty_folio_range, folio_mark_dirty_range(), folio_mkclean_dirtymap(), and iomap_dirty_folio_range() for XFS/iomap. It modifies core MM dirty folio tracking, write-protect/clean transitions in writeback (folio_clear_dirty_for_io), rmap PTE/PMD dirty walk, and page fault handling for shared mappings. These reachable MM and filesystem paths warrant fuzzing.",
  "WorthFuzzing": true
}

1/1 2026/09/05 04:02 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit 0519b461c9b3fdecaa880e0c93b4da997751c1b2\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Sat Sep 5 04:02:38 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c\nindex 0a5ebfda90f12..8d8a8acab01ac 100644\n--- a/fs/iomap/buffered-io.c\n+++ b/fs/iomap/buffered-io.c\n@@ -847,15 +847,19 @@ void iomap_invalidate_folio(struct folio *folio, size_t offset, size_t len)\n }\n EXPORT_SYMBOL_GPL(iomap_invalidate_folio);\n \n-bool iomap_dirty_folio(struct address_space *mapping, struct folio *folio)\n+bool iomap_dirty_folio_range(struct address_space *mapping, struct folio *folio,\n+\t\tsize_t off, size_t len)\n {\n-\tstruct inode *inode = mapping-\u003ehost;\n-\tsize_t len = folio_size(folio);\n-\n-\tifs_alloc(inode, folio, 0);\n-\tiomap_set_range_dirty(folio, 0, len);\n+\tifs_alloc(mapping-\u003ehost, folio, 0);\n+\tiomap_set_range_dirty(folio, off, len);\n \treturn filemap_dirty_folio(mapping, folio);\n }\n+EXPORT_SYMBOL_GPL(iomap_dirty_folio_range);\n+\n+bool iomap_dirty_folio(struct address_space *mapping, struct folio *folio)\n+{\n+\treturn iomap_dirty_folio_range(mapping, folio, 0, folio_size(folio));\n+}\n EXPORT_SYMBOL_GPL(iomap_dirty_folio);\n \n static void\n@@ -1804,7 +1808,7 @@ iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero,\n EXPORT_SYMBOL_GPL(iomap_truncate_page);\n \n static int iomap_folio_mkwrite_iter(struct iomap_iter *iter,\n-\t\tstruct folio *folio)\n+\t\tstruct folio *folio, size_t dirty_off, size_t dirty_len)\n {\n \tloff_t length = iomap_length(iter);\n \tint ret;\n@@ -1817,7 +1821,7 @@ static int iomap_folio_mkwrite_iter(struct iomap_iter *iter,\n \t\tblock_commit_write(folio, 0, length);\n \t} else {\n \t\tWARN_ON_ONCE(!folio_test_uptodate(folio));\n-\t\tfolio_mark_dirty(folio);\n+\t\tfolio_mark_dirty_range(folio, dirty_off, dirty_len);\n \t}\n \n \treturn iomap_iter_advance(iter, length);\n@@ -1832,6 +1836,7 @@ vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops,\n \t\t.private\t= private,\n \t};\n \tstruct folio *folio = page_folio(vmf-\u003epage);\n+\tsize_t dirty_off, dirty_len;\n \tssize_t ret;\n \n \tfolio_lock(folio);\n@@ -1840,8 +1845,22 @@ vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops,\n \t\tgoto out_unlock;\n \titer.pos = folio_pos(folio);\n \titer.len = ret;\n+\n+\t/*\n+\t * Blocks are still allocated for the whole folio, but only the page\n+\t * the fault was for has been written, so that is all that has to be\n+\t * written back.  A racing truncate can leave that page beyond i_size,\n+\t * and then there is nothing to dirty.\n+\t */\n+\tdirty_off = folio_page_idx(folio, vmf-\u003epage) \u003c\u003c PAGE_SHIFT;\n+\tif (dirty_off \u003c ret)\n+\t\tdirty_len = min_t(size_t, PAGE_SIZE, ret - dirty_off);\n+\telse\n+\t\tdirty_len = 0;\n+\n \twhile ((ret = iomap_iter(\u0026iter, ops)) \u003e 0)\n-\t\titer.status = iomap_folio_mkwrite_iter(\u0026iter, folio);\n+\t\titer.status = iomap_folio_mkwrite_iter(\u0026iter, folio,\n+\t\t\t\t\t\t       dirty_off, dirty_len);\n \n \tif (ret \u003c 0)\n \t\tgoto out_unlock;\ndiff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c\nindex 74a6089abadf9..600e7de2e599c 100644\n--- a/fs/xfs/xfs_aops.c\n+++ b/fs/xfs/xfs_aops.c\n@@ -863,7 +863,7 @@ const struct address_space_operations xfs_address_space_operations = {\n \t.read_folio\t\t= xfs_vm_read_folio,\n \t.readahead\t\t= xfs_vm_readahead,\n \t.writepages\t\t= xfs_vm_writepages,\n-\t.dirty_folio\t\t= iomap_dirty_folio,\n+\t.dirty_folio_range\t= iomap_dirty_folio_range,\n \t.release_folio\t\t= iomap_release_folio,\n \t.invalidate_folio\t= iomap_invalidate_folio,\n \t.bmap\t\t\t= xfs_vm_bmap,\ndiff --git a/include/linux/fs.h b/include/linux/fs.h\nindex 072d8cd09a0b2..1d98b6c0b8804 100644\n--- a/include/linux/fs.h\n+++ b/include/linux/fs.h\n@@ -406,6 +406,9 @@ struct address_space_operations {\n \n \t/* Mark a folio dirty.  Return true if this dirtied it */\n \tbool (*dirty_folio)(struct address_space *, struct folio *);\n+\t/* Mark [off, off + len) of a folio dirty */\n+\tbool (*dirty_folio_range)(struct address_space *mapping,\n+\t\t\t\t  struct folio *folio, size_t off, size_t len);\n \n \tvoid (*readahead)(struct readahead_control *);\n \ndiff --git a/include/linux/iomap.h b/include/linux/iomap.h\nindex bc7ae6327dbf8..3cf2ac751409c 100644\n--- a/include/linux/iomap.h\n+++ b/include/linux/iomap.h\n@@ -443,6 +443,8 @@ struct folio *iomap_get_folio(struct iomap_iter *iter, loff_t pos, size_t len);\n bool iomap_release_folio(struct folio *folio, gfp_t gfp_flags);\n void iomap_invalidate_folio(struct folio *folio, size_t offset, size_t len);\n bool iomap_dirty_folio(struct address_space *mapping, struct folio *folio);\n+bool iomap_dirty_folio_range(struct address_space *mapping, struct folio *folio,\n+\t\tsize_t off, size_t len);\n void iomap_folio_mark_uptodate(struct folio *folio);\n int iomap_file_unshare(struct inode *inode, loff_t pos, loff_t len,\n \t\tconst struct iomap_ops *ops,\ndiff --git a/include/linux/mm.h b/include/linux/mm.h\nindex 87feaa5a2b780..7628262c17e14 100644\n--- a/include/linux/mm.h\n+++ b/include/linux/mm.h\n@@ -3337,6 +3337,7 @@ struct kvec;\n struct page *get_dump_page(unsigned long addr, int *locked);\n \n bool folio_mark_dirty(struct folio *folio);\n+bool folio_mark_dirty_range(struct folio *folio, size_t off, size_t len);\n bool folio_mark_dirty_lock(struct folio *folio);\n bool set_page_dirty(struct page *page);\n int set_page_dirty_lock(struct page *page);\ndiff --git a/include/linux/rmap.h b/include/linux/rmap.h\nindex 8dc0871e5f001..6fc0a60202527 100644\n--- a/include/linux/rmap.h\n+++ b/include/linux/rmap.h\n@@ -927,6 +927,7 @@ unsigned long page_address_in_vma(const struct folio *folio,\n  * returns the number of cleaned PTEs.\n  */\n int folio_mkclean(struct folio *);\n+int folio_mkclean_dirtymap(struct folio *folio, unsigned long *dirty_map);\n \n int mapping_wrprotect_range(struct address_space *mapping, pgoff_t pgoff,\n \t\tunsigned long pfn, unsigned long nr_pages);\n@@ -990,6 +991,12 @@ static inline int folio_mkclean(struct folio *folio)\n {\n \treturn 0;\n }\n+\n+static inline int folio_mkclean_dirtymap(struct folio *folio,\n+\t\t\t\t\t unsigned long *dirty_map)\n+{\n+\treturn 0;\n+}\n #endif\t/* CONFIG_MMU */\n \n #endif\t/* _LINUX_RMAP_H */\ndiff --git a/mm/memory.c b/mm/memory.c\nindex 8da0f945141b4..27a059e0c016f 100644\n--- a/mm/memory.c\n+++ b/mm/memory.c\n@@ -3778,10 +3778,19 @@ static vm_fault_t fault_dirty_shared_page(struct vm_fault *vmf)\n \tstruct vm_area_struct *vma = vmf-\u003evma;\n \tstruct address_space *mapping;\n \tstruct folio *folio = page_folio(vmf-\u003epage);\n+\tsize_t off = folio_page_idx(folio, vmf-\u003epage) \u003c\u003c PAGE_SHIFT;\n \tbool dirtied;\n \tbool page_mkwrite = vma-\u003evm_ops \u0026\u0026 vma-\u003evm_ops-\u003epage_mkwrite;\n \n-\tdirtied = folio_mark_dirty(folio);\n+\t/*\n+\t * A PMD entry has one dirty bit for the whole folio, so there is no\n+\t * finer information to pass on. A PTE-mapped folio only has the page\n+\t * the fault was for dirtied so far.\n+\t */\n+\tif (pmd_trans_huge(pmdp_get_lockless(vmf-\u003epmd)))\n+\t\tdirtied = folio_mark_dirty(folio);\n+\telse\n+\t\tdirtied = folio_mark_dirty_range(folio, off, PAGE_SIZE);\n \tVM_BUG_ON_FOLIO(folio_test_anon(folio), folio);\n \t/*\n \t * Take a local copy of the address_space - folio.mapping may be zeroed\n@@ -5625,6 +5634,31 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct folio *folio, struct page *pa\n }\n #endif\n \n+/*\n+ * May the whole batch be marked dirty?\n+ *\n+ * Only a shared mapping of a filesystem that tracks dirty state per block says\n+ * no. There the page table dirty bits are the only record of which parts of a\n+ * large folio were written through the mapping, so pages nobody has stored to\n+ * have to stay clean and let the hardware set the bit on the first store.\n+ *\n+ * Everywhere else nothing ever reads those bits, and on hardware without a\n+ * dirty bit leaving them clean costs a fault per page for nothing. That covers\n+ * shmem, which has no dirty state below the folio.\n+ */\n+static bool can_dirty_whole_batch(struct vm_fault *vmf, unsigned int nr,\n+\t\t\t\t  bool prefault)\n+{\n+\tstruct vm_area_struct *vma = vmf-\u003evma;\n+\n+\tif (!(vmf-\u003eflags \u0026 FAULT_FLAG_WRITE) || prefault || nr == 1)\n+\t\treturn true;\n+\tif (!(vma-\u003evm_flags \u0026 VM_SHARED))\n+\t\treturn true;\n+\n+\treturn !vma-\u003evm_file-\u003ef_mapping-\u003ea_ops-\u003edirty_folio_range;\n+}\n+\n /**\n  * set_pte_range - Set a range of PTEs to point to pages in a folio.\n  * @vmf: Fault description.\n@@ -5639,6 +5673,7 @@ void set_pte_range(struct vm_fault *vmf, struct folio *folio,\n \tstruct vm_area_struct *vma = vmf-\u003evma;\n \tbool write = vmf-\u003eflags \u0026 FAULT_FLAG_WRITE;\n \tbool prefault = !in_range(vmf-\u003eaddress, addr, nr * PAGE_SIZE);\n+\tbool dirty_batch = can_dirty_whole_batch(vmf, nr, prefault);\n \tpte_t entry;\n \n \tflush_icache_pages(vma, page, nr);\n@@ -5649,10 +5684,13 @@ void set_pte_range(struct vm_fault *vmf, struct folio *folio,\n \telse\n \t\tentry = pte_sw_mkyoung(entry);\n \n-\tif (write)\n-\t\tentry = maybe_mkwrite(pte_mkdirty(entry), vma);\n-\telse if (pte_write(entry) \u0026\u0026 folio_test_dirty(folio))\n+\tif (write) {\n+\t\tif (dirty_batch)\n+\t\t\tentry = pte_mkdirty(entry);\n+\t\tentry = maybe_mkwrite(entry, vma);\n+\t} else if (pte_write(entry) \u0026\u0026 folio_test_dirty(folio)) {\n \t\tentry = pte_mkdirty(entry);\n+\t}\n \tif (unlikely(vmf_orig_pte_uffd_wp(vmf)))\n \t\tentry = pte_mkuffd(entry);\n \t/* copy-on-write page */\n@@ -5665,6 +5703,18 @@ void set_pte_range(struct vm_fault *vmf, struct folio *folio,\n \t}\n \tset_ptes(vma-\u003evm_mm, addr, vmf-\u003epte, entry, nr);\n \n+\t/*\n+\t * The page the fault was for is about to be stored to, so dirty it\n+\t * here rather than leave the store to a second page table walk, or to\n+\t * a second fault where the dirty bit is maintained in software.\n+\t */\n+\tif (!dirty_batch) {\n+\t\tpte_t *ptep = vmf-\u003epte + ((vmf-\u003eaddress - addr) \u003e\u003e PAGE_SHIFT);\n+\n+\t\tptep_set_access_flags(vma, vmf-\u003eaddress, ptep,\n+\t\t\t\t      pte_mkdirty(ptep_get(ptep)), 1);\n+\t}\n+\n \t/* no need to invalidate: a not-present page won't be cached */\n \tupdate_mmu_cache_range(vmf, vma, addr, vmf-\u003epte, nr);\n }\ndiff --git a/mm/page-writeback.c b/mm/page-writeback.c\nindex 6c9c7ba89b8a9..39b54c25a9fab 100644\n--- a/mm/page-writeback.c\n+++ b/mm/page-writeback.c\n@@ -2751,6 +2751,21 @@ bool folio_redirty_for_writepage(struct writeback_control *wbc,\n }\n EXPORT_SYMBOL(folio_redirty_for_writepage);\n \n+/*\n+ * Hand a dirtied range of @folio to the filesystem.  -\u003edirty_folio_range() can\n+ * express everything -\u003edirty_folio() can, so a filesystem that implements it\n+ * does not need both, and a whole-folio dirty comes through here as a range\n+ * covering the folio.\n+ */\n+static bool mapping_dirty_range(struct address_space *mapping,\n+\t\t\t\tstruct folio *folio, size_t off, size_t len)\n+{\n+\tif (!mapping-\u003ea_ops-\u003edirty_folio_range)\n+\t\treturn mapping-\u003ea_ops-\u003edirty_folio(mapping, folio);\n+\n+\treturn mapping-\u003ea_ops-\u003edirty_folio_range(mapping, folio, off, len);\n+}\n+\n /**\n  * folio_mark_dirty - Mark a folio as being modified.\n  * @folio: The folio.\n@@ -2782,13 +2797,39 @@ bool folio_mark_dirty(struct folio *folio)\n \t\t */\n \t\tif (folio_test_reclaim(folio))\n \t\t\tfolio_clear_reclaim(folio);\n-\t\treturn mapping-\u003ea_ops-\u003edirty_folio(mapping, folio);\n+\t\treturn mapping_dirty_range(mapping, folio, 0,\n+\t\t\t\t\t   folio_size(folio));\n \t}\n \n \treturn noop_dirty_folio(mapping, folio);\n }\n EXPORT_SYMBOL(folio_mark_dirty);\n \n+/**\n+ * folio_mark_dirty_range - Mark part of a folio as being modified.\n+ * @folio: The folio.\n+ * @off: Offset of the modified range within the folio.\n+ * @len: Length of the modified range.\n+ *\n+ * Like folio_mark_dirty(), but tells a filesystem that tracks dirty state per\n+ * block that only [@off, @off + @len) changed, so writeback can skip the rest\n+ * of the folio.  Filesystems without that tracking dirty the whole folio.\n+ *\n+ * Return: True if the folio was newly dirtied, false if it was already dirty.\n+ */\n+bool folio_mark_dirty_range(struct folio *folio, size_t off, size_t len)\n+{\n+\tstruct address_space *mapping = folio_mapping(folio);\n+\n+\tif (likely(mapping)) {\n+\t\tif (folio_test_reclaim(folio))\n+\t\t\tfolio_clear_reclaim(folio);\n+\t\treturn mapping_dirty_range(mapping, folio, off, len);\n+\t}\n+\n+\treturn noop_dirty_folio(mapping, folio);\n+}\n+\n /*\n  * folio_mark_dirty() is racy if the caller has no reference against\n  * folio-\u003emapping-\u003ehost, and if the folio is unlocked.  This is because another\n@@ -2844,6 +2885,41 @@ void __folio_cancel_dirty(struct folio *folio)\n }\n EXPORT_SYMBOL(__folio_cancel_dirty);\n \n+/*\n+ * Write-protect every mapping of @folio and hand the filesystem the parts that\n+ * were dirty in a page table.\n+ *\n+ * Without -\u003edirty_folio_range() there is nowhere to put per-block state, so\n+ * any PTE dirty bit dirties the whole folio.  Same when the folio is not\n+ * already dirty, because then the dirty transition needs the full accounting\n+ * in folio_mark_dirty(), and for a folio too large for the bitmap, which the\n+ * page cache does not make.\n+ */\n+static void folio_mkclean_for_io(struct folio *folio,\n+\t\t\t\t struct address_space *mapping)\n+{\n+\tDECLARE_BITMAP(map, 1UL \u003c\u003c MAX_PAGECACHE_ORDER);\n+\tunsigned int nr = folio_nr_pages(folio);\n+\tunsigned int start, end;\n+\n+\tif (!mapping-\u003ea_ops-\u003edirty_folio_range || !folio_test_dirty(folio) ||\n+\t    WARN_ON_ONCE(nr \u003e (1UL \u003c\u003c MAX_PAGECACHE_ORDER))) {\n+\t\tif (folio_mkclean(folio))\n+\t\t\tfolio_mark_dirty(folio);\n+\t\treturn;\n+\t}\n+\n+\tbitmap_zero(map, nr);\n+\tif (!folio_mkclean_dirtymap(folio, map))\n+\t\treturn;\n+\n+\tfor_each_set_bitrange(start, end, map, nr) {\n+\t\tmapping_dirty_range(mapping, folio,\n+\t\t\t\t    (size_t)start \u003c\u003c PAGE_SHIFT,\n+\t\t\t\t    (size_t)(end - start) \u003c\u003c PAGE_SHIFT);\n+\t}\n+}\n+\n /*\n  * Clear a folio's dirty flag, while caring for dirty memory accounting.\n  * Returns true if the folio was previously dirty.\n@@ -2875,9 +2951,9 @@ bool folio_clear_dirty_for_io(struct folio *folio)\n \t\t *\n \t\t * We use this sequence to make sure that\n \t\t *  (a) we account for dirty stats properly\n-\t\t *  (b) we tell the low-level filesystem to\n-\t\t *      mark the whole folio dirty if it was\n-\t\t *      dirty in a pagetable. Only to then\n+\t\t *  (b) we tell the low-level filesystem which\n+\t\t *      parts of the folio were dirty in a\n+\t\t *      pagetable. Only to then\n \t\t *  (c) clean the folio again and return 1 to\n \t\t *      cause the writeback.\n \t\t *\n@@ -2895,8 +2971,7 @@ bool folio_clear_dirty_for_io(struct folio *folio)\n \t\t * as a serialization point for all the different\n \t\t * threads doing their things.\n \t\t */\n-\t\tif (folio_mkclean(folio))\n-\t\t\tfolio_mark_dirty(folio);\n+\t\tfolio_mkclean_for_io(folio, mapping);\n \t\t/*\n \t\t * We carefully synchronise fault handlers against\n \t\t * installing a dirty pte and marking the folio dirty\ndiff --git a/mm/rmap.c b/mm/rmap.c\nindex 1f72d279ba68f..aaf45ac79fa84 100644\n--- a/mm/rmap.c\n+++ b/mm/rmap.c\n@@ -1100,12 +1100,18 @@ int folio_referenced(struct folio *folio, int is_locked,\n \treturn rwc.contended ? -1 : pra.referenced;\n }\n \n-static int page_vma_mkclean_one(struct page_vma_mapped_walk *pvmw)\n+struct mkclean_state {\n+\tunsigned long *dirty_map;\n+\tint cleaned;\n+};\n+\n+static int page_vma_mkclean_one(struct page_vma_mapped_walk *pvmw,\n+\t\t\t\tunsigned long *dirty_map)\n {\n-\tint cleaned = 0;\n \tstruct vm_area_struct *vma = pvmw-\u003evma;\n-\tstruct mmu_notifier_range range;\n \tunsigned long address = pvmw-\u003eaddress;\n+\tstruct mmu_notifier_range range;\n+\tint cleaned = 0;\n \n \t/*\n \t * We have to assume the worse case ie pmd for invalidation. Note that\n@@ -1134,6 +1140,15 @@ static int page_vma_mkclean_one(struct page_vma_mapped_walk *pvmw)\n \t\t\tif (!pte_dirty(entry) \u0026\u0026 !pte_write(entry))\n \t\t\t\tcontinue;\n \n+\t\t\tif (dirty_map \u0026\u0026 pte_dirty(entry)) {\n+\t\t\t\tpgoff_t idx = linear_page_index(vma, address) -\n+\t\t\t\t\t      pvmw-\u003epgoff;\n+\n+\t\t\t\t/* The walk only visits pages of this folio */\n+\t\t\t\tVM_WARN_ON_ONCE(idx \u003e= pvmw-\u003enr_pages);\n+\t\t\t\t__set_bit(idx, dirty_map);\n+\t\t\t}\n+\n \t\t\tflush_cache_page(vma, address, pte_pfn(entry));\n \t\t\tentry = ptep_clear_flush(vma, address, pte);\n \t\t\tentry = pte_wrprotect(entry);\n@@ -1155,6 +1170,9 @@ static int page_vma_mkclean_one(struct page_vma_mapped_walk *pvmw)\n \t\t\tif (!pmd_dirty(entry) \u0026\u0026 !pmd_write(entry))\n \t\t\t\tcontinue;\n \n+\t\t\tif (dirty_map \u0026\u0026 pmd_dirty(entry))\n+\t\t\t\tbitmap_set(dirty_map, 0, pvmw-\u003enr_pages);\n+\n \t\t\tflush_cache_range(vma, address,\n \t\t\t\t\t  address + HPAGE_PMD_SIZE);\n \t\t\tentry = pmdp_invalidate(vma, address, pmd);\n@@ -1181,9 +1199,9 @@ static bool page_mkclean_one(struct folio *folio, struct vm_area_struct *vma,\n \t\t\t     unsigned long address, void *arg)\n {\n \tDEFINE_FOLIO_VMA_WALK(pvmw, folio, vma, address, PVMW_SYNC);\n-\tint *cleaned = arg;\n+\tstruct mkclean_state *state = arg;\n \n-\t*cleaned += page_vma_mkclean_one(\u0026pvmw);\n+\tstate-\u003ecleaned += page_vma_mkclean_one(\u0026pvmw, state-\u003edirty_map);\n \n \treturn true;\n }\n@@ -1196,12 +1214,23 @@ static bool invalid_mkclean_vma(struct vm_area_struct *vma, void *arg)\n \treturn true;\n }\n \n-int folio_mkclean(struct folio *folio)\n+/**\n+ * folio_mkclean_dirtymap - Write-protect a folio and report what was dirty.\n+ * @folio: The folio to clean.\n+ * @dirty_map: Bitmap of at least folio_nr_pages(@folio) bits, or NULL.\n+ *\n+ * Write-protects and cleans every mapping of @folio.  With @dirty_map, sets a\n+ * bit for each page whose entry was dirty; a PMD-mapped folio has one dirty\n+ * bit for all of it, so every page is reported.\n+ *\n+ * Return: the number of page table entries cleaned.\n+ */\n+int folio_mkclean_dirtymap(struct folio *folio, unsigned long *dirty_map)\n {\n-\tint cleaned = 0;\n+\tstruct mkclean_state state = { .dirty_map = dirty_map };\n \tstruct address_space *mapping;\n \tstruct rmap_walk_control rwc = {\n-\t\t.arg = (void *)\u0026cleaned,\n+\t\t.arg = (void *)\u0026state,\n \t\t.rmap_one = page_mkclean_one,\n \t\t.invalid_vma = invalid_mkclean_vma,\n \t};\n@@ -1217,7 +1246,12 @@ int folio_mkclean(struct folio *folio)\n \n \trmap_walk(folio, \u0026rwc);\n \n-\treturn cleaned;\n+\treturn state.cleaned;\n+}\n+\n+int folio_mkclean(struct folio *folio)\n+{\n+\treturn folio_mkclean_dirtymap(folio, NULL);\n }\n EXPORT_SYMBOL_GPL(folio_mkclean);\n \n@@ -1241,7 +1275,7 @@ static bool mapping_wrprotect_range_one(struct folio *folio,\n \t\t.flags\t\t= PVMW_SYNC,\n \t};\n \n-\tstate-\u003ecleaned += page_vma_mkclean_one(\u0026pvmw);\n+\tstate-\u003ecleaned += page_vma_mkclean_one(\u0026pvmw, NULL);\n \n \treturn true;\n }\n@@ -1324,7 +1358,7 @@ int pfn_mkclean_range(unsigned long pfn, unsigned long nr_pages, pgoff_t pgoff,\n \tpvmw.address = vma_address(vma, pgoff, nr_pages);\n \tVM_BUG_ON_VMA(pvmw.address == -EFAULT, vma);\n \n-\treturn page_vma_mkclean_one(\u0026pvmw);\n+\treturn page_vma_mkclean_one(\u0026pvmw, NULL);\n }\n \n static void __folio_mod_stat(struct folio *folio, int nr, int nr_pmdmapped)\n"
}

2/1 2026/09/05 04:02 agent patch-evaluator
0m Model:
core

Args:
null

Results:
{
  "EnableConfigs": [
    "XFS_FS"
  ],
  "FocusSymbols": [
    "iomap_dirty_folio_range",
    "iomap_page_mkwrite",
    "folio_mark_dirty_range",
    "folio_mkclean_dirtymap",
    "folio_clear_dirty_for_io"
  ],
  "Reasoning": "The patch series introduces sub-folio range dirtying via -\u003edirty_folio_range, folio_mark_dirty_range(), folio_mkclean_dirtymap(), and iomap_dirty_folio_range() for XFS/iomap. It modifies core MM dirty folio tracking, write-protect/clean transitions in writeback (folio_clear_dirty_for_io), rmap PTE/PMD dirty walk, and page fault handling for shared mappings. These reachable MM and filesystem paths warrant fuzzing.",
  "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 0519b461c9b3fdecaa880e0c93b4da997751c1b2
Author: syz-cluster <triage@syzkaller.com>
Date:   Sat Sep 5 04:02:38 2026 +0000

    syz-cluster: applied patch under review

diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 0a5ebfda90f12..8d8a8acab01ac 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -847,15 +847,19 @@ void iomap_invalidate_folio(struct folio *folio, size_t offset, size_t len)
 }
 EXPORT_SYMBOL_GPL(iomap_invalidate_folio);
 
-bool iomap_dirty_folio(struct address_space *mapping, struct folio *folio)
+bool iomap_dirty_folio_range(struct address_space *mapping, struct folio *folio,
+		size_t off, size_t len)
 {
-	struct inode *inode = mapping->host;
-	size_t len = folio_size(folio);
-
-	ifs_alloc(inode, folio, 0);
-	iomap_set_range_dirty(folio, 0, len);
+	ifs_alloc(mapping->host, folio, 0);
+	iomap_set_range_dirty(folio, off, len);
 	return filemap_dirty_folio(mapping, folio);
 }
+EXPORT_SYMBOL_GPL(iomap_dirty_folio_range);
+
+bool iomap_dirty_folio(struct address_space *mapping, struct folio *folio)
+{
+	return iomap_dirty_folio_range(mapping, folio, 0, folio_size(folio));
+}
 EXPORT_SYMBOL_GPL(iomap_dirty_folio);
 
 static void
@@ -1804,7 +1808,7 @@ iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero,
 EXPORT_SYMBOL_GPL(iomap_truncate_page);
 
 static int iomap_folio_mkwrite_iter(struct iomap_iter *iter,
-		struct folio *folio)
+		struct folio *folio, size_t dirty_off, size_t dirty_len)
 {
 	loff_t length = iomap_length(iter);
 	int ret;
@@ -1817,7 +1821,7 @@ static int iomap_folio_mkwrite_iter(struct iomap_iter *iter,
 		block_commit_write(folio, 0, length);
 	} else {
 		WARN_ON_ONCE(!folio_test_uptodate(folio));
-		folio_mark_dirty(folio);
+		folio_mark_dirty_range(folio, dirty_off, dirty_len);
 	}
 
 	return iomap_iter_advance(iter, length);
@@ -1832,6 +1836,7 @@ vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops,
 		.private	= private,
 	};
 	struct folio *folio = page_folio(vmf->page);
+	size_t dirty_off, dirty_len;
 	ssize_t ret;
 
 	folio_lock(folio);
@@ -1840,8 +1845,22 @@ vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops,
 		goto out_unlock;
 	iter.pos = folio_pos(folio);
 	iter.len = ret;
+
+	/*
+	 * Blocks are still allocated for the whole folio, but only the page
+	 * the fault was for has been written, so that is all that has to be
+	 * written back.  A racing truncate can leave that page beyond i_size,
+	 * and then there is nothing to dirty.
+	 */
+	dirty_off = folio_page_idx(folio, vmf->page) << PAGE_SHIFT;
+	if (dirty_off < ret)
+		dirty_len = min_t(size_t, PAGE_SIZE, ret - dirty_off);
+	else
+		dirty_len = 0;
+
 	while ((ret = iomap_iter(&iter, ops)) > 0)
-		iter.status = iomap_folio_mkwrite_iter(&iter, folio);
+		iter.status = iomap_folio_mkwrite_iter(&iter, folio,
+						       dirty_off, dirty_len);
 
 	if (ret < 0)
 		goto out_unlock;
diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
index 74a6089abadf9..600e7de2e599c 100644
--- a/fs/xfs/xfs_aops.c
+++ b/fs/xfs/xfs_aops.c
@@ -863,7 +863,7 @@ const struct address_space_operations xfs_address_space_operations = {
 	.read_folio		= xfs_vm_read_folio,
 	.readahead		= xfs_vm_readahead,
 	.writepages		= xfs_vm_writepages,
-	.dirty_folio		= iomap_dirty_folio,
+	.dirty_folio_range	= iomap_dirty_folio_range,
 	.release_folio		= iomap_release_folio,
 	.invalidate_folio	= iomap_invalidate_folio,
 	.bmap			= xfs_vm_bmap,
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 072d8cd09a0b2..1d98b6c0b8804 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -406,6 +406,9 @@ struct address_space_operations {
 
 	/* Mark a folio dirty.  Return true if this dirtied it */
 	bool (*dirty_folio)(struct address_space *, struct folio *);
+	/* Mark [off, off + len) of a folio dirty */
+	bool (*dirty_folio_range)(struct address_space *mapping,
+				  struct folio *folio, size_t off, size_t len);
 
 	void (*readahead)(struct readahead_control *);
 
diff --git a/include/linux/iomap.h b/include/linux/iomap.h
index bc7ae6327dbf8..3cf2ac751409c 100644
--- a/include/linux/iomap.h
+++ b/include/linux/iomap.h
@@ -443,6 +443,8 @@ struct folio *iomap_get_folio(struct iomap_iter *iter, loff_t pos, size_t len);
 bool iomap_release_folio(struct folio *folio, gfp_t gfp_flags);
 void iomap_invalidate_folio(struct folio *folio, size_t offset, size_t len);
 bool iomap_dirty_folio(struct address_space *mapping, struct folio *folio);
+bool iomap_dirty_folio_range(struct address_space *mapping, struct folio *folio,
+		size_t off, size_t len);
 void iomap_folio_mark_uptodate(struct folio *folio);
 int iomap_file_unshare(struct inode *inode, loff_t pos, loff_t len,
 		const struct iomap_ops *ops,
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 87feaa5a2b780..7628262c17e14 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -3337,6 +3337,7 @@ struct kvec;
 struct page *get_dump_page(unsigned long addr, int *locked);
 
 bool folio_mark_dirty(struct folio *folio);
+bool folio_mark_dirty_range(struct folio *folio, size_t off, size_t len);
 bool folio_mark_dirty_lock(struct folio *folio);
 bool set_page_dirty(struct page *page);
 int set_page_dirty_lock(struct page *page);
diff --git a/include/linux/rmap.h b/include/linux/rmap.h
index 8dc0871e5f001..6fc0a60202527 100644
--- a/include/linux/rmap.h
+++ b/include/linux/rmap.h
@@ -927,6 +927,7 @@ unsigned long page_address_in_vma(const struct folio *folio,
  * returns the number of cleaned PTEs.
  */
 int folio_mkclean(struct folio *);
+int folio_mkclean_dirtymap(struct folio *folio, unsigned long *dirty_map);
 
 int mapping_wrprotect_range(struct address_space *mapping, pgoff_t pgoff,
 		unsigned long pfn, unsigned long nr_pages);
@@ -990,6 +991,12 @@ static inline int folio_mkclean(struct folio *folio)
 {
 	return 0;
 }
+
+static inline int folio_mkclean_dirtymap(struct folio *folio,
+					 unsigned long *dirty_map)
+{
+	return 0;
+}
 #endif	/* CONFIG_MMU */
 
 #endif	/* _LINUX_RMAP_H */
diff --git a/mm/memory.c b/mm/memory.c
index 8da0f945141b4..27a059e0c016f 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -3778,10 +3778,19 @@ static vm_fault_t fault_dirty_shared_page(struct vm_fault *vmf)
 	struct vm_area_struct *vma = vmf->vma;
 	struct address_space *mapping;
 	struct folio *folio = page_folio(vmf->page);
+	size_t off = folio_page_idx(folio, vmf->page) << PAGE_SHIFT;
 	bool dirtied;
 	bool page_mkwrite = vma->vm_ops && vma->vm_ops->page_mkwrite;
 
-	dirtied = folio_mark_dirty(folio);
+	/*
+	 * A PMD entry has one dirty bit for the whole folio, so there is no
+	 * finer information to pass on. A PTE-mapped folio only has the page
+	 * the fault was for dirtied so far.
+	 */
+	if (pmd_trans_huge(pmdp_get_lockless(vmf->pmd)))
+		dirtied = folio_mark_dirty(folio);
+	else
+		dirtied = folio_mark_dirty_range(folio, off, PAGE_SIZE);
 	VM_BUG_ON_FOLIO(folio_test_anon(folio), folio);
 	/*
 	 * Take a local copy of the address_space - folio.mapping may be zeroed
@@ -5625,6 +5634,31 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct folio *folio, struct page *pa
 }
 #endif
 
+/*
+ * May the whole batch be marked dirty?
+ *
+ * Only a shared mapping of a filesystem that tracks dirty state per block says
+ * no. There the page table dirty bits are the only record of which parts of a
+ * large folio were written through the mapping, so pages nobody has stored to
+ * have to stay clean and let the hardware set the bit on the first store.
+ *
+ * Everywhere else nothing ever reads those bits, and on hardware without a
+ * dirty bit leaving them clean costs a fault per page for nothing. That covers
+ * shmem, which has no dirty state below the folio.
+ */
+static bool can_dirty_whole_batch(struct vm_fault *vmf, unsigned int nr,
+				  bool prefault)
+{
+	struct vm_area_struct *vma = vmf->vma;
+
+	if (!(vmf->flags & FAULT_FLAG_WRITE) || prefault || nr == 1)
+		return true;
+	if (!(vma->vm_flags & VM_SHARED))
+		return true;
+
+	return !vma->vm_file->f_mapping->a_ops->dirty_folio_range;
+}
+
 /**
  * set_pte_range - Set a range of PTEs to point to pages in a folio.
  * @vmf: Fault description.
@@ -5639,6 +5673,7 @@ void set_pte_range(struct vm_fault *vmf, struct folio *folio,
 	struct vm_area_struct *vma = vmf->vma;
 	bool write = vmf->flags & FAULT_FLAG_WRITE;
 	bool prefault = !in_range(vmf->address, addr, nr * PAGE_SIZE);
+	bool dirty_batch = can_dirty_whole_batch(vmf, nr, prefault);
 	pte_t entry;
 
 	flush_icache_pages(vma, page, nr);
@@ -5649,10 +5684,13 @@ void set_pte_range(struct vm_fault *vmf, struct folio *folio,
 	else
 		entry = pte_sw_mkyoung(entry);
 
-	if (write)
-		entry = maybe_mkwrite(pte_mkdirty(entry), vma);
-	else if (pte_write(entry) && folio_test_dirty(folio))
+	if (write) {
+		if (dirty_batch)
+			entry = pte_mkdirty(entry);
+		entry = maybe_mkwrite(entry, vma);
+	} else if (pte_write(entry) && folio_test_dirty(folio)) {
 		entry = pte_mkdirty(entry);
+	}
 	if (unlikely(vmf_orig_pte_uffd_wp(vmf)))
 		entry = pte_mkuffd(entry);
 	/* copy-on-write page */
@@ -5665,6 +5703,18 @@ void set_pte_range(struct vm_fault *vmf, struct folio *folio,
 	}
 	set_ptes(vma->vm_mm, addr, vmf->pte, entry, nr);
 
+	/*
+	 * The page the fault was for is about to be stored to, so dirty it
+	 * here rather than leave the store to a second page table walk, or to
+	 * a second fault where the dirty bit is maintained in software.
+	 */
+	if (!dirty_batch) {
+		pte_t *ptep = vmf->pte + ((vmf->address - addr) >> PAGE_SHIFT);
+
+		ptep_set_access_flags(vma, vmf->address, ptep,
+				      pte_mkdirty(ptep_get(ptep)), 1);
+	}
+
 	/* no need to invalidate: a not-present page won't be cached */
 	update_mmu_cache_range(vmf, vma, addr, vmf->pte, nr);
 }
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 6c9c7ba89b8a9..39b54c25a9fab 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -2751,6 +2751,21 @@ bool folio_redirty_for_writepage(struct writeback_control *wbc,
 }
 EXPORT_SYMBOL(folio_redirty_for_writepage);
 
+/*
+ * Hand a dirtied range of @folio to the filesystem.  ->dirty_folio_range() can
+ * express everything ->dirty_folio() can, so a filesystem that implements it
+ * does not need both, and a whole-folio dirty comes through here as a range
+ * covering the folio.
+ */
+static bool mapping_dirty_range(struct address_space *mapping,
+				struct folio *folio, size_t off, size_t len)
+{
+	if (!mapping->a_ops->dirty_folio_range)
+		return mapping->a_ops->dirty_folio(mapping, folio);
+
+	return mapping->a_ops->dirty_folio_range(mapping, folio, off, len);
+}
+
 /**
  * folio_mark_dirty - Mark a folio as being modified.
  * @folio: The folio.
@@ -2782,13 +2797,39 @@ bool folio_mark_dirty(struct folio *folio)
 		 */
 		if (folio_test_reclaim(folio))
 			folio_clear_reclaim(folio);
-		return mapping->a_ops->dirty_folio(mapping, folio);
+		return mapping_dirty_range(mapping, folio, 0,
+					   folio_size(folio));
 	}
 
 	return noop_dirty_folio(mapping, folio);
 }
 EXPORT_SYMBOL(folio_mark_dirty);
 
+/**
+ * folio_mark_dirty_range - Mark part of a folio as being modified.
+ * @folio: The folio.
+ * @off: Offset of the modified range within the folio.
+ * @len: Length of the modified range.
+ *
+ * Like folio_mark_dirty(), but tells a filesystem that tracks dirty state per
+ * block that only [@off, @off + @len) changed, so writeback can skip the rest
+ * of the folio.  Filesystems without that tracking dirty the whole folio.
+ *
+ * Return: True if the folio was newly dirtied, false if it was already dirty.
+ */
+bool folio_mark_dirty_range(struct folio *folio, size_t off, size_t len)
+{
+	struct address_space *mapping = folio_mapping(folio);
+
+	if (likely(mapping)) {
+		if (folio_test_reclaim(folio))
+			folio_clear_reclaim(folio);
+		return mapping_dirty_range(mapping, folio, off, len);
+	}
+
+	return noop_dirty_folio(mapping, folio);
+}
+
 /*
  * folio_mark_dirty() is racy if the caller has no reference against
  * folio->mapping->host, and if the folio is unlocked.  This is because another
@@ -2844,6 +2885,41 @@ void __folio_cancel_dirty(struct folio *folio)
 }
 EXPORT_SYMBOL(__folio_cancel_dirty);
 
+/*
+ * Write-protect every mapping of @folio and hand the filesystem the parts that
+ * were dirty in a page table.
+ *
+ * Without ->dirty_folio_range() there is nowhere to put per-block state, so
+ * any PTE dirty bit dirties the whole folio.  Same when the folio is not
+ * already dirty, because then the dirty transition needs the full accounting
+ * in folio_mark_dirty(), and for a folio too large for the bitmap, which the
+ * page cache does not make.
+ */
+static void folio_mkclean_for_io(struct folio *folio,
+				 struct address_space *mapping)
+{
+	DECLARE_BITMAP(map, 1UL << MAX_PAGECACHE_ORDER);
+	unsigned int nr = folio_nr_pages(folio);
+	unsigned int start, end;
+
+	if (!mapping->a_ops->dirty_folio_range || !folio_test_dirty(folio) ||
+	    WARN_ON_ONCE(nr > (1UL << MAX_PAGECACHE_ORDER))) {
+		if (folio_mkclean(folio))
+			folio_mark_dirty(folio);
+		return;
+	}
+
+	bitmap_zero(map, nr);
+	if (!folio_mkclean_dirtymap(folio, map))
+		return;
+
+	for_each_set_bitrange(start, end, map, nr) {
+		mapping_dirty_range(mapping, folio,
+				    (size_t)start << PAGE_SHIFT,
+				    (size_t)(end - start) << PAGE_SHIFT);
+	}
+}
+
 /*
  * Clear a folio's dirty flag, while caring for dirty memory accounting.
  * Returns true if the folio was previously dirty.
@@ -2875,9 +2951,9 @@ bool folio_clear_dirty_for_io(struct folio *folio)
 		 *
 		 * We use this sequence to make sure that
 		 *  (a) we account for dirty stats properly
-		 *  (b) we tell the low-level filesystem to
-		 *      mark the whole folio dirty if it was
-		 *      dirty in a pagetable. Only to then
+		 *  (b) we tell the low-level filesystem which
+		 *      parts of the folio were dirty in a
+		 *      pagetable. Only to then
 		 *  (c) clean the folio again and return 1 to
 		 *      cause the writeback.
 		 *
@@ -2895,8 +2971,7 @@ bool folio_clear_dirty_for_io(struct folio *folio)
 		 * as a serialization point for all the different
 		 * threads doing their things.
 		 */
-		if (folio_mkclean(folio))
-			folio_mark_dirty(folio);
+		folio_mkclean_for_io(folio, mapping);
 		/*
 		 * We carefully synchronise fault handlers against
 		 * installing a dirty pte and marking the folio dirty
diff --git a/mm/rmap.c b/mm/rmap.c
index 1f72d279ba68f..aaf45ac79fa84 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1100,12 +1100,18 @@ int folio_referenced(struct folio *folio, int is_locked,
 	return rwc.contended ? -1 : pra.referenced;
 }
 
-static int page_vma_mkclean_one(struct page_vma_mapped_walk *pvmw)
+struct mkclean_state {
+	unsigned long *dirty_map;
+	int cleaned;
+};
+
+static int page_vma_mkclean_one(struct page_vma_mapped_walk *pvmw,
+				unsigned long *dirty_map)
 {
-	int cleaned = 0;
 	struct vm_area_struct *vma = pvmw->vma;
-	struct mmu_notifier_range range;
 	unsigned long address = pvmw->address;
+	struct mmu_notifier_range range;
+	int cleaned = 0;
 
 	/*
 	 * We have to assume the worse case ie pmd for invalidation. Note that
@@ -1134,6 +1140,15 @@ static int page_vma_mkclean_one(struct page_vma_mapped_walk *pvmw)
 			if (!pte_dirty(entry) && !pte_write(entry))
 				continue;
 
+			if (dirty_map && pte_dirty(entry)) {
+				pgoff_t idx = linear_page_index(vma, address) -
+					      pvmw->pgoff;
+
+				/* The walk only visits pages of this folio */
+				VM_WARN_ON_ONCE(idx >= pvmw->nr_pages);
+				__set_bit(idx, dirty_map);
+			}
+
 			flush_cache_page(vma, address, pte_pfn(entry));
 			entry = ptep_clear_flush(vma, address, pte);
 			entry = pte_wrprotect(entry);
@@ -1155,6 +1170,9 @@ static int page_vma_mkclean_one(struct page_vma_mapped_walk *pvmw)
 			if (!pmd_dirty(entry) && !pmd_write(entry))
 				continue;
 
+			if (dirty_map && pmd_dirty(entry))
+				bitmap_set(dirty_map, 0, pvmw->nr_pages);
+
 			flush_cache_range(vma, address,
 					  address + HPAGE_PMD_SIZE);
 			entry = pmdp_invalidate(vma, address, pmd);
@@ -1181,9 +1199,9 @@ static bool page_mkclean_one(struct folio *folio, struct vm_area_struct *vma,
 			     unsigned long address, void *arg)
 {
 	DEFINE_FOLIO_VMA_WALK(pvmw, folio, vma, address, PVMW_SYNC);
-	int *cleaned = arg;
+	struct mkclean_state *state = arg;
 
-	*cleaned += page_vma_mkclean_one(&pvmw);
+	state->cleaned += page_vma_mkclean_one(&pvmw, state->dirty_map);
 
 	return true;
 }
@@ -1196,12 +1214,23 @@ static bool invalid_mkclean_vma(struct vm_area_struct *vma, void *arg)
 	return true;
 }
 
-int folio_mkclean(struct folio *folio)
+/**
+ * folio_mkclean_dirtymap - Write-protect a folio and report what was dirty.
+ * @folio: The folio to clean.
+ * @dirty_map: Bitmap of at least folio_nr_pages(@folio) bits, or NULL.
+ *
+ * Write-protects and cleans every mapping of @folio.  With @dirty_map, sets a
+ * bit for each page whose entry was dirty; a PMD-mapped folio has one dirty
+ * bit for all of it, so every page is reported.
+ *
+ * Return: the number of page table entries cleaned.
+ */
+int folio_mkclean_dirtymap(struct folio *folio, unsigned long *dirty_map)
 {
-	int cleaned = 0;
+	struct mkclean_state state = { .dirty_map = dirty_map };
 	struct address_space *mapping;
 	struct rmap_walk_control rwc = {
-		.arg = (void *)&cleaned,
+		.arg = (void *)&state,
 		.rmap_one = page_mkclean_one,
 		.invalid_vma = invalid_mkclean_vma,
 	};
@@ -1217,7 +1246,12 @@ int folio_mkclean(struct folio *folio)
 
 	rmap_walk(folio, &rwc);
 
-	return cleaned;
+	return state.cleaned;
+}
+
+int folio_mkclean(struct folio *folio)
+{
+	return folio_mkclean_dirtymap(folio, NULL);
 }
 EXPORT_SYMBOL_GPL(folio_mkclean);
 
@@ -1241,7 +1275,7 @@ static bool mapping_wrprotect_range_one(struct folio *folio,
 		.flags		= PVMW_SYNC,
 	};
 
-	state->cleaned += page_vma_mkclean_one(&pvmw);
+	state->cleaned += page_vma_mkclean_one(&pvmw, NULL);
 
 	return true;
 }
@@ -1324,7 +1358,7 @@ int pfn_mkclean_range(unsigned long pfn, unsigned long nr_pages, pgoff_t pgoff,
 	pvmw.address = vma_address(vma, pgoff, nr_pages);
 	VM_BUG_ON_VMA(pvmw.address == -EFAULT, vma);
 
-	return page_vma_mkclean_one(&pvmw);
+	return page_vma_mkclean_one(&pvmw, NULL);
 }
 
 static void __folio_mod_stat(struct folio *folio, int nr, int nr_pmdmapped)

3/2 2026/09/05 04:02 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 9738
							output: 26
							thoughts: 514
						

Thoughts:
**Analyzing a Substantial Kernel Memory and Filesystem Modification**

Okay, here's what's running through my head. This patch is touching some **serious** core infrastructure. We're looking at modifications deep within memory management, virtual filesystem code (VFS), `iomap`, and even XFS. The specific files tell the story: changes to `iomap_dirty_folio_range`, `iomap_dirty_folio`, `iomap_folio_mkwrite_iter`, and `iomap_page_mkwrite` indicate fundamental adjustments to how the kernel handles buffered I/O through `iomap`. The inclusion of `.dirty_folio_range = iomap_dirty_folio_range` within `xfs_address_space_operations` is significant, directly integrating these `iomap` changes into XFS's address space operations.

The include files -- `fs.h`, `iomap.h`, `mm.h`, and `rmap.h` -- show that these changes are not isolated; they're expanding the `address_space_operations` structure, and adding new functions like `folio_mark_dirty_range`, and `folio_mkclean_dirtymap`. The MM code is also heavily involved, with `fault_dirty_shared_page`, `can_dirty_whole_batch`, and `set_pte_range` being modified, alongside changes to page writeback via functions like `mapping_dirty_range`, `folio_mark_dirty`, and `folio_mkclean_for_io`, as well as rmap (reverse map) modifications.  The changes to rmap look to support folio operations, so this could be a major memory reclamation or virtual memory change.

This is a **major** area of the kernel, affecting page cache writeback, faulting shared pages, mkwrite operations, reverse mapping, buffered IO, and XFS! And those are just the obvious functions that were changed. The impact of such changes could be far-reaching. Given the reach of these changes, I'm confident that this code is easily reachable within standard virtualized setups – think QEMU or even something like syzkaller.

My immediate next step is to examine the Kconfig options, to understand what build configurations would expose this code. I need to know the dependencies and what features are enabled to see the exposed attack surface. I'll need to use `grepper` or just manually go through the relevant Kconfig files, specifically `fs/xfs/Kconfig` and `fs/iomap/Kconfig`, to clarify the dependencies and find the enabled symbols.



4/2 2026/09/05 04:02 tool grepper
0m Args:
{
  "Expression": "config FS_IOMAP|config XFS_FS"
}

Results:
{
  "Output": "fs/Kconfig=12=config VALIDATE_FS_PARSER\n--\nfs/Kconfig-17-\nfs/Kconfig:18:config FS_IOMAP\nfs/Kconfig-19-\tbool\n--\nfs/xfs/Kconfig-1-# SPDX-License-Identifier: GPL-2.0-only\nfs/xfs/Kconfig:2:config XFS_FS\nfs/xfs/Kconfig-3-\ttristate \"XFS filesystem support\"\n"
}

5/2 2026/09/05 04:02 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 10966
							output: 33
							thoughts: 23
						

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

**XFS Configuration Dependencies: A Quick Audit**

Okay, so I need a refresher on the XFS configuration. Time to dive into the `fs/xfs/Kconfig` file. I'm going to quickly scan through it. I want to zero in on what other features or kernel subsystems XFS is pulling in through "select" or "depends on" directives. My goal is a high-level overview – looking for any subtle relationships or implied constraints that might impact my current focus, whatever it may be. I'm not after line-by-line understanding, just the key dependencies that dictate the XFS build configuration.



6/2 2026/09/05 04:02 tool read-file
0m Args:
{
  "File": "fs/xfs/Kconfig",
  "FirstLine": 1,
  "LineCount": 40
}

Results:
{
  "Contents": "   1:\t# SPDX-License-Identifier: GPL-2.0-only\n   2:\tconfig XFS_FS\n   3:\t\ttristate \"XFS filesystem support\"\n   4:\t\tdepends on BLOCK\n   5:\t\tselect EXPORTFS\n   6:\t\tselect CRC32\n   7:\t\tselect FS_IOMAP\n   8:\t\thelp\n   9:\t\t  XFS is a high performance journaling filesystem which originated\n  10:\t\t  on the SGI IRIX platform.  It is completely multi-threaded, can\n  11:\t\t  support large files and large filesystems, extended attributes,\n  12:\t\t  variable block sizes, is extent based, and makes extensive use of\n  13:\t\t  Btrees (directories, extents, free space) to aid both performance\n  14:\t\t  and scalability.\n  15:\t\n  16:\t\t  Refer to the documentation at \u003chttp://oss.sgi.com/projects/xfs/\u003e\n  17:\t\t  for complete details.  This implementation is on-disk compatible\n  18:\t\t  with the IRIX version of XFS.\n  19:\t\n  20:\t\t  To compile this file system support as a module, choose M here: the\n  21:\t\t  module will be called xfs.  Be aware, however, that if the file\n  22:\t\t  system of your root partition is compiled as a module, you'll need\n  23:\t\t  to use an initial ramdisk (initrd) to boot.\n  24:\t\n  25:\tconfig XFS_SUPPORT_V4\n  26:\t\tbool \"Support deprecated V4 (crc=0) format\"\n  27:\t\tdepends on XFS_FS\n  28:\t\tdefault n\n  29:\t\thelp\n  30:\t\t  The V4 filesystem format lacks certain features that are supported\n  31:\t\t  by the V5 format, such as metadata checksumming, strengthened\n  32:\t\t  metadata verification, and the ability to store timestamps past the\n  33:\t\t  year 2038.  Because of this, the V4 format is deprecated.  All users\n  34:\t\t  should upgrade by backing up their files, reformatting, and restoring\n  35:\t\t  from the backup.\n  36:\t\n  37:\t\t  Administrators and users can detect a V4 filesystem by running\n  38:\t\t  xfs_info against a filesystem mountpoint and checking for a string\n  39:\t\t  beginning with \"crc=\".  If the string \"crc=0\" is found, the\n  40:\t\t  filesystem is a V4 filesystem.  If no such string is found, please\n"
}

7/2 2026/09/05 04:02 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 11817
							output: 19
							thoughts: 88
						

Thoughts:
**Investigating XFS and Memory Management**

Okay, so XFS_FS is using BLOCK and FS_IOMAP, which is interesting. I need to understand the implications of that choice. I'm also reminded that mm/memory.c, mm/page-writeback.c, and mm/rmap.c are all foundational to the core Memory Management (MM) layer. I should make sure I understand how everything is working together in that area.

Since XFS is utilizing FS_IOMAP, I wonder if other filesystems are doing the same. It's time to dig deeper. I'll need to check if any other filesystems leverage iomap or specifically `dirty_folio_range`. A quick `grep` across the kernel source for `dirty_folio_range` should help me identify any other potential users of this functionality and how it's being used across the kernel. This broader context will give me a more complete picture.



8/2 2026/09/05 04:02 tool grepper
0m Args:
{
  "Expression": "dirty_folio_range"
}

Results:
{
  "Output": "fs/iomap/buffered-io.c=848=EXPORT_SYMBOL_GPL(iomap_invalidate_folio);\nfs/iomap/buffered-io.c-849-\nfs/iomap/buffered-io.c:850:bool iomap_dirty_folio_range(struct address_space *mapping, struct folio *folio,\nfs/iomap/buffered-io.c-851-\t\tsize_t off, size_t len)\n--\nfs/iomap/buffered-io.c-856-}\nfs/iomap/buffered-io.c:857:EXPORT_SYMBOL_GPL(iomap_dirty_folio_range);\nfs/iomap/buffered-io.c-858-\nfs/iomap/buffered-io.c=859=bool iomap_dirty_folio(struct address_space *mapping, struct folio *folio)\nfs/iomap/buffered-io.c-860-{\nfs/iomap/buffered-io.c:861:\treturn iomap_dirty_folio_range(mapping, folio, 0, folio_size(folio));\nfs/iomap/buffered-io.c-862-}\n--\nfs/xfs/xfs_aops.c=862=const struct address_space_operations xfs_address_space_operations = {\n--\nfs/xfs/xfs_aops.c-865-\t.writepages\t\t= xfs_vm_writepages,\nfs/xfs/xfs_aops.c:866:\t.dirty_folio_range\t= iomap_dirty_folio_range,\nfs/xfs/xfs_aops.c-867-\t.release_folio\t\t= iomap_release_folio,\n--\ninclude/linux/fs.h=401=struct address_space_operations {\n--\ninclude/linux/fs.h-409-\t/* Mark [off, off + len) of a folio dirty */\ninclude/linux/fs.h:410:\tbool (*dirty_folio_range)(struct address_space *mapping,\ninclude/linux/fs.h-411-\t\t\t\t  struct folio *folio, size_t off, size_t len);\n--\ninclude/linux/iomap.h=445=bool iomap_dirty_folio(struct address_space *mapping, struct folio *folio);\ninclude/linux/iomap.h:446:bool iomap_dirty_folio_range(struct address_space *mapping, struct folio *folio,\ninclude/linux/iomap.h-447-\t\tsize_t off, size_t len);\n--\nmm/memory.c=5649=static bool can_dirty_whole_batch(struct vm_fault *vmf, unsigned int nr,\n--\nmm/memory.c-5658-\nmm/memory.c:5659:\treturn !vma-\u003evm_file-\u003ef_mapping-\u003ea_ops-\u003edirty_folio_range;\nmm/memory.c-5660-}\n--\nmm/page-writeback.c=2752=EXPORT_SYMBOL(folio_redirty_for_writepage);\n--\nmm/page-writeback.c-2754-/*\nmm/page-writeback.c:2755: * Hand a dirtied range of @folio to the filesystem.  -\u003edirty_folio_range() can\nmm/page-writeback.c-2756- * express everything -\u003edirty_folio() can, so a filesystem that implements it\n--\nmm/page-writeback.c=2760=static bool mapping_dirty_range(struct address_space *mapping,\n--\nmm/page-writeback.c-2762-{\nmm/page-writeback.c:2763:\tif (!mapping-\u003ea_ops-\u003edirty_folio_range)\nmm/page-writeback.c-2764-\t\treturn mapping-\u003ea_ops-\u003edirty_folio(mapping, folio);\nmm/page-writeback.c-2765-\nmm/page-writeback.c:2766:\treturn mapping-\u003ea_ops-\u003edirty_folio_range(mapping, folio, off, len);\nmm/page-writeback.c-2767-}\n--\nmm/page-writeback.c=2886=EXPORT_SYMBOL(__folio_cancel_dirty);\n--\nmm/page-writeback.c-2891- *\nmm/page-writeback.c:2892: * Without -\u003edirty_folio_range() there is nowhere to put per-block state, so\nmm/page-writeback.c-2893- * any PTE dirty bit dirties the whole folio.  Same when the folio is not\n--\nmm/page-writeback.c=2898=static void folio_mkclean_for_io(struct folio *folio,\n--\nmm/page-writeback.c-2904-\nmm/page-writeback.c:2905:\tif (!mapping-\u003ea_ops-\u003edirty_folio_range || !folio_test_dirty(folio) ||\nmm/page-writeback.c-2906-\t    WARN_ON_ONCE(nr \u003e (1UL \u003c\u003c MAX_PAGECACHE_ORDER))) {\n"
}

9/2 2026/09/05 04:02 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 13426
							output: 201
							thoughts: 712
						

Thoughts:
**My Analysis of the Dirty Folio Range Implementation**

Okay, let's break this down. I'm focusing on the introduction of sub-folio range dirty tracking, specifically for filesystems like XFS that utilize iomap. My initial scan has identified a set of new and modified functions across `fs/iomap/buffered-io.c`, `mm/page-writeback.c`, `mm/rmap.c`, and `mm/memory.c`. I've categorized them based on their impact.

I've identified the key non-ubiquitous focus symbols I want to target. I'm avoiding the usual suspects like general allocators, page fault entry points, and core lock primitives, since those won't give me the specific code I'm after. I've specifically selected `iomap_dirty_folio_range`, `iomap_page_mkwrite`, `folio_mark_dirty_range`, `folio_mkclean_dirtymap`, and `folio_clear_dirty_for_io` as the core functions I want to focus on. These are the functions that will give me the most coverage of the newly introduced functionality.

I've checked the dependencies to see if I need to enable specific configurations for XFS to trigger the hooks I'm interested in. I know that `XFS_FS` will compile XFS and, importantly, also enable `FS_IOMAP`. I want to make sure I'm hitting the XFS code path.

Let's double-check all the requirements: the fuzzing is worth it, the configuration enables XFS, and I've got the correct `FocusSymbols` set to target the functions that reflect the core change.

The reasoning here is solid. The patch fundamentally changes how we track dirty sub-folio ranges. This is critical for supporting per-block dirty tracking on large folios, especially in filesystems like XFS which use iomap. This impacts everything from page fault handling, to shared page dirtying, to writeback transitions, and even rmap cleaning. That is exactly what I'm looking for - changes touching core memory management, iomap, and the XFS code path. This analysis looks good. Time to set-results.



10/2 2026/09/05 04:03 tool set-results
0m Args:
{
  "EnableConfigs": [
    "XFS_FS"
  ],
  "FocusSymbols": [
    "iomap_dirty_folio_range",
    "iomap_page_mkwrite",
    "folio_mark_dirty_range",
    "folio_mkclean_dirtymap",
    "folio_clear_dirty_for_io"
  ],
  "Reasoning": "The patch series introduces sub-folio range dirtying via -\u003edirty_folio_range, folio_mark_dirty_range(), folio_mkclean_dirtymap(), and iomap_dirty_folio_range() for XFS/iomap. It modifies core MM dirty folio tracking, write-protect/clean transitions in writeback (folio_clear_dirty_for_io), rmap PTE/PMD dirty walk, and page fault handling for shared mappings. These reachable MM and filesystem paths warrant fuzzing.",
  "WorthFuzzing": true
}

Results:
{
  "EnableConfigs": [
    "XFS_FS"
  ],
  "FocusSymbols": [
    "iomap_dirty_folio_range",
    "iomap_page_mkwrite",
    "folio_mark_dirty_range",
    "folio_mkclean_dirtymap",
    "folio_clear_dirty_for_io"
  ],
  "Reasoning": "The patch series introduces sub-folio range dirtying via -\u003edirty_folio_range, folio_mark_dirty_range(), folio_mkclean_dirtymap(), and iomap_dirty_folio_range() for XFS/iomap. It modifies core MM dirty folio tracking, write-protect/clean transitions in writeback (folio_clear_dirty_for_io), rmap PTE/PMD dirty walk, and page fault handling for shared mappings. These reachable MM and filesystem paths warrant fuzzing.",
  "WorthFuzzing": true
}

11/1 2026/09/05 04:03 action If
0m Args:
{
  "WorthFuzzing": true
}

Results:
null

12/2 2026/09/05 04:03 agent kmsan-evaluator
0m Model:
core

Args:
null

Results:
{
  "KMSANReasoning": "The patch introduces range-based dirty tracking for large folios in the memory management subsystem and iomap (specifically `dirty_folio_range`, `folio_mark_dirty_range`, and `folio_mkclean_dirtymap`).\n\n1. KMSAN applicability: The changes do not introduce or modify any data structures exposed or copied to user space, nor do they introduce uninitialized stack or heap variables. All new local variables (`dirty_off`, `dirty_len`, `state`, and stack bitmap `map` in `folio_mkclean_for_io`) are properly initialized before use (`bitmap_zero`, designated initializer, etc.). There are no info-leak or uninitialized memory read vectors.\n2. KASAN / standard detectors applicability: Potential bugs arising from range calculations, bitmask operations, or page table walks would be out-of-bounds accesses, assertions/locking issues, or logic errors, which are covered by KASAN, LOCKDEP, and existing kernel debug checks.\n\nTherefore, a dedicated KMSAN session is not warranted.",
  "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 0519b461c9b3fdecaa880e0c93b4da997751c1b2
Author: syz-cluster <triage@syzkaller.com>
Date:   Sat Sep 5 04:02:38 2026 +0000

    syz-cluster: applied patch under review

diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 0a5ebfda90f12..8d8a8acab01ac 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -847,15 +847,19 @@ void iomap_invalidate_folio(struct folio *folio, size_t offset, size_t len)
 }
 EXPORT_SYMBOL_GPL(iomap_invalidate_folio);
 
-bool iomap_dirty_folio(struct address_space *mapping, struct folio *folio)
+bool iomap_dirty_folio_range(struct address_space *mapping, struct folio *folio,
+		size_t off, size_t len)
 {
-	struct inode *inode = mapping->host;
-	size_t len = folio_size(folio);
-
-	ifs_alloc(inode, folio, 0);
-	iomap_set_range_dirty(folio, 0, len);
+	ifs_alloc(mapping->host, folio, 0);
+	iomap_set_range_dirty(folio, off, len);
 	return filemap_dirty_folio(mapping, folio);
 }
+EXPORT_SYMBOL_GPL(iomap_dirty_folio_range);
+
+bool iomap_dirty_folio(struct address_space *mapping, struct folio *folio)
+{
+	return iomap_dirty_folio_range(mapping, folio, 0, folio_size(folio));
+}
 EXPORT_SYMBOL_GPL(iomap_dirty_folio);
 
 static void
@@ -1804,7 +1808,7 @@ iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero,
 EXPORT_SYMBOL_GPL(iomap_truncate_page);
 
 static int iomap_folio_mkwrite_iter(struct iomap_iter *iter,
-		struct folio *folio)
+		struct folio *folio, size_t dirty_off, size_t dirty_len)
 {
 	loff_t length = iomap_length(iter);
 	int ret;
@@ -1817,7 +1821,7 @@ static int iomap_folio_mkwrite_iter(struct iomap_iter *iter,
 		block_commit_write(folio, 0, length);
 	} else {
 		WARN_ON_ONCE(!folio_test_uptodate(folio));
-		folio_mark_dirty(folio);
+		folio_mark_dirty_range(folio, dirty_off, dirty_len);
 	}
 
 	return iomap_iter_advance(iter, length);
@@ -1832,6 +1836,7 @@ vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops,
 		.private	= private,
 	};
 	struct folio *folio = page_folio(vmf->page);
+	size_t dirty_off, dirty_len;
 	ssize_t ret;
 
 	folio_lock(folio);
@@ -1840,8 +1845,22 @@ vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops,
 		goto out_unlock;
 	iter.pos = folio_pos(folio);
 	iter.len = ret;
+
+	/*
+	 * Blocks are still allocated for the whole folio, but only the page
+	 * the fault was for has been written, so that is all that has to be
+	 * written back.  A racing truncate can leave that page beyond i_size,
+	 * and then there is nothing to dirty.
+	 */
+	dirty_off = folio_page_idx(folio, vmf->page) << PAGE_SHIFT;
+	if (dirty_off < ret)
+		dirty_len = min_t(size_t, PAGE_SIZE, ret - dirty_off);
+	else
+		dirty_len = 0;
+
 	while ((ret = iomap_iter(&iter, ops)) > 0)
-		iter.status = iomap_folio_mkwrite_iter(&iter, folio);
+		iter.status = iomap_folio_mkwrite_iter(&iter, folio,
+						       dirty_off, dirty_len);
 
 	if (ret < 0)
 		goto out_unlock;
diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
index 74a6089abadf9..600e7de2e599c 100644
--- a/fs/xfs/xfs_aops.c
+++ b/fs/xfs/xfs_aops.c
@@ -863,7 +863,7 @@ const struct address_space_operations xfs_address_space_operations = {
 	.read_folio		= xfs_vm_read_folio,
 	.readahead		= xfs_vm_readahead,
 	.writepages		= xfs_vm_writepages,
-	.dirty_folio		= iomap_dirty_folio,
+	.dirty_folio_range	= iomap_dirty_folio_range,
 	.release_folio		= iomap_release_folio,
 	.invalidate_folio	= iomap_invalidate_folio,
 	.bmap			= xfs_vm_bmap,
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 072d8cd09a0b2..1d98b6c0b8804 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -406,6 +406,9 @@ struct address_space_operations {
 
 	/* Mark a folio dirty.  Return true if this dirtied it */
 	bool (*dirty_folio)(struct address_space *, struct folio *);
+	/* Mark [off, off + len) of a folio dirty */
+	bool (*dirty_folio_range)(struct address_space *mapping,
+				  struct folio *folio, size_t off, size_t len);
 
 	void (*readahead)(struct readahead_control *);
 
diff --git a/include/linux/iomap.h b/include/linux/iomap.h
index bc7ae6327dbf8..3cf2ac751409c 100644
--- a/include/linux/iomap.h
+++ b/include/linux/iomap.h
@@ -443,6 +443,8 @@ struct folio *iomap_get_folio(struct iomap_iter *iter, loff_t pos, size_t len);
 bool iomap_release_folio(struct folio *folio, gfp_t gfp_flags);
 void iomap_invalidate_folio(struct folio *folio, size_t offset, size_t len);
 bool iomap_dirty_folio(struct address_space *mapping, struct folio *folio);
+bool iomap_dirty_folio_range(struct address_space *mapping, struct folio *folio,
+		size_t off, size_t len);
 void iomap_folio_mark_uptodate(struct folio *folio);
 int iomap_file_unshare(struct inode *inode, loff_t pos, loff_t len,
 		const struct iomap_ops *ops,
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 87feaa5a2b780..7628262c17e14 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -3337,6 +3337,7 @@ struct kvec;
 struct page *get_dump_page(unsigned long addr, int *locked);
 
 bool folio_mark_dirty(struct folio *folio);
+bool folio_mark_dirty_range(struct folio *folio, size_t off, size_t len);
 bool folio_mark_dirty_lock(struct folio *folio);
 bool set_page_dirty(struct page *page);
 int set_page_dirty_lock(struct page *page);
diff --git a/include/linux/rmap.h b/include/linux/rmap.h
index 8dc0871e5f001..6fc0a60202527 100644
--- a/include/linux/rmap.h
+++ b/include/linux/rmap.h
@@ -927,6 +927,7 @@ unsigned long page_address_in_vma(const struct folio *folio,
  * returns the number of cleaned PTEs.
  */
 int folio_mkclean(struct folio *);
+int folio_mkclean_dirtymap(struct folio *folio, unsigned long *dirty_map);
 
 int mapping_wrprotect_range(struct address_space *mapping, pgoff_t pgoff,
 		unsigned long pfn, unsigned long nr_pages);
@@ -990,6 +991,12 @@ static inline int folio_mkclean(struct folio *folio)
 {
 	return 0;
 }
+
+static inline int folio_mkclean_dirtymap(struct folio *folio,
+					 unsigned long *dirty_map)
+{
+	return 0;
+}
 #endif	/* CONFIG_MMU */
 
 #endif	/* _LINUX_RMAP_H */
diff --git a/mm/memory.c b/mm/memory.c
index 8da0f945141b4..27a059e0c016f 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -3778,10 +3778,19 @@ static vm_fault_t fault_dirty_shared_page(struct vm_fault *vmf)
 	struct vm_area_struct *vma = vmf->vma;
 	struct address_space *mapping;
 	struct folio *folio = page_folio(vmf->page);
+	size_t off = folio_page_idx(folio, vmf->page) << PAGE_SHIFT;
 	bool dirtied;
 	bool page_mkwrite = vma->vm_ops && vma->vm_ops->page_mkwrite;
 
-	dirtied = folio_mark_dirty(folio);
+	/*
+	 * A PMD entry has one dirty bit for the whole folio, so there is no
+	 * finer information to pass on. A PTE-mapped folio only has the page
+	 * the fault was for dirtied so far.
+	 */
+	if (pmd_trans_huge(pmdp_get_lockless(vmf->pmd)))
+		dirtied = folio_mark_dirty(folio);
+	else
+		dirtied = folio_mark_dirty_range(folio, off, PAGE_SIZE);
 	VM_BUG_ON_FOLIO(folio_test_anon(folio), folio);
 	/*
 	 * Take a local copy of the address_space - folio.mapping may be zeroed
@@ -5625,6 +5634,31 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct folio *folio, struct page *pa
 }
 #endif
 
+/*
+ * May the whole batch be marked dirty?
+ *
+ * Only a shared mapping of a filesystem that tracks dirty state per block says
+ * no. There the page table dirty bits are the only record of which parts of a
+ * large folio were written through the mapping, so pages nobody has stored to
+ * have to stay clean and let the hardware set the bit on the first store.
+ *
+ * Everywhere else nothing ever reads those bits, and on hardware without a
+ * dirty bit leaving them clean costs a fault per page for nothing. That covers
+ * shmem, which has no dirty state below the folio.
+ */
+static bool can_dirty_whole_batch(struct vm_fault *vmf, unsigned int nr,
+				  bool prefault)
+{
+	struct vm_area_struct *vma = vmf->vma;
+
+	if (!(vmf->flags & FAULT_FLAG_WRITE) || prefault || nr == 1)
+		return true;
+	if (!(vma->vm_flags & VM_SHARED))
+		return true;
+
+	return !vma->vm_file->f_mapping->a_ops->dirty_folio_range;
+}
+
 /**
  * set_pte_range - Set a range of PTEs to point to pages in a folio.
  * @vmf: Fault description.
@@ -5639,6 +5673,7 @@ void set_pte_range(struct vm_fault *vmf, struct folio *folio,
 	struct vm_area_struct *vma = vmf->vma;
 	bool write = vmf->flags & FAULT_FLAG_WRITE;
 	bool prefault = !in_range(vmf->address, addr, nr * PAGE_SIZE);
+	bool dirty_batch = can_dirty_whole_batch(vmf, nr, prefault);
 	pte_t entry;
 
 	flush_icache_pages(vma, page, nr);
@@ -5649,10 +5684,13 @@ void set_pte_range(struct vm_fault *vmf, struct folio *folio,
 	else
 		entry = pte_sw_mkyoung(entry);
 
-	if (write)
-		entry = maybe_mkwrite(pte_mkdirty(entry), vma);
-	else if (pte_write(entry) && folio_test_dirty(folio))
+	if (write) {
+		if (dirty_batch)
+			entry = pte_mkdirty(entry);
+		entry = maybe_mkwrite(entry, vma);
+	} else if (pte_write(entry) && folio_test_dirty(folio)) {
 		entry = pte_mkdirty(entry);
+	}
 	if (unlikely(vmf_orig_pte_uffd_wp(vmf)))
 		entry = pte_mkuffd(entry);
 	/* copy-on-write page */
@@ -5665,6 +5703,18 @@ void set_pte_range(struct vm_fault *vmf, struct folio *folio,
 	}
 	set_ptes(vma->vm_mm, addr, vmf->pte, entry, nr);
 
+	/*
+	 * The page the fault was for is about to be stored to, so dirty it
+	 * here rather than leave the store to a second page table walk, or to
+	 * a second fault where the dirty bit is maintained in software.
+	 */
+	if (!dirty_batch) {
+		pte_t *ptep = vmf->pte + ((vmf->address - addr) >> PAGE_SHIFT);
+
+		ptep_set_access_flags(vma, vmf->address, ptep,
+				      pte_mkdirty(ptep_get(ptep)), 1);
+	}
+
 	/* no need to invalidate: a not-present page won't be cached */
 	update_mmu_cache_range(vmf, vma, addr, vmf->pte, nr);
 }
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 6c9c7ba89b8a9..39b54c25a9fab 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -2751,6 +2751,21 @@ bool folio_redirty_for_writepage(struct writeback_control *wbc,
 }
 EXPORT_SYMBOL(folio_redirty_for_writepage);
 
+/*
+ * Hand a dirtied range of @folio to the filesystem.  ->dirty_folio_range() can
+ * express everything ->dirty_folio() can, so a filesystem that implements it
+ * does not need both, and a whole-folio dirty comes through here as a range
+ * covering the folio.
+ */
+static bool mapping_dirty_range(struct address_space *mapping,
+				struct folio *folio, size_t off, size_t len)
+{
+	if (!mapping->a_ops->dirty_folio_range)
+		return mapping->a_ops->dirty_folio(mapping, folio);
+
+	return mapping->a_ops->dirty_folio_range(mapping, folio, off, len);
+}
+
 /**
  * folio_mark_dirty - Mark a folio as being modified.
  * @folio: The folio.
@@ -2782,13 +2797,39 @@ bool folio_mark_dirty(struct folio *folio)
 		 */
 		if (folio_test_reclaim(folio))
 			folio_clear_reclaim(folio);
-		return mapping->a_ops->dirty_folio(mapping, folio);
+		return mapping_dirty_range(mapping, folio, 0,
+					   folio_size(folio));
 	}
 
 	return noop_dirty_folio(mapping, folio);
 }
 EXPORT_SYMBOL(folio_mark_dirty);
 
+/**
+ * folio_mark_dirty_range - Mark part of a folio as being modified.
+ * @folio: The folio.
+ * @off: Offset of the modified range within the folio.
+ * @len: Length of the modified range.
+ *
+ * Like folio_mark_dirty(), but tells a filesystem that tracks dirty state per
+ * block that only [@off, @off + @len) changed, so writeback can skip the rest
+ * of the folio.  Filesystems without that tracking dirty the whole folio.
+ *
+ * Return: True if the folio was newly dirtied, false if it was already dirty.
+ */
+bool folio_mark_dirty_range(struct folio *folio, size_t off, size_t len)
+{
+	struct address_space *mapping = folio_mapping(folio);
+
+	if (likely(mapping)) {
+		if (folio_test_reclaim(folio))
+			folio_clear_reclaim(folio);
+		return mapping_dirty_range(mapping, folio, off, len);
+	}
+
+	return noop_dirty_folio(mapping, folio);
+}
+
 /*
  * folio_mark_dirty() is racy if the caller has no reference against
  * folio->mapping->host, and if the folio is unlocked.  This is because another
@@ -2844,6 +2885,41 @@ void __folio_cancel_dirty(struct folio *folio)
 }
 EXPORT_SYMBOL(__folio_cancel_dirty);
 
+/*
+ * Write-protect every mapping of @folio and hand the filesystem the parts that
+ * were dirty in a page table.
+ *
+ * Without ->dirty_folio_range() there is nowhere to put per-block state, so
+ * any PTE dirty bit dirties the whole folio.  Same when the folio is not
+ * already dirty, because then the dirty transition needs the full accounting
+ * in folio_mark_dirty(), and for a folio too large for the bitmap, which the
+ * page cache does not make.
+ */
+static void folio_mkclean_for_io(struct folio *folio,
+				 struct address_space *mapping)
+{
+	DECLARE_BITMAP(map, 1UL << MAX_PAGECACHE_ORDER);
+	unsigned int nr = folio_nr_pages(folio);
+	unsigned int start, end;
+
+	if (!mapping->a_ops->dirty_folio_range || !folio_test_dirty(folio) ||
+	    WARN_ON_ONCE(nr > (1UL << MAX_PAGECACHE_ORDER))) {
+		if (folio_mkclean(folio))
+			folio_mark_dirty(folio);
+		return;
+	}
+
+	bitmap_zero(map, nr);
+	if (!folio_mkclean_dirtymap(folio, map))
+		return;
+
+	for_each_set_bitrange(start, end, map, nr) {
+		mapping_dirty_range(mapping, folio,
+				    (size_t)start << PAGE_SHIFT,
+				    (size_t)(end - start) << PAGE_SHIFT);
+	}
+}
+
 /*
  * Clear a folio's dirty flag, while caring for dirty memory accounting.
  * Returns true if the folio was previously dirty.
@@ -2875,9 +2951,9 @@ bool folio_clear_dirty_for_io(struct folio *folio)
 		 *
 		 * We use this sequence to make sure that
 		 *  (a) we account for dirty stats properly
-		 *  (b) we tell the low-level filesystem to
-		 *      mark the whole folio dirty if it was
-		 *      dirty in a pagetable. Only to then
+		 *  (b) we tell the low-level filesystem which
+		 *      parts of the folio were dirty in a
+		 *      pagetable. Only to then
 		 *  (c) clean the folio again and return 1 to
 		 *      cause the writeback.
 		 *
@@ -2895,8 +2971,7 @@ bool folio_clear_dirty_for_io(struct folio *folio)
 		 * as a serialization point for all the different
 		 * threads doing their things.
 		 */
-		if (folio_mkclean(folio))
-			folio_mark_dirty(folio);
+		folio_mkclean_for_io(folio, mapping);
 		/*
 		 * We carefully synchronise fault handlers against
 		 * installing a dirty pte and marking the folio dirty
diff --git a/mm/rmap.c b/mm/rmap.c
index 1f72d279ba68f..aaf45ac79fa84 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1100,12 +1100,18 @@ int folio_referenced(struct folio *folio, int is_locked,
 	return rwc.contended ? -1 : pra.referenced;
 }
 
-static int page_vma_mkclean_one(struct page_vma_mapped_walk *pvmw)
+struct mkclean_state {
+	unsigned long *dirty_map;
+	int cleaned;
+};
+
+static int page_vma_mkclean_one(struct page_vma_mapped_walk *pvmw,
+				unsigned long *dirty_map)
 {
-	int cleaned = 0;
 	struct vm_area_struct *vma = pvmw->vma;
-	struct mmu_notifier_range range;
 	unsigned long address = pvmw->address;
+	struct mmu_notifier_range range;
+	int cleaned = 0;
 
 	/*
 	 * We have to assume the worse case ie pmd for invalidation. Note that
@@ -1134,6 +1140,15 @@ static int page_vma_mkclean_one(struct page_vma_mapped_walk *pvmw)
 			if (!pte_dirty(entry) && !pte_write(entry))
 				continue;
 
+			if (dirty_map && pte_dirty(entry)) {
+				pgoff_t idx = linear_page_index(vma, address) -
+					      pvmw->pgoff;
+
+				/* The walk only visits pages of this folio */
+				VM_WARN_ON_ONCE(idx >= pvmw->nr_pages);
+				__set_bit(idx, dirty_map);
+			}
+
 			flush_cache_page(vma, address, pte_pfn(entry));
 			entry = ptep_clear_flush(vma, address, pte);
 			entry = pte_wrprotect(entry);
@@ -1155,6 +1170,9 @@ static int page_vma_mkclean_one(struct page_vma_mapped_walk *pvmw)
 			if (!pmd_dirty(entry) && !pmd_write(entry))
 				continue;
 
+			if (dirty_map && pmd_dirty(entry))
+				bitmap_set(dirty_map, 0, pvmw->nr_pages);
+
 			flush_cache_range(vma, address,
 					  address + HPAGE_PMD_SIZE);
 			entry = pmdp_invalidate(vma, address, pmd);
@@ -1181,9 +1199,9 @@ static bool page_mkclean_one(struct folio *folio, struct vm_area_struct *vma,
 			     unsigned long address, void *arg)
 {
 	DEFINE_FOLIO_VMA_WALK(pvmw, folio, vma, address, PVMW_SYNC);
-	int *cleaned = arg;
+	struct mkclean_state *state = arg;
 
-	*cleaned += page_vma_mkclean_one(&pvmw);
+	state->cleaned += page_vma_mkclean_one(&pvmw, state->dirty_map);
 
 	return true;
 }
@@ -1196,12 +1214,23 @@ static bool invalid_mkclean_vma(struct vm_area_struct *vma, void *arg)
 	return true;
 }
 
-int folio_mkclean(struct folio *folio)
+/**
+ * folio_mkclean_dirtymap - Write-protect a folio and report what was dirty.
+ * @folio: The folio to clean.
+ * @dirty_map: Bitmap of at least folio_nr_pages(@folio) bits, or NULL.
+ *
+ * Write-protects and cleans every mapping of @folio.  With @dirty_map, sets a
+ * bit for each page whose entry was dirty; a PMD-mapped folio has one dirty
+ * bit for all of it, so every page is reported.
+ *
+ * Return: the number of page table entries cleaned.
+ */
+int folio_mkclean_dirtymap(struct folio *folio, unsigned long *dirty_map)
 {
-	int cleaned = 0;
+	struct mkclean_state state = { .dirty_map = dirty_map };
 	struct address_space *mapping;
 	struct rmap_walk_control rwc = {
-		.arg = (void *)&cleaned,
+		.arg = (void *)&state,
 		.rmap_one = page_mkclean_one,
 		.invalid_vma = invalid_mkclean_vma,
 	};
@@ -1217,7 +1246,12 @@ int folio_mkclean(struct folio *folio)
 
 	rmap_walk(folio, &rwc);
 
-	return cleaned;
+	return state.cleaned;
+}
+
+int folio_mkclean(struct folio *folio)
+{
+	return folio_mkclean_dirtymap(folio, NULL);
 }
 EXPORT_SYMBOL_GPL(folio_mkclean);
 
@@ -1241,7 +1275,7 @@ static bool mapping_wrprotect_range_one(struct folio *folio,
 		.flags		= PVMW_SYNC,
 	};
 
-	state->cleaned += page_vma_mkclean_one(&pvmw);
+	state->cleaned += page_vma_mkclean_one(&pvmw, NULL);
 
 	return true;
 }
@@ -1324,7 +1358,7 @@ int pfn_mkclean_range(unsigned long pfn, unsigned long nr_pages, pgoff_t pgoff,
 	pvmw.address = vma_address(vma, pgoff, nr_pages);
 	VM_BUG_ON_VMA(pvmw.address == -EFAULT, vma);
 
-	return page_vma_mkclean_one(&pvmw);
+	return page_vma_mkclean_one(&pvmw, NULL);
 }
 
 static void __folio_mod_stat(struct folio *folio, int nr, int nr_pmdmapped)

13/3 2026/09/05 04:03 llm kmsan-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 8950
							output: 19
							thoughts: 1049
						

Thoughts:
**Analyzing the Sub-Folio Dirty Tracking Implementation**

Okay, let's dive into this patch series. My initial assessment is that it aims to introduce granular tracking of dirty data within large folios, going beyond the traditional folio-level dirty flag. This looks like a necessary optimization for modern storage systems and should lead to more efficient writeback and caching behavior.

Here's my understanding, as I read through the changes.  It's an interesting approach, implementing `dirty_folio_range` within the `address_space_operations`. The main idea seems to be to introduce a mechanism, `iomap_dirty_folio_range`, and use it to track dirty regions within a folio, which is particularly relevant for handling larger folios.

Specifically, it looks like:

*   `iomap_dirty_folio_range` is introduced and called by `iomap_dirty_folio`. This suggests a clear delegation of the dirty range management to the new function. Modifications in `iomap_folio_mkwrite_iter` and `iomap_page_mkwrite` seem to be the primary consumers.
*   The `xfs` filesystem is updated to use the new functionality, which indicates a real-world application.
*   Function pointers are added to the `address_space_operations` struct, and relevant declarations are included.
*   The `mm` code now uses the `dirty_folio_range` function in several places, including `fault_dirty_shared_page`, `can_dirty_whole_batch`, `set_pte_range`, `mapping_dirty_range`, `folio_mark_dirty`, and `folio_mark_dirty_range`. This is where the core logic of the sub-folio dirty tracking is implemented.
*   `folio_mkclean_for_io` is particularly interesting. It appears to utilize a bitmap (`map`) to represent the dirty state of individual pages within a folio, which seems to be the key to the sub-folio tracking. I wonder about its usage and potential for issues.
*   `mm/rmap.c` introduces `struct mkclean_state` and related functions. This structure seems designed to facilitate cleaning and potentially unmapping pages or sub-page regions.

Now, let me zoom in on a potential area of concern. The use of a bitmap in `folio_mkclean_for_io` raises a question. Specifically, I'm interested in the initialization and usage of the `map` bitmap.

```c
    DECLARE_BITMAP(map, 1UL << MAX_PAGECACHE_ORDER);
    unsigned int nr = folio_nr_pages(folio);
    unsigned int start, end;

    if (!mapping->a_ops->dirty_folio_range || !folio_test_dirty(folio) ||
        WARN_ON_ONCE(nr > (1UL << MAX_PAGECACHE_ORDER))) {
        if (folio_mkclean(folio))
            folio_mark_dirty(folio);
        return;
    }

    bitmap_zero(map, nr);
    if (!folio_mkclean_dirtymap(folio, map))
        return;

    for_each_set_bitrange(start, end, map, nr) {
        mapping_dirty_range(mapping, folio,
                            (size_t)start << PAGE_SHIFT,
                            (size_t)(end - start) << PAGE_SHIFT);
    }
```

The code zeroes `nr` bits of the `map`. The loop `for_each_set_bitrange(start, end, map, nr)` iterates over the set bits within the `map`. It seems to me that `bitmap_zero` clears `map` for `nr` pages, and the loop uses the cleared `map`. The use of `nr` should bound the bitmap, and prevent out-of-bounds access. The code relies on the correct operation of the bitmap routines.
Let's make sure the bitmap access within `for_each_set_bitrange` respects the bounds set by `nr`.



14/3 2026/09/05 04:03 tool grepper
0m Error:
no matches

Args:
{
  "Expression": "#define bitmap_zero"
}

Results:
{
  "error": "no matches"
}

15/3 2026/09/05 04:03 llm kmsan-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 10912
							output: 33
							thoughts: 17
						

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

**Hunting Down `bitmap_zero`**

Okay, so I need to track down the definition of `bitmap_zero`. Given its function, it's pretty clear this is going to be related to bit manipulation within the kernel. My initial instinct is to go straight to `include/linux/bitmap.h`. That's where I'd expect to find the core bitmap manipulation macros and functions. It's the logical place to start digging, and hopefully, I'll find its definition or at least related utility functions there. I'm assuming it's implemented as a macro, but I won't rule out the possibility of it being a static inline function. Regardless, `bitmap.h` is where I'll get the details on how it actually does its job.



16/3 2026/09/05 04:03 tool grepper
0m Error:
no matches

Args:
{
  "Expression": "static inline void bitmap_zero",
  "PathPrefix": "include/linux/bitmap.h"
}

Results:
{
  "error": "no matches"
}

17/3 2026/09/05 04:03 llm kmsan-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 11157
							output: 30
							thoughts: 20
						

Thoughts:
Here's my take on those thoughts:

**Time to Investigate `bitmap_zero`**

Okay, so I'm thinking I need to find out more about how `bitmap_zero` is defined or used within the Linux kernel. Given the context, my initial instinct is to check the standard header file for bitmap definitions. I'm going to start by grepping the `include/linux/bitmap.h` file. That seems like the most logical place to begin, given that it's a core data structure and utility. I'm assuming that should yield a quick result with the relevant definitions or usages. Hopefully it's straightforward. Let's get to it!



18/3 2026/09/05 04:03 tool grepper
0m Args:
{
  "Expression": "bitmap_zero",
  "PathPrefix": "include/linux/bitmap.h"
}

Results:
{
  "Output": "include/linux/bitmap.h=17=struct device;\n--\ninclude/linux/bitmap.h-42- *\ninclude/linux/bitmap.h:43: *  bitmap_zero(dst, nbits)                     *dst = 0UL\ninclude/linux/bitmap.h-44- *  bitmap_fill(dst, nbits)                     *dst = ~0UL\n--\ninclude/linux/bitmap.h-93- *\ninclude/linux/bitmap.h:94: * Note, bitmap_zero() and bitmap_fill() operate over the region of\ninclude/linux/bitmap.h-95- * unsigned longs, that is, bits behind bitmap till the unsigned long\n--\ninclude/linux/bitmap.h=233=void bitmap_fold(unsigned long *dst, const unsigned long *orig,\n--\ninclude/linux/bitmap.h-240-\ninclude/linux/bitmap.h:241:static __always_inline void bitmap_zero(unsigned long *dst, unsigned int nbits)\ninclude/linux/bitmap.h-242-{\n--\ninclude/linux/bitmap.h=634=void bitmap_scatter(unsigned long *dst, const unsigned long *src,\n--\ninclude/linux/bitmap.h-639-\ninclude/linux/bitmap.h:640:\tbitmap_zero(dst, nbits);\ninclude/linux/bitmap.h-641-\n--\ninclude/linux/bitmap.h=691=void bitmap_gather(unsigned long *dst, const unsigned long *src,\n--\ninclude/linux/bitmap.h-696-\ninclude/linux/bitmap.h:697:\tbitmap_zero(dst, nbits);\ninclude/linux/bitmap.h-698-\n"
}

19/3 2026/09/05 04:03 llm kmsan-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 11778
							output: 35
							thoughts: 20
						

Thoughts:
Here's my summary, as though I'm thinking through this process:

**Diving into the Bitmap Header**

Okay, so I need to understand how these bitmaps are being handled. Let's zero in on the `include/linux/bitmap.h` header file. It's a fundamental part of the kernel's bit manipulation routines, so understanding the core data structures and macros in this header is essential for, well, pretty much anything. I'm going to navigate directly to the vicinity of line 240, as a starting point. That seems to be a reasonable place to jump in and get a sense of the context of bit operations. From there, I'll branch out to see how the code around that point is impacting the operations.



20/3 2026/09/05 04:03 tool read-file
0m Args:
{
  "File": "include/linux/bitmap.h",
  "FirstLine": 240,
  "LineCount": 20
}

Results:
{
  "Contents": " 240:\t\n 241:\tstatic __always_inline void bitmap_zero(unsigned long *dst, unsigned int nbits)\n 242:\t{\n 243:\t\tunsigned int len = bitmap_size(nbits);\n 244:\t\n 245:\t\tif (small_const_nbits(nbits))\n 246:\t\t\t*dst = 0;\n 247:\t\telse\n 248:\t\t\tmemset(dst, 0, len);\n 249:\t}\n 250:\t\n 251:\tstatic __always_inline void bitmap_fill(unsigned long *dst, unsigned int nbits)\n 252:\t{\n 253:\t\tunsigned int len = bitmap_size(nbits);\n 254:\t\n 255:\t\tif (small_const_nbits(nbits))\n 256:\t\t\t*dst = ~0UL;\n 257:\t\telse\n 258:\t\t\tmemset(dst, 0xff, len);\n 259:\t}\n"
}

21/3 2026/09/05 04:03 llm kmsan-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 12270
							output: 246
							thoughts: 1116
						

Thoughts:
**KMSAN Assessment: No Need for KMSAN**

Okay, let's break this down. My initial assessment starts with the core functionality. `bitmap_size` calculates the required memory for the bitmap, ensuring we're allocating enough space. The `for_each_set_bitrange` function is appropriately constrained to the relevant portion of the bitmap, given that it's using the correct calculations. Therefore, the `map` variable is properly initialized.

Next, I examined the `folio_mkclean_dirtymap` function and the initialization of the `state` struct. `state.cleaned` is initialized to zero, which is essential for tracking cleaned pages.

Then, the focus shifts to `iomap_page_mkwrite`. Here, `dirty_off` and `dirty_len` are calculated and fully initialized before they are ever used. This looks solid. The code is careful to handle the range within the page correctly, accounting for potential racing truncates. The logic seems robust.

Now, let's consider the broader implications of the patch. This patch optimizes writeback and dirty page tracking for large folios within XFS/iomap. Instead of marking the entire folio dirty, it tracks per-page dirty state and passes a specific range to the filesystem's callbacks, which updates the iomap sub-page/sub-folio dirty state.

I've carefully considered potential KMSAN concerns:

1.  **User-Space Interactions:** Are kernel structures exposed to userspace? No. This is internal MM and filesystem dirty tracking, so there are no copy-to-user operations or anything like that.
2.  **Uninitialized Variables:** Are there conditions or branches that depend on uninitialized variables? No. All variables, like `dirty_off`, `dirty_len`, `state`, and `map` are properly initialized.
3.  **Complex Data Structures:** Is there allocation or initialization of complex data structures where uninitialized fields could be read later? No. `ifs_alloc` is called before, and the data is allocated correctly.
4.  **Buffer Handling:** Are there bounds checks or logic that could lead to uninitialized bytes being accessed? No. The folio data and buffers are not exposed to userspace without initialization.

Given the KMSAN guidelines, the answer is no. This patch doesn't introduce or expose any new risks of uninitialized memory being read. Standard KASAN checks, LOCKDEP, and other bug detectors would likely catch any memory safety issues like out-of-bounds accesses. The potential bugs in this patch are more likely logic bugs related to range calculations, locking issues, or race conditions in memory management/writeback, which can be caught via testing or debugging.

Therefore, **NeedsKMSAN is definitely false.** I'm ready to prepare the reasoning and call `set-results`.



22/3 2026/09/05 04:03 tool set-results
0m Args:
{
  "KMSANReasoning": "The patch introduces range-based dirty tracking for large folios in the memory management subsystem and iomap (specifically `dirty_folio_range`, `folio_mark_dirty_range`, and `folio_mkclean_dirtymap`).\n\n1. KMSAN applicability: The changes do not introduce or modify any data structures exposed or copied to user space, nor do they introduce uninitialized stack or heap variables. All new local variables (`dirty_off`, `dirty_len`, `state`, and stack bitmap `map` in `folio_mkclean_for_io`) are properly initialized before use (`bitmap_zero`, designated initializer, etc.). There are no info-leak or uninitialized memory read vectors.\n2. KASAN / standard detectors applicability: Potential bugs arising from range calculations, bitmask operations, or page table walks would be out-of-bounds accesses, assertions/locking issues, or logic errors, which are covered by KASAN, LOCKDEP, and existing kernel debug checks.\n\nTherefore, a dedicated KMSAN session is not warranted.",
  "NeedsKMSAN": false
}

Results:
{
  "KMSANReasoning": "The patch introduces range-based dirty tracking for large folios in the memory management subsystem and iomap (specifically `dirty_folio_range`, `folio_mark_dirty_range`, and `folio_mkclean_dirtymap`).\n\n1. KMSAN applicability: The changes do not introduce or modify any data structures exposed or copied to user space, nor do they introduce uninitialized stack or heap variables. All new local variables (`dirty_off`, `dirty_len`, `state`, and stack bitmap `map` in `folio_mkclean_for_io`) are properly initialized before use (`bitmap_zero`, designated initializer, etc.). There are no info-leak or uninitialized memory read vectors.\n2. KASAN / standard detectors applicability: Potential bugs arising from range calculations, bitmask operations, or page table walks would be out-of-bounds accesses, assertions/locking issues, or logic errors, which are covered by KASAN, LOCKDEP, and existing kernel debug checks.\n\nTherefore, a dedicated KMSAN session is not warranted.",
  "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)