Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Eric Curtin" <ericcurtin17@gmail.com>
Cc: "Ryan Roberts" <ryan.roberts@arm.com>,
	"Catalin Marinas" <catalin.marinas@arm.com>,
	"Will Deacon" <will@kernel.org>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Aneesh Kumar K.V" <aneesh.kumar@kernel.org>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Nick Piggin" <npiggin@gmail.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Marc Zyngier" <maz@kernel.org>,
	"Oliver Upton" <oupton@kernel.org>,
	"Fuad Tabba" <fuad.tabba@linux.dev>,
	"Joey Gouly" <joey.gouly@arm.com>,
	"Steffen Eiden" <seiden@linux.ibm.com>,
	"Suzuki K Poulose" <suzuki.poulose@arm.com>,
	"Zenghui Yu" <yuzenghui@huawei.com>,
	linux-mm@kvack.org, kvmarm@lists.linux.dev
Subject: Re: [RFC PATCH v2 30/43] arm64: Support runtime folding of the pmd level
Date: Wed, 02 Dec 2026 02:34:50 +0000	[thread overview]
Message-ID: <sashiko-outbox-244690@kernel.org> (raw)
In-Reply-To: <20261201015240.1017259-31-ericcurtin17@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] arm64: mm: pud_bad() always returns false on 64K-page 3-level
  page tables
- [Low] arm64: mm: pmd_free() and __pmd_free_tlb() call virt_to_ptdesc()
  when folded
--

commit 9faa9f281977facf401ec8fc439354baf39f91d3
Author: Ryan Roberts <ryan.roberts@arm.com>

arm64: Support runtime folding of the pmd level

This commit adds pgtable_l3_enabled() and updates the page table manipulation
helpers, KVM stage-2 VMA size resolution, hugetlb, fixmap, KPTI, and ptdump
to support runtime folding of the PMD level.

> diff --git a/arch/arm64/include/asm/pgalloc.h b/arch/arm64/include/asm/pgalloc.h
> index 1b4509d3382c6..c79c7f43234b9 100644
> --- a/arch/arm64/include/asm/pgalloc.h
> +++ b/arch/arm64/include/asm/pgalloc.h
[ ... ]
> @@ -33,6 +35,17 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmdp)
>  	pudval |= (mm == &init_mm) ? PUD_TABLE_UXN : PUD_TABLE_PXN;
>  	__pud_populate(pudp, __pa(pmdp), pudval);
>  }
> +
> +static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
> +{
> +	struct ptdesc *ptdesc = virt_to_ptdesc(pmd);
> +
> +	if (!pgtable_l3_enabled())
> +		return;
> +
> +	BUG_ON((unsigned long)pmd & (PAGE_SIZE-1));
> +	pagetable_dtor_free(ptdesc);
> +}

[Severity: Low]
Should virt_to_ptdesc() be evaluated after checking pgtable_l3_enabled() here
and in __pmd_free_tlb()?

When the PMD level is folded at runtime and CONFIG_DEBUG_VIRTUAL is enabled,
calling virt_to_ptdesc() before the early return runs __virt_to_phys(), which
triggers a warning if pmd is a folded pointer into swapper_pg_dir in the
kernel image (such as via kasan_remove_zero_shadow() -> kasan_free_pmd()).

> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
> index a474c9fb485ad..c625fe7f84526 100644
> --- a/arch/arm64/include/asm/pgtable.h
> +++ b/arch/arm64/include/asm/pgtable.h
> @@ -760,12 +760,14 @@ static inline int pmd_trans_huge(pmd_t pmd)
>  }
>  #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
>  
> -#if defined(CONFIG_ARM64_64K_PAGES) || CONFIG_PGTABLE_LEVELS < 3
> -static inline bool pud_table(pud_t pud) { return true; }
> -#else
> -#define pud_table(pud)		((pud_val(pud) & PUD_TYPE_MASK) == \
> -				 PUD_TYPE_TABLE)
> -#endif
> +static inline bool pgtable_l3_enabled(void);
> +
> +static inline bool pud_table(pud_t pud)
> +{
> +	if (PAGE_SIZE == SZ_64K || !pgtable_l3_enabled())
> +		return true;
> +	return (pud_val(pud) & PUD_TYPE_MASK) == PUD_TYPE_TABLE;
> +}
[ ... ]
> @@ -824,22 +824,29 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd)
>  
>  #if CONFIG_PGTABLE_LEVELS > 2
>  
> -#define pud_none(pud)		(!pud_val(pud))
> -#define pud_bad(pud)		((pud_val(pud) & PUD_TYPE_MASK) != \
> -				 PUD_TYPE_TABLE)
> -#define pud_present(pud)	pte_present(pud_pte(pud))
> -#ifndef __PAGETABLE_PMD_FOLDED
> +static __always_inline bool pgtable_l3_enabled(void)
> +{
> +	return true;
> +}
> +
> +static inline bool mm_pmd_folded(const struct mm_struct *mm)
> +{
> +	return !pgtable_l3_enabled();
> +}
> +#define mm_pmd_folded  mm_pmd_folded
> +
> +#define pud_none(pud)		(pgtable_l3_enabled() && !pud_val(pud))
> +#define pud_bad(pud)		(pgtable_l3_enabled() && !pud_table(pud))

[Severity: Medium]
Does redefining pud_bad() in terms of !pud_table() cause pud_bad() to always
return false on 64K-page 3-level page tables?

Because pud_table() unconditionally returns true when PAGE_SIZE == SZ_64K,
this reverts commit bfb1d2b9021c ("arm64/mm: Check PUD_TYPE_TABLE in
pud_bad()"), preventing bad-PUD detection when 3 levels are active with 64K
pages and triggering WARN_ON(!pud_bad(pud_mkhuge(pud))) in pud_basic_tests()
under CONFIG_DEBUG_VM_PGTABLE.  Checking (pud_val(pud) & PUD_TYPE_MASK) !=
PUD_TYPE_TABLE directly when pgtable_l3_enabled() is true, matching p4d_bad()
and pgd_bad(), would preserve the check on 64K pages.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201015240.1017259-1-ericcurtin17@gmail.com?part=30


  reply	other threads:[~2026-12-02  2:34 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  1:51 [RFC PATCH v2 00/43] Boot-time page size selection for arm64 (core) Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 02/43] vmlinux.lds: Align page-aligned sections to PAGE_SIZE_MAX Eric Curtin
2026-12-02  2:34   ` sashiko-bot
2026-12-01  1:51 ` [RFC PATCH v2 03/43] mm: page_frag: Use PAGE_SIZE_MIN/MAX limits in page_frag_cache Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 04/43] mm: page_frag: Add _MIN/_MAX variants of PAGE_FRAG_CACHE_MAX_SIZE Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 05/43] mm: Avoid split pmd ptl if pmd level is run-time folded Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 06/43] mm/vmstat: Use THREAD_SIZE_MAX for the KSTACK_* counters Eric Curtin
2026-12-02  2:34   ` sashiko-bot
2026-12-01  1:51 ` [RFC PATCH v2 07/43] fork: Permit boot-time THREAD_SIZE determination Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 21/43] arm64: Test PAGE_SIZE instead of CONFIG_ARM64_*K_PAGES Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 25/43] arm64: Size and align the zero page and FDT ptes for PAGE_SIZE_MAX Eric Curtin
2026-12-01  1:52 ` [RFC PATCH v2 30/43] arm64: Support runtime folding of the pmd level Eric Curtin
2026-12-02  2:34   ` sashiko-bot [this message]
2026-12-01  1:52 ` [RFC PATCH v2 34/43] mm/damon/lru_sort: Initialise the stub access pattern at boot Eric Curtin
2026-12-01  1:52 ` [RFC PATCH v2 35/43] mm/zsmalloc: Size static limits for the worst-case page size Eric Curtin
2026-12-01  1:52 ` [RFC PATCH v2 38/43] mm: Use fixed sizes for shmem str_dup and swap cache PFN bits Eric Curtin
2026-12-01  1:52 ` [RFC PATCH v2 43/43] arm64: Enable boot-time page size selection Eric Curtin
2026-12-02  2:34   ` sashiko-bot
2026-12-01 10:41 ` [RFC PATCH v2 00/43] Boot-time page size selection for arm64 (core) Lorenzo Stoakes (ARM)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-244690@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=aneesh.kumar@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=ericcurtin17@gmail.com \
    --cc=fuad.tabba@linux.dev \
    --cc=joey.gouly@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-mm@kvack.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=npiggin@gmail.com \
    --cc=oupton@kernel.org \
    --cc=peterz@infradead.org \
    --cc=ryan.roberts@arm.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=seiden@linux.ibm.com \
    --cc=suzuki.poulose@arm.com \
    --cc=will@kernel.org \
    --cc=yuzenghui@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox