| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/09/26 18:21 | flow | patch-triage |
1mArgs:null Results: {
"EnableConfigs": [
"SWAP",
"TRANSPARENT_HUGEPAGE"
],
"FocusSymbols": [
"try_to_unmap_one",
"try_to_unmap",
"folio_dup_swap_pages",
"folio_put_swap_pages",
"cond_install_uffd_wp_ptes"
],
"KMSANReasoning": "The patch series optimizes anonymous folio handling by introducing PTE batching for unmapping, swap entry operations, and anon rmap sharing of swap-backed anonymous folios across contiguous pages.\n\nKMSAN vs KASAN Applicability:\n- KMSAN detects reads of uninitialized memory and information leaks to user space. This patch does not introduce any copy-to-user paths, socket/netlink/ioctl interfaces, or uninitialized stack/heap allocations. All local variables and PTE calculations are fully and explicitly initialized before use.\n- KASAN and standard kernel debug facilities (such as page table checks, VM_BUG_ON/VM_WARN_ON, and refcount tracking) are the appropriate tools to catch the risks associated with this patch, which include incorrect PTE values, swap count / folio refcount imbalances, potential use-after-free, or out-of-bounds folio page indexing.\n\nSince there are no uninitialized memory risks or kernel-to-user info-leaks, a dedicated KMSAN fuzzing session is not justified.",
"NeedsKMSAN": false,
"Reasoning": "The patch series adds batch unmapping for large anonymous swap-backed folios in core mm (mm/rmap.c), introduces new range-based swap counting functions (folio_dup_swap_pages, folio_put_swap_pages), and adds new runtime assertions (VM_WARN_ON_FOLIO). These changes alter reachable core memory management and swap handling paths on amd64 during folio unmapping and memory reclaim.",
"WorthFuzzing": true
} |
| 1/1 | 2026/09/26 18:21 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit b2dccc03952d04d8e09ed125e1fd46bbfff58bf0\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Sat Sep 26 18:21:06 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/arch/sparc/include/asm/pgtable_64.h b/arch/sparc/include/asm/pgtable_64.h\nindex 44d1333065a6a..f7dd1872884e4 100644\n--- a/arch/sparc/include/asm/pgtable_64.h\n+++ b/arch/sparc/include/asm/pgtable_64.h\n@@ -1037,6 +1037,9 @@ void adi_restore_tags(struct mm_struct *mm, struct vm_area_struct *vma,\n int adi_save_tags(struct mm_struct *mm, struct vm_area_struct *vma,\n \t\t unsigned long addr, pte_t oldpte);\n \n+int adi_save_tags_range(struct mm_struct *mm, struct vm_area_struct *vma,\n+\t\t\tunsigned long addr, pte_t oldpte, unsigned long nr);\n+\n #define __HAVE_ARCH_DO_SWAP_PAGE\n static inline void arch_do_swap_page(struct mm_struct *mm,\n \t\t\t\t struct vm_area_struct *vma,\n@@ -1057,10 +1060,11 @@ static inline void arch_do_swap_page(struct mm_struct *mm,\n #define __HAVE_ARCH_UNMAP_ONE\n static inline int arch_unmap_one(struct mm_struct *mm,\n \t\t\t\t struct vm_area_struct *vma,\n-\t\t\t\t unsigned long addr, pte_t oldpte)\n+\t\t\t\t unsigned long addr, pte_t oldpte,\n+\t\t\t\t unsigned long nr)\n {\n-\tif (adi_state.enabled \u0026\u0026 (pte_val(oldpte) \u0026 _PAGE_MCD_4V))\n-\t\treturn adi_save_tags(mm, vma, addr, oldpte);\n+\tif (adi_state.enabled)\n+\t\treturn adi_save_tags_range(mm, vma, addr, oldpte, nr);\n \treturn 0;\n }\n \ndiff --git a/arch/sparc/kernel/adi_64.c b/arch/sparc/kernel/adi_64.c\nindex 18036a43cf568..ffa378accefe3 100644\n--- a/arch/sparc/kernel/adi_64.c\n+++ b/arch/sparc/kernel/adi_64.c\n@@ -9,6 +9,7 @@\n #include \u003clinux/init.h\u003e\n #include \u003clinux/slab.h\u003e\n #include \u003clinux/mm_types.h\u003e\n+#include \u003clinux/pgtable.h\u003e\n #include \u003casm/mdesc.h\u003e\n #include \u003casm/adi_64.h\u003e\n #include \u003casm/mmu_64.h\u003e\n@@ -394,3 +395,23 @@ int adi_save_tags(struct mm_struct *mm, struct vm_area_struct *vma,\n \n \treturn 0;\n }\n+\n+int adi_save_tags_range(struct mm_struct *mm, struct vm_area_struct *vma,\n+\t\t\tunsigned long addr, pte_t oldpte, unsigned long nr)\n+{\n+\tunsigned long i;\n+\n+\tfor (i = 0; i \u003c nr; i++, addr += PAGE_SIZE,\n+\t oldpte = pte_next_pfn(oldpte)) {\n+\t\tint ret;\n+\n+\t\tif (!(pte_val(oldpte) \u0026 _PAGE_MCD_4V))\n+\t\t\tcontinue;\n+\n+\t\tret = adi_save_tags(mm, vma, addr, oldpte);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\t}\n+\n+\treturn 0;\n+}\ndiff --git a/include/linux/pgtable.h b/include/linux/pgtable.h\nindex 780fe849ff8b7..9c04bf3d0c04e 100644\n--- a/include/linux/pgtable.h\n+++ b/include/linux/pgtable.h\n@@ -1431,12 +1431,12 @@ static inline void arch_do_swap_page_nr(struct mm_struct *mm,\n * restored when the page is swapped back in. SPARC M7 and newer\n * processors support an ADI (Application Data Integrity) tag for the\n * page as metadata for the page. arch_unmap_one() can save this\n- * metadata on a swap-out of a page.\n+ * metadata on swap-out of one or more pages.\n */\n static inline int arch_unmap_one(struct mm_struct *mm,\n \t\t\t\t struct vm_area_struct *vma,\n-\t\t\t\t unsigned long addr,\n-\t\t\t\t pte_t orig_pte)\n+\t\t\t\t unsigned long addr, pte_t orig_pte,\n+\t\t\t\t unsigned long nr)\n {\n \treturn 0;\n }\ndiff --git a/include/linux/rmap.h b/include/linux/rmap.h\nindex 74cca0e3c7264..91b5763ef466f 100644\n--- a/include/linux/rmap.h\n+++ b/include/linux/rmap.h\n@@ -106,6 +106,23 @@ enum ttu_flags {\n \n #ifdef CONFIG_MMU\n \n+/*\n+ * Get max length of consecutive PTEs pointing to PageAnonExclusive() pages or\n+ * !PageAnonExclusive() pages, starting from start_idx. Caller must enforce\n+ * that the PTEs point to consecutive pages of the same anon large folio.\n+ */\n+static __always_inline unsigned long page_anon_exclusive_batch(unsigned long start_idx,\n+\t\tunsigned long max_len, struct page *first_page, bool anon_exclusive)\n+{\n+\tunsigned long idx;\n+\n+\tfor (idx = start_idx + 1; idx \u003c start_idx + max_len; ++idx) {\n+\t\tif (anon_exclusive != PageAnonExclusive(first_page + idx))\n+\t\t\tbreak;\n+\t}\n+\treturn idx - start_idx;\n+}\n+\n void anon_vma_init(void);\t/* create anon_vma_cachep */\n \n #ifdef CONFIG_MM_ID\n@@ -706,17 +723,23 @@ static inline int folio_try_dup_anon_rmap_pmd(struct folio *folio,\n }\n \n static __always_inline int __folio_try_share_anon_rmap(struct folio *folio,\n-\t\tstruct page *page, int nr_pages, enum pgtable_level level)\n+\t\tstruct page *page, unsigned long nr_pages, enum pgtable_level level)\n {\n+\t/* device private folios cannot get pinned via GUP. */\n+\tconst bool pinnable = !folio_is_device_private(folio);\n+\n \tVM_WARN_ON_FOLIO(!folio_test_anon(folio), folio);\n \tVM_WARN_ON_FOLIO(!PageAnonExclusive(page), folio);\n+\n \t__folio_rmap_sanity_checks(folio, page, nr_pages, level);\n \n-\t/* device private folios cannot get pinned via GUP. */\n-\tif (unlikely(folio_is_device_private(folio))) {\n-\t\tClearPageAnonExclusive(page);\n-\t\treturn 0;\n-\t}\n+\tVM_WARN_ON_ONCE(level != PGTABLE_LEVEL_PTE \u0026\u0026 level != PGTABLE_LEVEL_PMD);\n+\n+\t/* We only clear anon-exclusive from head page of PMD folio. */\n+\tif (level == PGTABLE_LEVEL_PMD)\n+\t\tnr_pages = 1;\n+\n+\tVM_WARN_ON_FOLIO(page_anon_exclusive_batch(0, nr_pages, page, true) != nr_pages, folio);\n \n \t/*\n \t * We have to make sure that when we clear PageAnonExclusive, that\n@@ -760,29 +783,38 @@ static __always_inline int __folio_try_share_anon_rmap(struct folio *folio,\n \t * so we use explicit ones here.\n \t */\n \n-\t/* Paired with the memory barrier in try_grab_folio(). */\n-\tif (IS_ENABLED(CONFIG_HAVE_GUP_FAST))\n-\t\tsmp_mb();\n+\tif (likely(pinnable)) {\n+\t\t/* Paired with the memory barrier in try_grab_folio(). */\n+\t\tif (IS_ENABLED(CONFIG_HAVE_GUP_FAST))\n+\t\t\tsmp_mb();\n \n-\tif (unlikely(folio_maybe_dma_pinned(folio)))\n-\t\treturn -EBUSY;\n-\tClearPageAnonExclusive(page);\n+\t\tif (unlikely(folio_maybe_dma_pinned(folio)))\n+\t\t\treturn -EBUSY;\n+\t}\n+\n+\tfor (;;) {\n+\t\tClearPageAnonExclusive(page);\n+\t\tif (--nr_pages == 0)\n+\t\t\tbreak;\n+\t\tpage++;\n+\t}\n \n \t/*\n \t * This is conceptually a smp_wmb() paired with the smp_rmb() in\n \t * gup_must_unshare().\n \t */\n-\tif (IS_ENABLED(CONFIG_HAVE_GUP_FAST))\n+\tif (likely(pinnable) \u0026\u0026 IS_ENABLED(CONFIG_HAVE_GUP_FAST))\n \t\tsmp_mb__after_atomic();\n \treturn 0;\n }\n \n /**\n- * folio_try_share_anon_rmap_pte - try marking an exclusive anonymous page\n- *\t\t\t\t mapped by a PTE possibly shared to prepare\n+ * folio_try_share_anon_rmap_ptes - try marking exclusive anonymous pages\n+ *\t\t\t\t mapped by PTEs possibly shared to prepare\n *\t\t\t\t for KSM or temporary unmapping\n * @folio:\tThe folio to share a mapping of\n- * @page:\tThe mapped exclusive page\n+ * @page:\tThe first mapped exclusive page of the batch in the folio\n+ * @nr_pages:\tThe number of pages to share in the folio (batch size)\n *\n * The caller needs to hold the page table lock and has to have the page table\n * entries cleared/invalidated.\n@@ -798,10 +830,17 @@ static __always_inline int __folio_try_share_anon_rmap(struct folio *folio,\n * Returns 0 if marking the mapped page possibly shared succeeded. Returns\n * -EBUSY otherwise.\n */\n+static inline int folio_try_share_anon_rmap_ptes(struct folio *folio,\n+\t\tstruct page *page, unsigned long nr_pages)\n+{\n+\treturn __folio_try_share_anon_rmap(folio, page, nr_pages,\n+\t\t\t\t\t PGTABLE_LEVEL_PTE);\n+}\n+\n static inline int folio_try_share_anon_rmap_pte(struct folio *folio,\n \t\tstruct page *page)\n {\n-\treturn __folio_try_share_anon_rmap(folio, page, 1, PGTABLE_LEVEL_PTE);\n+\treturn folio_try_share_anon_rmap_ptes(folio, page, 1);\n }\n \n /**\ndiff --git a/mm/internal.h b/mm/internal.h\nindex 0434dfcfc36f1..7e7afcd93b33c 100644\n--- a/mm/internal.h\n+++ b/mm/internal.h\n@@ -469,16 +469,16 @@ unsigned int folio_pte_batch(struct folio *folio, pte_t *ptep, pte_t pte,\n \t\tunsigned int max_nr);\n \n /**\n- * pte_move_swp_offset - Move the swap entry offset field of a swap pte\n- *\t forward or backward by delta\n- * @pte: The initial pte state; must be a swap entry\n+ * pte_move_softleaf_offset - Move the softleaf entry offset field of a\n+ * softleaf pte forward or backward by delta\n+ * @pte: The initial pte state; must be a softleaf entry\n * @delta: The direction and the offset we are moving; forward if delta\n *\t is positive; backward if delta is negative\n *\n- * Moves the swap offset, while maintaining all other fields, including\n- * swap type, and any swp pte bits. The resulting pte is returned.\n+ * Moves the softleaf offset, while maintaining all other fields, including\n+ * softleaf type, and any softleaf pte bits. The resulting pte is returned.\n */\n-static inline pte_t pte_move_swp_offset(pte_t pte, long delta)\n+static inline pte_t pte_move_softleaf_offset(pte_t pte, long delta)\n {\n \tconst softleaf_t entry = softleaf_from_pte(pte);\n \tpte_t new = __swp_entry_to_pte(__swp_entry(swp_type(entry),\n@@ -486,7 +486,7 @@ static inline pte_t pte_move_swp_offset(pte_t pte, long delta)\n \n \tif (pte_swp_soft_dirty(pte))\n \t\tnew = pte_swp_mksoft_dirty(new);\n-\tif (pte_swp_exclusive(pte))\n+\tif (softleaf_is_swap(entry) \u0026\u0026 pte_swp_exclusive(pte))\n \t\tnew = pte_swp_mkexclusive(new);\n \tif (pte_swp_uffd(pte))\n \t\tnew = pte_swp_mkuffd(new);\n@@ -496,15 +496,49 @@ static inline pte_t pte_move_swp_offset(pte_t pte, long delta)\n \n \n /**\n- * pte_next_swp_offset - Increment the swap entry offset field of a swap pte.\n- * @pte: The initial pte state; must be a swap entry.\n+ * pte_next_softleaf_offset - Increment the softleaf entry offset field of a\n+ * non-present pte.\n+ * @pte: The initial pte state; must be a softleaf entry.\n *\n- * Increments the swap offset, while maintaining all other fields, including\n- * swap type, and any swp pte bits. The resulting pte is returned.\n+ * Increments the softleaf offset, while maintaining all other fields, including\n+ * softleaf type, and any softleaf pte bits. The resulting pte is returned.\n */\n-static inline pte_t pte_next_swp_offset(pte_t pte)\n+static inline pte_t pte_next_softleaf_offset(pte_t pte)\n {\n-\treturn pte_move_swp_offset(pte, 1);\n+\treturn pte_move_softleaf_offset(pte, 1);\n+}\n+\n+/**\n+ * set_softleaf_ptes - Set consecutive softleaf PTEs.\n+ * @mm: Address space the PTEs belong to.\n+ * @addr: Address of the first PTE.\n+ * @ptep: Page table pointer for the first PTE.\n+ * @pte: PTE to set for the first entry.\n+ * @nr: Number of PTEs to set.\n+ *\n+ * Install @nr softleaf PTEs, advancing @pte when its softleaf entry\n+ * represents consecutive offsets. Swap entries advance through swap offsets,\n+ * PFN softleaf entries advance through PFNs (encoded by swap offset), and\n+ * marker entries are repeated unchanged.\n+ */\n+static inline void set_softleaf_ptes(struct mm_struct *mm, unsigned long addr,\n+\t\tpte_t *ptep, pte_t pte, unsigned long nr)\n+{\n+\tsoftleaf_t entry;\n+\tbool advance;\n+\n+\tentry = softleaf_from_pte(pte);\n+\tadvance = softleaf_is_swap(entry) || softleaf_has_pfn(entry);\n+\n+\tfor (;;) {\n+\t\tset_pte_at(mm, addr, ptep, pte);\n+\t\tif (--nr == 0)\n+\t\t\tbreak;\n+\t\tif (advance)\n+\t\t\tpte = pte_next_softleaf_offset(pte);\n+\t\tptep++;\n+\t\taddr += PAGE_SIZE;\n+\t}\n }\n \n /**\n@@ -524,7 +558,7 @@ static inline pte_t pte_next_swp_offset(pte_t pte)\n */\n static inline int swap_pte_batch(pte_t *start_ptep, int max_nr, pte_t pte)\n {\n-\tpte_t expected_pte = pte_next_swp_offset(pte);\n+\tpte_t expected_pte = pte_next_softleaf_offset(pte);\n \tconst pte_t *end_ptep = start_ptep + max_nr;\n \tpte_t *ptep = start_ptep + 1;\n \n@@ -536,7 +570,7 @@ static inline int swap_pte_batch(pte_t *start_ptep, int max_nr, pte_t pte)\n \n \t\tif (!pte_same(pte, expected_pte))\n \t\t\tbreak;\n-\t\texpected_pte = pte_next_swp_offset(expected_pte);\n+\t\texpected_pte = pte_next_softleaf_offset(expected_pte);\n \t\tptep++;\n \t}\n \ndiff --git a/mm/memory.c b/mm/memory.c\nindex 330cde31bf8b4..985a884b68008 100644\n--- a/mm/memory.c\n+++ b/mm/memory.c\n@@ -1700,14 +1700,8 @@ bool cond_install_uffd_wp_ptes(struct vm_area_struct *vma,\n \tif (likely(!arm_uffd_pte))\n \t\treturn false;\n \n-\tfor (;;) {\n-\t\tset_pte_at(vma-\u003evm_mm, addr, ptep,\n-\t\t\t make_pte_marker(PTE_MARKER_UFFD_WP));\n-\t\tif (--nr_ptes == 0)\n-\t\t\tbreak;\n-\t\tptep++;\n-\t\taddr += PAGE_SIZE;\n-\t}\n+\tset_softleaf_ptes(vma-\u003evm_mm, addr, ptep,\n+\t\t\t make_pte_marker(PTE_MARKER_UFFD_WP), nr_ptes);\n \n \treturn true;\n }\n@@ -4819,7 +4813,7 @@ static bool can_swapin_thp(struct vm_fault *vmf, pte_t *ptep, int nr_pages)\n \tidx = (vmf-\u003eaddress - addr) / PAGE_SIZE;\n \tpte = ptep_get(ptep);\n \n-\tif (!pte_same(pte, pte_move_swp_offset(vmf-\u003eorig_pte, -idx)))\n+\tif (!pte_same(pte, pte_move_softleaf_offset(vmf-\u003eorig_pte, -idx)))\n \t\treturn false;\n \t/*\n \t * swap_read_folio() can't handle the case a large folio is hybridly\n@@ -5134,7 +5128,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)\n \n \t\tfolio_ptep = vmf-\u003epte - idx;\n \t\tfolio_pte = ptep_get(folio_ptep);\n-\t\tif (!pte_same(folio_pte, pte_move_swp_offset(vmf-\u003eorig_pte, -idx)) ||\n+\t\tif (!pte_same(folio_pte, pte_move_softleaf_offset(vmf-\u003eorig_pte, -idx)) ||\n \t\t swap_pte_batch(folio_ptep, nr, folio_pte) != nr)\n \t\t\tgoto check_folio;\n \n@@ -5270,7 +5264,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)\n \tif (unlikely(folio != swapcache)) {\n \t\tfolio_add_new_anon_rmap(folio, vma, address, RMAP_EXCLUSIVE);\n \t\tfolio_add_lru_vma(folio, vma);\n-\t\tfolio_put_swap(swapcache, NULL);\n+\t\tfolio_put_swap(swapcache);\n \t} else if (!folio_test_anon(folio)) {\n \t\t/*\n \t\t * We currently only expect !anon folios that are fully\n@@ -5279,12 +5273,12 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)\n \t\tVM_WARN_ON_ONCE_FOLIO(folio_nr_pages(folio) != nr_pages, folio);\n \t\tVM_WARN_ON_ONCE_FOLIO(folio_mapped(folio), folio);\n \t\tfolio_add_new_anon_rmap(folio, vma, address, rmap_flags);\n-\t\tfolio_put_swap(folio, NULL);\n+\t\tfolio_put_swap(folio);\n \t} else {\n \t\tVM_WARN_ON_ONCE(nr_pages != 1 \u0026\u0026 nr_pages != folio_nr_pages(folio));\n \t\tfolio_add_anon_rmap_ptes(folio, page, nr_pages, vma, address,\n \t\t\t\t\t rmap_flags);\n-\t\tfolio_put_swap(folio, nr_pages == 1 ? page : NULL);\n+\t\tfolio_put_swap_pages(folio, page, nr_pages);\n \t}\n \n \tVM_BUG_ON(!folio_test_anon(folio) ||\ndiff --git a/mm/mprotect.c b/mm/mprotect.c\nindex e59c69cb5a238..6d254d5342633 100644\n--- a/mm/mprotect.c\n+++ b/mm/mprotect.c\n@@ -30,6 +30,7 @@\n #include \u003clinux/mm_inline.h\u003e\n #include \u003clinux/pgtable.h\u003e\n #include \u003clinux/userfaultfd_k.h\u003e\n+#include \u003clinux/rmap.h\u003e\n #include \u003cuapi/linux/mman.h\u003e\n #include \u003casm/cacheflush.h\u003e\n #include \u003casm/mmu_context.h\u003e\n@@ -138,23 +139,6 @@ static __always_inline void prot_commit_flush_ptes(struct vm_area_struct *vma,\n \t\ttlb_flush_pte_range(tlb, addr, nr_ptes * PAGE_SIZE);\n }\n \n-/*\n- * Get max length of consecutive ptes pointing to PageAnonExclusive() pages or\n- * !PageAnonExclusive() pages, starting from start_idx. Caller must enforce\n- * that the ptes point to consecutive pages of the same anon large folio.\n- */\n-static __always_inline int page_anon_exclusive_batch(int start_idx, int max_len,\n-\t\tstruct page *first_page, bool expected_anon_exclusive)\n-{\n-\tint idx;\n-\n-\tfor (idx = start_idx + 1; idx \u003c start_idx + max_len; ++idx) {\n-\t\tif (expected_anon_exclusive != PageAnonExclusive(first_page + idx))\n-\t\t\tbreak;\n-\t}\n-\treturn idx - start_idx;\n-}\n-\n /*\n * This function is a result of trying our very best to retain the\n * \"avoid the write-fault handler\" optimization. In can_change_pte_writable(),\ndiff --git a/mm/rmap.c b/mm/rmap.c\nindex fbd66a2823b7b..9e3589b07101d 100644\n--- a/mm/rmap.c\n+++ b/mm/rmap.c\n@@ -1959,6 +1959,7 @@ static inline unsigned int folio_unmap_pte_batch(struct folio *folio,\n \n \tif (flags \u0026 TTU_HWPOISON)\n \t\treturn 1;\n+\n \tif (!folio_test_large(folio))\n \t\treturn 1;\n \n@@ -1966,10 +1967,6 @@ static inline unsigned int folio_unmap_pte_batch(struct folio *folio,\n \tend_addr = pmd_addr_end(addr, vma-\u003evm_end);\n \tmax_nr = (end_addr - addr) \u003e\u003e PAGE_SHIFT;\n \n-\t/* We only support lazyfree or file folios batching for now ... */\n-\tif (folio_test_anon(folio) \u0026\u0026 folio_test_swapbacked(folio))\n-\t\treturn 1;\n-\n \tif (pte_unused(pte))\n \t\treturn 1;\n \n@@ -2141,16 +2138,25 @@ static pte_t swp_pte_prepare(swp_entry_t entry, pte_t old_pte,\n \treturn swp_pte;\n }\n \n-static bool ttu_anon_swapbacked_folio(struct vm_area_struct *vma,\n+static void finish_folio_unmap_batch(struct vm_area_struct *vma,\n+\t\tstruct folio *folio, struct page *page, unsigned long nr_pages)\n+{\n+\tfolio_remove_rmap_ptes(folio, page, nr_pages, vma);\n+\tif (vma-\u003evm_flags \u0026 VM_LOCKED)\n+\t\tmlock_drain_local();\n+\tfolio_put_refs(folio, nr_pages);\n+}\n+\n+static bool __ttu_anon_swapbacked_folio(struct vm_area_struct *vma,\n \t\tstruct folio *folio, struct page *page, unsigned long address,\n-\t\tpte_t *ptep, pte_t pteval)\n+\t\tpte_t *ptep, pte_t pteval, unsigned long nr_pages,\n+\t\tbool anon_exclusive)\n {\n-\tconst bool anon_exclusive = folio_test_anon(folio) \u0026\u0026\n-\t\t\t\t PageAnonExclusive(page);\n \tswp_entry_t entry = folio_page_swap_entry(folio, page);\n \tstruct mm_struct *mm = vma-\u003evm_mm;\n+\tpte_t swp_pte;\n \n-\tif (folio_dup_swap(folio, page) \u003c 0)\n+\tif (folio_dup_swap_pages(folio, page, nr_pages) \u003c 0)\n \t\treturn false;\n \n \t/*\n@@ -2158,22 +2164,57 @@ static bool ttu_anon_swapbacked_folio(struct vm_area_struct *vma,\n \t * architectures where we could have PFN swap PTEs,\n \t * so we'll not check/care.\n \t */\n-\tif (arch_unmap_one(mm, vma, address, pteval) \u003c 0) {\n-\t\tfolio_put_swap(folio, page);\n+\tif (arch_unmap_one(mm, vma, address, pteval, nr_pages) \u003c 0) {\n+\t\tfolio_put_swap_pages(folio, page, nr_pages);\n \t\treturn false;\n \t}\n \n \t/* See folio_try_share_anon_rmap(): clear PTE first. */\n-\tif (anon_exclusive \u0026\u0026 folio_try_share_anon_rmap_pte(folio, page)) {\n-\t\tfolio_put_swap(folio, page);\n+\tif (anon_exclusive \u0026\u0026\n+\t folio_try_share_anon_rmap_ptes(folio, page, nr_pages)) {\n+\t\tfolio_put_swap_pages(folio, page, nr_pages);\n \t\treturn false;\n \t}\n \n \tmm_prepare_for_swap_entries(mm);\n-\tdec_mm_counter(mm, MM_ANONPAGES);\n-\tinc_mm_counter(mm, MM_SWAPENTS);\n-\tset_pte_at(mm, address, ptep,\n-\t\t swp_pte_prepare(entry, pteval, anon_exclusive));\n+\tadd_mm_counter(mm, MM_ANONPAGES, -nr_pages);\n+\tadd_mm_counter(mm, MM_SWAPENTS, nr_pages);\n+\tswp_pte = swp_pte_prepare(entry, pteval, anon_exclusive);\n+\tset_softleaf_ptes(mm, address, ptep, swp_pte, nr_pages);\n+\tfinish_folio_unmap_batch(vma, folio, page, nr_pages);\n+\treturn true;\n+}\n+\n+static bool ttu_anon_swapbacked_folio(struct vm_area_struct *vma,\n+\t\tstruct folio *folio, struct page *first_page,\n+\t\tunsigned long address, pte_t *ptep, pte_t pteval,\n+\t\tunsigned long nr_pages)\n+{\n+\tunsigned long batch_idx = 0;\n+\n+\twhile (nr_pages) {\n+\t\tbool anon_exclusive = PageAnonExclusive(first_page + batch_idx);\n+\t\tunsigned long len = page_anon_exclusive_batch(batch_idx,\n+\t\t\t\tnr_pages, first_page, anon_exclusive);\n+\n+\t\tif (!__ttu_anon_swapbacked_folio(vma, folio,\n+\t\t\t\tfirst_page + batch_idx, address, ptep, pteval,\n+\t\t\t\tlen, anon_exclusive)) {\n+\t\t\t/* Restore the remaining PTEs that were cleared. */\n+\t\t\tset_ptes(vma-\u003evm_mm, address, ptep, pteval, nr_pages);\n+\t\t\treturn false;\n+\t\t}\n+\n+\t\tnr_pages -= len;\n+\t\tif (!nr_pages)\n+\t\t\tbreak;\n+\n+\t\tpteval = pte_advance_pfn(pteval, len);\n+\t\taddress += len * PAGE_SIZE;\n+\t\tbatch_idx += len;\n+\t\tptep += len;\n+\t}\n+\n \treturn true;\n }\n \n@@ -2186,15 +2227,22 @@ static bool ttu_anon_folio(struct vm_area_struct *vma, struct folio *folio,\n \t * See handle_pte_fault() ...\n \t */\n \tif (WARN_ON_ONCE(folio_test_swapbacked(folio) !=\n-\t\t\t folio_test_swapcache(folio)))\n+\t\t\t folio_test_swapcache(folio))) {\n+\t\tset_ptes(vma-\u003evm_mm, address, ptep, pteval, nr_pages);\n \t\treturn false;\n+\t}\n \n-\tif (!folio_test_swapbacked(folio))\n-\t\treturn ttu_anon_lazyfree_folio(vma, folio, nr_pages);\n+\tif (!folio_test_swapbacked(folio)) {\n+\t\tif (!ttu_anon_lazyfree_folio(vma, folio, nr_pages)) {\n+\t\t\tset_ptes(vma-\u003evm_mm, address, ptep, pteval, nr_pages);\n+\t\t\treturn false;\n+\t\t}\n+\t\tfinish_folio_unmap_batch(vma, folio, page, nr_pages);\n+\t\treturn true;\n+\t}\n \n-\t/* nr_pages \u003e 1 not supported yet */\n \treturn ttu_anon_swapbacked_folio(vma, folio, page, address, ptep,\n-\t\t\t\t\t pteval);\n+\t\t\t\t\t pteval, nr_pages);\n }\n \n /*\n@@ -2374,13 +2422,14 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,\n \t\t\t */\n \t\t\tdec_mm_counter(mm, mm_counter(folio));\n \t\t} else if (folio_test_anon(folio)) {\n+\t\t\t/* finish_folio_unmap_batch handled internally */\n \t\t\tif (!ttu_anon_folio(vma, folio, page, address,\n-\t\t\t\t\t pvmw.pte, pteval, nr_pages)) {\n-\t\t\t\tset_ptes(mm, address, pvmw.pte, pteval, nr_pages);\n+\t\t\t\t\t pvmw.pte, pteval, nr_pages))\n \t\t\t\tgoto walk_abort;\n-\t\t\t}\n \n-\t\t\tgoto finish_unmap;\n+\t\t\tif (nr_pages == folio_nr_pages(folio))\n+\t\t\t\tgoto walk_done;\n+\t\t\tcontinue;\n \t\t} else {\n \t\t\t/*\n \t\t\t * This is a locked file-backed folio,\n@@ -2395,11 +2444,8 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,\n \t\t\t */\n \t\t\tadd_mm_counter(mm, mm_counter_file(folio), -nr_pages);\n \t\t}\n-finish_unmap:\n-\t\tfolio_remove_rmap_ptes(folio, page, nr_pages, vma);\n-\t\tif (vma-\u003evm_flags \u0026 VM_LOCKED)\n-\t\t\tmlock_drain_local();\n-\t\tfolio_put_refs(folio, nr_pages);\n+\n+\t\tfinish_folio_unmap_batch(vma, folio, page, nr_pages);\n \n \t\t/*\n \t\t * If we are sure that we batched the entire folio and cleared\n@@ -2695,7 +2741,7 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma,\n \t\t\t * architectures where we could have PFN swap PTEs,\n \t\t\t * so we'll not check/care.\n \t\t\t */\n-\t\t\tif (arch_unmap_one(mm, vma, address, pteval) \u003c 0) {\n+\t\t\tif (arch_unmap_one(mm, vma, address, pteval, 1) \u003c 0) {\n \t\t\t\tif (folio_test_hugetlb(folio))\n \t\t\t\t\tset_huge_pte_at(mm, address, pvmw.pte,\n \t\t\t\t\t\t\tpteval, hsz);\ndiff --git a/mm/shmem.c b/mm/shmem.c\nindex 07b2855dfb7bd..2ea73d18126f5 100644\n--- a/mm/shmem.c\n+++ b/mm/shmem.c\n@@ -1916,7 +1916,7 @@ int shmem_writeout(struct swap_io_ctx *ctx, struct folio *folio,\n \t\t\tspin_unlock(\u0026shmem_swaplist_lock);\n \t\t}\n \n-\t\tfolio_dup_swap(folio, NULL);\n+\t\tfolio_dup_swap(folio);\n \t\tshmem_delete_from_page_cache(folio, swp_to_radix_entry(folio-\u003eswap));\n \n \t\tBUG_ON(folio_mapped(folio));\n@@ -1937,7 +1937,7 @@ int shmem_writeout(struct swap_io_ctx *ctx, struct folio *folio,\n \t\t/* Swap entry might be erased by racing shmem_free_swap() */\n \t\tif (!error) {\n \t\t\tshmem_recalc_inode(inode, 0, -nr_pages);\n-\t\t\tfolio_put_swap(folio, NULL);\n+\t\t\tfolio_put_swap(folio);\n \t\t}\n \n \t\t/*\n@@ -2370,7 +2370,7 @@ static void shmem_set_folio_swapin_error(struct inode *inode, pgoff_t index,\n \n \tnr_pages = folio_nr_pages(folio);\n \tfolio_wait_writeback(folio);\n-\tfolio_put_swap(folio, NULL);\n+\tfolio_put_swap(folio);\n \tswap_cache_del_folio(folio);\n \t/*\n \t * Don't treat swapin error folio as alloced. Otherwise inode-\u003ei_blocks\n@@ -2600,7 +2600,7 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,\n \tif (sgp == SGP_WRITE)\n \t\tfolio_mark_accessed(folio);\n \n-\tfolio_put_swap(folio, NULL);\n+\tfolio_put_swap(folio);\n \tswap_cache_del_folio(folio);\n \tfolio_mark_dirty(folio);\n \tput_swap_device(si);\ndiff --git a/mm/swap.h b/mm/swap.h\nindex d5bf21f517dce..891f41c4556c2 100644\n--- a/mm/swap.h\n+++ b/mm/swap.h\n@@ -244,8 +244,10 @@ extern int swap_retry_table_alloc(swp_entry_t entry, gfp_t gfp);\n * folio_put_swap(): does the opposite thing of folio_dup_swap().\n */\n int folio_alloc_swap(struct folio *folio);\n-int folio_dup_swap(struct folio *folio, struct page *page);\n-void folio_put_swap(struct folio *folio, struct page *page);\n+int folio_dup_swap_pages(struct folio *folio, struct page *page,\n+\t\tunsigned long nr_pages);\n+void folio_put_swap_pages(struct folio *folio, struct page *page,\n+\t\tunsigned long nr_pages);\n \n /* For internal use */\n extern void __swap_cluster_free_entries(struct swap_info_struct *si,\n@@ -368,12 +370,14 @@ static inline int folio_alloc_swap(struct folio *folio)\n \treturn -EINVAL;\n }\n \n-static inline int folio_dup_swap(struct folio *folio, struct page *page)\n+static inline int folio_dup_swap_pages(struct folio *folio, struct page *page,\n+\t\tunsigned long nr_pages)\n {\n \treturn -EINVAL;\n }\n \n-static inline void folio_put_swap(struct folio *folio, struct page *page)\n+static inline void folio_put_swap_pages(struct folio *folio, struct page *page,\n+\t\tunsigned long nr_pages)\n {\n }\n \n@@ -464,6 +468,29 @@ static inline void __swap_cache_replace_folio(struct swap_cluster_info *ci,\n }\n #endif /* CONFIG_SWAP */\n \n+/**\n+ * folio_dup_swap() - Increase swap count of all swap entries of a folio.\n+ * @folio: folio with swap entries bound.\n+ *\n+ * See folio_dup_swap_pages() for more information.\n+ */\n+static inline int folio_dup_swap(struct folio *folio)\n+{\n+\treturn folio_dup_swap_pages(folio, folio_page(folio, 0),\n+\t\t\t\t folio_nr_pages(folio));\n+}\n+\n+/**\n+ * folio_put_swap() - Decrease swap count of all swap entries of a folio.\n+ * @folio: folio with swap entries bound.\n+ *\n+ * See folio_put_swap_pages() for more information.\n+ */\n+static inline void folio_put_swap(struct folio *folio)\n+{\n+\tfolio_put_swap_pages(folio, folio_page(folio, 0), folio_nr_pages(folio));\n+}\n+\n extern const struct swap_ops swap_bdev_ops;\n \n int shmem_writeout(struct swap_io_ctx *ctx, struct folio *folio,\ndiff --git a/mm/swapfile.c b/mm/swapfile.c\nindex 254ce86fa923e..5d4d293044ab0 100644\n--- a/mm/swapfile.c\n+++ b/mm/swapfile.c\n@@ -1799,9 +1799,10 @@ int folio_alloc_swap(struct folio *folio)\n }\n \n /**\n- * folio_dup_swap() - Increase swap count of swap entries of a folio.\n+ * folio_dup_swap_pages() - Increase swap count of swap entries of a folio.\n * @folio: folio with swap entries bounded.\n- * @page: if not NULL, only increase the swap count of this page.\n+ * @page: the first page in the folio to increase the swap count for.\n+ * @nr_pages: the number of pages in the folio to increase the swap count for.\n *\n * Typically called when the folio is unmapped and have its swap entry to\n * take its place: Swap entries allocated to a folio has count == 0 and pinned\n@@ -1815,45 +1816,40 @@ int folio_alloc_swap(struct folio *folio)\n * swap_put_entries_direct on its swap entry before this helper returns, or\n * the swap count may underflow.\n */\n-int folio_dup_swap(struct folio *folio, struct page *page)\n+int folio_dup_swap_pages(struct folio *folio, struct page *page,\n+\t\tunsigned long nr_pages)\n {\n-\tswp_entry_t entry = folio-\u003eswap;\n-\tunsigned long nr_pages = folio_nr_pages(folio);\n+\tswp_entry_t entry = folio_page_swap_entry(folio, page);\n+\tunsigned long idx = folio_page_idx(folio, page);\n \n \tVM_WARN_ON_FOLIO(!folio_test_locked(folio), folio);\n \tVM_WARN_ON_FOLIO(!folio_test_swapcache(folio), folio);\n-\n-\tif (page) {\n-\t\tentry = folio_page_swap_entry(folio, page);\n-\t\tnr_pages = 1;\n-\t}\n+\tVM_WARN_ON_FOLIO(idx + nr_pages \u003e folio_nr_pages(folio), folio);\n \n \treturn swap_dup_entries_cluster(swap_entry_to_info(entry),\n \t\t\t\t\tswp_offset(entry), nr_pages);\n }\n \n /**\n- * folio_put_swap() - Decrease swap count of swap entries of a folio.\n+ * folio_put_swap_pages() - Decrease swap count of swap entries of a folio.\n * @folio: folio with swap entries bounded, must be in swap cache and locked.\n- * @page: if not NULL, only decrease the swap count of this page.\n+ * @page: the first page in the folio to decrease the swap count for.\n+ * @nr_pages: the number of pages in the folio to decrease the swap count for.\n *\n * This won't free the swap slots even if swap count drops to zero, they are\n * still pinned by the swap cache. User may call folio_free_swap to free them.\n * Context: Caller must ensure the folio is locked and in the swap cache.\n */\n-void folio_put_swap(struct folio *folio, struct page *page)\n+void folio_put_swap_pages(struct folio *folio, struct page *page,\n+\t\tunsigned long nr_pages)\n {\n-\tswp_entry_t entry = folio-\u003eswap;\n-\tunsigned long nr_pages = folio_nr_pages(folio);\n+\tswp_entry_t entry = folio_page_swap_entry(folio, page);\n \tstruct swap_info_struct *si = __swap_entry_to_info(entry);\n+\tunsigned long idx = folio_page_idx(folio, page);\n \n \tVM_WARN_ON_FOLIO(!folio_test_locked(folio), folio);\n \tVM_WARN_ON_FOLIO(!folio_test_swapcache(folio), folio);\n-\n-\tif (page) {\n-\t\tentry = folio_page_swap_entry(folio, page);\n-\t\tnr_pages = 1;\n-\t}\n+\tVM_WARN_ON_FOLIO(idx + nr_pages \u003e folio_nr_pages(folio), folio);\n \n \tswap_put_entries_cluster(si, swp_offset(entry), nr_pages, false);\n }\n@@ -2598,7 +2594,8 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd,\n \n setpte:\n \tset_pte_at(vma-\u003evm_mm, addr, pte, new_pte);\n-\tfolio_put_swap(swapcache, folio_file_page(swapcache, swp_offset(entry)));\n+\tfolio_put_swap_pages(swapcache,\n+\t\t\t folio_file_page(swapcache, swp_offset(entry)), 1);\n out:\n \tif (pte)\n \t\tpte_unmap_unlock(pte, ptl);\n"
} |
| 2/1 | 2026/09/26 18:21 | agent | patch-evaluator |
1mModel:core Args: null Results: {
"EnableConfigs": [
"SWAP",
"TRANSPARENT_HUGEPAGE"
],
"FocusSymbols": [
"try_to_unmap_one",
"try_to_unmap",
"folio_dup_swap_pages",
"folio_put_swap_pages",
"cond_install_uffd_wp_ptes"
],
"Reasoning": "The patch series adds batch unmapping for large anonymous swap-backed folios in core mm (mm/rmap.c), introduces new range-based swap counting functions (folio_dup_swap_pages, folio_put_swap_pages), and adds new runtime assertions (VM_WARN_ON_FOLIO). These changes alter reachable core memory management and swap handling paths on amd64 during folio unmapping and memory reclaim.",
"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 b2dccc03952d04d8e09ed125e1fd46bbfff58bf0
Author: syz-cluster <triage@syzkaller.com>
Date: Sat Sep 26 18:21:06 2026 +0000
syz-cluster: applied patch under review
diff --git a/arch/sparc/include/asm/pgtable_64.h b/arch/sparc/include/asm/pgtable_64.h
index 44d1333065a6a..f7dd1872884e4 100644
--- a/arch/sparc/include/asm/pgtable_64.h
+++ b/arch/sparc/include/asm/pgtable_64.h
@@ -1037,6 +1037,9 @@ void adi_restore_tags(struct mm_struct *mm, struct vm_area_struct *vma,
int adi_save_tags(struct mm_struct *mm, struct vm_area_struct *vma,
unsigned long addr, pte_t oldpte);
+int adi_save_tags_range(struct mm_struct *mm, struct vm_area_struct *vma,
+ unsigned long addr, pte_t oldpte, unsigned long nr);
+
#define __HAVE_ARCH_DO_SWAP_PAGE
static inline void arch_do_swap_page(struct mm_struct *mm,
struct vm_area_struct *vma,
@@ -1057,10 +1060,11 @@ static inline void arch_do_swap_page(struct mm_struct *mm,
#define __HAVE_ARCH_UNMAP_ONE
static inline int arch_unmap_one(struct mm_struct *mm,
struct vm_area_struct *vma,
- unsigned long addr, pte_t oldpte)
+ unsigned long addr, pte_t oldpte,
+ unsigned long nr)
{
- if (adi_state.enabled && (pte_val(oldpte) & _PAGE_MCD_4V))
- return adi_save_tags(mm, vma, addr, oldpte);
+ if (adi_state.enabled)
+ return adi_save_tags_range(mm, vma, addr, oldpte, nr);
return 0;
}
diff --git a/arch/sparc/kernel/adi_64.c b/arch/sparc/kernel/adi_64.c
index 18036a43cf568..ffa378accefe3 100644
--- a/arch/sparc/kernel/adi_64.c
+++ b/arch/sparc/kernel/adi_64.c
@@ -9,6 +9,7 @@
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/mm_types.h>
+#include <linux/pgtable.h>
#include <asm/mdesc.h>
#include <asm/adi_64.h>
#include <asm/mmu_64.h>
@@ -394,3 +395,23 @@ int adi_save_tags(struct mm_struct *mm, struct vm_area_struct *vma,
return 0;
}
+
+int adi_save_tags_range(struct mm_struct *mm, struct vm_area_struct *vma,
+ unsigned long addr, pte_t oldpte, unsigned long nr)
+{
+ unsigned long i;
+
+ for (i = 0; i < nr; i++, addr += PAGE_SIZE,
+ oldpte = pte_next_pfn(oldpte)) {
+ int ret;
+
+ if (!(pte_val(oldpte) & _PAGE_MCD_4V))
+ continue;
+
+ ret = adi_save_tags(mm, vma, addr, oldpte);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index 780fe849ff8b7..9c04bf3d0c04e 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -1431,12 +1431,12 @@ static inline void arch_do_swap_page_nr(struct mm_struct *mm,
* restored when the page is swapped back in. SPARC M7 and newer
* processors support an ADI (Application Data Integrity) tag for the
* page as metadata for the page. arch_unmap_one() can save this
- * metadata on a swap-out of a page.
+ * metadata on swap-out of one or more pages.
*/
static inline int arch_unmap_one(struct mm_struct *mm,
struct vm_area_struct *vma,
- unsigned long addr,
- pte_t orig_pte)
+ unsigned long addr, pte_t orig_pte,
+ unsigned long nr)
{
return 0;
}
diff --git a/include/linux/rmap.h b/include/linux/rmap.h
index 74cca0e3c7264..91b5763ef466f 100644
--- a/include/linux/rmap.h
+++ b/include/linux/rmap.h
@@ -106,6 +106,23 @@ enum ttu_flags {
#ifdef CONFIG_MMU
+/*
+ * Get max length of consecutive PTEs pointing to PageAnonExclusive() pages or
+ * !PageAnonExclusive() pages, starting from start_idx. Caller must enforce
+ * that the PTEs point to consecutive pages of the same anon large folio.
+ */
+static __always_inline unsigned long page_anon_exclusive_batch(unsigned long start_idx,
+ unsigned long max_len, struct page *first_page, bool anon_exclusive)
+{
+ unsigned long idx;
+
+ for (idx = start_idx + 1; idx < start_idx + max_len; ++idx) {
+ if (anon_exclusive != PageAnonExclusive(first_page + idx))
+ break;
+ }
+ return idx - start_idx;
+}
+
void anon_vma_init(void); /* create anon_vma_cachep */
#ifdef CONFIG_MM_ID
@@ -706,17 +723,23 @@ static inline int folio_try_dup_anon_rmap_pmd(struct folio *folio,
}
static __always_inline int __folio_try_share_anon_rmap(struct folio *folio,
- struct page *page, int nr_pages, enum pgtable_level level)
+ struct page *page, unsigned long nr_pages, enum pgtable_level level)
{
+ /* device private folios cannot get pinned via GUP. */
+ const bool pinnable = !folio_is_device_private(folio);
+
VM_WARN_ON_FOLIO(!folio_test_anon(folio), folio);
VM_WARN_ON_FOLIO(!PageAnonExclusive(page), folio);
+
__folio_rmap_sanity_checks(folio, page, nr_pages, level);
- /* device private folios cannot get pinned via GUP. */
- if (unlikely(folio_is_device_private(folio))) {
- ClearPageAnonExclusive(page);
- return 0;
- }
+ VM_WARN_ON_ONCE(level != PGTABLE_LEVEL_PTE && level != PGTABLE_LEVEL_PMD);
+
+ /* We only clear anon-exclusive from head page of PMD folio. */
+ if (level == PGTABLE_LEVEL_PMD)
+ nr_pages = 1;
+
+ VM_WARN_ON_FOLIO(page_anon_exclusive_batch(0, nr_pages, page, true) != nr_pages, folio);
/*
* We have to make sure that when we clear PageAnonExclusive, that
@@ -760,29 +783,38 @@ static __always_inline int __folio_try_share_anon_rmap(struct folio *folio,
* so we use explicit ones here.
*/
- /* Paired with the memory barrier in try_grab_folio(). */
- if (IS_ENABLED(CONFIG_HAVE_GUP_FAST))
- smp_mb();
+ if (likely(pinnable)) {
+ /* Paired with the memory barrier in try_grab_folio(). */
+ if (IS_ENABLED(CONFIG_HAVE_GUP_FAST))
+ smp_mb();
- if (unlikely(folio_maybe_dma_pinned(folio)))
- return -EBUSY;
- ClearPageAnonExclusive(page);
+ if (unlikely(folio_maybe_dma_pinned(folio)))
+ return -EBUSY;
+ }
+
+ for (;;) {
+ ClearPageAnonExclusive(page);
+ if (--nr_pages == 0)
+ break;
+ page++;
+ }
/*
* This is conceptually a smp_wmb() paired with the smp_rmb() in
* gup_must_unshare().
*/
- if (IS_ENABLED(CONFIG_HAVE_GUP_FAST))
+ if (likely(pinnable) && IS_ENABLED(CONFIG_HAVE_GUP_FAST))
smp_mb__after_atomic();
return 0;
}
/**
- * folio_try_share_anon_rmap_pte - try marking an exclusive anonymous page
- * mapped by a PTE possibly shared to prepare
+ * folio_try_share_anon_rmap_ptes - try marking exclusive anonymous pages
+ * mapped by PTEs possibly shared to prepare
* for KSM or temporary unmapping
* @folio: The folio to share a mapping of
- * @page: The mapped exclusive page
+ * @page: The first mapped exclusive page of the batch in the folio
+ * @nr_pages: The number of pages to share in the folio (batch size)
*
* The caller needs to hold the page table lock and has to have the page table
* entries cleared/invalidated.
@@ -798,10 +830,17 @@ static __always_inline int __folio_try_share_anon_rmap(struct folio *folio,
* Returns 0 if marking the mapped page possibly shared succeeded. Returns
* -EBUSY otherwise.
*/
+static inline int folio_try_share_anon_rmap_ptes(struct folio *folio,
+ struct page *page, unsigned long nr_pages)
+{
+ return __folio_try_share_anon_rmap(folio, page, nr_pages,
+ PGTABLE_LEVEL_PTE);
+}
+
static inline int folio_try_share_anon_rmap_pte(struct folio *folio,
struct page *page)
{
- return __folio_try_share_anon_rmap(folio, page, 1, PGTABLE_LEVEL_PTE);
+ return folio_try_share_anon_rmap_ptes(folio, page, 1);
}
/**
diff --git a/mm/internal.h b/mm/internal.h
index 0434dfcfc36f1..7e7afcd93b33c 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -469,16 +469,16 @@ unsigned int folio_pte_batch(struct folio *folio, pte_t *ptep, pte_t pte,
unsigned int max_nr);
/**
- * pte_move_swp_offset - Move the swap entry offset field of a swap pte
- * forward or backward by delta
- * @pte: The initial pte state; must be a swap entry
+ * pte_move_softleaf_offset - Move the softleaf entry offset field of a
+ * softleaf pte forward or backward by delta
+ * @pte: The initial pte state; must be a softleaf entry
* @delta: The direction and the offset we are moving; forward if delta
* is positive; backward if delta is negative
*
- * Moves the swap offset, while maintaining all other fields, including
- * swap type, and any swp pte bits. The resulting pte is returned.
+ * Moves the softleaf offset, while maintaining all other fields, including
+ * softleaf type, and any softleaf pte bits. The resulting pte is returned.
*/
-static inline pte_t pte_move_swp_offset(pte_t pte, long delta)
+static inline pte_t pte_move_softleaf_offset(pte_t pte, long delta)
{
const softleaf_t entry = softleaf_from_pte(pte);
pte_t new = __swp_entry_to_pte(__swp_entry(swp_type(entry),
@@ -486,7 +486,7 @@ static inline pte_t pte_move_swp_offset(pte_t pte, long delta)
if (pte_swp_soft_dirty(pte))
new = pte_swp_mksoft_dirty(new);
- if (pte_swp_exclusive(pte))
+ if (softleaf_is_swap(entry) && pte_swp_exclusive(pte))
new = pte_swp_mkexclusive(new);
if (pte_swp_uffd(pte))
new = pte_swp_mkuffd(new);
@@ -496,15 +496,49 @@ static inline pte_t pte_move_swp_offset(pte_t pte, long delta)
/**
- * pte_next_swp_offset - Increment the swap entry offset field of a swap pte.
- * @pte: The initial pte state; must be a swap entry.
+ * pte_next_softleaf_offset - Increment the softleaf entry offset field of a
+ * non-present pte.
+ * @pte: The initial pte state; must be a softleaf entry.
*
- * Increments the swap offset, while maintaining all other fields, including
- * swap type, and any swp pte bits. The resulting pte is returned.
+ * Increments the softleaf offset, while maintaining all other fields, including
+ * softleaf type, and any softleaf pte bits. The resulting pte is returned.
*/
-static inline pte_t pte_next_swp_offset(pte_t pte)
+static inline pte_t pte_next_softleaf_offset(pte_t pte)
{
- return pte_move_swp_offset(pte, 1);
+ return pte_move_softleaf_offset(pte, 1);
+}
+
+/**
+ * set_softleaf_ptes - Set consecutive softleaf PTEs.
+ * @mm: Address space the PTEs belong to.
+ * @addr: Address of the first PTE.
+ * @ptep: Page table pointer for the first PTE.
+ * @pte: PTE to set for the first entry.
+ * @nr: Number of PTEs to set.
+ *
+ * Install @nr softleaf PTEs, advancing @pte when its softleaf entry
+ * represents consecutive offsets. Swap entries advance through swap offsets,
+ * PFN softleaf entries advance through PFNs (encoded by swap offset), and
+ * marker entries are repeated unchanged.
+ */
+static inline void set_softleaf_ptes(struct mm_struct *mm, unsigned long addr,
+ pte_t *ptep, pte_t pte, unsigned long nr)
+{
+ softleaf_t entry;
+ bool advance;
+
+ entry = softleaf_from_pte(pte);
+ advance = softleaf_is_swap(entry) || softleaf_has_pfn(entry);
+
+ for (;;) {
+ set_pte_at(mm, addr, ptep, pte);
+ if (--nr == 0)
+ break;
+ if (advance)
+ pte = pte_next_softleaf_offset(pte);
+ ptep++;
+ addr += PAGE_SIZE;
+ }
}
/**
@@ -524,7 +558,7 @@ static inline pte_t pte_next_swp_offset(pte_t pte)
*/
static inline int swap_pte_batch(pte_t *start_ptep, int max_nr, pte_t pte)
{
- pte_t expected_pte = pte_next_swp_offset(pte);
+ pte_t expected_pte = pte_next_softleaf_offset(pte);
const pte_t *end_ptep = start_ptep + max_nr;
pte_t *ptep = start_ptep + 1;
@@ -536,7 +570,7 @@ static inline int swap_pte_batch(pte_t *start_ptep, int max_nr, pte_t pte)
if (!pte_same(pte, expected_pte))
break;
- expected_pte = pte_next_swp_offset(expected_pte);
+ expected_pte = pte_next_softleaf_offset(expected_pte);
ptep++;
}
diff --git a/mm/memory.c b/mm/memory.c
index 330cde31bf8b4..985a884b68008 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -1700,14 +1700,8 @@ bool cond_install_uffd_wp_ptes(struct vm_area_struct *vma,
if (likely(!arm_uffd_pte))
return false;
- for (;;) {
- set_pte_at(vma->vm_mm, addr, ptep,
- make_pte_marker(PTE_MARKER_UFFD_WP));
- if (--nr_ptes == 0)
- break;
- ptep++;
- addr += PAGE_SIZE;
- }
+ set_softleaf_ptes(vma->vm_mm, addr, ptep,
+ make_pte_marker(PTE_MARKER_UFFD_WP), nr_ptes);
return true;
}
@@ -4819,7 +4813,7 @@ static bool can_swapin_thp(struct vm_fault *vmf, pte_t *ptep, int nr_pages)
idx = (vmf->address - addr) / PAGE_SIZE;
pte = ptep_get(ptep);
- if (!pte_same(pte, pte_move_swp_offset(vmf->orig_pte, -idx)))
+ if (!pte_same(pte, pte_move_softleaf_offset(vmf->orig_pte, -idx)))
return false;
/*
* swap_read_folio() can't handle the case a large folio is hybridly
@@ -5134,7 +5128,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
folio_ptep = vmf->pte - idx;
folio_pte = ptep_get(folio_ptep);
- if (!pte_same(folio_pte, pte_move_swp_offset(vmf->orig_pte, -idx)) ||
+ if (!pte_same(folio_pte, pte_move_softleaf_offset(vmf->orig_pte, -idx)) ||
swap_pte_batch(folio_ptep, nr, folio_pte) != nr)
goto check_folio;
@@ -5270,7 +5264,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
if (unlikely(folio != swapcache)) {
folio_add_new_anon_rmap(folio, vma, address, RMAP_EXCLUSIVE);
folio_add_lru_vma(folio, vma);
- folio_put_swap(swapcache, NULL);
+ folio_put_swap(swapcache);
} else if (!folio_test_anon(folio)) {
/*
* We currently only expect !anon folios that are fully
@@ -5279,12 +5273,12 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
VM_WARN_ON_ONCE_FOLIO(folio_nr_pages(folio) != nr_pages, folio);
VM_WARN_ON_ONCE_FOLIO(folio_mapped(folio), folio);
folio_add_new_anon_rmap(folio, vma, address, rmap_flags);
- folio_put_swap(folio, NULL);
+ folio_put_swap(folio);
} else {
VM_WARN_ON_ONCE(nr_pages != 1 && nr_pages != folio_nr_pages(folio));
folio_add_anon_rmap_ptes(folio, page, nr_pages, vma, address,
rmap_flags);
- folio_put_swap(folio, nr_pages == 1 ? page : NULL);
+ folio_put_swap_pages(folio, page, nr_pages);
}
VM_BUG_ON(!folio_test_anon(folio) ||
diff --git a/mm/mprotect.c b/mm/mprotect.c
index e59c69cb5a238..6d254d5342633 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -30,6 +30,7 @@
#include <linux/mm_inline.h>
#include <linux/pgtable.h>
#include <linux/userfaultfd_k.h>
+#include <linux/rmap.h>
#include <uapi/linux/mman.h>
#include <asm/cacheflush.h>
#include <asm/mmu_context.h>
@@ -138,23 +139,6 @@ static __always_inline void prot_commit_flush_ptes(struct vm_area_struct *vma,
tlb_flush_pte_range(tlb, addr, nr_ptes * PAGE_SIZE);
}
-/*
- * Get max length of consecutive ptes pointing to PageAnonExclusive() pages or
- * !PageAnonExclusive() pages, starting from start_idx. Caller must enforce
- * that the ptes point to consecutive pages of the same anon large folio.
- */
-static __always_inline int page_anon_exclusive_batch(int start_idx, int max_len,
- struct page *first_page, bool expected_anon_exclusive)
-{
- int idx;
-
- for (idx = start_idx + 1; idx < start_idx + max_len; ++idx) {
- if (expected_anon_exclusive != PageAnonExclusive(first_page + idx))
- break;
- }
- return idx - start_idx;
-}
-
/*
* This function is a result of trying our very best to retain the
* "avoid the write-fault handler" optimization. In can_change_pte_writable(),
diff --git a/mm/rmap.c b/mm/rmap.c
index fbd66a2823b7b..9e3589b07101d 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1959,6 +1959,7 @@ static inline unsigned int folio_unmap_pte_batch(struct folio *folio,
if (flags & TTU_HWPOISON)
return 1;
+
if (!folio_test_large(folio))
return 1;
@@ -1966,10 +1967,6 @@ static inline unsigned int folio_unmap_pte_batch(struct folio *folio,
end_addr = pmd_addr_end(addr, vma->vm_end);
max_nr = (end_addr - addr) >> PAGE_SHIFT;
- /* We only support lazyfree or file folios batching for now ... */
- if (folio_test_anon(folio) && folio_test_swapbacked(folio))
- return 1;
-
if (pte_unused(pte))
return 1;
@@ -2141,16 +2138,25 @@ static pte_t swp_pte_prepare(swp_entry_t entry, pte_t old_pte,
return swp_pte;
}
-static bool ttu_anon_swapbacked_folio(struct vm_area_struct *vma,
+static void finish_folio_unmap_batch(struct vm_area_struct *vma,
+ struct folio *folio, struct page *page, unsigned long nr_pages)
+{
+ folio_remove_rmap_ptes(folio, page, nr_pages, vma);
+ if (vma->vm_flags & VM_LOCKED)
+ mlock_drain_local();
+ folio_put_refs(folio, nr_pages);
+}
+
+static bool __ttu_anon_swapbacked_folio(struct vm_area_struct *vma,
struct folio *folio, struct page *page, unsigned long address,
- pte_t *ptep, pte_t pteval)
+ pte_t *ptep, pte_t pteval, unsigned long nr_pages,
+ bool anon_exclusive)
{
- const bool anon_exclusive = folio_test_anon(folio) &&
- PageAnonExclusive(page);
swp_entry_t entry = folio_page_swap_entry(folio, page);
struct mm_struct *mm = vma->vm_mm;
+ pte_t swp_pte;
- if (folio_dup_swap(folio, page) < 0)
+ if (folio_dup_swap_pages(folio, page, nr_pages) < 0)
return false;
/*
@@ -2158,22 +2164,57 @@ static bool ttu_anon_swapbacked_folio(struct vm_area_struct *vma,
* architectures where we could have PFN swap PTEs,
* so we'll not check/care.
*/
- if (arch_unmap_one(mm, vma, address, pteval) < 0) {
- folio_put_swap(folio, page);
+ if (arch_unmap_one(mm, vma, address, pteval, nr_pages) < 0) {
+ folio_put_swap_pages(folio, page, nr_pages);
return false;
}
/* See folio_try_share_anon_rmap(): clear PTE first. */
- if (anon_exclusive && folio_try_share_anon_rmap_pte(folio, page)) {
- folio_put_swap(folio, page);
+ if (anon_exclusive &&
+ folio_try_share_anon_rmap_ptes(folio, page, nr_pages)) {
+ folio_put_swap_pages(folio, page, nr_pages);
return false;
}
mm_prepare_for_swap_entries(mm);
- dec_mm_counter(mm, MM_ANONPAGES);
- inc_mm_counter(mm, MM_SWAPENTS);
- set_pte_at(mm, address, ptep,
- swp_pte_prepare(entry, pteval, anon_exclusive));
+ add_mm_counter(mm, MM_ANONPAGES, -nr_pages);
+ add_mm_counter(mm, MM_SWAPENTS, nr_pages);
+ swp_pte = swp_pte_prepare(entry, pteval, anon_exclusive);
+ set_softleaf_ptes(mm, address, ptep, swp_pte, nr_pages);
+ finish_folio_unmap_batch(vma, folio, page, nr_pages);
+ return true;
+}
+
+static bool ttu_anon_swapbacked_folio(struct vm_area_struct *vma,
+ struct folio *folio, struct page *first_page,
+ unsigned long address, pte_t *ptep, pte_t pteval,
+ unsigned long nr_pages)
+{
+ unsigned long batch_idx = 0;
+
+ while (nr_pages) {
+ bool anon_exclusive = PageAnonExclusive(first_page + batch_idx);
+ unsigned long len = page_anon_exclusive_batch(batch_idx,
+ nr_pages, first_page, anon_exclusive);
+
+ if (!__ttu_anon_swapbacked_folio(vma, folio,
+ first_page + batch_idx, address, ptep, pteval,
+ len, anon_exclusive)) {
+ /* Restore the remaining PTEs that were cleared. */
+ set_ptes(vma->vm_mm, address, ptep, pteval, nr_pages);
+ return false;
+ }
+
+ nr_pages -= len;
+ if (!nr_pages)
+ break;
+
+ pteval = pte_advance_pfn(pteval, len);
+ address += len * PAGE_SIZE;
+ batch_idx += len;
+ ptep += len;
+ }
+
return true;
}
@@ -2186,15 +2227,22 @@ static bool ttu_anon_folio(struct vm_area_struct *vma, struct folio *folio,
* See handle_pte_fault() ...
*/
if (WARN_ON_ONCE(folio_test_swapbacked(folio) !=
- folio_test_swapcache(folio)))
+ folio_test_swapcache(folio))) {
+ set_ptes(vma->vm_mm, address, ptep, pteval, nr_pages);
return false;
+ }
- if (!folio_test_swapbacked(folio))
- return ttu_anon_lazyfree_folio(vma, folio, nr_pages);
+ if (!folio_test_swapbacked(folio)) {
+ if (!ttu_anon_lazyfree_folio(vma, folio, nr_pages)) {
+ set_ptes(vma->vm_mm, address, ptep, pteval, nr_pages);
+ return false;
+ }
+ finish_folio_unmap_batch(vma, folio, page, nr_pages);
+ return true;
+ }
- /* nr_pages > 1 not supported yet */
return ttu_anon_swapbacked_folio(vma, folio, page, address, ptep,
- pteval);
+ pteval, nr_pages);
}
/*
@@ -2374,13 +2422,14 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,
*/
dec_mm_counter(mm, mm_counter(folio));
} else if (folio_test_anon(folio)) {
+ /* finish_folio_unmap_batch handled internally */
if (!ttu_anon_folio(vma, folio, page, address,
- pvmw.pte, pteval, nr_pages)) {
- set_ptes(mm, address, pvmw.pte, pteval, nr_pages);
+ pvmw.pte, pteval, nr_pages))
goto walk_abort;
- }
- goto finish_unmap;
+ if (nr_pages == folio_nr_pages(folio))
+ goto walk_done;
+ continue;
} else {
/*
* This is a locked file-backed folio,
@@ -2395,11 +2444,8 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,
*/
add_mm_counter(mm, mm_counter_file(folio), -nr_pages);
}
-finish_unmap:
- folio_remove_rmap_ptes(folio, page, nr_pages, vma);
- if (vma->vm_flags & VM_LOCKED)
- mlock_drain_local();
- folio_put_refs(folio, nr_pages);
+
+ finish_folio_unmap_batch(vma, folio, page, nr_pages);
/*
* If we are sure that we batched the entire folio and cleared
@@ -2695,7 +2741,7 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma,
* architectures where we could have PFN swap PTEs,
* so we'll not check/care.
*/
- if (arch_unmap_one(mm, vma, address, pteval) < 0) {
+ if (arch_unmap_one(mm, vma, address, pteval, 1) < 0) {
if (folio_test_hugetlb(folio))
set_huge_pte_at(mm, address, pvmw.pte,
pteval, hsz);
diff --git a/mm/shmem.c b/mm/shmem.c
index 07b2855dfb7bd..2ea73d18126f5 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1916,7 +1916,7 @@ int shmem_writeout(struct swap_io_ctx *ctx, struct folio *folio,
spin_unlock(&shmem_swaplist_lock);
}
- folio_dup_swap(folio, NULL);
+ folio_dup_swap(folio);
shmem_delete_from_page_cache(folio, swp_to_radix_entry(folio->swap));
BUG_ON(folio_mapped(folio));
@@ -1937,7 +1937,7 @@ int shmem_writeout(struct swap_io_ctx *ctx, struct folio *folio,
/* Swap entry might be erased by racing shmem_free_swap() */
if (!error) {
shmem_recalc_inode(inode, 0, -nr_pages);
- folio_put_swap(folio, NULL);
+ folio_put_swap(folio);
}
/*
@@ -2370,7 +2370,7 @@ static void shmem_set_folio_swapin_error(struct inode *inode, pgoff_t index,
nr_pages = folio_nr_pages(folio);
folio_wait_writeback(folio);
- folio_put_swap(folio, NULL);
+ folio_put_swap(folio);
swap_cache_del_folio(folio);
/*
* Don't treat swapin error folio as alloced. Otherwise inode->i_blocks
@@ -2600,7 +2600,7 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,
if (sgp == SGP_WRITE)
folio_mark_accessed(folio);
- folio_put_swap(folio, NULL);
+ folio_put_swap(folio);
swap_cache_del_folio(folio);
folio_mark_dirty(folio);
put_swap_device(si);
diff --git a/mm/swap.h b/mm/swap.h
index d5bf21f517dce..891f41c4556c2 100644
--- a/mm/swap.h
+++ b/mm/swap.h
@@ -244,8 +244,10 @@ extern int swap_retry_table_alloc(swp_entry_t entry, gfp_t gfp);
* folio_put_swap(): does the opposite thing of folio_dup_swap().
*/
int folio_alloc_swap(struct folio *folio);
-int folio_dup_swap(struct folio *folio, struct page *page);
-void folio_put_swap(struct folio *folio, struct page *page);
+int folio_dup_swap_pages(struct folio *folio, struct page *page,
+ unsigned long nr_pages);
+void folio_put_swap_pages(struct folio *folio, struct page *page,
+ unsigned long nr_pages);
/* For internal use */
extern void __swap_cluster_free_entries(struct swap_info_struct *si,
@@ -368,12 +370,14 @@ static inline int folio_alloc_swap(struct folio *folio)
return -EINVAL;
}
-static inline int folio_dup_swap(struct folio *folio, struct page *page)
+static inline int folio_dup_swap_pages(struct folio *folio, struct page *page,
+ unsigned long nr_pages)
{
return -EINVAL;
}
-static inline void folio_put_swap(struct folio *folio, struct page *page)
+static inline void folio_put_swap_pages(struct folio *folio, struct page *page,
+ unsigned long nr_pages)
{
}
@@ -464,6 +468,29 @@ static inline void __swap_cache_replace_folio(struct swap_cluster_info *ci,
}
#endif /* CONFIG_SWAP */
+/**
+ * folio_dup_swap() - Increase swap count of all swap entries of a folio.
+ * @folio: folio with swap entries bound.
+ *
+ * See folio_dup_swap_pages() for more information.
+ */
+static inline int folio_dup_swap(struct folio *folio)
+{
+ return folio_dup_swap_pages(folio, folio_page(folio, 0),
+ folio_nr_pages(folio));
+}
+
+/**
+ * folio_put_swap() - Decrease swap count of all swap entries of a folio.
+ * @folio: folio with swap entries bound.
+ *
+ * See folio_put_swap_pages() for more information.
+ */
+static inline void folio_put_swap(struct folio *folio)
+{
+ folio_put_swap_pages(folio, folio_page(folio, 0), folio_nr_pages(folio));
+}
+
extern const struct swap_ops swap_bdev_ops;
int shmem_writeout(struct swap_io_ctx *ctx, struct folio *folio,
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 254ce86fa923e..5d4d293044ab0 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1799,9 +1799,10 @@ int folio_alloc_swap(struct folio *folio)
}
/**
- * folio_dup_swap() - Increase swap count of swap entries of a folio.
+ * folio_dup_swap_pages() - Increase swap count of swap entries of a folio.
* @folio: folio with swap entries bounded.
- * @page: if not NULL, only increase the swap count of this page.
+ * @page: the first page in the folio to increase the swap count for.
+ * @nr_pages: the number of pages in the folio to increase the swap count for.
*
* Typically called when the folio is unmapped and have its swap entry to
* take its place: Swap entries allocated to a folio has count == 0 and pinned
@@ -1815,45 +1816,40 @@ int folio_alloc_swap(struct folio *folio)
* swap_put_entries_direct on its swap entry before this helper returns, or
* the swap count may underflow.
*/
-int folio_dup_swap(struct folio *folio, struct page *page)
+int folio_dup_swap_pages(struct folio *folio, struct page *page,
+ unsigned long nr_pages)
{
- swp_entry_t entry = folio->swap;
- unsigned long nr_pages = folio_nr_pages(folio);
+ swp_entry_t entry = folio_page_swap_entry(folio, page);
+ unsigned long idx = folio_page_idx(folio, page);
VM_WARN_ON_FOLIO(!folio_test_locked(folio), folio);
VM_WARN_ON_FOLIO(!folio_test_swapcache(folio), folio);
-
- if (page) {
- entry = folio_page_swap_entry(folio, page);
- nr_pages = 1;
- }
+ VM_WARN_ON_FOLIO(idx + nr_pages > folio_nr_pages(folio), folio);
return swap_dup_entries_cluster(swap_entry_to_info(entry),
swp_offset(entry), nr_pages);
}
/**
- * folio_put_swap() - Decrease swap count of swap entries of a folio.
+ * folio_put_swap_pages() - Decrease swap count of swap entries of a folio.
* @folio: folio with swap entries bounded, must be in swap cache and locked.
- * @page: if not NULL, only decrease the swap count of this page.
+ * @page: the first page in the folio to decrease the swap count for.
+ * @nr_pages: the number of pages in the folio to decrease the swap count for.
*
* This won't free the swap slots even if swap count drops to zero, they are
* still pinned by the swap cache. User may call folio_free_swap to free them.
* Context: Caller must ensure the folio is locked and in the swap cache.
*/
-void folio_put_swap(struct folio *folio, struct page *page)
+void folio_put_swap_pages(struct folio *folio, struct page *page,
+ unsigned long nr_pages)
{
- swp_entry_t entry = folio->swap;
- unsigned long nr_pages = folio_nr_pages(folio);
+ swp_entry_t entry = folio_page_swap_entry(folio, page);
struct swap_info_struct *si = __swap_entry_to_info(entry);
+ unsigned long idx = folio_page_idx(folio, page);
VM_WARN_ON_FOLIO(!folio_test_locked(folio), folio);
VM_WARN_ON_FOLIO(!folio_test_swapcache(folio), folio);
-
- if (page) {
- entry = folio_page_swap_entry(folio, page);
- nr_pages = 1;
- }
+ VM_WARN_ON_FOLIO(idx + nr_pages > folio_nr_pages(folio), folio);
swap_put_entries_cluster(si, swp_offset(entry), nr_pages, false);
}
@@ -2598,7 +2594,8 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd,
setpte:
set_pte_at(vma->vm_mm, addr, pte, new_pte);
- folio_put_swap(swapcache, folio_file_page(swapcache, swp_offset(entry)));
+ folio_put_swap_pages(swapcache,
+ folio_file_page(swapcache, swp_offset(entry)), 1);
out:
if (pte)
pte_unmap_unlock(pte, ptl);
|
| 3/2 | 2026/09/26 18:21 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 13698 output: 26 thoughts: 978 Thoughts: **Patch Series Evaluation for Syzkaller Fuzzing** Okay, so the user wants me to assess this patch series targeting syzkaller fuzzing on amd64. Let's break this down. From a quick glance at the diff, I'm seeing changes across several core memory management files, and even some SPARC-specific code, which is interesting, but the emphasis is definitely on `mm/`. The fact that it touches `arch/sparc` is not surprising as the memory management layer is often arch-agnostic, but changes to those functions can affect more than one architecture. Specifically, it looks like this patch is introducing batch unmapping of anonymous, swapbacked folios. This is a significant optimization, and could expose a range of new or deeper code paths. The changes include modifications to: * `include/linux/pgtable.h`: The `arch_unmap_one` signature is updated to take in `nr`, presumably indicating the number of pages. * `include/linux/rmap.h`: The move of `page_anon_exclusive_batch` and changes with `__folio_try_share_anon_rmap` are clear indicators of this batching logic. * `mm/internal.h`: Renaming the swap functions to `softleaf` suggests the patch is handling a memory-related structure change. * `mm/memory.c`: The use of `set_softleaf_ptes`, along with `can_swapin_thp` and `do_swap_page`, indicates this batching is deeply integrated with swap operations. * `mm/mprotect.c` & `mm/rmap.c`: These are key areas, where the batching and the implementation of handling it are the crux of the patch. * `mm/shmem.c`: Updates to swap handling, and * `mm/swap.h`/`mm/swapfile.c`: The changes in these files for swap functions. This is all about improving the efficiency of how the kernel manages swap-backed anonymous pages, which, in turn, helps large folios, THP, or mTHP. This is a solid candidate for syzkaller coverage, especially in standard virtualized environments. Based on the criteria, specifically Section 3, this is definitively `WorthFuzzing=true`. It's modifying core mm logic, adding assertions (`VM_WARN_ON_FOLIO`), and changing the flow of how memory is managed. We're well within the "core subsystems" and "refactoring/code cleanup" categories. Now, I need to figure out the best `EnableConfigs` and `FocusSymbols`, and write some concise reasoning. |
| 4/2 | 2026/09/26 18:21 | tool | grepper |
0mArgs:{
"Expression": "CONFIG_SWAP",
"PathPrefix": "mm/"
}Results: {
"Output": "mm/Makefile=77=endif\nmm/Makefile-78-\nmm/Makefile:79:obj-$(CONFIG_SWAP)\t+= page_io.o swap_state.o swapfile.o\nmm/Makefile-80-obj-$(CONFIG_ZSWAP)\t+= zswap.o\n--\nmm/filemap.c=4636=static void filemap_cachestat(struct address_space *mapping,\n--\nmm/filemap.c-4683-\nmm/filemap.c:4684:#ifdef CONFIG_SWAP /* implies CONFIG_MMU */\nmm/filemap.c-4685-\t\t\tif (shmem_mapping(mapping)) {\n--\nmm/ksm.c=3136=struct folio *ksm_might_need_to_copy(struct folio *folio,\n--\nmm/ksm.c-3175-\t\t__folio_set_locked(new_folio);\nmm/ksm.c:3176:#ifdef CONFIG_SWAP\nmm/ksm.c-3177-\t\tcount_vm_event(KSM_SWPIN_COPY);\n--\nmm/madvise.c=152=static int madvise_update_vma(vm_flags_t new_flags,\n--\nmm/madvise.c-195-\nmm/madvise.c:196:#ifdef CONFIG_SWAP\nmm/madvise.c-197-static int swapin_walk_pmd_entry(pmd_t *pmd, unsigned long start,\n--\nmm/madvise.c=244=static void shmem_swapin_range(struct vm_area_struct *vma,\n--\nmm/madvise.c-279-}\nmm/madvise.c:280:#endif\t\t/* CONFIG_SWAP */\nmm/madvise.c-281-\n--\nmm/madvise.c=291=static long madvise_willneed(struct madvise_behavior *madv_behavior)\n--\nmm/madvise.c-299-\nmm/madvise.c:300:#ifdef CONFIG_SWAP\nmm/madvise.c-301-\tif (vma_is_cow_mapping(vma) \u0026\u0026 vma-\u003eanon_vma) {\n--\nmm/memcontrol-v1.c=247=void memcg1_commit_charge(struct folio *folio, struct mem_cgroup *memcg)\n--\nmm/memcontrol-v1.c-256-\nmm/memcontrol-v1.c:257:#ifdef CONFIG_SWAP\nmm/memcontrol-v1.c-258-/**\n--\nmm/memcontrol-v1.c=1825=static const unsigned int memcg1_stats[] = {\n--\nmm/memcontrol-v1.c-1836-\tWORKINGSET_REFAULT_FILE,\nmm/memcontrol-v1.c:1837:#ifdef CONFIG_SWAP\nmm/memcontrol-v1.c-1838-\tMEMCG_SWAP,\n--\nmm/memcontrol-v1.c=1843=static const char *const memcg1_stat_names[] = {\n--\nmm/memcontrol-v1.c-1854-\t\"workingset_refault_file\",\nmm/memcontrol-v1.c:1855:#ifdef CONFIG_SWAP\nmm/memcontrol-v1.c-1856-\t\"swap\",\n--\nmm/memcontrol.c=395=static const unsigned int memcg_node_stat_items[] = {\n--\nmm/memcontrol.c-423-\tNR_SECONDARY_PAGETABLE,\nmm/memcontrol.c:424:#ifdef CONFIG_SWAP\nmm/memcontrol.c-425-\tNR_SWAPCACHE,\n--\nmm/memcontrol.c=613=static const unsigned int memcg_vm_event_stat[] = {\n--\nmm/memcontrol.c-625-\tPGLAZYFREED,\nmm/memcontrol.c:626:#ifdef CONFIG_SWAP\nmm/memcontrol.c-627-\tSWPIN_ZERO,\n--\nmm/memcontrol.c=1610=static const struct memory_stat memory_stats[] = {\n--\nmm/memcontrol.c-1628-\t{ \"file_writeback\",\t\tNR_WRITEBACK\t\t\t},\nmm/memcontrol.c:1629:#ifdef CONFIG_SWAP\nmm/memcontrol.c-1630-\t{ \"swapcached\",\t\t\tNR_SWAPCACHE\t\t\t},\n--\nmm/memcontrol.c=5923=int __init mem_cgroup_init(void)\n--\nmm/memcontrol.c-5960-\nmm/memcontrol.c:5961:#ifdef CONFIG_SWAP\nmm/memcontrol.c-5962-/**\n--\nmm/memcontrol.c=6445=subsys_initcall(mem_cgroup_swap_init);\nmm/memcontrol.c-6446-\nmm/memcontrol.c:6447:#endif /* CONFIG_SWAP */\nmm/memcontrol.c-6448-\n--\nmm/migrate.c=583=static int __folio_migrate_mapping(struct address_space *mapping,\n--\nmm/migrate.c-703-\t\t}\nmm/migrate.c:704:#ifdef CONFIG_SWAP\nmm/migrate.c-705-\t\tif (folio_test_swapcache(folio)) {\n--\nmm/mincore.c=48=static unsigned char mincore_swap(swp_entry_t entry, bool shmem)\n--\nmm/mincore.c-61-\nmm/mincore.c:62:\tif (!IS_ENABLED(CONFIG_SWAP)) {\nmm/mincore.c-63-\t\tWARN_ON(1);\n--\nmm/swap.h=85=static inline int mem_cgroup_swappiness(const struct mem_cgroup *memcg)\n--\nmm/swap.h-94-\nmm/swap.h:95:#ifdef CONFIG_SWAP\nmm/swap.h-96-#include \u003clinux/swapops.h\u003e /* for swp_offset */\n--\nmm/swap.h=338=void swap_update_readahead(struct folio *folio, struct vm_area_struct *vma,\n--\nmm/swap.h-340-\nmm/swap.h:341:#else /* CONFIG_SWAP */\nmm/swap.h-342-\n--\nmm/swap.h=465=static inline void __swap_cache_replace_folio(struct swap_cluster_info *ci,\n--\nmm/swap.h-468-}\nmm/swap.h:469:#endif /* CONFIG_SWAP */\nmm/swap.h-470-\n--\nmm/vma_init.c=45=static void vm_area_init_from(const struct vm_area_struct *src,\n--\nmm/vma_init.c-69-#endif\nmm/vma_init.c:70:#ifdef CONFIG_SWAP\nmm/vma_init.c-71-\tmemcpy(\u0026dest-\u003eswap_readahead_info, \u0026src-\u003eswap_readahead_info,\n--\nmm/vmscan.c=345=static bool can_demote(int nid, struct scan_control *sc,\n--\nmm/vmscan.c-364-\nmm/vmscan.c:365:#ifdef CONFIG_SWAP\nmm/vmscan.c-366-static inline bool reclaimable_anon_is_low(struct mem_cgroup *memcg,\n--\nmm/vmscan.c=404=static inline bool reclaimable_anon_is_low(struct mem_cgroup *memcg,\n--\nmm/vmscan.c-408-}\nmm/vmscan.c:409:#endif /* CONFIG_SWAP */\nmm/vmscan.c-410-\n--\nmm/vmstat.c=1199=const char * const vmstat_text[] = {\n--\nmm/vmstat.c-1279-#endif\nmm/vmstat.c:1280:#ifdef CONFIG_SWAP\nmm/vmstat.c-1281-\t[I(NR_SWAPCACHE)]\t\t\t= \"nr_swapcached\",\n--\nmm/vmstat.c-1452-\nmm/vmstat.c:1453:#ifdef CONFIG_SWAP\nmm/vmstat.c-1454-\t[I(SWAP_RA)]\t\t\t\t= \"swap_ra\",\n--\nmm/vmstat.c-1505-#endif /* CONFIG_DEBUG_STACK_USAGE */\nmm/vmstat.c:1506:#ifdef CONFIG_SWAP\nmm/vmstat.c-1507-\t[I(NRSWPIN)]\t\t\t\t= \"nrswpin\",\nmm/vmstat.c-1508-\t[I(NRSWPOUT)]\t\t\t\t= \"nrswpout\",\nmm/vmstat.c:1509:#endif /* CONFIG_SWAP */\nmm/vmstat.c-1510-#undef I\n"
} |
| 5/2 | 2026/09/26 18:21 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 17566 output: 27 thoughts: 91 Thoughts: Okay, let's dive into this. Here's how I'm thinking through this: **Analyzing Relevant Kconfig Options for Swap File Functionality** Alright, I need to figure out which Kconfig options are driving the compilation of `swapfile.c`. My initial thought is to check if `CONFIG_SWAP` is involved, since the build system comment indicates it's conditional (`obj-$(CONFIG_SWAP) += page_io.o swap_state.o swapfile.o`). That seems like the obvious starting point. While I'm at it, I should also consider how Transparent Huge Pages, or `CONFIG_TRANSPARENT_HUGEPAGE`, might play a role here. THP affects large folios, and anonymous memory might be relevant to swap. Now, I'll dive into the `Kconfig` files directly to confirm my initial hypothesis about `CONFIG_SWAP` and get a better understanding of its dependencies and implications. It's time to trace the config settings. |
| 6/2 | 2026/09/26 18:21 | tool | grepper |
0mArgs:{
"Expression": "config SWAP\\b",
"PathPrefix": "mm/"
}Results: {
"Output": "mm/Kconfig=9=config ARCH_NO_SWAP\n--\nmm/Kconfig-11-\nmm/Kconfig:12:menuconfig SWAP\nmm/Kconfig-13-\tbool \"Support for paging of anonymous memory (swap)\"\n"
} |
| 7/2 | 2026/09/26 18:21 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 17972 output: 31 thoughts: 16 Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person: **Analyzing the Kconfig for Memory Management** Alright, so the first step in understanding this aspect of the system is clear: let's dive straight into the heart of the matter. My initial thought is to examine the `mm/Kconfig` file, specifically around line 12. This likely contains crucial configuration options related to memory management. I suspect we'll be dealing with the core knobs that control how memory is allocated, managed, and protected. This will probably include things like NUMA support, page size configurations, memory hotplug options, or even potentially some architectural-specific memory features. Line 12 likely serves as a good entry point to get a broad overview of the available configuration parameters, their dependencies, and any default values assigned to these critical memory management settings. My immediate goal is to establish a basic map of the configurable landscape. From there, I can determine which are most relevant to the particular investigation I'm undertaking. |
| 8/2 | 2026/09/26 18:21 | tool | read-file |
0mArgs:{
"File": "mm/Kconfig",
"FirstLine": 10,
"LineCount": 30
}Results: {
"Contents": " 10:\t\tbool\n 11:\t\n 12:\tmenuconfig SWAP\n 13:\t\tbool \"Support for paging of anonymous memory (swap)\"\n 14:\t\tdepends on MMU \u0026\u0026 BLOCK \u0026\u0026 !ARCH_NO_SWAP\n 15:\t\tdefault y\n 16:\t\thelp\n 17:\t\t This option allows you to choose whether you want to have support\n 18:\t\t for so called swap devices or swap files in your kernel that are\n 19:\t\t used to provide more virtual memory than the actual RAM present\n 20:\t\t in your computer. If unsure say Y.\n 21:\t\n 22:\tconfig ZSWAP\n 23:\t\tbool \"Compressed cache for swap pages\"\n 24:\t\tdepends on SWAP\n 25:\t\tselect CRYPTO\n 26:\t\tselect ZSMALLOC\n 27:\t\thelp\n 28:\t\t A lightweight compressed cache for swap pages. It takes\n 29:\t\t pages that are in the process of being swapped out and attempts to\n 30:\t\t compress them into a dynamically allocated RAM-based memory pool.\n 31:\t\t This can result in a significant I/O reduction on swap device and,\n 32:\t\t in the case where decompressing from RAM is faster than swap device\n 33:\t\t reads, can also improve workload performance.\n 34:\t\n 35:\tconfig ZSWAP_DEFAULT_ON\n 36:\t\tbool \"Enable the compressed cache for swap pages by default\"\n 37:\t\tdepends on ZSWAP\n 38:\t\thelp\n 39:\t\t If selected, the compressed cache for swap pages will be enabled\n"
} |
| 9/2 | 2026/09/26 18:21 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 18657 output: 32 thoughts: 205 Thoughts: Here's my thought process, as I analyze this code snippet: **Analyzing Anonymous Folio Unmapping with Large Pages** Okay, so I'm looking at how anonymous folios are unmapped in this particular scenario. My initial thought is to dive into the `TRANSPARENT_HUGEPAGE` configuration. I see the code is specifically targeting the batch unmapping of anonymous folios when they are considered large. The core logic hinges on `folio_unmap_pte_batch()`. I immediately zero in on those crucial checks within that function: if `TTU_HWPOISON` is set, or if the folio isn't a large folio according to `folio_test_large()`, the function bails out early. Therefore, for this batch unmapping optimization to even be relevant, the folios in question must meet the criteria of being large, and not be hardware-poisoned. The `folio_test_large()` function is key here. Given the context, it strongly suggests that for anonymous folios to be considered "large," we *must* have `CONFIG_TRANSPARENT_HUGEPAGE` enabled. This linkage feels critical, as this seems to be the gateway for THP size anonymous folios. Now, I'll need to confirm that. I'm going to shift gears and dig into the code related to anonymous folio creation to understand how large anonymous folios are actually instantiated. Specifically, I'll want to check the relation between mTHP or THP and `CONFIG_TRANSPARENT_HUGEPAGE` within the Linux memory management (mm) subsystem. Finally, I need to ensure there are no other configurations that play a role, or that this configuration is contingent on some other specific dependencies. Let me verify the dependencies of `CONFIG_TRANSPARENT_HUGEPAGE`. |
| 10/2 | 2026/09/26 18:21 | tool | grepper |
0mArgs:{
"Expression": "config TRANSPARENT_HUGEPAGE\\b",
"PathPrefix": "mm/"
}Results: {
"Output": "mm/Kconfig=831=config MM_ID\n--\nmm/Kconfig-833-\nmm/Kconfig:834:menuconfig TRANSPARENT_HUGEPAGE\nmm/Kconfig-835-\tbool \"Transparent Hugepage Support\"\n"
} |
| 11/2 | 2026/09/26 18:21 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 19356 output: 42 thoughts: 1491 Thoughts: **Analyzing Recent Page Table Batching Changes** Okay, let's dive into these changes. My primary focus is on how they're impacting the `folio_pte_batch` and `swap_pte_batch` mechanisms. Let's see what's happened across the codebase. First, I see some SPARC-related ADI tag saving in `arch/sparc/kernel/adi_64.c`, but that's not relevant to my work on amd64, so I'm skipping that. In `include/linux/pgtable.h`, the default `arch_unmap_one` stub now correctly takes a `nr` parameter. Good, that's a positive step towards more generalized handling. `include/linux/rmap.h` looks interesting. I see a new static inline `page_anon_exclusive_batch` and a related static __always_inline function, `__folio_try_share_anon_rmap`. It now takes a `nr_pages` parameter, which is a key signal. The inclusion of a `VM_WARN_ON_FOLIO` check in `__folio_try_share_anon_rmap` signals that this is intended to catch potential bugs and that a batching scheme is being enabled. I'll need to pay close attention to how it's being used. There's also `folio_try_share_anon_rmap_ptes`, which inlines the above call. `mm/internal.h` has the core of it, with `pte_move_softleaf_offset` (formerly `pte_move_swp_offset`), `pte_next_softleaf_offset`, `set_softleaf_ptes`, and `swap_pte_batch`. The new `set_softleaf_ptes` seems to be intended to operate on a batch of PTEs, based on the `nr` parameter. This is a crucial area. In `mm/memory.c`, `cond_install_uffd_wp_ptes` now utilizes `set_softleaf_ptes` instead of a manual loop, which is cleaner. `can_swapin_thp` and `do_swap_page` are calling `pte_move_softleaf_offset`, and there are now calls to `folio_put_swap` and the new `folio_put_swap_pages`, suggesting that swap handling is being optimized for folio batching. `mm/mprotect.c` has a duplicate definition that was removed. `mm/rmap.c` is where things get really interesting. The restriction on batching for anonymous swapbacked folios has been removed in `folio_unmap_pte_batch`. This is a significant change! The addition of `finish_folio_unmap_batch` and `__ttu_anon_swapbacked_folio`, along with the new `ttu_anon_swapbacked_folio` and `ttu_anon_folio` functions, strongly indicates that batching is now enabled for anonymous, swap-backed folios. The calls to `folio_dup_swap_pages`, `arch_unmap_one`, and `folio_try_share_anon_rmap_ptes` within `__ttu_anon_swapbacked_folio` confirm this. The counter updates for `MM_ANONPAGES` and `MM_SWAPENTS`, and installation of swap PTEs via `set_softleaf_ptes` further support this. `try_to_unmap_one` now correctly handles `folio_test_anon(folio)` batching. `try_to_migrate_one` now calls `arch_unmap_one` with `1`. In `mm/shmem.c`, I see simplified signatures for `folio_dup_swap` and `folio_put_swap`, which now take just the folio. In `mm/swap.h`, there are new functions: `folio_alloc_swap`, `folio_dup_swap_pages`, `folio_put_swap_pages`, and the old `folio_dup_swap` and `folio_put_swap` are updated to call these new batching functions. `mm/swapfile.c` now includes batch-aware logic with `folio_dup_swap_pages` and `folio_put_swap_pages`, including assertions to ensure the batch doesn't exceed the folio size, and calls to `swap_dup_entries_cluster` and `swap_put_entries_cluster`. `unuse_pte` is also updated to use `folio_put_swap_pages` with a batch size of 1. I need to confirm the visibility of `try_to_unmap_one`. My next step is to examine the symbol visibility. I'm especially |
| 12/2 | 2026/09/26 18:21 | tool | grepper |
0mArgs:{
"Expression": "(try_to_unmap_one|try_to_unmap)",
"PathPrefix": "mm/rmap.c"
}Results: {
"Output": "mm/rmap.c=635=struct anon_vma *folio_lock_anon_vma_read(const struct folio *folio,\n--\nmm/rmap.c-712- */\nmm/rmap.c:713:void try_to_unmap_flush(void)\nmm/rmap.c-714-{\n--\nmm/rmap.c-725-/* Flush iff there are potentially writable TLB entries that can race with IO */\nmm/rmap.c:726:void try_to_unmap_flush_dirty(void)\nmm/rmap.c-727-{\n--\nmm/rmap.c-730-\tif (tlb_ubc-\u003ewritable)\nmm/rmap.c:731:\t\ttry_to_unmap_flush();\nmm/rmap.c-732-}\n--\nmm/rmap.c=744=static void set_tlb_ubc_flush_pending(struct mm_struct *mm, pte_t pteval,\n--\nmm/rmap.c-777-\t * If the PTE was dirty then it's best to assume it's writable. The\nmm/rmap.c:778:\t * caller must use try_to_unmap_flush_dirty() or try_to_unmap_flush()\nmm/rmap.c-779-\t * before the page is queued for IO.\n--\nmm/rmap.c=1952=static inline unsigned int folio_unmap_pte_batch(struct folio *folio,\n--\nmm/rmap.c-1982-\nmm/rmap.c:1983:static bool try_to_unmap_poisoned_hugetlb_one(struct folio *folio,\nmm/rmap.c-1984-\t\tstruct vm_area_struct *vma, unsigned long address, void *arg)\n--\nmm/rmap.c-1994-\t/*\nmm/rmap.c:1995:\t * The try_to_unmap() is only passed a hugetlb folio in the case\nmm/rmap.c-1996-\t * where the hugetlb folio is poisoned.\n--\nmm/rmap.c=2221=static bool ttu_anon_folio(struct vm_area_struct *vma, struct folio *folio,\n--\nmm/rmap.c-2250- */\nmm/rmap.c:2251:static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,\nmm/rmap.c-2252-\t\t unsigned long address, void *arg)\n--\nmm/rmap.c-2267-\t * in between its ptep_get_and_clear_full() and folio_remove_rmap_*(),\nmm/rmap.c:2268:\t * try_to_unmap() may return before folio_mapped() has become false,\nmm/rmap.c-2269-\t * if page table locking is skipped: use TTU_SYNC to wait for that.\n--\nmm/rmap.c-2277-\t * Note that the folio can not be freed in this function as call of\nmm/rmap.c:2278:\t * try_to_unmap() must hold a reference on the folio.\nmm/rmap.c-2279-\t */\n--\nmm/rmap.c=2474=static int folio_not_mapped(struct folio *folio)\n--\nmm/rmap.c-2479-/**\nmm/rmap.c:2480: * try_to_unmap - Try to remove all page table mappings to a folio.\nmm/rmap.c-2481- * @folio: The folio to unmap.\n--\nmm/rmap.c-2489- */\nmm/rmap.c:2490:void try_to_unmap(struct folio *folio, enum ttu_flags flags)\nmm/rmap.c-2491-{\n--\nmm/rmap.c-2493-\t\t.rmap_one = folio_test_hugetlb(folio) ?\nmm/rmap.c:2494:\t\t\t\ttry_to_unmap_poisoned_hugetlb_one : try_to_unmap_one,\nmm/rmap.c-2495-\t\t.arg = (void *)flags,\n--\nmm/rmap.c=2512=static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma,\n--\nmm/rmap.c-2539-\t * Note that the page can not be free in this function as call of\nmm/rmap.c:2540:\t * try_to_unmap() must hold a reference on the page.\nmm/rmap.c-2541-\t */\n"
} |
| 13/2 | 2026/09/26 18:21 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 23090 output: 32 thoughts: 349 Thoughts: **Analyzing Potential Inlining and Symbol Visibility** Okay, let's break this down. I'm looking at how `try_to_unmap_one` is handled within the context of `try_to_unmap`. I see that the address of `try_to_unmap_one` is being passed as a function pointer to the `rmap_one` field of the `rmap_walk_control` structure. This is significant because, as a consequence, the compiler *won't* inline it. It'll be a real, tangible symbol in the kernel image, `vmlinux`. That's important for debugging, symbol lookups, and potentially for instrumentation. And `try_to_unmap` seems to be the entry point to that functionality. Next, I'm shifting my focus to `mm/swapfile.c` to see if there are similar patterns with swap page operations. I'm specifically curious about `folio_dup_swap_pages` and `folio_put_swap_pages`. Are they static functions or are they publicly accessible symbols? Yes, it appears they are defined as non-static, global symbols in `mm/swapfile.c`. So, they too have a visible, external interface. Finally, I'm looking at `do_swap_page` in `mm/memory.c`, and my initial question is if that routine is declared as static. Let me quickly check the source code in `mm/memory.c` to confirm. |
| 14/2 | 2026/09/26 18:21 | tool | grepper |
0mArgs:{
"Expression": "vm_fault_t do_swap_page",
"PathPrefix": "mm/"
}Results: {
"Output": "mm/internal.h=602=static inline vm_fault_t vmf_anon_prepare(struct vm_fault *vmf)\n--\nmm/internal.h-610-\nmm/internal.h:611:vm_fault_t do_swap_page(struct vm_fault *vmf);\nmm/internal.h-612-void folio_rotate_reclaimable(struct folio *folio);\n--\nmm/memory.c=4919=static void check_swap_exclusive(struct folio *folio, swp_entry_t entry,\n--\nmm/memory.c-4936- */\nmm/memory.c:4937:vm_fault_t do_swap_page(struct vm_fault *vmf)\nmm/memory.c-4938-{\n"
} |
| 15/2 | 2026/09/26 18:21 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 23996 output: 29 thoughts: 343 Thoughts: **My Reasoning on Function Selection for Focused Fuzzing** Okay, hold on a second! Before I finalize this list for the fuzzer, I need to remember the crucial advice from Section 4. Specifically, avoid those *ubiquitous lifecycle hot-paths*. We want to be *focused*, not dilute the effort with functions that are called everywhere. Generic allocators, deallocators, core synch primitives, things like that are right out. So, is `do_swap_page` a candidate? Well, it's *specifically* for swap page faults. That's a good sign. But standard page faults might not even involve swap unless the memory has been paged out. Hmm. Then again, `folio_dup_swap_pages`, `folio_put_swap_pages`, `try_to_unmap_one`, and `try_to_unmap` seem *directly* related to unmapping folios and managing swap references. That sounds promising. Now, the real test. Is `try_to_unmap` too ubiquitous? It's used in memory reclaim via `shrink_folio_list`, memory migration, DAMON, MADV_PAGEOUT... That's a red flag. Let me see *who* is calling it. Gotta check to see how ubiquitous it really is. A quick grep of the `mm/` directory should clear that up. |
| 16/2 | 2026/09/26 18:21 | tool | grepper |
0mArgs:{
"Expression": "try_to_unmap\\(",
"PathPrefix": "mm/"
}Results: {
"Output": "mm/huge_memory.c=3533=static int unmap_folio(struct folio *folio)\n--\nmm/huge_memory.c-3553-\telse\nmm/huge_memory.c:3554:\t\ttry_to_unmap(folio, ttu_flags | TTU_IGNORE_MLOCK);\nmm/huge_memory.c-3555-\n--\nmm/khugepaged.c=2213=static enum scan_result collapse_file(struct mm_struct *mm, unsigned long addr,\n--\nmm/khugepaged.c-2400-\t\tif (folio_mapped(folio))\nmm/khugepaged.c:2401:\t\t\ttry_to_unmap(folio,\nmm/khugepaged.c-2402-\t\t\t\t\tTTU_IGNORE_MLOCK | TTU_BATCH_FLUSH);\n--\nmm/khugepaged.c-2427-\t\t * At this point, the folio is locked and unmapped. If the PTE\nmm/khugepaged.c:2428:\t\t * was dirty, try_to_unmap() has transferred the dirty bit to\nmm/khugepaged.c-2429-\t\t * the folio and we must not collapse it into a clean\n--\nmm/memory-failure.c=821=static int kill_accessing_process(struct task_struct *p, unsigned long pfn,\n--\nmm/memory-failure.c-836-\t/*\nmm/memory-failure.c:837:\t * ret = 1 when CMCI wins, regardless of whether try_to_unmap()\nmm/memory-failure.c-838-\t * succeeds or fails, then kill the process with SIGBUS.\n--\nmm/memory-failure.c=1064=static int me_pagecache_dirty(struct page_state *ps, struct page *p)\n--\nmm/memory-failure.c-1089- * normal PTEs and swap PTEs. We try to handle them consistently by calling\nmm/memory-failure.c:1090: * try_to_unmap(!TTU_HWPOISON) to convert the normal PTEs to swap PTEs,\nmm/memory-failure.c-1091- * and then\n--\nmm/memory-failure.c=1549=static int get_hwpoison_page(struct page *p, unsigned long flags)\n--\nmm/memory-failure.c-1564- * The caller must guarantee the folio isn't large folio, except hugetlb.\nmm/memory-failure.c:1565: * try_to_unmap() can't handle it.\nmm/memory-failure.c-1566- */\nmm/memory-failure.c=1567=int unmap_poisoned_folio(struct folio *folio, unsigned long pfn, bool must_kill)\n--\nmm/memory-failure.c-1609-\nmm/memory-failure.c:1610:\t\ttry_to_unmap(folio, ttu|TTU_RMAP_LOCKED);\nmm/memory-failure.c-1611-\t\ti_mmap_unlock_write(mapping);\nmm/memory-failure.c-1612-\t} else {\nmm/memory-failure.c:1613:\t\ttry_to_unmap(folio, ttu);\nmm/memory-failure.c-1614-\t}\n--\nmm/memory-failure.c=1623=static bool hwpoison_user_mappings(struct folio *folio, struct page *p,\n--\nmm/memory-failure.c-1660-\t/*\nmm/memory-failure.c:1661:\t * try_to_unmap() might put mlocked page in lru cache, so call\nmm/memory-failure.c-1662-\t * shake_page() again to ensure that it's flushed.\n--\nmm/migrate.c=1212=static int migrate_folio_unmap(new_folio_t get_new_folio,\n--\nmm/migrate.c-1319-\t * and treated as swapcache but it has no rmap yet.\nmm/migrate.c:1320:\t * Calling try_to_unmap() against a src-\u003emapping==NULL page will\nmm/migrate.c-1321-\t * trigger a BUG. So handle it here.\n--\nmm/migrate.c=1362=static int migrate_folio_move(free_folio_t put_new_folio, unsigned long private,\n--\nmm/migrate.c-1471- * This means that when we try to migrate hugepage whose subpages are\nmm/migrate.c:1472: * doing direct I/O, some references remain after try_to_unmap() and\nmm/migrate.c-1473- * hugepage migration fails without data corruption.\n--\nmm/rmap.c=1983=static bool try_to_unmap_poisoned_hugetlb_one(struct folio *folio,\n--\nmm/rmap.c-1994-\t/*\nmm/rmap.c:1995:\t * The try_to_unmap() is only passed a hugetlb folio in the case\nmm/rmap.c-1996-\t * where the hugetlb folio is poisoned.\n--\nmm/rmap.c=2251=static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,\n--\nmm/rmap.c-2267-\t * in between its ptep_get_and_clear_full() and folio_remove_rmap_*(),\nmm/rmap.c:2268:\t * try_to_unmap() may return before folio_mapped() has become false,\nmm/rmap.c-2269-\t * if page table locking is skipped: use TTU_SYNC to wait for that.\n--\nmm/rmap.c-2277-\t * Note that the folio can not be freed in this function as call of\nmm/rmap.c:2278:\t * try_to_unmap() must hold a reference on the folio.\nmm/rmap.c-2279-\t */\n--\nmm/rmap.c=2474=static int folio_not_mapped(struct folio *folio)\n--\nmm/rmap.c-2489- */\nmm/rmap.c:2490:void try_to_unmap(struct folio *folio, enum ttu_flags flags)\nmm/rmap.c-2491-{\n--\nmm/rmap.c=2512=static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma,\n--\nmm/rmap.c-2539-\t * Note that the page can not be free in this function as call of\nmm/rmap.c:2540:\t * try_to_unmap() must hold a reference on the page.\nmm/rmap.c-2541-\t */\n--\nmm/truncate.c=180=static int folio_split_or_unmap(struct folio *folio, struct page *split_at,\n--\nmm/truncate.c-198-\tif (ret \u0026\u0026 !shmem_mapping(folio-\u003emapping)) {\nmm/truncate.c:199:\t\ttry_to_unmap(folio, ttu_flags);\nmm/truncate.c-200-\t\tWARN_ON(folio_mapped(folio));\n--\nmm/vmscan.c=1161=static unsigned int shrink_folio_list(struct list_head *folio_list,\n--\nmm/vmscan.c-1456-\nmm/vmscan.c:1457:\t\t\ttry_to_unmap(folio, flags);\nmm/vmscan.c-1458-\t\t\tif (folio_mapped(folio)) {\n"
} |
| 17/2 | 2026/09/26 18:21 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 26599 output: 33 thoughts: 892 Thoughts: **Analyzing Unmapping and Swap Functionality in the Kernel** Okay, so I'm diving into this unmapping code, and it looks like `try_to_unmap` is the crucial entry point for unmapping a folio during page reclaim, splitting, poisoning, or khugepaged collapse. `try_to_unmap_one` is that core rmap walk callback. Let me just check real quick if `try_to_unmap_one` is inlined or has a symbol. Aha, it's `static bool try_to_unmap_one(...)`, but because its address is taken (it's used in `.rmap_one = ... try_to_unmap_one`), the compiler *should* preserve the function symbol. Now, hold on... what about those `folio_dup_swap_pages` and `folio_put_swap_pages` functions? They're non-static in `mm/swapfile.c`. I need to broaden my scope. Let's see what else has been touched. In `mm/rmap.c`, there's `try_to_unmap` (which calls `try_to_unmap_one`), `try_to_unmap_one` itself, plus some static helpers like `ttu_anon_folio`, `ttu_anon_swapbacked_folio`, `__ttu_anon_swapbacked_folio`, and `finish_folio_unmap_batch`, and then `try_to_migrate_one` is there as well. Then in `mm/swapfile.c`, there's `folio_dup_swap_pages`, `folio_put_swap_pages`, and `unuse_pte` (which is static). And finally, in `mm/memory.c`, there's `cond_install_uffd_wp_ptes` and `do_swap_page`. Wait, `do_swap_page` is the *swap-in* handler – it's *not* the ubiquitous page fault handler (`handle_mm_fault` or `__handle_mm_fault` and then `do_anonymous_page`). I need to be careful with that. I remember those guidelines: Avoid listing general, ubiquitous functions like page fault handlers, *especially* if the changes don't center on those general handlers. It'll throw off the fuzzing focus. I remember it clearly: page fault handlers are explicitly called out, so I'll avoid `do_swap_page` if it is a general function. But, if `folio_dup_swap_pages`, `folio_put_swap_pages`, `try_to_unmap_one`, and `try_to_unmap` are the *primary* places where the changes are implemented, they are better targets. Now let's see about `mm/shmem.c`. Oh, in `mm/shmem.c`: `shmem_writeout`, `shmem_set_folio_swapin_error`, `shmem_swapin_folio` saw some minor call updates related to `folio_dup_swap(folio)` and `folio_put_swap(folio)`. And what about `cond_install_uffd_wp_ptes`? That's called when unmapping with uffd-wp, right? Time to see where it's being called... |
| 18/2 | 2026/09/26 18:22 | tool | grepper |
0mArgs:{
"Expression": "cond_install_uffd_wp_ptes",
"PathPrefix": "mm/"
}Results: {
"Output": "mm/internal.h=278=void unmap_vmas(struct mmu_gather *tlb, struct unmap_desc *unmap);\n--\nmm/internal.h-281-\nmm/internal.h:282:bool cond_install_uffd_wp_ptes(struct vm_area_struct *vma,\nmm/internal.h-283-\t\tunsigned long addr, pte_t *ptep, pte_t pte,\n--\nmm/memory.c=1639=static inline bool zap_drop_markers(struct zap_details *details)\n--\nmm/memory.c-1647-/**\nmm/memory.c:1648: * cond_install_uffd_wp_ptes - install uffd-wp markers after clearing PTEs\nmm/memory.c-1649- * @vma: The VMA the pages are mapped into.\n--\nmm/memory.c-1667- */\nmm/memory.c:1668:bool cond_install_uffd_wp_ptes(struct vm_area_struct *vma,\nmm/memory.c-1669-\t\tunsigned long addr, pte_t *ptep, pte_t pte,\n--\nmm/memory.c=1716=zap_install_uffd_wp_if_needed(struct vm_area_struct *vma,\n--\nmm/memory.c-1722-\nmm/memory.c:1723:\treturn cond_install_uffd_wp_ptes(vma, addr, pte, pteval, nr);\nmm/memory.c-1724-}\n--\nmm/rmap.c=2251=static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,\n--\nmm/rmap.c-2399-\t\t */\nmm/rmap.c:2400:\t\tcond_install_uffd_wp_ptes(vma, address, pvmw.pte, pteval,\nmm/rmap.c-2401-\t\t\t\t\t nr_pages);\n"
} |
| 19/2 | 2026/09/26 18:22 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 28781 output: 30 thoughts: 970 Thoughts: **Analyzing Recent Memory Management Changes** Okay, let's break down these memory management changes, starting with the modification to `cond_install_uffd_wp_ptes` in `mm/memory.c`. I see they've switched from a loop that iteratively calls `set_pte_at` to using `set_softleaf_ptes`. This is an interesting optimization, aiming for a more efficient way to set page table entries, probably reducing overhead for a range of pages. Next, I'll examine the functions involved in the rmap subsystem. Specifically, `try_to_migrate_one` in `mm/rmap.c` is marked as static, used via `.rmap_one`, which gives me a clue about its role as an internal helper. Now, let's shift focus to the new folio functions: `folio_dup_swap_pages` and `folio_put_swap_pages`. They're replacements for the older `folio_dup_swap` and `folio_put_swap`, which suggests an improvement for handling page ranges. Checking `mm/swapfile.c`, yes, they're defined there, on lines 1816 and 1842. This is a clear indicator of the scope of these changes, and is likely where the bulk of the "swap" functionality lives. Then, `try_to_unmap_one` in `mm/rmap.c` stands out as an rmap handler, a central function where a lot of the unmapping modifications have been integrated. Coupled with its public entry point `try_to_unmap` for unmapping folios, these are two important symbols that are crucial to follow. Furthermore, `ttu_anon_swapbacked_folio` is defined as static within `mm/rmap.c` and is likely inlined into `try_to_unmap_one`. So `try_to_unmap_one` calls `ttu_anon_folio` which in turn calls `ttu_anon_swapbacked_folio`, highlighting how these functions are intertwined in the unmapping process. I need to quickly assess which symbols are directly exposed, which ones are changed, and the scope of those changes. `try_to_unmap` and `try_to_unmap_one` are exposed symbols within `vmlinux`. `folio_dup_swap_pages`, `folio_put_swap_pages`, and `cond_install_uffd_wp_ptes` are also non-static symbols that were modified. Finally, I need to check the dependencies: 1. For the `swapfile.c` changes (specifically the new `folio` functions), `CONFIG_SWAP` is obviously necessary. These functions are actually stubs when `CONFIG_SWAP` is disabled. That looks like a straightforward dependency. The `menuconfig SWAP` option, in turn, requires `MMU && BLOCK && !ARCH_NO_SWAP`. 2. Now, the patch seems to optimize anonymous swapbacked folios by batching them in `folio_unmap_pte_batch`, but first it checks if the folios are large: `if (!folio_test_large(folio)) return 1;`. Given these anonymous folios are large folios (mTHP / THP), they therefore need `CONFIG_TRANSPARENT_HUGEPAGE` enabled. Let's make sure that's correct in `mm/Kconfig`. |
| 20/2 | 2026/09/26 18:22 | tool | grepper |
0mArgs:{
"Expression": "config TRANSPARENT_HUGEPAGE",
"PathPrefix": "mm/"
}Results: {
"Output": "mm/Kconfig=831=config MM_ID\n--\nmm/Kconfig-833-\nmm/Kconfig:834:menuconfig TRANSPARENT_HUGEPAGE\nmm/Kconfig-835-\tbool \"Transparent Hugepage Support\"\n--\nmm/Kconfig=852=choice\n--\nmm/Kconfig-857-\nmm/Kconfig:858:\tconfig TRANSPARENT_HUGEPAGE_ALWAYS\nmm/Kconfig-859-\t\tbool \"always\"\n--\nmm/Kconfig-864-\nmm/Kconfig:865:\tconfig TRANSPARENT_HUGEPAGE_MADVISE\nmm/Kconfig-866-\t\tbool \"madvise\"\n--\nmm/Kconfig-873-\nmm/Kconfig:874:\tconfig TRANSPARENT_HUGEPAGE_NEVER\nmm/Kconfig-875-\t\tbool \"never\"\n--\nmm/Kconfig=881=choice\n--\nmm/Kconfig-890-\nmm/Kconfig:891:\tconfig TRANSPARENT_HUGEPAGE_SHMEM_HUGE_NEVER\nmm/Kconfig-892-\t\tbool \"never\"\n--\nmm/Kconfig-900-\nmm/Kconfig:901:\tconfig TRANSPARENT_HUGEPAGE_SHMEM_HUGE_ALWAYS\nmm/Kconfig-902-\t\tbool \"always\"\n--\nmm/Kconfig-908-\nmm/Kconfig:909:\tconfig TRANSPARENT_HUGEPAGE_SHMEM_HUGE_WITHIN_SIZE\nmm/Kconfig-910-\t\tbool \"within_size\"\n--\nmm/Kconfig-916-\nmm/Kconfig:917:\tconfig TRANSPARENT_HUGEPAGE_SHMEM_HUGE_ADVISE\nmm/Kconfig-918-\t\tbool \"advise\"\n--\nmm/Kconfig=926=choice\n--\nmm/Kconfig-935-\nmm/Kconfig:936:\tconfig TRANSPARENT_HUGEPAGE_TMPFS_HUGE_NEVER\nmm/Kconfig-937-\t\tbool \"never\"\n--\nmm/Kconfig-944-\nmm/Kconfig:945:\tconfig TRANSPARENT_HUGEPAGE_TMPFS_HUGE_ALWAYS\nmm/Kconfig-946-\t\tbool \"always\"\n--\nmm/Kconfig-952-\nmm/Kconfig:953:\tconfig TRANSPARENT_HUGEPAGE_TMPFS_HUGE_WITHIN_SIZE\nmm/Kconfig-954-\t\tbool \"within_size\"\n--\nmm/Kconfig-960-\nmm/Kconfig:961:\tconfig TRANSPARENT_HUGEPAGE_TMPFS_HUGE_ADVISE\nmm/Kconfig-962-\t\tbool \"advise\"\n"
} |
| 21/2 | 2026/09/26 18:22 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 31234 output: 33 thoughts: 74 Thoughts: Here's my thought process, as it stands: **Digging into UFFD and WP PTEs** Okay, so I'm looking into this area and need to make sure I'm not missing any other potential configuration options that relate to this functionality. The initial thought is to check if there are any other related configurations; let's see, what about `CONFIG_USERFAULTFD`? That's probably the most relevant here. And, since we're dealing with write protection and userfaultfd, the next thing that springs to mind is `cond_install_uffd_wp_ptes`. I recall that gets called, specifically, when the PTE markers are used for `UFFD_WP`. Now, I want to drill down further; the place to find the actual implementation of `cond_install_uffd_wp_ptes` is going to be in `mm/memory.c`. I need to get into the nitty gritty of how those PTEs are being set up. |
| 22/2 | 2026/09/26 18:22 | tool | grepper |
0mArgs:{
"Expression": "cond_install_uffd_wp_ptes",
"PathPrefix": "mm/"
}Results: {
"Output": "mm/internal.h=278=void unmap_vmas(struct mmu_gather *tlb, struct unmap_desc *unmap);\n--\nmm/internal.h-281-\nmm/internal.h:282:bool cond_install_uffd_wp_ptes(struct vm_area_struct *vma,\nmm/internal.h-283-\t\tunsigned long addr, pte_t *ptep, pte_t pte,\n--\nmm/memory.c=1639=static inline bool zap_drop_markers(struct zap_details *details)\n--\nmm/memory.c-1647-/**\nmm/memory.c:1648: * cond_install_uffd_wp_ptes - install uffd-wp markers after clearing PTEs\nmm/memory.c-1649- * @vma: The VMA the pages are mapped into.\n--\nmm/memory.c-1667- */\nmm/memory.c:1668:bool cond_install_uffd_wp_ptes(struct vm_area_struct *vma,\nmm/memory.c-1669-\t\tunsigned long addr, pte_t *ptep, pte_t pte,\n--\nmm/memory.c=1716=zap_install_uffd_wp_if_needed(struct vm_area_struct *vma,\n--\nmm/memory.c-1722-\nmm/memory.c:1723:\treturn cond_install_uffd_wp_ptes(vma, addr, pte, pteval, nr);\nmm/memory.c-1724-}\n--\nmm/rmap.c=2251=static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,\n--\nmm/rmap.c-2399-\t\t */\nmm/rmap.c:2400:\t\tcond_install_uffd_wp_ptes(vma, address, pvmw.pte, pteval,\nmm/rmap.c-2401-\t\t\t\t\t nr_pages);\n"
} |
| 23/2 | 2026/09/26 18:22 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 32085 output: 34 thoughts: 23 Thoughts: Okay, here's my attempt at summarizing the thought process, as requested, geared toward an expert audience, and written in the first person: **Diving into `mm/memory.c` - a Targeted Examination** Right, let's zero in on lines 1668 to 1710 within `mm/memory.c`. I need to get a clear picture of what's happening in that particular segment. I'm assuming, given the context of the larger code base, that this probably deals with some aspect of memory management, potentially related to allocation, freeing, or page table manipulation. Given my experience, the specific lines referenced will contain hints as to whether this relates to direct memory access, NUMA, or handling of huge pages. The line numbers are, of course, a good indicator and let's go straight to the code and see. Let's see if this is related to a specific architecture's memory management or a more generic feature within the kernel's memory subsystem. I will be looking closely at any function calls within this block, paying close attention to any atomic operations or synchronization primitives used, as these usually are the telltale signs of potential race conditions or performance bottlenecks. I also have to keep in mind, of course, the general design goals of the kernel here, for scalability and performance. With this in mind, the lines should be easy to dissect and understand. |
| 24/2 | 2026/09/26 18:22 | tool | read-file |
0mArgs:{
"File": "mm/memory.c",
"FirstLine": 1668,
"LineCount": 45
}Results: {
"Contents": "1668:\tbool cond_install_uffd_wp_ptes(struct vm_area_struct *vma,\n1669:\t\t\tunsigned long addr, pte_t *ptep, pte_t pte,\n1670:\t\t\tunsigned long nr_ptes)\n1671:\t{\n1672:\t\tbool arm_uffd_pte = false;\n1673:\t\n1674:\t\tif (!uffd_supports_wp_marker())\n1675:\t\t\treturn false;\n1676:\t\n1677:\t\t/* The current status of the pte should be \"cleared\" before calling */\n1678:\t\tWARN_ON_ONCE(!pte_none(ptep_get(ptep)));\n1679:\t\n1680:\t\t/*\n1681:\t\t * NOTE: userfaultfd_wp_unpopulated() doesn't need this whole\n1682:\t\t * thing, because when zapping either it means it's dropping the\n1683:\t\t * page, or in TTU where the present pte will be quickly replaced\n1684:\t\t * with a swap pte. There's no way of leaking the bit.\n1685:\t\t */\n1686:\t\tif (vma_is_anonymous(vma) || !userfaultfd_wp(vma))\n1687:\t\t\treturn false;\n1688:\t\n1689:\t\t/* A uffd-wp wr-protected normal pte */\n1690:\t\tif (unlikely(pte_present(pte) \u0026\u0026 pte_uffd(pte)))\n1691:\t\t\tarm_uffd_pte = true;\n1692:\t\n1693:\t\t/*\n1694:\t\t * A uffd-wp wr-protected swap pte. Note: this should even cover an\n1695:\t\t * existing pte marker with uffd-wp bit set.\n1696:\t\t */\n1697:\t\tif (unlikely(pte_swp_uffd_any(pte)))\n1698:\t\t\tarm_uffd_pte = true;\n1699:\t\n1700:\t\tif (likely(!arm_uffd_pte))\n1701:\t\t\treturn false;\n1702:\t\n1703:\t\tset_softleaf_ptes(vma-\u003evm_mm, addr, ptep,\n1704:\t\t\t\t make_pte_marker(PTE_MARKER_UFFD_WP), nr_ptes);\n1705:\t\n1706:\t\treturn true;\n1707:\t}\n1708:\t\n1709:\t/*\n1710:\t * This function makes sure that we'll replace the none pte with an uffd-wp\n1711:\t * swap special pte marker when necessary. Must be with the pgtable lock held.\n1712:\t *\n"
} |
| 25/2 | 2026/09/26 18:22 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 33174 output: 31 thoughts: 739 Thoughts: **Analyzing Potential Fuzzing Needs in the Anonymous Page Sharing Path** Okay, let's dive into this code. I'm focusing on the modifications around `__folio_try_share_anon_rmap` in `include/linux/rmap.h`. Specifically, that new assertion: `VM_WARN_ON_FOLIO(page_anon_exclusive_batch(0, nr_pages, page, true) != nr_pages, folio);` catches my eye. This is important because according to the guidelines, any new or stricter runtime checks in reachable code paths *require* fuzzing. Even if the developer *thinks* the invariant holds, we need to verify it with fuzzing. I'm also noting similar assertions in `folio_dup_swap_pages` and `folio_put_swap_pages` related to page indexing (`VM_WARN_ON_FOLIO(idx + nr_pages > folio_nr_pages(folio), folio);`). These are all potential areas of interest for fuzzing. Looking deeper, the code path in `try_to_unmap_one` has also changed: it introduces a *new* path specifically for batched unmapping of anonymous swapbacked folios. This means a completely new code path, which is something I need to keep in mind for our fuzzing efforts. Now I need to see where `__folio_try_share_anon_rmap` is actually used. I can see from the code that `folio_try_share_anon_rmap_ptes`, `folio_try_share_anon_rmap_pte`, and `folio_try_share_anon_rmap_pmd` all call it, and they're all inlined in `rmap.h`. I'll need to grep for these calls to determine the calling functions and overall flow. This is a critical step to identify the reachability of these assertions and determine the best approach for fuzzing. |
| 26/2 | 2026/09/26 18:22 | tool | grepper |
0mArgs:{
"Expression": "folio_try_share_anon_rmap",
"PathPrefix": "mm/"
}Results: {
"Output": "mm/gup.c=517=static struct folio *try_grab_folio_fast(struct page *page, int refs,\n--\nmm/gup.c-573-\t * This is essentially a smp_mb() and is paired with a memory\nmm/gup.c:574:\t * barrier in folio_try_share_anon_rmap_*().\nmm/gup.c-575-\t */\n--\nmm/huge_memory.c=3178=static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd,\n--\nmm/huge_memory.c-3280-\t\tif (freeze \u0026\u0026 anon_exclusive \u0026\u0026\nmm/huge_memory.c:3281:\t\t folio_try_share_anon_rmap_pmd(folio, page))\nmm/huge_memory.c-3282-\t\t\tfreeze = false;\n--\nmm/huge_memory.c-3344-\t\t *\nmm/huge_memory.c:3345:\t\t * See folio_try_share_anon_rmap_pmd(): invalidate PMD first.\nmm/huge_memory.c-3346-\t\t */\n--\nmm/huge_memory.c-3348-\t\tif (freeze \u0026\u0026 anon_exclusive \u0026\u0026\nmm/huge_memory.c:3349:\t\t folio_try_share_anon_rmap_pmd(folio, page))\nmm/huge_memory.c-3350-\t\t\tfreeze = false;\n--\nmm/huge_memory.c=5062=int set_pmd_migration_entry(struct page_vma_mapped_walk *pvmw,\n--\nmm/huge_memory.c-5096-\nmm/huge_memory.c:5097:\t/* See folio_try_share_anon_rmap_pmd(): invalidate PMD first. */\nmm/huge_memory.c-5098-\tanon_exclusive = folio_test_anon(folio) \u0026\u0026 PageAnonExclusive(page);\nmm/huge_memory.c:5099:\tif (anon_exclusive \u0026\u0026 folio_try_share_anon_rmap_pmd(folio, page)) {\nmm/huge_memory.c-5100-\t\tset_pmd_at(mm, address, pvmw-\u003epmd, pmdval);\n--\nmm/internal.h=1338=enum {\n--\nmm/internal.h-1369- * * GUP-fast and KSM or temporary unmapping (swap, migration): see\nmm/internal.h:1370: * folio_try_share_anon_rmap_*()\nmm/internal.h-1371- *\n--\nmm/internal.h=1379=static inline bool gup_must_unshare(struct vm_area_struct *vma,\n--\nmm/internal.h-1412-\nmm/internal.h:1413:\t/* Paired with a memory barrier in folio_try_share_anon_rmap_*(). */\nmm/internal.h-1414-\tif (IS_ENABLED(CONFIG_HAVE_GUP_FAST))\n--\nmm/ksm.c=1292=static int write_protect_page(struct vm_area_struct *vma, struct folio *folio,\n--\nmm/ksm.c-1355-\nmm/ksm.c:1356:\t\t/* See folio_try_share_anon_rmap_pte(): clear PTE first. */\nmm/ksm.c-1357-\t\tif (anon_exclusive \u0026\u0026\nmm/ksm.c:1358:\t\t folio_try_share_anon_rmap_pte(folio, \u0026folio-\u003epage)) {\nmm/ksm.c-1359-\t\t\tset_pte_at(mm, pvmw.address, pvmw.pte, entry);\n--\nmm/migrate_device.c=245=static int migrate_vma_collect_pmd(pmd_t *pmdp,\n--\nmm/migrate_device.c-420-\nmm/migrate_device.c:421:\t\t\t\tif (folio_try_share_anon_rmap_pte(folio, page)) {\nmm/migrate_device.c-422-\t\t\t\t\tset_pte_at(mm, addr, ptep, pte);\n--\nmm/rmap.c=2150=static bool __ttu_anon_swapbacked_folio(struct vm_area_struct *vma,\n--\nmm/rmap.c-2171-\nmm/rmap.c:2172:\t/* See folio_try_share_anon_rmap(): clear PTE first. */\nmm/rmap.c-2173-\tif (anon_exclusive \u0026\u0026\nmm/rmap.c:2174:\t folio_try_share_anon_rmap_ptes(folio, page, nr_pages)) {\nmm/rmap.c-2175-\t\tfolio_put_swap_pages(folio, page, nr_pages);\n--\nmm/rmap.c=2512=static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma,\n--\nmm/rmap.c-2754-\nmm/rmap.c:2755:\t\t\t/* See folio_try_share_anon_rmap_pte(): clear PTE first. */\nmm/rmap.c-2756-\t\t\tif (folio_test_hugetlb(folio)) {\n--\nmm/rmap.c-2765-\t\t\t} else if (anon_exclusive \u0026\u0026\nmm/rmap.c:2766:\t\t\t\t folio_try_share_anon_rmap_pte(folio, subpage)) {\nmm/rmap.c-2767-\t\t\t\tset_pte_at(mm, address, pvmw.pte, pteval);\n"
} |
| 27/2 | 2026/09/26 18:22 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 35798 output: 32 thoughts: 1038 Thoughts: **Focusing the Fuzzer: Identifying Key Symbols and Dependencies for Anonymous Swapbacked Folio Unmapping** Okay, so I'm digging into how to effectively fuzz this new anonymous swapbacked folio unmapping logic. The goal is to avoid wasting the fuzzer's resources on ubiquitous functions and instead target the specific code that's been added or changed, as per Section 4's guidelines. My first thought process went directly to the call chain: I know `folio_try_share_anon_rmap_ptes` is triggered from `__ttu_anon_swapbacked_folio`, which in turn is called by `ttu_anon_swapbacked_folio`, and ultimately by `try_to_unmap_one` after going through `ttu_anon_folio` and then `try_to_unmap_one`. So, based on the call-chain, `try_to_unmap_one` might be a good starting point. Now, let's break down the approach, and identify the key functions to focus the fuzzer. Since the guidelines tell us to: * **AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:** I need to avoid page fault and trap handlers or core synchronization primitives. * **TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:** The key here is the logic that was *added* or *altered*. * **HANDLING STATIC INLINE FUNCTIONS**: Target caller functions exercising inlines to get addressable symbols. So, here's what I've identified: 1. `folio_dup_swap_pages` (mm/swapfile.c): This is a brand new, non-static function with a runtime assertion (`VM_WARN_ON_FOLIO`) which is a clear sign that the fuzzing efforts should start with this new functionality. 2. `folio_put_swap_pages` (mm/swapfile.c): Also newly introduced, non-static, and has the same assertion. Sounds like we're on the right track to target them. 3. `try_to_unmap_one` (mm/rmap.c): This one is interesting. It's *static*, but the code specifically references its address: `.rmap_one = try_to_unmap_one` in `try_to_unmap`, meaning it's addressable. It implements the batch unmap logic for anonymous folios, so it’s critical. 4. `try_to_unmap` (mm/rmap.c): This is a public API entrypoint that calls `try_to_unmap_one` so this should be considered. 5. `try_to_migrate_one` (mm/rmap.c): This is address-taken and calls the updated `arch_unmap_one`. Let's include this for further unmap logic. 6. `cond_install_uffd_wp_ptes` (mm/memory.c): This non-static function was modified to call the new `set_softleaf_ptes`. It should be good to target also. Okay, so what about `do_swap_page`? This is a page fault handler (involved in swap faults). While the code has been updated, Section 4 explicitly warns against focusing on those ubiquitous handlers. We have identified more specific functions like `try_to_unmap_one`, `try_to_unmap`, `folio_dup_swap_pages`, and `folio_put_swap_pages`. These seem more promising for directly hitting the new batching logic without diluting the fuzzing efforts. Next, I need to check the required configuration. Based on my knowledge, `CONFIG_SWAP` seems obvious because it enables swap functionality, which is fundamental to this logic, enabling `folio_dup_swap_pages` and `folio_put_swap_pages`, and anonymous swapbacked folio handling. `CONFIG_TRANSPARENT_HUGEPAGE` is also critical because it enables large folios of anonymous memory, which enables multi-PTE batching (`folio_unmap_pte_batch` only batches large folios). Finally, I'll quickly double-check the dependencies. Let's make sure that `TRANSPARENT_HUGEPAGE` itself doesn't depend on something obscure. I will consult `mm/Kconfig`, just to be certain. I know the dependency is `MMU && !PREEMPT_RT` (or something similar), but better to confirm. Alright, I'll go check line 834 of `mm/Kconfig` for the exact dependency just to be thorough. |
| 28/2 | 2026/09/26 18:22 | tool | read-file |
0mArgs:{
"File": "mm/Kconfig",
"FirstLine": 830,
"LineCount": 25
}Results: {
"Contents": " 830:\t\n 831:\tconfig MM_ID\n 832:\t\tdef_bool n\n 833:\t\n 834:\tmenuconfig TRANSPARENT_HUGEPAGE\n 835:\t\tbool \"Transparent Hugepage Support\"\n 836:\t\tdepends on HAVE_ARCH_TRANSPARENT_HUGEPAGE \u0026\u0026 !PREEMPT_RT\n 837:\t\tselect COMPACTION\n 838:\t\tselect XARRAY_MULTI\n 839:\t\tselect MM_ID\n 840:\t\thelp\n 841:\t\t Transparent Hugepages allows the kernel to use huge pages and\n 842:\t\t huge tlb transparently to the applications whenever possible.\n 843:\t\t This feature can improve computing performance to certain\n 844:\t\t applications by speeding up page faults during memory\n 845:\t\t allocation, by reducing the number of tlb misses and by speeding\n 846:\t\t up the pagetable walking.\n 847:\t\n 848:\t\t If memory constrained on embedded, you may want to say N.\n 849:\t\n 850:\tif TRANSPARENT_HUGEPAGE\n 851:\t\n 852:\tchoice\n 853:\t\tprompt \"Transparent Hugepage Support sysfs defaults\"\n 854:\t\tdefault TRANSPARENT_HUGEPAGE_ALWAYS\n"
} |
| 29/2 | 2026/09/26 18:22 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 38224 output: 187 thoughts: 361 Thoughts: **My Assessment of the Patch's Vulnerability Potential** Okay, so on amd64, we've got `HAVE_ARCH_TRANSPARENT_HUGEPAGE` set to 'y'. That immediately flags `TRANSPARENT_HUGEPAGE` and `SWAP` as the crucial configurations to consider. I'll also glance at `USERFAULTFD` because, while `cond_install_uffd_wp_ptes` does utilize userfaultfd-wp, it's just a single caller of `set_softleaf_ptes`. It's a connection, but not a primary one. Still, worth noting in the summary. I need to meticulously verify everything. This patch definitely warrants fuzzing, and here's why: it's introducing batch unmapping for large, anonymous swap-backed folios, which immediately gets my attention. The patch introduces range-based swap reference handling helpers in `mm/swapfile.c` and new runtime assertions. It modifies PTE sharing and swap PTE encoding helpers in core memory management. This is all *potentially* reachable on amd64, especially in virtualized environments, during crucial memory operations like reclaim, paging, and folio unmapping. The code's going to be hit hard. My primary focus needs to be on these symbols: `try_to_unmap_one`, `try_to_unmap`, `folio_dup_swap_pages`, `folio_put_swap_pages`, and `cond_install_uffd_wp_ptes`. Those seem like the critical interaction points. I'm confident that the core configuration parameters, namely `SWAP` and `TRANSPARENT_HUGEPAGE`, should be enabled to trigger the vulnerable code paths. Alright, everything appears to be in order and follows the instructions. Let's call `set-results`. |
| 30/2 | 2026/09/26 18:22 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"SWAP",
"TRANSPARENT_HUGEPAGE"
],
"FocusSymbols": [
"try_to_unmap_one",
"try_to_unmap",
"folio_dup_swap_pages",
"folio_put_swap_pages",
"cond_install_uffd_wp_ptes"
],
"Reasoning": "The patch series adds batch unmapping for large anonymous swap-backed folios in core mm (mm/rmap.c), introduces new range-based swap counting functions (folio_dup_swap_pages, folio_put_swap_pages), and adds new runtime assertions (VM_WARN_ON_FOLIO). These changes alter reachable core memory management and swap handling paths on amd64 during folio unmapping and memory reclaim.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"SWAP",
"TRANSPARENT_HUGEPAGE"
],
"FocusSymbols": [
"try_to_unmap_one",
"try_to_unmap",
"folio_dup_swap_pages",
"folio_put_swap_pages",
"cond_install_uffd_wp_ptes"
],
"Reasoning": "The patch series adds batch unmapping for large anonymous swap-backed folios in core mm (mm/rmap.c), introduces new range-based swap counting functions (folio_dup_swap_pages, folio_put_swap_pages), and adds new runtime assertions (VM_WARN_ON_FOLIO). These changes alter reachable core memory management and swap handling paths on amd64 during folio unmapping and memory reclaim.",
"WorthFuzzing": true
} |
| 31/1 | 2026/09/26 18:22 | action | If |
0mArgs:{
"WorthFuzzing": true
}Results: null |
| 32/2 | 2026/09/26 18:22 | agent | kmsan-evaluator |
0mModel:core Args: null Results: {
"KMSANReasoning": "The patch series optimizes anonymous folio handling by introducing PTE batching for unmapping, swap entry operations, and anon rmap sharing of swap-backed anonymous folios across contiguous pages.\n\nKMSAN vs KASAN Applicability:\n- KMSAN detects reads of uninitialized memory and information leaks to user space. This patch does not introduce any copy-to-user paths, socket/netlink/ioctl interfaces, or uninitialized stack/heap allocations. All local variables and PTE calculations are fully and explicitly initialized before use.\n- KASAN and standard kernel debug facilities (such as page table checks, VM_BUG_ON/VM_WARN_ON, and refcount tracking) are the appropriate tools to catch the risks associated with this patch, which include incorrect PTE values, swap count / folio refcount imbalances, potential use-after-free, or out-of-bounds folio page indexing.\n\nSince there are no uninitialized memory risks or kernel-to-user info-leaks, a dedicated KMSAN fuzzing session is not justified.",
"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 b2dccc03952d04d8e09ed125e1fd46bbfff58bf0
Author: syz-cluster <triage@syzkaller.com>
Date: Sat Sep 26 18:21:06 2026 +0000
syz-cluster: applied patch under review
diff --git a/arch/sparc/include/asm/pgtable_64.h b/arch/sparc/include/asm/pgtable_64.h
index 44d1333065a6a..f7dd1872884e4 100644
--- a/arch/sparc/include/asm/pgtable_64.h
+++ b/arch/sparc/include/asm/pgtable_64.h
@@ -1037,6 +1037,9 @@ void adi_restore_tags(struct mm_struct *mm, struct vm_area_struct *vma,
int adi_save_tags(struct mm_struct *mm, struct vm_area_struct *vma,
unsigned long addr, pte_t oldpte);
+int adi_save_tags_range(struct mm_struct *mm, struct vm_area_struct *vma,
+ unsigned long addr, pte_t oldpte, unsigned long nr);
+
#define __HAVE_ARCH_DO_SWAP_PAGE
static inline void arch_do_swap_page(struct mm_struct *mm,
struct vm_area_struct *vma,
@@ -1057,10 +1060,11 @@ static inline void arch_do_swap_page(struct mm_struct *mm,
#define __HAVE_ARCH_UNMAP_ONE
static inline int arch_unmap_one(struct mm_struct *mm,
struct vm_area_struct *vma,
- unsigned long addr, pte_t oldpte)
+ unsigned long addr, pte_t oldpte,
+ unsigned long nr)
{
- if (adi_state.enabled && (pte_val(oldpte) & _PAGE_MCD_4V))
- return adi_save_tags(mm, vma, addr, oldpte);
+ if (adi_state.enabled)
+ return adi_save_tags_range(mm, vma, addr, oldpte, nr);
return 0;
}
diff --git a/arch/sparc/kernel/adi_64.c b/arch/sparc/kernel/adi_64.c
index 18036a43cf568..ffa378accefe3 100644
--- a/arch/sparc/kernel/adi_64.c
+++ b/arch/sparc/kernel/adi_64.c
@@ -9,6 +9,7 @@
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/mm_types.h>
+#include <linux/pgtable.h>
#include <asm/mdesc.h>
#include <asm/adi_64.h>
#include <asm/mmu_64.h>
@@ -394,3 +395,23 @@ int adi_save_tags(struct mm_struct *mm, struct vm_area_struct *vma,
return 0;
}
+
+int adi_save_tags_range(struct mm_struct *mm, struct vm_area_struct *vma,
+ unsigned long addr, pte_t oldpte, unsigned long nr)
+{
+ unsigned long i;
+
+ for (i = 0; i < nr; i++, addr += PAGE_SIZE,
+ oldpte = pte_next_pfn(oldpte)) {
+ int ret;
+
+ if (!(pte_val(oldpte) & _PAGE_MCD_4V))
+ continue;
+
+ ret = adi_save_tags(mm, vma, addr, oldpte);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index 780fe849ff8b7..9c04bf3d0c04e 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -1431,12 +1431,12 @@ static inline void arch_do_swap_page_nr(struct mm_struct *mm,
* restored when the page is swapped back in. SPARC M7 and newer
* processors support an ADI (Application Data Integrity) tag for the
* page as metadata for the page. arch_unmap_one() can save this
- * metadata on a swap-out of a page.
+ * metadata on swap-out of one or more pages.
*/
static inline int arch_unmap_one(struct mm_struct *mm,
struct vm_area_struct *vma,
- unsigned long addr,
- pte_t orig_pte)
+ unsigned long addr, pte_t orig_pte,
+ unsigned long nr)
{
return 0;
}
diff --git a/include/linux/rmap.h b/include/linux/rmap.h
index 74cca0e3c7264..91b5763ef466f 100644
--- a/include/linux/rmap.h
+++ b/include/linux/rmap.h
@@ -106,6 +106,23 @@ enum ttu_flags {
#ifdef CONFIG_MMU
+/*
+ * Get max length of consecutive PTEs pointing to PageAnonExclusive() pages or
+ * !PageAnonExclusive() pages, starting from start_idx. Caller must enforce
+ * that the PTEs point to consecutive pages of the same anon large folio.
+ */
+static __always_inline unsigned long page_anon_exclusive_batch(unsigned long start_idx,
+ unsigned long max_len, struct page *first_page, bool anon_exclusive)
+{
+ unsigned long idx;
+
+ for (idx = start_idx + 1; idx < start_idx + max_len; ++idx) {
+ if (anon_exclusive != PageAnonExclusive(first_page + idx))
+ break;
+ }
+ return idx - start_idx;
+}
+
void anon_vma_init(void); /* create anon_vma_cachep */
#ifdef CONFIG_MM_ID
@@ -706,17 +723,23 @@ static inline int folio_try_dup_anon_rmap_pmd(struct folio *folio,
}
static __always_inline int __folio_try_share_anon_rmap(struct folio *folio,
- struct page *page, int nr_pages, enum pgtable_level level)
+ struct page *page, unsigned long nr_pages, enum pgtable_level level)
{
+ /* device private folios cannot get pinned via GUP. */
+ const bool pinnable = !folio_is_device_private(folio);
+
VM_WARN_ON_FOLIO(!folio_test_anon(folio), folio);
VM_WARN_ON_FOLIO(!PageAnonExclusive(page), folio);
+
__folio_rmap_sanity_checks(folio, page, nr_pages, level);
- /* device private folios cannot get pinned via GUP. */
- if (unlikely(folio_is_device_private(folio))) {
- ClearPageAnonExclusive(page);
- return 0;
- }
+ VM_WARN_ON_ONCE(level != PGTABLE_LEVEL_PTE && level != PGTABLE_LEVEL_PMD);
+
+ /* We only clear anon-exclusive from head page of PMD folio. */
+ if (level == PGTABLE_LEVEL_PMD)
+ nr_pages = 1;
+
+ VM_WARN_ON_FOLIO(page_anon_exclusive_batch(0, nr_pages, page, true) != nr_pages, folio);
/*
* We have to make sure that when we clear PageAnonExclusive, that
@@ -760,29 +783,38 @@ static __always_inline int __folio_try_share_anon_rmap(struct folio *folio,
* so we use explicit ones here.
*/
- /* Paired with the memory barrier in try_grab_folio(). */
- if (IS_ENABLED(CONFIG_HAVE_GUP_FAST))
- smp_mb();
+ if (likely(pinnable)) {
+ /* Paired with the memory barrier in try_grab_folio(). */
+ if (IS_ENABLED(CONFIG_HAVE_GUP_FAST))
+ smp_mb();
- if (unlikely(folio_maybe_dma_pinned(folio)))
- return -EBUSY;
- ClearPageAnonExclusive(page);
+ if (unlikely(folio_maybe_dma_pinned(folio)))
+ return -EBUSY;
+ }
+
+ for (;;) {
+ ClearPageAnonExclusive(page);
+ if (--nr_pages == 0)
+ break;
+ page++;
+ }
/*
* This is conceptually a smp_wmb() paired with the smp_rmb() in
* gup_must_unshare().
*/
- if (IS_ENABLED(CONFIG_HAVE_GUP_FAST))
+ if (likely(pinnable) && IS_ENABLED(CONFIG_HAVE_GUP_FAST))
smp_mb__after_atomic();
return 0;
}
/**
- * folio_try_share_anon_rmap_pte - try marking an exclusive anonymous page
- * mapped by a PTE possibly shared to prepare
+ * folio_try_share_anon_rmap_ptes - try marking exclusive anonymous pages
+ * mapped by PTEs possibly shared to prepare
* for KSM or temporary unmapping
* @folio: The folio to share a mapping of
- * @page: The mapped exclusive page
+ * @page: The first mapped exclusive page of the batch in the folio
+ * @nr_pages: The number of pages to share in the folio (batch size)
*
* The caller needs to hold the page table lock and has to have the page table
* entries cleared/invalidated.
@@ -798,10 +830,17 @@ static __always_inline int __folio_try_share_anon_rmap(struct folio *folio,
* Returns 0 if marking the mapped page possibly shared succeeded. Returns
* -EBUSY otherwise.
*/
+static inline int folio_try_share_anon_rmap_ptes(struct folio *folio,
+ struct page *page, unsigned long nr_pages)
+{
+ return __folio_try_share_anon_rmap(folio, page, nr_pages,
+ PGTABLE_LEVEL_PTE);
+}
+
static inline int folio_try_share_anon_rmap_pte(struct folio *folio,
struct page *page)
{
- return __folio_try_share_anon_rmap(folio, page, 1, PGTABLE_LEVEL_PTE);
+ return folio_try_share_anon_rmap_ptes(folio, page, 1);
}
/**
diff --git a/mm/internal.h b/mm/internal.h
index 0434dfcfc36f1..7e7afcd93b33c 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -469,16 +469,16 @@ unsigned int folio_pte_batch(struct folio *folio, pte_t *ptep, pte_t pte,
unsigned int max_nr);
/**
- * pte_move_swp_offset - Move the swap entry offset field of a swap pte
- * forward or backward by delta
- * @pte: The initial pte state; must be a swap entry
+ * pte_move_softleaf_offset - Move the softleaf entry offset field of a
+ * softleaf pte forward or backward by delta
+ * @pte: The initial pte state; must be a softleaf entry
* @delta: The direction and the offset we are moving; forward if delta
* is positive; backward if delta is negative
*
- * Moves the swap offset, while maintaining all other fields, including
- * swap type, and any swp pte bits. The resulting pte is returned.
+ * Moves the softleaf offset, while maintaining all other fields, including
+ * softleaf type, and any softleaf pte bits. The resulting pte is returned.
*/
-static inline pte_t pte_move_swp_offset(pte_t pte, long delta)
+static inline pte_t pte_move_softleaf_offset(pte_t pte, long delta)
{
const softleaf_t entry = softleaf_from_pte(pte);
pte_t new = __swp_entry_to_pte(__swp_entry(swp_type(entry),
@@ -486,7 +486,7 @@ static inline pte_t pte_move_swp_offset(pte_t pte, long delta)
if (pte_swp_soft_dirty(pte))
new = pte_swp_mksoft_dirty(new);
- if (pte_swp_exclusive(pte))
+ if (softleaf_is_swap(entry) && pte_swp_exclusive(pte))
new = pte_swp_mkexclusive(new);
if (pte_swp_uffd(pte))
new = pte_swp_mkuffd(new);
@@ -496,15 +496,49 @@ static inline pte_t pte_move_swp_offset(pte_t pte, long delta)
/**
- * pte_next_swp_offset - Increment the swap entry offset field of a swap pte.
- * @pte: The initial pte state; must be a swap entry.
+ * pte_next_softleaf_offset - Increment the softleaf entry offset field of a
+ * non-present pte.
+ * @pte: The initial pte state; must be a softleaf entry.
*
- * Increments the swap offset, while maintaining all other fields, including
- * swap type, and any swp pte bits. The resulting pte is returned.
+ * Increments the softleaf offset, while maintaining all other fields, including
+ * softleaf type, and any softleaf pte bits. The resulting pte is returned.
*/
-static inline pte_t pte_next_swp_offset(pte_t pte)
+static inline pte_t pte_next_softleaf_offset(pte_t pte)
{
- return pte_move_swp_offset(pte, 1);
+ return pte_move_softleaf_offset(pte, 1);
+}
+
+/**
+ * set_softleaf_ptes - Set consecutive softleaf PTEs.
+ * @mm: Address space the PTEs belong to.
+ * @addr: Address of the first PTE.
+ * @ptep: Page table pointer for the first PTE.
+ * @pte: PTE to set for the first entry.
+ * @nr: Number of PTEs to set.
+ *
+ * Install @nr softleaf PTEs, advancing @pte when its softleaf entry
+ * represents consecutive offsets. Swap entries advance through swap offsets,
+ * PFN softleaf entries advance through PFNs (encoded by swap offset), and
+ * marker entries are repeated unchanged.
+ */
+static inline void set_softleaf_ptes(struct mm_struct *mm, unsigned long addr,
+ pte_t *ptep, pte_t pte, unsigned long nr)
+{
+ softleaf_t entry;
+ bool advance;
+
+ entry = softleaf_from_pte(pte);
+ advance = softleaf_is_swap(entry) || softleaf_has_pfn(entry);
+
+ for (;;) {
+ set_pte_at(mm, addr, ptep, pte);
+ if (--nr == 0)
+ break;
+ if (advance)
+ pte = pte_next_softleaf_offset(pte);
+ ptep++;
+ addr += PAGE_SIZE;
+ }
}
/**
@@ -524,7 +558,7 @@ static inline pte_t pte_next_swp_offset(pte_t pte)
*/
static inline int swap_pte_batch(pte_t *start_ptep, int max_nr, pte_t pte)
{
- pte_t expected_pte = pte_next_swp_offset(pte);
+ pte_t expected_pte = pte_next_softleaf_offset(pte);
const pte_t *end_ptep = start_ptep + max_nr;
pte_t *ptep = start_ptep + 1;
@@ -536,7 +570,7 @@ static inline int swap_pte_batch(pte_t *start_ptep, int max_nr, pte_t pte)
if (!pte_same(pte, expected_pte))
break;
- expected_pte = pte_next_swp_offset(expected_pte);
+ expected_pte = pte_next_softleaf_offset(expected_pte);
ptep++;
}
diff --git a/mm/memory.c b/mm/memory.c
index 330cde31bf8b4..985a884b68008 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -1700,14 +1700,8 @@ bool cond_install_uffd_wp_ptes(struct vm_area_struct *vma,
if (likely(!arm_uffd_pte))
return false;
- for (;;) {
- set_pte_at(vma->vm_mm, addr, ptep,
- make_pte_marker(PTE_MARKER_UFFD_WP));
- if (--nr_ptes == 0)
- break;
- ptep++;
- addr += PAGE_SIZE;
- }
+ set_softleaf_ptes(vma->vm_mm, addr, ptep,
+ make_pte_marker(PTE_MARKER_UFFD_WP), nr_ptes);
return true;
}
@@ -4819,7 +4813,7 @@ static bool can_swapin_thp(struct vm_fault *vmf, pte_t *ptep, int nr_pages)
idx = (vmf->address - addr) / PAGE_SIZE;
pte = ptep_get(ptep);
- if (!pte_same(pte, pte_move_swp_offset(vmf->orig_pte, -idx)))
+ if (!pte_same(pte, pte_move_softleaf_offset(vmf->orig_pte, -idx)))
return false;
/*
* swap_read_folio() can't handle the case a large folio is hybridly
@@ -5134,7 +5128,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
folio_ptep = vmf->pte - idx;
folio_pte = ptep_get(folio_ptep);
- if (!pte_same(folio_pte, pte_move_swp_offset(vmf->orig_pte, -idx)) ||
+ if (!pte_same(folio_pte, pte_move_softleaf_offset(vmf->orig_pte, -idx)) ||
swap_pte_batch(folio_ptep, nr, folio_pte) != nr)
goto check_folio;
@@ -5270,7 +5264,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
if (unlikely(folio != swapcache)) {
folio_add_new_anon_rmap(folio, vma, address, RMAP_EXCLUSIVE);
folio_add_lru_vma(folio, vma);
- folio_put_swap(swapcache, NULL);
+ folio_put_swap(swapcache);
} else if (!folio_test_anon(folio)) {
/*
* We currently only expect !anon folios that are fully
@@ -5279,12 +5273,12 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)
VM_WARN_ON_ONCE_FOLIO(folio_nr_pages(folio) != nr_pages, folio);
VM_WARN_ON_ONCE_FOLIO(folio_mapped(folio), folio);
folio_add_new_anon_rmap(folio, vma, address, rmap_flags);
- folio_put_swap(folio, NULL);
+ folio_put_swap(folio);
} else {
VM_WARN_ON_ONCE(nr_pages != 1 && nr_pages != folio_nr_pages(folio));
folio_add_anon_rmap_ptes(folio, page, nr_pages, vma, address,
rmap_flags);
- folio_put_swap(folio, nr_pages == 1 ? page : NULL);
+ folio_put_swap_pages(folio, page, nr_pages);
}
VM_BUG_ON(!folio_test_anon(folio) ||
diff --git a/mm/mprotect.c b/mm/mprotect.c
index e59c69cb5a238..6d254d5342633 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -30,6 +30,7 @@
#include <linux/mm_inline.h>
#include <linux/pgtable.h>
#include <linux/userfaultfd_k.h>
+#include <linux/rmap.h>
#include <uapi/linux/mman.h>
#include <asm/cacheflush.h>
#include <asm/mmu_context.h>
@@ -138,23 +139,6 @@ static __always_inline void prot_commit_flush_ptes(struct vm_area_struct *vma,
tlb_flush_pte_range(tlb, addr, nr_ptes * PAGE_SIZE);
}
-/*
- * Get max length of consecutive ptes pointing to PageAnonExclusive() pages or
- * !PageAnonExclusive() pages, starting from start_idx. Caller must enforce
- * that the ptes point to consecutive pages of the same anon large folio.
- */
-static __always_inline int page_anon_exclusive_batch(int start_idx, int max_len,
- struct page *first_page, bool expected_anon_exclusive)
-{
- int idx;
-
- for (idx = start_idx + 1; idx < start_idx + max_len; ++idx) {
- if (expected_anon_exclusive != PageAnonExclusive(first_page + idx))
- break;
- }
- return idx - start_idx;
-}
-
/*
* This function is a result of trying our very best to retain the
* "avoid the write-fault handler" optimization. In can_change_pte_writable(),
diff --git a/mm/rmap.c b/mm/rmap.c
index fbd66a2823b7b..9e3589b07101d 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1959,6 +1959,7 @@ static inline unsigned int folio_unmap_pte_batch(struct folio *folio,
if (flags & TTU_HWPOISON)
return 1;
+
if (!folio_test_large(folio))
return 1;
@@ -1966,10 +1967,6 @@ static inline unsigned int folio_unmap_pte_batch(struct folio *folio,
end_addr = pmd_addr_end(addr, vma->vm_end);
max_nr = (end_addr - addr) >> PAGE_SHIFT;
- /* We only support lazyfree or file folios batching for now ... */
- if (folio_test_anon(folio) && folio_test_swapbacked(folio))
- return 1;
-
if (pte_unused(pte))
return 1;
@@ -2141,16 +2138,25 @@ static pte_t swp_pte_prepare(swp_entry_t entry, pte_t old_pte,
return swp_pte;
}
-static bool ttu_anon_swapbacked_folio(struct vm_area_struct *vma,
+static void finish_folio_unmap_batch(struct vm_area_struct *vma,
+ struct folio *folio, struct page *page, unsigned long nr_pages)
+{
+ folio_remove_rmap_ptes(folio, page, nr_pages, vma);
+ if (vma->vm_flags & VM_LOCKED)
+ mlock_drain_local();
+ folio_put_refs(folio, nr_pages);
+}
+
+static bool __ttu_anon_swapbacked_folio(struct vm_area_struct *vma,
struct folio *folio, struct page *page, unsigned long address,
- pte_t *ptep, pte_t pteval)
+ pte_t *ptep, pte_t pteval, unsigned long nr_pages,
+ bool anon_exclusive)
{
- const bool anon_exclusive = folio_test_anon(folio) &&
- PageAnonExclusive(page);
swp_entry_t entry = folio_page_swap_entry(folio, page);
struct mm_struct *mm = vma->vm_mm;
+ pte_t swp_pte;
- if (folio_dup_swap(folio, page) < 0)
+ if (folio_dup_swap_pages(folio, page, nr_pages) < 0)
return false;
/*
@@ -2158,22 +2164,57 @@ static bool ttu_anon_swapbacked_folio(struct vm_area_struct *vma,
* architectures where we could have PFN swap PTEs,
* so we'll not check/care.
*/
- if (arch_unmap_one(mm, vma, address, pteval) < 0) {
- folio_put_swap(folio, page);
+ if (arch_unmap_one(mm, vma, address, pteval, nr_pages) < 0) {
+ folio_put_swap_pages(folio, page, nr_pages);
return false;
}
/* See folio_try_share_anon_rmap(): clear PTE first. */
- if (anon_exclusive && folio_try_share_anon_rmap_pte(folio, page)) {
- folio_put_swap(folio, page);
+ if (anon_exclusive &&
+ folio_try_share_anon_rmap_ptes(folio, page, nr_pages)) {
+ folio_put_swap_pages(folio, page, nr_pages);
return false;
}
mm_prepare_for_swap_entries(mm);
- dec_mm_counter(mm, MM_ANONPAGES);
- inc_mm_counter(mm, MM_SWAPENTS);
- set_pte_at(mm, address, ptep,
- swp_pte_prepare(entry, pteval, anon_exclusive));
+ add_mm_counter(mm, MM_ANONPAGES, -nr_pages);
+ add_mm_counter(mm, MM_SWAPENTS, nr_pages);
+ swp_pte = swp_pte_prepare(entry, pteval, anon_exclusive);
+ set_softleaf_ptes(mm, address, ptep, swp_pte, nr_pages);
+ finish_folio_unmap_batch(vma, folio, page, nr_pages);
+ return true;
+}
+
+static bool ttu_anon_swapbacked_folio(struct vm_area_struct *vma,
+ struct folio *folio, struct page *first_page,
+ unsigned long address, pte_t *ptep, pte_t pteval,
+ unsigned long nr_pages)
+{
+ unsigned long batch_idx = 0;
+
+ while (nr_pages) {
+ bool anon_exclusive = PageAnonExclusive(first_page + batch_idx);
+ unsigned long len = page_anon_exclusive_batch(batch_idx,
+ nr_pages, first_page, anon_exclusive);
+
+ if (!__ttu_anon_swapbacked_folio(vma, folio,
+ first_page + batch_idx, address, ptep, pteval,
+ len, anon_exclusive)) {
+ /* Restore the remaining PTEs that were cleared. */
+ set_ptes(vma->vm_mm, address, ptep, pteval, nr_pages);
+ return false;
+ }
+
+ nr_pages -= len;
+ if (!nr_pages)
+ break;
+
+ pteval = pte_advance_pfn(pteval, len);
+ address += len * PAGE_SIZE;
+ batch_idx += len;
+ ptep += len;
+ }
+
return true;
}
@@ -2186,15 +2227,22 @@ static bool ttu_anon_folio(struct vm_area_struct *vma, struct folio *folio,
* See handle_pte_fault() ...
*/
if (WARN_ON_ONCE(folio_test_swapbacked(folio) !=
- folio_test_swapcache(folio)))
+ folio_test_swapcache(folio))) {
+ set_ptes(vma->vm_mm, address, ptep, pteval, nr_pages);
return false;
+ }
- if (!folio_test_swapbacked(folio))
- return ttu_anon_lazyfree_folio(vma, folio, nr_pages);
+ if (!folio_test_swapbacked(folio)) {
+ if (!ttu_anon_lazyfree_folio(vma, folio, nr_pages)) {
+ set_ptes(vma->vm_mm, address, ptep, pteval, nr_pages);
+ return false;
+ }
+ finish_folio_unmap_batch(vma, folio, page, nr_pages);
+ return true;
+ }
- /* nr_pages > 1 not supported yet */
return ttu_anon_swapbacked_folio(vma, folio, page, address, ptep,
- pteval);
+ pteval, nr_pages);
}
/*
@@ -2374,13 +2422,14 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,
*/
dec_mm_counter(mm, mm_counter(folio));
} else if (folio_test_anon(folio)) {
+ /* finish_folio_unmap_batch handled internally */
if (!ttu_anon_folio(vma, folio, page, address,
- pvmw.pte, pteval, nr_pages)) {
- set_ptes(mm, address, pvmw.pte, pteval, nr_pages);
+ pvmw.pte, pteval, nr_pages))
goto walk_abort;
- }
- goto finish_unmap;
+ if (nr_pages == folio_nr_pages(folio))
+ goto walk_done;
+ continue;
} else {
/*
* This is a locked file-backed folio,
@@ -2395,11 +2444,8 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,
*/
add_mm_counter(mm, mm_counter_file(folio), -nr_pages);
}
-finish_unmap:
- folio_remove_rmap_ptes(folio, page, nr_pages, vma);
- if (vma->vm_flags & VM_LOCKED)
- mlock_drain_local();
- folio_put_refs(folio, nr_pages);
+
+ finish_folio_unmap_batch(vma, folio, page, nr_pages);
/*
* If we are sure that we batched the entire folio and cleared
@@ -2695,7 +2741,7 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma,
* architectures where we could have PFN swap PTEs,
* so we'll not check/care.
*/
- if (arch_unmap_one(mm, vma, address, pteval) < 0) {
+ if (arch_unmap_one(mm, vma, address, pteval, 1) < 0) {
if (folio_test_hugetlb(folio))
set_huge_pte_at(mm, address, pvmw.pte,
pteval, hsz);
diff --git a/mm/shmem.c b/mm/shmem.c
index 07b2855dfb7bd..2ea73d18126f5 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1916,7 +1916,7 @@ int shmem_writeout(struct swap_io_ctx *ctx, struct folio *folio,
spin_unlock(&shmem_swaplist_lock);
}
- folio_dup_swap(folio, NULL);
+ folio_dup_swap(folio);
shmem_delete_from_page_cache(folio, swp_to_radix_entry(folio->swap));
BUG_ON(folio_mapped(folio));
@@ -1937,7 +1937,7 @@ int shmem_writeout(struct swap_io_ctx *ctx, struct folio *folio,
/* Swap entry might be erased by racing shmem_free_swap() */
if (!error) {
shmem_recalc_inode(inode, 0, -nr_pages);
- folio_put_swap(folio, NULL);
+ folio_put_swap(folio);
}
/*
@@ -2370,7 +2370,7 @@ static void shmem_set_folio_swapin_error(struct inode *inode, pgoff_t index,
nr_pages = folio_nr_pages(folio);
folio_wait_writeback(folio);
- folio_put_swap(folio, NULL);
+ folio_put_swap(folio);
swap_cache_del_folio(folio);
/*
* Don't treat swapin error folio as alloced. Otherwise inode->i_blocks
@@ -2600,7 +2600,7 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,
if (sgp == SGP_WRITE)
folio_mark_accessed(folio);
- folio_put_swap(folio, NULL);
+ folio_put_swap(folio);
swap_cache_del_folio(folio);
folio_mark_dirty(folio);
put_swap_device(si);
diff --git a/mm/swap.h b/mm/swap.h
index d5bf21f517dce..891f41c4556c2 100644
--- a/mm/swap.h
+++ b/mm/swap.h
@@ -244,8 +244,10 @@ extern int swap_retry_table_alloc(swp_entry_t entry, gfp_t gfp);
* folio_put_swap(): does the opposite thing of folio_dup_swap().
*/
int folio_alloc_swap(struct folio *folio);
-int folio_dup_swap(struct folio *folio, struct page *page);
-void folio_put_swap(struct folio *folio, struct page *page);
+int folio_dup_swap_pages(struct folio *folio, struct page *page,
+ unsigned long nr_pages);
+void folio_put_swap_pages(struct folio *folio, struct page *page,
+ unsigned long nr_pages);
/* For internal use */
extern void __swap_cluster_free_entries(struct swap_info_struct *si,
@@ -368,12 +370,14 @@ static inline int folio_alloc_swap(struct folio *folio)
return -EINVAL;
}
-static inline int folio_dup_swap(struct folio *folio, struct page *page)
+static inline int folio_dup_swap_pages(struct folio *folio, struct page *page,
+ unsigned long nr_pages)
{
return -EINVAL;
}
-static inline void folio_put_swap(struct folio *folio, struct page *page)
+static inline void folio_put_swap_pages(struct folio *folio, struct page *page,
+ unsigned long nr_pages)
{
}
@@ -464,6 +468,29 @@ static inline void __swap_cache_replace_folio(struct swap_cluster_info *ci,
}
#endif /* CONFIG_SWAP */
+/**
+ * folio_dup_swap() - Increase swap count of all swap entries of a folio.
+ * @folio: folio with swap entries bound.
+ *
+ * See folio_dup_swap_pages() for more information.
+ */
+static inline int folio_dup_swap(struct folio *folio)
+{
+ return folio_dup_swap_pages(folio, folio_page(folio, 0),
+ folio_nr_pages(folio));
+}
+
+/**
+ * folio_put_swap() - Decrease swap count of all swap entries of a folio.
+ * @folio: folio with swap entries bound.
+ *
+ * See folio_put_swap_pages() for more information.
+ */
+static inline void folio_put_swap(struct folio *folio)
+{
+ folio_put_swap_pages(folio, folio_page(folio, 0), folio_nr_pages(folio));
+}
+
extern const struct swap_ops swap_bdev_ops;
int shmem_writeout(struct swap_io_ctx *ctx, struct folio *folio,
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 254ce86fa923e..5d4d293044ab0 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1799,9 +1799,10 @@ int folio_alloc_swap(struct folio *folio)
}
/**
- * folio_dup_swap() - Increase swap count of swap entries of a folio.
+ * folio_dup_swap_pages() - Increase swap count of swap entries of a folio.
* @folio: folio with swap entries bounded.
- * @page: if not NULL, only increase the swap count of this page.
+ * @page: the first page in the folio to increase the swap count for.
+ * @nr_pages: the number of pages in the folio to increase the swap count for.
*
* Typically called when the folio is unmapped and have its swap entry to
* take its place: Swap entries allocated to a folio has count == 0 and pinned
@@ -1815,45 +1816,40 @@ int folio_alloc_swap(struct folio *folio)
* swap_put_entries_direct on its swap entry before this helper returns, or
* the swap count may underflow.
*/
-int folio_dup_swap(struct folio *folio, struct page *page)
+int folio_dup_swap_pages(struct folio *folio, struct page *page,
+ unsigned long nr_pages)
{
- swp_entry_t entry = folio->swap;
- unsigned long nr_pages = folio_nr_pages(folio);
+ swp_entry_t entry = folio_page_swap_entry(folio, page);
+ unsigned long idx = folio_page_idx(folio, page);
VM_WARN_ON_FOLIO(!folio_test_locked(folio), folio);
VM_WARN_ON_FOLIO(!folio_test_swapcache(folio), folio);
-
- if (page) {
- entry = folio_page_swap_entry(folio, page);
- nr_pages = 1;
- }
+ VM_WARN_ON_FOLIO(idx + nr_pages > folio_nr_pages(folio), folio);
return swap_dup_entries_cluster(swap_entry_to_info(entry),
swp_offset(entry), nr_pages);
}
/**
- * folio_put_swap() - Decrease swap count of swap entries of a folio.
+ * folio_put_swap_pages() - Decrease swap count of swap entries of a folio.
* @folio: folio with swap entries bounded, must be in swap cache and locked.
- * @page: if not NULL, only decrease the swap count of this page.
+ * @page: the first page in the folio to decrease the swap count for.
+ * @nr_pages: the number of pages in the folio to decrease the swap count for.
*
* This won't free the swap slots even if swap count drops to zero, they are
* still pinned by the swap cache. User may call folio_free_swap to free them.
* Context: Caller must ensure the folio is locked and in the swap cache.
*/
-void folio_put_swap(struct folio *folio, struct page *page)
+void folio_put_swap_pages(struct folio *folio, struct page *page,
+ unsigned long nr_pages)
{
- swp_entry_t entry = folio->swap;
- unsigned long nr_pages = folio_nr_pages(folio);
+ swp_entry_t entry = folio_page_swap_entry(folio, page);
struct swap_info_struct *si = __swap_entry_to_info(entry);
+ unsigned long idx = folio_page_idx(folio, page);
VM_WARN_ON_FOLIO(!folio_test_locked(folio), folio);
VM_WARN_ON_FOLIO(!folio_test_swapcache(folio), folio);
-
- if (page) {
- entry = folio_page_swap_entry(folio, page);
- nr_pages = 1;
- }
+ VM_WARN_ON_FOLIO(idx + nr_pages > folio_nr_pages(folio), folio);
swap_put_entries_cluster(si, swp_offset(entry), nr_pages, false);
}
@@ -2598,7 +2594,8 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd,
setpte:
set_pte_at(vma->vm_mm, addr, pte, new_pte);
- folio_put_swap(swapcache, folio_file_page(swapcache, swp_offset(entry)));
+ folio_put_swap_pages(swapcache,
+ folio_file_page(swapcache, swp_offset(entry)), 1);
out:
if (pte)
pte_unmap_unlock(pte, ptl);
|
| 33/3 | 2026/09/26 18:22 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 12910 output: 242 thoughts: 2780 Thoughts: **KMSAN Evaluation: Anonymous Folio Batching Patch Series** Okay, let's break this down. The objective here is to determine whether this patch series, focusing on batching operations for anonymous folios during unmapping, swap-in, and swap-out, warrants a KMSAN fuzzing session. My initial assessment is that it doesn't, but let's be methodical. My first thought is always to understand the scope of the change. This patch significantly touches the memory management subsystem, specifically the handling of anonymous pages and their interaction with swap space and page tables. It introduces batching optimizations to improve efficiency. It seems to be focused around manipulating PTEs to optimize swap operations, particularly when dealing with contiguous anonymous pages or folios. The target architecture is amd64. Crucially, I need to identify if this code introduces, modifies, or exposes uninitialized memory risks. Let me go through the main parts of the patch one by one: * **`mm/rmap.c`:** The core of the patch involves functions like `__ttu_anon_swapbacked_folio`, `set_softleaf_ptes`, `finish_folio_unmap_batch`, and `try_to_unmap_one`. I'm verifying the potential of uninitialized memory usage. I see that the `swp_pte` variable within `__ttu_anon_swapbacked_folio` is explicitly initialized, and the `set_softleaf_ptes` functions use variables initialized before usage. The PTE entries written to page tables are fully initialized with correct metadata (swap offset/flags). `folio_dup_swap_pages` and `folio_put_swap_pages` and related functions don't seem to read or write uninitialized memory. They work with swap entries. * **`include/linux/rmap.h`:** The `__folio_try_share_anon_rmap` function clears a `PageAnonExclusive` flag, and also needs to be examined. It appears the relevant variables are correctly initialized. * **Other files:** The SPARC-specific functions, like `adi_save_tags_range`, are irrelevant for our target architecture, but I still checked them and they also look correct. The most important question is: *Are there any kernel structures being sent to userspace?* I see no use of `copy_to_user`, `put_user`, socket buffers, netlink, ioctl, or BPF. The patch is about core kernel internal memory management, not exposing internal structures. No data leaks, no direct user-space communication here. Now, let's consider the *types of bugs* this patch could introduce, which are not related to KMSAN: 1. Incorrect page table entries. 2. Page refcount/mapcount/swap count imbalances. 3. Use-after-free conditions related to folios, pages, or swap slots. 4. Concurrency issues/races with GUP and pinning. 5. Out-of-bounds page accesses (though guarded in many locations). 6. Synchronization or barrier issues. I'm confident that most of the bugs that I listed above, such as out-of-bounds access, refcount issues, and UAFs, are within the scope of KASAN (Kernel Address Sanitizer) and standard kernel debugging facilities (page table integrity, refcount tracking, and VM_WARN\_ON/VM_BUG\_ON). KMSAN specifically focuses on *reads of uninitialized memory* and information leaks to user space. There's no uninitialized stack/heap allocations, and PTEs are properly generated, and there is no direct data transfer to userspace. Therefore, after a thorough review, I'm concluding that this patch series does *not* introduce or expose uninitialized memory risks that KMSAN would detect, but that KASAN and standard kernel bug detectors would miss. There is no need for a dedicated KMSAN fuzzing session. |
| 34/3 | 2026/09/26 18:22 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch series optimizes anonymous folio handling by introducing PTE batching for unmapping, swap entry operations, and anon rmap sharing of swap-backed anonymous folios across contiguous pages.\n\nKMSAN vs KASAN Applicability:\n- KMSAN detects reads of uninitialized memory and information leaks to user space. This patch does not introduce any copy-to-user paths, socket/netlink/ioctl interfaces, or uninitialized stack/heap allocations. All local variables and PTE calculations are fully and explicitly initialized before use.\n- KASAN and standard kernel debug facilities (such as page table checks, VM_BUG_ON/VM_WARN_ON, and refcount tracking) are the appropriate tools to catch the risks associated with this patch, which include incorrect PTE values, swap count / folio refcount imbalances, potential use-after-free, or out-of-bounds folio page indexing.\n\nSince there are no uninitialized memory risks or kernel-to-user info-leaks, a dedicated KMSAN fuzzing session is not justified.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch series optimizes anonymous folio handling by introducing PTE batching for unmapping, swap entry operations, and anon rmap sharing of swap-backed anonymous folios across contiguous pages.\n\nKMSAN vs KASAN Applicability:\n- KMSAN detects reads of uninitialized memory and information leaks to user space. This patch does not introduce any copy-to-user paths, socket/netlink/ioctl interfaces, or uninitialized stack/heap allocations. All local variables and PTE calculations are fully and explicitly initialized before use.\n- KASAN and standard kernel debug facilities (such as page table checks, VM_BUG_ON/VM_WARN_ON, and refcount tracking) are the appropriate tools to catch the risks associated with this patch, which include incorrect PTE values, swap count / folio refcount imbalances, potential use-after-free, or out-of-bounds folio page indexing.\n\nSince there are no uninitialized memory risks or kernel-to-user info-leaks, a dedicated KMSAN fuzzing session is not justified.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|