mm/thp: define default pmd_pgtable()
authorAnshuman Khandual <anshuman.khandual@arm.com>
Thu, 1 Jul 2021 01:53:59 +0000 (18:53 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 1 Jul 2021 18:06:03 +0000 (11:06 -0700)
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.

Link: https://lkml.kernel.org/r/1623646133-20306-1-git-send-email-anshuman.khandual@arm.com
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
Acked-by: Mike Rapoport <rppt@linux.ibm.com>
Cc: Nick Hu <nickhu@andestech.com>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Vineet Gupta <vgupta@synopsys.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Guo Ren <guoren@kernel.org>
Cc: Brian Cain <bcain@codeaurora.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Ley Foon Tan <ley.foon.tan@intel.com>
Cc: Jonas Bonn <jonas@southpole.se>
Cc: Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
Cc: Stafford Horne <shorne@gmail.com>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jeff Dike <jdike@addtoit.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Chris Zankel <chris@zankel.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
33 files changed:
arch/alpha/include/asm/pgalloc.h
arch/arc/include/asm/pgalloc.h
arch/arc/include/asm/pgtable.h
arch/arm/include/asm/pgalloc.h
arch/arm64/include/asm/pgalloc.h
arch/csky/include/asm/pgalloc.h
arch/hexagon/include/asm/pgtable.h
arch/ia64/include/asm/pgalloc.h
arch/m68k/include/asm/mcf_pgalloc.h
arch/m68k/include/asm/mcf_pgtable.h
arch/m68k/include/asm/motorola_pgalloc.h
arch/m68k/include/asm/motorola_pgtable.h
arch/m68k/include/asm/sun3_pgalloc.h
arch/microblaze/include/asm/pgalloc.h
arch/mips/include/asm/pgalloc.h
arch/nds32/include/asm/pgalloc.h
arch/nios2/include/asm/pgalloc.h
arch/openrisc/include/asm/pgalloc.h
arch/parisc/include/asm/pgalloc.h
arch/powerpc/include/asm/pgalloc.h
arch/powerpc/include/asm/pgtable.h
arch/riscv/include/asm/pgalloc.h
arch/s390/include/asm/pgalloc.h
arch/s390/include/asm/pgtable.h
arch/sh/include/asm/pgalloc.h
arch/sparc/include/asm/pgalloc_32.h
arch/sparc/include/asm/pgalloc_64.h
arch/sparc/include/asm/pgtable_32.h
arch/sparc/include/asm/pgtable_64.h
arch/um/include/asm/pgalloc.h
arch/x86/include/asm/pgalloc.h
arch/xtensa/include/asm/pgalloc.h
include/linux/pgtable.h

index 9c6a24fe493d59e88303647c2ed80e6a4f53c136..68be7adbfe58d08cb3de662ec44d8f2537791b05 100644 (file)
@@ -18,7 +18,6 @@ pmd_populate(struct mm_struct *mm, pmd_t *pmd, pgtable_t pte)
 {
        pmd_set(pmd, (pte_t *)(page_to_pa(pte) + PAGE_OFFSET));
 }
-#define pmd_pgtable(pmd) pmd_page(pmd)
 
 static inline void
 pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte)
index 6147db9252487f76875afbc7953a3c69b518aac1..a32ca3104ced7545e4795603ec448bfcd01eac4a 100644 (file)
@@ -129,6 +129,4 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t ptep)
 
 #define __pte_free_tlb(tlb, pte, addr)  pte_free((tlb)->mm, pte)
 
-#define pmd_pgtable(pmd)       ((pgtable_t) pmd_page_vaddr(pmd))
-
 #endif /* _ASM_ARC_PGALLOC_H */
index 577682e8cc7ff8dd67b8f5be9a7d8659d5c4518b..320cc0ae8a08d23118255e45defcfa164a681071 100644 (file)
@@ -350,6 +350,8 @@ void update_mmu_cache(struct vm_area_struct *vma, unsigned long address,
 
 #define kern_addr_valid(addr)  (1)
 
+#define pmd_pgtable(pmd)       ((pgtable_t) pmd_page_vaddr(pmd))
+
 /*
  * remap a physical page `pfn' of size `size' with page protection `prot'
  * into virtual address `from'
index fdee1f04f4f3dc0f424b337d68b86c485c0e5a39..a17f01235c29c0dc619c0929aa761df861a5dd2d 100644 (file)
@@ -143,7 +143,6 @@ pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
 
        __pmd_populate(pmdp, page_to_phys(ptep), prot);
 }
-#define pmd_pgtable(pmd) pmd_page(pmd)
 
 #endif /* CONFIG_MMU */
 
index 31fbab3d6f99234c301cde17d856dec02f12b17c..8433a2058eb15f00a8275156d534d8d65ed702c8 100644 (file)
@@ -86,6 +86,5 @@ pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
        VM_BUG_ON(mm == &init_mm);
        __pmd_populate(pmdp, page_to_phys(ptep), PMD_TYPE_TABLE | PMD_TABLE_PXN);
 }
-#define pmd_pgtable(pmd) pmd_page(pmd)
 
 #endif
index cd211aabbefd1462bc00537b6c4f8afec8d97f9d..bbbd0698b3972909d1b2aee8db105cff938be9f0 100644 (file)
@@ -22,8 +22,6 @@ static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
        set_pmd(pmd, __pmd(__pa(page_address(pte))));
 }
 
-#define pmd_pgtable(pmd) pmd_page(pmd)
-
 extern void pgd_init(unsigned long *p);
 
 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm)
index e4979508cddf7786dcb8178ed8409902deb8233e..18cd6ea9ab2389961dfddcb2e3d73f59d76dba7a 100644 (file)
@@ -239,7 +239,6 @@ static inline int pmd_bad(pmd_t pmd)
  * pmd_page - converts a PMD entry to a page pointer
  */
 #define pmd_page(pmd)  (pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT))
-#define pmd_pgtable(pmd) pmd_page(pmd)
 
 /**
  * pte_none - check if pte is mapped
index 9601cfe83c9406e85fca0825c74790519795d424..0fb2b6291d58dc3a85cae2f07b5053ba8b1f4846 100644 (file)
@@ -52,7 +52,6 @@ pmd_populate(struct mm_struct *mm, pmd_t * pmd_entry, pgtable_t pte)
 {
        pmd_val(*pmd_entry) = page_to_phys(pte);
 }
-#define pmd_pgtable(pmd) pmd_page(pmd)
 
 static inline void
 pmd_populate_kernel(struct mm_struct *mm, pmd_t * pmd_entry, pte_t * pte)
index bc1228e00518ee9aac940ccb90ce15c056d4078c..5c2c0a864524cc104b8d1c758ff039950fcf5767 100644 (file)
@@ -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)
 {
index 8d4ec05996c5b82b8b0c862f7ac6f1f8eaed3366..6f2b87d7a50d0bf31690e0c719d95604d681dacf 100644 (file)
 
 #ifndef __ASSEMBLY__
 
+#define pmd_pgtable(pmd) pfn_to_virt(pmd_val(pmd) >> PAGE_SHIFT)
+
 /*
  * Conversion functions: convert a page and protection to a page entry,
  * and a page entry and page directory to the page they refer to.
index b4fc3b4f6bb38d661bc44759f96aee7e6f77db8f..74a817d9387fd105b6a1189b9149498e3c329d44 100644 (file)
@@ -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)
 {
index 8076467eff4b0aa7e1c6c1c35c6d9b802cbaa3a7..a2908164ee6fc46d8a6081673a8fe3574304c3ac 100644 (file)
@@ -105,6 +105,8 @@ extern unsigned long mm_cachebits;
 #define __S110 PAGE_SHARED_C
 #define __S111 PAGE_SHARED_C
 
+#define pmd_pgtable(pmd) ((pgtable_t)pmd_page_vaddr(pmd))
+
 /*
  * Conversion functions: convert a page and protection to a page entry,
  * and a page entry and page directory to the page they refer to.
index 000f64869b919e4687a390a6e01d9d605bc03ee2..198036aff5193433340f8c0fdfa3e870fb926248 100644 (file)
@@ -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
index d56b9f670ad11211769dd8962f8c5da079631a7a..6c33b05f730ff01846ce8b8f9a22449e2eb74090 100644 (file)
@@ -28,8 +28,6 @@ static inline pgd_t *get_pgd(void)
 
 #define pgd_alloc(mm)          get_pgd()
 
-#define pmd_pgtable(pmd)       pmd_page(pmd)
-
 extern pte_t *pte_alloc_one_kernel(struct mm_struct *mm);
 
 #define __pte_free_tlb(tlb, pte, addr) pte_free((tlb)->mm, (pte))
index 8b18424b31208c36a92514beecd8b9efc98ae7a2..dd53d0f79cb339915b3bf3cd0c11254cd4d8a647 100644 (file)
@@ -28,7 +28,6 @@ static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
 {
        set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
 }
-#define pmd_pgtable(pmd) pmd_page(pmd)
 
 /*
  * Initialize a new pmd table with invalid pointers.
index 85c117347c86b0ae0aa98ef4870153be06609630..a08e1ebca70eddfa5a4f9813962acd5ee4954f51 100644 (file)
 #define __HAVE_ARCH_PTE_ALLOC_ONE
 #include <asm-generic/pgalloc.h>       /* for pte_{alloc,free}_one */
 
-/*
- * Since we have only two-level page tables, these are trivial
- */
-#define pmd_pgtable(pmd) pmd_page(pmd)
-
 extern pgd_t *pgd_alloc(struct mm_struct *mm);
 extern void pgd_free(struct mm_struct *mm, pgd_t * pgd);
 
index e6600d2a5ae052982bbb6c271f87d5ce14d2df00..3c4ae74d57985f3e71209b3da3ff6e8fc8b8d235 100644 (file)
@@ -25,7 +25,6 @@ static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
 {
        set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
 }
-#define pmd_pgtable(pmd) pmd_page(pmd)
 
 /*
  * Initialize a new pmd table with invalid pointers.
index 88820299ecc4acade973d50172e2a30483576f5c..b7b2b8d16fad543cac1bdc7a874a20acc215ebb0 100644 (file)
@@ -72,6 +72,4 @@ do {                                  \
        tlb_remove_page((tlb), (pte));  \
 } while (0)
 
-#define pmd_pgtable(pmd) pmd_page(pmd)
-
 #endif
index dda55708531166b5f47b19c10404ac0c4f89512c..6a7e98e71f1d337a5fc2dbf2550e43c030ce437e 100644 (file)
@@ -69,6 +69,5 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte)
 
 #define pmd_populate(mm, pmd, pte_page) \
        pmd_populate_kernel(mm, pmd, page_address(pte_page))
-#define pmd_pgtable(pmd) pmd_page(pmd)
 
 #endif
index 6dd78a2dc03aff1b410b982a76d048a4f2d1d7ad..3360cad78acead9fc360d65498dda34b7fe0955e 100644 (file)
@@ -70,9 +70,4 @@ extern struct kmem_cache *pgtable_cache[];
 #include <asm/nohash/pgalloc.h>
 #endif
 
-static inline pgtable_t pmd_pgtable(pmd_t pmd)
-{
-       return (pgtable_t)pmd_page_vaddr(pmd);
-}
-
 #endif /* _ASM_POWERPC_PGALLOC_H */
index c6a676714f04099b6fecd66cf0c1bf034d83daa2..5969743719bc6db919d0835d179c77d957d6c400 100644 (file)
@@ -152,6 +152,12 @@ static inline bool p4d_is_leaf(p4d_t p4d)
 }
 #endif
 
+#define pmd_pgtable pmd_pgtable
+static inline pgtable_t pmd_pgtable(pmd_t pmd)
+{
+       return (pgtable_t)pmd_page_vaddr(pmd);
+}
+
 #ifdef CONFIG_PPC64
 #define is_ioremap_addr is_ioremap_addr
 static inline bool is_ioremap_addr(const void *x)
index 23b1544e0ca5b322aefa8cf83af5c528a8b10498..0af6933a7100de2acd1659751176224024c6f1c9 100644 (file)
@@ -38,8 +38,6 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
 }
 #endif /* __PAGETABLE_PMD_FOLDED */
 
-#define pmd_pgtable(pmd)       pmd_page(pmd)
-
 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
 {
        pgd_t *pgd;
index 6b187cd7225116b9a18859742e75f534bf5a51a7..f14a555eff7425c6b61512491f3afcb5158e1f2e 100644 (file)
@@ -134,9 +134,6 @@ static inline void pmd_populate(struct mm_struct *mm,
 
 #define pmd_populate_kernel(mm, pmd, pte) pmd_populate(mm, pmd, pte)
 
-#define pmd_pgtable(pmd) \
-       ((pgtable_t)__va(pmd_val(pmd) & -sizeof(pte_t)*PTRS_PER_PTE))
-
 /*
  * page table entry allocation/free routines.
  */
index 7c86bf03fc8f0feffc3f4638855fcf87877f7046..1f8f5da53262aab9c9d903cc9ddb3bd0b52d2a42 100644 (file)
@@ -1709,4 +1709,7 @@ extern void s390_reset_cmma(struct mm_struct *mm);
 #define HAVE_ARCH_UNMAPPED_AREA
 #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
 
+#define pmd_pgtable(pmd) \
+       ((pgtable_t)__va(pmd_val(pmd) & -sizeof(pte_t)*PTRS_PER_PTE))
+
 #endif /* _S390_PAGE_H */
index 0e6b0be25e33be4a2c986a385014ccf81976633a..a9e98233c4d498a2fe3b4a282329d358102a942d 100644 (file)
@@ -30,7 +30,6 @@ static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
 {
        set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
 }
-#define pmd_pgtable(pmd) pmd_page(pmd)
 
 #define __pte_free_tlb(tlb,pte,addr)                   \
 do {                                                   \
index 9d353e6dc5a9bfec43cea1a3277a5a37682c74b4..4f73e87b22a32b6cb45a0c821bd4f84876bdeb30 100644 (file)
@@ -51,7 +51,6 @@ static inline void free_pmd_fast(pmd_t * pmd)
 #define __pmd_free_tlb(tlb, pmd, addr) pmd_free((tlb)->mm, pmd)
 
 #define pmd_populate(mm, pmd, pte)     pmd_set(pmd, pte)
-#define pmd_pgtable(pmd)               (pgtable_t)__pmd_page(pmd)
 
 void pmd_set(pmd_t *pmdp, pte_t *ptep);
 #define pmd_populate_kernel            pmd_populate
index a8dafc55098546523a6fa5415385b3a5b8c6d8d7..7b5561d17ab14cf35088a0c0ff84d285c387a231 100644 (file)
@@ -67,7 +67,6 @@ void pte_free(struct mm_struct *mm, pgtable_t ptepage);
 
 #define pmd_populate_kernel(MM, PMD, PTE)      pmd_set(MM, PMD, PTE)
 #define pmd_populate(MM, PMD, PTE)             pmd_set(MM, PMD, PTE)
-#define pmd_pgtable(PMD)                       ((pte_t *)pmd_page_vaddr(PMD))
 
 void pgtable_free(void *table, bool is_page);
 
index 0888bda245f5334913e66b00825289ef39d647f9..ebaf374b55ab924ba69c0f975a1a03b61f278efc 100644 (file)
@@ -432,4 +432,6 @@ static inline int io_remap_pfn_range(struct vm_area_struct *vma,
 /* We provide our own get_unmapped_area to cope with VA holes for userland */
 #define HAVE_ARCH_UNMAPPED_AREA
 
+#define pmd_pgtable(pmd)       ((pgtable_t)__pmd_page(pmd))
+
 #endif /* !(_SPARC_PGTABLE_H) */
index a400e0f2304651213cbd9d2a1bc8b35645f44278..e0ee48ec390304bd62192deec4d143dcc8bf101e 100644 (file)
@@ -1117,6 +1117,8 @@ extern unsigned long cmdline_memory_size;
 
 asmlinkage void do_sparc64_fault(struct pt_regs *regs);
 
+#define pmd_pgtable(PMD)       ((pte_t *)pmd_page_vaddr(PMD))
+
 #ifdef CONFIG_HUGETLB_PAGE
 
 #define pud_leaf_size pud_leaf_size
index 2bbf28cf3aa9258ab1b8970e500c049e708ab842..8ec7cd46dd962146047aa1927b0e1b521b0891cd 100644 (file)
@@ -19,7 +19,6 @@
        set_pmd(pmd, __pmd(_PAGE_TABLE +                        \
                ((unsigned long long)page_to_pfn(pte) <<        \
                        (unsigned long long) PAGE_SHIFT)))
-#define pmd_pgtable(pmd) pmd_page(pmd)
 
 /*
  * Allocate and free page tables.
index 62ad61d6fefcb32acf235544d7364b68c7b2fc3b..c7ec5bb88334eab119ccf78002be2e7679291113 100644 (file)
@@ -84,8 +84,6 @@ static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
        set_pmd(pmd, __pmd(((pteval_t)pfn << PAGE_SHIFT) | _PAGE_TABLE));
 }
 
-#define pmd_pgtable(pmd) pmd_page(pmd)
-
 #if CONFIG_PGTABLE_LEVELS > 2
 extern void ___pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd);
 
index d3a22da4d2c91b91fbeaeee316f4c2e3efd38529..eeb2de3a89e575166eb6b780e2e50baaedcc68b3 100644 (file)
@@ -25,7 +25,6 @@
        (pmd_val(*(pmdp)) = ((unsigned long)ptep))
 #define pmd_populate(mm, pmdp, page)                                        \
        (pmd_val(*(pmdp)) = ((unsigned long)page_to_virt(page)))
-#define pmd_pgtable(pmd) pmd_page(pmd)
 
 static inline pgd_t*
 pgd_alloc(struct mm_struct *mm)
@@ -63,7 +62,6 @@ static inline pgtable_t pte_alloc_one(struct mm_struct *mm)
        return page;
 }
 
-#define pmd_pgtable(pmd) pmd_page(pmd)
 #endif /* CONFIG_MMU */
 
 #endif /* _XTENSA_PGALLOC_H */
index 69700e3e615fc49a70a25eab6c1e401d3e0deb15..e82660f7b9e4defc0dc4310a6f4e8b60c265592b 100644 (file)
 #define FIRST_USER_ADDRESS     0UL
 #endif
 
+/*
+ * This defines the generic helper for accessing PMD page
+ * table page. Although platforms can still override this
+ * via their respective <asm/pgtable.h>.
+ */
+#ifndef pmd_pgtable
+#define pmd_pgtable(pmd) pmd_page(pmd)
+#endif
+
 /*
  * A page table page can be thought of an array like this: pXd_t[PTRS_PER_PxD]
  *