diff mbox series

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

Message ID 20200714100051.345018-1-penberg@gmail.com (mailing list archive)
State New, archived
Headers show
Series [1/2] mm: pgtable: Make generic pgprot_* macros available for no-MMU | expand

Commit Message

Pekka Enberg July 14, 2020, 10 a.m. UTC
From: Pekka Enberg <penberg@kernel.org>

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.

Suggested-by: Palmer Dabbelt <palmerdabbelt@google.com>
Cc: Mike Rapoport <rppt@linux.ibm.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
---
 include/linux/pgtable.h | 69 +++++++++++++++++++++--------------------
 1 file changed, 35 insertions(+), 34 deletions(-)

Comments

Mike Rapoport July 14, 2020, 11:53 a.m. UTC | #1
On Tue, Jul 14, 2020 at 01:00:50PM +0300, Pekka Enberg wrote:
> From: Pekka Enberg <penberg@kernel.org>
> 
> 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.
> 
> Suggested-by: Palmer Dabbelt <palmerdabbelt@google.com>
> Cc: Mike Rapoport <rppt@linux.ibm.com>
> Cc: Tom Lendacky <thomas.lendacky@amd.com>
> Signed-off-by: Pekka Enberg <penberg@kernel.org>

Reviewed-by: Mike Rapoport <rppt@linux.ibm.com>

> ---
>  include/linux/pgtable.h | 69 +++++++++++++++++++++--------------------
>  1 file changed, 35 insertions(+), 34 deletions(-)
> 
> diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
> index 56c1e8eb7bb0..ed9026ad7c31 100644
> --- a/include/linux/pgtable.h
> +++ b/include/linux/pgtable.h
> @@ -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
> -- 
> 2.26.2
>
kernel test robot July 14, 2020, 8:42 p.m. UTC | #2
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
Reported-by: kernel test robot <lkp@intel.com>

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@lists.01.org
diff mbox series

Patch

diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index 56c1e8eb7bb0..ed9026ad7c31 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -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