Re: [PATCH v2 5/9] mm: Initialize struct vm_unmapped_area_info

2024-02-26 Thread Christophe Leroy


Le 26/02/2024 à 20:09, Rick Edgecombe a écrit :
> Future changes will need to add a field to struct vm_unmapped_area_info.
> This would cause trouble for any archs that don't initialize the
> struct. Currently every user sets each field, so if new fields are
> added, the core code parsing the struct will see garbage in the new
> field.
> 
> It could be possible to initialize the new field for each arch to 0, but
> instead simply inialize the field with a C99 struct inializing syntax.

Why doing a full init of the struct when all fields are re-written a few 
lines after ?

If I take the exemple of powerpc function slice_find_area_bottomup():

struct vm_unmapped_area_info info;

info.flags = 0;
info.length = len;
info.align_mask = PAGE_MASK & ((1ul << pshift) - 1);
info.align_offset = 0;

For me it looks better to just add:

info.new_field = 0; /* or whatever value it needs to have */

Christophe


> 
> Cc: linux...@kvack.org
> Cc: linux-alpha@vger.kernel.org
> Cc: linux-snps-...@lists.infradead.org
> Cc: linux-arm-ker...@lists.infradead.org
> Cc: linux-c...@vger.kernel.org
> Cc: loonga...@lists.linux.dev
> Cc: linux-m...@vger.kernel.org
> Cc: linux-par...@vger.kernel.org
> Cc: linuxppc-...@lists.ozlabs.org
> Cc: linux-s...@vger.kernel.org
> Cc: linux...@vger.kernel.org
> Cc: sparcli...@vger.kernel.org
> Cc: x...@kernel.org
> Suggested-by: Kirill A. Shutemov 
> Signed-off-by: Rick Edgecombe 
> Link: 
> https://lore.kernel.org/lkml/3ynogxcgokc6i6xojbxzzwqectg472laes24u7jmtktlxcch5e@dfytra3ia3zc/#t
> ---
> Hi archs,
> 
> For some context, this is part of a larger series to improve shadow stack
> guard gaps. It involves plumbing a new field via
> struct vm_unmapped_area_info. The first user is x86, but arm and riscv may
> likely use it as well. The change is compile tested only for non-x86 but
> seems like a relatively safe one.
> 
> Thanks,
> 
> Rick
> 
> v2:
>   - New patch
> ---
>   arch/alpha/kernel/osf_sys.c  | 2 +-
>   arch/arc/mm/mmap.c   | 2 +-
>   arch/arm/mm/mmap.c   | 4 ++--
>   arch/csky/abiv1/mmap.c   | 2 +-
>   arch/loongarch/mm/mmap.c | 2 +-
>   arch/mips/mm/mmap.c  | 2 +-
>   arch/parisc/kernel/sys_parisc.c  | 2 +-
>   arch/powerpc/mm/book3s64/slice.c | 4 ++--
>   arch/s390/mm/hugetlbpage.c   | 4 ++--
>   arch/s390/mm/mmap.c  | 4 ++--
>   arch/sh/mm/mmap.c| 4 ++--
>   arch/sparc/kernel/sys_sparc_32.c | 2 +-
>   arch/sparc/kernel/sys_sparc_64.c | 4 ++--
>   arch/sparc/mm/hugetlbpage.c  | 4 ++--
>   arch/x86/kernel/sys_x86_64.c | 4 ++--
>   arch/x86/mm/hugetlbpage.c| 4 ++--
>   fs/hugetlbfs/inode.c | 4 ++--
>   mm/mmap.c| 4 ++--
>   18 files changed, 29 insertions(+), 29 deletions(-)
> 
> diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
> index 5db88b627439..dd6801bb9240 100644
> --- a/arch/alpha/kernel/osf_sys.c
> +++ b/arch/alpha/kernel/osf_sys.c
> @@ -1218,7 +1218,7 @@ static unsigned long
>   arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
>unsigned long limit)
>   {
> - struct vm_unmapped_area_info info;
> + struct vm_unmapped_area_info info = {};
>   
>   info.flags = 0;
>   info.length = len;
> diff --git a/arch/arc/mm/mmap.c b/arch/arc/mm/mmap.c
> index 3c1c7ae73292..6549b3375f54 100644
> --- a/arch/arc/mm/mmap.c
> +++ b/arch/arc/mm/mmap.c
> @@ -27,7 +27,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long 
> addr,
>   {
>   struct mm_struct *mm = current->mm;
>   struct vm_area_struct *vma;
> - struct vm_unmapped_area_info info;
> + struct vm_unmapped_area_info info = {};
>   
>   /*
>* We enforce the MAP_FIXED case.
> diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
> index a0f8a0ca0788..525795578c29 100644
> --- a/arch/arm/mm/mmap.c
> +++ b/arch/arm/mm/mmap.c
> @@ -34,7 +34,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long 
> addr,
>   struct vm_area_struct *vma;
>   int do_align = 0;
>   int aliasing = cache_is_vipt_aliasing();
> - struct vm_unmapped_area_info info;
> + struct vm_unmapped_area_info info = {};
>   
>   /*
>* We only need to do colour alignment if either the I or D
> @@ -87,7 +87,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const 
> unsigned long addr0,
>   unsigned long addr = addr0;
>   int do_align = 0;
>   int aliasing = cache_is_vipt_aliasing();
> - struct vm_unmapped_area_info info;
> + struct vm_unmapped_area_info info = {};
>   
>   /*
>* We only need to do colour alignment if either the I or D
> diff --git a/arch/csky/abiv1/mmap.c b/arch/csky/abiv1/mmap.c
> index 6792aca4..726659d41fa9 100644
> --- a/arch/csky/abiv1/mmap.c
> +++ b/arch/csky/abiv1/mmap.c
> @@ -28,7 +28,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long 
> addr,
>   struct mm_struct *mm = 

Re: [PATCH 3/4] arch: define CONFIG_PAGE_SIZE_*KB on all architectures

2024-02-26 Thread Guo Ren
On Tue, Feb 27, 2024 at 12:15 AM Arnd Bergmann  wrote:
>
> From: Arnd Bergmann 
>
> Most architectures only support a single hardcoded page size. In order
> to ensure that each one of these sets the corresponding Kconfig symbols,
> change over the PAGE_SHIFT definition to the common one and allow
> only the hardware page size to be selected.
>
> Signed-off-by: Arnd Bergmann 
> ---
>  arch/alpha/Kconfig | 1 +
>  arch/alpha/include/asm/page.h  | 2 +-
>  arch/arm/Kconfig   | 1 +
>  arch/arm/include/asm/page.h| 2 +-
>  arch/csky/Kconfig  | 1 +
>  arch/csky/include/asm/page.h   | 2 +-
>  arch/m68k/Kconfig  | 3 +++
>  arch/m68k/Kconfig.cpu  | 2 ++
>  arch/m68k/include/asm/page.h   | 6 +-
>  arch/microblaze/Kconfig| 1 +
>  arch/microblaze/include/asm/page.h | 2 +-
>  arch/nios2/Kconfig | 1 +
>  arch/nios2/include/asm/page.h  | 2 +-
>  arch/openrisc/Kconfig  | 1 +
>  arch/openrisc/include/asm/page.h   | 2 +-
>  arch/riscv/Kconfig | 1 +
>  arch/riscv/include/asm/page.h  | 2 +-
>  arch/s390/Kconfig  | 1 +
>  arch/s390/include/asm/page.h   | 2 +-
>  arch/sparc/Kconfig | 2 ++
>  arch/sparc/include/asm/page_32.h   | 2 +-
>  arch/sparc/include/asm/page_64.h   | 3 +--
>  arch/um/Kconfig| 1 +
>  arch/um/include/asm/page.h | 2 +-
>  arch/x86/Kconfig   | 1 +
>  arch/x86/include/asm/page_types.h  | 2 +-
>  arch/xtensa/Kconfig| 1 +
>  arch/xtensa/include/asm/page.h | 2 +-
>  28 files changed, 32 insertions(+), 19 deletions(-)
>
> diff --git a/arch/alpha/Kconfig b/arch/alpha/Kconfig
> index d6968d090d49..4f490250d323 100644
> --- a/arch/alpha/Kconfig
> +++ b/arch/alpha/Kconfig
> @@ -14,6 +14,7 @@ config ALPHA
> select PCI_DOMAINS if PCI
> select PCI_SYSCALL if PCI
> select HAVE_ASM_MODVERSIONS
> +   select HAVE_PAGE_SIZE_8KB
> select HAVE_PCSPKR_PLATFORM
> select HAVE_PERF_EVENTS
> select NEED_DMA_MAP_STATE
> diff --git a/arch/alpha/include/asm/page.h b/arch/alpha/include/asm/page.h
> index 4db1ebc0ed99..70419e6be1a3 100644
> --- a/arch/alpha/include/asm/page.h
> +++ b/arch/alpha/include/asm/page.h
> @@ -6,7 +6,7 @@
>  #include 
>
>  /* PAGE_SHIFT determines the page size */
> -#define PAGE_SHIFT 13
> +#define PAGE_SHIFT CONFIG_PAGE_SHIFT
>  #define PAGE_SIZE  (_AC(1,UL) << PAGE_SHIFT)
>  #define PAGE_MASK  (~(PAGE_SIZE-1))
>
> diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
> index 0af6709570d1..9d52ba3a8ad1 100644
> --- a/arch/arm/Kconfig
> +++ b/arch/arm/Kconfig
> @@ -116,6 +116,7 @@ config ARM
> select HAVE_MOD_ARCH_SPECIFIC
> select HAVE_NMI
> select HAVE_OPTPROBES if !THUMB2_KERNEL
> +   select HAVE_PAGE_SIZE_4KB
> select HAVE_PCI if MMU
> select HAVE_PERF_EVENTS
> select HAVE_PERF_REGS
> diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
> index 119aa85d1feb..62af9f7f9e96 100644
> --- a/arch/arm/include/asm/page.h
> +++ b/arch/arm/include/asm/page.h
> @@ -8,7 +8,7 @@
>  #define _ASMARM_PAGE_H
>
>  /* PAGE_SHIFT determines the page size */
> -#define PAGE_SHIFT 12
> +#define PAGE_SHIFT CONFIG_PAGE_SHIFT
>  #define PAGE_SIZE  (_AC(1,UL) << PAGE_SHIFT)
>  #define PAGE_MASK  (~((1 << PAGE_SHIFT) - 1))
>
> diff --git a/arch/csky/Kconfig b/arch/csky/Kconfig
> index cf2a6fd7dff8..9c2723ab1c94 100644
> --- a/arch/csky/Kconfig
> +++ b/arch/csky/Kconfig
> @@ -89,6 +89,7 @@ config CSKY
> select HAVE_KPROBES if !CPU_CK610
> select HAVE_KPROBES_ON_FTRACE if !CPU_CK610
> select HAVE_KRETPROBES if !CPU_CK610
> +   select HAVE_PAGE_SIZE_4KB
> select HAVE_PERF_EVENTS
> select HAVE_PERF_REGS
> select HAVE_PERF_USER_STACK_DUMP
> diff --git a/arch/csky/include/asm/page.h b/arch/csky/include/asm/page.h
> index 4a0502e324a6..f70f37402d75 100644
> --- a/arch/csky/include/asm/page.h
> +++ b/arch/csky/include/asm/page.h
> @@ -10,7 +10,7 @@
>  /*
>   * PAGE_SHIFT determines the page size: 4KB
>   */
> -#define PAGE_SHIFT 12
> +#define PAGE_SHIFT CONFIG_PAGE_SHIFT
LGTM, thx.
Acked-by: Guo Ren 

>  #define PAGE_SIZE  (_AC(1, UL) << PAGE_SHIFT)
>  #define PAGE_MASK  (~(PAGE_SIZE - 1))
>  #define THREAD_SIZE(PAGE_SIZE * 2)
> diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig
> index 4b3e93cac723..7b709453d5e7 100644
> --- a/arch/m68k/Kconfig
> +++ b/arch/m68k/Kconfig
> @@ -84,12 +84,15 @@ config MMU
>
>  config MMU_MOTOROLA
> bool
> +   select HAVE_PAGE_SIZE_4KB
>
>  config MMU_COLDFIRE
> +   select HAVE_PAGE_SIZE_8KB
> bool
>
>  config MMU_SUN3
> bool
> +   select HAVE_PAGE_SIZE_8KB
> depends on MMU && !MMU_MOTOROLA && !MMU_COLDFIRE
>
>  config ARCH_SUPPORTS_KEXEC
> diff --git 

[PATCH v2 5/9] mm: Initialize struct vm_unmapped_area_info

2024-02-26 Thread Rick Edgecombe
Future changes will need to add a field to struct vm_unmapped_area_info.
This would cause trouble for any archs that don't initialize the
struct. Currently every user sets each field, so if new fields are
added, the core code parsing the struct will see garbage in the new
field.

It could be possible to initialize the new field for each arch to 0, but
instead simply inialize the field with a C99 struct inializing syntax.

Cc: linux...@kvack.org
Cc: linux-alpha@vger.kernel.org
Cc: linux-snps-...@lists.infradead.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-c...@vger.kernel.org
Cc: loonga...@lists.linux.dev
Cc: linux-m...@vger.kernel.org
Cc: linux-par...@vger.kernel.org
Cc: linuxppc-...@lists.ozlabs.org
Cc: linux-s...@vger.kernel.org
Cc: linux...@vger.kernel.org
Cc: sparcli...@vger.kernel.org
Cc: x...@kernel.org
Suggested-by: Kirill A. Shutemov 
Signed-off-by: Rick Edgecombe 
Link: 
https://lore.kernel.org/lkml/3ynogxcgokc6i6xojbxzzwqectg472laes24u7jmtktlxcch5e@dfytra3ia3zc/#t
---
Hi archs,

For some context, this is part of a larger series to improve shadow stack
guard gaps. It involves plumbing a new field via
struct vm_unmapped_area_info. The first user is x86, but arm and riscv may
likely use it as well. The change is compile tested only for non-x86 but
seems like a relatively safe one.

Thanks,

Rick

v2:
 - New patch
---
 arch/alpha/kernel/osf_sys.c  | 2 +-
 arch/arc/mm/mmap.c   | 2 +-
 arch/arm/mm/mmap.c   | 4 ++--
 arch/csky/abiv1/mmap.c   | 2 +-
 arch/loongarch/mm/mmap.c | 2 +-
 arch/mips/mm/mmap.c  | 2 +-
 arch/parisc/kernel/sys_parisc.c  | 2 +-
 arch/powerpc/mm/book3s64/slice.c | 4 ++--
 arch/s390/mm/hugetlbpage.c   | 4 ++--
 arch/s390/mm/mmap.c  | 4 ++--
 arch/sh/mm/mmap.c| 4 ++--
 arch/sparc/kernel/sys_sparc_32.c | 2 +-
 arch/sparc/kernel/sys_sparc_64.c | 4 ++--
 arch/sparc/mm/hugetlbpage.c  | 4 ++--
 arch/x86/kernel/sys_x86_64.c | 4 ++--
 arch/x86/mm/hugetlbpage.c| 4 ++--
 fs/hugetlbfs/inode.c | 4 ++--
 mm/mmap.c| 4 ++--
 18 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
index 5db88b627439..dd6801bb9240 100644
--- a/arch/alpha/kernel/osf_sys.c
+++ b/arch/alpha/kernel/osf_sys.c
@@ -1218,7 +1218,7 @@ static unsigned long
 arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
 unsigned long limit)
 {
-   struct vm_unmapped_area_info info;
+   struct vm_unmapped_area_info info = {};
 
info.flags = 0;
info.length = len;
diff --git a/arch/arc/mm/mmap.c b/arch/arc/mm/mmap.c
index 3c1c7ae73292..6549b3375f54 100644
--- a/arch/arc/mm/mmap.c
+++ b/arch/arc/mm/mmap.c
@@ -27,7 +27,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
 {
struct mm_struct *mm = current->mm;
struct vm_area_struct *vma;
-   struct vm_unmapped_area_info info;
+   struct vm_unmapped_area_info info = {};
 
/*
 * We enforce the MAP_FIXED case.
diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
index a0f8a0ca0788..525795578c29 100644
--- a/arch/arm/mm/mmap.c
+++ b/arch/arm/mm/mmap.c
@@ -34,7 +34,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
struct vm_area_struct *vma;
int do_align = 0;
int aliasing = cache_is_vipt_aliasing();
-   struct vm_unmapped_area_info info;
+   struct vm_unmapped_area_info info = {};
 
/*
 * We only need to do colour alignment if either the I or D
@@ -87,7 +87,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const 
unsigned long addr0,
unsigned long addr = addr0;
int do_align = 0;
int aliasing = cache_is_vipt_aliasing();
-   struct vm_unmapped_area_info info;
+   struct vm_unmapped_area_info info = {};
 
/*
 * We only need to do colour alignment if either the I or D
diff --git a/arch/csky/abiv1/mmap.c b/arch/csky/abiv1/mmap.c
index 6792aca4..726659d41fa9 100644
--- a/arch/csky/abiv1/mmap.c
+++ b/arch/csky/abiv1/mmap.c
@@ -28,7 +28,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
struct mm_struct *mm = current->mm;
struct vm_area_struct *vma;
int do_align = 0;
-   struct vm_unmapped_area_info info;
+   struct vm_unmapped_area_info info = {};
 
/*
 * We only need to do colour alignment if either the I or D
diff --git a/arch/loongarch/mm/mmap.c b/arch/loongarch/mm/mmap.c
index a9630a81b38a..664bf4abfdcf 100644
--- a/arch/loongarch/mm/mmap.c
+++ b/arch/loongarch/mm/mmap.c
@@ -24,7 +24,7 @@ static unsigned long arch_get_unmapped_area_common(struct 
file *filp,
struct vm_area_struct *vma;
unsigned long addr = addr0;
int do_color_align;
-   struct vm_unmapped_area_info info;
+   struct vm_unmapped_area_info info = {};
 
if (unlikely(len > TASK_SIZE))
   

Re: [PATCH 2/4] arch: simplify architecture specific page size configuration

2024-02-26 Thread Christophe Leroy


Le 26/02/2024 à 17:14, Arnd Bergmann a écrit :
> From: Arnd Bergmann 
> 
> arc, arm64, parisc and powerpc all have their own Kconfig symbols
> in place of the common CONFIG_PAGE_SIZE_4KB symbols. Change these
> so the common symbols are the ones that are actually used, while
> leaving the arhcitecture specific ones as the user visible
> place for configuring it, to avoid breaking user configs.
> 
> Signed-off-by: Arnd Bergmann 

Reviewed-by: Christophe Leroy  (powerpc32)

> ---
>   arch/arc/Kconfig  |  3 +++
>   arch/arc/include/uapi/asm/page.h  |  6 ++
>   arch/arm64/Kconfig| 29 +
>   arch/arm64/include/asm/page-def.h |  2 +-
>   arch/parisc/Kconfig   |  3 +++
>   arch/parisc/include/asm/page.h| 10 +-
>   arch/powerpc/Kconfig  | 31 ++-
>   arch/powerpc/include/asm/page.h   |  2 +-
>   scripts/gdb/linux/constants.py.in |  2 +-
>   scripts/gdb/linux/mm.py   |  2 +-
>   10 files changed, 32 insertions(+), 58 deletions(-)
> 
> diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig
> index 1b0483c51cc1..4092bec198be 100644
> --- a/arch/arc/Kconfig
> +++ b/arch/arc/Kconfig
> @@ -284,14 +284,17 @@ choice
>   
>   config ARC_PAGE_SIZE_8K
>   bool "8KB"
> + select HAVE_PAGE_SIZE_8KB
>   help
> Choose between 8k vs 16k
>   
>   config ARC_PAGE_SIZE_16K
> + select HAVE_PAGE_SIZE_16KB
>   bool "16KB"
>   
>   config ARC_PAGE_SIZE_4K
>   bool "4KB"
> + select HAVE_PAGE_SIZE_4KB
>   depends on ARC_MMU_V3 || ARC_MMU_V4
>   
>   endchoice
> diff --git a/arch/arc/include/uapi/asm/page.h 
> b/arch/arc/include/uapi/asm/page.h
> index 2a4ad619abfb..7fd9e741b527 100644
> --- a/arch/arc/include/uapi/asm/page.h
> +++ b/arch/arc/include/uapi/asm/page.h
> @@ -13,10 +13,8 @@
>   #include 
>   
>   /* PAGE_SHIFT determines the page size */
> -#if defined(CONFIG_ARC_PAGE_SIZE_16K)
> -#define PAGE_SHIFT 14
> -#elif defined(CONFIG_ARC_PAGE_SIZE_4K)
> -#define PAGE_SHIFT 12
> +#ifdef __KERNEL__
> +#define PAGE_SHIFT CONFIG_PAGE_SHIFT
>   #else
>   /*
>* Default 8k
> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> index aa7c1d435139..29290b8cb36d 100644
> --- a/arch/arm64/Kconfig
> +++ b/arch/arm64/Kconfig
> @@ -277,27 +277,21 @@ config 64BIT
>   config MMU
>   def_bool y
>   
> -config ARM64_PAGE_SHIFT
> - int
> - default 16 if ARM64_64K_PAGES
> - default 14 if ARM64_16K_PAGES
> - default 12
> -
>   config ARM64_CONT_PTE_SHIFT
>   int
> - default 5 if ARM64_64K_PAGES
> - default 7 if ARM64_16K_PAGES
> + default 5 if PAGE_SIZE_64KB
> + default 7 if PAGE_SIZE_16KB
>   default 4
>   
>   config ARM64_CONT_PMD_SHIFT
>   int
> - default 5 if ARM64_64K_PAGES
> - default 5 if ARM64_16K_PAGES
> + default 5 if PAGE_SIZE_64KB
> + default 5 if PAGE_SIZE_16KB
>   default 4
>   
>   config ARCH_MMAP_RND_BITS_MIN
> - default 14 if ARM64_64K_PAGES
> - default 16 if ARM64_16K_PAGES
> + default 14 if PAGE_SIZE_64KB
> + default 16 if PAGE_SIZE_16KB
>   default 18
>   
>   # max bits determined by the following formula:
> @@ -1259,11 +1253,13 @@ choice
>   
>   config ARM64_4K_PAGES
>   bool "4KB"
> + select HAVE_PAGE_SIZE_4KB
>   help
> This feature enables 4KB pages support.
>   
>   config ARM64_16K_PAGES
>   bool "16KB"
> + select HAVE_PAGE_SIZE_16KB
>   help
> The system will use 16KB pages support. AArch32 emulation
> requires applications compiled with 16K (or a multiple of 16K)
> @@ -1271,6 +1267,7 @@ config ARM64_16K_PAGES
>   
>   config ARM64_64K_PAGES
>   bool "64KB"
> + select HAVE_PAGE_SIZE_64KB
>   help
> This feature enables 64KB pages support (4KB by default)
> allowing only two levels of page tables and faster TLB
> @@ -1291,19 +1288,19 @@ choice
>   
>   config ARM64_VA_BITS_36
>   bool "36-bit" if EXPERT
> - depends on ARM64_16K_PAGES
> + depends on PAGE_SIZE_16KB
>   
>   config ARM64_VA_BITS_39
>   bool "39-bit"
> - depends on ARM64_4K_PAGES
> + depends on PAGE_SIZE_4KB
>   
>   config ARM64_VA_BITS_42
>   bool "42-bit"
> - depends on ARM64_64K_PAGES
> + depends on PAGE_SIZE_64KB
>   
>   config ARM64_VA_BITS_47
>   bool "47-bit"
> - depends on ARM64_16K_PAGES
> + depends on PAGE_SIZE_16KB
>   
>   config ARM64_VA_BITS_48
>   bool "48-bit"
> diff --git a/arch/arm64/include/asm/page-def.h 
> b/arch/arm64/include/asm/page-def.h
> index 2403f7b4cdbf..792e9fe881dc 100644
> --- a/arch/arm64/include/asm/page-def.h
> +++ b/arch/arm64/include/asm/page-def.h
> @@ -11,7 +11,7 @@
>   #include 
>   
>   /* PAGE_SHIFT determines the page size */
> -#define PAGE_SHIFT   CONFIG_ARM64_PAGE_SHIFT
> +#define PAGE_SHIFT   CONFIG_PAGE_SHIFT
>   #define PAGE_SIZE   (_AC(1, UL) << PAGE_SHIFT)
>   #define PAGE_MASK   

Re: [PATCH 1/4] arch: consolidate existing CONFIG_PAGE_SIZE_*KB definitions

2024-02-26 Thread Christophe Leroy


Le 26/02/2024 à 17:14, Arnd Bergmann a écrit :
> From: Arnd Bergmann 
> 
> These four architectures define the same Kconfig symbols for configuring
> the page size. Move the logic into a common place where it can be shared
> with all other architectures.
> 
> Signed-off-by: Arnd Bergmann 
> ---
>   arch/Kconfig  | 58 +--
>   arch/hexagon/Kconfig  | 25 +++--
>   arch/hexagon/include/asm/page.h   |  6 +---
>   arch/loongarch/Kconfig| 21 ---
>   arch/loongarch/include/asm/page.h | 10 +-
>   arch/mips/Kconfig | 58 +++
>   arch/mips/include/asm/page.h  | 16 +
>   arch/sh/include/asm/page.h| 13 +--
>   arch/sh/mm/Kconfig| 42 +++---
>   9 files changed, 88 insertions(+), 161 deletions(-)
> 
> diff --git a/arch/Kconfig b/arch/Kconfig
> index a5af0edd3eb8..237cea01ed9b 100644
> --- a/arch/Kconfig
> +++ b/arch/Kconfig
> @@ -1078,17 +1078,71 @@ config HAVE_ARCH_COMPAT_MMAP_BASES
> and vice-versa 32-bit applications to call 64-bit mmap().
> Required for applications doing different bitness syscalls.
>   
> +config HAVE_PAGE_SIZE_4KB
> + bool
> +
> +config HAVE_PAGE_SIZE_8KB
> + bool
> +
> +config HAVE_PAGE_SIZE_16KB
> + bool
> +
> +config HAVE_PAGE_SIZE_32KB
> + bool
> +
> +config HAVE_PAGE_SIZE_64KB
> + bool
> +
> +config HAVE_PAGE_SIZE_256KB
> + bool
> +
> +choice
> + prompt "MMU page size"
> +

That's a nice re-factor.

The only drawback I see is that we are loosing several interesting 
arch-specific comments/help text. Don't know if there could be an easy 
way to keep them.


> +config PAGE_SIZE_4KB
> + bool "4KB pages"
> + depends on HAVE_PAGE_SIZE_4KB
> +
> +config PAGE_SIZE_8KB
> + bool "8KB pages"
> + depends on HAVE_PAGE_SIZE_8KB
> +
> +config PAGE_SIZE_16KB
> + bool "16KB pages"
> + depends on HAVE_PAGE_SIZE_16KB
> +
> +config PAGE_SIZE_32KB
> + bool "32KB pages"
> + depends on HAVE_PAGE_SIZE_32KB
> +
> +config PAGE_SIZE_64KB
> + bool "64KB pages"
> + depends on HAVE_PAGE_SIZE_64KB
> +
> +config PAGE_SIZE_256KB
> + bool "256KB pages"
> + depends on HAVE_PAGE_SIZE_256KB

Hexagon seem to also use CONFIG_PAGE_SIZE_1MB ?

> +
> +endchoice
> +
>   config PAGE_SIZE_LESS_THAN_64KB
>   def_bool y
> - depends on !ARM64_64K_PAGES
>   depends on !PAGE_SIZE_64KB
> - depends on !PARISC_PAGE_SIZE_64KB
>   depends on PAGE_SIZE_LESS_THAN_256KB
>   
>   config PAGE_SIZE_LESS_THAN_256KB
>   def_bool y
>   depends on !PAGE_SIZE_256KB
>   
> +config PAGE_SHIFT
> + int
> + default 12 if PAGE_SIZE_4KB
> + default 13 if PAGE_SIZE_8KB
> + default 14 if PAGE_SIZE_16KB
> + default 15 if PAGE_SIZE_32KB
> + default 16 if PAGE_SIZE_64KB
> + default 18 if PAGE_SIZE_256KB
> +
>   # This allows to use a set of generic functions to determine mmap base
>   # address by giving priority to top-down scheme only if the process
>   # is not in legacy mode (compat task, unlimited stack size or
> diff --git a/arch/hexagon/Kconfig b/arch/hexagon/Kconfig
> index a880ee067d2e..aac46ee1a000 100644
> --- a/arch/hexagon/Kconfig
> +++ b/arch/hexagon/Kconfig
> @@ -8,6 +8,11 @@ config HEXAGON
>   select ARCH_HAS_SYNC_DMA_FOR_DEVICE
>   select ARCH_NO_PREEMPT
>   select DMA_GLOBAL_POOL
> + select FRAME_POINTER
> + select HAVE_PAGE_SIZE_4KB
> + select HAVE_PAGE_SIZE_16KB
> + select HAVE_PAGE_SIZE_64KB
> + select HAVE_PAGE_SIZE_256KB
>   # Other pending projects/to-do items.
>   # select HAVE_REGS_AND_STACK_ACCESS_API
>   # select HAVE_HW_BREAKPOINT if PERF_EVENTS
> @@ -120,26 +125,6 @@ config NR_CPUS
> This is purely to save memory - each supported CPU adds
> approximately eight kilobytes to the kernel image.
>   
> -choice
> - prompt "Kernel page size"
> - default PAGE_SIZE_4KB
> - help
> -   Changes the default page size; use with caution.
> -
> -config PAGE_SIZE_4KB
> - bool "4KB"
> -
> -config PAGE_SIZE_16KB
> - bool "16KB"
> -
> -config PAGE_SIZE_64KB
> - bool "64KB"
> -
> -config PAGE_SIZE_256KB
> - bool "256KB"
> -
> -endchoice
> -
>   source "kernel/Kconfig.hz"
>   
>   endmenu
> diff --git a/arch/hexagon/include/asm/page.h b/arch/hexagon/include/asm/page.h
> index 10f1bc07423c..65c9bac639fa 100644
> --- a/arch/hexagon/include/asm/page.h
> +++ b/arch/hexagon/include/asm/page.h
> @@ -13,27 +13,22 @@
>   /*  This is probably not the most graceful way to handle this.  */
>   
>   #ifdef CONFIG_PAGE_SIZE_4KB
> -#define PAGE_SHIFT 12
>   #define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_4KB
>   #endif
>   
>   #ifdef CONFIG_PAGE_SIZE_16KB
> -#define PAGE_SHIFT 14
>   #define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_16KB
>   #endif
>   
>   #ifdef CONFIG_PAGE_SIZE_64KB
> -#define PAGE_SHIFT 16
>   #define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_64KB
>   

Re: [PATCH 4/4] vdso: avoid including asm/page.h

2024-02-26 Thread Christophe Leroy


Le 26/02/2024 à 17:14, Arnd Bergmann a écrit :
> From: Arnd Bergmann 
> 
> The recent change to the vdso_data_store broke building compat VDSO
> on at least arm64 because it includes headers outside of the include/vdso/
> namespace:

I understand that powerpc64 also has an issue, see 
https://patchwork.ozlabs.org/project/linuxppc-dev/patch/20231221120410.2226678-1-...@ellerman.id.au/

> 
> In file included from arch/arm64/include/asm/lse.h:5,
>   from arch/arm64/include/asm/cmpxchg.h:14,
>   from arch/arm64/include/asm/atomic.h:16,
>   from include/linux/atomic.h:7,
>   from include/asm-generic/bitops/atomic.h:5,
>   from arch/arm64/include/asm/bitops.h:25,
>   from include/linux/bitops.h:68,
>   from arch/arm64/include/asm/memory.h:209,
>   from arch/arm64/include/asm/page.h:46,
>   from include/vdso/datapage.h:22,
>   from lib/vdso/gettimeofday.c:5,
>   from :
> arch/arm64/include/asm/atomic_ll_sc.h:298:9: error: unknown type name 'u128'
>298 | u128 full;
> 
> Use an open-coded page size calculation based on the new CONFIG_PAGE_SHIFT
> Kconfig symbol instead.
> 
> Reported-by: Linux Kernel Functional Testing 
> Fixes: a0d2fcd62ac2 ("vdso/ARM: Make union vdso_data_store available for all 
> architectures")
> Link: 
> https://lore.kernel.org/lkml/ca+g9fytrxxm_ko9fnpz3xarxhv7ud_yqp-teupqrnrhu+_0...@mail.gmail.com/
> Signed-off-by: Arnd Bergmann 
> ---
>   include/vdso/datapage.h | 4 +---
>   1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/include/vdso/datapage.h b/include/vdso/datapage.h
> index 7ba44379a095..2c39a67d7e23 100644
> --- a/include/vdso/datapage.h
> +++ b/include/vdso/datapage.h
> @@ -19,8 +19,6 @@
>   #include 
>   #include 
>   
> -#include 
> -
>   #ifdef CONFIG_ARCH_HAS_VDSO_DATA
>   #include 
>   #else
> @@ -128,7 +126,7 @@ extern struct vdso_data _timens_data[CS_BASES] 
> __attribute__((visibility("hidden
>*/
>   union vdso_data_store {
>   struct vdso_datadata[CS_BASES];
> - u8  page[PAGE_SIZE];
> + u8  page[1ul << CONFIG_PAGE_SHIFT];

Usually 1UL is used (capital letter)

Maybe better to (re)define PAGE_SIZE instead, something like:

#define PAGE_SIZE (1UL << CONFIG_PAGE_SHIFT)


>   };
>   
>   /*


Re: [PATCH 1/4] arch: consolidate existing CONFIG_PAGE_SIZE_*KB definitions

2024-02-26 Thread Samuel Holland
On 2024-02-26 10:14 AM, Arnd Bergmann wrote:
> From: Arnd Bergmann 
> 
> These four architectures define the same Kconfig symbols for configuring
> the page size. Move the logic into a common place where it can be shared
> with all other architectures.
> 
> Signed-off-by: Arnd Bergmann 
> ---
>  arch/Kconfig  | 58 +--
>  arch/hexagon/Kconfig  | 25 +++--
>  arch/hexagon/include/asm/page.h   |  6 +---
>  arch/loongarch/Kconfig| 21 ---
>  arch/loongarch/include/asm/page.h | 10 +-
>  arch/mips/Kconfig | 58 +++
>  arch/mips/include/asm/page.h  | 16 +
>  arch/sh/include/asm/page.h| 13 +--
>  arch/sh/mm/Kconfig| 42 +++---
>  9 files changed, 88 insertions(+), 161 deletions(-)
> 
> diff --git a/arch/Kconfig b/arch/Kconfig
> index a5af0edd3eb8..237cea01ed9b 100644
> --- a/arch/Kconfig
> +++ b/arch/Kconfig
> @@ -1078,17 +1078,71 @@ config HAVE_ARCH_COMPAT_MMAP_BASES
> and vice-versa 32-bit applications to call 64-bit mmap().
> Required for applications doing different bitness syscalls.
>  
> +config HAVE_PAGE_SIZE_4KB
> + bool
> +
> +config HAVE_PAGE_SIZE_8KB
> + bool
> +
> +config HAVE_PAGE_SIZE_16KB
> + bool
> +
> +config HAVE_PAGE_SIZE_32KB
> + bool
> +
> +config HAVE_PAGE_SIZE_64KB
> + bool
> +
> +config HAVE_PAGE_SIZE_256KB
> + bool
> +
> +choice
> + prompt "MMU page size"

Should this have some generic help text (at least a warning about 
compatibility)?

> +
> +config PAGE_SIZE_4KB
> + bool "4KB pages"
> + depends on HAVE_PAGE_SIZE_4KB
> +
> +config PAGE_SIZE_8KB
> + bool "8KB pages"
> + depends on HAVE_PAGE_SIZE_8KB
> +
> +config PAGE_SIZE_16KB
> + bool "16KB pages"
> + depends on HAVE_PAGE_SIZE_16KB
> +
> +config PAGE_SIZE_32KB
> + bool "32KB pages"
> + depends on HAVE_PAGE_SIZE_32KB
> +
> +config PAGE_SIZE_64KB
> + bool "64KB pages"
> + depends on HAVE_PAGE_SIZE_64KB
> +
> +config PAGE_SIZE_256KB
> + bool "256KB pages"
> + depends on HAVE_PAGE_SIZE_256KB
> +
> +endchoice
> +
>  config PAGE_SIZE_LESS_THAN_64KB
>   def_bool y
> - depends on !ARM64_64K_PAGES
>   depends on !PAGE_SIZE_64KB
> - depends on !PARISC_PAGE_SIZE_64KB
>   depends on PAGE_SIZE_LESS_THAN_256KB
>  
>  config PAGE_SIZE_LESS_THAN_256KB
>   def_bool y
>   depends on !PAGE_SIZE_256KB
>  
> +config PAGE_SHIFT
> + int
> + default 12 if PAGE_SIZE_4KB
> + default 13 if PAGE_SIZE_8KB
> + default 14 if PAGE_SIZE_16KB
> + default 15 if PAGE_SIZE_32KB
> + default 16 if PAGE_SIZE_64KB
> + default 18 if PAGE_SIZE_256KB
> +
>  # This allows to use a set of generic functions to determine mmap base
>  # address by giving priority to top-down scheme only if the process
>  # is not in legacy mode (compat task, unlimited stack size or
> diff --git a/arch/hexagon/Kconfig b/arch/hexagon/Kconfig
> index a880ee067d2e..aac46ee1a000 100644
> --- a/arch/hexagon/Kconfig
> +++ b/arch/hexagon/Kconfig
> @@ -8,6 +8,11 @@ config HEXAGON
>   select ARCH_HAS_SYNC_DMA_FOR_DEVICE
>   select ARCH_NO_PREEMPT
>   select DMA_GLOBAL_POOL
> + select FRAME_POINTER

Looks like a paste error.

> + select HAVE_PAGE_SIZE_4KB
> + select HAVE_PAGE_SIZE_16KB
> + select HAVE_PAGE_SIZE_64KB
> + select HAVE_PAGE_SIZE_256KB
>   # Other pending projects/to-do items.
>   # select HAVE_REGS_AND_STACK_ACCESS_API
>   # select HAVE_HW_BREAKPOINT if PERF_EVENTS
> @@ -120,26 +125,6 @@ config NR_CPUS
> This is purely to save memory - each supported CPU adds
> approximately eight kilobytes to the kernel image.
>  
> -choice
> - prompt "Kernel page size"
> - default PAGE_SIZE_4KB
> - help
> -   Changes the default page size; use with caution.
> -
> -config PAGE_SIZE_4KB
> - bool "4KB"
> -
> -config PAGE_SIZE_16KB
> - bool "16KB"
> -
> -config PAGE_SIZE_64KB
> - bool "64KB"
> -
> -config PAGE_SIZE_256KB
> - bool "256KB"
> -
> -endchoice
> -
>  source "kernel/Kconfig.hz"
>  
>  endmenu
> diff --git a/arch/hexagon/include/asm/page.h b/arch/hexagon/include/asm/page.h
> index 10f1bc07423c..65c9bac639fa 100644
> --- a/arch/hexagon/include/asm/page.h
> +++ b/arch/hexagon/include/asm/page.h
> @@ -13,27 +13,22 @@
>  /*  This is probably not the most graceful way to handle this.  */
>  
>  #ifdef CONFIG_PAGE_SIZE_4KB
> -#define PAGE_SHIFT 12
>  #define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_4KB
>  #endif
>  
>  #ifdef CONFIG_PAGE_SIZE_16KB
> -#define PAGE_SHIFT 14
>  #define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_16KB
>  #endif
>  
>  #ifdef CONFIG_PAGE_SIZE_64KB
> -#define PAGE_SHIFT 16
>  #define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_64KB
>  #endif
>  
>  #ifdef CONFIG_PAGE_SIZE_256KB
> -#define PAGE_SHIFT 18
>  #define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_256KB
>  #endif
>  
>  #ifdef CONFIG_PAGE_SIZE_1MB
> 

[PATCH 4/4] vdso: avoid including asm/page.h

2024-02-26 Thread Arnd Bergmann
From: Arnd Bergmann 

The recent change to the vdso_data_store broke building compat VDSO
on at least arm64 because it includes headers outside of the include/vdso/
namespace:

In file included from arch/arm64/include/asm/lse.h:5,
 from arch/arm64/include/asm/cmpxchg.h:14,
 from arch/arm64/include/asm/atomic.h:16,
 from include/linux/atomic.h:7,
 from include/asm-generic/bitops/atomic.h:5,
 from arch/arm64/include/asm/bitops.h:25,
 from include/linux/bitops.h:68,
 from arch/arm64/include/asm/memory.h:209,
 from arch/arm64/include/asm/page.h:46,
 from include/vdso/datapage.h:22,
 from lib/vdso/gettimeofday.c:5,
 from :
arch/arm64/include/asm/atomic_ll_sc.h:298:9: error: unknown type name 'u128'
  298 | u128 full;

Use an open-coded page size calculation based on the new CONFIG_PAGE_SHIFT
Kconfig symbol instead.

Reported-by: Linux Kernel Functional Testing 
Fixes: a0d2fcd62ac2 ("vdso/ARM: Make union vdso_data_store available for all 
architectures")
Link: 
https://lore.kernel.org/lkml/ca+g9fytrxxm_ko9fnpz3xarxhv7ud_yqp-teupqrnrhu+_0...@mail.gmail.com/
Signed-off-by: Arnd Bergmann 
---
 include/vdso/datapage.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/include/vdso/datapage.h b/include/vdso/datapage.h
index 7ba44379a095..2c39a67d7e23 100644
--- a/include/vdso/datapage.h
+++ b/include/vdso/datapage.h
@@ -19,8 +19,6 @@
 #include 
 #include 
 
-#include 
-
 #ifdef CONFIG_ARCH_HAS_VDSO_DATA
 #include 
 #else
@@ -128,7 +126,7 @@ extern struct vdso_data _timens_data[CS_BASES] 
__attribute__((visibility("hidden
  */
 union vdso_data_store {
struct vdso_datadata[CS_BASES];
-   u8  page[PAGE_SIZE];
+   u8  page[1ul << CONFIG_PAGE_SHIFT];
 };
 
 /*
-- 
2.39.2




[PATCH 3/4] arch: define CONFIG_PAGE_SIZE_*KB on all architectures

2024-02-26 Thread Arnd Bergmann
From: Arnd Bergmann 

Most architectures only support a single hardcoded page size. In order
to ensure that each one of these sets the corresponding Kconfig symbols,
change over the PAGE_SHIFT definition to the common one and allow
only the hardware page size to be selected.

Signed-off-by: Arnd Bergmann 
---
 arch/alpha/Kconfig | 1 +
 arch/alpha/include/asm/page.h  | 2 +-
 arch/arm/Kconfig   | 1 +
 arch/arm/include/asm/page.h| 2 +-
 arch/csky/Kconfig  | 1 +
 arch/csky/include/asm/page.h   | 2 +-
 arch/m68k/Kconfig  | 3 +++
 arch/m68k/Kconfig.cpu  | 2 ++
 arch/m68k/include/asm/page.h   | 6 +-
 arch/microblaze/Kconfig| 1 +
 arch/microblaze/include/asm/page.h | 2 +-
 arch/nios2/Kconfig | 1 +
 arch/nios2/include/asm/page.h  | 2 +-
 arch/openrisc/Kconfig  | 1 +
 arch/openrisc/include/asm/page.h   | 2 +-
 arch/riscv/Kconfig | 1 +
 arch/riscv/include/asm/page.h  | 2 +-
 arch/s390/Kconfig  | 1 +
 arch/s390/include/asm/page.h   | 2 +-
 arch/sparc/Kconfig | 2 ++
 arch/sparc/include/asm/page_32.h   | 2 +-
 arch/sparc/include/asm/page_64.h   | 3 +--
 arch/um/Kconfig| 1 +
 arch/um/include/asm/page.h | 2 +-
 arch/x86/Kconfig   | 1 +
 arch/x86/include/asm/page_types.h  | 2 +-
 arch/xtensa/Kconfig| 1 +
 arch/xtensa/include/asm/page.h | 2 +-
 28 files changed, 32 insertions(+), 19 deletions(-)

diff --git a/arch/alpha/Kconfig b/arch/alpha/Kconfig
index d6968d090d49..4f490250d323 100644
--- a/arch/alpha/Kconfig
+++ b/arch/alpha/Kconfig
@@ -14,6 +14,7 @@ config ALPHA
select PCI_DOMAINS if PCI
select PCI_SYSCALL if PCI
select HAVE_ASM_MODVERSIONS
+   select HAVE_PAGE_SIZE_8KB
select HAVE_PCSPKR_PLATFORM
select HAVE_PERF_EVENTS
select NEED_DMA_MAP_STATE
diff --git a/arch/alpha/include/asm/page.h b/arch/alpha/include/asm/page.h
index 4db1ebc0ed99..70419e6be1a3 100644
--- a/arch/alpha/include/asm/page.h
+++ b/arch/alpha/include/asm/page.h
@@ -6,7 +6,7 @@
 #include 
 
 /* PAGE_SHIFT determines the page size */
-#define PAGE_SHIFT 13
+#define PAGE_SHIFT CONFIG_PAGE_SHIFT
 #define PAGE_SIZE  (_AC(1,UL) << PAGE_SHIFT)
 #define PAGE_MASK  (~(PAGE_SIZE-1))
 
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 0af6709570d1..9d52ba3a8ad1 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -116,6 +116,7 @@ config ARM
select HAVE_MOD_ARCH_SPECIFIC
select HAVE_NMI
select HAVE_OPTPROBES if !THUMB2_KERNEL
+   select HAVE_PAGE_SIZE_4KB
select HAVE_PCI if MMU
select HAVE_PERF_EVENTS
select HAVE_PERF_REGS
diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
index 119aa85d1feb..62af9f7f9e96 100644
--- a/arch/arm/include/asm/page.h
+++ b/arch/arm/include/asm/page.h
@@ -8,7 +8,7 @@
 #define _ASMARM_PAGE_H
 
 /* PAGE_SHIFT determines the page size */
-#define PAGE_SHIFT 12
+#define PAGE_SHIFT CONFIG_PAGE_SHIFT
 #define PAGE_SIZE  (_AC(1,UL) << PAGE_SHIFT)
 #define PAGE_MASK  (~((1 << PAGE_SHIFT) - 1))
 
diff --git a/arch/csky/Kconfig b/arch/csky/Kconfig
index cf2a6fd7dff8..9c2723ab1c94 100644
--- a/arch/csky/Kconfig
+++ b/arch/csky/Kconfig
@@ -89,6 +89,7 @@ config CSKY
select HAVE_KPROBES if !CPU_CK610
select HAVE_KPROBES_ON_FTRACE if !CPU_CK610
select HAVE_KRETPROBES if !CPU_CK610
+   select HAVE_PAGE_SIZE_4KB
select HAVE_PERF_EVENTS
select HAVE_PERF_REGS
select HAVE_PERF_USER_STACK_DUMP
diff --git a/arch/csky/include/asm/page.h b/arch/csky/include/asm/page.h
index 4a0502e324a6..f70f37402d75 100644
--- a/arch/csky/include/asm/page.h
+++ b/arch/csky/include/asm/page.h
@@ -10,7 +10,7 @@
 /*
  * PAGE_SHIFT determines the page size: 4KB
  */
-#define PAGE_SHIFT 12
+#define PAGE_SHIFT CONFIG_PAGE_SHIFT
 #define PAGE_SIZE  (_AC(1, UL) << PAGE_SHIFT)
 #define PAGE_MASK  (~(PAGE_SIZE - 1))
 #define THREAD_SIZE(PAGE_SIZE * 2)
diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig
index 4b3e93cac723..7b709453d5e7 100644
--- a/arch/m68k/Kconfig
+++ b/arch/m68k/Kconfig
@@ -84,12 +84,15 @@ config MMU
 
 config MMU_MOTOROLA
bool
+   select HAVE_PAGE_SIZE_4KB
 
 config MMU_COLDFIRE
+   select HAVE_PAGE_SIZE_8KB
bool
 
 config MMU_SUN3
bool
+   select HAVE_PAGE_SIZE_8KB
depends on MMU && !MMU_MOTOROLA && !MMU_COLDFIRE
 
 config ARCH_SUPPORTS_KEXEC
diff --git a/arch/m68k/Kconfig.cpu b/arch/m68k/Kconfig.cpu
index 9dcf245c9cbf..c777a129768a 100644
--- a/arch/m68k/Kconfig.cpu
+++ b/arch/m68k/Kconfig.cpu
@@ -30,6 +30,7 @@ config COLDFIRE
select GENERIC_CSUM
select GPIOLIB
select HAVE_LEGACY_CLK
+   select HAVE_PAGE_SIZE_8KB if !MMU
 
 endchoice
 
@@ -45,6 +46,7 @@ config M68000
   

[PATCH 2/4] arch: simplify architecture specific page size configuration

2024-02-26 Thread Arnd Bergmann
From: Arnd Bergmann 

arc, arm64, parisc and powerpc all have their own Kconfig symbols
in place of the common CONFIG_PAGE_SIZE_4KB symbols. Change these
so the common symbols are the ones that are actually used, while
leaving the arhcitecture specific ones as the user visible
place for configuring it, to avoid breaking user configs.

Signed-off-by: Arnd Bergmann 
---
 arch/arc/Kconfig  |  3 +++
 arch/arc/include/uapi/asm/page.h  |  6 ++
 arch/arm64/Kconfig| 29 +
 arch/arm64/include/asm/page-def.h |  2 +-
 arch/parisc/Kconfig   |  3 +++
 arch/parisc/include/asm/page.h| 10 +-
 arch/powerpc/Kconfig  | 31 ++-
 arch/powerpc/include/asm/page.h   |  2 +-
 scripts/gdb/linux/constants.py.in |  2 +-
 scripts/gdb/linux/mm.py   |  2 +-
 10 files changed, 32 insertions(+), 58 deletions(-)

diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig
index 1b0483c51cc1..4092bec198be 100644
--- a/arch/arc/Kconfig
+++ b/arch/arc/Kconfig
@@ -284,14 +284,17 @@ choice
 
 config ARC_PAGE_SIZE_8K
bool "8KB"
+   select HAVE_PAGE_SIZE_8KB
help
  Choose between 8k vs 16k
 
 config ARC_PAGE_SIZE_16K
+   select HAVE_PAGE_SIZE_16KB
bool "16KB"
 
 config ARC_PAGE_SIZE_4K
bool "4KB"
+   select HAVE_PAGE_SIZE_4KB
depends on ARC_MMU_V3 || ARC_MMU_V4
 
 endchoice
diff --git a/arch/arc/include/uapi/asm/page.h b/arch/arc/include/uapi/asm/page.h
index 2a4ad619abfb..7fd9e741b527 100644
--- a/arch/arc/include/uapi/asm/page.h
+++ b/arch/arc/include/uapi/asm/page.h
@@ -13,10 +13,8 @@
 #include 
 
 /* PAGE_SHIFT determines the page size */
-#if defined(CONFIG_ARC_PAGE_SIZE_16K)
-#define PAGE_SHIFT 14
-#elif defined(CONFIG_ARC_PAGE_SIZE_4K)
-#define PAGE_SHIFT 12
+#ifdef __KERNEL__
+#define PAGE_SHIFT CONFIG_PAGE_SHIFT
 #else
 /*
  * Default 8k
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index aa7c1d435139..29290b8cb36d 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -277,27 +277,21 @@ config 64BIT
 config MMU
def_bool y
 
-config ARM64_PAGE_SHIFT
-   int
-   default 16 if ARM64_64K_PAGES
-   default 14 if ARM64_16K_PAGES
-   default 12
-
 config ARM64_CONT_PTE_SHIFT
int
-   default 5 if ARM64_64K_PAGES
-   default 7 if ARM64_16K_PAGES
+   default 5 if PAGE_SIZE_64KB
+   default 7 if PAGE_SIZE_16KB
default 4
 
 config ARM64_CONT_PMD_SHIFT
int
-   default 5 if ARM64_64K_PAGES
-   default 5 if ARM64_16K_PAGES
+   default 5 if PAGE_SIZE_64KB
+   default 5 if PAGE_SIZE_16KB
default 4
 
 config ARCH_MMAP_RND_BITS_MIN
-   default 14 if ARM64_64K_PAGES
-   default 16 if ARM64_16K_PAGES
+   default 14 if PAGE_SIZE_64KB
+   default 16 if PAGE_SIZE_16KB
default 18
 
 # max bits determined by the following formula:
@@ -1259,11 +1253,13 @@ choice
 
 config ARM64_4K_PAGES
bool "4KB"
+   select HAVE_PAGE_SIZE_4KB
help
  This feature enables 4KB pages support.
 
 config ARM64_16K_PAGES
bool "16KB"
+   select HAVE_PAGE_SIZE_16KB
help
  The system will use 16KB pages support. AArch32 emulation
  requires applications compiled with 16K (or a multiple of 16K)
@@ -1271,6 +1267,7 @@ config ARM64_16K_PAGES
 
 config ARM64_64K_PAGES
bool "64KB"
+   select HAVE_PAGE_SIZE_64KB
help
  This feature enables 64KB pages support (4KB by default)
  allowing only two levels of page tables and faster TLB
@@ -1291,19 +1288,19 @@ choice
 
 config ARM64_VA_BITS_36
bool "36-bit" if EXPERT
-   depends on ARM64_16K_PAGES
+   depends on PAGE_SIZE_16KB
 
 config ARM64_VA_BITS_39
bool "39-bit"
-   depends on ARM64_4K_PAGES
+   depends on PAGE_SIZE_4KB
 
 config ARM64_VA_BITS_42
bool "42-bit"
-   depends on ARM64_64K_PAGES
+   depends on PAGE_SIZE_64KB
 
 config ARM64_VA_BITS_47
bool "47-bit"
-   depends on ARM64_16K_PAGES
+   depends on PAGE_SIZE_16KB
 
 config ARM64_VA_BITS_48
bool "48-bit"
diff --git a/arch/arm64/include/asm/page-def.h 
b/arch/arm64/include/asm/page-def.h
index 2403f7b4cdbf..792e9fe881dc 100644
--- a/arch/arm64/include/asm/page-def.h
+++ b/arch/arm64/include/asm/page-def.h
@@ -11,7 +11,7 @@
 #include 
 
 /* PAGE_SHIFT determines the page size */
-#define PAGE_SHIFT CONFIG_ARM64_PAGE_SHIFT
+#define PAGE_SHIFT CONFIG_PAGE_SHIFT
 #define PAGE_SIZE  (_AC(1, UL) << PAGE_SHIFT)
 #define PAGE_MASK  (~(PAGE_SIZE-1))
 
diff --git a/arch/parisc/Kconfig b/arch/parisc/Kconfig
index 5c845e8d59d9..b180e684fa0d 100644
--- a/arch/parisc/Kconfig
+++ b/arch/parisc/Kconfig
@@ -273,6 +273,7 @@ choice
 
 config PARISC_PAGE_SIZE_4KB
bool "4KB"
+   select HAVE_PAGE_SIZE_4KB
help
  This lets you select the page size of the kernel.  For 

[PATCH 1/4] arch: consolidate existing CONFIG_PAGE_SIZE_*KB definitions

2024-02-26 Thread Arnd Bergmann
From: Arnd Bergmann 

These four architectures define the same Kconfig symbols for configuring
the page size. Move the logic into a common place where it can be shared
with all other architectures.

Signed-off-by: Arnd Bergmann 
---
 arch/Kconfig  | 58 +--
 arch/hexagon/Kconfig  | 25 +++--
 arch/hexagon/include/asm/page.h   |  6 +---
 arch/loongarch/Kconfig| 21 ---
 arch/loongarch/include/asm/page.h | 10 +-
 arch/mips/Kconfig | 58 +++
 arch/mips/include/asm/page.h  | 16 +
 arch/sh/include/asm/page.h| 13 +--
 arch/sh/mm/Kconfig| 42 +++---
 9 files changed, 88 insertions(+), 161 deletions(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index a5af0edd3eb8..237cea01ed9b 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -1078,17 +1078,71 @@ config HAVE_ARCH_COMPAT_MMAP_BASES
  and vice-versa 32-bit applications to call 64-bit mmap().
  Required for applications doing different bitness syscalls.
 
+config HAVE_PAGE_SIZE_4KB
+   bool
+
+config HAVE_PAGE_SIZE_8KB
+   bool
+
+config HAVE_PAGE_SIZE_16KB
+   bool
+
+config HAVE_PAGE_SIZE_32KB
+   bool
+
+config HAVE_PAGE_SIZE_64KB
+   bool
+
+config HAVE_PAGE_SIZE_256KB
+   bool
+
+choice
+   prompt "MMU page size"
+
+config PAGE_SIZE_4KB
+   bool "4KB pages"
+   depends on HAVE_PAGE_SIZE_4KB
+
+config PAGE_SIZE_8KB
+   bool "8KB pages"
+   depends on HAVE_PAGE_SIZE_8KB
+
+config PAGE_SIZE_16KB
+   bool "16KB pages"
+   depends on HAVE_PAGE_SIZE_16KB
+
+config PAGE_SIZE_32KB
+   bool "32KB pages"
+   depends on HAVE_PAGE_SIZE_32KB
+
+config PAGE_SIZE_64KB
+   bool "64KB pages"
+   depends on HAVE_PAGE_SIZE_64KB
+
+config PAGE_SIZE_256KB
+   bool "256KB pages"
+   depends on HAVE_PAGE_SIZE_256KB
+
+endchoice
+
 config PAGE_SIZE_LESS_THAN_64KB
def_bool y
-   depends on !ARM64_64K_PAGES
depends on !PAGE_SIZE_64KB
-   depends on !PARISC_PAGE_SIZE_64KB
depends on PAGE_SIZE_LESS_THAN_256KB
 
 config PAGE_SIZE_LESS_THAN_256KB
def_bool y
depends on !PAGE_SIZE_256KB
 
+config PAGE_SHIFT
+   int
+   default 12 if PAGE_SIZE_4KB
+   default 13 if PAGE_SIZE_8KB
+   default 14 if PAGE_SIZE_16KB
+   default 15 if PAGE_SIZE_32KB
+   default 16 if PAGE_SIZE_64KB
+   default 18 if PAGE_SIZE_256KB
+
 # This allows to use a set of generic functions to determine mmap base
 # address by giving priority to top-down scheme only if the process
 # is not in legacy mode (compat task, unlimited stack size or
diff --git a/arch/hexagon/Kconfig b/arch/hexagon/Kconfig
index a880ee067d2e..aac46ee1a000 100644
--- a/arch/hexagon/Kconfig
+++ b/arch/hexagon/Kconfig
@@ -8,6 +8,11 @@ config HEXAGON
select ARCH_HAS_SYNC_DMA_FOR_DEVICE
select ARCH_NO_PREEMPT
select DMA_GLOBAL_POOL
+   select FRAME_POINTER
+   select HAVE_PAGE_SIZE_4KB
+   select HAVE_PAGE_SIZE_16KB
+   select HAVE_PAGE_SIZE_64KB
+   select HAVE_PAGE_SIZE_256KB
# Other pending projects/to-do items.
# select HAVE_REGS_AND_STACK_ACCESS_API
# select HAVE_HW_BREAKPOINT if PERF_EVENTS
@@ -120,26 +125,6 @@ config NR_CPUS
  This is purely to save memory - each supported CPU adds
  approximately eight kilobytes to the kernel image.
 
-choice
-   prompt "Kernel page size"
-   default PAGE_SIZE_4KB
-   help
- Changes the default page size; use with caution.
-
-config PAGE_SIZE_4KB
-   bool "4KB"
-
-config PAGE_SIZE_16KB
-   bool "16KB"
-
-config PAGE_SIZE_64KB
-   bool "64KB"
-
-config PAGE_SIZE_256KB
-   bool "256KB"
-
-endchoice
-
 source "kernel/Kconfig.hz"
 
 endmenu
diff --git a/arch/hexagon/include/asm/page.h b/arch/hexagon/include/asm/page.h
index 10f1bc07423c..65c9bac639fa 100644
--- a/arch/hexagon/include/asm/page.h
+++ b/arch/hexagon/include/asm/page.h
@@ -13,27 +13,22 @@
 /*  This is probably not the most graceful way to handle this.  */
 
 #ifdef CONFIG_PAGE_SIZE_4KB
-#define PAGE_SHIFT 12
 #define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_4KB
 #endif
 
 #ifdef CONFIG_PAGE_SIZE_16KB
-#define PAGE_SHIFT 14
 #define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_16KB
 #endif
 
 #ifdef CONFIG_PAGE_SIZE_64KB
-#define PAGE_SHIFT 16
 #define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_64KB
 #endif
 
 #ifdef CONFIG_PAGE_SIZE_256KB
-#define PAGE_SHIFT 18
 #define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_256KB
 #endif
 
 #ifdef CONFIG_PAGE_SIZE_1MB
-#define PAGE_SHIFT 20
 #define HEXAGON_L1_PTE_SIZE __HVM_PDE_S_1MB
 #endif
 
@@ -50,6 +45,7 @@
 #define HVM_HUGEPAGE_SIZE 0x5
 #endif
 
+#define PAGE_SHIFT CONFIG_PAGE_SHIFT
 #define PAGE_SIZE  (1UL << PAGE_SHIFT)
 #define PAGE_MASK  (~((1 << PAGE_SHIFT) - 1))
 
diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig
index 929f68926b34..b274784c2e26 100644
--- 

[PATCH 0/4] arch: mm, vdso: consolidate PAGE_SIZE definition

2024-02-26 Thread Arnd Bergmann
From: Arnd Bergmann 

Naresh noticed that the newly added usage of the PAGE_SIZE macro in
include/vdso/datapage.h introduced a build regression. I had an older
patch that I revived to have this defined through Kconfig rather than
through including asm/page.h, which is not allowed in vdso code.

I rebased and tested on top of the tip/timers/core branch that
introduced the regression. If these patches get added, the
compat VDSOs all build again, but the changes are a bit invasive.

  Arnd

Link: 
https://lore.kernel.org/lkml/ca+g9fytrxxm_ko9fnpz3xarxhv7ud_yqp-teupqrnrhu+_0...@mail.gmail.com/
Link: https://lore.kernel.org/all/65dc6c14.170a0220.f4a3f.9...@mx.google.com/

Arnd Bergmann (4):
  arch: consolidate existing CONFIG_PAGE_SIZE_*KB definitions
  arch: simplify architecture specific page size configuration
  arch: define CONFIG_PAGE_SIZE_*KB on all architectures
  vdso: avoid including asm/page.h

 arch/Kconfig   | 58 --
 arch/alpha/Kconfig |  1 +
 arch/alpha/include/asm/page.h  |  2 +-
 arch/arc/Kconfig   |  3 ++
 arch/arc/include/uapi/asm/page.h   |  6 ++--
 arch/arm/Kconfig   |  1 +
 arch/arm/include/asm/page.h|  2 +-
 arch/arm64/Kconfig | 29 +++
 arch/arm64/include/asm/page-def.h  |  2 +-
 arch/csky/Kconfig  |  1 +
 arch/csky/include/asm/page.h   |  2 +-
 arch/hexagon/Kconfig   | 25 +++--
 arch/hexagon/include/asm/page.h|  6 +---
 arch/loongarch/Kconfig | 21 ---
 arch/loongarch/include/asm/page.h  | 10 +-
 arch/m68k/Kconfig  |  3 ++
 arch/m68k/Kconfig.cpu  |  2 ++
 arch/m68k/include/asm/page.h   |  6 +---
 arch/microblaze/Kconfig|  1 +
 arch/microblaze/include/asm/page.h |  2 +-
 arch/mips/Kconfig  | 58 +++---
 arch/mips/include/asm/page.h   | 16 +
 arch/nios2/Kconfig |  1 +
 arch/nios2/include/asm/page.h  |  2 +-
 arch/openrisc/Kconfig  |  1 +
 arch/openrisc/include/asm/page.h   |  2 +-
 arch/parisc/Kconfig|  3 ++
 arch/parisc/include/asm/page.h | 10 +-
 arch/powerpc/Kconfig   | 31 
 arch/powerpc/include/asm/page.h|  2 +-
 arch/riscv/Kconfig |  1 +
 arch/riscv/include/asm/page.h  |  2 +-
 arch/s390/Kconfig  |  1 +
 arch/s390/include/asm/page.h   |  2 +-
 arch/sh/include/asm/page.h | 13 +--
 arch/sh/mm/Kconfig | 42 +++---
 arch/sparc/Kconfig |  2 ++
 arch/sparc/include/asm/page_32.h   |  2 +-
 arch/sparc/include/asm/page_64.h   |  3 +-
 arch/um/Kconfig|  1 +
 arch/um/include/asm/page.h |  2 +-
 arch/x86/Kconfig   |  1 +
 arch/x86/include/asm/page_types.h  |  2 +-
 arch/xtensa/Kconfig|  1 +
 arch/xtensa/include/asm/page.h |  2 +-
 include/vdso/datapage.h|  4 +--
 scripts/gdb/linux/constants.py.in  |  2 +-
 scripts/gdb/linux/mm.py|  2 +-
 48 files changed, 153 insertions(+), 241 deletions(-)

-- 
2.39.2
To: Thomas Gleixner 
To: Vincenzo Frascino 
To: Kees Cook 
To: Anna-Maria Behnsen 
Cc: Matt Turner 
Cc: Vineet Gupta 
Cc: Russell King 
Cc: Catalin Marinas 
Cc: Guo Ren 
Cc: Brian Cain 
Cc: Huacai Chen 
Cc: Geert Uytterhoeven 
Cc: Michal Simek 
Cc: Thomas Bogendoerfer 
Cc: Helge Deller 
Cc: Michael Ellerman 
Cc: Christophe Leroy 
Cc: Palmer Dabbelt 
Cc: John Paul Adrian Glaubitz 
Cc: Andreas Larsson 
Cc: Richard Weinberger 
Cc: x...@kernel.org
Cc: Max Filippov 
Cc: Andy Lutomirski 
Cc: Vincenzo Frascino 
Cc: Jan Kiszka 
Cc: Kieran Bingham 
Cc: Andrew Morton 
Cc: Arnd Bergmann 
Cc: linux-ker...@vger.kernel.org
Cc: linux-alpha@vger.kernel.org
Cc: linux-snps-...@lists.infradead.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-c...@vger.kernel.org
Cc: linux-hexa...@vger.kernel.org
Cc: loonga...@lists.linux.dev
Cc: linux-m...@lists.linux-m68k.org
Cc: linux-m...@vger.kernel.org
Cc: linux-openr...@vger.kernel.org
Cc: linux-par...@vger.kernel.org
Cc: linuxppc-...@lists.ozlabs.org
Cc: linux-ri...@lists.infradead.org
Cc: linux-s...@vger.kernel.org
Cc: linux...@vger.kernel.org
Cc: sparcli...@vger.kernel.org
Cc: linux...@lists.infradead.org