Skip to contentSkip to conversation

mm: pgtable: Make generic pgprot_* macros available for no-MMU

PATCH Superseded Pekka Enberg 3 participants 4 messages Jul 14, 2020

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 mm: pgtable: Make generic pgprot_* macros available for no-MMU

From: Pekka Enberg <[email protected]>

The <linux/pgtable.h> header defines some generic pgprot_* implementations, but they are only available when CONFIG_MMU is enabled. The RISC-V architecture, for example, therefore defines some of these pgprot_* macros for !NOMMU.

Let's make the pgprot_* generic available even for !NOMMU so we can remove the RISC-V specific definitions.

Compile-tested with x86 defconfig, and riscv defconfig and !MMU defconfig.

---
 include/linux/pgtable.h | 69 +++++++++++++++++++++--------------------
 1 file changed, 35 insertions(+), 34 deletions(-)
include/linux/pgtable.h +35 -34
index 56c1e8eb7bb0..ed9026ad7c31 100644
@@ -647,40 +647,6 @@ static inline int arch_unmap_one(struct mm_struct *mm,
 #define flush_tlb_fix_spurious_fault(vma, address) flush_tlb_page(vma, address)
 #endif
 
-#ifndef pgprot_nx
-#define pgprot_nx(prot)	(prot)
-#endif
-
-#ifndef pgprot_noncached
-#define pgprot_noncached(prot)	(prot)
-#endif
-
-#ifndef pgprot_writecombine
-#define pgprot_writecombine pgprot_noncached
-#endif
-
-#ifndef pgprot_writethrough
-#define pgprot_writethrough pgprot_noncached
-#endif
-
-#ifndef pgprot_device
-#define pgprot_device pgprot_noncached
-#endif
-
-#ifndef pgprot_modify
-#define pgprot_modify pgprot_modify
-static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
-{
-	if (pgprot_val(oldprot) == pgprot_val(pgprot_noncached(oldprot)))
-		newprot = pgprot_noncached(newprot);
-	if (pgprot_val(oldprot) == pgprot_val(pgprot_writecombine(oldprot)))
-		newprot = pgprot_writecombine(newprot);
-	if (pgprot_val(oldprot) == pgprot_val(pgprot_device(oldprot)))
-		newprot = pgprot_device(newprot);
-	return newprot;
-}
-#endif
-
 /*
  * When walking page tables, get the address of the next boundary,
  * or the end address of the range if that comes earlier.  Although no
@@ -840,6 +806,41 @@ static inline void ptep_modify_prot_commit(struct vm_area_struct *vma,
  * No-op macros that just return the current protection value. Defined here
  * because these macros can be used used even if CONFIG_MMU is not defined.
  */
+
+#ifndef pgprot_nx
+#define pgprot_nx(prot)	(prot)
+#endif
+
+#ifndef pgprot_noncached
+#define pgprot_noncached(prot)	(prot)
+#endif
+
+#ifndef pgprot_writecombine
+#define pgprot_writecombine pgprot_noncached
+#endif
+
+#ifndef pgprot_writethrough
+#define pgprot_writethrough pgprot_noncached
+#endif
+
+#ifndef pgprot_device
+#define pgprot_device pgprot_noncached
+#endif
+
+#ifndef pgprot_modify
+#define pgprot_modify pgprot_modify
+static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
+{
+	if (pgprot_val(oldprot) == pgprot_val(pgprot_noncached(oldprot)))
+		newprot = pgprot_noncached(newprot);
+	if (pgprot_val(oldprot) == pgprot_val(pgprot_writecombine(oldprot)))
+		newprot = pgprot_writecombine(newprot);
+	if (pgprot_val(oldprot) == pgprot_val(pgprot_device(oldprot)))
+		newprot = pgprot_device(newprot);
+	return newprot;
+}
+#endif
+
 #ifndef pgprot_encrypted
 #define pgprot_encrypted(prot)	(prot)
 #endif
Signature · 1 line
2.26.2
#1 lore raw

PATCH 2/2 riscv: Use generic pgprot_* macros from <linux/pgtable.h>

From: Pekka Enberg <[email protected]>

The <linux/pgtable.h> header now defines generic pgprot_ macros also for the no-MMU configuration, so let's use them.

Cc Palmer Dabbelt <[email protected]>
---
 arch/riscv/include/asm/mmio.h | 6 ------
 1 file changed, 6 deletions(-)
arch/riscv/include/asm/mmio.h +0 -6
index 56053c9838b2..aff6c33ab0c0 100644
@@ -14,12 +14,6 @@
 #include <linux/types.h>
 #include <asm/mmiowb.h>
 
-#ifndef CONFIG_MMU
-#define pgprot_noncached(x)	(x)
-#define pgprot_writecombine(x)	(x)
-#define pgprot_device(x)	(x)
-#endif /* CONFIG_MMU */
-
 /* Generic IO read/write.  These perform native-endian accesses. */
 #define __raw_writeb __raw_writeb
 static inline void __raw_writeb(u8 val, volatile void __iomem *addr)
Signature · 1 line
2.26.2
Reviewed-by on v1 1/2
#2 lore raw
In reply to Pekka Enberg
Quoted 10 lines · Pekka Enberg

From: Pekka Enberg <[email protected]>

The <linux/pgtable.h> header defines some generic pgprot_* implementations, but they are only available when CONFIG_MMU is enabled. The RISC-V architecture, for example, therefore defines some of these pgprot_* macros for !NOMMU.

Let's make the pgprot_* generic available even for !NOMMU so we can remove the RISC-V specific definitions.

Quoted 6 lines

Compile-tested with x86 defconfig, and riscv defconfig and !MMU defconfig.

Quoted 94 lines
---
 include/linux/pgtable.h | 69 +++++++++++++++++++++--------------------
 1 file changed, 35 insertions(+), 34 deletions(-)
include/linux/pgtable.h +35 -34
index 56c1e8eb7bb0..ed9026ad7c31 100644
@@ -647,40 +647,6 @@ static inline int arch_unmap_one(struct mm_struct *mm,
 #define flush_tlb_fix_spurious_fault(vma, address) flush_tlb_page(vma, address)
 #endif
 
-#ifndef pgprot_nx
-#define pgprot_nx(prot)	(prot)
-#endif
-
-#ifndef pgprot_noncached
-#define pgprot_noncached(prot)	(prot)
-#endif
-
-#ifndef pgprot_writecombine
-#define pgprot_writecombine pgprot_noncached
-#endif
-
-#ifndef pgprot_writethrough
-#define pgprot_writethrough pgprot_noncached
-#endif
-
-#ifndef pgprot_device
-#define pgprot_device pgprot_noncached
-#endif
-
-#ifndef pgprot_modify
-#define pgprot_modify pgprot_modify
-static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
-{
-	if (pgprot_val(oldprot) == pgprot_val(pgprot_noncached(oldprot)))
-		newprot = pgprot_noncached(newprot);
-	if (pgprot_val(oldprot) == pgprot_val(pgprot_writecombine(oldprot)))
-		newprot = pgprot_writecombine(newprot);
-	if (pgprot_val(oldprot) == pgprot_val(pgprot_device(oldprot)))
-		newprot = pgprot_device(newprot);
-	return newprot;
-}
-#endif
-
 /*
  * When walking page tables, get the address of the next boundary,
  * or the end address of the range if that comes earlier.  Although no
@@ -840,6 +806,41 @@ static inline void ptep_modify_prot_commit(struct vm_area_struct *vma,
  * No-op macros that just return the current protection value. Defined here
  * because these macros can be used used even if CONFIG_MMU is not defined.
  */
+
+#ifndef pgprot_nx
+#define pgprot_nx(prot)	(prot)
+#endif
+
+#ifndef pgprot_noncached
+#define pgprot_noncached(prot)	(prot)
+#endif
+
+#ifndef pgprot_writecombine
+#define pgprot_writecombine pgprot_noncached
+#endif
+
+#ifndef pgprot_writethrough
+#define pgprot_writethrough pgprot_noncached
+#endif
+
+#ifndef pgprot_device
+#define pgprot_device pgprot_noncached
+#endif
+
+#ifndef pgprot_modify
+#define pgprot_modify pgprot_modify
+static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
+{
+	if (pgprot_val(oldprot) == pgprot_val(pgprot_noncached(oldprot)))
+		newprot = pgprot_noncached(newprot);
+	if (pgprot_val(oldprot) == pgprot_val(pgprot_writecombine(oldprot)))
+		newprot = pgprot_writecombine(newprot);
+	if (pgprot_val(oldprot) == pgprot_val(pgprot_device(oldprot)))
+		newprot = pgprot_device(newprot);
+	return newprot;
+}
+#endif
+
 #ifndef pgprot_encrypted
 #define pgprot_encrypted(prot)	(prot)
 #endif
Signature · 1 line
2.26.2
Signature · 2 lines
Sincerely yours,
Mike.
#3 lore raw
In reply to Pekka Enberg
I love your patch! Yet something to improve:

Hi Pekka,

I love your patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.8-rc5 next-20200714]
[cannot apply to mmotm/master]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Pekka-Enberg/mm-pgtable-Make-generic-pgprot_-macros-available-for-no-MMU/20200714-180502
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 0dc589da873b58b70f4caf4b070fb0cf70fdd1dc
config: arm-randconfig-r033-20200714 (attached as .config)
compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

In file included from include/linux/mm.h:32,
from include/linux/scatterlist.h:8, from include/linux/dma-mapping.h:11, from drivers/gpu/drm/tilcdc/tilcdc_crtc.c:8:
include/linux/pgtable.h: In function 'pgprot_modify':

>> include/linux/pgtable.h:834:26: error: self-comparison always evaluates to true [-Werror=tautological-compare]
     834 |  if (pgprot_val(oldprot) == pgprot_val(pgprot_noncached(oldprot)))
         |                          ^~
   include/linux/pgtable.h:836:26: error: self-comparison always evaluates to true [-Werror=tautological-compare]
     836 |  if (pgprot_val(oldprot) == pgprot_val(pgprot_writecombine(oldprot)))
         |                          ^~
   include/linux/pgtable.h:838:26: error: self-comparison always evaluates to true [-Werror=tautological-compare]
     838 |  if (pgprot_val(oldprot) == pgprot_val(pgprot_device(oldprot)))
         |                          ^~

cc1: all warnings being treated as errors

vim +834 include/linux/pgtable.h

829
830 #ifndef pgprot_modify
831 #define pgprot_modify pgprot_modify
832 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
833 {

 > 834		if (pgprot_val(oldprot) == pgprot_val(pgprot_noncached(oldprot)))

835 newprot = pgprot_noncached(newprot);
836 if (pgprot_val(oldprot) == pgprot_val(pgprot_writecombine(oldprot)))
837 newprot = pgprot_writecombine(newprot);
838 if (pgprot_val(oldprot) == pgprot_val(pgprot_device(oldprot)))
839 newprot = pgprot_device(newprot);
840 return newprot;
841 }
842 #endif
843

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org