Re: [PATCH] mm/thp: Define default pmd_pgtable()

From: Geert Uytterhoeven
Date: Tue Jun 08 2021 - 02:59:13 EST


Hi Anshuman,

On Tue, Jun 8, 2021 at 7:31 AM Anshuman Khandual
<anshuman.khandual@xxxxxxx> wrote:
> Currently most platforms define pmd_pgtable() as pmd_page() duplicating the
> same code all over. Instead just define a default value i.e pmd_page() for
> pmd_pgtable() and let platforms override when required via <asm/pgtable.h>.
> All the existing platform that override pmd_pgtable() have been moved into
> their respective <asm/pgtable.h> header in order to precede before the new
> generic definition. This makes it much cleaner with reduced code.

> Signed-off-by: Anshuman Khandual <anshuman.khandual@xxxxxxx>

Thanks for your patch!

> This patch has been built tested across multiple platforms. But the m68k
> changes in particular might not be optimal, followed the existing switch
> from (arch/m68k/include/asm/pgalloc.h).

Indeed. Why not move them to the existing
arch/m68k/asm/{sun3,mcf,motorola}_pgtable.h>, instead of introducing
yet another #if/#elif/#else/#endif block?

> --- a/arch/m68k/include/asm/mcf_pgalloc.h
> +++ b/arch/m68k/include/asm/mcf_pgalloc.h
> @@ -32,8 +32,6 @@ extern inline pmd_t *pmd_alloc_kernel(pgd_t *pgd, unsigned long address)
>
> #define pmd_populate_kernel pmd_populate
>
> -#define pmd_pgtable(pmd) pfn_to_virt(pmd_val(pmd) >> PAGE_SHIFT)
> -
> static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t pgtable,
> unsigned long address)
> {
> diff --git a/arch/m68k/include/asm/motorola_pgalloc.h b/arch/m68k/include/asm/motorola_pgalloc.h
> index b4fc3b4f6bb3..74a817d9387f 100644
> --- a/arch/m68k/include/asm/motorola_pgalloc.h
> +++ b/arch/m68k/include/asm/motorola_pgalloc.h
> @@ -88,7 +88,6 @@ static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, pgtable_t page
> {
> pmd_set(pmd, page);
> }
> -#define pmd_pgtable(pmd) ((pgtable_t)pmd_page_vaddr(pmd))
>
> static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
> {
> diff --git a/arch/m68k/include/asm/pgtable.h b/arch/m68k/include/asm/pgtable.h
> index ad15d655a9bf..7be5e5e712b2 100644
> --- a/arch/m68k/include/asm/pgtable.h
> +++ b/arch/m68k/include/asm/pgtable.h
> @@ -4,3 +4,12 @@
> #else
> #include <asm/pgtable_mm.h>
> #endif
> +
> +
> +#if defined(CONFIG_COLDFIRE)
> +#define pmd_pgtable(pmd) pfn_to_virt(pmd_val(pmd) >> PAGE_SHIFT)
> +#elif defined(CONFIG_SUN3)
> +#define pmd_pgtable(pmd) pmd_page(pmd)
> +#else
> +#define pmd_pgtable(pmd) ((pgtable_t)pmd_page_vaddr(pmd))
> +#endif
> diff --git a/arch/m68k/include/asm/sun3_pgalloc.h b/arch/m68k/include/asm/sun3_pgalloc.h
> index 000f64869b91..198036aff519 100644
> --- a/arch/m68k/include/asm/sun3_pgalloc.h
> +++ b/arch/m68k/include/asm/sun3_pgalloc.h
> @@ -32,7 +32,6 @@ static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, pgtable_t page
> {
> pmd_val(*pmd) = __pa((unsigned long)page_address(page));
> }
> -#define pmd_pgtable(pmd) pmd_page(pmd)
>
> /*
> * allocating and freeing a pmd is trivial: the 1-entry pmd is

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds