scs: switch to vmapped shadow stacks
v2 cover scs: switch to vmapped shadow stacks
As discussed a few months ago [1][2], virtually mapped shadow call stacks are better for safety and robustness. This series dusts off the VMAP option from the original SCS patch series and switches the kernel to use virtually mapped shadow stacks unconditionally when SCS is enabled.
[1] https://lore.kernel.org/lkml/20200515172355.GD23334@willie-the-truck/
[2] https://lore.kernel.org/lkml/[email protected]/
Changes in v2:
- Added SCS_ORDER and used it to define SCS_SIZE, switched vmalloc() to use SCS_SIZE and removed the alignment.
- Moved the kasan_unpoison_vmalloc() to scs_alloc() when using a cached shadow stack instead of calling it in scs_free().
- Added a comment to scs_free().
- Moved arm64 IRQ and SDEI shadow stack initialization to irq/sdei.c, and removed the now unneeded scs.c.
Sami Tolvanen (2):
scs: switch to vmapped shadow stacks
arm64: scs: use vmapped IRQ and SDEI shadow stacks
arch/arm64/kernel/Makefile | 1 - arch/arm64/kernel/entry.S | 6 ++-- arch/arm64/kernel/irq.c | 19 ++++++++++ arch/arm64/kernel/scs.c | 16 --------- arch/arm64/kernel/sdei.c | 71 +++++++++++++++++++++++++++++++------- include/linux/scs.h | 16 ++++----- kernel/scs.c | 66 +++++++++++++++++++++++++++++------ 7 files changed, 142 insertions(+), 53 deletions(-) delete mode 100644 arch/arm64/kernel/scs.c
base-commit: d5beb3140f91b1c8a3d41b14d729aefa4dcc58bc
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
PATCH v2 1/2 scs: switch to vmapped shadow stacks
The kernel currently uses kmem_cache to allocate shadow call stacks, which means an overflows may not be immediately detected and can potentially result in another task's shadow stack to be overwritten.
This change switches SCS to use virtually mapped shadow stacks for tasks, which increases shadow stack size to a full page and provides more robust overflow detection, similarly to VMAP_STACK.
--- include/linux/scs.h | 12 ++++----- kernel/scs.c | 66 +++++++++++++++++++++++++++++++++++++-------- 2 files changed, 61 insertions(+), 17 deletions(-)
include/linux/scs.h +6 -6
@@ -15,12 +15,8 @@#ifdef CONFIG_SHADOW_CALL_STACK -/* -* In testing, 1 KiB shadow stack size (i.e. 128 stack frames on a 64-bit -* architecture) provided ~40% safety margin on stack usage while keeping -* memory allocation overhead reasonable. -*/ -#define SCS_SIZE SZ_1K +#define SCS_ORDER 0 +#define SCS_SIZE (PAGE_SIZE << SCS_ORDER)#define GFP_SCS (GFP_KERNEL | __GFP_ZERO)/* An illegal pointer value to mark the end of the shadow stack. */
@@ -33,6 +29,8 @@#define task_scs (tsk) (task_thread_info(tsk)->scs_base)#define task_scs_sp (tsk) (task_thread_info(tsk)->scs_sp) +void *scs_alloc (int node); +void scs_free (void *s);void scs_init (void );int scs_prepare (struct task_struct *tsk,int node);void scs_release (struct task_struct *tsk);
@@ -61,6 +59,8 @@ static inline bool task_scs_end_corrupted(struct task_struct *tsk)#else /* CONFIG_SHADOW_CALL_STACK */ +static inline void *scs_alloc (int node) {return NULL ; } +static inline void scs_free (void *s) {}static inline void scs_init (void ) {}static inline void scs_task_reset (struct task_struct *tsk) {}static inline int scs_prepare (struct task_struct *tsk,int node) {return 0 ; }
kernel/scs.c +55 -11
105 lines not on this page · raw message
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
Quoted 9 lines · Sami Tolvanen
The kernel currently uses
kmem_cacheto allocate shadow call stacks, which means an overflows may not be immediately detected and can potentially result in another task's shadow stack to be overwritten.This change switches SCS to use virtually mapped shadow stacks for tasks, which increases shadow stack size to a full page and provides more robust overflow detection, similarly to
VMAP_STACK.Signed-off-by Sami Tolvanen <[email protected]>
Signature · 1 line
Kees Cook
Quoted 94 lines · Sami Tolvanen
The kernel currently uses
kmem_cacheto allocate shadow call stacks, which means an overflows may not be immediately detected and can potentially result in another task's shadow stack to be overwritten.This change switches SCS to use virtually mapped shadow stacks for tasks, which increases shadow stack size to a full page and provides more robust overflow detection, similarly to
VMAP_STACK.Signed-off-by Sami Tolvanen <[email protected]>--- include/linux/scs.h | 12 ++++----- kernel/scs.c | 66 +++++++++++++++++++++++++++++++++++++-------- 2 files changed, 61 insertions(+), 17 deletions(-)include/linux/scs.h +6
-6@@ -15,12 +15,8 @@#ifdef CONFIG_SHADOW_CALL_STACK -/* -* In testing, 1 KiB shadow stack size (i.e. 128 stack frames on a 64-bit -* architecture) provided ~40% safety margin on stack usage while keeping -* memory allocation overhead reasonable. -*/ -#define SCS_SIZE SZ_1K +#define SCS_ORDER 0 +#define SCS_SIZE (PAGE_SIZE << SCS_ORDER)#define GFP_SCS (GFP_KERNEL | __GFP_ZERO)/* An illegal pointer value to mark the end of the shadow stack. */ @@ -33,6 +29,8 @@#define task_scs (tsk) (task_thread_info(tsk)->scs_base)#define task_scs_sp (tsk) (task_thread_info(tsk)->scs_sp) +void *scs_alloc (int node); +void scs_free (void *s);void scs_init (void );int scs_prepare (struct task_struct *tsk,int node);void scs_release (struct task_struct *tsk);@@ -61,6 +59,8 @@ static inline bool task_scs_end_corrupted(struct task_struct *tsk)#else /* CONFIG_SHADOW_CALL_STACK */ +static inline void *scs_alloc (int node) {return NULL ; } +static inline void scs_free (void *s) {}static inline void scs_init (void ) {}static inline void scs_task_reset (struct task_struct *tsk) {}static inline int scs_prepare (struct task_struct *tsk,int node) {return 0 ; }kernel/scs.c +16
-6@@ -5,50 +5,94 @@* Copyright (C) 2019 Google LLC */ +#include <linux/cpuhotplug.h> #include <linux/kasan.h> #include <linux/mm.h> #include <linux/scs.h> -#include <linux/slab.h> +#include <linux/vmalloc.h> #include <linux/vmstat.h> -static struct kmem_cache *scs_cache; -static void __scs_account (void *s,int account) { -struct page *scs_page =virt_to_page (s); +struct page *scs_page =vmalloc_to_page (s);mod_node_page_state (page_pgdat (scs_page),NR_KERNEL_SCS_KB , account * (SCS_SIZE /SZ_1K )); } -static void *scs_alloc (int node) +/* Matches NR_CACHED_STACKS for VMAP_STACK */ +#define NR_CACHED_SCS 2 +static DEFINE_PER_CPU(void *, scs_cache[NR_CACHED_SCS]); + +void *scs_alloc (int node) { -void *s =kmem_cache_alloc_node (scs_cache,GFP_SCS , node); +int i; +void *s; + +for (i =0 ; i <NR_CACHED_SCS ; i++) { + s =this_cpu_xchg (scs_cache[i],NULL ); +if (s) { +kasan_unpoison_vmalloc (s,SCS_SIZE ); +memset (s,0 ,SCS_SIZE );
kernel/scs.c line 46
Quoted 10 lines
kernel/scs.c +7
-0+ goto out; + } + } + + s =__vmalloc_node_range (SCS_SIZE ,1 ,VMALLOC_START ,VMALLOC_END , +GFP_SCS ,PAGE_KERNEL ,0 , node, +__builtin_return_address (0 ));if (!s)return NULL ;
Sorry I didn't spot this before, but if you put the xchg/vmalloc code into a new __scs_alloc() function then you can drop the label and this becomes:
s = __scs_alloc(...); if (!s) return NULL; *__scs_maghic(s) = SCS_ENG_MAGIC; ...
With that:
Will
Quoted 28 lines · Will Deacon
Quoted 11 lines · Sami Tolvanen
kernel/scs.c +9
-1+void *scs_alloc (int node) { -void *s =kmem_cache_alloc_node (scs_cache,GFP_SCS , node); +int i; +void *s; + +for (i =0 ; i <NR_CACHED_SCS ; i++) { + s =this_cpu_xchg (scs_cache[i],NULL ); +if (s) { +kasan_unpoison_vmalloc (s,SCS_SIZE ); +memset (s,0 ,SCS_SIZE );kernel/scs.c line 46
Quoted 10 lines
kernel/scs.c +7
-0+ goto out; + } + } + + s =__vmalloc_node_range (SCS_SIZE ,1 ,VMALLOC_START ,VMALLOC_END , +GFP_SCS ,PAGE_KERNEL ,0 , node, +__builtin_return_address (0 ));if (!s)return NULL ;Sorry I didn't spot this before, but if you put the xchg/vmalloc code into a new
__scs_alloc()function then you can drop the label and this becomes:
Quoted 6 lines
s = __scs_alloc(...);
if (!s)
return NULL;
*__scs_maghic(s) = SCS_ENG_MAGIC;
...Good point, I'll change this in v3.
Sami
PATCH v2 2/2 arm64: scs: use vmapped IRQ and SDEI shadow stacks
In reply to Sami TolvanenUse scs_alloc() to allocate also IRQ and SDEI shadow stacks instead of using statically allocated stacks.
--- arch/arm64/kernel/Makefile | 1 - arch/arm64/kernel/entry.S | 6 ++-- arch/arm64/kernel/irq.c | 19 ++++++++++ arch/arm64/kernel/scs.c | 16 --------- arch/arm64/kernel/sdei.c | 71 +++++++++++++++++++++++++++++++------- include/linux/scs.h | 4 --- 6 files changed, 81 insertions(+), 36 deletions(-) delete mode 100644 arch/arm64/kernel/scs.c
arch/arm64/kernel/Makefile +0 -1
@@ -58,7 +58,6 @@ obj-$(CONFIG_CRASH_DUMP) += crash_dump.o obj-$(CONFIG_CRASH_CORE) += crash_core.o obj-$(CONFIG_ARM_SDE_INTERFACE) += sdei.o obj-$(CONFIG_ARM64_PTR_AUTH) += pointer_auth.o -obj-$(CONFIG_SHADOW_CALL_STACK) += scs.o obj-$(CONFIG_ARM64_MTE) += mte.o obj-y += vdso/ probes/
arch/arm64/kernel/entry.S +3 -3
@@ -441,7 +441,7 @@ SYM_CODE_END(__swpan_exit_el0) #ifdef CONFIG_SHADOW_CALL_STACK /* also switch to the irq shadow stack */ - adr_this_cpu scs_sp, irq_shadow_call_stack, x26 + ldr_this_cpu scs_sp, irq_shadow_call_stack_ptr, x26 #endif 9998:
@@ -1097,9 +1097,9 @@ SYM_CODE_START(__sdei_asm_handler) #ifdef CONFIG_SHADOW_CALL_STACK /* Use a separate shadow call stack for normal and critical events */ cbnz w4, 3f - adr_this_cpu dst=scs_sp, sym=sdei_shadow_call_stack_normal, tmp=x6 + ldr_this_cpu dst=scs_sp, sym=sdei_shadow_call_stack_normal_ptr, tmp=x6 b 4f -3: adr_this_cpu dst=scs_sp, sym=sdei_shadow_call_stack_critical, tmp=x6 +3: ldr_this_cpu dst=scs_sp, sym=sdei_shadow_call_stack_critical_ptr, tmp=x6 4: #endif
arch/arm64/kernel/irq.c +19 -0
@@ -17,6 +17,7 @@#include <linux/init.h> #include <linux/irqchip.h> #include <linux/kprobes.h> +#include <linux/scs.h> #include <linux/seq_file.h> #include <linux/vmalloc.h> #include <asm/daifflags.h>
@@ -27,6 +28,22 @@ DEFINE_PER_CPU(struct nmi_ctx, nmi_contexts); DEFINE_PER_CPU(unsigned long *, irq_stack_ptr); + +DECLARE_PER_CPU(unsigned long *, irq_shadow_call_stack_ptr); + +#ifdef CONFIG_SHADOW_CALL_STACK +DEFINE_PER_CPU(unsigned long *, irq_shadow_call_stack_ptr); +#endif + +static void init_irq_scs (void ) +{ +int cpu; + +for_each_possible_cpu (cpu) +per_cpu (irq_shadow_call_stack_ptr, cpu) = +scs_alloc (cpu_to_node (cpu)); +} +#ifdef CONFIG_VMAP_STACK static void init_irq_stacks (void ) {
@@ -54,6 +71,8 @@ static void init_irq_stacks(void)void __init init_IRQ (void ) {init_irq_stacks (); +if (IS_ENABLED (CONFIG_SHADOW_CALL_STACK )) +init_irq_scs ();irqchip_init ();if (!handle_arch_irq)panic ("No interrupt controller found." );
arch/arm64/kernel/scs.c deleted +0 -16
@@ -1,16 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* -* Shadow Call Stack support. -* -* Copyright (C) 2019 Google LLC -*/ - -#include <linux/percpu.h> -#include <linux/scs.h> - -DEFINE_SCS (irq_shadow_call_stack); - -#ifdef CONFIG_ARM_SDE_INTERFACE -DEFINE_SCS (sdei_shadow_call_stack_normal); -DEFINE_SCS (sdei_shadow_call_stack_critical); -#endif
arch/arm64/kernel/sdei.c +59 -12
112 lines not on this page · raw message
include/linux/scs.h +0 -4
@@ -22,10 +22,6 @@/* An illegal pointer value to mark the end of the shadow stack. */ #define SCS_END_MAGIC (0x5f6UL + POISON_POINTER_DELTA) -/* Allocate a static per-CPU shadow stack */ -#define DEFINE_SCS (name) \ - DEFINE_PER_CPU(unsigned long [SCS_SIZE/sizeof(long)], name) \ -#define task_scs (tsk) (task_thread_info(tsk)->scs_base)#define task_scs_sp (tsk) (task_thread_info(tsk)->scs_sp)
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
Re: [PATCH v2 2/2] arm64: scs: use vmapped IRQ and SDEI shadow stacks
Quoted 13 lines · Sami Tolvanen
Use
scs_alloc()to allocate also IRQ and SDEI shadow stacks instead of using statically allocated stacks.Signed-off-by Sami Tolvanen <[email protected]>--- arch/arm64/kernel/Makefile | 1 - arch/arm64/kernel/entry.S | 6 ++-- arch/arm64/kernel/irq.c | 19 ++++++++++ arch/arm64/kernel/scs.c | 16 --------- arch/arm64/kernel/sdei.c | 71 +++++++++++++++++++++++++++++++------- include/linux/scs.h | 4 --- 6 files changed, 81 insertions(+), 36 deletions(-) delete mode 100644 arch/arm64/kernel/scs.c
[...]
Quoted 33 lines
arch/arm64/kernel/sdei.c +17
-6@@ -70,18 +97,40 @@ static int _init_sdei_stack(unsigned long * __percpu *ptr, int cpu)return 0 ; } +static int _init_sdei_scs (unsigned long *__percpu *ptr,int cpu) +{ +void *s; + + s =scs_alloc (cpu_to_node (cpu)); +if (!s) +return -ENOMEM ; +per_cpu (*ptr, cpu) = s; + +return 0 ; +} +static int init_sdei_stacks (void ) {int cpu;int err =0 ;for_each_possible_cpu (cpu) { - err =_init_sdei_stack (&sdei_stack_normal_ptr, cpu); -if (err) -break ; - err =_init_sdei_stack (&sdei_stack_critical_ptr, cpu); -if (err) -break ; +if (IS_ENABLED (CONFIG_VMAP_STACK )) { + err =_init_sdei_stack (&sdei_stack_normal_ptr, cpu); +if (err) +break ; + err =_init_sdei_stack (&sdei_stack_critical_ptr, cpu);
arch/arm64/kernel/sdei.c static int _init_sdei_stack(unsigned long * __percpu *ptr, int cpu) · line 132
Quoted 10 lines
arch/arm64/kernel/sdei.c +10
-0+if (err) +break ; + } +if (IS_ENABLED (CONFIG_SHADOW_CALL_STACK )) { + err =_init_sdei_scs (&sdei_shadow_call_stack_normal_ptr, cpu); +if (err) +break ; + err =_init_sdei_scs (&sdei_shadow_call_stack_critical_ptr, cpu); +if (err) +break ;
This looks ok to me, but I think it would be better to follow the same approach as you have for the IRQ stacks and instead have a separate init_sdei_scs() function (similarly for the free() path), which means you can simply the IS_ENABLED() checks too.
Either way:
Will
Re: [PATCH v2 2/2] arm64: scs: use vmapped IRQ and SDEI shadow stacks
Quoted 58 lines · Will Deacon
Quoted 13 lines · Sami Tolvanen
Use
scs_alloc()to allocate also IRQ and SDEI shadow stacks instead of using statically allocated stacks.Signed-off-by Sami Tolvanen <[email protected]>--- arch/arm64/kernel/Makefile | 1 - arch/arm64/kernel/entry.S | 6 ++-- arch/arm64/kernel/irq.c | 19 ++++++++++ arch/arm64/kernel/scs.c | 16 --------- arch/arm64/kernel/sdei.c | 71 +++++++++++++++++++++++++++++++------- include/linux/scs.h | 4 --- 6 files changed, 81 insertions(+), 36 deletions(-) delete mode 100644 arch/arm64/kernel/scs.c[...]
Quoted 40 lines
arch/arm64/kernel/sdei.c +24
-6@@ -70,18 +97,40 @@ static int _init_sdei_stack(unsigned long * __percpu *ptr, int cpu)return 0 ; } +static int _init_sdei_scs (unsigned long *__percpu *ptr,int cpu) +{ +void *s; + + s =scs_alloc (cpu_to_node (cpu)); +if (!s) +return -ENOMEM ; +per_cpu (*ptr, cpu) = s; + +return 0 ; +} +static int init_sdei_stacks (void ) {int cpu;int err =0 ;for_each_possible_cpu (cpu) { - err =_init_sdei_stack (&sdei_stack_normal_ptr, cpu); -if (err) -break ; - err =_init_sdei_stack (&sdei_stack_critical_ptr, cpu); -if (err) -break ; +if (IS_ENABLED (CONFIG_VMAP_STACK )) { + err =_init_sdei_stack (&sdei_stack_normal_ptr, cpu); +if (err) +break ; + err =_init_sdei_stack (&sdei_stack_critical_ptr, cpu); +if (err) +break ; + } +if (IS_ENABLED (CONFIG_SHADOW_CALL_STACK )) { + err =_init_sdei_scs (&sdei_shadow_call_stack_normal_ptr, cpu); +if (err) +break ;
Quoted 8 lines
arch/arm64/kernel/sdei.c static int _init_sdei_stack(unsigned long * __percpu *ptr, int cpu) · line 132
Quoted 3 lines
arch/arm64/kernel/sdei.c +3
-0+ err =_init_sdei_scs (&sdei_shadow_call_stack_critical_ptr, cpu); +if (err) +break ;This looks ok to me, but I think it would be better to follow the same approach as you have for the IRQ stacks and instead have a separate
init_sdei_scs()function (similarly for thefree()path), which means you can simply theIS_ENABLED()checks too.
OK, I can change this in v3. It makes error handling in sdei_arch_get_entry_point() a bit more awkward though. We'll need something like this:
if (IS_ENABLED(CONFIG_VMAP_STACK)) {
if (init_sdei_stacks())
return 0;
}
if (IS_ENABLED(CONFIG_SHADOW_CALL_STACK)) {
if (init_sdei_scs()) {
if (IS_ENABLED(CONFIG_VMAP_STACK))
free_sdei_stacks();
return 0;
}
}Sami
Will Deacon
maintainerRe: [PATCH v2 2/2] arm64: scs: use vmapped IRQ and SDEI shadow stacks
Quoted 72 lines · Sami Tolvanen
Quoted 58 lines · Will Deacon
Quoted 13 lines · Sami Tolvanen
Use
scs_alloc()to allocate also IRQ and SDEI shadow stacks instead of using statically allocated stacks.Signed-off-by Sami Tolvanen <[email protected]>--- arch/arm64/kernel/Makefile | 1 - arch/arm64/kernel/entry.S | 6 ++-- arch/arm64/kernel/irq.c | 19 ++++++++++ arch/arm64/kernel/scs.c | 16 --------- arch/arm64/kernel/sdei.c | 71 +++++++++++++++++++++++++++++++------- include/linux/scs.h | 4 --- 6 files changed, 81 insertions(+), 36 deletions(-) delete mode 100644 arch/arm64/kernel/scs.c[...]
Quoted 40 lines
arch/arm64/kernel/sdei.c +24
-6@@ -70,18 +97,40 @@ static int _init_sdei_stack(unsigned long * __percpu *ptr, int cpu)return 0 ; } +static int _init_sdei_scs (unsigned long *__percpu *ptr,int cpu) +{ +void *s; + + s =scs_alloc (cpu_to_node (cpu)); +if (!s) +return -ENOMEM ; +per_cpu (*ptr, cpu) = s; + +return 0 ; +} +static int init_sdei_stacks (void ) {int cpu;int err =0 ;for_each_possible_cpu (cpu) { - err =_init_sdei_stack (&sdei_stack_normal_ptr, cpu); -if (err) -break ; - err =_init_sdei_stack (&sdei_stack_critical_ptr, cpu); -if (err) -break ; +if (IS_ENABLED (CONFIG_VMAP_STACK )) { + err =_init_sdei_stack (&sdei_stack_normal_ptr, cpu); +if (err) +break ; + err =_init_sdei_stack (&sdei_stack_critical_ptr, cpu); +if (err) +break ; + } +if (IS_ENABLED (CONFIG_SHADOW_CALL_STACK )) { + err =_init_sdei_scs (&sdei_shadow_call_stack_normal_ptr, cpu); +if (err) +break ;Quoted 8 lines
arch/arm64/kernel/sdei.c static int _init_sdei_stack(unsigned long * __percpu *ptr, int cpu) · line 132
Quoted 3 lines
arch/arm64/kernel/sdei.c +3
-0+ err =_init_sdei_scs (&sdei_shadow_call_stack_critical_ptr, cpu); +if (err) +break ;This looks ok to me, but I think it would be better to follow the same approach as you have for the IRQ stacks and instead have a separate
init_sdei_scs()function (similarly for thefree()path), which means you can simply theIS_ENABLED()checks too.OK, I can change this in v3. It makes error handling in
sdei_arch_get_entry_point()a bit more awkward though. We'll need something like this:
Quoted 11 lines
if (IS_ENABLED(CONFIG_VMAP_STACK)) {
if (init_sdei_stacks())
return 0;
}
if (IS_ENABLED(CONFIG_SHADOW_CALL_STACK)) {
if (init_sdei_scs()) {
if (IS_ENABLED(CONFIG_VMAP_STACK))
free_sdei_stacks();
return 0;
}Can you push the IS_ENABLED() checks into their respective functions? Then you can do something like:
if (init_sdei_stacks()) return 0; if (init_sdei_scs()) goto out_free_stacks; ...
out_free_stacks:
free_sdei_stacks(); return 0;
Will
Will Deacon
maintainerRe: [PATCH v2 2/2] arm64: scs: use vmapped IRQ and SDEI shadow stacks
Quoted 58 lines · Will Deacon
Quoted 34 lines · Sami Tolvanen
Quoted 24 lines · Will Deacon
Quoted 12 lines · Sami Tolvanen
for_each_possible_cpu(cpu) {arch/arm64/kernel/sdei.c +5
-6- err =_init_sdei_stack (&sdei_stack_normal_ptr, cpu); -if (err) -break ; - err =_init_sdei_stack (&sdei_stack_critical_ptr, cpu); -if (err) -break ; +if (IS_ENABLED (CONFIG_VMAP_STACK )) { + err =_init_sdei_stack (&sdei_stack_normal_ptr, cpu); +if (err) +break ; + err =_init_sdei_stack (&sdei_stack_critical_ptr, cpu);arch/arm64/kernel/sdei.c static int _init_sdei_stack(unsigned long * __percpu *ptr, int cpu) · line 132
Quoted 10 lines
arch/arm64/kernel/sdei.c +10
-0+if (err) +break ; + } +if (IS_ENABLED (CONFIG_SHADOW_CALL_STACK )) { + err =_init_sdei_scs (&sdei_shadow_call_stack_normal_ptr, cpu); +if (err) +break ; + err =_init_sdei_scs (&sdei_shadow_call_stack_critical_ptr, cpu); +if (err) +break ;Quoted 4 lines
This looks ok to me, but I think it would be better to follow the same approach as you have for the IRQ stacks and instead have a separate
init_sdei_scs()function (similarly for thefree()path), which means you can simply theIS_ENABLED()checks too.OK, I can change this in v3. It makes error handling in
sdei_arch_get_entry_point()a bit more awkward though. We'll need something like this:Quoted 11 lines
if (IS_ENABLED(CONFIG_VMAP_STACK)) { if (init_sdei_stacks()) return 0; } if (IS_ENABLED(CONFIG_SHADOW_CALL_STACK)) { if (init_sdei_scs()) { if (IS_ENABLED(CONFIG_VMAP_STACK)) free_sdei_stacks(); return 0; }Can you push the
IS_ENABLED()checks into their respective functions? Then you can do something like:if (init_sdei_stacks()) return 0; if (init_sdei_scs()) goto out_free_stacks; ...
Quoted 3 lines
out_free_stacks:free_sdei_stacks(); return 0;
Wait, I see you already posted a v3. Maybe I can just hack this up on top...
Will