]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mm: introduce a common definition of mk_pte()
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Wed, 2 Apr 2025 18:16:56 +0000 (19:16 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 12 May 2025 00:48:02 +0000 (17:48 -0700)
Most architectures simply call pfn_pte().  Centralise that as the normal
definition and remove the definition of mk_pte() from the architectures
which have either that exact definition or something similar.

Link: https://lkml.kernel.org/r/20250402181709.2386022-3-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org> # m68k
Acked-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Alexander Gordeev <agordeev@linux.ibm.com> # s390
Cc: Zi Yan <ziy@nvidia.com>
Cc: Andreas Larsson <andreas@gaisler.com>
Cc: Anton Ivanov <anton.ivanov@cambridgegreys.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Johannes Berg <johannes@sipsolutions.net>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Richard Weinberger <richard@nod.at>
Cc: <x86@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
22 files changed:
arch/alpha/include/asm/pgtable.h
arch/arc/include/asm/pgtable-levels.h
arch/arm/include/asm/pgtable.h
arch/arm64/include/asm/pgtable.h
arch/csky/include/asm/pgtable.h
arch/hexagon/include/asm/pgtable.h
arch/loongarch/include/asm/pgtable.h
arch/m68k/include/asm/mcf_pgtable.h
arch/m68k/include/asm/motorola_pgtable.h
arch/m68k/include/asm/sun3_pgtable.h
arch/microblaze/include/asm/pgtable.h
arch/mips/include/asm/pgtable.h
arch/nios2/include/asm/pgtable.h
arch/openrisc/include/asm/pgtable.h
arch/parisc/include/asm/pgtable.h
arch/powerpc/include/asm/pgtable.h
arch/riscv/include/asm/pgtable.h
arch/s390/include/asm/pgtable.h
arch/sh/include/asm/pgtable_32.h
arch/sparc/include/asm/pgtable_64.h
arch/xtensa/include/asm/pgtable.h
include/linux/mm.h

index 02e8817a89212c1c7566a0497f9248a3c11775f2..2676017f42f1759483608e3a5c46beb8625763d0 100644 (file)
@@ -192,13 +192,6 @@ extern unsigned long __zero_page(void);
 #define pte_pfn(pte)           (pte_val(pte) >> PFN_PTE_SHIFT)
 
 #define pte_page(pte)  pfn_to_page(pte_pfn(pte))
-#define mk_pte(page, pgprot)                                           \
-({                                                                     \
-       pte_t pte;                                                      \
-                                                                       \
-       pte_val(pte) = (page_to_pfn(page) << 32) | pgprot_val(pgprot);  \
-       pte;                                                            \
-})
 
 extern inline pte_t pfn_pte(unsigned long physpfn, pgprot_t pgprot)
 { pte_t pte; pte_val(pte) = (PHYS_TWIDDLE(physpfn) << 32) | pgprot_val(pgprot); return pte; }
index 86e148226463017d9891f9ea721b2f330b1b0f77..55dbd2719e353cd9aeecf71961a179fc7bcd1d0b 100644 (file)
 #define set_pte(ptep, pte)     ((*(ptep)) = (pte))
 #define pte_pfn(pte)           (pte_val(pte) >> PAGE_SHIFT)
 #define pfn_pte(pfn, prot)     __pte(__pfn_to_phys(pfn) | pgprot_val(prot))
-#define mk_pte(page, prot)     pfn_pte(page_to_pfn(page), prot)
 
 #ifdef CONFIG_ISA_ARCV2
 #define pmd_leaf(x)            (pmd_val(x) & _PAGE_HW_SZ)
index 6b986ef6042f84be64ccf22b2297332be276e5e8..7f1c3b4e3e0449cc26d41062c4e59c7a42376c41 100644 (file)
@@ -168,7 +168,6 @@ static inline pte_t *pmd_page_vaddr(pmd_t pmd)
 #define pfn_pte(pfn,prot)      __pte(__pfn_to_phys(pfn) | pgprot_val(prot))
 
 #define pte_page(pte)          pfn_to_page(pte_pfn(pte))
-#define mk_pte(page,prot)      pfn_pte(page_to_pfn(page), prot)
 
 #define pte_clear(mm,addr,ptep)        set_pte_ext(ptep, __pte(0), 0)
 
index d3b538be1500b8dab3ea1af419e716d3cecd25d4..f03c6c2b094464bb06821428e9828cfc30d33f2c 100644 (file)
@@ -813,12 +813,6 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd)
 /* use ONLY for statically allocated translation tables */
 #define pte_offset_kimg(dir,addr)      ((pte_t *)__phys_to_kimg(pte_offset_phys((dir), (addr))))
 
-/*
- * Conversion functions: convert a page and protection to a page entry,
- * and a page entry and page directory to the page they refer to.
- */
-#define mk_pte(page,prot)      pfn_pte(page_to_pfn(page),prot)
-
 #if CONFIG_PGTABLE_LEVELS > 2
 
 #define pmd_ERROR(e)   \
index a397e1718ab67506bde9b388aa473b683b118623..b8378431aeff7c5e1705d8fac2981a7123f39c2f 100644 (file)
@@ -249,11 +249,6 @@ static inline pgprot_t pgprot_writecombine(pgprot_t _prot)
        return __pgprot(prot);
 }
 
-/*
- * Conversion functions: convert a page and protection to a page entry,
- * and a page entry and page directory to the page they refer to.
- */
-#define mk_pte(page, pgprot)    pfn_pte(page_to_pfn(page), (pgprot))
 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
 {
        return __pte((pte_val(pte) & _PAGE_CHG_MASK) |
index 8c5b7a1c3d909db90d13caf8299a8f5548a11972..9fbdfdbc539f8539b0377a601b8a1027d6a26212 100644 (file)
@@ -238,9 +238,6 @@ static inline int pte_present(pte_t pte)
        return pte_val(pte) & _PAGE_PRESENT;
 }
 
-/* mk_pte - make a PTE out of a page pointer and protection bits */
-#define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
-
 /* pte_page - returns a page (frame pointer/descriptor?) based on a PTE */
 #define pte_page(x) pfn_to_page(pte_pfn(x))
 
index da346733a1daeda61fd03156582f4df81a36c385..9ba3a4ebcd98c96b2f9a43cf1311e38d3d10157f 100644 (file)
@@ -426,12 +426,6 @@ static inline unsigned long pte_accessible(struct mm_struct *mm, pte_t a)
        return false;
 }
 
-/*
- * Conversion functions: convert a page and protection to a page entry,
- * and a page entry and page directory to the page they refer to.
- */
-#define mk_pte(page, pgprot)   pfn_pte(page_to_pfn(page), (pgprot))
-
 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
 {
        return __pte((pte_val(pte) & _PAGE_CHG_MASK) |
index 48f87a8a88320a53fe79e0755d9237051c2123d1..f5c596b211d422f8f7c4d9d7387e5cf8203d252d 100644 (file)
 
 #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.
- */
-#define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
-
 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
 {
        pte_val(pte) = (pte_val(pte) & CF_PAGE_CHG_MASK) | pgprot_val(newprot);
index 9866c7acdabe17674e153eff7ad2cca43de5e1c4..040ac3bad713cd2a5e9d3b930f4c47c321937fdf 100644 (file)
@@ -81,12 +81,6 @@ extern unsigned long mm_cachebits;
 
 #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.
- */
-#define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
-
 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
 {
        pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot);
index 30081aee8164362148217582ec279c7a401a9621..73745dc0ec0e0f4ba8f86cce875492273617c3ce 100644 (file)
 
 #ifndef __ASSEMBLY__
 
-/*
- * Conversion functions: convert a page and protection to a page entry,
- * and a page entry and page directory to the page they refer to.
- */
-#define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
-
 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
 {
        pte_val(pte) = (pte_val(pte) & SUN3_PAGE_CHG_MASK) | pgprot_val(newprot);
index e4ea2ec3642f065a6d71041704e6d310369127dd..b1bb2c65dd047e0d412a6b81db1447d2b0846060 100644 (file)
@@ -285,14 +285,6 @@ static inline pte_t mk_pte_phys(phys_addr_t physpage, pgprot_t pgprot)
        return pte;
 }
 
-#define mk_pte(page, pgprot) \
-({                                                                        \
-       pte_t pte;                                                         \
-       pte_val(pte) = (((page - mem_map) << PAGE_SHIFT) + memory_start) |  \
-                       pgprot_val(pgprot);                                \
-       pte;                                                               \
-})
-
 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
 {
        pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot);
index c29a551eb0ca8d01521e4b207ce38efe35962b62..d69cfa5a8ac62d9bcd1fcdafedcc7fe8598b6eeb 100644 (file)
@@ -504,12 +504,6 @@ static inline int ptep_set_access_flags(struct vm_area_struct *vma,
        return true;
 }
 
-/*
- * Conversion functions: convert a page and protection to a page entry,
- * and a page entry and page directory to the page they refer to.
- */
-#define mk_pte(page, pgprot)   pfn_pte(page_to_pfn(page), (pgprot))
-
 #if defined(CONFIG_XPA)
 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
 {
index eab87c6beacb5a46607e2f4fd81e8cc18112d1af..f490f2fa0dca046f4faa7e8ee41130f3650d28d9 100644 (file)
@@ -217,12 +217,6 @@ static inline void pte_clear(struct mm_struct *mm,
        set_pte(ptep, null);
 }
 
-/*
- * Conversion functions: convert a page and protection to a page entry,
- * and a page entry and page directory to the page they refer to.
- */
-#define mk_pte(page, prot)     (pfn_pte(page_to_pfn(page), prot))
-
 /*
  * 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 60c6ce7ff2dcf5059469c0544eb8d07db3e296b5..71bfb8c8c482a3b3c31ea48e4311f45c86558307 100644 (file)
@@ -299,8 +299,6 @@ static inline pte_t __mk_pte(void *page, pgprot_t pgprot)
        return pte;
 }
 
-#define mk_pte(page, pgprot) __mk_pte(page_address(page), (pgprot))
-
 #define mk_pte_phys(physpage, pgprot) \
 ({                                                                      \
        pte_t __pte;                                                    \
index babf65751e8180dd9f113940c1bdf848f86d9178..e85963fefa6382031a0bd794cad55496c80921f7 100644 (file)
@@ -338,10 +338,6 @@ static inline pte_t pte_mkspecial(pte_t pte)       { pte_val(pte) |= _PAGE_SPECIAL; re
 #endif
 
 
-/*
- * Conversion functions: convert a page and protection to a page entry,
- * and a page entry and page directory to the page they refer to.
- */
 #define __mk_pte(addr,pgprot) \
 ({                                                                     \
        pte_t __pte;                                                    \
@@ -351,8 +347,6 @@ static inline pte_t pte_mkspecial(pte_t pte)        { pte_val(pte) |= _PAGE_SPECIAL; re
        __pte;                                                          \
 })
 
-#define mk_pte(page, pgprot)   pfn_pte(page_to_pfn(page), (pgprot))
-
 static inline pte_t pfn_pte(unsigned long pfn, pgprot_t pgprot)
 {
        pte_t pte;
index 2f72ad885332e8909499e70ace6d7e9c3660a251..93d77ad5a92fa44f8a08a68baaf2d36950654ae0 100644 (file)
@@ -53,9 +53,8 @@ void set_ptes(struct mm_struct *mm, unsigned long addr, pte_t *ptep,
 #define MAX_PTRS_PER_PGD PTRS_PER_PGD
 #endif
 
-/* Keep these as a macros to avoid include dependency mess */
+/* Keep this as a macro to avoid include dependency mess */
 #define pte_page(x)            pfn_to_page(pte_pfn(x))
-#define mk_pte(page, pgprot)   pfn_pte(page_to_pfn(page), (pgprot))
 
 static inline unsigned long pte_pfn(pte_t pte)
 {
index 428e48e5f57d0679d8df28521c1dea2692fbefcb..f19240fd018e165ba0d1f3ab4651b0013afbfb7a 100644 (file)
@@ -343,8 +343,6 @@ static inline pte_t pfn_pte(unsigned long pfn, pgprot_t prot)
        return __pte((pfn << _PAGE_PFN_SHIFT) | prot_val);
 }
 
-#define mk_pte(page, prot)       pfn_pte(page_to_pfn(page), prot)
-
 #define pte_pgprot pte_pgprot
 static inline pgprot_t pte_pgprot(pte_t pte)
 {
index 49833002232bb4a1edf6225cd8b9568049527b04..3ef5d2198480b6c55ef8ef1e2e4f5713d06f1082 100644 (file)
@@ -1448,11 +1448,6 @@ static inline pte_t mk_pte_phys(unsigned long physpage, pgprot_t pgprot)
        return pte_mkyoung(__pte);
 }
 
-static inline pte_t mk_pte(struct page *page, pgprot_t pgprot)
-{
-       return mk_pte_phys(page_to_phys(page), pgprot);
-}
-
 #define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
 #define p4d_index(address) (((address) >> P4D_SHIFT) & (PTRS_PER_P4D-1))
 #define pud_index(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD-1))
index f939f1215232c52a715db530cc9df2b261f717cc..db2e48366e0d5d52b309b172ca123c06a2bdbdf0 100644 (file)
@@ -380,14 +380,6 @@ PTE_BIT_FUNC(low, mkspecial, |= _PAGE_SPECIAL);
 
 #define pgprot_noncached        pgprot_writecombine
 
-/*
- * Conversion functions: convert a page and protection to a page entry,
- * and a page entry and page directory to the page they refer to.
- *
- * extern pte_t mk_pte(struct page *page, pgprot_t pgprot)
- */
-#define mk_pte(page, pgprot)   pfn_pte(page_to_pfn(page), (pgprot))
-
 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
 {
        pte.pte_low &= _PAGE_CHG_MASK;
index dc28f2c4eee3f267afa9de596c2295ce2880fc60..d9c9035760843dccc6e9bc2e86e4b2a2e9179832 100644 (file)
@@ -225,7 +225,6 @@ static inline pte_t pfn_pte(unsigned long pfn, pgprot_t prot)
        BUILD_BUG_ON(_PAGE_SZBITS_4U != 0UL || _PAGE_SZBITS_4V != 0UL);
        return __pte(paddr | pgprot_val(prot));
 }
-#define mk_pte(page, pgprot)   pfn_pte(page_to_pfn(page), (pgprot))
 
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 static inline pmd_t pfn_pmd(unsigned long page_nr, pgprot_t pgprot)
index 1647a7cc3fbf6760e4187858d3a20f6ccf9773a3..cb1725c40e369200656e034c8a493064dd074780 100644 (file)
@@ -269,17 +269,11 @@ static inline pte_t pte_mkwrite_novma(pte_t pte)
                ((__pgprot((pgprot_val(prot) & ~_PAGE_CA_MASK) | \
                           _PAGE_CA_BYPASS)))
 
-/*
- * Conversion functions: convert a page and protection to a page entry,
- * and a page entry and page directory to the page they refer to.
- */
-
 #define PFN_PTE_SHIFT          PAGE_SHIFT
 #define pte_pfn(pte)           (pte_val(pte) >> PAGE_SHIFT)
 #define pte_same(a,b)          (pte_val(a) == pte_val(b))
 #define pte_page(x)            pfn_to_page(pte_pfn(x))
 #define pfn_pte(pfn, prot)     __pte(((pfn) << PAGE_SHIFT) | pgprot_val(prot))
-#define mk_pte(page, prot)     pfn_pte(page_to_pfn(page), prot)
 
 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
 {
index bf55206935c467f7508e863332063bb15f904a24..aa944eaad0ec5d1c34d870a3ec2cd2200c0cc262 100644 (file)
@@ -2004,6 +2004,15 @@ static inline struct folio *pfn_folio(unsigned long pfn)
        return page_folio(pfn_to_page(pfn));
 }
 
+#ifndef mk_pte
+#ifdef CONFIG_MMU
+static inline pte_t mk_pte(struct page *page, pgprot_t pgprot)
+{
+       return pfn_pte(page_to_pfn(page), pgprot);
+}
+#endif
+#endif
+
 static inline bool folio_has_pincount(const struct folio *folio)
 {
        if (IS_ENABLED(CONFIG_64BIT))