linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] Provide a single definition of mk_pte()
@ 2024-08-14 15:44 Matthew Wilcox (Oracle)
  2024-08-14 15:44 ` [PATCH 1/5] mm: Introduce a common " Matthew Wilcox (Oracle)
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Matthew Wilcox (Oracle) @ 2024-08-14 15:44 UTC (permalink / raw)
  To: linux-mm, linux-arch; +Cc: Matthew Wilcox (Oracle), linux-s390, linux-um, x86

Each architecturee must provide a definition of mk_pte() today.  They must
also provide pfn_pte().  Usually the former is defined in terms of the
latter, but not on some architectures.  I was trying to decide what we
should do for creating PTEs in a folio world, and it struck me that we
should have architectures only provide pfn_pte() and then I don't need
to trouble the arch maintainers with whatever MM API I come up with.

The architectures not on the cc list I considered trivial.  The
architectures who have named patches are less trivial, and I did my
best to write a decent commit message explaining why I did what I did
to each architecture.

I have some followup patches which remove folio->page conversions, but
if this set of patches are wrong on any architecture, then they'll also
be wrong, so I'm not sending them right now.

Matthew Wilcox (Oracle) (5):
  mm: Introduce a common definition of mk_pte()
  x86: Remove custom definition of mk_pte()
  um: Remove custom definition of mk_pte()
  s390: Remove custom definition of mk_pte()
  mm: Make mk_pte() definition unconditional

 arch/alpha/include/asm/pgtable.h         |  7 -------
 arch/arc/include/asm/pgtable-levels.h    |  1 -
 arch/arm/include/asm/pgtable.h           |  1 -
 arch/arm64/include/asm/pgtable.h         |  6 ------
 arch/csky/include/asm/pgtable.h          |  5 -----
 arch/hexagon/include/asm/pgtable.h       |  3 ---
 arch/loongarch/include/asm/pgtable.h     |  6 ------
 arch/m68k/include/asm/mcf_pgtable.h      |  6 ------
 arch/m68k/include/asm/motorola_pgtable.h |  6 ------
 arch/m68k/include/asm/sun3_pgtable.h     |  6 ------
 arch/microblaze/include/asm/pgtable.h    |  8 --------
 arch/mips/include/asm/pgtable.h          |  6 ------
 arch/nios2/include/asm/pgtable.h         |  6 ------
 arch/openrisc/include/asm/pgtable.h      |  2 --
 arch/parisc/include/asm/pgtable.h        |  2 --
 arch/powerpc/include/asm/pgtable.h       |  1 -
 arch/riscv/include/asm/pgtable.h         |  2 --
 arch/s390/include/asm/pgtable.h          | 10 ----------
 arch/sh/include/asm/pgtable_32.h         |  8 --------
 arch/sparc/include/asm/pgtable_32.h      |  9 ++-------
 arch/sparc/include/asm/pgtable_64.h      |  1 -
 arch/um/include/asm/pgtable-2level.h     |  1 -
 arch/um/include/asm/pgtable-3level.h     |  9 ---------
 arch/um/include/asm/pgtable.h            | 17 ++++++++++-------
 arch/x86/include/asm/pgtable.h           | 19 +++----------------
 arch/xtensa/include/asm/pgtable.h        |  1 -
 include/linux/pgtable.h                  |  5 +++++
 27 files changed, 20 insertions(+), 134 deletions(-)

-- 
2.43.0



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/5] mm: Introduce a common definition of mk_pte()
  2024-08-14 15:44 [PATCH 0/5] Provide a single definition of mk_pte() Matthew Wilcox (Oracle)
@ 2024-08-14 15:44 ` Matthew Wilcox (Oracle)
  2024-08-15  2:45   ` kernel test robot
  2024-08-15  2:45   ` kernel test robot
  2024-08-14 15:44 ` [PATCH 2/5] x86: Remove custom " Matthew Wilcox (Oracle)
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 11+ messages in thread
From: Matthew Wilcox (Oracle) @ 2024-08-14 15:44 UTC (permalink / raw)
  To: linux-mm, linux-arch; +Cc: Matthew Wilcox (Oracle), linux-s390, linux-um, x86

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.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 arch/alpha/include/asm/pgtable.h         | 7 -------
 arch/arc/include/asm/pgtable-levels.h    | 1 -
 arch/arm/include/asm/pgtable.h           | 1 -
 arch/arm64/include/asm/pgtable.h         | 6 ------
 arch/csky/include/asm/pgtable.h          | 5 -----
 arch/hexagon/include/asm/pgtable.h       | 3 ---
 arch/loongarch/include/asm/pgtable.h     | 6 ------
 arch/m68k/include/asm/mcf_pgtable.h      | 6 ------
 arch/m68k/include/asm/motorola_pgtable.h | 6 ------
 arch/m68k/include/asm/sun3_pgtable.h     | 6 ------
 arch/microblaze/include/asm/pgtable.h    | 8 --------
 arch/mips/include/asm/pgtable.h          | 6 ------
 arch/nios2/include/asm/pgtable.h         | 6 ------
 arch/openrisc/include/asm/pgtable.h      | 2 --
 arch/parisc/include/asm/pgtable.h        | 2 --
 arch/powerpc/include/asm/pgtable.h       | 1 -
 arch/riscv/include/asm/pgtable.h         | 2 --
 arch/s390/include/asm/pgtable.h          | 1 +
 arch/sh/include/asm/pgtable_32.h         | 8 --------
 arch/sparc/include/asm/pgtable_32.h      | 9 ++-------
 arch/sparc/include/asm/pgtable_64.h      | 1 -
 arch/xtensa/include/asm/pgtable.h        | 1 -
 include/linux/pgtable.h                  | 7 +++++++
 23 files changed, 10 insertions(+), 91 deletions(-)

diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
index 635f0a5f5bbd..63e95f36f8ec 100644
--- a/arch/alpha/include/asm/pgtable.h
+++ b/arch/alpha/include/asm/pgtable.h
@@ -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; }
diff --git a/arch/arc/include/asm/pgtable-levels.h b/arch/arc/include/asm/pgtable-levels.h
index 86e148226463..55dbd2719e35 100644
--- a/arch/arc/include/asm/pgtable-levels.h
+++ b/arch/arc/include/asm/pgtable-levels.h
@@ -177,7 +177,6 @@
 #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)
diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
index be91e376df79..74c3b5a6eab3 100644
--- a/arch/arm/include/asm/pgtable.h
+++ b/arch/arm/include/asm/pgtable.h
@@ -169,7 +169,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)
 
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index 7a4f5604be3f..33b6bf2add61 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -741,12 +741,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)	\
diff --git a/arch/csky/include/asm/pgtable.h b/arch/csky/include/asm/pgtable.h
index a397e1718ab6..b8378431aeff 100644
--- a/arch/csky/include/asm/pgtable.h
+++ b/arch/csky/include/asm/pgtable.h
@@ -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) |
diff --git a/arch/hexagon/include/asm/pgtable.h b/arch/hexagon/include/asm/pgtable.h
index 8c5b7a1c3d90..9fbdfdbc539f 100644
--- a/arch/hexagon/include/asm/pgtable.h
+++ b/arch/hexagon/include/asm/pgtable.h
@@ -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))
 
diff --git a/arch/loongarch/include/asm/pgtable.h b/arch/loongarch/include/asm/pgtable.h
index 85431f20a14d..f2bbe3f74440 100644
--- a/arch/loongarch/include/asm/pgtable.h
+++ b/arch/loongarch/include/asm/pgtable.h
@@ -450,12 +450,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) |
diff --git a/arch/m68k/include/asm/mcf_pgtable.h b/arch/m68k/include/asm/mcf_pgtable.h
index 48f87a8a8832..f5c596b211d4 100644
--- a/arch/m68k/include/asm/mcf_pgtable.h
+++ b/arch/m68k/include/asm/mcf_pgtable.h
@@ -96,12 +96,6 @@
 
 #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);
diff --git a/arch/m68k/include/asm/motorola_pgtable.h b/arch/m68k/include/asm/motorola_pgtable.h
index 9866c7acdabe..040ac3bad713 100644
--- a/arch/m68k/include/asm/motorola_pgtable.h
+++ b/arch/m68k/include/asm/motorola_pgtable.h
@@ -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);
diff --git a/arch/m68k/include/asm/sun3_pgtable.h b/arch/m68k/include/asm/sun3_pgtable.h
index 30081aee8164..73745dc0ec0e 100644
--- a/arch/m68k/include/asm/sun3_pgtable.h
+++ b/arch/m68k/include/asm/sun3_pgtable.h
@@ -76,12 +76,6 @@
 
 #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);
diff --git a/arch/microblaze/include/asm/pgtable.h b/arch/microblaze/include/asm/pgtable.h
index e4ea2ec3642f..b1bb2c65dd04 100644
--- a/arch/microblaze/include/asm/pgtable.h
+++ b/arch/microblaze/include/asm/pgtable.h
@@ -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);
diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
index c29a551eb0ca..d69cfa5a8ac6 100644
--- a/arch/mips/include/asm/pgtable.h
+++ b/arch/mips/include/asm/pgtable.h
@@ -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)
 {
diff --git a/arch/nios2/include/asm/pgtable.h b/arch/nios2/include/asm/pgtable.h
index eab87c6beacb..f490f2fa0dca 100644
--- a/arch/nios2/include/asm/pgtable.h
+++ b/arch/nios2/include/asm/pgtable.h
@@ -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.
diff --git a/arch/openrisc/include/asm/pgtable.h b/arch/openrisc/include/asm/pgtable.h
index 60c6ce7ff2dc..71bfb8c8c482 100644
--- a/arch/openrisc/include/asm/pgtable.h
+++ b/arch/openrisc/include/asm/pgtable.h
@@ -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;                                                    \
diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
index babf65751e81..4e87ebf08297 100644
--- a/arch/parisc/include/asm/pgtable.h
+++ b/arch/parisc/include/asm/pgtable.h
@@ -351,8 +351,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;
diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
index 264a6c09517a..f99cb39653f2 100644
--- a/arch/powerpc/include/asm/pgtable.h
+++ b/arch/powerpc/include/asm/pgtable.h
@@ -55,7 +55,6 @@ void set_ptes(struct mm_struct *mm, unsigned long addr, pte_t *ptep,
 
 /* Keep these as a macros 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)
 {
diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
index 089f3c9f56a3..b63196bfe61c 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -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)
-
 static inline int pte_present(pte_t pte)
 {
 	return (pte_val(pte) & (_PAGE_PRESENT | _PAGE_PROT_NONE));
diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
index 3fa280d0672a..6a21d947a687 100644
--- a/arch/s390/include/asm/pgtable.h
+++ b/arch/s390/include/asm/pgtable.h
@@ -1422,6 +1422,7 @@ static inline pte_t mk_pte(struct page *page, pgprot_t pgprot)
 		__pte = pte_mkdirty(__pte);
 	return __pte;
 }
+#define mk_pte mk_pte
 
 #define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
 #define p4d_index(address) (((address) >> P4D_SHIFT) & (PTRS_PER_P4D-1))
diff --git a/arch/sh/include/asm/pgtable_32.h b/arch/sh/include/asm/pgtable_32.h
index f939f1215232..db2e48366e0d 100644
--- a/arch/sh/include/asm/pgtable_32.h
+++ b/arch/sh/include/asm/pgtable_32.h
@@ -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;
diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
index 62bcafe38b1f..531059cc2abb 100644
--- a/arch/sparc/include/asm/pgtable_32.h
+++ b/arch/sparc/include/asm/pgtable_32.h
@@ -255,7 +255,6 @@ static inline pte_t pte_mkyoung(pte_t pte)
 }
 
 #define PFN_PTE_SHIFT			(PAGE_SHIFT - 4)
-#define pfn_pte(pfn, prot)		mk_pte(pfn_to_page(pfn), prot)
 
 static inline unsigned long pte_pfn(pte_t pte)
 {
@@ -272,13 +271,9 @@ static inline unsigned long pte_pfn(pte_t pte)
 
 #define pte_page(pte)	pfn_to_page(pte_pfn(pte))
 
-/*
- * Conversion functions: convert a page and protection to a page entry,
- * and a page entry and page directory to the page they refer to.
- */
-static inline pte_t mk_pte(struct page *page, pgprot_t pgprot)
+static inline pte_t pfn_pte(struct page *page, pgprot_t pgprot)
 {
-	return __pte((page_to_pfn(page) << (PAGE_SHIFT-4)) | pgprot_val(pgprot));
+	return __pte((pfn << PFN_PTE_SHIFT) | pgprot_val(pgprot));
 }
 
 static inline pte_t mk_pte_phys(unsigned long page, pgprot_t pgprot)
diff --git a/arch/sparc/include/asm/pgtable_64.h b/arch/sparc/include/asm/pgtable_64.h
index 3fe429d73a65..c7a4d0034b60 100644
--- a/arch/sparc/include/asm/pgtable_64.h
+++ b/arch/sparc/include/asm/pgtable_64.h
@@ -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)
diff --git a/arch/xtensa/include/asm/pgtable.h b/arch/xtensa/include/asm/pgtable.h
index 1647a7cc3fbf..c550ed288273 100644
--- a/arch/xtensa/include/asm/pgtable.h
+++ b/arch/xtensa/include/asm/pgtable.h
@@ -279,7 +279,6 @@ static inline pte_t pte_mkwrite_novma(pte_t pte)
 #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)
 {
diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index 2289e9f7aa1b..8204ffd87d74 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -41,6 +41,13 @@
 #define FIRST_USER_ADDRESS	0UL
 #endif
 
+#ifndef mk_pte
+static inline pte_t mk_pte(struct page *page, pgprot_t pgprot)
+{
+	return pfn_pte(page_to_pfn(page), pgprot);
+}
+#endif
+
 /*
  * This defines the generic helper for accessing PMD page
  * table page. Although platforms can still override this
-- 
2.43.0



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 2/5] x86: Remove custom definition of mk_pte()
  2024-08-14 15:44 [PATCH 0/5] Provide a single definition of mk_pte() Matthew Wilcox (Oracle)
  2024-08-14 15:44 ` [PATCH 1/5] mm: Introduce a common " Matthew Wilcox (Oracle)
@ 2024-08-14 15:44 ` Matthew Wilcox (Oracle)
  2024-08-15  4:08   ` kernel test robot
  2024-08-14 15:44 ` [PATCH 3/5] um: " Matthew Wilcox (Oracle)
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Matthew Wilcox (Oracle) @ 2024-08-14 15:44 UTC (permalink / raw)
  To: linux-mm, linux-arch; +Cc: Matthew Wilcox (Oracle), linux-s390, linux-um, x86

Move the shadow stack check to pfn_pte() which lets us use the common
definition of mk_pte().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 arch/x86/include/asm/pgtable.h | 19 +++----------------
 1 file changed, 3 insertions(+), 16 deletions(-)

diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index a7c1e9cfea41..59baf4e183b2 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -760,6 +760,9 @@ static inline pgprotval_t check_pgprot(pgprot_t pgprot)
 static inline pte_t pfn_pte(unsigned long page_nr, pgprot_t pgprot)
 {
 	phys_addr_t pfn = (phys_addr_t)page_nr << PAGE_SHIFT;
+	/* This bit combination is used to mark shadow stacks */
+	WARN_ON_ONCE((pgprot_val(pgprot) & (_PAGE_DIRTY | _PAGE_RW)) ==
+			_PAGE_DIRTY);
 	pfn ^= protnone_mask(pgprot_val(pgprot));
 	pfn &= PTE_PFN_MASK;
 	return __pte(pfn | check_pgprot(pgprot));
@@ -1056,22 +1059,6 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd)
  */
 #define pmd_page(pmd)	pfn_to_page(pmd_pfn(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.
- *
- * (Currently stuck as a macro because of indirect forward reference
- * to linux/mm.h:page_to_nid())
- */
-#define mk_pte(page, pgprot)						  \
-({									  \
-	pgprot_t __pgprot = pgprot;					  \
-									  \
-	WARN_ON_ONCE((pgprot_val(__pgprot) & (_PAGE_DIRTY | _PAGE_RW)) == \
-		    _PAGE_DIRTY);					  \
-	pfn_pte(page_to_pfn(page), __pgprot);				  \
-})
-
 static inline int pmd_bad(pmd_t pmd)
 {
 	return (pmd_flags(pmd) & ~(_PAGE_USER | _PAGE_ACCESSED)) !=
-- 
2.43.0



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 3/5] um: Remove custom definition of mk_pte()
  2024-08-14 15:44 [PATCH 0/5] Provide a single definition of mk_pte() Matthew Wilcox (Oracle)
  2024-08-14 15:44 ` [PATCH 1/5] mm: Introduce a common " Matthew Wilcox (Oracle)
  2024-08-14 15:44 ` [PATCH 2/5] x86: Remove custom " Matthew Wilcox (Oracle)
@ 2024-08-14 15:44 ` Matthew Wilcox (Oracle)
  2024-08-14 15:44 ` [PATCH 4/5] s390: " Matthew Wilcox (Oracle)
  2024-08-14 15:44 ` [PATCH 5/5] mm: Make mk_pte() definition unconditional Matthew Wilcox (Oracle)
  4 siblings, 0 replies; 11+ messages in thread
From: Matthew Wilcox (Oracle) @ 2024-08-14 15:44 UTC (permalink / raw)
  To: linux-mm, linux-arch; +Cc: Matthew Wilcox (Oracle), linux-s390, linux-um, x86

Move the pfn_pte() definitions from the 2level and 3level files to
the generic pgtable.h, move the setting of newprot and newpage bits
into pfn_pte() and delete the custom definition of mk_pte() so that
we use the central definition.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 arch/um/include/asm/pgtable-2level.h |  1 -
 arch/um/include/asm/pgtable-3level.h |  9 ---------
 arch/um/include/asm/pgtable.h        | 17 ++++++++++-------
 3 files changed, 10 insertions(+), 17 deletions(-)

diff --git a/arch/um/include/asm/pgtable-2level.h b/arch/um/include/asm/pgtable-2level.h
index 8256ecc5b919..2be7ba470abb 100644
--- a/arch/um/include/asm/pgtable-2level.h
+++ b/arch/um/include/asm/pgtable-2level.h
@@ -37,7 +37,6 @@ static inline void pgd_mkuptodate(pgd_t pgd)	{ }
 #define set_pmd(pmdptr, pmdval) (*(pmdptr) = (pmdval))
 
 #define pte_pfn(x) phys_to_pfn(pte_val(x))
-#define pfn_pte(pfn, prot) __pte(pfn_to_phys(pfn) | pgprot_val(prot))
 #define pfn_pmd(pfn, prot) __pmd(pfn_to_phys(pfn) | pgprot_val(prot))
 
 #endif
diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
index 8a5032ec231f..20870be83cfa 100644
--- a/arch/um/include/asm/pgtable-3level.h
+++ b/arch/um/include/asm/pgtable-3level.h
@@ -82,15 +82,6 @@ static inline unsigned long pte_pfn(pte_t pte)
 	return phys_to_pfn(pte_val(pte));
 }
 
-static inline pte_t pfn_pte(unsigned long page_nr, pgprot_t pgprot)
-{
-	pte_t pte;
-	phys_t phys = pfn_to_phys(page_nr);
-
-	pte_set_val(pte, phys, pgprot);
-	return pte;
-}
-
 static inline pmd_t pfn_pmd(unsigned long page_nr, pgprot_t pgprot)
 {
 	return __pmd((page_nr << PAGE_SHIFT) | pgprot_val(pgprot));
diff --git a/arch/um/include/asm/pgtable.h b/arch/um/include/asm/pgtable.h
index 5bb397b65efb..6ecc4c4ffeab 100644
--- a/arch/um/include/asm/pgtable.h
+++ b/arch/um/include/asm/pgtable.h
@@ -292,13 +292,16 @@ static inline int pte_same(pte_t pte_a, pte_t pte_b)
 #define page_to_phys(page) pfn_to_phys(page_to_pfn(page))
 #define virt_to_page(addr) __virt_to_page((const unsigned long) addr)
 
-#define mk_pte(page, pgprot) \
-	({ pte_t pte;					\
-							\
-	pte_set_val(pte, page_to_phys(page), (pgprot));	\
-	if (pte_present(pte))				\
-		pte_mknewprot(pte_mknewpage(pte));	\
-	pte;})
+static inline pte_t pfn_pte(unsigned long pfn, pgprot_t pgprot)
+{
+	pte_t pte;
+
+	pte_set_val(pte, pfn * PAGE_SIZE, pgprot);
+	if (pte_present(pte))
+		pte_mknewprot(pte_mknewpage(pte));
+
+	return pte;
+}
 
 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
 {
-- 
2.43.0



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 4/5] s390: Remove custom definition of mk_pte()
  2024-08-14 15:44 [PATCH 0/5] Provide a single definition of mk_pte() Matthew Wilcox (Oracle)
                   ` (2 preceding siblings ...)
  2024-08-14 15:44 ` [PATCH 3/5] um: " Matthew Wilcox (Oracle)
@ 2024-08-14 15:44 ` Matthew Wilcox (Oracle)
  2024-08-15 12:12   ` Alexander Gordeev
  2024-08-22 14:06   ` Alexander Gordeev
  2024-08-14 15:44 ` [PATCH 5/5] mm: Make mk_pte() definition unconditional Matthew Wilcox (Oracle)
  4 siblings, 2 replies; 11+ messages in thread
From: Matthew Wilcox (Oracle) @ 2024-08-14 15:44 UTC (permalink / raw)
  To: linux-mm, linux-arch; +Cc: Matthew Wilcox (Oracle), linux-s390, linux-um, x86

I believe the test for PageDirty() is no longer needed.  The
commit adding it was abf09bed3cce with the rationale that this
avoided faults for tmpfs and shmem pages.  shmem does not mark
newly allocated folios as dirty since 2016 (commit 75edd345e8ed)
so this test has been ineffective since then.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 arch/s390/include/asm/pgtable.h | 11 -----------
 1 file changed, 11 deletions(-)

diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
index 6a21d947a687..1bb7f33394d0 100644
--- a/arch/s390/include/asm/pgtable.h
+++ b/arch/s390/include/asm/pgtable.h
@@ -1413,17 +1413,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)
-{
-	unsigned long physpage = page_to_phys(page);
-	pte_t __pte = mk_pte_phys(physpage, pgprot);
-
-	if (pte_write(__pte) && PageDirty(page))
-		__pte = pte_mkdirty(__pte);
-	return __pte;
-}
-#define mk_pte mk_pte
-
 #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))
-- 
2.43.0



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 5/5] mm: Make mk_pte() definition unconditional
  2024-08-14 15:44 [PATCH 0/5] Provide a single definition of mk_pte() Matthew Wilcox (Oracle)
                   ` (3 preceding siblings ...)
  2024-08-14 15:44 ` [PATCH 4/5] s390: " Matthew Wilcox (Oracle)
@ 2024-08-14 15:44 ` Matthew Wilcox (Oracle)
  4 siblings, 0 replies; 11+ messages in thread
From: Matthew Wilcox (Oracle) @ 2024-08-14 15:44 UTC (permalink / raw)
  To: linux-mm, linux-arch; +Cc: Matthew Wilcox (Oracle), linux-s390, linux-um, x86

All architectures now use the common mk_pte() definition, so we
can remove the condition.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 include/linux/pgtable.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index 8204ffd87d74..1d46422b79cc 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -41,12 +41,10 @@
 #define FIRST_USER_ADDRESS	0UL
 #endif
 
-#ifndef mk_pte
 static inline pte_t mk_pte(struct page *page, pgprot_t pgprot)
 {
 	return pfn_pte(page_to_pfn(page), pgprot);
 }
-#endif
 
 /*
  * This defines the generic helper for accessing PMD page
-- 
2.43.0



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/5] mm: Introduce a common definition of mk_pte()
  2024-08-14 15:44 ` [PATCH 1/5] mm: Introduce a common " Matthew Wilcox (Oracle)
@ 2024-08-15  2:45   ` kernel test robot
  2024-08-15  2:45   ` kernel test robot
  1 sibling, 0 replies; 11+ messages in thread
From: kernel test robot @ 2024-08-15  2:45 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle), linux-mm, linux-arch
  Cc: oe-kbuild-all, Matthew Wilcox (Oracle), linux-s390, linux-um, x86

Hi Matthew,

kernel test robot noticed the following build errors:

[auto build test ERROR on geert-m68k/for-next]
[also build test ERROR on geert-m68k/for-linus uml/next linus/master v6.11-rc3 next-20240814]
[cannot apply to uml/fixes]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Matthew-Wilcox-Oracle/mm-Introduce-a-common-definition-of-mk_pte/20240815-001852
base:   https://git.kernel.org/pub/scm/linux/kernel/git/geert/linux-m68k.git for-next
patch link:    https://lore.kernel.org/r/20240814154427.162475-2-willy%40infradead.org
patch subject: [PATCH 1/5] mm: Introduce a common definition of mk_pte()
config: arc-allnoconfig (https://download.01.org/0day-ci/archive/20240815/202408151035.TtR6QRvZ-lkp@intel.com/config)
compiler: arc-elf-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240815/202408151035.TtR6QRvZ-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202408151035.TtR6QRvZ-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from arch/arc/include/asm/io.h:11,
                    from include/linux/io.h:14,
                    from lib/iomap_copy.c:7:
   include/linux/pgtable.h: In function 'mk_pte':
>> include/asm-generic/memory_model.h:19:59: error: 'mem_map' undeclared (first use in this function); did you mean 'memcmp'?
      19 | #define __page_to_pfn(page)     ((unsigned long)((page) - mem_map) + \
         |                                                           ^~~~~~~
   arch/arc/include/asm/page.h:75:37: note: in definition of macro '__pte'
      75 | #define __pte(x)        ((pte_t) { (x) })
         |                                     ^
   include/asm-generic/memory_model.h:62:33: note: in expansion of macro 'PFN_PHYS'
      62 | #define __pfn_to_phys(pfn)      PFN_PHYS(pfn)
         |                                 ^~~~~~~~
   arch/arc/include/asm/pgtable-levels.h:179:39: note: in expansion of macro '__pfn_to_phys'
     179 | #define pfn_pte(pfn, prot)      __pte(__pfn_to_phys(pfn) | pgprot_val(prot))
         |                                       ^~~~~~~~~~~~~
   include/linux/pgtable.h:47:16: note: in expansion of macro 'pfn_pte'
      47 |         return pfn_pte(page_to_pfn(page), pgprot);
         |                ^~~~~~~
   include/asm-generic/memory_model.h:64:21: note: in expansion of macro '__page_to_pfn'
      64 | #define page_to_pfn __page_to_pfn
         |                     ^~~~~~~~~~~~~
   include/linux/pgtable.h:47:24: note: in expansion of macro 'page_to_pfn'
      47 |         return pfn_pte(page_to_pfn(page), pgprot);
         |                        ^~~~~~~~~~~
   include/asm-generic/memory_model.h:19:59: note: each undeclared identifier is reported only once for each function it appears in
      19 | #define __page_to_pfn(page)     ((unsigned long)((page) - mem_map) + \
         |                                                           ^~~~~~~
   arch/arc/include/asm/page.h:75:37: note: in definition of macro '__pte'
      75 | #define __pte(x)        ((pte_t) { (x) })
         |                                     ^
   include/asm-generic/memory_model.h:62:33: note: in expansion of macro 'PFN_PHYS'
      62 | #define __pfn_to_phys(pfn)      PFN_PHYS(pfn)
         |                                 ^~~~~~~~
   arch/arc/include/asm/pgtable-levels.h:179:39: note: in expansion of macro '__pfn_to_phys'
     179 | #define pfn_pte(pfn, prot)      __pte(__pfn_to_phys(pfn) | pgprot_val(prot))
         |                                       ^~~~~~~~~~~~~
   include/linux/pgtable.h:47:16: note: in expansion of macro 'pfn_pte'
      47 |         return pfn_pte(page_to_pfn(page), pgprot);
         |                ^~~~~~~
   include/asm-generic/memory_model.h:64:21: note: in expansion of macro '__page_to_pfn'
      64 | #define page_to_pfn __page_to_pfn
         |                     ^~~~~~~~~~~~~
   include/linux/pgtable.h:47:24: note: in expansion of macro 'page_to_pfn'
      47 |         return pfn_pte(page_to_pfn(page), pgprot);
         |                        ^~~~~~~~~~~


vim +19 include/asm-generic/memory_model.h

a117e66ed45ac0 KAMEZAWA Hiroyuki 2006-03-27  17  
67de648211fa04 Andy Whitcroft    2006-06-23  18  #define __pfn_to_page(pfn)	(mem_map + ((pfn) - ARCH_PFN_OFFSET))
67de648211fa04 Andy Whitcroft    2006-06-23 @19  #define __page_to_pfn(page)	((unsigned long)((page) - mem_map) + \
a117e66ed45ac0 KAMEZAWA Hiroyuki 2006-03-27  20  				 ARCH_PFN_OFFSET)
a117e66ed45ac0 KAMEZAWA Hiroyuki 2006-03-27  21  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/5] mm: Introduce a common definition of mk_pte()
  2024-08-14 15:44 ` [PATCH 1/5] mm: Introduce a common " Matthew Wilcox (Oracle)
  2024-08-15  2:45   ` kernel test robot
@ 2024-08-15  2:45   ` kernel test robot
  1 sibling, 0 replies; 11+ messages in thread
From: kernel test robot @ 2024-08-15  2:45 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle), linux-mm, linux-arch
  Cc: oe-kbuild-all, Matthew Wilcox (Oracle), linux-s390, linux-um, x86

Hi Matthew,

kernel test robot noticed the following build errors:

[auto build test ERROR on geert-m68k/for-next]
[also build test ERROR on geert-m68k/for-linus uml/next linus/master v6.11-rc3 next-20240814]
[cannot apply to uml/fixes]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Matthew-Wilcox-Oracle/mm-Introduce-a-common-definition-of-mk_pte/20240815-001852
base:   https://git.kernel.org/pub/scm/linux/kernel/git/geert/linux-m68k.git for-next
patch link:    https://lore.kernel.org/r/20240814154427.162475-2-willy%40infradead.org
patch subject: [PATCH 1/5] mm: Introduce a common definition of mk_pte()
config: alpha-randconfig-r051-20240815 (https://download.01.org/0day-ci/archive/20240815/202408151008.zU4OfDoL-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 13.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240815/202408151008.zU4OfDoL-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202408151008.zU4OfDoL-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from arch/alpha/include/asm/page.h:89,
                    from include/linux/shm.h:6,
                    from include/linux/sched.h:23,
                    from arch/alpha/kernel/asm-offsets.c:10:
   include/linux/pgtable.h: In function 'mk_pte':
>> include/asm-generic/memory_model.h:47:21: error: implicit declaration of function 'page_to_section'; did you mean 'present_section'? [-Werror=implicit-function-declaration]
      47 |         int __sec = page_to_section(__pg);                      \
         |                     ^~~~~~~~~~~~~~~
   include/asm-generic/memory_model.h:64:21: note: in expansion of macro '__page_to_pfn'
      64 | #define page_to_pfn __page_to_pfn
         |                     ^~~~~~~~~~~~~
   include/linux/pgtable.h:47:24: note: in expansion of macro 'page_to_pfn'
      47 |         return pfn_pte(page_to_pfn(page), pgprot);
         |                        ^~~~~~~~~~~
   In file included from include/linux/pid_namespace.h:7,
                    from include/linux/ptrace.h:10,
                    from arch/alpha/kernel/asm-offsets.c:11:
   include/linux/mm.h: At top level:
>> include/linux/mm.h:1904:29: error: conflicting types for 'page_to_section'; have 'long unsigned int(const struct page *)'
    1904 | static inline unsigned long page_to_section(const struct page *page)
         |                             ^~~~~~~~~~~~~~~
   include/asm-generic/memory_model.h:47:21: note: previous implicit declaration of 'page_to_section' with type 'int()'
      47 |         int __sec = page_to_section(__pg);                      \
         |                     ^~~~~~~~~~~~~~~
   include/asm-generic/memory_model.h:64:21: note: in expansion of macro '__page_to_pfn'
      64 | #define page_to_pfn __page_to_pfn
         |                     ^~~~~~~~~~~~~
   include/linux/pgtable.h:47:24: note: in expansion of macro 'page_to_pfn'
      47 |         return pfn_pte(page_to_pfn(page), pgprot);
         |                        ^~~~~~~~~~~
   cc1: some warnings being treated as errors
   make[3]: *** [scripts/Makefile.build:117: arch/alpha/kernel/asm-offsets.s] Error 1
   make[3]: Target 'prepare' not remade because of errors.
   make[2]: *** [Makefile:1208: prepare0] Error 2
   make[2]: Target 'prepare' not remade because of errors.
   make[1]: *** [Makefile:240: __sub-make] Error 2
   make[1]: Target 'prepare' not remade because of errors.
   make: *** [Makefile:240: __sub-make] Error 2
   make: Target 'prepare' not remade because of errors.


vim +47 include/asm-generic/memory_model.h

8f6aac419bd590f Christoph Lameter 2007-10-16  39  
a117e66ed45ac05 KAMEZAWA Hiroyuki 2006-03-27  40  #elif defined(CONFIG_SPARSEMEM)
a117e66ed45ac05 KAMEZAWA Hiroyuki 2006-03-27  41  /*
1a49123b3434615 Zhang Yanfei      2013-10-03  42   * Note: section's mem_map is encoded to reflect its start_pfn.
a117e66ed45ac05 KAMEZAWA Hiroyuki 2006-03-27  43   * section[i].section_mem_map == mem_map's address - start_pfn;
a117e66ed45ac05 KAMEZAWA Hiroyuki 2006-03-27  44   */
67de648211fa041 Andy Whitcroft    2006-06-23  45  #define __page_to_pfn(pg)					\
aa462abe8aaf219 Ian Campbell      2011-08-17  46  ({	const struct page *__pg = (pg);				\
a117e66ed45ac05 KAMEZAWA Hiroyuki 2006-03-27 @47  	int __sec = page_to_section(__pg);			\
f05b6284ee5d3be Randy Dunlap      2007-02-10  48  	(unsigned long)(__pg - __section_mem_map_addr(__nr_to_section(__sec)));	\
a117e66ed45ac05 KAMEZAWA Hiroyuki 2006-03-27  49  })
a117e66ed45ac05 KAMEZAWA Hiroyuki 2006-03-27  50  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/5] x86: Remove custom definition of mk_pte()
  2024-08-14 15:44 ` [PATCH 2/5] x86: Remove custom " Matthew Wilcox (Oracle)
@ 2024-08-15  4:08   ` kernel test robot
  0 siblings, 0 replies; 11+ messages in thread
From: kernel test robot @ 2024-08-15  4:08 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle), linux-mm, linux-arch
  Cc: llvm, oe-kbuild-all, Matthew Wilcox (Oracle), linux-s390, linux-um, x86

Hi Matthew,

kernel test robot noticed the following build errors:

[auto build test ERROR on geert-m68k/for-next]
[also build test ERROR on geert-m68k/for-linus uml/next linus/master v6.11-rc3 next-20240814]
[cannot apply to uml/fixes]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Matthew-Wilcox-Oracle/mm-Introduce-a-common-definition-of-mk_pte/20240815-001852
base:   https://git.kernel.org/pub/scm/linux/kernel/git/geert/linux-m68k.git for-next
patch link:    https://lore.kernel.org/r/20240814154427.162475-3-willy%40infradead.org
patch subject: [PATCH 2/5] x86: Remove custom definition of mk_pte()
config: x86_64-buildonly-randconfig-003-20240815 (https://download.01.org/0day-ci/archive/20240815/202408151133.BaOdxDkR-lkp@intel.com/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240815/202408151133.BaOdxDkR-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202408151133.BaOdxDkR-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from arch/x86/kernel/asm-offsets.c:14:
   In file included from include/linux/suspend.h:5:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:21:
   In file included from include/linux/mm.h:30:
>> include/linux/pgtable.h:47:17: error: call to undeclared function 'page_to_section'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
      47 |         return pfn_pte(page_to_pfn(page), pgprot);
         |                        ^
   include/asm-generic/memory_model.h:64:21: note: expanded from macro 'page_to_pfn'
      64 | #define page_to_pfn __page_to_pfn
         |                     ^
   include/asm-generic/memory_model.h:47:14: note: expanded from macro '__page_to_pfn'
      47 |         int __sec = page_to_section(__pg);                      \
         |                     ^
   include/linux/pgtable.h:47:17: note: did you mean '__nr_to_section'?
   include/asm-generic/memory_model.h:64:21: note: expanded from macro 'page_to_pfn'
      64 | #define page_to_pfn __page_to_pfn
         |                     ^
   include/asm-generic/memory_model.h:47:14: note: expanded from macro '__page_to_pfn'
      47 |         int __sec = page_to_section(__pg);                      \
         |                     ^
   include/linux/mmzone.h:1853:35: note: '__nr_to_section' declared here
    1853 | static inline struct mem_section *__nr_to_section(unsigned long nr)
         |                                   ^
   In file included from arch/x86/kernel/asm-offsets.c:14:
   In file included from include/linux/suspend.h:5:
   In file included from include/linux/swap.h:9:
   In file included from include/linux/memcontrol.h:21:
>> include/linux/mm.h:1904:29: error: static declaration of 'page_to_section' follows non-static declaration
    1904 | static inline unsigned long page_to_section(const struct page *page)
         |                             ^
   include/linux/pgtable.h:47:17: note: previous implicit declaration is here
      47 |         return pfn_pte(page_to_pfn(page), pgprot);
         |                        ^
   include/asm-generic/memory_model.h:64:21: note: expanded from macro 'page_to_pfn'
      64 | #define page_to_pfn __page_to_pfn
         |                     ^
   include/asm-generic/memory_model.h:47:14: note: expanded from macro '__page_to_pfn'
      47 |         int __sec = page_to_section(__pg);                      \
         |                     ^
   2 errors generated.
   make[3]: *** [scripts/Makefile.build:117: arch/x86/kernel/asm-offsets.s] Error 1 shuffle=262036656
   make[3]: Target 'prepare' not remade because of errors.
   make[2]: *** [Makefile:1208: prepare0] Error 2 shuffle=262036656
   make[2]: Target 'prepare' not remade because of errors.
   make[1]: *** [Makefile:240: __sub-make] Error 2 shuffle=262036656
   make[1]: Target 'prepare' not remade because of errors.
   make: *** [Makefile:240: __sub-make] Error 2 shuffle=262036656
   make: Target 'prepare' not remade because of errors.


vim +/page_to_section +47 include/linux/pgtable.h

1c2f7d14d84f767 Anshuman Khandual       2021-06-30  43  
9353c36cfa235ae Matthew Wilcox (Oracle  2024-08-14  44) #ifndef mk_pte
9353c36cfa235ae Matthew Wilcox (Oracle  2024-08-14  45) static inline pte_t mk_pte(struct page *page, pgprot_t pgprot)
9353c36cfa235ae Matthew Wilcox (Oracle  2024-08-14  46) {
9353c36cfa235ae Matthew Wilcox (Oracle  2024-08-14 @47) 	return pfn_pte(page_to_pfn(page), pgprot);
9353c36cfa235ae Matthew Wilcox (Oracle  2024-08-14  48) }
9353c36cfa235ae Matthew Wilcox (Oracle  2024-08-14  49) #endif
9353c36cfa235ae Matthew Wilcox (Oracle  2024-08-14  50) 

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 4/5] s390: Remove custom definition of mk_pte()
  2024-08-14 15:44 ` [PATCH 4/5] s390: " Matthew Wilcox (Oracle)
@ 2024-08-15 12:12   ` Alexander Gordeev
  2024-08-22 14:06   ` Alexander Gordeev
  1 sibling, 0 replies; 11+ messages in thread
From: Alexander Gordeev @ 2024-08-15 12:12 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle),
	Gerald Schaefer, Heiko Carstens, Vasily Gorbik, Claudio Imbrenda,
	Christian Borntraeger
  Cc: linux-mm, linux-arch, linux-s390, linux-um, x86

On Wed, Aug 14, 2024 at 04:44:24PM +0100, Matthew Wilcox (Oracle) wrote:

Hi Matthew,

> I believe the test for PageDirty() is no longer needed.  The
> commit adding it was abf09bed3cce with the rationale that this
> avoided faults for tmpfs and shmem pages.  shmem does not mark
> newly allocated folios as dirty since 2016 (commit 75edd345e8ed)
> so this test has been ineffective since then.

We will investigate if that is really safe thing to do.
Some people on vacation, so we might be not too quick
with the response.

> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
>  arch/s390/include/asm/pgtable.h | 11 -----------
>  1 file changed, 11 deletions(-)
...

Thanks!


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 4/5] s390: Remove custom definition of mk_pte()
  2024-08-14 15:44 ` [PATCH 4/5] s390: " Matthew Wilcox (Oracle)
  2024-08-15 12:12   ` Alexander Gordeev
@ 2024-08-22 14:06   ` Alexander Gordeev
  1 sibling, 0 replies; 11+ messages in thread
From: Alexander Gordeev @ 2024-08-22 14:06 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle); +Cc: linux-mm, linux-arch, linux-s390, linux-um, x86

On Wed, Aug 14, 2024 at 04:44:24PM +0100, Matthew Wilcox (Oracle) wrote:

Hi Matthew,

> I believe the test for PageDirty() is no longer needed.  The
> commit adding it was abf09bed3cce with the rationale that this
> avoided faults for tmpfs and shmem pages.  shmem does not mark
> newly allocated folios as dirty since 2016 (commit 75edd345e8ed)
> so this test has been ineffective since then.

The PageDirty() test you suggest to remove is still entered.
I initially thought that test could also be useful for other
architectures as an optimization, but at least one path we
take for shmem mapping is raising eyebrow, because it is a
read accesss:

handle_pte_fault() -> do_pte_missing() -> do_fault() ->
do_read_fault() -> finish_fault() -> set_pte_range() -> mk_pte()

A read fault causing the PTE dirtifying is something strange
and your patch alone could be a nice cleanup.

As other architectures do not do such a trick suggests that
mk_pte() + pte_mkdirty() is called from the same handler
or pte_mkdirty() is expected to be called from a follow-up
write handler.

I could not identify locations where that would not be the case,
but may be you know?

...
> -static inline pte_t mk_pte(struct page *page, pgprot_t pgprot)
> -{
> -	unsigned long physpage = page_to_phys(page);
> -	pte_t __pte = mk_pte_phys(physpage, pgprot);
> -
> -	if (pte_write(__pte) && PageDirty(page))
> -		__pte = pte_mkdirty(__pte);
> -	return __pte;
> -}
> -#define mk_pte mk_pte

Thanks!


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-08-22 14:07 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-14 15:44 [PATCH 0/5] Provide a single definition of mk_pte() Matthew Wilcox (Oracle)
2024-08-14 15:44 ` [PATCH 1/5] mm: Introduce a common " Matthew Wilcox (Oracle)
2024-08-15  2:45   ` kernel test robot
2024-08-15  2:45   ` kernel test robot
2024-08-14 15:44 ` [PATCH 2/5] x86: Remove custom " Matthew Wilcox (Oracle)
2024-08-15  4:08   ` kernel test robot
2024-08-14 15:44 ` [PATCH 3/5] um: " Matthew Wilcox (Oracle)
2024-08-14 15:44 ` [PATCH 4/5] s390: " Matthew Wilcox (Oracle)
2024-08-15 12:12   ` Alexander Gordeev
2024-08-22 14:06   ` Alexander Gordeev
2024-08-14 15:44 ` [PATCH 5/5] mm: Make mk_pte() definition unconditional Matthew Wilcox (Oracle)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox