Skip to content

Commit de57ecc

Browse files
RISC-V: Add some comments about the shadow and overflow stacks
It took me a while to page all this back in when trying to review the recent spin_shadow_stack, so I figured I'd just write up some comments. Reviewed-by: Guo Ren <[email protected]> Reviewed-by: Jisheng Zhang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent b003b3b commit de57ecc

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

arch/riscv/kernel/traps.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,18 +200,18 @@ void __init trap_init(void)
200200
}
201201

202202
#ifdef CONFIG_VMAP_STACK
203+
/*
204+
* Extra stack space that allows us to provide panic messages when the kernel
205+
* has overflowed its stack.
206+
*/
203207
static DEFINE_PER_CPU(unsigned long [OVERFLOW_STACK_SIZE/sizeof(long)],
204208
overflow_stack)__aligned(16);
205209
/*
206-
* shadow stack, handled_ kernel_ stack_ overflow(in kernel/entry.S) is used
207-
* to get per-cpu overflow stack(get_overflow_stack).
210+
* A temporary stack for use by handle_kernel_stack_overflow. This is used so
211+
* we can call into C code to get the per-hart overflow stack. Usage of this
212+
* stack must be protected by spin_shadow_stack.
208213
*/
209214
long shadow_stack[SHADOW_OVERFLOW_STACK_SIZE/sizeof(long)] __aligned(16);
210-
asmlinkage unsigned long get_overflow_stack(void)
211-
{
212-
return (unsigned long)this_cpu_ptr(overflow_stack) +
213-
OVERFLOW_STACK_SIZE;
214-
}
215215

216216
/*
217217
* A pseudo spinlock to protect the shadow stack from being used by multiple
@@ -222,6 +222,12 @@ asmlinkage unsigned long get_overflow_stack(void)
222222
*/
223223
unsigned long spin_shadow_stack;
224224

225+
asmlinkage unsigned long get_overflow_stack(void)
226+
{
227+
return (unsigned long)this_cpu_ptr(overflow_stack) +
228+
OVERFLOW_STACK_SIZE;
229+
}
230+
225231
asmlinkage void handle_bad_stack(struct pt_regs *regs)
226232
{
227233
unsigned long tsk_stk = (unsigned long)current->stack;

0 commit comments

Comments
 (0)