Re: [PATCH 2/2] arm64: scs: use vmapped IRQ and SDEI shadow stacks
From: Will Deacon <will@kernel.org>
Date: 2020-11-19 13:11:49
Also in:
lkml
On Thu, Oct 22, 2020 at 01:23:55PM -0700, Sami Tolvanen wrote:
quoted hunk ↗ jump to hunk
Use scs_alloc() to allocate also IRQ and SDEI shadow stacks instead of using statically allocated stacks. Signed-off-by: Sami Tolvanen <samitolvanen@google.com> --- arch/arm64/include/asm/scs.h | 21 ++++++++++- arch/arm64/kernel/entry.S | 6 ++-- arch/arm64/kernel/irq.c | 2 ++ arch/arm64/kernel/scs.c | 67 +++++++++++++++++++++++++++++++++--- arch/arm64/kernel/sdei.c | 7 ++++ include/linux/scs.h | 8 ++--- kernel/scs.c | 4 +-- 7 files changed, 101 insertions(+), 14 deletions(-)diff --git a/arch/arm64/include/asm/scs.h b/arch/arm64/include/asm/scs.h index eaa2cd92e4c1..e9d2c3e67ff9 100644 --- a/arch/arm64/include/asm/scs.h +++ b/arch/arm64/include/asm/scs.h@@ -24,6 +24,25 @@ .endm #endif /* CONFIG_SHADOW_CALL_STACK */ -#endif /* __ASSEMBLY __ */ +#else /* __ASSEMBLY__ */ + +#include <linux/scs.h> + +#ifdef CONFIG_SHADOW_CALL_STACK + +extern void scs_init_irq(void); + +extern void scs_free_sdei(void);
This is only called on the scs_init_sdei() failure path, so it can be static. But see below, because I think we should move all of these functions out of scs.c anyway.
quoted hunk ↗ jump to hunk
diff --git a/arch/arm64/kernel/irq.c b/arch/arm64/kernel/irq.c index 9cf2fb87584a..54ba3725bc0e 100644 --- a/arch/arm64/kernel/irq.c +++ b/arch/arm64/kernel/irq.c@@ -20,6 +20,7 @@ #include <linux/seq_file.h> #include <linux/vmalloc.h> #include <asm/daifflags.h> +#include <asm/scs.h> #include <asm/vmap_stack.h> /* Only access this in an NMI enter/exit */@@ -54,6 +55,7 @@ static void init_irq_stacks(void) void __init init_IRQ(void) { init_irq_stacks(); + scs_init_irq();
If we internalise this in init_irq_stacks()...
quoted hunk ↗ jump to hunk
diff --git a/arch/arm64/kernel/sdei.c b/arch/arm64/kernel/sdei.c index 7689f2031c0c..04519a7cb51d 100644 --- a/arch/arm64/kernel/sdei.c +++ b/arch/arm64/kernel/sdei.c@@ -13,6 +13,7 @@ #include <asm/kprobes.h> #include <asm/mmu.h> #include <asm/ptrace.h> +#include <asm/scs.h> #include <asm/sections.h> #include <asm/stacktrace.h> #include <asm/sysreg.h>@@ -138,6 +139,12 @@ unsigned long sdei_arch_get_entry_point(int conduit) return 0; } + if (scs_init_sdei()) {
... and this in init_sdei_stacks(), then I think we remove all of the code from arch/arm64/kernel/scs.c.
quoted hunk ↗ jump to hunk
diff --git a/include/linux/scs.h b/include/linux/scs.h index 86e3c4b7b714..6b35a83576d4 100644 --- a/include/linux/scs.h +++ b/include/linux/scs.h@@ -21,13 +21,11 @@ /* 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) +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);@@ -56,6 +54,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; }diff --git a/kernel/scs.c b/kernel/scs.c index 2136edba548d..8df4a92cd939 100644 --- a/kernel/scs.c +++ b/kernel/scs.c@@ -24,7 +24,7 @@ static void __scs_account(void *s, int account) #define NR_CACHED_SCS 2 static DEFINE_PER_CPU(void *, scs_cache[NR_CACHED_SCS]); -static void *scs_alloc(int node) +void *scs_alloc(int node) { int i; void *s;@@ -63,7 +63,7 @@ static void *scs_alloc(int node) return s; } -static void scs_free(void *s) +void scs_free(void *s)
Should be part of the first patch? Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel