Re: [PATCH 1/1] mm/huge_memory: fix pgtable withdrawal for huge zero PMDs
From: David Hildenbrand (Arm)
Date: Tue Sep 15 2026 - 11:13:51 EST
On 9/13/26 07:19, Lance Yang wrote:
> From: Lance Yang <lance.yang@xxxxxxxxx>
>
> has_deposited_pgtable() uses !vma_is_dax() to decide whether a huge zero
> PMD has a deposited PTE page table. That also accepts raw PFN mappings
> of huge_zero_pfn, although vmf_insert_pfn_pmd() does not deposit a page
> table on x86.
>
> Zapping such a mapping would call pgtable_trans_huge_withdraw() without
> a corresponding deposit. With pmd_huge_pte(mm, pmd) == NULL, that causes
> a NULL pointer dereference.
>
> Use vma_is_anonymous() for the huge zero PMD check. This matches how PTE
> page tables are allocated, deposited and moved.
>
> - For anonymous page faults that install a huge zero PMD,
> do_huge_pmd_anonymous_page() allocates a PTE page table and
> set_huge_zero_folio() deposits it before installing the PMD.
>
> - On fork, copy_huge_pmd() allocates and deposits a PTE page table when
> copying a huge zero PMD into an anonymous VMA.
>
> - Raw PFN mappings use vmf_insert_pfn_pmd(), and DAX file holes use
> vmf_insert_folio_pmd() to map the huge zero folio. Both use insert_pmd(),
> which deposits a PTE page table only when arch_needs_pgtable_deposit()
> requires it.
>
> - Moving an anonymous huge PMD preserves its deposited PTE page table.
> move_huge_pmd() transfers the deposit when necessary. For UFFD MOVE,
> both VMAs must be anonymous, and move_pages_huge_pmd() transfers the
> deposit as well.
>
> Keep arch_needs_pgtable_deposit() first so architectures that require a
> deposited PTE page table still return true regardless of the VMA type.
>
> Commit d80a9cb1a64a ("mm/huge_memory: add and use
> normal_or_softleaf_folio_pmd()") removed the vma_is_special_huge() check
> in zap_huge_pmd(). That check skipped the huge zero PMD deposit test for
> non-DAX VM_PFNMAP and VM_MIXEDMAP mappings. Removing it exposed these
> mappings to the incorrect !vma_is_dax() test.
>
> Fixes: d80a9cb1a64a ("mm/huge_memory: add and use normal_or_softleaf_folio_pmd()")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Lance Yang <lance.yang@xxxxxxxxx>
> ---
> mm/huge_memory.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 6895b38e4704..0ed997a97416 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -2529,11 +2529,11 @@ static bool has_deposited_pgtable(struct vm_area_struct *vma, pmd_t pmdval,
> return true;
>
> /*
> - * Huge zero always deposited except for DAX which handles itself, see
> - * set_huge_zero_folio().
> + * Huge zero PMDs have a deposited page table only for anonymous VMAs,
> + * see set_huge_zero_folio().
> */
> if (is_huge_zero_pmd(pmdval))
> - return !vma_is_dax(vma);
> + return vma_is_anonymous(vma);
>
> /*
> * Otherwise, only anonymous folios are deposited, see
Ok, it's really only DAX and anonymous VMAs that use the huge zero folio. Other
(module) code would have a hard time using it, as mm_get_huge_zero_folio() is
not exported to modules.
DAX uses dax_pmd_load_hole()->vmf_insert_folio_pmd()->insert_pmd() where we
deposit a page table only if arch_needs_pgtable_deposit().
So I think the rule is simply:
arch_needs_pgtable_deposit() -> always deposited
vma_is_anonymous() -> always deposited
?
The trick is that we don't have anon THPs in non-anon VMAs.
So could this be simplified further or am I missing something?
--
Cheers,
David