Re: [PATCH v2 8/9] mm/rmap: re-enable discarding lazyfree THPs at PMD level
From: Liam R. Howlett
Date: Thu Dec 03 2026 - 23:37:20 EST
On 26/12/03 11:17PM, Zi Yan wrote:
> The patch "mm/rmap: don't discard lazyfree THPs at PMD level" disabled
Nit, the hash for the disabling patch would be useful here.
> the PMD-level discard, because it cleared the PMD before checking whether
> the folio could be discarded, and munmap() or mremap() could skip that
> transiently none PMD.
>
> __discard_anon_folio_pmd_locked() now keeps the PMD invalidated, not
> cleared, until the discard is committed, GUP-fast no longer follows an
> invalidated PMD on any architecture, powerpc page table check no longer
> counts an invalidated PMD as mapped, and sparc64 keeps thp_pte_count
> balanced when an invalidated PMD is set again or cleared. Discard lazyfree
> THPs at PMD level again.
>
> Also call update_hiwater_rss() before unmap_huge_pmd_locked(), as the
> PTE path does before lowering RSS. The PMD path has skipped it since the
> PMD-level discard was added in commit 735ecdfaf4e8 ("mm/vmscan: avoid
> split lazyfree THP during shrink_folio_list()"), so a discard could lower
> RSS without recording the high watermark first, and VmHWM could be
> under-reported.
>
> Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
> Closes: https://sashiko.dev/#/patchset/20261015-anon_vma_uaf_fix-v1-0-7b977303b42b%40nvidia.com?part=7
> Signed-off-by: Zi Yan <ziy@xxxxxxxxxx>
> To: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> To: David Hildenbrand <david@xxxxxxxxxx>
> To: Lorenzo Stoakes <ljs@xxxxxxxxxx>
> Cc: Rik van Riel <riel@xxxxxxxxxxx>
> Cc: "Liam R. Howlett" <liam@xxxxxxxxxxxxx>
> Cc: Vlastimil Babka <vbabka@xxxxxxxxxx>
> Cc: Harry Yoo <harry@xxxxxxxxxx>
> Cc: Jann Horn <jannh@xxxxxxxxxx>
> Cc: Lance Yang <lance.yang@xxxxxxxxx>
> Cc: Kyle Zeng <kylebot@xxxxxxxxxx>
> Cc: linux-mm@xxxxxxxxx
> Cc: linux-kernel@xxxxxxxxxxxxxxx
Acked-by: Liam R. Howlett (Google) <liam@xxxxxxxxxxxxx>
> ---
> mm/rmap.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/mm/rmap.c b/mm/rmap.c
> index f0c17d2e04847..32acae9efc313 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -2285,6 +2285,19 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,
> }
>
> if (!pvmw.pte) {
> + if (folio_test_lazyfree(folio)) {
> + /* Update high watermark before we lower rss */
> + update_hiwater_rss(mm);
> + if (unmap_huge_pmd_locked(vma, pvmw.address, pvmw.pmd, folio))
> + goto walk_done;
> + /*
> + * unmap_huge_pmd_locked has either already marked
> + * the folio as swap-backed or decided to retain it
> + * due to GUP or speculative references.
> + */
> + goto walk_abort;
> + }
> +
> if (flags & TTU_SPLIT_HUGE_PMD) {
> /*
> * We temporarily have to drop the PTL and
>
> --
> 2.53.0
>