| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/11/03 12:45 | flow | patch-triage |
21mArgs:null Results: {
"EnableConfigs": [
"MMU",
"TRANSPARENT_HUGEPAGE",
"HUGETLBFS"
],
"FocusSymbols": [
"__get_user_pages",
"follow_page_mask",
"follow_page_pte",
"follow_huge_pmd",
"follow_huge_pud",
"follow_pmd_mask",
"gup_pte_batch_len",
"gup_grab_folio_pages"
],
"KMSANReasoning": "The patch refactors the GUP (get_user_pages) slow path in mm/gup.c to support batched PTE and huge PMD/PUD lookups and folio pinning (introducing helpers like gup_grab_folio_pages, gup_lookup_pte, gup_pte_batch_len, gup_fill_pages, and updating follow_page_pte / follow_page_mask).\n\nNo uninitialized memory hazards are introduced or exposed:\n1. No structures are copied to user space, so there is no risk of kernel info-leaks.\n2. All local variables and pointers (e.g. `nr`, `need_no_page_table`, `ret`, `off`, `pagep`) are strictly initialized or unconditionally assigned prior to read or branch operations.\n3. The caller-provided `pages` array is populated with valid `struct page *` pointers for all `nr` pages returned.\n4. Any potential bugs in batch length calculations or index offsets would manifest as out-of-bounds accesses on the `pages` array, incorrect refcounts, or locking errors, all of which are caught by KASAN, LOCKDEP, or standard kernel debug assertions.\n\nTherefore, dedicated KMSAN fuzzing is not justified.",
"NeedsKMSAN": false,
"Reasoning": "The patch refactors the core memory management page table walk in mm/gup.c (get_user_pages / follow_page_mask) to support batching of contiguous PTEs and huge PMDs/PUDs for folios. It reworks reference acquisition (try_grab_folio), dirty/accessed tracking, error propagation, cache flushing, and adds a runtime assertion (VM_WARN_ON_ONCE(nr \u003e nr_pages)). This code is fully reachable in virtualized environments via syscalls exercising GUP (e.g., madvise with MADV_POPULATE_READ/WRITE, mlock, process_vm_readv/writev, ptrace, io_uring, direct I/O).",
"WorthFuzzing": true
} |
| 1/1 | 2026/11/03 12:45 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit ec6963d74782bda695601c9573e98ad620e5c8e5\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Tue Nov 3 12:45:18 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/mm/gup.c b/mm/gup.c\nindex 7d43ce717b2461..47f204e21a3a79 100644\n--- a/mm/gup.c\n+++ b/mm/gup.c\n@@ -608,15 +608,15 @@ static inline bool can_follow_write_common(struct page *page,\n \treturn page \u0026\u0026 PageAnon(page) \u0026\u0026 PageAnonExclusive(page);\n }\n \n-static struct page *no_page_table(struct vm_area_struct *vma,\n-\t\t\t\t unsigned int flags, unsigned long address)\n+static long no_page_table(struct vm_area_struct *vma,\n+\t\tunsigned int flags, unsigned long address)\n {\n \tif (!(flags \u0026 FOLL_DUMP))\n-\t\treturn NULL;\n+\t\treturn 0;\n \n \t/*\n \t * When core dumping, we don't want to allocate unnecessary pages or\n-\t * page tables. Return error instead of NULL to skip handle_mm_fault,\n+\t * page tables. Return error instead of 0 to skip handle_mm_fault,\n \t * then get_dump_page() will return NULL to leave a hole in the dump.\n \t * But we can only make this optimization where a hole would surely\n \t * be zero-filled if handle_mm_fault() actually did handle it.\n@@ -625,12 +625,48 @@ static struct page *no_page_table(struct vm_area_struct *vma,\n \t\tstruct hstate *h = hstate_vma(vma);\n \n \t\tif (!hugetlbfs_pagecache_present(h, vma, address))\n-\t\t\treturn ERR_PTR(-EFAULT);\n+\t\t\treturn -EFAULT;\n \t} else if ((vma_is_anonymous(vma) || !vma-\u003evm_ops-\u003efault)) {\n-\t\treturn ERR_PTR(-EFAULT);\n+\t\treturn -EFAULT;\n \t}\n \n-\treturn NULL;\n+\treturn 0;\n+}\n+\n+static void gup_fill_pages(struct vm_area_struct *vma, unsigned long address,\n+\t\tstruct page *page, unsigned long nr, struct page **pages)\n+{\n+\tunsigned long i;\n+\n+\tif (!pages)\n+\t\treturn;\n+\n+\tfor (i = 0; i \u003c nr; i++) {\n+\t\tstruct page *subpage = page + i;\n+\n+\t\tpages[i] = subpage;\n+\t\tflush_anon_page(vma, subpage, address + i * PAGE_SIZE);\n+\t\tflush_dcache_page(subpage);\n+\t}\n+}\n+\n+/*\n+ * Flush the caches for @nr pages stored in @pages. The caller already\n+ * holds folio references, so the pages cannot go away; this runs\n+ * without any page table lock held.\n+ */\n+static void gup_flush_pages(struct vm_area_struct *vma, unsigned long address,\n+\t\tstruct page **pages, unsigned long nr)\n+{\n+\tunsigned long i;\n+\n+\tif (!pages)\n+\t\treturn;\n+\n+\tfor (i = 0; i \u003c nr; i++) {\n+\t\tflush_anon_page(vma, pages[i], address + i * PAGE_SIZE);\n+\t\tflush_dcache_page(pages[i]);\n+\t}\n }\n \n #ifdef CONFIG_PGTABLE_HAS_HUGE_LEAVES\n@@ -646,38 +682,43 @@ static inline bool can_follow_write_pud(pud_t pud, struct page *page,\n \treturn can_follow_write_common(page, vma, flags);\n }\n \n-static struct page *follow_huge_pud(struct vm_area_struct *vma,\n-\t\t\t\t unsigned long addr, pud_t *pudp,\n-\t\t\t\t int flags, unsigned long *page_mask)\n+static long follow_huge_pud(struct vm_area_struct *vma,\n+\t\tunsigned long addr, unsigned long end, pud_t *pudp,\n+\t\tunsigned int flags, struct page **pages)\n {\n \tstruct mm_struct *mm = vma-\u003evm_mm;\n \tstruct page *page;\n \tpud_t pud = *pudp;\n \tunsigned long pfn = pud_pfn(pud);\n+\tunsigned long off, nr;\n \tint ret;\n \n \tassert_spin_locked(pud_lockptr(mm, pudp));\n \n \tif (!pud_present(pud))\n-\t\treturn NULL;\n+\t\treturn 0;\n \n \tif ((flags \u0026 FOLL_WRITE) \u0026\u0026\n \t !can_follow_write_pud(pud, pfn_to_page(pfn), vma, flags))\n-\t\treturn NULL;\n+\t\treturn 0;\n \n-\tpfn += (addr \u0026 ~PUD_MASK) \u003e\u003e PAGE_SHIFT;\n+\toff = PFN_DOWN(addr \u0026 ~PUD_MASK);\n+\tpfn += off;\n \tpage = pfn_to_page(pfn);\n \n \tif (!pud_write(pud) \u0026\u0026 gup_must_unshare(vma, flags, page))\n-\t\treturn ERR_PTR(-EMLINK);\n+\t\treturn -EMLINK;\n+\n+\tnr = min(HPAGE_PUD_NR - off, PFN_DOWN(end - addr));\n \n-\tret = try_grab_folio(page_folio(page), 1, flags);\n+\tret = try_grab_folio(page_folio(page), nr, flags);\n \tif (ret)\n-\t\tpage = ERR_PTR(ret);\n-\telse\n-\t\t*page_mask = HPAGE_PUD_NR - 1;\n+\t\treturn ret;\n+\n+\tif (pages)\n+\t\tpages[0] = page;\n \n-\treturn page;\n+\treturn nr;\n }\n \n /* FOLL_FORCE can write to even unwritable PMDs in COW mappings. */\n@@ -698,14 +739,14 @@ static inline bool can_follow_write_pmd(pmd_t pmd, struct page *page,\n \treturn !userfaultfd_huge_pmd_wp(vma, pmd);\n }\n \n-static struct page *follow_huge_pmd(struct vm_area_struct *vma,\n-\t\t\t\t unsigned long addr, pmd_t *pmd,\n-\t\t\t\t unsigned int flags,\n-\t\t\t\t unsigned long *page_mask)\n+static long follow_huge_pmd(struct vm_area_struct *vma,\n+\t\tunsigned long addr, unsigned long end, pmd_t *pmd,\n+\t\tunsigned int flags, struct page **pages)\n {\n \tstruct mm_struct *mm = vma-\u003evm_mm;\n \tpmd_t pmdval = *pmd;\n \tstruct page *page;\n+\tunsigned long off, nr;\n \tint ret;\n \n \tassert_spin_locked(pmd_lockptr(mm, pmd));\n@@ -713,50 +754,54 @@ static struct page *follow_huge_pmd(struct vm_area_struct *vma,\n \tpage = pmd_page(pmdval);\n \tif ((flags \u0026 FOLL_WRITE) \u0026\u0026\n \t !can_follow_write_pmd(pmdval, page, vma, flags))\n-\t\treturn NULL;\n+\t\treturn 0;\n \n \t/* Avoid dumping huge zero page */\n \tif ((flags \u0026 FOLL_DUMP) \u0026\u0026 is_huge_zero_pmd(pmdval))\n-\t\treturn ERR_PTR(-EFAULT);\n+\t\treturn -EFAULT;\n \n \tif (pmd_protnone(*pmd) \u0026\u0026 !gup_can_follow_protnone(vma, flags))\n-\t\treturn NULL;\n+\t\treturn 0;\n \n \tif (!pmd_write(pmdval) \u0026\u0026 gup_must_unshare(vma, flags, page))\n-\t\treturn ERR_PTR(-EMLINK);\n+\t\treturn -EMLINK;\n \n \tVM_WARN_ON_ONCE_PAGE((flags \u0026 FOLL_PIN) \u0026\u0026 PageAnon(page) \u0026\u0026\n \t\t\t !PageAnonExclusive(page), page);\n \n-\tret = try_grab_folio(page_folio(page), 1, flags);\n+\toff = PFN_DOWN(addr \u0026 ~HPAGE_PMD_MASK);\n+\tnr = min(HPAGE_PMD_NR - off, PFN_DOWN(end - addr));\n+\n+\tret = try_grab_folio(page_folio(page), nr, flags);\n \tif (ret)\n-\t\treturn ERR_PTR(ret);\n+\t\treturn ret;\n \n #ifdef CONFIG_TRANSPARENT_HUGEPAGE\n \tif (pmd_trans_huge(pmdval) \u0026\u0026 (flags \u0026 FOLL_TOUCH))\n \t\ttouch_pmd(vma, addr, pmd, flags \u0026 FOLL_WRITE);\n #endif\t/* CONFIG_TRANSPARENT_HUGEPAGE */\n \n-\tpage += (addr \u0026 ~HPAGE_PMD_MASK) \u003e\u003e PAGE_SHIFT;\n-\t*page_mask = HPAGE_PMD_NR - 1;\n+\tpage += off;\n+\n+\tif (pages)\n+\t\tpages[0] = page;\n \n-\treturn page;\n+\treturn nr;\n }\n \n #else /* CONFIG_PGTABLE_HAS_HUGE_LEAVES */\n-static struct page *follow_huge_pud(struct vm_area_struct *vma,\n-\t\t\t\t unsigned long addr, pud_t *pudp,\n-\t\t\t\t int flags, unsigned long *page_mask)\n+static long follow_huge_pud(struct vm_area_struct *vma,\n+\t\tunsigned long addr, unsigned long end, pud_t *pudp,\n+\t\tunsigned int flags, struct page **pages)\n {\n-\treturn NULL;\n+\treturn 0;\n }\n \n-static struct page *follow_huge_pmd(struct vm_area_struct *vma,\n-\t\t\t\t unsigned long addr, pmd_t *pmd,\n-\t\t\t\t unsigned int flags,\n-\t\t\t\t unsigned long *page_mask)\n+static long follow_huge_pmd(struct vm_area_struct *vma,\n+\t\tunsigned long addr, unsigned long end, pmd_t *pmd,\n+\t\tunsigned int flags, struct page **pages)\n {\n-\treturn NULL;\n+\treturn 0;\n }\n #endif\t/* CONFIG_PGTABLE_HAS_HUGE_LEAVES */\n \n@@ -799,110 +844,213 @@ static inline bool can_follow_write_pte(pte_t pte, struct page *page,\n \treturn !userfaultfd_pte_wp(vma, pte);\n }\n \n-static struct page *follow_page_pte(struct vm_area_struct *vma,\n-\t\tunsigned long address, pmd_t *pmd, unsigned int flags)\n+/*\n+ * Grab a folio reference for @nr pages starting at @page, mark the folio\n+ * accessed (and dirty for FOLL_WRITE), and store the pages for the caller.\n+ * The caller flushes the caches after dropping the page table lock.\n+ */\n+static long gup_grab_folio_pages(struct folio *folio,\n+\t\tstruct page *page, unsigned long nr, bool dirty,\n+\t\tunsigned int flags, struct page **pages)\n+{\n+\tunsigned long i;\n+\tlong ret;\n+\n+\t/* try_grab_folio() does nothing unless FOLL_GET or FOLL_PIN is set. */\n+\tret = try_grab_folio(folio, nr, flags);\n+\tif (unlikely(ret))\n+\t\treturn ret;\n+\n+\t/*\n+\t * We need to make the page accessible if and only if we are going\n+\t * to access its content (the FOLL_PIN case). Please see\n+\t * Documentation/core-api/pin_user_pages.rst for details.\n+\t */\n+\tif (flags \u0026 FOLL_PIN) {\n+\t\tret = arch_make_folio_accessible(folio);\n+\t\tif (ret) {\n+\t\t\tgup_put_folio(folio, nr, flags);\n+\t\t\treturn ret;\n+\t\t}\n+\t}\n+\tif (flags \u0026 FOLL_TOUCH) {\n+\t\tif ((flags \u0026 FOLL_WRITE) \u0026\u0026 !dirty \u0026\u0026 !folio_test_dirty(folio))\n+\t\t\tfolio_mark_dirty(folio);\n+\t\t/*\n+\t\t * pte_mkyoung() would be more correct here, but atomic care\n+\t\t * is needed to avoid losing the dirty bit: it is easier to use\n+\t\t * folio_mark_accessed().\n+\t\t */\n+\t\tfolio_mark_accessed(folio);\n+\t}\n+\n+\tif (pages) {\n+\t\tfor (i = 0; i \u003c nr; i++)\n+\t\t\tpages[i] = page + i;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * Resolve one present PTE to the page it maps. Returns no page and no error\n+ * when the PTE cannot be followed but the caller may fault it in, and a\n+ * negative errno when the caller must report the failure.\n+ */\n+static long gup_lookup_pte(struct vm_area_struct *vma, unsigned long address,\n+\t\tpte_t *ptep, pte_t pte, unsigned int flags, struct page **pagep)\n {\n-\tstruct mm_struct *mm = vma-\u003evm_mm;\n-\tstruct folio *folio;\n \tstruct page *page;\n-\tspinlock_t *ptl;\n-\tpte_t *ptep, pte;\n-\tint ret;\n \n-\tptep = pte_offset_map_lock(mm, pmd, address, \u0026ptl);\n-\tif (!ptep)\n-\t\treturn no_page_table(vma, flags, address);\n-\tpte = ptep_get(ptep);\n+\t*pagep = NULL;\n+\n \tif (!pte_present(pte))\n-\t\tgoto no_page;\n+\t\treturn 0;\n \tif (pte_protnone(pte) \u0026\u0026 !gup_can_follow_protnone(vma, flags))\n-\t\tgoto no_page;\n+\t\treturn 0;\n \n \tpage = vm_normal_page(vma, address, pte);\n \n \t/*\n \t * We only care about anon pages in can_follow_write_pte().\n \t */\n-\tif ((flags \u0026 FOLL_WRITE) \u0026\u0026\n-\t !can_follow_write_pte(pte, page, vma, flags)) {\n-\t\tpage = NULL;\n-\t\tgoto out;\n-\t}\n+\tif ((flags \u0026 FOLL_WRITE) \u0026\u0026 !can_follow_write_pte(pte, page, vma, flags))\n+\t\treturn 0;\n \n \tif (unlikely(!page)) {\n \t\tif (flags \u0026 FOLL_DUMP) {\n \t\t\t/* Avoid special (like zero) pages in core dumps */\n-\t\t\tpage = ERR_PTR(-EFAULT);\n-\t\t\tgoto out;\n-\t\t}\n-\n-\t\tif (is_zero_pfn(pte_pfn(pte))) {\n-\t\t\tpage = pte_page(pte);\n-\t\t} else {\n-\t\t\tret = follow_pfn_pte(vma, address, ptep, flags);\n-\t\t\tpage = ERR_PTR(ret);\n-\t\t\tgoto out;\n+\t\t\treturn -EFAULT;\n \t\t}\n+\t\tif (!is_zero_pfn(pte_pfn(pte)))\n+\t\t\treturn follow_pfn_pte(vma, address, ptep, flags);\n+\t\tpage = pte_page(pte);\n \t}\n-\tfolio = page_folio(page);\n \n-\tif (!pte_write(pte) \u0026\u0026 gup_must_unshare(vma, flags, page)) {\n-\t\tpage = ERR_PTR(-EMLINK);\n-\t\tgoto out;\n-\t}\n+\tif (!pte_write(pte) \u0026\u0026 gup_must_unshare(vma, flags, page))\n+\t\treturn -EMLINK;\n \n \tVM_WARN_ON_ONCE_PAGE((flags \u0026 FOLL_PIN) \u0026\u0026 PageAnon(page) \u0026\u0026\n \t\t\t !PageAnonExclusive(page), page);\n \n-\t/* try_grab_folio() does nothing unless FOLL_GET or FOLL_PIN is set. */\n-\tret = try_grab_folio(folio, 1, flags);\n-\tif (unlikely(ret)) {\n-\t\tpage = ERR_PTR(ret);\n-\t\tgoto out;\n-\t}\n+\t*pagep = page;\n+\treturn 0;\n+}\n \n-\t/*\n-\t * We need to make the page accessible if and only if we are going\n-\t * to access its content (the FOLL_PIN case). Please see\n-\t * Documentation/core-api/pin_user_pages.rst for details.\n-\t */\n-\tif (flags \u0026 FOLL_PIN) {\n-\t\tret = arch_make_folio_accessible(folio);\n-\t\tif (ret) {\n-\t\t\tunpin_user_page(page);\n-\t\t\tpage = ERR_PTR(ret);\n-\t\t\tgoto out;\n+/*\n+ * Return how many PTEs map consecutive pages of the same folio and can be\n+ * committed as one run. Always at least 1.\n+ *\n+ * The write-fault and unshare checks in gup_lookup_pte() are per PTE, but a\n+ * writable run needs no repeat: a writable anon page is exclusive. A read-only\n+ * run under FOLL_WRITE or FOLL_PIN does need the per-page check, so it stays\n+ * one page at a time.\n+ */\n+static unsigned long gup_pte_batch_len(struct vm_area_struct *vma,\n+\t\tunsigned long address, unsigned long walk_end,\n+\t\tstruct folio *folio, pte_t *ptep, pte_t *batch_pte, unsigned int flags)\n+{\n+\tunsigned long max;\n+\n+\tif (!folio_test_large(folio))\n+\t\treturn 1;\n+\tif (!pte_write(*batch_pte) \u0026\u0026 (flags \u0026 (FOLL_WRITE | FOLL_PIN)))\n+\t\treturn 1;\n+\n+\tmax = (walk_end - address) \u003e\u003e PAGE_SHIFT;\n+\tif (max \u003c= 1)\n+\t\treturn 1;\n+\n+\t/* Merge young/dirty across batch so folio_mark_dirty sees any dirty. */\n+\treturn folio_pte_batch_flags(folio, vma, ptep, batch_pte, max,\n+\t\t\t\t FPB_RESPECT_WRITE | FPB_MERGE_YOUNG_DIRTY);\n+}\n+\n+/*\n+ * Walk the PTEs from the start address to the end of this page table or VMA,\n+ * whichever comes first, and commit every page found.\n+ *\n+ * A failure on the first PTE is returned to the caller. A failure after that\n+ * is a short read; __get_user_pages() retrying the read will get the error.\n+ *\n+ * Return: the number of pages stored in @pages, 0 when no mapping exists at\n+ * the start address, or a negative errno for a failure on the first PTE.\n+ */\n+static long follow_page_pte(struct vm_area_struct *vma,\n+\t\tunsigned long address, unsigned long end, pmd_t *pmd,\n+\t\tunsigned int flags, struct page **pages)\n+{\n+\tstruct mm_struct *mm = vma-\u003evm_mm;\n+\tbool need_no_page_table = false;\n+\tpte_t *ptep, *orig_ptep;\n+\tunsigned long walk_end, base;\n+\tunsigned long nr = 0;\n+\tspinlock_t *ptl;\n+\tlong ret = 0;\n+\n+\torig_ptep = ptep = pte_offset_map_lock(mm, pmd, address, \u0026ptl);\n+\tif (!ptep)\n+\t\treturn no_page_table(vma, flags, address);\n+\n+\tbase = address;\n+\twalk_end = min(pmd_addr_end(address, end), vma-\u003evm_end);\n+\n+\tfor (; address \u003c walk_end; address += PAGE_SIZE, ptep++) {\n+\t\tpte_t pte = ptep_get(ptep);\n+\t\tstruct folio *folio;\n+\t\tstruct page *page;\n+\t\tunsigned long batch;\n+\t\tpte_t batch_pte;\n+\n+\t\tret = gup_lookup_pte(vma, address, ptep, pte, flags, \u0026page);\n+\t\tif (ret || !page) {\n+\t\t\t/*\n+\t\t\t * no_page_table() may look up the page cache, so it\n+\t\t\t * cannot run under the PTE lock. A none PTE returns\n+\t\t\t * from gup_lookup_pte() before any write check runs,\n+\t\t\t * so this is the same call the old code made -- not a\n+\t\t\t * new failure mode for FOLL_WRITE.\n+\t\t\t */\n+\t\t\tif (!ret \u0026\u0026 pte_none(pte))\n+\t\t\t\tneed_no_page_table = true;\n+\t\t\tbreak;\n \t\t}\n-\t}\n-\tif (flags \u0026 FOLL_TOUCH) {\n-\t\tif ((flags \u0026 FOLL_WRITE) \u0026\u0026\n-\t\t !pte_dirty(pte) \u0026\u0026 !folio_test_dirty(folio))\n-\t\t\tfolio_mark_dirty(folio);\n+\t\tfolio = page_folio(page);\n+\t\tbatch_pte = pte;\n+\n+\t\tbatch = gup_pte_batch_len(vma, address, walk_end, folio,\n+\t\t\t\t\t ptep, \u0026batch_pte, flags);\n+\t\tret = gup_grab_folio_pages(folio, page, batch,\n+\t\t\t\t\t\t pte_dirty(batch_pte), flags,\n+\t\t\t\t\t\t pages ? pages + nr : NULL);\n+\t\tif (ret)\n+\t\t\tbreak;\n+\t\tnr += batch;\n \t\t/*\n-\t\t * pte_mkyoung() would be more correct here, but atomic care\n-\t\t * is needed to avoid losing the dirty bit: it is easier to use\n-\t\t * folio_mark_accessed().\n+\t\t * The loop's own increment covers one PTE; skip\n+\t\t * the rest of the batch.\n \t\t */\n-\t\tfolio_mark_accessed(folio);\n+\t\tptep += batch - 1;\n+\t\taddress += (batch - 1) * PAGE_SIZE;\n \t}\n-out:\n-\tpte_unmap_unlock(ptep, ptl);\n-\treturn page;\n-no_page:\n-\tpte_unmap_unlock(ptep, ptl);\n-\tif (!pte_none(pte))\n-\t\treturn NULL;\n-\treturn no_page_table(vma, flags, address);\n+\tpte_unmap_unlock(orig_ptep, ptl);\n+\n+\tif (nr) {\n+\t\tgup_flush_pages(vma, base, pages, nr);\n+\t\treturn nr;\n+\t}\n+\tif (need_no_page_table)\n+\t\treturn no_page_table(vma, flags, address);\n+\treturn ret;\n }\n \n-static struct page *follow_pmd_mask(struct vm_area_struct *vma,\n-\t\t\t\t unsigned long address, pud_t *pudp,\n-\t\t\t\t unsigned int flags,\n-\t\t\t\t unsigned long *page_mask)\n+static long follow_pmd_mask(struct vm_area_struct *vma,\n+\t\tunsigned long address, unsigned long end, pud_t *pudp,\n+\t\tunsigned int flags, struct page **pages)\n {\n \tpmd_t *pmd, pmdval;\n \tspinlock_t *ptl;\n-\tstruct page *page;\n+\tlong ret;\n \tstruct mm_struct *mm = vma-\u003evm_mm;\n \n \tpmd = pmd_offset(pudp, address);\n@@ -912,7 +1060,7 @@ static struct page *follow_pmd_mask(struct vm_area_struct *vma,\n \tif (!pmd_present(pmdval))\n \t\treturn no_page_table(vma, flags, address);\n \tif (likely(!pmd_leaf(pmdval)))\n-\t\treturn follow_page_pte(vma, address, pmd, flags);\n+\t\treturn follow_page_pte(vma, address, end, pmd, flags, pages);\n \n \tif (pmd_protnone(pmdval) \u0026\u0026 !gup_can_follow_protnone(vma, flags))\n \t\treturn no_page_table(vma, flags, address);\n@@ -925,28 +1073,35 @@ static struct page *follow_pmd_mask(struct vm_area_struct *vma,\n \t}\n \tif (unlikely(!pmd_leaf(pmdval))) {\n \t\tspin_unlock(ptl);\n-\t\treturn follow_page_pte(vma, address, pmd, flags);\n+\t\treturn follow_page_pte(vma, address, end, pmd, flags, pages);\n \t}\n \tif (pmd_trans_huge(pmdval) \u0026\u0026 (flags \u0026 FOLL_SPLIT_PMD)) {\n \t\tspin_unlock(ptl);\n \t\tsplit_huge_pmd(vma, pmd, address);\n \t\t/* If pmd was left empty, stuff a page table in there quickly */\n-\t\treturn pte_alloc(mm, pmd) ? ERR_PTR(-ENOMEM) :\n-\t\t\tfollow_page_pte(vma, address, pmd, flags);\n+\t\treturn pte_alloc(mm, pmd) ? -ENOMEM :\n+\t\t\tfollow_page_pte(vma, address, end, pmd, flags, pages);\n \t}\n-\tpage = follow_huge_pmd(vma, address, pmd, flags, page_mask);\n+\tret = follow_huge_pmd(vma, address, end, pmd, flags, pages);\n \tspin_unlock(ptl);\n-\treturn page;\n+\n+\t/*\n+\t * The ref is already held, so the page cannot go away: fill the\n+\t * array and flush caches without the pmd lock.\n+\t */\n+\tif (ret \u003e 0 \u0026\u0026 pages)\n+\t\tgup_fill_pages(vma, address, pages[0], ret, pages);\n+\n+\treturn ret;\n }\n \n-static struct page *follow_pud_mask(struct vm_area_struct *vma,\n-\t\t\t\t unsigned long address, p4d_t *p4dp,\n-\t\t\t\t unsigned int flags,\n-\t\t\t\t unsigned long *page_mask)\n+static long follow_pud_mask(struct vm_area_struct *vma,\n+\t\tunsigned long address, unsigned long end, p4d_t *p4dp,\n+\t\tunsigned int flags, struct page **pages)\n {\n \tpud_t *pudp, pud;\n \tspinlock_t *ptl;\n-\tstruct page *page;\n+\tlong ret;\n \tstruct mm_struct *mm = vma-\u003evm_mm;\n \n \tpudp = pud_offset(p4dp, address);\n@@ -955,22 +1110,29 @@ static struct page *follow_pud_mask(struct vm_area_struct *vma,\n \t\treturn no_page_table(vma, flags, address);\n \tif (pud_leaf(pud)) {\n \t\tptl = pud_lock(mm, pudp);\n-\t\tpage = follow_huge_pud(vma, address, pudp, flags, page_mask);\n+\t\tret = follow_huge_pud(vma, address, end, pudp, flags, pages);\n \t\tspin_unlock(ptl);\n-\t\tif (page)\n-\t\t\treturn page;\n+\t\t/*\n+\t\t * The ref is already held, so the page cannot go away: fill\n+\t\t * the array and flush caches without the lock. A 1 GB folio\n+\t\t * can be up to HPAGE_PUD_NR pages, too long to flush under a\n+\t\t * spinlock.\n+\t\t */\n+\t\tif (ret \u003e 0 \u0026\u0026 pages)\n+\t\t\tgup_fill_pages(vma, address, pages[0], ret, pages);\n+\t\tif (ret)\n+\t\t\treturn ret;\n \t\treturn no_page_table(vma, flags, address);\n \t}\n \tif (unlikely(pud_bad(pud)))\n \t\treturn no_page_table(vma, flags, address);\n \n-\treturn follow_pmd_mask(vma, address, pudp, flags, page_mask);\n+\treturn follow_pmd_mask(vma, address, end, pudp, flags, pages);\n }\n \n-static struct page *follow_p4d_mask(struct vm_area_struct *vma,\n-\t\t\t\t unsigned long address, pgd_t *pgdp,\n-\t\t\t\t unsigned int flags,\n-\t\t\t\t unsigned long *page_mask)\n+static long follow_p4d_mask(struct vm_area_struct *vma,\n+\t\tunsigned long address, unsigned long end, pgd_t *pgdp,\n+\t\tunsigned int flags, struct page **pages)\n {\n \tp4d_t *p4dp, p4d;\n \n@@ -981,15 +1143,18 @@ static struct page *follow_p4d_mask(struct vm_area_struct *vma,\n \tif (!p4d_present(p4d) || p4d_bad(p4d))\n \t\treturn no_page_table(vma, flags, address);\n \n-\treturn follow_pud_mask(vma, address, p4dp, flags, page_mask);\n+\treturn follow_pud_mask(vma, address, end, p4dp, flags, pages);\n }\n \n /**\n- * follow_page_mask - look up a page descriptor from a user-virtual address\n+ * follow_page_mask - look up pages at a user-virtual address\n * @vma: vm_area_struct mapping @address\n * @address: virtual address to look up\n+ * @end: virtual address at which to stop batching contiguous pages\n * @flags: flags modifying lookup behaviour\n- * @page_mask: a pointer to output page_mask\n+ * @pages: array to receive the pages, refcounted per @flags, or NULL to\n+ * walk the page tables (e.g. to fault pages in) without collecting\n+ * or refcounting them\n *\n * @flags can have FOLL_ flags set, defined in \u003clinux/mm.h\u003e\n *\n@@ -998,33 +1163,32 @@ static struct page *follow_p4d_mask(struct vm_area_struct *vma,\n * trigger a fault with FAULT_FLAG_UNSHARE set. Note that unsharing is only\n * relevant with FOLL_PIN and !FOLL_WRITE.\n *\n- * On output, @page_mask is set according to the size of the page.\n- *\n- * Return: the mapped (struct page *), %NULL if no mapping exists, or\n- * an error pointer if there is a mapping to something not represented\n- * by a page descriptor (see also vm_normal_page()).\n+ * Return: the number of contiguous pages starting at @address that were\n+ * placed into @pages (if non-NULL), which may be fewer than the pages\n+ * requested via @end; 0 if no mapping exists at @address; or a negative\n+ * errno for a mapping to something not represented by a page descriptor\n+ * (see also vm_normal_page()).\n */\n-static struct page *follow_page_mask(struct vm_area_struct *vma,\n-\t\t\t unsigned long address, unsigned int flags,\n-\t\t\t unsigned long *page_mask)\n+static long follow_page_mask(struct vm_area_struct *vma,\n+\t\tunsigned long address, unsigned long end,\n+\t\tunsigned int flags, struct page **pages)\n {\n \tpgd_t *pgd;\n \tstruct mm_struct *mm = vma-\u003evm_mm;\n-\tstruct page *page;\n+\tlong ret;\n \n \tvma_pgtable_walk_begin(vma);\n \n-\t*page_mask = 0;\n \tpgd = pgd_offset(mm, address);\n \n \tif (pgd_none(*pgd) || unlikely(pgd_bad(*pgd)))\n-\t\tpage = no_page_table(vma, flags, address);\n+\t\tret = no_page_table(vma, flags, address);\n \telse\n-\t\tpage = follow_p4d_mask(vma, address, pgd, flags, page_mask);\n+\t\tret = follow_p4d_mask(vma, address, end, pgd, flags, pages);\n \n \tvma_pgtable_walk_end(vma);\n \n-\treturn page;\n+\treturn ret;\n }\n \n static int get_gate_page(struct mm_struct *mm, unsigned long address,\n@@ -1358,7 +1522,6 @@ static long __get_user_pages(struct mm_struct *mm,\n {\n \tlong ret = 0, i = 0;\n \tstruct vm_area_struct *vma = NULL;\n-\tunsigned long page_mask = 0;\n \n \tif (!nr_pages)\n \t\treturn 0;\n@@ -1373,7 +1536,7 @@ static long __get_user_pages(struct mm_struct *mm,\n \n \tdo {\n \t\tstruct page *page;\n-\t\tunsigned int page_increm;\n+\t\tlong nr;\n \n \t\t/* first iteration or cross vma bound */\n \t\tif (!vma || start \u003e= vma-\u003evm_end) {\n@@ -1400,8 +1563,12 @@ static long __get_user_pages(struct mm_struct *mm,\n \t\t\t\t\t\tpages ? \u0026page : NULL);\n \t\t\t\tif (ret)\n \t\t\t\t\tgoto out;\n-\t\t\t\tpage_mask = 0;\n-\t\t\t\tgoto next_page;\n+\t\t\t\tgup_fill_pages(vma, start, page, 1,\n+\t\t\t\t\t pages ? pages + i : NULL);\n+\t\t\t\ti++;\n+\t\t\t\tstart += PAGE_SIZE;\n+\t\t\t\tnr_pages--;\n+\t\t\t\tcontinue;\n \t\t\t}\n \n \t\t\tif (!vma) {\n@@ -1423,10 +1590,11 @@ static long __get_user_pages(struct mm_struct *mm,\n \t\t}\n \t\tcond_resched();\n \n-\t\tpage = follow_page_mask(vma, start, gup_flags, \u0026page_mask);\n-\t\tif (!page || PTR_ERR(page) == -EMLINK) {\n+\t\tnr = follow_page_mask(vma, start, start + nr_pages * PAGE_SIZE,\n+\t\t\t\t gup_flags, pages ? \u0026pages[i] : NULL);\n+\t\tif (!nr || nr == -EMLINK) {\n \t\t\tret = faultin_page(vma, start, gup_flags,\n-\t\t\t\t\t PTR_ERR(page) == -EMLINK, locked);\n+\t\t\t\t\t nr == -EMLINK, locked);\n \t\t\tswitch (ret) {\n \t\t\tcase 0:\n \t\t\t\tgoto retry;\n@@ -1440,70 +1608,30 @@ static long __get_user_pages(struct mm_struct *mm,\n \t\t\t\tgoto out;\n \t\t\t}\n \t\t\tBUG();\n-\t\t} else if (PTR_ERR(page) == -EEXIST) {\n+\t\t} else if (nr == -EEXIST) {\n \t\t\t/*\n \t\t\t * Proper page table entry exists, but no corresponding\n \t\t\t * struct page. If the caller expects **pages to be\n \t\t\t * filled in, bail out now, because that can't be done\n-\t\t\t * for this page.\n+\t\t\t * for this page. Otherwise advance by the one page\n+\t\t\t * follow_page_mask() looked at.\n \t\t\t */\n \t\t\tif (pages) {\n-\t\t\t\tret = PTR_ERR(page);\n+\t\t\t\tret = nr;\n \t\t\t\tgoto out;\n \t\t\t}\n-\t\t} else if (IS_ERR(page)) {\n-\t\t\tret = PTR_ERR(page);\n+\t\t\tnr = 1;\n+\t\t} else if (nr \u003c 0) {\n+\t\t\tret = nr;\n \t\t\tgoto out;\n \t\t}\n-next_page:\n-\t\tpage_increm = 1 + (~(start \u003e\u003e PAGE_SHIFT) \u0026 page_mask);\n-\t\tif (page_increm \u003e nr_pages)\n-\t\t\tpage_increm = nr_pages;\n-\n-\t\tif (pages) {\n-\t\t\tstruct page *subpage;\n-\t\t\tunsigned int j;\n-\n-\t\t\t/*\n-\t\t\t * This must be a large folio (and doesn't need to\n-\t\t\t * be the whole folio; it can be part of it), do\n-\t\t\t * the refcount work for all the subpages too.\n-\t\t\t *\n-\t\t\t * NOTE: here the page may not be the head page\n-\t\t\t * e.g. when start addr is not thp-size aligned.\n-\t\t\t * try_grab_folio() should have taken care of tail\n-\t\t\t * pages.\n-\t\t\t */\n-\t\t\tif (page_increm \u003e 1) {\n-\t\t\t\tstruct folio *folio = page_folio(page);\n-\n-\t\t\t\t/*\n-\t\t\t\t * Since we already hold refcount on the\n-\t\t\t\t * large folio, this should never fail.\n-\t\t\t\t */\n-\t\t\t\tif (try_grab_folio(folio, page_increm - 1,\n-\t\t\t\t\t\t gup_flags)) {\n-\t\t\t\t\t/*\n-\t\t\t\t\t * Release the 1st page ref if the\n-\t\t\t\t\t * folio is problematic, fail hard.\n-\t\t\t\t\t */\n-\t\t\t\t\tgup_put_folio(folio, 1, gup_flags);\n-\t\t\t\t\tret = -EFAULT;\n-\t\t\t\t\tgoto out;\n-\t\t\t\t}\n-\t\t\t}\n \n-\t\t\tfor (j = 0; j \u003c page_increm; j++) {\n-\t\t\t\tsubpage = page + j;\n-\t\t\t\tpages[i + j] = subpage;\n-\t\t\t\tflush_anon_page(vma, subpage, start + j * PAGE_SIZE);\n-\t\t\t\tflush_dcache_page(subpage);\n-\t\t\t}\n-\t\t}\n+\t\t/* Check that we didn't pin more pages than the caller will free. */\n+\t\tVM_WARN_ON_ONCE(nr \u003e nr_pages);\n \n-\t\ti += page_increm;\n-\t\tstart += page_increm * PAGE_SIZE;\n-\t\tnr_pages -= page_increm;\n+\t\ti += nr;\n+\t\tstart += nr * PAGE_SIZE;\n+\t\tnr_pages -= nr;\n \t} while (nr_pages);\n out:\n \treturn i ? i : ret;\n"
} |
| 2/1 | 2026/11/03 12:45 | agent | patch-evaluator |
19mModel:core Args: null Results: {
"EnableConfigs": [
"MMU",
"TRANSPARENT_HUGEPAGE",
"HUGETLBFS"
],
"FocusSymbols": [
"__get_user_pages",
"follow_page_mask",
"follow_page_pte",
"follow_huge_pmd",
"follow_huge_pud",
"follow_pmd_mask",
"gup_pte_batch_len",
"gup_grab_folio_pages"
],
"Reasoning": "The patch refactors the core memory management page table walk in mm/gup.c (get_user_pages / follow_page_mask) to support batching of contiguous PTEs and huge PMDs/PUDs for folios. It reworks reference acquisition (try_grab_folio), dirty/accessed tracking, error propagation, cache flushing, and adds a runtime assertion (VM_WARN_ON_ONCE(nr \u003e nr_pages)). This code is fully reachable in virtualized environments via syscalls exercising GUP (e.g., madvise with MADV_POPULATE_READ/WRITE, mlock, process_vm_readv/writev, ptrace, io_uring, direct I/O).",
"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 ec6963d74782bda695601c9573e98ad620e5c8e5
Author: syz-cluster <triage@syzkaller.com>
Date: Tue Nov 3 12:45:18 2026 +0000
syz-cluster: applied patch under review
diff --git a/mm/gup.c b/mm/gup.c
index 7d43ce717b2461..47f204e21a3a79 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -608,15 +608,15 @@ static inline bool can_follow_write_common(struct page *page,
return page && PageAnon(page) && PageAnonExclusive(page);
}
-static struct page *no_page_table(struct vm_area_struct *vma,
- unsigned int flags, unsigned long address)
+static long no_page_table(struct vm_area_struct *vma,
+ unsigned int flags, unsigned long address)
{
if (!(flags & FOLL_DUMP))
- return NULL;
+ return 0;
/*
* When core dumping, we don't want to allocate unnecessary pages or
- * page tables. Return error instead of NULL to skip handle_mm_fault,
+ * page tables. Return error instead of 0 to skip handle_mm_fault,
* then get_dump_page() will return NULL to leave a hole in the dump.
* But we can only make this optimization where a hole would surely
* be zero-filled if handle_mm_fault() actually did handle it.
@@ -625,12 +625,48 @@ static struct page *no_page_table(struct vm_area_struct *vma,
struct hstate *h = hstate_vma(vma);
if (!hugetlbfs_pagecache_present(h, vma, address))
- return ERR_PTR(-EFAULT);
+ return -EFAULT;
} else if ((vma_is_anonymous(vma) || !vma->vm_ops->fault)) {
- return ERR_PTR(-EFAULT);
+ return -EFAULT;
}
- return NULL;
+ return 0;
+}
+
+static void gup_fill_pages(struct vm_area_struct *vma, unsigned long address,
+ struct page *page, unsigned long nr, struct page **pages)
+{
+ unsigned long i;
+
+ if (!pages)
+ return;
+
+ for (i = 0; i < nr; i++) {
+ struct page *subpage = page + i;
+
+ pages[i] = subpage;
+ flush_anon_page(vma, subpage, address + i * PAGE_SIZE);
+ flush_dcache_page(subpage);
+ }
+}
+
+/*
+ * Flush the caches for @nr pages stored in @pages. The caller already
+ * holds folio references, so the pages cannot go away; this runs
+ * without any page table lock held.
+ */
+static void gup_flush_pages(struct vm_area_struct *vma, unsigned long address,
+ struct page **pages, unsigned long nr)
+{
+ unsigned long i;
+
+ if (!pages)
+ return;
+
+ for (i = 0; i < nr; i++) {
+ flush_anon_page(vma, pages[i], address + i * PAGE_SIZE);
+ flush_dcache_page(pages[i]);
+ }
}
#ifdef CONFIG_PGTABLE_HAS_HUGE_LEAVES
@@ -646,38 +682,43 @@ static inline bool can_follow_write_pud(pud_t pud, struct page *page,
return can_follow_write_common(page, vma, flags);
}
-static struct page *follow_huge_pud(struct vm_area_struct *vma,
- unsigned long addr, pud_t *pudp,
- int flags, unsigned long *page_mask)
+static long follow_huge_pud(struct vm_area_struct *vma,
+ unsigned long addr, unsigned long end, pud_t *pudp,
+ unsigned int flags, struct page **pages)
{
struct mm_struct *mm = vma->vm_mm;
struct page *page;
pud_t pud = *pudp;
unsigned long pfn = pud_pfn(pud);
+ unsigned long off, nr;
int ret;
assert_spin_locked(pud_lockptr(mm, pudp));
if (!pud_present(pud))
- return NULL;
+ return 0;
if ((flags & FOLL_WRITE) &&
!can_follow_write_pud(pud, pfn_to_page(pfn), vma, flags))
- return NULL;
+ return 0;
- pfn += (addr & ~PUD_MASK) >> PAGE_SHIFT;
+ off = PFN_DOWN(addr & ~PUD_MASK);
+ pfn += off;
page = pfn_to_page(pfn);
if (!pud_write(pud) && gup_must_unshare(vma, flags, page))
- return ERR_PTR(-EMLINK);
+ return -EMLINK;
+
+ nr = min(HPAGE_PUD_NR - off, PFN_DOWN(end - addr));
- ret = try_grab_folio(page_folio(page), 1, flags);
+ ret = try_grab_folio(page_folio(page), nr, flags);
if (ret)
- page = ERR_PTR(ret);
- else
- *page_mask = HPAGE_PUD_NR - 1;
+ return ret;
+
+ if (pages)
+ pages[0] = page;
- return page;
+ return nr;
}
/* FOLL_FORCE can write to even unwritable PMDs in COW mappings. */
@@ -698,14 +739,14 @@ static inline bool can_follow_write_pmd(pmd_t pmd, struct page *page,
return !userfaultfd_huge_pmd_wp(vma, pmd);
}
-static struct page *follow_huge_pmd(struct vm_area_struct *vma,
- unsigned long addr, pmd_t *pmd,
- unsigned int flags,
- unsigned long *page_mask)
+static long follow_huge_pmd(struct vm_area_struct *vma,
+ unsigned long addr, unsigned long end, pmd_t *pmd,
+ unsigned int flags, struct page **pages)
{
struct mm_struct *mm = vma->vm_mm;
pmd_t pmdval = *pmd;
struct page *page;
+ unsigned long off, nr;
int ret;
assert_spin_locked(pmd_lockptr(mm, pmd));
@@ -713,50 +754,54 @@ static struct page *follow_huge_pmd(struct vm_area_struct *vma,
page = pmd_page(pmdval);
if ((flags & FOLL_WRITE) &&
!can_follow_write_pmd(pmdval, page, vma, flags))
- return NULL;
+ return 0;
/* Avoid dumping huge zero page */
if ((flags & FOLL_DUMP) && is_huge_zero_pmd(pmdval))
- return ERR_PTR(-EFAULT);
+ return -EFAULT;
if (pmd_protnone(*pmd) && !gup_can_follow_protnone(vma, flags))
- return NULL;
+ return 0;
if (!pmd_write(pmdval) && gup_must_unshare(vma, flags, page))
- return ERR_PTR(-EMLINK);
+ return -EMLINK;
VM_WARN_ON_ONCE_PAGE((flags & FOLL_PIN) && PageAnon(page) &&
!PageAnonExclusive(page), page);
- ret = try_grab_folio(page_folio(page), 1, flags);
+ off = PFN_DOWN(addr & ~HPAGE_PMD_MASK);
+ nr = min(HPAGE_PMD_NR - off, PFN_DOWN(end - addr));
+
+ ret = try_grab_folio(page_folio(page), nr, flags);
if (ret)
- return ERR_PTR(ret);
+ return ret;
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
if (pmd_trans_huge(pmdval) && (flags & FOLL_TOUCH))
touch_pmd(vma, addr, pmd, flags & FOLL_WRITE);
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
- page += (addr & ~HPAGE_PMD_MASK) >> PAGE_SHIFT;
- *page_mask = HPAGE_PMD_NR - 1;
+ page += off;
+
+ if (pages)
+ pages[0] = page;
- return page;
+ return nr;
}
#else /* CONFIG_PGTABLE_HAS_HUGE_LEAVES */
-static struct page *follow_huge_pud(struct vm_area_struct *vma,
- unsigned long addr, pud_t *pudp,
- int flags, unsigned long *page_mask)
+static long follow_huge_pud(struct vm_area_struct *vma,
+ unsigned long addr, unsigned long end, pud_t *pudp,
+ unsigned int flags, struct page **pages)
{
- return NULL;
+ return 0;
}
-static struct page *follow_huge_pmd(struct vm_area_struct *vma,
- unsigned long addr, pmd_t *pmd,
- unsigned int flags,
- unsigned long *page_mask)
+static long follow_huge_pmd(struct vm_area_struct *vma,
+ unsigned long addr, unsigned long end, pmd_t *pmd,
+ unsigned int flags, struct page **pages)
{
- return NULL;
+ return 0;
}
#endif /* CONFIG_PGTABLE_HAS_HUGE_LEAVES */
@@ -799,110 +844,213 @@ static inline bool can_follow_write_pte(pte_t pte, struct page *page,
return !userfaultfd_pte_wp(vma, pte);
}
-static struct page *follow_page_pte(struct vm_area_struct *vma,
- unsigned long address, pmd_t *pmd, unsigned int flags)
+/*
+ * Grab a folio reference for @nr pages starting at @page, mark the folio
+ * accessed (and dirty for FOLL_WRITE), and store the pages for the caller.
+ * The caller flushes the caches after dropping the page table lock.
+ */
+static long gup_grab_folio_pages(struct folio *folio,
+ struct page *page, unsigned long nr, bool dirty,
+ unsigned int flags, struct page **pages)
+{
+ unsigned long i;
+ long ret;
+
+ /* try_grab_folio() does nothing unless FOLL_GET or FOLL_PIN is set. */
+ ret = try_grab_folio(folio, nr, flags);
+ if (unlikely(ret))
+ return ret;
+
+ /*
+ * We need to make the page accessible if and only if we are going
+ * to access its content (the FOLL_PIN case). Please see
+ * Documentation/core-api/pin_user_pages.rst for details.
+ */
+ if (flags & FOLL_PIN) {
+ ret = arch_make_folio_accessible(folio);
+ if (ret) {
+ gup_put_folio(folio, nr, flags);
+ return ret;
+ }
+ }
+ if (flags & FOLL_TOUCH) {
+ if ((flags & FOLL_WRITE) && !dirty && !folio_test_dirty(folio))
+ folio_mark_dirty(folio);
+ /*
+ * pte_mkyoung() would be more correct here, but atomic care
+ * is needed to avoid losing the dirty bit: it is easier to use
+ * folio_mark_accessed().
+ */
+ folio_mark_accessed(folio);
+ }
+
+ if (pages) {
+ for (i = 0; i < nr; i++)
+ pages[i] = page + i;
+ }
+
+ return 0;
+}
+
+/*
+ * Resolve one present PTE to the page it maps. Returns no page and no error
+ * when the PTE cannot be followed but the caller may fault it in, and a
+ * negative errno when the caller must report the failure.
+ */
+static long gup_lookup_pte(struct vm_area_struct *vma, unsigned long address,
+ pte_t *ptep, pte_t pte, unsigned int flags, struct page **pagep)
{
- struct mm_struct *mm = vma->vm_mm;
- struct folio *folio;
struct page *page;
- spinlock_t *ptl;
- pte_t *ptep, pte;
- int ret;
- ptep = pte_offset_map_lock(mm, pmd, address, &ptl);
- if (!ptep)
- return no_page_table(vma, flags, address);
- pte = ptep_get(ptep);
+ *pagep = NULL;
+
if (!pte_present(pte))
- goto no_page;
+ return 0;
if (pte_protnone(pte) && !gup_can_follow_protnone(vma, flags))
- goto no_page;
+ return 0;
page = vm_normal_page(vma, address, pte);
/*
* We only care about anon pages in can_follow_write_pte().
*/
- if ((flags & FOLL_WRITE) &&
- !can_follow_write_pte(pte, page, vma, flags)) {
- page = NULL;
- goto out;
- }
+ if ((flags & FOLL_WRITE) && !can_follow_write_pte(pte, page, vma, flags))
+ return 0;
if (unlikely(!page)) {
if (flags & FOLL_DUMP) {
/* Avoid special (like zero) pages in core dumps */
- page = ERR_PTR(-EFAULT);
- goto out;
- }
-
- if (is_zero_pfn(pte_pfn(pte))) {
- page = pte_page(pte);
- } else {
- ret = follow_pfn_pte(vma, address, ptep, flags);
- page = ERR_PTR(ret);
- goto out;
+ return -EFAULT;
}
+ if (!is_zero_pfn(pte_pfn(pte)))
+ return follow_pfn_pte(vma, address, ptep, flags);
+ page = pte_page(pte);
}
- folio = page_folio(page);
- if (!pte_write(pte) && gup_must_unshare(vma, flags, page)) {
- page = ERR_PTR(-EMLINK);
- goto out;
- }
+ if (!pte_write(pte) && gup_must_unshare(vma, flags, page))
+ return -EMLINK;
VM_WARN_ON_ONCE_PAGE((flags & FOLL_PIN) && PageAnon(page) &&
!PageAnonExclusive(page), page);
- /* try_grab_folio() does nothing unless FOLL_GET or FOLL_PIN is set. */
- ret = try_grab_folio(folio, 1, flags);
- if (unlikely(ret)) {
- page = ERR_PTR(ret);
- goto out;
- }
+ *pagep = page;
+ return 0;
+}
- /*
- * We need to make the page accessible if and only if we are going
- * to access its content (the FOLL_PIN case). Please see
- * Documentation/core-api/pin_user_pages.rst for details.
- */
- if (flags & FOLL_PIN) {
- ret = arch_make_folio_accessible(folio);
- if (ret) {
- unpin_user_page(page);
- page = ERR_PTR(ret);
- goto out;
+/*
+ * Return how many PTEs map consecutive pages of the same folio and can be
+ * committed as one run. Always at least 1.
+ *
+ * The write-fault and unshare checks in gup_lookup_pte() are per PTE, but a
+ * writable run needs no repeat: a writable anon page is exclusive. A read-only
+ * run under FOLL_WRITE or FOLL_PIN does need the per-page check, so it stays
+ * one page at a time.
+ */
+static unsigned long gup_pte_batch_len(struct vm_area_struct *vma,
+ unsigned long address, unsigned long walk_end,
+ struct folio *folio, pte_t *ptep, pte_t *batch_pte, unsigned int flags)
+{
+ unsigned long max;
+
+ if (!folio_test_large(folio))
+ return 1;
+ if (!pte_write(*batch_pte) && (flags & (FOLL_WRITE | FOLL_PIN)))
+ return 1;
+
+ max = (walk_end - address) >> PAGE_SHIFT;
+ if (max <= 1)
+ return 1;
+
+ /* Merge young/dirty across batch so folio_mark_dirty sees any dirty. */
+ return folio_pte_batch_flags(folio, vma, ptep, batch_pte, max,
+ FPB_RESPECT_WRITE | FPB_MERGE_YOUNG_DIRTY);
+}
+
+/*
+ * Walk the PTEs from the start address to the end of this page table or VMA,
+ * whichever comes first, and commit every page found.
+ *
+ * A failure on the first PTE is returned to the caller. A failure after that
+ * is a short read; __get_user_pages() retrying the read will get the error.
+ *
+ * Return: the number of pages stored in @pages, 0 when no mapping exists at
+ * the start address, or a negative errno for a failure on the first PTE.
+ */
+static long follow_page_pte(struct vm_area_struct *vma,
+ unsigned long address, unsigned long end, pmd_t *pmd,
+ unsigned int flags, struct page **pages)
+{
+ struct mm_struct *mm = vma->vm_mm;
+ bool need_no_page_table = false;
+ pte_t *ptep, *orig_ptep;
+ unsigned long walk_end, base;
+ unsigned long nr = 0;
+ spinlock_t *ptl;
+ long ret = 0;
+
+ orig_ptep = ptep = pte_offset_map_lock(mm, pmd, address, &ptl);
+ if (!ptep)
+ return no_page_table(vma, flags, address);
+
+ base = address;
+ walk_end = min(pmd_addr_end(address, end), vma->vm_end);
+
+ for (; address < walk_end; address += PAGE_SIZE, ptep++) {
+ pte_t pte = ptep_get(ptep);
+ struct folio *folio;
+ struct page *page;
+ unsigned long batch;
+ pte_t batch_pte;
+
+ ret = gup_lookup_pte(vma, address, ptep, pte, flags, &page);
+ if (ret || !page) {
+ /*
+ * no_page_table() may look up the page cache, so it
+ * cannot run under the PTE lock. A none PTE returns
+ * from gup_lookup_pte() before any write check runs,
+ * so this is the same call the old code made -- not a
+ * new failure mode for FOLL_WRITE.
+ */
+ if (!ret && pte_none(pte))
+ need_no_page_table = true;
+ break;
}
- }
- if (flags & FOLL_TOUCH) {
- if ((flags & FOLL_WRITE) &&
- !pte_dirty(pte) && !folio_test_dirty(folio))
- folio_mark_dirty(folio);
+ folio = page_folio(page);
+ batch_pte = pte;
+
+ batch = gup_pte_batch_len(vma, address, walk_end, folio,
+ ptep, &batch_pte, flags);
+ ret = gup_grab_folio_pages(folio, page, batch,
+ pte_dirty(batch_pte), flags,
+ pages ? pages + nr : NULL);
+ if (ret)
+ break;
+ nr += batch;
/*
- * pte_mkyoung() would be more correct here, but atomic care
- * is needed to avoid losing the dirty bit: it is easier to use
- * folio_mark_accessed().
+ * The loop's own increment covers one PTE; skip
+ * the rest of the batch.
*/
- folio_mark_accessed(folio);
+ ptep += batch - 1;
+ address += (batch - 1) * PAGE_SIZE;
}
-out:
- pte_unmap_unlock(ptep, ptl);
- return page;
-no_page:
- pte_unmap_unlock(ptep, ptl);
- if (!pte_none(pte))
- return NULL;
- return no_page_table(vma, flags, address);
+ pte_unmap_unlock(orig_ptep, ptl);
+
+ if (nr) {
+ gup_flush_pages(vma, base, pages, nr);
+ return nr;
+ }
+ if (need_no_page_table)
+ return no_page_table(vma, flags, address);
+ return ret;
}
-static struct page *follow_pmd_mask(struct vm_area_struct *vma,
- unsigned long address, pud_t *pudp,
- unsigned int flags,
- unsigned long *page_mask)
+static long follow_pmd_mask(struct vm_area_struct *vma,
+ unsigned long address, unsigned long end, pud_t *pudp,
+ unsigned int flags, struct page **pages)
{
pmd_t *pmd, pmdval;
spinlock_t *ptl;
- struct page *page;
+ long ret;
struct mm_struct *mm = vma->vm_mm;
pmd = pmd_offset(pudp, address);
@@ -912,7 +1060,7 @@ static struct page *follow_pmd_mask(struct vm_area_struct *vma,
if (!pmd_present(pmdval))
return no_page_table(vma, flags, address);
if (likely(!pmd_leaf(pmdval)))
- return follow_page_pte(vma, address, pmd, flags);
+ return follow_page_pte(vma, address, end, pmd, flags, pages);
if (pmd_protnone(pmdval) && !gup_can_follow_protnone(vma, flags))
return no_page_table(vma, flags, address);
@@ -925,28 +1073,35 @@ static struct page *follow_pmd_mask(struct vm_area_struct *vma,
}
if (unlikely(!pmd_leaf(pmdval))) {
spin_unlock(ptl);
- return follow_page_pte(vma, address, pmd, flags);
+ return follow_page_pte(vma, address, end, pmd, flags, pages);
}
if (pmd_trans_huge(pmdval) && (flags & FOLL_SPLIT_PMD)) {
spin_unlock(ptl);
split_huge_pmd(vma, pmd, address);
/* If pmd was left empty, stuff a page table in there quickly */
- return pte_alloc(mm, pmd) ? ERR_PTR(-ENOMEM) :
- follow_page_pte(vma, address, pmd, flags);
+ return pte_alloc(mm, pmd) ? -ENOMEM :
+ follow_page_pte(vma, address, end, pmd, flags, pages);
}
- page = follow_huge_pmd(vma, address, pmd, flags, page_mask);
+ ret = follow_huge_pmd(vma, address, end, pmd, flags, pages);
spin_unlock(ptl);
- return page;
+
+ /*
+ * The ref is already held, so the page cannot go away: fill the
+ * array and flush caches without the pmd lock.
+ */
+ if (ret > 0 && pages)
+ gup_fill_pages(vma, address, pages[0], ret, pages);
+
+ return ret;
}
-static struct page *follow_pud_mask(struct vm_area_struct *vma,
- unsigned long address, p4d_t *p4dp,
- unsigned int flags,
- unsigned long *page_mask)
+static long follow_pud_mask(struct vm_area_struct *vma,
+ unsigned long address, unsigned long end, p4d_t *p4dp,
+ unsigned int flags, struct page **pages)
{
pud_t *pudp, pud;
spinlock_t *ptl;
- struct page *page;
+ long ret;
struct mm_struct *mm = vma->vm_mm;
pudp = pud_offset(p4dp, address);
@@ -955,22 +1110,29 @@ static struct page *follow_pud_mask(struct vm_area_struct *vma,
return no_page_table(vma, flags, address);
if (pud_leaf(pud)) {
ptl = pud_lock(mm, pudp);
- page = follow_huge_pud(vma, address, pudp, flags, page_mask);
+ ret = follow_huge_pud(vma, address, end, pudp, flags, pages);
spin_unlock(ptl);
- if (page)
- return page;
+ /*
+ * The ref is already held, so the page cannot go away: fill
+ * the array and flush caches without the lock. A 1 GB folio
+ * can be up to HPAGE_PUD_NR pages, too long to flush under a
+ * spinlock.
+ */
+ if (ret > 0 && pages)
+ gup_fill_pages(vma, address, pages[0], ret, pages);
+ if (ret)
+ return ret;
return no_page_table(vma, flags, address);
}
if (unlikely(pud_bad(pud)))
return no_page_table(vma, flags, address);
- return follow_pmd_mask(vma, address, pudp, flags, page_mask);
+ return follow_pmd_mask(vma, address, end, pudp, flags, pages);
}
-static struct page *follow_p4d_mask(struct vm_area_struct *vma,
- unsigned long address, pgd_t *pgdp,
- unsigned int flags,
- unsigned long *page_mask)
+static long follow_p4d_mask(struct vm_area_struct *vma,
+ unsigned long address, unsigned long end, pgd_t *pgdp,
+ unsigned int flags, struct page **pages)
{
p4d_t *p4dp, p4d;
@@ -981,15 +1143,18 @@ static struct page *follow_p4d_mask(struct vm_area_struct *vma,
if (!p4d_present(p4d) || p4d_bad(p4d))
return no_page_table(vma, flags, address);
- return follow_pud_mask(vma, address, p4dp, flags, page_mask);
+ return follow_pud_mask(vma, address, end, p4dp, flags, pages);
}
/**
- * follow_page_mask - look up a page descriptor from a user-virtual address
+ * follow_page_mask - look up pages at a user-virtual address
* @vma: vm_area_struct mapping @address
* @address: virtual address to look up
+ * @end: virtual address at which to stop batching contiguous pages
* @flags: flags modifying lookup behaviour
- * @page_mask: a pointer to output page_mask
+ * @pages: array to receive the pages, refcounted per @flags, or NULL to
+ * walk the page tables (e.g. to fault pages in) without collecting
+ * or refcounting them
*
* @flags can have FOLL_ flags set, defined in <linux/mm.h>
*
@@ -998,33 +1163,32 @@ static struct page *follow_p4d_mask(struct vm_area_struct *vma,
* trigger a fault with FAULT_FLAG_UNSHARE set. Note that unsharing is only
* relevant with FOLL_PIN and !FOLL_WRITE.
*
- * On output, @page_mask is set according to the size of the page.
- *
- * Return: the mapped (struct page *), %NULL if no mapping exists, or
- * an error pointer if there is a mapping to something not represented
- * by a page descriptor (see also vm_normal_page()).
+ * Return: the number of contiguous pages starting at @address that were
+ * placed into @pages (if non-NULL), which may be fewer than the pages
+ * requested via @end; 0 if no mapping exists at @address; or a negative
+ * errno for a mapping to something not represented by a page descriptor
+ * (see also vm_normal_page()).
*/
-static struct page *follow_page_mask(struct vm_area_struct *vma,
- unsigned long address, unsigned int flags,
- unsigned long *page_mask)
+static long follow_page_mask(struct vm_area_struct *vma,
+ unsigned long address, unsigned long end,
+ unsigned int flags, struct page **pages)
{
pgd_t *pgd;
struct mm_struct *mm = vma->vm_mm;
- struct page *page;
+ long ret;
vma_pgtable_walk_begin(vma);
- *page_mask = 0;
pgd = pgd_offset(mm, address);
if (pgd_none(*pgd) || unlikely(pgd_bad(*pgd)))
- page = no_page_table(vma, flags, address);
+ ret = no_page_table(vma, flags, address);
else
- page = follow_p4d_mask(vma, address, pgd, flags, page_mask);
+ ret = follow_p4d_mask(vma, address, end, pgd, flags, pages);
vma_pgtable_walk_end(vma);
- return page;
+ return ret;
}
static int get_gate_page(struct mm_struct *mm, unsigned long address,
@@ -1358,7 +1522,6 @@ static long __get_user_pages(struct mm_struct *mm,
{
long ret = 0, i = 0;
struct vm_area_struct *vma = NULL;
- unsigned long page_mask = 0;
if (!nr_pages)
return 0;
@@ -1373,7 +1536,7 @@ static long __get_user_pages(struct mm_struct *mm,
do {
struct page *page;
- unsigned int page_increm;
+ long nr;
/* first iteration or cross vma bound */
if (!vma || start >= vma->vm_end) {
@@ -1400,8 +1563,12 @@ static long __get_user_pages(struct mm_struct *mm,
pages ? &page : NULL);
if (ret)
goto out;
- page_mask = 0;
- goto next_page;
+ gup_fill_pages(vma, start, page, 1,
+ pages ? pages + i : NULL);
+ i++;
+ start += PAGE_SIZE;
+ nr_pages--;
+ continue;
}
if (!vma) {
@@ -1423,10 +1590,11 @@ static long __get_user_pages(struct mm_struct *mm,
}
cond_resched();
- page = follow_page_mask(vma, start, gup_flags, &page_mask);
- if (!page || PTR_ERR(page) == -EMLINK) {
+ nr = follow_page_mask(vma, start, start + nr_pages * PAGE_SIZE,
+ gup_flags, pages ? &pages[i] : NULL);
+ if (!nr || nr == -EMLINK) {
ret = faultin_page(vma, start, gup_flags,
- PTR_ERR(page) == -EMLINK, locked);
+ nr == -EMLINK, locked);
switch (ret) {
case 0:
goto retry;
@@ -1440,70 +1608,30 @@ static long __get_user_pages(struct mm_struct *mm,
goto out;
}
BUG();
- } else if (PTR_ERR(page) == -EEXIST) {
+ } else if (nr == -EEXIST) {
/*
* Proper page table entry exists, but no corresponding
* struct page. If the caller expects **pages to be
* filled in, bail out now, because that can't be done
- * for this page.
+ * for this page. Otherwise advance by the one page
+ * follow_page_mask() looked at.
*/
if (pages) {
- ret = PTR_ERR(page);
+ ret = nr;
goto out;
}
- } else if (IS_ERR(page)) {
- ret = PTR_ERR(page);
+ nr = 1;
+ } else if (nr < 0) {
+ ret = nr;
goto out;
}
-next_page:
- page_increm = 1 + (~(start >> PAGE_SHIFT) & page_mask);
- if (page_increm > nr_pages)
- page_increm = nr_pages;
-
- if (pages) {
- struct page *subpage;
- unsigned int j;
-
- /*
- * This must be a large folio (and doesn't need to
- * be the whole folio; it can be part of it), do
- * the refcount work for all the subpages too.
- *
- * NOTE: here the page may not be the head page
- * e.g. when start addr is not thp-size aligned.
- * try_grab_folio() should have taken care of tail
- * pages.
- */
- if (page_increm > 1) {
- struct folio *folio = page_folio(page);
-
- /*
- * Since we already hold refcount on the
- * large folio, this should never fail.
- */
- if (try_grab_folio(folio, page_increm - 1,
- gup_flags)) {
- /*
- * Release the 1st page ref if the
- * folio is problematic, fail hard.
- */
- gup_put_folio(folio, 1, gup_flags);
- ret = -EFAULT;
- goto out;
- }
- }
- for (j = 0; j < page_increm; j++) {
- subpage = page + j;
- pages[i + j] = subpage;
- flush_anon_page(vma, subpage, start + j * PAGE_SIZE);
- flush_dcache_page(subpage);
- }
- }
+ /* Check that we didn't pin more pages than the caller will free. */
+ VM_WARN_ON_ONCE(nr > nr_pages);
- i += page_increm;
- start += page_increm * PAGE_SIZE;
- nr_pages -= page_increm;
+ i += nr;
+ start += nr * PAGE_SIZE;
+ nr_pages -= nr;
} while (nr_pages);
out:
return i ? i : ret;
|
| 3/2 | 2026/11/03 12:45 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 12395 output: 32 thoughts: 272 Thoughts: **My Assessment of the GUP Patch's Fuzzing Potential** Okay, so I've got this request to evaluate a kernel patch series targeting `mm/gup.c` for fuzzability with syzkaller. Standard stuff, a security/QA task really. My first instinct is to de-frame this, do a quick risk analysis. No red flags; it's a code review, not some critical vulnerability announcement. The context is clear: a change to `mm/gup.c`. Now, my core triage philosophy kicks in. Reachability is the primary concern, and `mm/gup.c` is *definitely* reachable. GUP (get_user_pages) is fundamental memory management, so this is high value for fuzzing. I can safely call that the fuzzing criteria: `mm/` modifications are always worth a closer look! That’s a firm **WorthFuzzing=true** in my book. Even if the patch claims “no functional change,” I'm not going to blindly trust that. Refactoring, optimization, especially in GUP with batching changes, can hide subtle bugs that fuzzing can uncover. Now, let's get into the nitty-gritty. I need to zero in on specific entry points, so I'll extract some focus symbols. I won't waste time on ubiquitous, lifecycle hot-paths like general allocators, page faults, or lock primitives. I’m looking for feature logic, entrypoints, and caller functions specific to *this* patch. Finally, I'll need to identify any relevant enable configurations. I'll start by inspecting the diff and codebase with the tools I have available, likely running some `git grep` commands or checking the modified commit / functions in `mm/gup.c`. From there, I'll be able to decide if this patch is worthy of the syzkaller treatment. |
| 4/2 | 2026/11/03 12:45 | tool | grepper |
0mArgs:{
"Expression": "follow_page_mask",
"PathPrefixes": [
"mm/gup.c"
]
}Results: {
"Output": "mm/gup.c=1133=static long follow_p4d_mask(struct vm_area_struct *vma,\n--\nmm/gup.c-1149-/**\nmm/gup.c:1150: * follow_page_mask - look up pages at a user-virtual address\nmm/gup.c-1151- * @vma: vm_area_struct mapping @address\n--\nmm/gup.c-1171- */\nmm/gup.c:1172:static long follow_page_mask(struct vm_area_struct *vma,\nmm/gup.c-1173-\t\tunsigned long address, unsigned long end,\n--\nmm/gup.c=1518=static long __get_user_pages(struct mm_struct *mm,\n--\nmm/gup.c-1592-\nmm/gup.c:1593:\t\tnr = follow_page_mask(vma, start, start + nr_pages * PAGE_SIZE,\nmm/gup.c-1594-\t\t\t\t gup_flags, pages ? \u0026pages[i] : NULL);\n--\nmm/gup.c-1616-\t\t\t * for this page. Otherwise advance by the one page\nmm/gup.c:1617:\t\t\t * follow_page_mask() looked at.\nmm/gup.c-1618-\t\t\t */\n"
} |
| 5/2 | 2026/11/03 12:45 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 13468 output: 29 thoughts: 268 Thoughts: **Analyzing Recent Changes in mm/gup.c** Alright, let's dive into these recent modifications in `mm/gup.c`. I need to understand the implications of these changes. My initial focus is on the functions that have been added or altered. I see: * `no_page_table` – Hmm, signature changed to `long`, that's interesting. I wonder what the performance implications are. * A series of static helper functions: `gup_fill_pages`, `gup_flush_pages`, `gup_grab_folio_pages`, `gup_lookup_pte`, and `gup_pte_batch_len`. These clearly suggest an internal refactoring or optimization of the Get User Pages (GUP) mechanism. * `follow_huge_pud`, `follow_huge_pmd`, `follow_page_pte` are also added. These are hinting towards improved handling of huge pages, likely improving performance. * We've got the usual suspects for address space traversal: `follow_pmd_mask`, `follow_pud_mask`, `follow_p4d_mask`, and `follow_page_mask`. * And finally, the key function, `__get_user_pages`. This is the core. Now, I'll need to trace the usage of `__get_user_pages`, and potentially any non-static functions that call it or `follow_page_mask` in this modified version. I'll need to understand the calling contexts to gauge the impact of these changes. Let's see what calls it. Time to run a quick grep. |
| 6/2 | 2026/11/03 12:46 | tool | grepper |
0mArgs:{
"Expression": "__get_user_pages",
"PathPrefixes": [
"mm/"
]
}Results: {
"Output": "mm/gup.c=949=static unsigned long gup_pte_batch_len(struct vm_area_struct *vma,\n--\nmm/gup.c-973- * A failure on the first PTE is returned to the caller. A failure after that\nmm/gup.c:974: * is a short read; __get_user_pages() retrying the read will get the error.\nmm/gup.c-975- *\n--\nmm/gup.c=1429=static struct vm_area_struct *gup_vma_lookup(struct mm_struct *mm,\n--\nmm/gup.c-1464-/**\nmm/gup.c:1465: * __get_user_pages() - pin user pages in memory\nmm/gup.c-1466- * @mm:\t\tmm_struct of target mm\n--\nmm/gup.c-1487- *\nmm/gup.c:1488: * __get_user_pages walks a process's page tables and takes a reference to\nmm/gup.c-1489- * each struct page that each user address corresponds to at a given\n--\nmm/gup.c-1493- * This does not guarantee that the page exists in the user mappings when\nmm/gup.c:1494: * __get_user_pages returns, and there may even be a completely different\nmm/gup.c-1495- * page there in some cases (eg. if mmapped pagecache has been invalidated\n--\nmm/gup.c-1514- * In most cases, get_user_pages or get_user_pages_fast should be used\nmm/gup.c:1515: * instead of __get_user_pages. __get_user_pages should be used only if\nmm/gup.c-1516- * you need some special @gup_flags.\nmm/gup.c-1517- */\nmm/gup.c:1518:static long __get_user_pages(struct mm_struct *mm,\nmm/gup.c-1519-\t\tunsigned long start, unsigned long nr_pages,\n--\nmm/gup.c=1753=static bool gup_signal_pending(unsigned int flags)\n--\nmm/gup.c-1773- *\nmm/gup.c:1774: * Please note that this function, unlike __get_user_pages(), will not return 0\nmm/gup.c-1775- * for nr_pages \u003e 0, unless FOLL_NOWAIT is used.\nmm/gup.c-1776- */\nmm/gup.c:1777:static __always_inline long __get_user_pages_locked(struct mm_struct *mm,\nmm/gup.c-1778-\t\t\t\t\t\tunsigned long start,\n--\nmm/gup.c-1819-\tfor (;;) {\nmm/gup.c:1820:\t\tret = __get_user_pages(mm, start, nr_pages, flags, pages,\nmm/gup.c-1821-\t\t\t\t locked);\n--\nmm/gup.c-1879-\t\t*locked = 1;\nmm/gup.c:1880:\t\tret = __get_user_pages(mm, start, 1, flags | FOLL_TRIED,\nmm/gup.c-1881-\t\t\t\t pages, locked);\n--\nmm/gup.c=1941=long populate_vma_page_range(struct vm_area_struct *vma,\n--\nmm/gup.c-1991-\t */\nmm/gup.c:1992:\tret = __get_user_pages(mm, start, nr_pages, gup_flags,\nmm/gup.c-1993-\t\t\t NULL, locked ? locked : \u0026local_locked);\n--\nmm/gup.c-2010- * Returns either number of processed pages in the MM, or a negative error\nmm/gup.c:2011: * code on error (see __get_user_pages()). Note that this function reports\nmm/gup.c-2012- * errors related to VMAs, such as incompatible mappings, as expected by\n--\nmm/gup.c=2019=long faultin_page_range(struct mm_struct *mm, unsigned long start,\n--\nmm/gup.c-2043-\nmm/gup.c:2044:\tret = __get_user_pages_locked(mm, start, nr_pages, NULL, locked,\nmm/gup.c-2045-\t\t\t\t gup_flags);\n--\nmm/gup.c=2057=int __mm_populate(unsigned long start, unsigned long len, int ignore_errors)\n--\nmm/gup.c-2110-#else /* CONFIG_MMU */\nmm/gup.c:2111:static long __get_user_pages_locked(struct mm_struct *mm, unsigned long start,\nmm/gup.c-2112-\t\tunsigned long nr_pages, struct page **pages,\n--\nmm/gup.c=2330=struct page *get_dump_page(unsigned long addr, int *locked)\n--\nmm/gup.c-2334-\nmm/gup.c:2335:\tret = __get_user_pages_locked(current-\u003emm, addr, 1, \u0026page, locked,\nmm/gup.c-2336-\t\t\t\t FOLL_FORCE | FOLL_DUMP | FOLL_GET);\n--\nmm/gup.c=2459=migrate_longterm_unpinnable_folios(struct list_head *movable_folio_list,\n--\nmm/gup.c-2487-\t\t * We can't migrate folios with unexpected references, so drop\nmm/gup.c:2488:\t\t * the reference obtained by __get_user_pages_locked().\nmm/gup.c-2489-\t\t * Migrating folios have been added to movable_folio_list after\n--\nmm/gup.c=2592=static long check_and_migrate_movable_folios(unsigned long nr_folios,\n--\nmm/gup.c-2599-/*\nmm/gup.c:2600: * __gup_longterm_locked() is a wrapper for __get_user_pages_locked which\nmm/gup.c-2601- * allows us to process the FOLL_LONGTERM flag.\n--\nmm/gup.c=2603=static long __gup_longterm_locked(struct mm_struct *mm,\n--\nmm/gup.c-2613-\tif (!(gup_flags \u0026 FOLL_LONGTERM))\nmm/gup.c:2614:\t\treturn __get_user_pages_locked(mm, start, nr_pages, pages,\nmm/gup.c-2615-\t\t\t\t\t locked, gup_flags);\n--\nmm/gup.c-2618-\tdo {\nmm/gup.c:2619:\t\tnr_pinned_pages = __get_user_pages_locked(mm, start, nr_pages,\nmm/gup.c-2620-\t\t\t\t\t\t\t pages, locked,\n--\nmm/gup.c=2741=long get_user_pages_remote(struct mm_struct *mm,\n--\nmm/gup.c-2751-\nmm/gup.c:2752:\treturn __get_user_pages_locked(mm, start, nr_pages, pages,\nmm/gup.c-2753-\t\t\t\t locked ? locked : \u0026local_locked,\n--\nmm/gup.c=2782=long get_user_pages(unsigned long start, unsigned long nr_pages,\n--\nmm/gup.c-2789-\nmm/gup.c:2790:\treturn __get_user_pages_locked(current-\u003emm, start, nr_pages, pages,\nmm/gup.c-2791-\t\t\t\t \u0026locked, gup_flags);\n--\nmm/gup.c=2810=long get_user_pages_unlocked(unsigned long start, unsigned long nr_pages,\n--\nmm/gup.c-2818-\nmm/gup.c:2819:\treturn __get_user_pages_locked(current-\u003emm, start, nr_pages, pages,\nmm/gup.c-2820-\t\t\t\t \u0026locked, gup_flags);\n--\nmm/memory.c=7297=static int __access_remote_vm(struct mm_struct *mm, unsigned long addr,\n--\nmm/memory.c-7308-\nmm/memory.c:7309:\t/* Avoid triggering the temporary warning in __get_user_pages */\nmm/memory.c-7310-\tif (!vma_lookup(mm, addr) \u0026\u0026 !expand_stack(mm, addr))\n--\nmm/memory.c=7420=int __copy_remote_mm_str(struct mm_struct *mm, unsigned long addr,\n--\nmm/memory.c-7432-\nmm/memory.c:7433:\t/* Avoid triggering the temporary warning in __get_user_pages */\nmm/memory.c-7434-\tif (!vma_lookup(mm, addr)) {\n"
} |
| 7/2 | 2026/11/03 12:46 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 16503 output: 47 thoughts: 92 Thoughts: Okay, let's dive into this. Here's my thought process on the matter: **Analyzing `mm/gup.c` Call Sites** Right, I need to understand the landscape of how `__get_user_pages`, `pin_user_pages`, and `get_user_pages` are being used within `mm/gup.c`. My immediate thought is to track down all the call sites to those functions. I'll need to meticulously examine `mm/gup.c`, concentrating on where those specific functions are invoked. That's the key to understanding how they're being utilized in this context. I'll pay particularly close attention to the code in the region roughly between lines 2700 and 3000, assuming that's a reasonable section to start with. The goal is to see exactly what functions are *calling* these GUP-related routines. From there, I can start forming a mental map of their purpose. |
| 8/2 | 2026/11/03 12:48 | tool | grepper |
0mArgs:{
"Expression": "__get_user_pages_locked|pin_user_pages|get_user_pages",
"PathPrefixes": [
"mm/gup.c"
]
}Results: {
"Output": "\nFull output is too long, showing 200 out of 392 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (1 files in total):\nmm/gup.c:99\n\nmm/gup.c=140=int __must_check try_grab_folio(struct folio *folio, int refs,\n--\nmm/gup.c-179- *\nmm/gup.c:180: * Pages that were pinned via pin_user_pages*() must be released via either\nmm/gup.c:181: * unpin_user_page(), or one of the unpin_user_pages*() routines. This is so\nmm/gup.c-182- * that such pages can be separately tracked and uniquely handled. In\n--\nmm/gup.c=247=static inline struct folio *gup_folio_next(struct page **list,\n--\nmm/gup.c-262-/**\nmm/gup.c:263: * unpin_user_pages_dirty_lock() - release and optionally dirty gup-pinned pages\nmm/gup.c-264- * @pages: array of pages to be maybe marked dirty, and definitely released.\n--\nmm/gup.c-267- *\nmm/gup.c:268: * \"gup-pinned page\" refers to a page that has had one of the get_user_pages()\nmm/gup.c-269- * variants called on that page.\n--\nmm/gup.c-273- * listed as clean. In any case, releases all pages using unpin_user_page(),\nmm/gup.c:274: * possibly via unpin_user_pages(), for the non-dirty case.\nmm/gup.c-275- *\n--\nmm/gup.c-283- */\nmm/gup.c:284:void unpin_user_pages_dirty_lock(struct page **pages, unsigned long npages,\nmm/gup.c-285-\t\t\t\t bool make_dirty)\n--\nmm/gup.c-291-\tif (!make_dirty) {\nmm/gup.c:292:\t\tunpin_user_pages(pages, npages);\nmm/gup.c-293-\t\treturn;\n--\nmm/gup.c-326-}\nmm/gup.c:327:EXPORT_SYMBOL(unpin_user_pages_dirty_lock);\nmm/gup.c-328-\n--\nmm/gup.c-337- * \"gup-pinned page range\" refers to a range of pages that has had one of the\nmm/gup.c:338: * pin_user_pages() variants called on that page.\nmm/gup.c-339- *\n--\nmm/gup.c=373=EXPORT_SYMBOL(unpin_user_page_range_dirty_lock);\nmm/gup.c-374-\nmm/gup.c:375:static void gup_fast_unpin_user_pages(struct page **pages, unsigned long npages)\nmm/gup.c-376-{\n--\nmm/gup.c-392-/**\nmm/gup.c:393: * unpin_user_pages() - release an array of gup-pinned pages.\nmm/gup.c-394- * @pages: array of pages to be marked dirty and released.\n--\nmm/gup.c-400- */\nmm/gup.c:401:void unpin_user_pages(struct page **pages, unsigned long npages)\nmm/gup.c-402-{\n--\nmm/gup.c-424-}\nmm/gup.c:425:EXPORT_SYMBOL(unpin_user_pages);\nmm/gup.c-426-\n--\nmm/gup.c=479=static inline void mm_set_has_pinned_flag(struct mm_struct *mm)\n--\nmm/gup.c-497- * Either FOLL_PIN or FOLL_GET (or neither) must be set, but not both at the\nmm/gup.c:498: * same time. (That's true throughout the get_user_pages*() and\nmm/gup.c:499: * pin_user_pages*() APIs.) Cases:\nmm/gup.c-500- *\n--\nmm/gup.c=852=static long gup_grab_folio_pages(struct folio *folio,\n--\nmm/gup.c-866-\t * to access its content (the FOLL_PIN case). Please see\nmm/gup.c:867:\t * Documentation/core-api/pin_user_pages.rst for details.\nmm/gup.c-868-\t */\n--\nmm/gup.c=949=static unsigned long gup_pte_batch_len(struct vm_area_struct *vma,\n--\nmm/gup.c-973- * A failure on the first PTE is returned to the caller. A failure after that\nmm/gup.c:974: * is a short read; __get_user_pages() retrying the read will get the error.\nmm/gup.c-975- *\n--\nmm/gup.c=1429=static struct vm_area_struct *gup_vma_lookup(struct mm_struct *mm,\n--\nmm/gup.c-1464-/**\nmm/gup.c:1465: * __get_user_pages() - pin user pages in memory\nmm/gup.c-1466- * @mm:\t\tmm_struct of target mm\n--\nmm/gup.c-1487- *\nmm/gup.c:1488: * __get_user_pages walks a process's page tables and takes a reference to\nmm/gup.c-1489- * each struct page that each user address corresponds to at a given\n--\nmm/gup.c-1493- * This does not guarantee that the page exists in the user mappings when\nmm/gup.c:1494: * __get_user_pages returns, and there may even be a completely different\nmm/gup.c-1495- * page there in some cases (eg. if mmapped pagecache has been invalidated\n--\nmm/gup.c-1513- *\nmm/gup.c:1514: * In most cases, get_user_pages or get_user_pages_fast should be used\nmm/gup.c:1515: * instead of __get_user_pages. __get_user_pages should be used only if\nmm/gup.c-1516- * you need some special @gup_flags.\nmm/gup.c-1517- */\nmm/gup.c:1518:static long __get_user_pages(struct mm_struct *mm,\nmm/gup.c-1519-\t\tunsigned long start, unsigned long nr_pages,\n--\nmm/gup.c=1640=static bool vma_permits_fault(struct vm_area_struct *vma,\n--\nmm/gup.c-1678- *\nmm/gup.c:1679: * The main difference with get_user_pages() is that this function will\nmm/gup.c-1680- * unconditionally call handle_mm_fault() which will in turn perform all the\nmm/gup.c-1681- * necessary SW fixup of the dirty and young bits in the PTE, while\nmm/gup.c:1682: * get_user_pages() only guarantees to update these in the struct page.\nmm/gup.c-1683- *\n--\nmm/gup.c=1753=static bool gup_signal_pending(unsigned int flags)\n--\nmm/gup.c-1773- *\nmm/gup.c:1774: * Please note that this function, unlike __get_user_pages(), will not return 0\nmm/gup.c-1775- * for nr_pages \u003e 0, unless FOLL_NOWAIT is used.\nmm/gup.c-1776- */\nmm/gup.c:1777:static __always_inline long __get_user_pages_locked(struct mm_struct *mm,\nmm/gup.c-1778-\t\t\t\t\t\tunsigned long start,\n--\nmm/gup.c-1819-\tfor (;;) {\nmm/gup.c:1820:\t\tret = __get_user_pages(mm, start, nr_pages, flags, pages,\nmm/gup.c-1821-\t\t\t\t locked);\n--\nmm/gup.c-1879-\t\t*locked = 1;\nmm/gup.c:1880:\t\tret = __get_user_pages(mm, start, 1, flags | FOLL_TRIED,\nmm/gup.c-1881-\t\t\t\t pages, locked);\n--\nmm/gup.c=1941=long populate_vma_page_range(struct vm_area_struct *vma,\n--\nmm/gup.c-1991-\t */\nmm/gup.c:1992:\tret = __get_user_pages(mm, start, nr_pages, gup_flags,\nmm/gup.c-1993-\t\t\t NULL, locked ? locked : \u0026local_locked);\n--\nmm/gup.c-2010- * Returns either number of processed pages in the MM, or a negative error\nmm/gup.c:2011: * code on error (see __get_user_pages()). Note that this function reports\nmm/gup.c-2012- * errors related to VMAs, such as incompatible mappings, as expected by\n--\nmm/gup.c=2019=long faultin_page_range(struct mm_struct *mm, unsigned long start,\n--\nmm/gup.c-2043-\nmm/gup.c:2044:\tret = __get_user_pages_locked(mm, start, nr_pages, NULL, locked,\nmm/gup.c-2045-\t\t\t\t gup_flags);\n--\nmm/gup.c=2057=int __mm_populate(unsigned long start, unsigned long len, int ignore_errors)\n--\nmm/gup.c-2110-#else /* CONFIG_MMU */\nmm/gup.c:2111:static long __get_user_pages_locked(struct mm_struct *mm, unsigned long start,\nmm/gup.c-2112-\t\tunsigned long nr_pages, struct page **pages,\n--\nmm/gup.c=2330=struct page *get_dump_page(unsigned long addr, int *locked)\n--\nmm/gup.c-2334-\nmm/gup.c:2335:\tret = __get_user_pages_locked(current-\u003emm, addr, 1, \u0026page, locked,\nmm/gup.c-2336-\t\t\t\t FOLL_FORCE | FOLL_DUMP | FOLL_GET);\n--\nmm/gup.c=2372=static void pofs_unpin(struct pages_or_folios *pofs)\n--\nmm/gup.c-2376-\telse\nmm/gup.c:2377:\t\tunpin_user_pages(pofs-\u003epages, pofs-\u003enr_entries);\nmm/gup.c-2378-}\n--\nmm/gup.c=2459=migrate_longterm_unpinnable_folios(struct list_head *movable_folio_list,\n--\nmm/gup.c-2487-\t\t * We can't migrate folios with unexpected references, so drop\nmm/gup.c:2488:\t\t * the reference obtained by __get_user_pages_locked().\nmm/gup.c-2489-\t\t * Migrating folios have been added to movable_folio_list after\n--\nmm/gup.c=2592=static long check_and_migrate_movable_folios(unsigned long nr_folios,\n--\nmm/gup.c-2599-/*\nmm/gup.c:2600: * __gup_longterm_locked() is a wrapper for __get_user_pages_locked which\nmm/gup.c-2601- * allows us to process the FOLL_LONGTERM flag.\n--\nmm/gup.c=2603=static long __gup_longterm_locked(struct mm_struct *mm,\n--\nmm/gup.c-2613-\tif (!(gup_flags \u0026 FOLL_LONGTERM))\nmm/gup.c:2614:\t\treturn __get_user_pages_locked(mm, start, nr_pages, pages,\nmm/gup.c-2615-\t\t\t\t\t locked, gup_flags);\n--\nmm/gup.c-2618-\tdo {\nmm/gup.c:2619:\t\tnr_pinned_pages = __get_user_pages_locked(mm, start, nr_pages,\nmm/gup.c-2620-\t\t\t\t\t\t\t pages, locked,\n--\nmm/gup.c=2638=static bool is_valid_gup_args(struct page **pages, int *locked,\n--\nmm/gup.c-2685-/**\nmm/gup.c:2686: * get_user_pages_remote() - pin user pages in memory\nmm/gup.c-2687- * @mm:\t\tmm_struct of target mm\n--\nmm/gup.c-2709- *\nmm/gup.c:2710: * get_user_pages_remote walks a process's page tables and takes a reference\nmm/gup.c-2711- * to each struct page that each user address corresponds to at a given\n--\nmm/gup.c-2715- * This does not guarantee that the page exists in the user mappings when\nmm/gup.c:2716: * get_user_pages_remote returns, and there may even be a completely different\nmm/gup.c-2717- * page there in some cases (eg. if mmapped pagecache has been invalidated\n--\nmm/gup.c-2727- *\nmm/gup.c:2728: * get_user_pages_remote is typically used for fewer-copy IO operations,\nmm/gup.c-2729- * to get a handle on the memory by some means other than accesses\n--\nmm/gup.c-2733- *\nmm/gup.c:2734: * See also get_user_pages_fast, for performance critical applications.\nmm/gup.c-2735- *\nmm/gup.c:2736: * get_user_pages_remote should be phased out in favor of\nmm/gup.c:2737: * get_user_pages_locked|unlocked or get_user_pages_fast. Nothing\n\n"
} |
| 9/2 | 2026/11/03 12:48 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 20679 output: 36 thoughts: 24 Thoughts: Here's my thought process, as requested: **Examining Code Snippets in mm/gup.c** Okay, so I need to dive into `mm/gup.c` again. Specifically, I'm interested in what's happening *after* line 2737. Given the context, I'm probably looking for something related to the granular memory operations or maybe a specific optimization. Using `read-file` seems like the most direct approach. I'll load the file, quickly navigate to the right spot, and then I'll start analyzing the code from there. I expect that lines right after 2737 should be a good indicator of whatever process I'm currently investigating. |
| 10/2 | 2026/11/03 12:49 | tool | read-file |
0mArgs:{
"File": "mm/gup.c",
"FirstLine": 2740,
"LineCount": 100
}Results: {
"Contents": "2740:\t */\n2741:\tlong get_user_pages_remote(struct mm_struct *mm,\n2742:\t\t\tunsigned long start, unsigned long nr_pages,\n2743:\t\t\tunsigned int gup_flags, struct page **pages,\n2744:\t\t\tint *locked)\n2745:\t{\n2746:\t\tint local_locked = 1;\n2747:\t\n2748:\t\tif (!is_valid_gup_args(pages, locked, \u0026gup_flags,\n2749:\t\t\t\t FOLL_TOUCH | FOLL_REMOTE))\n2750:\t\t\treturn -EINVAL;\n2751:\t\n2752:\t\treturn __get_user_pages_locked(mm, start, nr_pages, pages,\n2753:\t\t\t\t\t locked ? locked : \u0026local_locked,\n2754:\t\t\t\t\t gup_flags);\n2755:\t}\n2756:\tEXPORT_SYMBOL(get_user_pages_remote);\n2757:\t\n2758:\t#else /* CONFIG_MMU */\n2759:\tlong get_user_pages_remote(struct mm_struct *mm,\n2760:\t\t\t\t unsigned long start, unsigned long nr_pages,\n2761:\t\t\t\t unsigned int gup_flags, struct page **pages,\n2762:\t\t\t\t int *locked)\n2763:\t{\n2764:\t\treturn 0;\n2765:\t}\n2766:\t#endif /* !CONFIG_MMU */\n2767:\t\n2768:\t/**\n2769:\t * get_user_pages() - pin user pages in memory\n2770:\t * @start: starting user address\n2771:\t * @nr_pages: number of pages from start to pin\n2772:\t * @gup_flags: flags modifying lookup behaviour\n2773:\t * @pages: array that receives pointers to the pages pinned.\n2774:\t * Should be at least nr_pages long. Or NULL, if caller\n2775:\t * only intends to ensure the pages are faulted in.\n2776:\t *\n2777:\t * This is the same as get_user_pages_remote(), just with a less-flexible\n2778:\t * calling convention where we assume that the mm being operated on belongs to\n2779:\t * the current task, and doesn't allow passing of a locked parameter. We also\n2780:\t * obviously don't pass FOLL_REMOTE in here.\n2781:\t */\n2782:\tlong get_user_pages(unsigned long start, unsigned long nr_pages,\n2783:\t\t\t unsigned int gup_flags, struct page **pages)\n2784:\t{\n2785:\t\tint locked = 1;\n2786:\t\n2787:\t\tif (!is_valid_gup_args(pages, NULL, \u0026gup_flags, FOLL_TOUCH))\n2788:\t\t\treturn -EINVAL;\n2789:\t\n2790:\t\treturn __get_user_pages_locked(current-\u003emm, start, nr_pages, pages,\n2791:\t\t\t\t\t \u0026locked, gup_flags);\n2792:\t}\n2793:\tEXPORT_SYMBOL(get_user_pages);\n2794:\t\n2795:\t/*\n2796:\t * get_user_pages_unlocked() is suitable to replace the form:\n2797:\t *\n2798:\t * mmap_read_lock(mm);\n2799:\t * get_user_pages(mm, ..., pages, NULL);\n2800:\t * mmap_read_unlock(mm);\n2801:\t *\n2802:\t * with:\n2803:\t *\n2804:\t * get_user_pages_unlocked(mm, ..., pages);\n2805:\t *\n2806:\t * It is functionally equivalent to get_user_pages_fast so\n2807:\t * get_user_pages_fast should be used instead if specific gup_flags\n2808:\t * (e.g. FOLL_FORCE) are not required.\n2809:\t */\n2810:\tlong get_user_pages_unlocked(unsigned long start, unsigned long nr_pages,\n2811:\t\t\t\t struct page **pages, unsigned int gup_flags)\n2812:\t{\n2813:\t\tint locked = 0;\n2814:\t\n2815:\t\tif (!is_valid_gup_args(pages, NULL, \u0026gup_flags,\n2816:\t\t\t\t FOLL_TOUCH | FOLL_UNLOCKABLE))\n2817:\t\t\treturn -EINVAL;\n2818:\t\n2819:\t\treturn __get_user_pages_locked(current-\u003emm, start, nr_pages, pages,\n2820:\t\t\t\t\t \u0026locked, gup_flags);\n2821:\t}\n2822:\tEXPORT_SYMBOL(get_user_pages_unlocked);\n2823:\t\n2824:\t/*\n2825:\t * GUP-fast\n2826:\t *\n2827:\t * get_user_pages_fast attempts to pin user pages by walking the page\n2828:\t * tables directly and avoids taking locks. Thus the walker needs to be\n2829:\t * protected from page table pages being freed from under it, and should\n2830:\t * block any THP splits.\n2831:\t *\n2832:\t * One way to achieve this is to have the walker disable interrupts, and\n2833:\t * rely on IPIs from the TLB flushing code blocking before the page table\n2834:\t * pages are freed. This is unsuitable for architectures that do not need\n2835:\t * to broadcast an IPI when invalidating TLBs.\n2836:\t *\n2837:\t * Another way to achieve this is to batch up page table containing pages\n2838:\t * belonging to more than one mm_user, then rcu_sched a callback to free those\n2839:\t * pages. Disabling interrupts will allow the gup_fast() walker to both block\n"
} |
| 11/2 | 2026/11/03 12:49 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 22502 output: 34 thoughts: 41 Thoughts: Here's my thought process, as if I were considering this issue: **Delving Deeper into `mm/gup.c`** Okay, so we're looking at memory management and `pin_user_pages`. My next logical step is to dive into the source code, specifically `mm/gup.c`. I need to understand how `pin_user_pages` is *defined* within that file. Therefore, I need to use `grep` to quickly locate all instances where `pin_user_pages` is defined. This will help me trace its implementation, understand its parameters, and see how it interacts with other kernel functions. That `grep` search will be essential to get a better handle on the potential issues. |
| 12/2 | 2026/11/03 12:50 | tool | grepper |
0mArgs:{
"Expression": "^long pin_user_pages",
"PathPrefixes": [
"mm/gup.c"
]
}Results: {
"Output": "mm/gup.c=3470=EXPORT_SYMBOL_GPL(pin_user_pages_fast);\n--\nmm/gup.c-3494- */\nmm/gup.c:3495:long pin_user_pages_remote(struct mm_struct *mm,\nmm/gup.c-3496-\t\t\t unsigned long start, unsigned long nr_pages,\n--\nmm/gup.c=3509=EXPORT_SYMBOL(pin_user_pages_remote);\n--\nmm/gup.c-3528- */\nmm/gup.c:3529:long pin_user_pages(unsigned long start, unsigned long nr_pages,\nmm/gup.c-3530-\t\t unsigned int gup_flags, struct page **pages)\n--\nmm/gup.c=3539=EXPORT_SYMBOL(pin_user_pages);\n--\nmm/gup.c-3548- */\nmm/gup.c:3549:long pin_user_pages_unlocked(unsigned long start, unsigned long nr_pages,\nmm/gup.c-3550-\t\t\t struct page **pages, unsigned int gup_flags)\n"
} |
| 13/2 | 2026/11/03 12:50 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 23045 output: 35 thoughts: 55 Thoughts: Here's my take on those thoughts: **Dissecting `pin_user_pages` Functionality** Okay, so I need to understand the execution path of `pin_user_pages`. Specifically, I'm curious about the underlying mechanisms it utilizes for handling user-space page pinning. My immediate question is: does it delegate to `__gup_longterm_locked` or `__get_user_pages_locked`? I know these are key functions in the memory management subsystem, so figuring out which one (or if it uses something else) is essential to understanding the locking strategy and overall performance implications. Time to fire up `read-file` and zero in on the source code, targeting around line 3529 to see how the sausage gets made. Let's see what the function actually *does* under the hood. |
| 14/2 | 2026/11/03 12:51 | tool | read-file |
0mArgs:{
"File": "mm/gup.c",
"FirstLine": 3520,
"LineCount": 40
}Results: {
"Contents": "3520:\t * Nearly the same as get_user_pages(), except that FOLL_TOUCH is not set, and\n3521:\t * FOLL_PIN is set.\n3522:\t *\n3523:\t * FOLL_PIN means that the pages must be released via unpin_user_page(). Please\n3524:\t * see Documentation/core-api/pin_user_pages.rst for details.\n3525:\t *\n3526:\t * Note that if a zero_page is amongst the returned pages, it will not have\n3527:\t * pins in it and unpin_user_page*() will not remove pins from it.\n3528:\t */\n3529:\tlong pin_user_pages(unsigned long start, unsigned long nr_pages,\n3530:\t\t\t unsigned int gup_flags, struct page **pages)\n3531:\t{\n3532:\t\tint locked = 1;\n3533:\t\n3534:\t\tif (!is_valid_gup_args(pages, NULL, \u0026gup_flags, FOLL_PIN))\n3535:\t\t\treturn 0;\n3536:\t\treturn __gup_longterm_locked(current-\u003emm, start, nr_pages,\n3537:\t\t\t\t\t pages, \u0026locked, gup_flags);\n3538:\t}\n3539:\tEXPORT_SYMBOL(pin_user_pages);\n3540:\t\n3541:\t/*\n3542:\t * pin_user_pages_unlocked() is the FOLL_PIN variant of\n3543:\t * get_user_pages_unlocked(). Behavior is the same, except that this one sets\n3544:\t * FOLL_PIN and rejects FOLL_GET.\n3545:\t *\n3546:\t * Note that if a zero_page is amongst the returned pages, it will not have\n3547:\t * pins in it and unpin_user_page*() will not remove pins from it.\n3548:\t */\n3549:\tlong pin_user_pages_unlocked(unsigned long start, unsigned long nr_pages,\n3550:\t\t\t\t struct page **pages, unsigned int gup_flags)\n3551:\t{\n3552:\t\tint locked = 0;\n3553:\t\n3554:\t\tif (!is_valid_gup_args(pages, NULL, \u0026gup_flags,\n3555:\t\t\t\t FOLL_PIN | FOLL_TOUCH | FOLL_UNLOCKABLE))\n3556:\t\t\treturn 0;\n3557:\t\n3558:\t\treturn __gup_longterm_locked(current-\u003emm, start, nr_pages, pages,\n3559:\t\t\t\t\t \u0026locked, gup_flags);\n"
} |
| 15/2 | 2026/11/03 12:51 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 24031 output: 38 thoughts: 170 Thoughts: Okay, let's break this down. **Investigating the Paths to Page Population** Right, so I'm tracing the flow of page population, specifically focusing on how user pages are brought into memory. I see that `__gup_longterm_locked` is a key function, as it calls `__get_user_pages_locked`, which in turn, calls the core function `__get_user_pages`. This is one branch of the tree. Now, I'm also noticing that `populate_vma_page_range` calls `__get_user_pages` directly. And this `populate_vma_page_range` function is critical because it's invoked by operations like `mmap` when using `MAP_POPULATE`, `madvise` with flags such as `MADV_POPULATE_READ`, `MADV_POPULATE_WRITE`, and `MADV_WILLNEED`, and also during `mlock`. This identifies a second major pathway. Furthermore, it appears `faultin_page_range` calls `__get_user_pages_locked`, which is itself used during `madvise(MADV_POPULATE_READ/WRITE)`. This third point seems a little redundant. Alright, the next step is to examine what is calling `populate_vma_page_range` and `faultin_page_range`. I need to understand the higher-level context and trigger points for these functions to fully grasp how page population is initiated in these scenarios. |
| 16/2 | 2026/11/03 12:53 | tool | grepper |
0mArgs:{
"Expression": "faultin_page_range|populate_vma_page_range",
"PathPrefixes": [
"mm/"
]
}Results: {
"Output": "mm/gup.c=1777=static __always_inline long __get_user_pages_locked(struct mm_struct *mm,\n--\nmm/gup.c-1921-/**\nmm/gup.c:1922: * populate_vma_page_range() - populate a range of pages in the vma.\nmm/gup.c-1923- * @vma: target vma\n--\nmm/gup.c-1940- */\nmm/gup.c:1941:long populate_vma_page_range(struct vm_area_struct *vma,\nmm/gup.c-1942-\t\tunsigned long start, unsigned long end, int *locked)\n--\nmm/gup.c-1998-/*\nmm/gup.c:1999: * faultin_page_range() - populate (prefault) page tables inside the\nmm/gup.c-2000- *\t\t\t given range readable/writable\n--\nmm/gup.c-2018- */\nmm/gup.c:2019:long faultin_page_range(struct mm_struct *mm, unsigned long start,\nmm/gup.c-2020-\t\t\tunsigned long end, bool write, int *locked)\n--\nmm/gup.c=2057=int __mm_populate(unsigned long start, unsigned long len, int ignore_errors)\n--\nmm/gup.c-2090-\t\t/*\nmm/gup.c:2091:\t\t * Now fault in a range of pages. populate_vma_page_range()\nmm/gup.c-2092-\t\t * double checks the vma flags, so that it won't mlock pages\n--\nmm/gup.c-2094-\t\t */\nmm/gup.c:2095:\t\tret = populate_vma_page_range(vma, nstart, nend, \u0026locked);\nmm/gup.c-2096-\t\tif (ret \u003c 0) {\n--\nmm/internal.h=911=void unmap_mapping_folio(struct folio *folio);\nmm/internal.h:912:extern long populate_vma_page_range(struct vm_area_struct *vma,\nmm/internal.h-913-\t\tunsigned long start, unsigned long end, int *locked);\nmm/internal.h:914:extern long faultin_page_range(struct mm_struct *mm, unsigned long start,\nmm/internal.h-915-\t\tunsigned long end, bool write, int *locked);\n--\nmm/madvise.c=969=static long madvise_populate(struct madvise_behavior *madv_behavior)\n--\nmm/madvise.c-979-\t\t/* Populate (prefault) page tables readable/writable. */\nmm/madvise.c:980:\t\tpages = faultin_page_range(mm, start, end, write, \u0026locked);\nmm/madvise.c-981-\t\tif (!locked) {\n--\nmm/mlock.c=454=static int mlock_fixup(struct vma_iterator *vmi, struct vm_area_struct *vma,\n--\nmm/mlock.c-490-\t * It's okay if try_to_unmap_one unmaps a page just after we\nmm/mlock.c:491:\t * set VMA_LOCKED_BIT, populate_vma_page_range will bring it back.\nmm/mlock.c-492-\t */\n--\nmm/mmap.c=976=struct vm_area_struct *find_extend_vma_locked(struct mm_struct *mm, unsigned long addr)\n--\nmm/mmap.c-988-\tif (vma_test(prev, VMA_LOCKED_BIT))\nmm/mmap.c:989:\t\tpopulate_vma_page_range(prev, addr, prev-\u003evm_end, NULL);\nmm/mmap.c-990-\treturn prev;\n--\nmm/mmap.c=998=struct vm_area_struct *find_extend_vma_locked(struct mm_struct *mm, unsigned long addr)\n--\nmm/mmap.c-1012-\tif (vma_test(vma, VMA_LOCKED_BIT))\nmm/mmap.c:1013:\t\tpopulate_vma_page_range(vma, addr, start, NULL);\nmm/mmap.c-1014-\treturn vma;\n--\nmm/mprotect.c=760=mprotect_fixup(struct vma_iterator *vmi, struct mmu_gather *tlb,\n--\nmm/mprotect.c-853-\t !vma_flags_test_any(\u0026old_vma_flags, VMA_WRITE_BIT, VMA_SHARED_BIT))\nmm/mprotect.c:854:\t\tpopulate_vma_page_range(vma, start, end, NULL);\nmm/mprotect.c-855-\n"
} |
| 17/2 | 2026/11/03 12:53 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 25848 output: 27 thoughts: 921 Thoughts: **Analyzing a Core Memory Management Patch** Okay, this is some serious memory management code! I need to dive deep into these patch changes in `mm/gup.c`. Let's break it down methodically. First, I see that the `no_page_table()` function's return type has shifted from `struct page *` to `long`, now returning 0 or -EFAULT instead of the old NULL/ERR_PTR(-EFAULT) combo. That's a subtle but important change in error handling. Next, the introduction of `gup_fill_pages()` and `gup_flush_pages()` for batch cache flushes without the overhead of page table locks is a smart optimization. `follow_huge_pud()` and `follow_huge_pmd()` have had a return type makeover as well, now accepting a few more parameters like `(vma, addr, end, pudp, flags, pages)`. The logic calculating `nr` (number of pages) now uses `min` to avoid buffer overflows, and the batching is done with `try_grab_folio` for efficiency. `gup_grab_folio_pages()` is now responsible for grabbing folio references for a batch of pages, and marking them as dirty or accessed, and populating the `pages` array. A dedicated function, good for clarity. I've got a new one in the mix called `gup_lookup_pte()`. It's tasked with resolving a single PTE to the corresponding page. Then there's `gup_pte_batch_len()`. This is the really interesting one, figuring out how many PTEs map consecutive pages of the same folio, allowing for efficient batch operations. It leverages `folio_pte_batch_flags` with options like `FPB_RESPECT_WRITE` and `FPB_MERGE_YOUNG_DIRTY`. `follow_page_pte()` is where the batching magic happens! It's now walking PTEs in a loop, committing contiguous PTE runs as batches using `gup_pte_batch_len` and `gup_grab_folio_pages`, then flushes pages after unlocking ptl via `gup_flush_pages`. The `follow_*_mask()` functions (PMD, PUD, P4D, and regular pages) have all been updated to take an `end` address and `struct page **pages`, and return a `long` indicating the number of contiguous pages resolved. Finally, the big one, `__get_user_pages()` is fundamentally changed. Instead of the old single-page-at-a-time approach, it's calling `follow_page_mask` with the entire range, from `start` to `nr_pages * PAGE_SIZE`, and receiving `nr` directly. There's even an assertion `VM_WARN_ON_ONCE(nr > nr_pages)`, which is great to see for catching potential issues. Error handling has also been improved. This is a major optimization and refactoring! We are talking contiguous PTE batching, huge page (PMD and PUD) handling, folio batching, cache flushing, dirty/accessed tracking, and improved error handling. This could be a really rich area for fuzzing. Looking at the scope: Core subsystem changes in `mm/`, refactoring for clarity, and a runtime assertion - that's a good trifecta for fuzzing targets. Furthermore, it's all reachable in a standard QEMU environment through normal system calls like `madvise`, `mlock`, `process_vm_readv/writev`, `ptrace`, `io_uring`, `splice`, direct I/O, etc. Now, let's look at the config options and relevant symbols to narrow down the attack surface. |
| 18/2 | 2026/11/03 12:53 | tool | grepper |
0mArgs:{
"Expression": "gup\\.o",
"PathPrefixes": [
"mm/"
]
}Results: {
"Output": "mm/Makefile=51=obj-y\t\t\t:= filemap.o mempool.o oom_kill.o fadvise.o \\\n--\nmm/Makefile-57-\t\t\t interval_tree.o list_lru.o workingset.o \\\nmm/Makefile:58:\t\t\t debug.o gup.o mmap_lock.o vma_init.o char-mem.o \\\nmm/Makefile-59-\t\t\t $(mmu-y)\n"
} |
| 19/2 | 2026/11/03 12:53 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 27737 output: 31 thoughts: 79 Thoughts: Okay, here's my understanding, considering I'm deeply familiar with kernel internals: **Investigating the Build and Configuration of `gup.o`** Right, so I'm digging into how `gup.o` is constructed, and I know from experience that it's always included in `mm/Makefile` using `obj-y`. That's standard practice, nothing unusual there. Now, I'm specifically interested in the `mm/gup.c` source file. Aha! Here's something interesting: almost the *entire* file is gated behind `#ifdef CONFIG_MMU`. I knew MMU support was fundamental, but this is a pretty strong indication of its dependency. I need to take a closer look at how `CONFIG_MMU` is defined and what other parts of the system are affected by its absence or presence. Time to delve into the kernel's configuration options and see what's what. This suggests that the core functionality of `gup.c` is deeply intertwined with a Memory Management Unit. |
| 20/2 | 2026/11/03 12:54 | tool | grepper |
0mArgs:{
"Expression": "CONFIG_MMU",
"PathPrefixes": [
"mm/gup.c"
]
}Results: {
"Output": "mm/gup.c=479=static inline void mm_set_has_pinned_flag(struct mm_struct *mm)\n--\nmm/gup.c-484-\nmm/gup.c:485:#ifdef CONFIG_MMU\nmm/gup.c-486-\n--\nmm/gup.c=2057=int __mm_populate(unsigned long start, unsigned long len, int ignore_errors)\n--\nmm/gup.c-2109-}\nmm/gup.c:2110:#else /* CONFIG_MMU */\nmm/gup.c-2111-static long __get_user_pages_locked(struct mm_struct *mm, unsigned long start,\n--\nmm/gup.c-2178-}\nmm/gup.c:2179:#endif /* !CONFIG_MMU */\nmm/gup.c-2180-\n--\nmm/gup.c=2638=static bool is_valid_gup_args(struct page **pages, int *locked,\n--\nmm/gup.c-2683-\nmm/gup.c:2684:#ifdef CONFIG_MMU\nmm/gup.c-2685-/**\n--\nmm/gup.c=2756=EXPORT_SYMBOL(get_user_pages_remote);\nmm/gup.c-2757-\nmm/gup.c:2758:#else /* CONFIG_MMU */\nmm/gup.c-2759-long get_user_pages_remote(struct mm_struct *mm,\n--\nmm/gup.c-2765-}\nmm/gup.c:2766:#endif /* !CONFIG_MMU */\nmm/gup.c-2767-\n"
} |
| 21/2 | 2026/11/03 12:54 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 28529 output: 40 thoughts: 184 Thoughts: Okay, let's see. Here's how I'm thinking through this code: **Analyzing Huge Page Configuration in the Kernel** Alright, I'm looking at this diff and immediately I'm drawn to these preprocessor directives. I'm seeing `#ifdef CONFIG_PGTABLE_HAS_HUGE_LEAVES` and `#ifdef CONFIG_TRANSPARENT_HUGEPAGE`, and it's clear these are going to control how the `follow_huge_pud` function behaves. I need to understand what's going on with huge pages in this context, so these two configurations are the keys. The code clearly branches differently based on their definitions. It's evident the huge page functionality is being conditionally compiled, and this `follow_huge_pud` function seems central to handling those pages, and the Transparent Huge Pages (THP) also are defined within a branching condition. My immediate next step is to figure out *exactly* where `CONFIG_PGTABLE_HAS_HUGE_LEAVES` and `CONFIG_TRANSPARENT_HUGEPAGE` are defined. Are they in the kernel config? Are they environment variables? Are they defined in some other header? I have to locate their definitions to fully understand the logic flow here. I need to trace back to the Kconfig or include files to know what the implications are, what the default values are, and under what circumstances each path is taken. That will give me the full picture. |
| 22/2 | 2026/11/03 12:55 | tool | grepper |
0mArgs:{
"Expression": "config PGTABLE_HAS_HUGE_LEAVES",
"PathPrefixes": [
"arch/",
"mm/"
]
}Results: {
"Output": "mm/Kconfig=992=config PAGE_MAPCOUNT\n--\nmm/Kconfig-997-#\nmm/Kconfig:998:config PGTABLE_HAS_HUGE_LEAVES\nmm/Kconfig-999-\tdef_bool TRANSPARENT_HUGEPAGE || HUGETLB_PAGE\n"
} |
| 23/2 | 2026/11/03 12:55 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29151 output: 34 thoughts: 87 Thoughts: Okay, here's my understanding, tailored for an expert audience: **Analyzing the PGTABLE_HAS_HUGE_LEAVES Configuration** Right, so `PGTABLE_HAS_HUGE_LEAVES` is defined as a boolean expression. Specifically, it's equivalent to `TRANSPARENT_HUGEPAGE || HUGETLB_PAGE`. That means either one of those being set – `TRANSPARENT_HUGEPAGE` or `HUGETLB_PAGE` – automatically enables `PGTABLE_HAS_HUGE_LEAVES`. So, it's a simple OR condition. Makes sense from a functionality standpoint; either THP or explicit huge page support implies the need for huge leaves in the page tables. Now, let me just quickly glance at `mm/Kconfig` to refresh my memory on `TRANSPARENT_HUGEPAGE`... I want to verify its dependencies and any potential interactions. |
| 24/2 | 2026/11/03 12:56 | tool | grepper |
0mArgs:{
"Expression": "config TRANSPARENT_HUGEPAGE$",
"PathPrefixes": [
"mm/Kconfig"
]
}Results: {
"Output": "mm/Kconfig=827=config MM_ID\n--\nmm/Kconfig-829-\nmm/Kconfig:830:menuconfig TRANSPARENT_HUGEPAGE\nmm/Kconfig-831-\tbool \"Transparent Hugepage Support\"\n"
} |
| 25/2 | 2026/11/03 12:56 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29544 output: 32 thoughts: 27 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Investigating `HUGETLB_PAGE`** Right, let's dive into this `HUGETLB_PAGE` business. My first instinct is to zero in on where this is actually defined and configured, so the logical starting point is the `mm/Kconfig` file. I need to understand how this is exposed and controlled within the kernel build system. That's where the real meat of the configuration will be. Time to see what's what in `mm/Kconfig`. Let's get to it. |
| 26/2 | 2026/11/03 12:57 | tool | grepper |
0mArgs:{
"Expression": "config HUGETLB_PAGE$",
"PathPrefixes": [
"mm/Kconfig"
]
}Results: {
"Output": "no matches"
} |
| 27/2 | 2026/11/03 12:57 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29746 output: 22 thoughts: 15 Thoughts: Here's my thought process, summarized as you requested: **Searching for HUGETLB_PAGE Configuration** Okay, time to dig in. I need to get a handle on the configuration options for huge pages. My first instinct is to do a broad search, and what I want to know is where the `config HUGETLB_PAGE` variable is defined. Let's see if I can find it across the board. |
| 28/2 | 2026/11/03 12:58 | tool | grepper |
0mArgs:{
"Expression": "config HUGETLB_PAGE\\b"
}Results: {
"Output": "fs/Kconfig=271=endif # HUGETLBFS\nfs/Kconfig-272-\nfs/Kconfig:273:config HUGETLB_PAGE\nfs/Kconfig-274-\tdef_bool HUGETLBFS\n"
} |
| 29/2 | 2026/11/03 12:58 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29945 output: 34 thoughts: 3473 Thoughts: **Focus Symbol Selection for `mm/gup.c` Changes** Okay, let's break this down. My goal here is to identify the most effective `FocusSymbols` to guide fuzzing towards the significant changes in `mm/gup.c`, specifically concerning large page support and batching logic. Given the guidelines, I need to pinpoint functions that are *feature-specific* and not ubiquitous hot-paths, and the entrypoints related to the modified functionality. First, I established the context: `HUGETLBFS` enables `HUGETLB_PAGE`, and `TRANSPARENT_HUGEPAGE` enables THP along with `PGTABLE_HAS_HUGE_LEAVES`. `CONFIG_MMU` is a given; it's a default, and therefore not a primary concern for focus. I checked for other configuration dependencies, noticing the key role of `TRANSPARENT_HUGEPAGE` in enabling large page features. I went through the changed lines in `mm/gup.c`, making a list of the modified functions: `no_page_table`, `gup_fill_pages`, `gup_flush_pages`, `follow_huge_pud`, `follow_huge_pmd`, `gup_grab_folio_pages`, `gup_lookup_pte`, `gup_pte_batch_len`, `follow_page_pte`, `follow_pmd_mask`, `follow_pud_mask`, `follow_p4d_mask`, and `__get_user_pages`. I also noted the configuration guards, especially those around `PGTABLE_HAS_HUGE_LEAVES` and the interplay between `TRANSPARENT_HUGEPAGE`, large pages (PMD/PUD), and huge leaf support. Now, the crucial question: are these functions static or exported, and can they be targeted? I observed that many functions, like `__get_user_pages`, are `static`. However, `__get_user_pages` itself is called by several non-static functions like `populate_vma_page_range`, `faultin_page_range`, `get_user_pages`, etc. I considered the potential for inlining of `static` functions, acknowledging the rule: compiler-inlined static functions in headers (.h) lack distinct symbols, so I need to target their callers in .c files. I also noted that *static* functions in .c files can be distinct symbols. I ruled out the functions likely to be inlined, such as `gup_fill_pages`, `gup_lookup_pte`, and `gup_pte_batch_len` as less important. The important point is that, in this case, `__get_user_pages` is *not* ubiquitous. It's not called during standard syscall execution, page faults, or normal memory allocation, but it *is* called when features such as: mlock, madvise, mmap(MAP_POPULATE), mprotect, process_vm_readv / process_vm_writev, ptrace, direct I/O, vhost, io_uring, KVM, and InfiniBand pin user memory. This makes it a prime candidate for a focused symbol. Next, I examined the functions that *directly implement* the changed logic and are not ubiquitous. This led me to select the following functions as candidates for `FocusSymbols`: * `follow_page_mask`: This is the core lookup that takes a range `[address, end)` * `follow_page_pte`: The PTE walk which has been modified to batch contiguous PTEs. * `follow_huge_pmd`: Rewritten to support batching of PMD-mapped huge pages. * `follow_huge_pud`: Rewritten to support batching of PUD-mapped huge pages. * `__get_user_pages`: The central caller modified to drive the new batching logic and handle short reads / errors / assertions. * `faultin_page_range`: Direct caller of `__get_user_pages_locked` used for madvise populate. * `populate_vma_page_range`: Direct caller of `__get_user_pages` used for mlock / MAP_POPULATE. Crucially, I confirmed that none of these functions are marked as `static inline` in the code, which means they should be distinct symbols. Further investigation revealed all the functions are `static long`, which increases the chances they will be separate symbols even if the compiler *does* try to inline them. I also confirmed they are substantial functions, with loops, locks and complex branching. Finally, I checked relevant `CONFIG` options: `MM |
| 30/2 | 2026/11/03 13:00 | tool | grepper |
0mArgs:{
"Expression": "menuconfig TRANSPARENT_HUGEPAGE",
"PathPrefixes": [
"mm/Kconfig"
]
}Results: {
"Output": "mm/Kconfig=827=config MM_ID\n--\nmm/Kconfig-829-\nmm/Kconfig:830:menuconfig TRANSPARENT_HUGEPAGE\nmm/Kconfig-831-\tbool \"Transparent Hugepage Support\"\n"
} |
| 31/2 | 2026/11/03 13:00 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 34552 output: 32 thoughts: 17 Thoughts: Okay, here's my summary, tailored for an expert audience, as if it's coming directly from my own thought process: **Diving into TRANSPARENT_HUGEPAGE Dependencies** Alright, let's get down to brass tacks. Time to dissect the dependencies of `TRANSPARENT_HUGEPAGE`. I need to understand exactly what other kernel components, subsystems, or potentially even userspace libraries this feature leans on. This isn't just about knowing if it's enabled or disabled; it's about the ripple effects. We're talking about potential interactions with memory management, NUMA architectures, the page table handling code, maybe even specific CPU features. My goal here is to get a holistic view of the implications. This will involve delving into the source code, poking around configuration options, and really digging down to the low-level interactions that might be at play. I'm thinking I'll start by mapping out the call chains and cross-references. |
| 32/2 | 2026/11/03 13:01 | tool | read-file |
0mArgs:{
"File": "mm/Kconfig",
"FirstLine": 828,
"LineCount": 30
}Results: {
"Contents": " 828:\t\tdef_bool n\n 829:\t\n 830:\tmenuconfig TRANSPARENT_HUGEPAGE\n 831:\t\tbool \"Transparent Hugepage Support\"\n 832:\t\tdepends on HAVE_ARCH_TRANSPARENT_HUGEPAGE \u0026\u0026 !PREEMPT_RT\n 833:\t\tselect COMPACTION\n 834:\t\tselect XARRAY_MULTI\n 835:\t\tselect MM_ID\n 836:\t\thelp\n 837:\t\t Transparent Hugepages allows the kernel to use huge pages and\n 838:\t\t huge tlb transparently to the applications whenever possible.\n 839:\t\t This feature can improve computing performance to certain\n 840:\t\t applications by speeding up page faults during memory\n 841:\t\t allocation, by reducing the number of tlb misses and by speeding\n 842:\t\t up the pagetable walking.\n 843:\t\n 844:\t\t If memory constrained on embedded, you may want to say N.\n 845:\t\n 846:\tif TRANSPARENT_HUGEPAGE\n 847:\t\n 848:\tchoice\n 849:\t\tprompt \"Transparent Hugepage Support sysfs defaults\"\n 850:\t\tdefault TRANSPARENT_HUGEPAGE_ALWAYS\n 851:\t\thelp\n 852:\t\t Selects the sysfs defaults for Transparent Hugepage Support.\n 853:\t\n 854:\t\tconfig TRANSPARENT_HUGEPAGE_ALWAYS\n 855:\t\t\tbool \"always\"\n 856:\t\thelp\n 857:\t\t Enabling Transparent Hugepage always, can increase the\n"
} |
| 33/2 | 2026/11/03 13:01 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 35229 output: 32 thoughts: 75 Thoughts: Here's my summary, as I understand it: **Examining Transparent Hugepages and the Filesystem Configuration** Okay, so I'm looking at `TRANSPARENT_HUGEPAGE`, and it's clear this feature hinges on a couple of factors: `HAVE_ARCH_TRANSPARENT_HUGEPAGE` being enabled *and* the system *not* being a `PREEMPT_RT` system. That makes sense, given the potential real-time constraints. On amd64 architecture specifically, `HAVE_ARCH_TRANSPARENT_HUGEPAGE` is definitely set to "y". Now, I need to understand how this interacts with the filesystem side of things. I need to take a look at `HUGETLBFS` within `fs/Kconfig`. I'm guessing that enabling this would have an impact on how transparent hugepages function in the file system context. I wonder what the interaction is? I will check `HUGETLBFS` to see what I can find. |
| 34/2 | 2026/11/03 13:03 | tool | read-file |
0mArgs:{
"File": "fs/Kconfig",
"FirstLine": 240,
"LineCount": 40
}Results: {
"Contents": " 240:\t\t Quota support allows to set per user and group limits for tmpfs\n 241:\t\t usage. Say Y to enable quota support. Once enabled you can control\n 242:\t\t user and group quota enforcement with quota, usrquota and grpquota\n 243:\t\t mount options.\n 244:\t\n 245:\t\t If unsure, say N.\n 246:\t\n 247:\tconfig ARCH_SUPPORTS_HUGETLBFS\n 248:\t\tdef_bool n\n 249:\t\n 250:\tmenuconfig HUGETLBFS\n 251:\t\tbool \"HugeTLB file system support\"\n 252:\t\tdepends on ARCH_SUPPORTS_HUGETLBFS\n 253:\t\tselect MEMFD_CREATE\n 254:\t\tselect PADATA if SMP\n 255:\t\thelp\n 256:\t\t hugetlbfs is a filesystem backing for HugeTLB pages, based on\n 257:\t\t ramfs. For architectures that support it, say Y here and read\n 258:\t\t \u003cfile:Documentation/admin-guide/mm/hugetlbpage.rst\u003e for details.\n 259:\t\n 260:\t\t If unsure, say N.\n 261:\t\n 262:\tif HUGETLBFS\n 263:\tconfig HUGETLB_PAGE_OPTIMIZE_VMEMMAP_DEFAULT_ON\n 264:\t\tbool \"HugeTLB Vmemmap Optimization (HVO) defaults to on\"\n 265:\t\tdefault n\n 266:\t\tdepends on HUGETLB_PAGE_OPTIMIZE_VMEMMAP\n 267:\t\thelp\n 268:\t\t The HugeTLB Vmemmap Optimization (HVO) defaults to off. Say Y here to\n 269:\t\t enable HVO by default. It can be disabled via hugetlb_free_vmemmap=off\n 270:\t\t (boot command line) or hugetlb_optimize_vmemmap (sysctl).\n 271:\tendif # HUGETLBFS\n 272:\t\n 273:\tconfig HUGETLB_PAGE\n 274:\t\tdef_bool HUGETLBFS\n 275:\t\tselect XARRAY_MULTI\n 276:\t\n 277:\tconfig HUGETLB_PAGE_OPTIMIZE_VMEMMAP\n 278:\t\tdef_bool HUGETLB_PAGE\n 279:\t\tdepends on ARCH_WANT_OPTIMIZE_HUGETLB_VMEMMAP\n"
} |
| 35/2 | 2026/11/03 13:03 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 36196 output: 280 thoughts: 851 Thoughts: **GUP Patch Analysis: A Focused Fuzzing Strategy** Okay, so I've been looking at this GUP patch and I need to figure out the best way to approach fuzzing it. First, I see that this patch touches the core of memory management, specifically `mm/gup.c`. I need to ensure the right kernel configs are in place to enable the relevant functionality, so I've checked: `HUGETLBFS`, `TRANSPARENT_HUGEPAGE`, and `MMU` are all essential, especially as they enable huge page handling and are related to how GUP walks page tables. I've also verified that other related configurations are present as well (`CONFIG_PGTABLE_HAS_HUGE_LEAVES`). Now, I've identified the key functions in this patch that are worth focusing on. I've compiled a list of symbols I want to concentrate my fuzzing efforts on to avoid dilution: `__get_user_pages`, `follow_page_mask`, `follow_page_pte`, `follow_huge_pmd`, `follow_huge_pud`, `follow_pmd_mask`, `gup_pte_batch_len`, and `gup_grab_folio_pages`. These are the core elements that represent the changed page-table walking, batching, and huge page handling logic. I've made sure to narrow the focus to the pertinent functions, as these functions are not ubiquitous like other core memory functions, but are specific to GUP/locked page table walks and page pinning. This patch essentially refactors the GUP logic to batch PTEs, handle huge pages in a batched way, and update how page ranges are processed. It introduces a new assertion (`VM_WARN_ON_ONCE(nr > nr_pages)`) and affects reference counting, dirty/accessed tracking, and error handling. The primary entry points into these functions are syscalls like `madvise`, `mlock`, `process_vm_readv/writev`, `ptrace`, `io_uring` and direct I/O. Therefore, the code changes are definitely reachable in typical virtualized environments. This all points to it being definitely "WorthFuzzing"! |
| 36/2 | 2026/11/03 13:04 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"MMU",
"TRANSPARENT_HUGEPAGE",
"HUGETLBFS"
],
"FocusSymbols": [
"__get_user_pages",
"follow_page_mask",
"follow_page_pte",
"follow_huge_pmd",
"follow_huge_pud",
"follow_pmd_mask",
"gup_pte_batch_len",
"gup_grab_folio_pages"
],
"Reasoning": "The patch refactors the core memory management page table walk in mm/gup.c (get_user_pages / follow_page_mask) to support batching of contiguous PTEs and huge PMDs/PUDs for folios. It reworks reference acquisition (try_grab_folio), dirty/accessed tracking, error propagation, cache flushing, and adds a runtime assertion (VM_WARN_ON_ONCE(nr \u003e nr_pages)). This code is fully reachable in virtualized environments via syscalls exercising GUP (e.g., madvise with MADV_POPULATE_READ/WRITE, mlock, process_vm_readv/writev, ptrace, io_uring, direct I/O).",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"MMU",
"TRANSPARENT_HUGEPAGE",
"HUGETLBFS"
],
"FocusSymbols": [
"__get_user_pages",
"follow_page_mask",
"follow_page_pte",
"follow_huge_pmd",
"follow_huge_pud",
"follow_pmd_mask",
"gup_pte_batch_len",
"gup_grab_folio_pages"
],
"Reasoning": "The patch refactors the core memory management page table walk in mm/gup.c (get_user_pages / follow_page_mask) to support batching of contiguous PTEs and huge PMDs/PUDs for folios. It reworks reference acquisition (try_grab_folio), dirty/accessed tracking, error propagation, cache flushing, and adds a runtime assertion (VM_WARN_ON_ONCE(nr \u003e nr_pages)). This code is fully reachable in virtualized environments via syscalls exercising GUP (e.g., madvise with MADV_POPULATE_READ/WRITE, mlock, process_vm_readv/writev, ptrace, io_uring, direct I/O).",
"WorthFuzzing": true
} |
| 37/1 | 2026/11/03 13:04 | action | If |
1mArgs:{
"WorthFuzzing": true
}Results: null |
| 38/2 | 2026/11/03 13:04 | agent | kmsan-evaluator |
1mModel:core Args: null Results: {
"KMSANReasoning": "The patch refactors the GUP (get_user_pages) slow path in mm/gup.c to support batched PTE and huge PMD/PUD lookups and folio pinning (introducing helpers like gup_grab_folio_pages, gup_lookup_pte, gup_pte_batch_len, gup_fill_pages, and updating follow_page_pte / follow_page_mask).\n\nNo uninitialized memory hazards are introduced or exposed:\n1. No structures are copied to user space, so there is no risk of kernel info-leaks.\n2. All local variables and pointers (e.g. `nr`, `need_no_page_table`, `ret`, `off`, `pagep`) are strictly initialized or unconditionally assigned prior to read or branch operations.\n3. The caller-provided `pages` array is populated with valid `struct page *` pointers for all `nr` pages returned.\n4. Any potential bugs in batch length calculations or index offsets would manifest as out-of-bounds accesses on the `pages` array, incorrect refcounts, or locking errors, all of which are caught by KASAN, LOCKDEP, or standard kernel debug assertions.\n\nTherefore, dedicated KMSAN fuzzing 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 ec6963d74782bda695601c9573e98ad620e5c8e5
Author: syz-cluster <triage@syzkaller.com>
Date: Tue Nov 3 12:45:18 2026 +0000
syz-cluster: applied patch under review
diff --git a/mm/gup.c b/mm/gup.c
index 7d43ce717b2461..47f204e21a3a79 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -608,15 +608,15 @@ static inline bool can_follow_write_common(struct page *page,
return page && PageAnon(page) && PageAnonExclusive(page);
}
-static struct page *no_page_table(struct vm_area_struct *vma,
- unsigned int flags, unsigned long address)
+static long no_page_table(struct vm_area_struct *vma,
+ unsigned int flags, unsigned long address)
{
if (!(flags & FOLL_DUMP))
- return NULL;
+ return 0;
/*
* When core dumping, we don't want to allocate unnecessary pages or
- * page tables. Return error instead of NULL to skip handle_mm_fault,
+ * page tables. Return error instead of 0 to skip handle_mm_fault,
* then get_dump_page() will return NULL to leave a hole in the dump.
* But we can only make this optimization where a hole would surely
* be zero-filled if handle_mm_fault() actually did handle it.
@@ -625,12 +625,48 @@ static struct page *no_page_table(struct vm_area_struct *vma,
struct hstate *h = hstate_vma(vma);
if (!hugetlbfs_pagecache_present(h, vma, address))
- return ERR_PTR(-EFAULT);
+ return -EFAULT;
} else if ((vma_is_anonymous(vma) || !vma->vm_ops->fault)) {
- return ERR_PTR(-EFAULT);
+ return -EFAULT;
}
- return NULL;
+ return 0;
+}
+
+static void gup_fill_pages(struct vm_area_struct *vma, unsigned long address,
+ struct page *page, unsigned long nr, struct page **pages)
+{
+ unsigned long i;
+
+ if (!pages)
+ return;
+
+ for (i = 0; i < nr; i++) {
+ struct page *subpage = page + i;
+
+ pages[i] = subpage;
+ flush_anon_page(vma, subpage, address + i * PAGE_SIZE);
+ flush_dcache_page(subpage);
+ }
+}
+
+/*
+ * Flush the caches for @nr pages stored in @pages. The caller already
+ * holds folio references, so the pages cannot go away; this runs
+ * without any page table lock held.
+ */
+static void gup_flush_pages(struct vm_area_struct *vma, unsigned long address,
+ struct page **pages, unsigned long nr)
+{
+ unsigned long i;
+
+ if (!pages)
+ return;
+
+ for (i = 0; i < nr; i++) {
+ flush_anon_page(vma, pages[i], address + i * PAGE_SIZE);
+ flush_dcache_page(pages[i]);
+ }
}
#ifdef CONFIG_PGTABLE_HAS_HUGE_LEAVES
@@ -646,38 +682,43 @@ static inline bool can_follow_write_pud(pud_t pud, struct page *page,
return can_follow_write_common(page, vma, flags);
}
-static struct page *follow_huge_pud(struct vm_area_struct *vma,
- unsigned long addr, pud_t *pudp,
- int flags, unsigned long *page_mask)
+static long follow_huge_pud(struct vm_area_struct *vma,
+ unsigned long addr, unsigned long end, pud_t *pudp,
+ unsigned int flags, struct page **pages)
{
struct mm_struct *mm = vma->vm_mm;
struct page *page;
pud_t pud = *pudp;
unsigned long pfn = pud_pfn(pud);
+ unsigned long off, nr;
int ret;
assert_spin_locked(pud_lockptr(mm, pudp));
if (!pud_present(pud))
- return NULL;
+ return 0;
if ((flags & FOLL_WRITE) &&
!can_follow_write_pud(pud, pfn_to_page(pfn), vma, flags))
- return NULL;
+ return 0;
- pfn += (addr & ~PUD_MASK) >> PAGE_SHIFT;
+ off = PFN_DOWN(addr & ~PUD_MASK);
+ pfn += off;
page = pfn_to_page(pfn);
if (!pud_write(pud) && gup_must_unshare(vma, flags, page))
- return ERR_PTR(-EMLINK);
+ return -EMLINK;
+
+ nr = min(HPAGE_PUD_NR - off, PFN_DOWN(end - addr));
- ret = try_grab_folio(page_folio(page), 1, flags);
+ ret = try_grab_folio(page_folio(page), nr, flags);
if (ret)
- page = ERR_PTR(ret);
- else
- *page_mask = HPAGE_PUD_NR - 1;
+ return ret;
+
+ if (pages)
+ pages[0] = page;
- return page;
+ return nr;
}
/* FOLL_FORCE can write to even unwritable PMDs in COW mappings. */
@@ -698,14 +739,14 @@ static inline bool can_follow_write_pmd(pmd_t pmd, struct page *page,
return !userfaultfd_huge_pmd_wp(vma, pmd);
}
-static struct page *follow_huge_pmd(struct vm_area_struct *vma,
- unsigned long addr, pmd_t *pmd,
- unsigned int flags,
- unsigned long *page_mask)
+static long follow_huge_pmd(struct vm_area_struct *vma,
+ unsigned long addr, unsigned long end, pmd_t *pmd,
+ unsigned int flags, struct page **pages)
{
struct mm_struct *mm = vma->vm_mm;
pmd_t pmdval = *pmd;
struct page *page;
+ unsigned long off, nr;
int ret;
assert_spin_locked(pmd_lockptr(mm, pmd));
@@ -713,50 +754,54 @@ static struct page *follow_huge_pmd(struct vm_area_struct *vma,
page = pmd_page(pmdval);
if ((flags & FOLL_WRITE) &&
!can_follow_write_pmd(pmdval, page, vma, flags))
- return NULL;
+ return 0;
/* Avoid dumping huge zero page */
if ((flags & FOLL_DUMP) && is_huge_zero_pmd(pmdval))
- return ERR_PTR(-EFAULT);
+ return -EFAULT;
if (pmd_protnone(*pmd) && !gup_can_follow_protnone(vma, flags))
- return NULL;
+ return 0;
if (!pmd_write(pmdval) && gup_must_unshare(vma, flags, page))
- return ERR_PTR(-EMLINK);
+ return -EMLINK;
VM_WARN_ON_ONCE_PAGE((flags & FOLL_PIN) && PageAnon(page) &&
!PageAnonExclusive(page), page);
- ret = try_grab_folio(page_folio(page), 1, flags);
+ off = PFN_DOWN(addr & ~HPAGE_PMD_MASK);
+ nr = min(HPAGE_PMD_NR - off, PFN_DOWN(end - addr));
+
+ ret = try_grab_folio(page_folio(page), nr, flags);
if (ret)
- return ERR_PTR(ret);
+ return ret;
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
if (pmd_trans_huge(pmdval) && (flags & FOLL_TOUCH))
touch_pmd(vma, addr, pmd, flags & FOLL_WRITE);
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
- page += (addr & ~HPAGE_PMD_MASK) >> PAGE_SHIFT;
- *page_mask = HPAGE_PMD_NR - 1;
+ page += off;
+
+ if (pages)
+ pages[0] = page;
- return page;
+ return nr;
}
#else /* CONFIG_PGTABLE_HAS_HUGE_LEAVES */
-static struct page *follow_huge_pud(struct vm_area_struct *vma,
- unsigned long addr, pud_t *pudp,
- int flags, unsigned long *page_mask)
+static long follow_huge_pud(struct vm_area_struct *vma,
+ unsigned long addr, unsigned long end, pud_t *pudp,
+ unsigned int flags, struct page **pages)
{
- return NULL;
+ return 0;
}
-static struct page *follow_huge_pmd(struct vm_area_struct *vma,
- unsigned long addr, pmd_t *pmd,
- unsigned int flags,
- unsigned long *page_mask)
+static long follow_huge_pmd(struct vm_area_struct *vma,
+ unsigned long addr, unsigned long end, pmd_t *pmd,
+ unsigned int flags, struct page **pages)
{
- return NULL;
+ return 0;
}
#endif /* CONFIG_PGTABLE_HAS_HUGE_LEAVES */
@@ -799,110 +844,213 @@ static inline bool can_follow_write_pte(pte_t pte, struct page *page,
return !userfaultfd_pte_wp(vma, pte);
}
-static struct page *follow_page_pte(struct vm_area_struct *vma,
- unsigned long address, pmd_t *pmd, unsigned int flags)
+/*
+ * Grab a folio reference for @nr pages starting at @page, mark the folio
+ * accessed (and dirty for FOLL_WRITE), and store the pages for the caller.
+ * The caller flushes the caches after dropping the page table lock.
+ */
+static long gup_grab_folio_pages(struct folio *folio,
+ struct page *page, unsigned long nr, bool dirty,
+ unsigned int flags, struct page **pages)
+{
+ unsigned long i;
+ long ret;
+
+ /* try_grab_folio() does nothing unless FOLL_GET or FOLL_PIN is set. */
+ ret = try_grab_folio(folio, nr, flags);
+ if (unlikely(ret))
+ return ret;
+
+ /*
+ * We need to make the page accessible if and only if we are going
+ * to access its content (the FOLL_PIN case). Please see
+ * Documentation/core-api/pin_user_pages.rst for details.
+ */
+ if (flags & FOLL_PIN) {
+ ret = arch_make_folio_accessible(folio);
+ if (ret) {
+ gup_put_folio(folio, nr, flags);
+ return ret;
+ }
+ }
+ if (flags & FOLL_TOUCH) {
+ if ((flags & FOLL_WRITE) && !dirty && !folio_test_dirty(folio))
+ folio_mark_dirty(folio);
+ /*
+ * pte_mkyoung() would be more correct here, but atomic care
+ * is needed to avoid losing the dirty bit: it is easier to use
+ * folio_mark_accessed().
+ */
+ folio_mark_accessed(folio);
+ }
+
+ if (pages) {
+ for (i = 0; i < nr; i++)
+ pages[i] = page + i;
+ }
+
+ return 0;
+}
+
+/*
+ * Resolve one present PTE to the page it maps. Returns no page and no error
+ * when the PTE cannot be followed but the caller may fault it in, and a
+ * negative errno when the caller must report the failure.
+ */
+static long gup_lookup_pte(struct vm_area_struct *vma, unsigned long address,
+ pte_t *ptep, pte_t pte, unsigned int flags, struct page **pagep)
{
- struct mm_struct *mm = vma->vm_mm;
- struct folio *folio;
struct page *page;
- spinlock_t *ptl;
- pte_t *ptep, pte;
- int ret;
- ptep = pte_offset_map_lock(mm, pmd, address, &ptl);
- if (!ptep)
- return no_page_table(vma, flags, address);
- pte = ptep_get(ptep);
+ *pagep = NULL;
+
if (!pte_present(pte))
- goto no_page;
+ return 0;
if (pte_protnone(pte) && !gup_can_follow_protnone(vma, flags))
- goto no_page;
+ return 0;
page = vm_normal_page(vma, address, pte);
/*
* We only care about anon pages in can_follow_write_pte().
*/
- if ((flags & FOLL_WRITE) &&
- !can_follow_write_pte(pte, page, vma, flags)) {
- page = NULL;
- goto out;
- }
+ if ((flags & FOLL_WRITE) && !can_follow_write_pte(pte, page, vma, flags))
+ return 0;
if (unlikely(!page)) {
if (flags & FOLL_DUMP) {
/* Avoid special (like zero) pages in core dumps */
- page = ERR_PTR(-EFAULT);
- goto out;
- }
-
- if (is_zero_pfn(pte_pfn(pte))) {
- page = pte_page(pte);
- } else {
- ret = follow_pfn_pte(vma, address, ptep, flags);
- page = ERR_PTR(ret);
- goto out;
+ return -EFAULT;
}
+ if (!is_zero_pfn(pte_pfn(pte)))
+ return follow_pfn_pte(vma, address, ptep, flags);
+ page = pte_page(pte);
}
- folio = page_folio(page);
- if (!pte_write(pte) && gup_must_unshare(vma, flags, page)) {
- page = ERR_PTR(-EMLINK);
- goto out;
- }
+ if (!pte_write(pte) && gup_must_unshare(vma, flags, page))
+ return -EMLINK;
VM_WARN_ON_ONCE_PAGE((flags & FOLL_PIN) && PageAnon(page) &&
!PageAnonExclusive(page), page);
- /* try_grab_folio() does nothing unless FOLL_GET or FOLL_PIN is set. */
- ret = try_grab_folio(folio, 1, flags);
- if (unlikely(ret)) {
- page = ERR_PTR(ret);
- goto out;
- }
+ *pagep = page;
+ return 0;
+}
- /*
- * We need to make the page accessible if and only if we are going
- * to access its content (the FOLL_PIN case). Please see
- * Documentation/core-api/pin_user_pages.rst for details.
- */
- if (flags & FOLL_PIN) {
- ret = arch_make_folio_accessible(folio);
- if (ret) {
- unpin_user_page(page);
- page = ERR_PTR(ret);
- goto out;
+/*
+ * Return how many PTEs map consecutive pages of the same folio and can be
+ * committed as one run. Always at least 1.
+ *
+ * The write-fault and unshare checks in gup_lookup_pte() are per PTE, but a
+ * writable run needs no repeat: a writable anon page is exclusive. A read-only
+ * run under FOLL_WRITE or FOLL_PIN does need the per-page check, so it stays
+ * one page at a time.
+ */
+static unsigned long gup_pte_batch_len(struct vm_area_struct *vma,
+ unsigned long address, unsigned long walk_end,
+ struct folio *folio, pte_t *ptep, pte_t *batch_pte, unsigned int flags)
+{
+ unsigned long max;
+
+ if (!folio_test_large(folio))
+ return 1;
+ if (!pte_write(*batch_pte) && (flags & (FOLL_WRITE | FOLL_PIN)))
+ return 1;
+
+ max = (walk_end - address) >> PAGE_SHIFT;
+ if (max <= 1)
+ return 1;
+
+ /* Merge young/dirty across batch so folio_mark_dirty sees any dirty. */
+ return folio_pte_batch_flags(folio, vma, ptep, batch_pte, max,
+ FPB_RESPECT_WRITE | FPB_MERGE_YOUNG_DIRTY);
+}
+
+/*
+ * Walk the PTEs from the start address to the end of this page table or VMA,
+ * whichever comes first, and commit every page found.
+ *
+ * A failure on the first PTE is returned to the caller. A failure after that
+ * is a short read; __get_user_pages() retrying the read will get the error.
+ *
+ * Return: the number of pages stored in @pages, 0 when no mapping exists at
+ * the start address, or a negative errno for a failure on the first PTE.
+ */
+static long follow_page_pte(struct vm_area_struct *vma,
+ unsigned long address, unsigned long end, pmd_t *pmd,
+ unsigned int flags, struct page **pages)
+{
+ struct mm_struct *mm = vma->vm_mm;
+ bool need_no_page_table = false;
+ pte_t *ptep, *orig_ptep;
+ unsigned long walk_end, base;
+ unsigned long nr = 0;
+ spinlock_t *ptl;
+ long ret = 0;
+
+ orig_ptep = ptep = pte_offset_map_lock(mm, pmd, address, &ptl);
+ if (!ptep)
+ return no_page_table(vma, flags, address);
+
+ base = address;
+ walk_end = min(pmd_addr_end(address, end), vma->vm_end);
+
+ for (; address < walk_end; address += PAGE_SIZE, ptep++) {
+ pte_t pte = ptep_get(ptep);
+ struct folio *folio;
+ struct page *page;
+ unsigned long batch;
+ pte_t batch_pte;
+
+ ret = gup_lookup_pte(vma, address, ptep, pte, flags, &page);
+ if (ret || !page) {
+ /*
+ * no_page_table() may look up the page cache, so it
+ * cannot run under the PTE lock. A none PTE returns
+ * from gup_lookup_pte() before any write check runs,
+ * so this is the same call the old code made -- not a
+ * new failure mode for FOLL_WRITE.
+ */
+ if (!ret && pte_none(pte))
+ need_no_page_table = true;
+ break;
}
- }
- if (flags & FOLL_TOUCH) {
- if ((flags & FOLL_WRITE) &&
- !pte_dirty(pte) && !folio_test_dirty(folio))
- folio_mark_dirty(folio);
+ folio = page_folio(page);
+ batch_pte = pte;
+
+ batch = gup_pte_batch_len(vma, address, walk_end, folio,
+ ptep, &batch_pte, flags);
+ ret = gup_grab_folio_pages(folio, page, batch,
+ pte_dirty(batch_pte), flags,
+ pages ? pages + nr : NULL);
+ if (ret)
+ break;
+ nr += batch;
/*
- * pte_mkyoung() would be more correct here, but atomic care
- * is needed to avoid losing the dirty bit: it is easier to use
- * folio_mark_accessed().
+ * The loop's own increment covers one PTE; skip
+ * the rest of the batch.
*/
- folio_mark_accessed(folio);
+ ptep += batch - 1;
+ address += (batch - 1) * PAGE_SIZE;
}
-out:
- pte_unmap_unlock(ptep, ptl);
- return page;
-no_page:
- pte_unmap_unlock(ptep, ptl);
- if (!pte_none(pte))
- return NULL;
- return no_page_table(vma, flags, address);
+ pte_unmap_unlock(orig_ptep, ptl);
+
+ if (nr) {
+ gup_flush_pages(vma, base, pages, nr);
+ return nr;
+ }
+ if (need_no_page_table)
+ return no_page_table(vma, flags, address);
+ return ret;
}
-static struct page *follow_pmd_mask(struct vm_area_struct *vma,
- unsigned long address, pud_t *pudp,
- unsigned int flags,
- unsigned long *page_mask)
+static long follow_pmd_mask(struct vm_area_struct *vma,
+ unsigned long address, unsigned long end, pud_t *pudp,
+ unsigned int flags, struct page **pages)
{
pmd_t *pmd, pmdval;
spinlock_t *ptl;
- struct page *page;
+ long ret;
struct mm_struct *mm = vma->vm_mm;
pmd = pmd_offset(pudp, address);
@@ -912,7 +1060,7 @@ static struct page *follow_pmd_mask(struct vm_area_struct *vma,
if (!pmd_present(pmdval))
return no_page_table(vma, flags, address);
if (likely(!pmd_leaf(pmdval)))
- return follow_page_pte(vma, address, pmd, flags);
+ return follow_page_pte(vma, address, end, pmd, flags, pages);
if (pmd_protnone(pmdval) && !gup_can_follow_protnone(vma, flags))
return no_page_table(vma, flags, address);
@@ -925,28 +1073,35 @@ static struct page *follow_pmd_mask(struct vm_area_struct *vma,
}
if (unlikely(!pmd_leaf(pmdval))) {
spin_unlock(ptl);
- return follow_page_pte(vma, address, pmd, flags);
+ return follow_page_pte(vma, address, end, pmd, flags, pages);
}
if (pmd_trans_huge(pmdval) && (flags & FOLL_SPLIT_PMD)) {
spin_unlock(ptl);
split_huge_pmd(vma, pmd, address);
/* If pmd was left empty, stuff a page table in there quickly */
- return pte_alloc(mm, pmd) ? ERR_PTR(-ENOMEM) :
- follow_page_pte(vma, address, pmd, flags);
+ return pte_alloc(mm, pmd) ? -ENOMEM :
+ follow_page_pte(vma, address, end, pmd, flags, pages);
}
- page = follow_huge_pmd(vma, address, pmd, flags, page_mask);
+ ret = follow_huge_pmd(vma, address, end, pmd, flags, pages);
spin_unlock(ptl);
- return page;
+
+ /*
+ * The ref is already held, so the page cannot go away: fill the
+ * array and flush caches without the pmd lock.
+ */
+ if (ret > 0 && pages)
+ gup_fill_pages(vma, address, pages[0], ret, pages);
+
+ return ret;
}
-static struct page *follow_pud_mask(struct vm_area_struct *vma,
- unsigned long address, p4d_t *p4dp,
- unsigned int flags,
- unsigned long *page_mask)
+static long follow_pud_mask(struct vm_area_struct *vma,
+ unsigned long address, unsigned long end, p4d_t *p4dp,
+ unsigned int flags, struct page **pages)
{
pud_t *pudp, pud;
spinlock_t *ptl;
- struct page *page;
+ long ret;
struct mm_struct *mm = vma->vm_mm;
pudp = pud_offset(p4dp, address);
@@ -955,22 +1110,29 @@ static struct page *follow_pud_mask(struct vm_area_struct *vma,
return no_page_table(vma, flags, address);
if (pud_leaf(pud)) {
ptl = pud_lock(mm, pudp);
- page = follow_huge_pud(vma, address, pudp, flags, page_mask);
+ ret = follow_huge_pud(vma, address, end, pudp, flags, pages);
spin_unlock(ptl);
- if (page)
- return page;
+ /*
+ * The ref is already held, so the page cannot go away: fill
+ * the array and flush caches without the lock. A 1 GB folio
+ * can be up to HPAGE_PUD_NR pages, too long to flush under a
+ * spinlock.
+ */
+ if (ret > 0 && pages)
+ gup_fill_pages(vma, address, pages[0], ret, pages);
+ if (ret)
+ return ret;
return no_page_table(vma, flags, address);
}
if (unlikely(pud_bad(pud)))
return no_page_table(vma, flags, address);
- return follow_pmd_mask(vma, address, pudp, flags, page_mask);
+ return follow_pmd_mask(vma, address, end, pudp, flags, pages);
}
-static struct page *follow_p4d_mask(struct vm_area_struct *vma,
- unsigned long address, pgd_t *pgdp,
- unsigned int flags,
- unsigned long *page_mask)
+static long follow_p4d_mask(struct vm_area_struct *vma,
+ unsigned long address, unsigned long end, pgd_t *pgdp,
+ unsigned int flags, struct page **pages)
{
p4d_t *p4dp, p4d;
@@ -981,15 +1143,18 @@ static struct page *follow_p4d_mask(struct vm_area_struct *vma,
if (!p4d_present(p4d) || p4d_bad(p4d))
return no_page_table(vma, flags, address);
- return follow_pud_mask(vma, address, p4dp, flags, page_mask);
+ return follow_pud_mask(vma, address, end, p4dp, flags, pages);
}
/**
- * follow_page_mask - look up a page descriptor from a user-virtual address
+ * follow_page_mask - look up pages at a user-virtual address
* @vma: vm_area_struct mapping @address
* @address: virtual address to look up
+ * @end: virtual address at which to stop batching contiguous pages
* @flags: flags modifying lookup behaviour
- * @page_mask: a pointer to output page_mask
+ * @pages: array to receive the pages, refcounted per @flags, or NULL to
+ * walk the page tables (e.g. to fault pages in) without collecting
+ * or refcounting them
*
* @flags can have FOLL_ flags set, defined in <linux/mm.h>
*
@@ -998,33 +1163,32 @@ static struct page *follow_p4d_mask(struct vm_area_struct *vma,
* trigger a fault with FAULT_FLAG_UNSHARE set. Note that unsharing is only
* relevant with FOLL_PIN and !FOLL_WRITE.
*
- * On output, @page_mask is set according to the size of the page.
- *
- * Return: the mapped (struct page *), %NULL if no mapping exists, or
- * an error pointer if there is a mapping to something not represented
- * by a page descriptor (see also vm_normal_page()).
+ * Return: the number of contiguous pages starting at @address that were
+ * placed into @pages (if non-NULL), which may be fewer than the pages
+ * requested via @end; 0 if no mapping exists at @address; or a negative
+ * errno for a mapping to something not represented by a page descriptor
+ * (see also vm_normal_page()).
*/
-static struct page *follow_page_mask(struct vm_area_struct *vma,
- unsigned long address, unsigned int flags,
- unsigned long *page_mask)
+static long follow_page_mask(struct vm_area_struct *vma,
+ unsigned long address, unsigned long end,
+ unsigned int flags, struct page **pages)
{
pgd_t *pgd;
struct mm_struct *mm = vma->vm_mm;
- struct page *page;
+ long ret;
vma_pgtable_walk_begin(vma);
- *page_mask = 0;
pgd = pgd_offset(mm, address);
if (pgd_none(*pgd) || unlikely(pgd_bad(*pgd)))
- page = no_page_table(vma, flags, address);
+ ret = no_page_table(vma, flags, address);
else
- page = follow_p4d_mask(vma, address, pgd, flags, page_mask);
+ ret = follow_p4d_mask(vma, address, end, pgd, flags, pages);
vma_pgtable_walk_end(vma);
- return page;
+ return ret;
}
static int get_gate_page(struct mm_struct *mm, unsigned long address,
@@ -1358,7 +1522,6 @@ static long __get_user_pages(struct mm_struct *mm,
{
long ret = 0, i = 0;
struct vm_area_struct *vma = NULL;
- unsigned long page_mask = 0;
if (!nr_pages)
return 0;
@@ -1373,7 +1536,7 @@ static long __get_user_pages(struct mm_struct *mm,
do {
struct page *page;
- unsigned int page_increm;
+ long nr;
/* first iteration or cross vma bound */
if (!vma || start >= vma->vm_end) {
@@ -1400,8 +1563,12 @@ static long __get_user_pages(struct mm_struct *mm,
pages ? &page : NULL);
if (ret)
goto out;
- page_mask = 0;
- goto next_page;
+ gup_fill_pages(vma, start, page, 1,
+ pages ? pages + i : NULL);
+ i++;
+ start += PAGE_SIZE;
+ nr_pages--;
+ continue;
}
if (!vma) {
@@ -1423,10 +1590,11 @@ static long __get_user_pages(struct mm_struct *mm,
}
cond_resched();
- page = follow_page_mask(vma, start, gup_flags, &page_mask);
- if (!page || PTR_ERR(page) == -EMLINK) {
+ nr = follow_page_mask(vma, start, start + nr_pages * PAGE_SIZE,
+ gup_flags, pages ? &pages[i] : NULL);
+ if (!nr || nr == -EMLINK) {
ret = faultin_page(vma, start, gup_flags,
- PTR_ERR(page) == -EMLINK, locked);
+ nr == -EMLINK, locked);
switch (ret) {
case 0:
goto retry;
@@ -1440,70 +1608,30 @@ static long __get_user_pages(struct mm_struct *mm,
goto out;
}
BUG();
- } else if (PTR_ERR(page) == -EEXIST) {
+ } else if (nr == -EEXIST) {
/*
* Proper page table entry exists, but no corresponding
* struct page. If the caller expects **pages to be
* filled in, bail out now, because that can't be done
- * for this page.
+ * for this page. Otherwise advance by the one page
+ * follow_page_mask() looked at.
*/
if (pages) {
- ret = PTR_ERR(page);
+ ret = nr;
goto out;
}
- } else if (IS_ERR(page)) {
- ret = PTR_ERR(page);
+ nr = 1;
+ } else if (nr < 0) {
+ ret = nr;
goto out;
}
-next_page:
- page_increm = 1 + (~(start >> PAGE_SHIFT) & page_mask);
- if (page_increm > nr_pages)
- page_increm = nr_pages;
-
- if (pages) {
- struct page *subpage;
- unsigned int j;
-
- /*
- * This must be a large folio (and doesn't need to
- * be the whole folio; it can be part of it), do
- * the refcount work for all the subpages too.
- *
- * NOTE: here the page may not be the head page
- * e.g. when start addr is not thp-size aligned.
- * try_grab_folio() should have taken care of tail
- * pages.
- */
- if (page_increm > 1) {
- struct folio *folio = page_folio(page);
-
- /*
- * Since we already hold refcount on the
- * large folio, this should never fail.
- */
- if (try_grab_folio(folio, page_increm - 1,
- gup_flags)) {
- /*
- * Release the 1st page ref if the
- * folio is problematic, fail hard.
- */
- gup_put_folio(folio, 1, gup_flags);
- ret = -EFAULT;
- goto out;
- }
- }
- for (j = 0; j < page_increm; j++) {
- subpage = page + j;
- pages[i + j] = subpage;
- flush_anon_page(vma, subpage, start + j * PAGE_SIZE);
- flush_dcache_page(subpage);
- }
- }
+ /* Check that we didn't pin more pages than the caller will free. */
+ VM_WARN_ON_ONCE(nr > nr_pages);
- i += page_increm;
- start += page_increm * PAGE_SIZE;
- nr_pages -= page_increm;
+ i += nr;
+ start += nr * PAGE_SIZE;
+ nr_pages -= nr;
} while (nr_pages);
out:
return i ? i : ret;
|
| 39/3 | 2026/11/03 13:04 | llm | kmsan-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 11607 output: 295 thoughts: 2699 Thoughts: **KMSAN Evaluation: No Dedicated Session Warranted** Okay, here's my assessment of this patch. My primary goal is to determine if it introduces any risks that *only* KMSAN could detect, given KMSAN is resource-intensive. Let's dig in. The core of this patch modifies `mm/gup.c`, specifically how page table walks are performed within the `get_user_pages` family of functions. It's refactoring the code to batch contiguous PTEs and huge PMD/PUD lookups to improve performance, rather than processing individual pages in a loop. New helper functions like `gup_fill_pages`, `gup_flush_pages`, and `gup_grab_folio_pages` are introduced, and existing functions such as `follow_page_pte` and others are significantly refactored. I’ve meticulously checked for any uninitialized memory concerns. All local variables within these modified and newly introduced functions are properly initialized before use. The code always sets variables before reading them. I traced how the `pages` array is handled. This is an array of `struct page *` pointers supplied by the caller, or a NULL pointer. If non-NULL, the code carefully fills this array with valid `struct page *` pointers, up to the calculated `nr` (number of pages). At no point does the patch introduce, read, or return uninitialized stack or heap data. Crucially, this patch *doesn't* involve copying any data to user space. It’s internal to kernel memory management, operating on page table metadata and `struct page` / `struct folio` structures. No kernel-to-user memory transfers are involved. The key distinction is between KASAN and KMSAN. Standard KASAN is already enabled, and it's excellent at catching out-of-bounds accesses, use-after-free conditions, double frees, and memory corruption. KMSAN, on the other hand, *only* detects reads of uninitialized memory (stack, heap, or page allocations) and potential kernel-to-user memory information leaks. Given that this patch primarily involves refactoring page table walks and batching lookups, any potential errors would most likely manifest as out-of-bounds accesses, incorrect calculations, or reference count imbalances. KASAN is the tool for these issues. KMSAN doesn't have a role here. I believe a KMSAN fuzzing session isn't necessary. I'm confident in setting `NeedsKMSAN=false`. My analysis indicates no KMSAN-specific vulnerabilities are introduced or exposed. |
| 40/3 | 2026/11/03 13:06 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch refactors the GUP (get_user_pages) slow path in mm/gup.c to support batched PTE and huge PMD/PUD lookups and folio pinning (introducing helpers like gup_grab_folio_pages, gup_lookup_pte, gup_pte_batch_len, gup_fill_pages, and updating follow_page_pte / follow_page_mask).\n\nNo uninitialized memory hazards are introduced or exposed:\n1. No structures are copied to user space, so there is no risk of kernel info-leaks.\n2. All local variables and pointers (e.g. `nr`, `need_no_page_table`, `ret`, `off`, `pagep`) are strictly initialized or unconditionally assigned prior to read or branch operations.\n3. The caller-provided `pages` array is populated with valid `struct page *` pointers for all `nr` pages returned.\n4. Any potential bugs in batch length calculations or index offsets would manifest as out-of-bounds accesses on the `pages` array, incorrect refcounts, or locking errors, all of which are caught by KASAN, LOCKDEP, or standard kernel debug assertions.\n\nTherefore, dedicated KMSAN fuzzing is not justified.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch refactors the GUP (get_user_pages) slow path in mm/gup.c to support batched PTE and huge PMD/PUD lookups and folio pinning (introducing helpers like gup_grab_folio_pages, gup_lookup_pte, gup_pte_batch_len, gup_fill_pages, and updating follow_page_pte / follow_page_mask).\n\nNo uninitialized memory hazards are introduced or exposed:\n1. No structures are copied to user space, so there is no risk of kernel info-leaks.\n2. All local variables and pointers (e.g. `nr`, `need_no_page_table`, `ret`, `off`, `pagep`) are strictly initialized or unconditionally assigned prior to read or branch operations.\n3. The caller-provided `pages` array is populated with valid `struct page *` pointers for all `nr` pages returned.\n4. Any potential bugs in batch length calculations or index offsets would manifest as out-of-bounds accesses on the `pages` array, incorrect refcounts, or locking errors, all of which are caught by KASAN, LOCKDEP, or standard kernel debug assertions.\n\nTherefore, dedicated KMSAN fuzzing 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) |
|---|