mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 1/1] mm/huge_memory: simplify pgtable deposit detection
@ 2026-09-17  5:40 Lance Yang
  2026-09-17 14:24 ` Kiryl Shutsemau
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Lance Yang @ 2026-09-17  5:40 UTC (permalink / raw)
  To: akpm, david
  Cc: ziy, baolin.wang, liam, nico.pache, ryan.roberts, dev.jain,
	baohua, lance.yang, usama.arif, kas, linux-mm, linux-kernel

Whether a PMD has a deposited PTE page table only depends on whether the
architecture requires deposits or the VMA is anonymous.

Implement this rule directly in vma_has_deposited_pgtable(), avoiding
mistaking a non-anonymous raw PFN PMD for one with a deposit and attempting
to withdraw a page table that was never deposited.

Suggested-by: David Hildenbrand <david@kernel.org>
Signed-off-by: Lance Yang <lance.yang@linux.dev>
---
v1 -> v2:
 - Simplify the pgtable deposit check and rename the helper (per David) - thanks!
 - https://lore.kernel.org/linux-mm/20260913051942.40889-1-lance.yang@linux.dev

 mm/huge_memory.c | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)

diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 30b7c63b0e35..bfd972b997f9 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -2521,25 +2521,13 @@ static struct folio *normal_or_softleaf_folio_pmd(struct vm_area_struct *vma,
 	return pmd_to_softleaf_folio(pmdval);
 }
 
-static bool has_deposited_pgtable(struct vm_area_struct *vma, pmd_t pmdval,
-		struct folio *folio)
+static bool vma_has_deposited_pgtable(struct vm_area_struct *vma)
 {
-	/* Some architectures require unconditional depositing. */
-	if (arch_needs_pgtable_deposit())
-		return true;
-
-	/*
-	 * Huge zero always deposited except for DAX which handles itself, see
-	 * set_huge_zero_folio().
-	 */
-	if (is_huge_zero_pmd(pmdval))
-		return !vma_is_dax(vma);
-
 	/*
-	 * Otherwise, only anonymous folios are deposited, see
-	 * __do_huge_pmd_anonymous_page().
+	 * PMDs in anonymous VMAs always have a deposited page table. PMDs in
+	 * other VMAs only have one when required by the architecture.
 	 */
-	return folio && folio_test_anon(folio);
+	return arch_needs_pgtable_deposit() || vma_is_anonymous(vma);
 }
 
 /**
@@ -2579,7 +2567,7 @@ bool zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
 
 	is_present = pmd_present(orig_pmd);
 	folio = normal_or_softleaf_folio_pmd(vma, addr, orig_pmd, is_present);
-	has_deposit = has_deposited_pgtable(vma, orig_pmd, folio);
+	has_deposit = vma_has_deposited_pgtable(vma);
 	if (folio)
 		zap_huge_pmd_folio(mm, vma, orig_pmd, folio, is_present);
 	if (has_deposit)
-- 
2.39.3 (Apple Git-146)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/1] mm/huge_memory: simplify pgtable deposit detection
  2026-09-17  5:40 [PATCH v2 1/1] mm/huge_memory: simplify pgtable deposit detection Lance Yang
@ 2026-09-17 14:24 ` Kiryl Shutsemau
  2026-09-17 15:27 ` David Hildenbrand (Arm)
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Kiryl Shutsemau @ 2026-09-17 14:24 UTC (permalink / raw)
  To: Lance Yang
  Cc: akpm, david, ziy, baolin.wang, liam, nico.pache, ryan.roberts,
	dev.jain, baohua, usama.arif, linux-mm, linux-kernel

On Thu, Sep 17, 2026 at 01:40:15PM +0800, Lance Yang wrote:
> Whether a PMD has a deposited PTE page table only depends on whether the
> architecture requires deposits or the VMA is anonymous.
> 
> Implement this rule directly in vma_has_deposited_pgtable(), avoiding
> mistaking a non-anonymous raw PFN PMD for one with a deposit and attempting
> to withdraw a page table that was never deposited.
> 
> Suggested-by: David Hildenbrand <david@kernel.org>
> Signed-off-by: Lance Yang <lance.yang@linux.dev>

Reviewed-by: Kiryl Shutsemau (Meta) <kas@kernel.org>

-- 
  Kiryl Shutsemau / Kirill A. Shutemov

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/1] mm/huge_memory: simplify pgtable deposit detection
  2026-09-17  5:40 [PATCH v2 1/1] mm/huge_memory: simplify pgtable deposit detection Lance Yang
  2026-09-17 14:24 ` Kiryl Shutsemau
@ 2026-09-17 15:27 ` David Hildenbrand (Arm)
  2026-09-17 15:29 ` Zi Yan
  2026-09-17 23:13 ` Andrew Morton
  3 siblings, 0 replies; 5+ messages in thread
From: David Hildenbrand (Arm) @ 2026-09-17 15:27 UTC (permalink / raw)
  To: Lance Yang, akpm
  Cc: ziy, baolin.wang, liam, nico.pache, ryan.roberts, dev.jain,
	baohua, usama.arif, kas, linux-mm, linux-kernel

On 9/17/26 07:40, Lance Yang wrote:
> Whether a PMD has a deposited PTE page table only depends on whether the
> architecture requires deposits or the VMA is anonymous.
> 
> Implement this rule directly in vma_has_deposited_pgtable(), avoiding
> mistaking a non-anonymous raw PFN PMD for one with a deposit and attempting
> to withdraw a page table that was never deposited.
> 
> Suggested-by: David Hildenbrand <david@kernel.org>
> Signed-off-by: Lance Yang <lance.yang@linux.dev>
> ---

Acked-by: David Hildenbrand (Arm) <david@kernel.org>

-- 
Cheers,

David

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/1] mm/huge_memory: simplify pgtable deposit detection
  2026-09-17  5:40 [PATCH v2 1/1] mm/huge_memory: simplify pgtable deposit detection Lance Yang
  2026-09-17 14:24 ` Kiryl Shutsemau
  2026-09-17 15:27 ` David Hildenbrand (Arm)
@ 2026-09-17 15:29 ` Zi Yan
  2026-09-17 23:13 ` Andrew Morton
  3 siblings, 0 replies; 5+ messages in thread
From: Zi Yan @ 2026-09-17 15:29 UTC (permalink / raw)
  To: Lance Yang
  Cc: akpm, david, baolin.wang, liam, nico.pache, ryan.roberts,
	dev.jain, baohua, usama.arif, kas, linux-mm, linux-kernel

On 17 Sep 2026, at 1:40, Lance Yang wrote:

> Whether a PMD has a deposited PTE page table only depends on whether the
> architecture requires deposits or the VMA is anonymous.
>
> Implement this rule directly in vma_has_deposited_pgtable(), avoiding
> mistaking a non-anonymous raw PFN PMD for one with a deposit and attempting
> to withdraw a page table that was never deposited.
>
> Suggested-by: David Hildenbrand <david@kernel.org>
> Signed-off-by: Lance Yang <lance.yang@linux.dev>
> ---
> v1 -> v2:
>  - Simplify the pgtable deposit check and rename the helper (per David) - thanks!
>  - https://lore.kernel.org/linux-mm/20260913051942.40889-1-lance.yang@linux.dev
>
>  mm/huge_memory.c | 22 +++++-----------------
>  1 file changed, 5 insertions(+), 17 deletions(-)
>

LGTM.

Acked-by: Zi Yan <ziy@nvidia.com>

Best Regards,
Yan, Zi

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/1] mm/huge_memory: simplify pgtable deposit detection
  2026-09-17  5:40 [PATCH v2 1/1] mm/huge_memory: simplify pgtable deposit detection Lance Yang
                   ` (2 preceding siblings ...)
  2026-09-17 15:29 ` Zi Yan
@ 2026-09-17 23:13 ` Andrew Morton
  3 siblings, 0 replies; 5+ messages in thread
From: Andrew Morton @ 2026-09-17 23:13 UTC (permalink / raw)
  To: Lance Yang
  Cc: david, ziy, baolin.wang, liam, nico.pache, ryan.roberts,
	dev.jain, baohua, usama.arif, kas, linux-mm, linux-kernel

On Thu, 17 Sep 2026 13:40:15 +0800 Lance Yang <lance.yang@linux.dev> wrote:

> Whether a PMD has a deposited PTE page table only depends on whether the
> architecture requires deposits or the VMA is anonymous.
> 
> Implement this rule directly in vma_has_deposited_pgtable(), avoiding
> mistaking a non-anonymous raw PFN PMD for one with a deposit and attempting
> to withdraw a page table that was never deposited.

A large part of my life is asking $LLM "what are the userspace-visible
runtime effects of this bug".  Because NOBODY EVER TELLS ME!!!

This time it says "Processes using PMD-sized raw PFN mappings can
trigger a kernel NULL-pointer dereference when the mapping is torn
down", which sounds kinda important if true.

Help me out here?

Also, thanks ;)

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-09-17 23:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-17  5:40 [PATCH v2 1/1] mm/huge_memory: simplify pgtable deposit detection Lance Yang
2026-09-17 14:24 ` Kiryl Shutsemau
2026-09-17 15:27 ` David Hildenbrand (Arm)
2026-09-17 15:29 ` Zi Yan
2026-09-17 23:13 ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®