linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/8] arm64: set VMAP_STACK by default
@ 2025-07-07 16:01 Breno Leitao
  2025-07-07 16:01 ` [PATCH 1/8] arm64: Enable VMAP_STACK support Breno Leitao
                   ` (10 more replies)
  0 siblings, 11 replies; 15+ messages in thread
From: Breno Leitao @ 2025-07-07 16:01 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Ard Biesheuvel
  Cc: linux-arm-kernel, linux-kernel, linux-efi, Breno Leitao, leo.yan,
	kernel-team, mark.rutland

Hi all,

This patchset select VMAP_STACK on arm64 by default, and cleans up the
code by removing all associated CONFIG_VMAP_STACK conditionals.

This is a suggestion from Will Deacon from another discussion[1].

With VMAP_STACK now always enabled on arm64, the code can be
significantly simplified, reducing complexity and potential for
misconfiguration.

Overview of Changes

    * Remove all #ifdef CONFIG_VMAP_STACK and related runtime checks
      throughout the architecture codebase.
    * Replace runtime checks with build-time assertions where
      appropriate.

Link: https://lore.kernel.org/all/aGfYL8eXjTA9puQr@willie-the-truck/ [1]

Signed-off-by: Breno Leitao <leitao@debian.org>
---
Breno Leitao (8):
      arm64: Enable VMAP_STACK support
      arm64: efi: Remove CONFIG_VMAP_STACK check
      arm64: Remove CONFIG_VMAP_STACK conditionals from THREAD_SHIFT and THREAD_ALIGN
      arm64: remove CONFIG_VMAP_STACK conditionals from irq stack setup
      arm64: remove CONFIG_VMAP_STACK conditionals from traps overflow stack
      arm64: remove CONFIG_VMAP_STACK checks from stacktrace overflow logic
      arm64: remove CONFIG_VMAP_STACK checks from SDEI stack handling
      arm64: remove CONFIG_VMAP_STACK checks from entry code

 arch/arm64/Kconfig                  |  1 +
 arch/arm64/include/asm/memory.h     |  6 +-----
 arch/arm64/include/asm/stacktrace.h |  6 +-----
 arch/arm64/kernel/efi.c             |  5 -----
 arch/arm64/kernel/entry-common.c    |  2 --
 arch/arm64/kernel/entry.S           |  6 ------
 arch/arm64/kernel/irq.c             | 13 -------------
 arch/arm64/kernel/sdei.c            |  8 ++------
 arch/arm64/kernel/stacktrace.c      |  4 +---
 arch/arm64/kernel/traps.c           |  3 ---
 10 files changed, 6 insertions(+), 48 deletions(-)
---
base-commit: 9dd1757493416310a5e71146a08bc228869f8dae
change-id: 20250707-arm64_vmap-fa70ba3c9cfb

Best regards,
-- 
Breno Leitao <leitao@debian.org>



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

* [PATCH 1/8] arm64: Enable VMAP_STACK support
  2025-07-07 16:01 [PATCH 0/8] arm64: set VMAP_STACK by default Breno Leitao
@ 2025-07-07 16:01 ` Breno Leitao
  2025-07-07 17:23   ` Mark Rutland
  2025-07-07 16:01 ` [PATCH 2/8] arm64: efi: Remove CONFIG_VMAP_STACK check Breno Leitao
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 15+ messages in thread
From: Breno Leitao @ 2025-07-07 16:01 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Ard Biesheuvel
  Cc: linux-arm-kernel, linux-kernel, linux-efi, Breno Leitao, leo.yan,
	kernel-team, mark.rutland

Enable virtually mapped kernel stacks for ARM64. This provides better
stack overflow detection and improved security by mapping kernel stacks
in vmalloc space rather than using direct mapping.

VMAP_STACK helps catch stack overflows early by placing guard pages
around kernel stacks, and also provides better isolation between
kernel stacks and other kernel data structures.

All dependencies are satisfied for arm64: HAVE_ARCH_VMAP_STACK is
already selected above, and KASAN_VMALLOC is selected when KASAN is
enabled, meeting the KASAN dependency requirements.

Suggested-by: Will Deacon <will@kernel.org>
Signed-off-by: Breno Leitao <leitao@debian.org>
---
 arch/arm64/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 393d71124f5d..179b302f43c2 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -280,6 +280,7 @@ config ARM64
 	select HAVE_SOFTIRQ_ON_OWN_STACK
 	select USER_STACKTRACE_SUPPORT
 	select VDSO_GETRANDOM
+	select VMAP_STACK
 	help
 	  ARM 64-bit (AArch64) Linux support.
 

-- 
2.47.1



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

* [PATCH 2/8] arm64: efi: Remove CONFIG_VMAP_STACK check
  2025-07-07 16:01 [PATCH 0/8] arm64: set VMAP_STACK by default Breno Leitao
  2025-07-07 16:01 ` [PATCH 1/8] arm64: Enable VMAP_STACK support Breno Leitao
@ 2025-07-07 16:01 ` Breno Leitao
  2025-07-07 16:01 ` [PATCH 3/8] arm64: Remove CONFIG_VMAP_STACK conditionals from THREAD_SHIFT and THREAD_ALIGN Breno Leitao
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Breno Leitao @ 2025-07-07 16:01 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Ard Biesheuvel
  Cc: linux-arm-kernel, linux-kernel, linux-efi, Breno Leitao, leo.yan,
	kernel-team, mark.rutland

Remove the CONFIG_VMAP_STACK check in arm64_efi_rt_init() since
VMAP_STACK is now always enabled on arm64.

The arch_alloc_vmap_stack() call will fail to build if VMAP_STACK
is not set, providing sufficient protection without the explicit
runtime check.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 arch/arm64/kernel/efi.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c
index 62230d6dd919..6c371b158b99 100644
--- a/arch/arm64/kernel/efi.c
+++ b/arch/arm64/kernel/efi.c
@@ -215,11 +215,6 @@ static int __init arm64_efi_rt_init(void)
 	if (!efi_enabled(EFI_RUNTIME_SERVICES))
 		return 0;
 
-	if (!IS_ENABLED(CONFIG_VMAP_STACK)) {
-		clear_bit(EFI_RUNTIME_SERVICES, &efi.flags);
-		return -ENOMEM;
-	}
-
 	p = arch_alloc_vmap_stack(THREAD_SIZE, NUMA_NO_NODE);
 	if (!p) {
 		pr_warn("Failed to allocate EFI runtime stack\n");

-- 
2.47.1



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

* [PATCH 3/8] arm64: Remove CONFIG_VMAP_STACK conditionals from THREAD_SHIFT and THREAD_ALIGN
  2025-07-07 16:01 [PATCH 0/8] arm64: set VMAP_STACK by default Breno Leitao
  2025-07-07 16:01 ` [PATCH 1/8] arm64: Enable VMAP_STACK support Breno Leitao
  2025-07-07 16:01 ` [PATCH 2/8] arm64: efi: Remove CONFIG_VMAP_STACK check Breno Leitao
@ 2025-07-07 16:01 ` Breno Leitao
  2025-07-07 16:01 ` [PATCH 4/8] arm64: remove CONFIG_VMAP_STACK conditionals from irq stack setup Breno Leitao
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Breno Leitao @ 2025-07-07 16:01 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Ard Biesheuvel
  Cc: linux-arm-kernel, linux-kernel, linux-efi, Breno Leitao, leo.yan,
	kernel-team, mark.rutland

Now that VMAP_STACK is always enabled on arm64, remove the
CONFIG_VMAP_STACK conditional logic from the definitions of THREAD_SHIFT
and THREAD_ALIGN in arch/arm64/include/asm/memory.h. This simplifies the
code by unconditionally setting THREAD_ALIGN to (2 * THREAD_SIZE) and
adjusting the THREAD_SHIFT definition to only depend on MIN_THREAD_SHIFT
and PAGE_SHIFT.

This change reflects the updated arm64 stack model, where all kernel
threads use virtually mapped stacks with guard pages, and ensures
alignment and stack sizing are consistently handled.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 arch/arm64/include/asm/memory.h | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h
index 717829df294e..5213248e081b 100644
--- a/arch/arm64/include/asm/memory.h
+++ b/arch/arm64/include/asm/memory.h
@@ -118,7 +118,7 @@
  * VMAP'd stacks are allocated at page granularity, so we must ensure that such
  * stacks are a multiple of page size.
  */
-#if defined(CONFIG_VMAP_STACK) && (MIN_THREAD_SHIFT < PAGE_SHIFT)
+#if (MIN_THREAD_SHIFT < PAGE_SHIFT)
 #define THREAD_SHIFT		PAGE_SHIFT
 #else
 #define THREAD_SHIFT		MIN_THREAD_SHIFT
@@ -135,11 +135,7 @@
  * checking sp & (1 << THREAD_SHIFT), which we can do cheaply in the entry
  * assembly.
  */
-#ifdef CONFIG_VMAP_STACK
 #define THREAD_ALIGN		(2 * THREAD_SIZE)
-#else
-#define THREAD_ALIGN		THREAD_SIZE
-#endif
 
 #define IRQ_STACK_SIZE		THREAD_SIZE
 

-- 
2.47.1



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

* [PATCH 4/8] arm64: remove CONFIG_VMAP_STACK conditionals from irq stack setup
  2025-07-07 16:01 [PATCH 0/8] arm64: set VMAP_STACK by default Breno Leitao
                   ` (2 preceding siblings ...)
  2025-07-07 16:01 ` [PATCH 3/8] arm64: Remove CONFIG_VMAP_STACK conditionals from THREAD_SHIFT and THREAD_ALIGN Breno Leitao
@ 2025-07-07 16:01 ` Breno Leitao
  2025-07-07 16:01 ` [PATCH 5/8] arm64: remove CONFIG_VMAP_STACK conditionals from traps overflow stack Breno Leitao
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Breno Leitao @ 2025-07-07 16:01 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Ard Biesheuvel
  Cc: linux-arm-kernel, linux-kernel, linux-efi, Breno Leitao, leo.yan,
	kernel-team, mark.rutland

With VMAP_STACK always enabled on arm64, drop the CONFIG_VMAP_STACK
checks and legacy irq stack allocation from arch/arm64/kernel/irq.c. The
code now unconditionally uses the VMAP_STACK path for irq stack
initialization, simplifying the logic.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 arch/arm64/kernel/irq.c | 13 -------------
 1 file changed, 13 deletions(-)

diff --git a/arch/arm64/kernel/irq.c b/arch/arm64/kernel/irq.c
index 85087e2df564..c0065a1d77cf 100644
--- a/arch/arm64/kernel/irq.c
+++ b/arch/arm64/kernel/irq.c
@@ -51,7 +51,6 @@ static void init_irq_scs(void)
 			scs_alloc(early_cpu_to_node(cpu));
 }
 
-#ifdef CONFIG_VMAP_STACK
 static void __init init_irq_stacks(void)
 {
 	int cpu;
@@ -62,18 +61,6 @@ static void __init init_irq_stacks(void)
 		per_cpu(irq_stack_ptr, cpu) = p;
 	}
 }
-#else
-/* irq stack only needs to be 16 byte aligned - not IRQ_STACK_SIZE aligned. */
-DEFINE_PER_CPU_ALIGNED(unsigned long [IRQ_STACK_SIZE/sizeof(long)], irq_stack);
-
-static void init_irq_stacks(void)
-{
-	int cpu;
-
-	for_each_possible_cpu(cpu)
-		per_cpu(irq_stack_ptr, cpu) = per_cpu(irq_stack, cpu);
-}
-#endif
 
 #ifndef CONFIG_PREEMPT_RT
 static void ____do_softirq(struct pt_regs *regs)

-- 
2.47.1



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

* [PATCH 5/8] arm64: remove CONFIG_VMAP_STACK conditionals from traps overflow stack
  2025-07-07 16:01 [PATCH 0/8] arm64: set VMAP_STACK by default Breno Leitao
                   ` (3 preceding siblings ...)
  2025-07-07 16:01 ` [PATCH 4/8] arm64: remove CONFIG_VMAP_STACK conditionals from irq stack setup Breno Leitao
@ 2025-07-07 16:01 ` Breno Leitao
  2025-07-07 16:01 ` [PATCH 6/8] arm64: remove CONFIG_VMAP_STACK checks from stacktrace overflow logic Breno Leitao
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Breno Leitao @ 2025-07-07 16:01 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Ard Biesheuvel
  Cc: linux-arm-kernel, linux-kernel, linux-efi, Breno Leitao, leo.yan,
	kernel-team, mark.rutland

With VMAP_STACK now always enabled on arm64, remove the
CONFIG_VMAP_STACK checks from overflow stack definitions and related
code in arch/arm64/kernel/traps.c. The overflow_stack and
panic_bad_stack() logic are now unconditionally included, simplifying
the source and matching the mandatory stack model.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 arch/arm64/kernel/traps.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
index 9bfa5c944379..6acbcffca650 100644
--- a/arch/arm64/kernel/traps.c
+++ b/arch/arm64/kernel/traps.c
@@ -894,8 +894,6 @@ void bad_el0_sync(struct pt_regs *regs, int reason, unsigned long esr)
 			      "Bad EL0 synchronous exception");
 }
 
-#ifdef CONFIG_VMAP_STACK
-
 DEFINE_PER_CPU(unsigned long [OVERFLOW_STACK_SIZE/sizeof(long)], overflow_stack)
 	__aligned(16);
 
@@ -927,7 +925,6 @@ void __noreturn panic_bad_stack(struct pt_regs *regs, unsigned long esr, unsigne
 	nmi_panic(NULL, "kernel stack overflow");
 	cpu_park_loop();
 }
-#endif
 
 void __noreturn arm64_serror_panic(struct pt_regs *regs, unsigned long esr)
 {

-- 
2.47.1



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

* [PATCH 6/8] arm64: remove CONFIG_VMAP_STACK checks from stacktrace overflow logic
  2025-07-07 16:01 [PATCH 0/8] arm64: set VMAP_STACK by default Breno Leitao
                   ` (4 preceding siblings ...)
  2025-07-07 16:01 ` [PATCH 5/8] arm64: remove CONFIG_VMAP_STACK conditionals from traps overflow stack Breno Leitao
@ 2025-07-07 16:01 ` Breno Leitao
  2025-07-07 16:01 ` [PATCH 7/8] arm64: remove CONFIG_VMAP_STACK checks from SDEI stack handling Breno Leitao
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Breno Leitao @ 2025-07-07 16:01 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Ard Biesheuvel
  Cc: linux-arm-kernel, linux-kernel, linux-efi, Breno Leitao, leo.yan,
	kernel-team, mark.rutland

With VMAP_STACK now always enabled on arm64, remove all CONFIG_VMAP_STACK
conditionals from overflow stack handling in stacktrace code.

This change unconditionally defines the per-CPU overflow_stack and
stackinfo_get_overflow() helper in arch/arm64/include/asm/stacktrace.h,
and always includes the overflow stack in the stack_info array in
arch/arm64/kernel/stacktrace.c. Also, drop redundant CONFIG_VMAP_STACK
checks from SDEI stack declarations.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 arch/arm64/include/asm/stacktrace.h | 6 +-----
 arch/arm64/kernel/stacktrace.c      | 4 +---
 2 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/arch/arm64/include/asm/stacktrace.h b/arch/arm64/include/asm/stacktrace.h
index 66ec8caa6ac0..6d3280932bf5 100644
--- a/arch/arm64/include/asm/stacktrace.h
+++ b/arch/arm64/include/asm/stacktrace.h
@@ -59,7 +59,6 @@ static inline bool on_task_stack(const struct task_struct *tsk,
 
 #define on_thread_stack()	(on_task_stack(current, current_stack_pointer, 1))
 
-#ifdef CONFIG_VMAP_STACK
 DECLARE_PER_CPU(unsigned long [OVERFLOW_STACK_SIZE/sizeof(long)], overflow_stack);
 
 static inline struct stack_info stackinfo_get_overflow(void)
@@ -72,11 +71,8 @@ static inline struct stack_info stackinfo_get_overflow(void)
 		.high = high,
 	};
 }
-#else
-#define stackinfo_get_overflow()	stackinfo_get_unknown()
-#endif
 
-#if defined(CONFIG_ARM_SDE_INTERFACE) && defined(CONFIG_VMAP_STACK)
+#if defined(CONFIG_ARM_SDE_INTERFACE)
 DECLARE_PER_CPU(unsigned long *, sdei_stack_normal_ptr);
 DECLARE_PER_CPU(unsigned long *, sdei_stack_critical_ptr);
 
diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c
index 1d9d51d7627f..e823320fe031 100644
--- a/arch/arm64/kernel/stacktrace.c
+++ b/arch/arm64/kernel/stacktrace.c
@@ -332,10 +332,8 @@ kunwind_stack_walk(kunwind_consume_fn consume_state,
 	struct stack_info stacks[] = {
 		stackinfo_get_task(task),
 		STACKINFO_CPU(irq),
-#if defined(CONFIG_VMAP_STACK)
 		STACKINFO_CPU(overflow),
-#endif
-#if defined(CONFIG_VMAP_STACK) && defined(CONFIG_ARM_SDE_INTERFACE)
+#if defined(CONFIG_ARM_SDE_INTERFACE)
 		STACKINFO_SDEI(normal),
 		STACKINFO_SDEI(critical),
 #endif

-- 
2.47.1



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

* [PATCH 7/8] arm64: remove CONFIG_VMAP_STACK checks from SDEI stack handling
  2025-07-07 16:01 [PATCH 0/8] arm64: set VMAP_STACK by default Breno Leitao
                   ` (5 preceding siblings ...)
  2025-07-07 16:01 ` [PATCH 6/8] arm64: remove CONFIG_VMAP_STACK checks from stacktrace overflow logic Breno Leitao
@ 2025-07-07 16:01 ` Breno Leitao
  2025-07-07 16:01 ` [PATCH 8/8] arm64: remove CONFIG_VMAP_STACK checks from entry code Breno Leitao
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Breno Leitao @ 2025-07-07 16:01 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Ard Biesheuvel
  Cc: linux-arm-kernel, linux-kernel, linux-efi, Breno Leitao, leo.yan,
	kernel-team, mark.rutland

With VMAP_STACK now always enabled on arm64, remove all
CONFIG_VMAP_STACK conditionals from SDEI stack allocation and
initialization in arch/arm64/kernel/sdei.c.

This change unconditionally defines the SDEI stack pointers and replaces
runtime checks with BUILD_BUG_ON() assertions, ensuring that the code is
only built when VMAP_STACK is enabled. This simplifies the logic and
reflects the mandatory use of VMAP_STACK for all arm64 kernel builds.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 arch/arm64/kernel/sdei.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/arch/arm64/kernel/sdei.c b/arch/arm64/kernel/sdei.c
index 255d12f881c2..6f24a0251e18 100644
--- a/arch/arm64/kernel/sdei.c
+++ b/arch/arm64/kernel/sdei.c
@@ -34,10 +34,8 @@ unsigned long sdei_exit_mode;
 DECLARE_PER_CPU(unsigned long *, sdei_stack_normal_ptr);
 DECLARE_PER_CPU(unsigned long *, sdei_stack_critical_ptr);
 
-#ifdef CONFIG_VMAP_STACK
 DEFINE_PER_CPU(unsigned long *, sdei_stack_normal_ptr);
 DEFINE_PER_CPU(unsigned long *, sdei_stack_critical_ptr);
-#endif
 
 DECLARE_PER_CPU(unsigned long *, sdei_shadow_call_stack_normal_ptr);
 DECLARE_PER_CPU(unsigned long *, sdei_shadow_call_stack_critical_ptr);
@@ -65,8 +63,7 @@ static void free_sdei_stacks(void)
 {
 	int cpu;
 
-	if (!IS_ENABLED(CONFIG_VMAP_STACK))
-		return;
+	BUILD_BUG_ON(!IS_ENABLED(CONFIG_VMAP_STACK));
 
 	for_each_possible_cpu(cpu) {
 		_free_sdei_stack(&sdei_stack_normal_ptr, cpu);
@@ -91,8 +88,7 @@ static int init_sdei_stacks(void)
 	int cpu;
 	int err = 0;
 
-	if (!IS_ENABLED(CONFIG_VMAP_STACK))
-		return 0;
+	BUILD_BUG_ON(!IS_ENABLED(CONFIG_VMAP_STACK));
 
 	for_each_possible_cpu(cpu) {
 		err = _init_sdei_stack(&sdei_stack_normal_ptr, cpu);

-- 
2.47.1



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

* [PATCH 8/8] arm64: remove CONFIG_VMAP_STACK checks from entry code
  2025-07-07 16:01 [PATCH 0/8] arm64: set VMAP_STACK by default Breno Leitao
                   ` (6 preceding siblings ...)
  2025-07-07 16:01 ` [PATCH 7/8] arm64: remove CONFIG_VMAP_STACK checks from SDEI stack handling Breno Leitao
@ 2025-07-07 16:01 ` Breno Leitao
  2025-07-07 17:25 ` [PATCH 0/8] arm64: set VMAP_STACK by default Mark Rutland
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Breno Leitao @ 2025-07-07 16:01 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Ard Biesheuvel
  Cc: linux-arm-kernel, linux-kernel, linux-efi, Breno Leitao, leo.yan,
	kernel-team, mark.rutland

With VMAP_STACK now always enabled on arm64, remove all CONFIG_VMAP_STACK
conditionals from entry handling in arch/arm64/kernel/entry-common.c and
arch/arm64/kernel/entry.S.

This change unconditionally includes the bad stack handling and overflow
detection logic, simplifying the code and reflecting the mandatory use of
VMAP_STACK for all arm64 kernel builds.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 arch/arm64/kernel/entry-common.c | 2 --
 arch/arm64/kernel/entry.S        | 6 ------
 2 files changed, 8 deletions(-)

diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c
index 7c1970b341b8..99a341ee7131 100644
--- a/arch/arm64/kernel/entry-common.c
+++ b/arch/arm64/kernel/entry-common.c
@@ -977,7 +977,6 @@ UNHANDLED(el0t, 32, fiq)
 UNHANDLED(el0t, 32, error)
 #endif /* CONFIG_COMPAT */
 
-#ifdef CONFIG_VMAP_STACK
 asmlinkage void noinstr __noreturn handle_bad_stack(struct pt_regs *regs)
 {
 	unsigned long esr = read_sysreg(esr_el1);
@@ -986,7 +985,6 @@ asmlinkage void noinstr __noreturn handle_bad_stack(struct pt_regs *regs)
 	arm64_enter_nmi(regs);
 	panic_bad_stack(regs, esr, far);
 }
-#endif /* CONFIG_VMAP_STACK */
 
 #ifdef CONFIG_ARM_SDE_INTERFACE
 asmlinkage noinstr unsigned long
diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
index 5ae2a34b50bd..ea74cb7aac5b 100644
--- a/arch/arm64/kernel/entry.S
+++ b/arch/arm64/kernel/entry.S
@@ -55,7 +55,6 @@
 	.endif
 
 	sub	sp, sp, #PT_REGS_SIZE
-#ifdef CONFIG_VMAP_STACK
 	/*
 	 * Test whether the SP has overflowed, without corrupting a GPR.
 	 * Task and IRQ stacks are aligned so that SP & (1 << THREAD_SHIFT)
@@ -97,7 +96,6 @@
 	/* We were already on the overflow stack. Restore sp/x0 and carry on. */
 	sub	sp, sp, x0
 	mrs	x0, tpidrro_el0
-#endif
 	b	el\el\ht\()_\regsize\()_\label
 .org .Lventry_start\@ + 128	// Did we overflow the ventry slot?
 	.endm
@@ -540,7 +538,6 @@ SYM_CODE_START(vectors)
 	kernel_ventry	0, t, 32, error		// Error 32-bit EL0
 SYM_CODE_END(vectors)
 
-#ifdef CONFIG_VMAP_STACK
 SYM_CODE_START_LOCAL(__bad_stack)
 	/*
 	 * We detected an overflow in kernel_ventry, which switched to the
@@ -568,7 +565,6 @@ SYM_CODE_START_LOCAL(__bad_stack)
 	bl	handle_bad_stack
 	ASM_BUG()
 SYM_CODE_END(__bad_stack)
-#endif /* CONFIG_VMAP_STACK */
 
 
 	.macro entry_handler el:req, ht:req, regsize:req, label:req
@@ -1003,7 +999,6 @@ SYM_CODE_START(__sdei_asm_handler)
 1:	adr_this_cpu dst=x5, sym=sdei_active_critical_event, tmp=x6
 2:	str	x19, [x5]
 
-#ifdef CONFIG_VMAP_STACK
 	/*
 	 * entry.S may have been using sp as a scratch register, find whether
 	 * this is a normal or critical event and switch to the appropriate
@@ -1016,7 +1011,6 @@ SYM_CODE_START(__sdei_asm_handler)
 2:	mov	x6, #SDEI_STACK_SIZE
 	add	x5, x5, x6
 	mov	sp, x5
-#endif
 
 #ifdef CONFIG_SHADOW_CALL_STACK
 	/* Use a separate shadow call stack for normal and critical events */

-- 
2.47.1



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

* Re: [PATCH 1/8] arm64: Enable VMAP_STACK support
  2025-07-07 16:01 ` [PATCH 1/8] arm64: Enable VMAP_STACK support Breno Leitao
@ 2025-07-07 17:23   ` Mark Rutland
  2025-07-08  9:39     ` Breno Leitao
  0 siblings, 1 reply; 15+ messages in thread
From: Mark Rutland @ 2025-07-07 17:23 UTC (permalink / raw)
  To: Breno Leitao
  Cc: Catalin Marinas, Will Deacon, Ard Biesheuvel, linux-arm-kernel,
	linux-kernel, linux-efi, leo.yan, kernel-team

Hi Breno,

On Mon, Jul 07, 2025 at 09:01:01AM -0700, Breno Leitao wrote:
> Enable virtually mapped kernel stacks for ARM64. This provides better
> stack overflow detection and improved security by mapping kernel stacks
> in vmalloc space rather than using direct mapping.
> 
> VMAP_STACK helps catch stack overflows early by placing guard pages
> around kernel stacks, and also provides better isolation between
> kernel stacks and other kernel data structures.
> 
> All dependencies are satisfied for arm64: HAVE_ARCH_VMAP_STACK is
> already selected above, and KASAN_VMALLOC is selected when KASAN is
> enabled, meeting the KASAN dependency requirements.

I reckon it might be better to say something like:

| arm64: Mandate VMAP_STACK
|
| On arm64, VMAP_STACK has been enabled by default for a while now, and
| the only reason to disable it was a historical lack of support for
| KASAN_VMALLOC. Today there's no good reason to disable VMAP_STACK.
|
| Mandate VMAP_STACK, which will allow code to be simplified in
| subsequent patches.

... to make it clear that we're not changing the default, and we are
removing the ability to deselect VMAP_STACK.

Either way, the patch itself looks good to me.

Mark.

> 
> Suggested-by: Will Deacon <will@kernel.org>
> Signed-off-by: Breno Leitao <leitao@debian.org>
> ---
>  arch/arm64/Kconfig | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> index 393d71124f5d..179b302f43c2 100644
> --- a/arch/arm64/Kconfig
> +++ b/arch/arm64/Kconfig
> @@ -280,6 +280,7 @@ config ARM64
>  	select HAVE_SOFTIRQ_ON_OWN_STACK
>  	select USER_STACKTRACE_SUPPORT
>  	select VDSO_GETRANDOM
> +	select VMAP_STACK
>  	help
>  	  ARM 64-bit (AArch64) Linux support.
>  
> 
> -- 
> 2.47.1
> 


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

* Re: [PATCH 0/8] arm64: set VMAP_STACK by default
  2025-07-07 16:01 [PATCH 0/8] arm64: set VMAP_STACK by default Breno Leitao
                   ` (7 preceding siblings ...)
  2025-07-07 16:01 ` [PATCH 8/8] arm64: remove CONFIG_VMAP_STACK checks from entry code Breno Leitao
@ 2025-07-07 17:25 ` Mark Rutland
  2025-07-08  1:13 ` Ard Biesheuvel
  2025-07-08 14:44 ` Will Deacon
  10 siblings, 0 replies; 15+ messages in thread
From: Mark Rutland @ 2025-07-07 17:25 UTC (permalink / raw)
  To: Breno Leitao
  Cc: Catalin Marinas, Will Deacon, Ard Biesheuvel, linux-arm-kernel,
	linux-kernel, linux-efi, leo.yan, kernel-team

On Mon, Jul 07, 2025 at 09:01:00AM -0700, Breno Leitao wrote:
> Hi all,
> 
> This patchset select VMAP_STACK on arm64 by default, and cleans up the
> code by removing all associated CONFIG_VMAP_STACK conditionals.
> 
> This is a suggestion from Will Deacon from another discussion[1].
> 
> With VMAP_STACK now always enabled on arm64, the code can be
> significantly simplified, reducing complexity and potential for
> misconfiguration.
> 
> Overview of Changes
> 
>     * Remove all #ifdef CONFIG_VMAP_STACK and related runtime checks
>       throughout the architecture codebase.
>     * Replace runtime checks with build-time assertions where
>       appropriate.
> 
> Link: https://lore.kernel.org/all/aGfYL8eXjTA9puQr@willie-the-truck/ [1]
> 
> Signed-off-by: Breno Leitao <leitao@debian.org>

Nice!

Aside from a minor comment on the first patch, this all looks good to
me. For the series:

Acked-by: Mark Rutland <mark.rutland@arm.com>

Mark.

> ---
> Breno Leitao (8):
>       arm64: Enable VMAP_STACK support
>       arm64: efi: Remove CONFIG_VMAP_STACK check
>       arm64: Remove CONFIG_VMAP_STACK conditionals from THREAD_SHIFT and THREAD_ALIGN
>       arm64: remove CONFIG_VMAP_STACK conditionals from irq stack setup
>       arm64: remove CONFIG_VMAP_STACK conditionals from traps overflow stack
>       arm64: remove CONFIG_VMAP_STACK checks from stacktrace overflow logic
>       arm64: remove CONFIG_VMAP_STACK checks from SDEI stack handling
>       arm64: remove CONFIG_VMAP_STACK checks from entry code
> 
>  arch/arm64/Kconfig                  |  1 +
>  arch/arm64/include/asm/memory.h     |  6 +-----
>  arch/arm64/include/asm/stacktrace.h |  6 +-----
>  arch/arm64/kernel/efi.c             |  5 -----
>  arch/arm64/kernel/entry-common.c    |  2 --
>  arch/arm64/kernel/entry.S           |  6 ------
>  arch/arm64/kernel/irq.c             | 13 -------------
>  arch/arm64/kernel/sdei.c            |  8 ++------
>  arch/arm64/kernel/stacktrace.c      |  4 +---
>  arch/arm64/kernel/traps.c           |  3 ---
>  10 files changed, 6 insertions(+), 48 deletions(-)
> ---
> base-commit: 9dd1757493416310a5e71146a08bc228869f8dae
> change-id: 20250707-arm64_vmap-fa70ba3c9cfb
> 
> Best regards,
> -- 
> Breno Leitao <leitao@debian.org>
> 


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

* Re: [PATCH 0/8] arm64: set VMAP_STACK by default
  2025-07-07 16:01 [PATCH 0/8] arm64: set VMAP_STACK by default Breno Leitao
                   ` (8 preceding siblings ...)
  2025-07-07 17:25 ` [PATCH 0/8] arm64: set VMAP_STACK by default Mark Rutland
@ 2025-07-08  1:13 ` Ard Biesheuvel
  2025-07-08 14:44 ` Will Deacon
  10 siblings, 0 replies; 15+ messages in thread
From: Ard Biesheuvel @ 2025-07-08  1:13 UTC (permalink / raw)
  To: Breno Leitao
  Cc: Catalin Marinas, Will Deacon, linux-arm-kernel, linux-kernel,
	linux-efi, leo.yan, kernel-team, mark.rutland

On Tue, 8 Jul 2025 at 02:01, Breno Leitao <leitao@debian.org> wrote:
>
> Hi all,
>
> This patchset select VMAP_STACK on arm64 by default, and cleans up the
> code by removing all associated CONFIG_VMAP_STACK conditionals.
>
> This is a suggestion from Will Deacon from another discussion[1].
>
> With VMAP_STACK now always enabled on arm64, the code can be
> significantly simplified, reducing complexity and potential for
> misconfiguration.
>
> Overview of Changes
>
>     * Remove all #ifdef CONFIG_VMAP_STACK and related runtime checks
>       throughout the architecture codebase.
>     * Replace runtime checks with build-time assertions where
>       appropriate.
>
> Link: https://lore.kernel.org/all/aGfYL8eXjTA9puQr@willie-the-truck/ [1]
>
> Signed-off-by: Breno Leitao <leitao@debian.org>
> ---
> Breno Leitao (8):
>       arm64: Enable VMAP_STACK support
>       arm64: efi: Remove CONFIG_VMAP_STACK check
>       arm64: Remove CONFIG_VMAP_STACK conditionals from THREAD_SHIFT and THREAD_ALIGN
>       arm64: remove CONFIG_VMAP_STACK conditionals from irq stack setup
>       arm64: remove CONFIG_VMAP_STACK conditionals from traps overflow stack
>       arm64: remove CONFIG_VMAP_STACK checks from stacktrace overflow logic
>       arm64: remove CONFIG_VMAP_STACK checks from SDEI stack handling
>       arm64: remove CONFIG_VMAP_STACK checks from entry code
>

For the series,

Acked-by: Ard Biesheuvel <ardb@kernel.org>


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

* Re: [PATCH 1/8] arm64: Enable VMAP_STACK support
  2025-07-07 17:23   ` Mark Rutland
@ 2025-07-08  9:39     ` Breno Leitao
  2025-07-08 12:14       ` Will Deacon
  0 siblings, 1 reply; 15+ messages in thread
From: Breno Leitao @ 2025-07-08  9:39 UTC (permalink / raw)
  To: Mark Rutland
  Cc: Catalin Marinas, Will Deacon, Ard Biesheuvel, linux-arm-kernel,
	linux-kernel, linux-efi, leo.yan, kernel-team

Hello Mark,

On Mon, Jul 07, 2025 at 06:23:09PM +0100, Mark Rutland wrote:
> On Mon, Jul 07, 2025 at 09:01:01AM -0700, Breno Leitao wrote:
> > Enable virtually mapped kernel stacks for ARM64. This provides better
> > stack overflow detection and improved security by mapping kernel stacks
> > in vmalloc space rather than using direct mapping.
> > 
> > VMAP_STACK helps catch stack overflows early by placing guard pages
> > around kernel stacks, and also provides better isolation between
> > kernel stacks and other kernel data structures.
> > 
> > All dependencies are satisfied for arm64: HAVE_ARCH_VMAP_STACK is
> > already selected above, and KASAN_VMALLOC is selected when KASAN is
> > enabled, meeting the KASAN dependency requirements.
> 
> I reckon it might be better to say something like:
> 
> | arm64: Mandate VMAP_STACK
> |
> | On arm64, VMAP_STACK has been enabled by default for a while now, and
> | the only reason to disable it was a historical lack of support for
> | KASAN_VMALLOC. Today there's no good reason to disable VMAP_STACK.
> |
> | Mandate VMAP_STACK, which will allow code to be simplified in
> | subsequent patches.
> 
> ... to make it clear that we're not changing the default, and we are
> removing the ability to deselect VMAP_STACK.
> 
> Either way, the patch itself looks good to me.

Thanks for the suggestion. I will update and respin.

Thanks for the review,
--breno


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

* Re: [PATCH 1/8] arm64: Enable VMAP_STACK support
  2025-07-08  9:39     ` Breno Leitao
@ 2025-07-08 12:14       ` Will Deacon
  0 siblings, 0 replies; 15+ messages in thread
From: Will Deacon @ 2025-07-08 12:14 UTC (permalink / raw)
  To: Breno Leitao
  Cc: Mark Rutland, Catalin Marinas, Ard Biesheuvel, linux-arm-kernel,
	linux-kernel, linux-efi, leo.yan, kernel-team

Hey Breno,

Thanks for doing this.

On Tue, Jul 08, 2025 at 02:39:56AM -0700, Breno Leitao wrote:
> On Mon, Jul 07, 2025 at 06:23:09PM +0100, Mark Rutland wrote:
> > On Mon, Jul 07, 2025 at 09:01:01AM -0700, Breno Leitao wrote:
> > > Enable virtually mapped kernel stacks for ARM64. This provides better
> > > stack overflow detection and improved security by mapping kernel stacks
> > > in vmalloc space rather than using direct mapping.
> > > 
> > > VMAP_STACK helps catch stack overflows early by placing guard pages
> > > around kernel stacks, and also provides better isolation between
> > > kernel stacks and other kernel data structures.
> > > 
> > > All dependencies are satisfied for arm64: HAVE_ARCH_VMAP_STACK is
> > > already selected above, and KASAN_VMALLOC is selected when KASAN is
> > > enabled, meeting the KASAN dependency requirements.
> > 
> > I reckon it might be better to say something like:
> > 
> > | arm64: Mandate VMAP_STACK
> > |
> > | On arm64, VMAP_STACK has been enabled by default for a while now, and
> > | the only reason to disable it was a historical lack of support for
> > | KASAN_VMALLOC. Today there's no good reason to disable VMAP_STACK.
> > |
> > | Mandate VMAP_STACK, which will allow code to be simplified in
> > | subsequent patches.
> > 
> > ... to make it clear that we're not changing the default, and we are
> > removing the ability to deselect VMAP_STACK.
> > 
> > Either way, the patch itself looks good to me.
> 
> Thanks for the suggestion. I will update and respin.

No need to respin just for that; I can fold the above when I apply.

Cheers,

Will


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

* Re: [PATCH 0/8] arm64: set VMAP_STACK by default
  2025-07-07 16:01 [PATCH 0/8] arm64: set VMAP_STACK by default Breno Leitao
                   ` (9 preceding siblings ...)
  2025-07-08  1:13 ` Ard Biesheuvel
@ 2025-07-08 14:44 ` Will Deacon
  10 siblings, 0 replies; 15+ messages in thread
From: Will Deacon @ 2025-07-08 14:44 UTC (permalink / raw)
  To: Catalin Marinas, Ard Biesheuvel, Breno Leitao
  Cc: kernel-team, Will Deacon, linux-arm-kernel, linux-kernel,
	linux-efi, leo.yan, kernel-team, mark.rutland

On Mon, 07 Jul 2025 09:01:00 -0700, Breno Leitao wrote:
> This patchset select VMAP_STACK on arm64 by default, and cleans up the
> code by removing all associated CONFIG_VMAP_STACK conditionals.
> 
> This is a suggestion from Will Deacon from another discussion[1].
> 
> With VMAP_STACK now always enabled on arm64, the code can be
> significantly simplified, reducing complexity and potential for
> misconfiguration.
> 
> [...]

Applied to arm64 (for-next/vmap-stack), thanks!

[1/8] arm64: Enable VMAP_STACK support
      https://git.kernel.org/arm64/c/ef6861b8e6dd
[2/8] arm64: efi: Remove CONFIG_VMAP_STACK check
      https://git.kernel.org/arm64/c/63829521a8e8
[3/8] arm64: Remove CONFIG_VMAP_STACK conditionals from THREAD_SHIFT and THREAD_ALIGN
      https://git.kernel.org/arm64/c/0909c719c17b
[4/8] arm64: remove CONFIG_VMAP_STACK conditionals from irq stack setup
      https://git.kernel.org/arm64/c/c4a5699d5cef
[5/8] arm64: remove CONFIG_VMAP_STACK conditionals from traps overflow stack
      https://git.kernel.org/arm64/c/e5692bba1e66
[6/8] arm64: remove CONFIG_VMAP_STACK checks from stacktrace overflow logic
      https://git.kernel.org/arm64/c/907cb5cd8efd
[7/8] arm64: remove CONFIG_VMAP_STACK checks from SDEI stack handling
      https://git.kernel.org/arm64/c/3e72b9e9f01a
[8/8] arm64: remove CONFIG_VMAP_STACK checks from entry code
      https://git.kernel.org/arm64/c/9d1869f0f537

Cheers,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev


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

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

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-07 16:01 [PATCH 0/8] arm64: set VMAP_STACK by default Breno Leitao
2025-07-07 16:01 ` [PATCH 1/8] arm64: Enable VMAP_STACK support Breno Leitao
2025-07-07 17:23   ` Mark Rutland
2025-07-08  9:39     ` Breno Leitao
2025-07-08 12:14       ` Will Deacon
2025-07-07 16:01 ` [PATCH 2/8] arm64: efi: Remove CONFIG_VMAP_STACK check Breno Leitao
2025-07-07 16:01 ` [PATCH 3/8] arm64: Remove CONFIG_VMAP_STACK conditionals from THREAD_SHIFT and THREAD_ALIGN Breno Leitao
2025-07-07 16:01 ` [PATCH 4/8] arm64: remove CONFIG_VMAP_STACK conditionals from irq stack setup Breno Leitao
2025-07-07 16:01 ` [PATCH 5/8] arm64: remove CONFIG_VMAP_STACK conditionals from traps overflow stack Breno Leitao
2025-07-07 16:01 ` [PATCH 6/8] arm64: remove CONFIG_VMAP_STACK checks from stacktrace overflow logic Breno Leitao
2025-07-07 16:01 ` [PATCH 7/8] arm64: remove CONFIG_VMAP_STACK checks from SDEI stack handling Breno Leitao
2025-07-07 16:01 ` [PATCH 8/8] arm64: remove CONFIG_VMAP_STACK checks from entry code Breno Leitao
2025-07-07 17:25 ` [PATCH 0/8] arm64: set VMAP_STACK by default Mark Rutland
2025-07-08  1:13 ` Ard Biesheuvel
2025-07-08 14:44 ` Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).