[PATCH] arm64: mm: Use generic enum pgtable_level

Ryan Roberts ryan.roberts at arm.com
Mon Mar 16 07:22:11 PDT 2026


On 16/03/2026 14:01, Kevin Brodsky wrote:
> enum pgtable_type was introduced for arm64 by commit c64f46ee1377
> ("arm64: mm: use enum to identify pgtable level instead of
> *_SHIFT"). In the meantime, the generic enum pgtable_level got
> introduced by commit b22cc9a9c7ff ("mm/rmap: convert "enum
> rmap_level" to "enum pgtable_level"").
> 
> Let's switch to the generic enum pgtable_level. The only difference
> is that it also includes PGD level - this isn't relevant in
> __pgd_pgtable_alloc() so we just add a default statement.
> 
> Suggested-by: David Hildenbrand (Arm) <david at kernel.org>
> Signed-off-by: Kevin Brodsky <kevin.brodsky at arm.com>
> ---
> Cc: Catalin Marinas <catalin.marinas at arm.com>
> Cc: Ryan Roberts <ryan.roberts at arm.com>
> Cc: Will Deacon <will at kernel.org>
> ---
>  arch/arm64/include/asm/mmu.h |  7 -----
>  arch/arm64/mm/mmu.c          | 58 +++++++++++++++++++-----------------
>  2 files changed, 30 insertions(+), 35 deletions(-)
> 

[...]

>  static phys_addr_t __pgd_pgtable_alloc(struct mm_struct *mm, gfp_t gfp,
> -				       enum pgtable_type pgtable_type)
> +				       enum pgtable_level pgtable_level)
>  {
>  	/* Page is zeroed by init_clear_pgtable() so don't duplicate effort. */
>  	struct ptdesc *ptdesc = pagetable_alloc(gfp & ~__GFP_ZERO, 0);
> @@ -539,40 +539,42 @@ static phys_addr_t __pgd_pgtable_alloc(struct mm_struct *mm, gfp_t gfp,
>  
>  	pa = page_to_phys(ptdesc_page(ptdesc));
>  
> -	switch (pgtable_type) {
> -	case TABLE_PTE:
> +	switch (pgtable_level) {
> +	case PGTABLE_LEVEL_PTE:
>  		BUG_ON(!pagetable_pte_ctor(mm, ptdesc));
>  		break;
> -	case TABLE_PMD:
> +	case PGTABLE_LEVEL_PMD:
>  		BUG_ON(!pagetable_pmd_ctor(mm, ptdesc));
>  		break;
> -	case TABLE_PUD:
> +	case PGTABLE_LEVEL_PUD:
>  		pagetable_pud_ctor(ptdesc);
>  		break;
> -	case TABLE_P4D:
> +	case PGTABLE_LEVEL_P4D:
>  		pagetable_p4d_ctor(ptdesc);
>  		break;
> +	default:
> +		break;

nit: I think we should either explicitly support pgd or explicitly bug/warn. Now
that the enum has PGTABLE_LEVEL_PGD it looks legit to call __pgd_pgtable_alloc()
to allocate one. But it will currently silently fail to call pagetable_pgd_ctor().

Probably simplest just to call BUG() in the default path?

With this addressed:

Reviewed-by: Ryan Roberts <ryan.roberts at arm.com>

Thanks,
Ryan





More information about the linux-arm-kernel mailing list