* FAILED: patch "[PATCH] mm/khugepaged: don't map folios that are not uptodate in" failed to apply to 6.6-stable tree
@ 2026-12-02 16:10 gregkh
2026-12-04 3:59 ` [PATCH 6.6.y 1/2] mm/khugepaged: convert collapse_pte_mapped_thp() to use folios Sasha Levin
0 siblings, 1 reply; 3+ messages in thread
From: gregkh @ 2026-12-02 16:10 UTC (permalink / raw)
To: david, baolin.wang, hughd, kas, lance.yang, ljs, mason, pfalcato,
sj, ziy, zokeefe
Cc: stable
The patch below does not apply to the 6.6-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 <stable@vger.kernel.org>.
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.6.y
git checkout FETCH_HEAD
git cherry-pick -x 043a2260b96ffc13121a1dd65282e67eb2e1d8a8
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2026120201-basis-idiom-f1a8@gregkh' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 043a2260b96ffc13121a1dd65282e67eb2e1d8a8 Mon Sep 17 00:00:00 2001
From: "David Hildenbrand (Arm)" <david@kernel.org>
Date: Thu, 5 Nov 2026 19:16:44 +0100
Subject: [PATCH] mm/khugepaged: don't map folios that are not uptodate in
MADV_COLLAPSE
madvise(MADV_COLLAPSE) can map PMD-sized pagecache folios that are not
uptodate. For example, shmem fallocate() can put such folios into the
page cache.
collapse_file() already refuses to proceed with folios that are not
uptodate. Let's just do the same in try_collapse_pte_mapped_thp() and skip
such folios, leaving handling to the page faults.
Note that collapse_file() effectively clears shmem folios through
shmem_get_folio(); let's keep this fix simple and simply let the page
fault path deal with that.
Fixes: 34488399fa08 ("mm/madvise: add file and shmem support to MADV_COLLAPSE")
Reported-by: Chris Mason <mason@kernel.org>
Cc: stable@vger.kernel.org
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Acked-by: Hugh Dickins <hughd@google.com>
Acked-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Zach O'Keefe <zokeefe@google.com>
Reviewed-by: SJ Park <sj@kernel.org>
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Reviewed-by: Lance Yang <lance.yang@linux.dev>
Reviewed-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
Link: https://patch.msgid.link/20261105-set_huge_pmd_uptodate-v1-1-a78d8a1b7117@kernel.org
Reviewed-by: Pedro Falcato <pfalcato@suse.de>
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index 4bbe319ef86f..964f78c3856b 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -1888,6 +1888,12 @@ static enum scan_result try_collapse_pte_mapped_thp(struct mm_struct *mm, unsign
goto drop_folio;
}
+ /* Leave any uninitialized folios to the page fault path. */
+ if (!folio_test_uptodate(folio)) {
+ result = SCAN_FAIL;
+ goto drop_folio;
+ }
+
result = find_pmd_or_thp_or_none(mm, haddr, &pmd);
switch (result) {
case SCAN_SUCCEED:
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 6.6.y 1/2] mm/khugepaged: convert collapse_pte_mapped_thp() to use folios 2026-12-02 16:10 FAILED: patch "[PATCH] mm/khugepaged: don't map folios that are not uptodate in" failed to apply to 6.6-stable tree gregkh @ 2026-12-04 3:59 ` Sasha Levin 2026-12-04 3:59 ` [PATCH 6.6.y 2/2] mm/khugepaged: don't map folios that are not uptodate in MADV_COLLAPSE Sasha Levin 0 siblings, 1 reply; 3+ messages in thread From: Sasha Levin @ 2026-12-04 3:59 UTC (permalink / raw) To: stable Cc: Vishal Moola (Oracle), Rik van Riel, Yang Shi, Kefeng Wang, Matthew Wilcox (Oracle), Andrew Morton, Sasha Levin From: "Vishal Moola (Oracle)" <vishal.moola@gmail.com> [ Upstream commit 98b32d296d95d7aa0516c36b72406277412268cd ] This removes 2 calls to compound_head() and helps convert khugepaged to use folios throughout. Previously, if the address passed to collapse_pte_mapped_thp() corresponded to a tail page, the scan would fail immediately. Using filemap_lock_folio() we get the corresponding folio back and try to operate on the folio instead. Link: https://lkml.kernel.org/r/20231020183331.10770-6-vishal.moola@gmail.com Signed-off-by: Vishal Moola (Oracle) <vishal.moola@gmail.com> Reviewed-by: Rik van Riel <riel@surriel.com> Reviewed-by: Yang Shi <shy828301@gmail.com> Cc: Kefeng Wang <wangkefeng.wang@huawei.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Stable-dep-of: 043a2260b96f ("mm/khugepaged: don't map folios that are not uptodate in MADV_COLLAPSE") Signed-off-by: Sasha Levin <sashal@kernel.org> --- mm/khugepaged.c | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 2eae83f34c76c..a870ed3d6b98d 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1475,7 +1475,7 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr, bool notified = false; unsigned long haddr = addr & HPAGE_PMD_MASK; struct vm_area_struct *vma = vma_lookup(mm, haddr); - struct page *hpage; + struct folio *folio; pte_t *start_pte, *pte; pmd_t *pmd, pgt_pmd; spinlock_t *pml = NULL, *ptl; @@ -1508,19 +1508,14 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr, if (userfaultfd_wp(vma)) return SCAN_PTE_UFFD_WP; - hpage = find_lock_page(vma->vm_file->f_mapping, + folio = filemap_lock_folio(vma->vm_file->f_mapping, linear_page_index(vma, haddr)); - if (!hpage) + if (IS_ERR(folio)) return SCAN_PAGE_NULL; - if (!PageHead(hpage)) { - result = SCAN_FAIL; - goto drop_hpage; - } - - if (compound_order(hpage) != HPAGE_PMD_ORDER) { + if (folio_order(folio) != HPAGE_PMD_ORDER) { result = SCAN_PAGE_COMPOUND; - goto drop_hpage; + goto drop_folio; } result = find_pmd_or_thp_or_none(mm, haddr, &pmd); @@ -1534,13 +1529,13 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr, */ goto maybe_install_pmd; default: - goto drop_hpage; + goto drop_folio; } result = SCAN_FAIL; start_pte = pte_offset_map_lock(mm, pmd, haddr, &ptl); if (!start_pte) /* mmap_lock + page lock should prevent this */ - goto drop_hpage; + goto drop_folio; /* step 1: check all mapped PTEs are to the right huge page */ for (i = 0, addr = haddr, pte = start_pte; @@ -1565,7 +1560,7 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr, * Note that uprobe, debugger, or MAP_PRIVATE may change the * page table, but the new page will not be a subpage of hpage. */ - if (hpage + i != page) + if (folio_page(folio, i) != page) goto abort; } @@ -1580,7 +1575,7 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr, * page_table_lock) ptl nests inside pml. The less time we hold pml, * the better; but userfaultfd's mfill_atomic_pte() on a private VMA * inserts a valid as-if-COWed PTE without even looking up page cache. - * So page lock of hpage does not protect from it, so we must not drop + * So page lock of folio does not protect from it, so we must not drop * ptl before pgt_pmd is removed, so uffd private needs pml taken now. */ if (userfaultfd_armed(vma) && !(vma->vm_flags & VM_SHARED)) @@ -1604,7 +1599,7 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr, continue; /* * We dropped ptl after the first scan, to do the mmu_notifier: - * page lock stops more PTEs of the hpage being faulted in, but + * page lock stops more PTEs of the folio being faulted in, but * does not stop write faults COWing anon copies from existing * PTEs; and does not stop those being swapped out or migrated. */ @@ -1613,7 +1608,7 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr, goto abort; } page = vm_normal_page(vma, addr, ptent); - if (hpage + i != page) + if (folio_page(folio, i) != page) goto abort; /* @@ -1633,8 +1628,8 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr, /* step 3: set proper refcount and mm_counters. */ if (nr_ptes) { - page_ref_sub(hpage, nr_ptes); - add_mm_counter(mm, mm_counter_file(hpage), -nr_ptes); + folio_ref_sub(folio, nr_ptes); + add_mm_counter(mm, mm_counter_file(&folio->page), -nr_ptes); } /* step 4: remove empty page table */ @@ -1658,14 +1653,14 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr, maybe_install_pmd: /* step 5: install pmd entry */ result = install_pmd - ? set_huge_pmd(vma, haddr, pmd, hpage) + ? set_huge_pmd(vma, haddr, pmd, &folio->page) : SCAN_SUCCEED; - goto drop_hpage; + goto drop_folio; abort: if (nr_ptes) { flush_tlb_mm(mm); - page_ref_sub(hpage, nr_ptes); - add_mm_counter(mm, mm_counter_file(hpage), -nr_ptes); + folio_ref_sub(folio, nr_ptes); + add_mm_counter(mm, mm_counter_file(&folio->page), -nr_ptes); } if (start_pte) pte_unmap_unlock(start_pte, ptl); @@ -1673,9 +1668,9 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr, spin_unlock(pml); if (notified) mmu_notifier_invalidate_range_end(&range); -drop_hpage: - unlock_page(hpage); - put_page(hpage); +drop_folio: + folio_unlock(folio); + folio_put(folio); return result; } -- 2.53.0 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 6.6.y 2/2] mm/khugepaged: don't map folios that are not uptodate in MADV_COLLAPSE 2026-12-04 3:59 ` [PATCH 6.6.y 1/2] mm/khugepaged: convert collapse_pte_mapped_thp() to use folios Sasha Levin @ 2026-12-04 3:59 ` Sasha Levin 0 siblings, 0 replies; 3+ messages in thread From: Sasha Levin @ 2026-12-04 3:59 UTC (permalink / raw) To: stable Cc: David Hildenbrand (Arm), Chris Mason, Lorenzo Stoakes (ARM), Hugh Dickins, Zi Yan, Zach O'Keefe, SJ Park, Baolin Wang, Lance Yang, Kiryl Shutsemau (Meta), Pedro Falcato, Sasha Levin From: "David Hildenbrand (Arm)" <david@kernel.org> [ Upstream commit 043a2260b96ffc13121a1dd65282e67eb2e1d8a8 ] madvise(MADV_COLLAPSE) can map PMD-sized pagecache folios that are not uptodate. For example, shmem fallocate() can put such folios into the page cache. collapse_file() already refuses to proceed with folios that are not uptodate. Let's just do the same in try_collapse_pte_mapped_thp() and skip such folios, leaving handling to the page faults. Note that collapse_file() effectively clears shmem folios through shmem_get_folio(); let's keep this fix simple and simply let the page fault path deal with that. Fixes: 34488399fa08 ("mm/madvise: add file and shmem support to MADV_COLLAPSE") Reported-by: Chris Mason <mason@kernel.org> Cc: stable@vger.kernel.org Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org> Acked-by: Hugh Dickins <hughd@google.com> Acked-by: Zi Yan <ziy@nvidia.com> Reviewed-by: Zach O'Keefe <zokeefe@google.com> Reviewed-by: SJ Park <sj@kernel.org> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com> Reviewed-by: Lance Yang <lance.yang@linux.dev> Reviewed-by: Kiryl Shutsemau (Meta) <kas@kernel.org> Link: https://patch.msgid.link/20261105-set_huge_pmd_uptodate-v1-1-a78d8a1b7117@kernel.org Reviewed-by: Pedro Falcato <pfalcato@suse.de> Signed-off-by: David Hildenbrand (Arm) <david@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org> --- mm/khugepaged.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index a870ed3d6b98d..e2b7819ce36ed 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1518,6 +1518,12 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr, goto drop_folio; } + /* Leave any uninitialized folios to the page fault path. */ + if (!folio_test_uptodate(folio)) { + result = SCAN_FAIL; + goto drop_folio; + } + result = find_pmd_or_thp_or_none(mm, haddr, &pmd); switch (result) { case SCAN_SUCCEED: -- 2.53.0 ^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-04 3:59 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-12-02 16:10 FAILED: patch "[PATCH] mm/khugepaged: don't map folios that are not uptodate in" failed to apply to 6.6-stable tree gregkh 2026-12-04 3:59 ` [PATCH 6.6.y 1/2] mm/khugepaged: convert collapse_pte_mapped_thp() to use folios Sasha Levin 2026-12-04 3:59 ` [PATCH 6.6.y 2/2] mm/khugepaged: don't map folios that are not uptodate in MADV_COLLAPSE Sasha Levin
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox