FAILED: patch "[PATCH] mm/madvise: use vm_normal_folio_pmd() in cold/pageout PMD range" failed to apply to 6.12-stable tree
Subsystems (3)
Sasha Levin
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x 0bd719cb607ef14bcd554e044bbd80dd901b9996
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.12.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 0bd719cb607ef14bcd554e044bbd80dd901b9996 Mon Sep 17 00:00:00 2001
From: Gregory Price <[email protected]>
Date: Sat, 26 Sep 2026 06:51:10 -0400
Subject: [PATCH] mm/madvise: use vm_normal_folio_pmd() in cold/pageout PMD
range
mmap a VM_MIXEDMAP region whose ->huge_fault installs a PMD through vmf_insert_pfn_pmd() - mshv_vtl_low does this, and needs CAP_SYS_ADMIN to open - then:
madvise(p, PMD_SIZE, MADV_PAGEOUT);
With a stand-in module for the driver:
BUG: unable to handle page fault for address: fffff587c0000008 RIP: 0010:madvise_cold_or_pageout_pte_range+0x410/0x9b0 walk_pgd_range+0x52b/0xaf0 __walk_page_range+0x6a/0x1d0 walk_page_range_vma_unsafe+0x8e/0x120 madvise_pageout+0xb2/0x180 madvise_vma_behavior+0x46b/0xa90 do_madvise+0x108/0x190 __x64_sys_madvise+0x26/0x30
Nothing validates the pfn on the way in:
can_madv_lru_vma() rejects VM_PFNMAP, but not VM_MIXEDMAP can_fault() *pfn = vmf->pgoff & ~(mask >> PAGE_SHIFT); vmf_insert_pfn_pmd() no pfn_valid() check pmd_folio() pfn_to_page() -> unpopulated vmemmap
Even with a valid pfn the path is wrong. The mapping carries no rmap, so folio_maybe_mapped_shared() sees mapcount 0, and the walker goes on to folio_deactivate(), or folio_isolate_lru() plus reclaim_pages(), against a folio this mapping does not own.
Use vm_normal_folio_pmd() and skip on NULL, as the PTE half of this same walker already does with vm_normal_folio(). This also filters the huge zero PMD, so its separate check is no longer needed.
--- mm/madvise.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
mm/madvise.c +3 -4
@@ -394,16 +394,15 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,return 0 ; orig_pmd = *pmd; -if (is_huge_zero_pmd (orig_pmd)) - goto huge_unlock; -if (unlikely (!pmd_present (orig_pmd))) {VM_WARN_ON_ONCE (!pmd_is_migration_entry (orig_pmd) && !pmd_is_device_private_entry (orig_pmd)); goto huge_unlock; } - folio =pmd_folio (orig_pmd); + folio =vm_normal_folio_pmd (vma, addr, orig_pmd); +if (!folio) + goto huge_unlock;if (folio_is_zone_device (folio)) goto huge_unlock;
Signature · 1 line
2.53.0