Skip to content

Commit 8168f09

Browse files
mrutland-armwilldeacon
authored andcommitted
arm64: entry: split bad stack entry
We'd like to keep all the entry sequencing in entry-common.c, as this will allow us to ensure this is consistent, and free from any unsound instrumentation. Currently handle_bad_stack() performs the NMI entry sequence in traps.c. Let's split the low-level entry sequence from the reporting, moving the former to entry-common.c and keeping the latter in traps.c. To make it clear that reporting function never returns, it is renamed to panic_bad_stack(). Signed-off-by: Mark Rutland <mark.rutland@arm.com> Acked-by: Catalin Marinas <catalin.marinas@arm.com> Acked-by: Marc Zyngier <maz@kernel.org> Reviewed-by: Joey Gouly <joey.gouly@arm.com> Cc: James Morse <james.morse@arm.com> Cc: Will Deacon <will@kernel.org> Link: https://lore.kernel.org/r/20210607094624.34689-17-mark.rutland@arm.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent afd05e2 commit 8168f09

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

arch/arm64/include/asm/exception.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ static inline u32 disr_to_esr(u64 disr)
3131
return esr;
3232
}
3333

34+
asmlinkage void handle_bad_stack(struct pt_regs *regs);
35+
3436
asmlinkage void el1t_64_sync_handler(struct pt_regs *regs);
3537
asmlinkage void el1t_64_irq_handler(struct pt_regs *regs);
3638
asmlinkage void el1t_64_fiq_handler(struct pt_regs *regs);
@@ -73,4 +75,6 @@ void do_el0_svc(struct pt_regs *regs);
7375
void do_el0_svc_compat(struct pt_regs *regs);
7476
void do_ptrauth_fault(struct pt_regs *regs, unsigned int esr);
7577
void do_serror(struct pt_regs *regs, unsigned int esr);
78+
79+
void panic_bad_stack(struct pt_regs *regs, unsigned int esr, unsigned long far);
7680
#endif /* __ASM_EXCEPTION_H */

arch/arm64/kernel/entry-common.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,3 +699,14 @@ UNHANDLED(el0t, 32, irq)
699699
UNHANDLED(el0t, 32, fiq)
700700
UNHANDLED(el0t, 32, error)
701701
#endif /* CONFIG_COMPAT */
702+
703+
#ifdef CONFIG_VMAP_STACK
704+
asmlinkage void noinstr handle_bad_stack(struct pt_regs *regs)
705+
{
706+
unsigned int esr = read_sysreg(esr_el1);
707+
unsigned long far = read_sysreg(far_el1);
708+
709+
arm64_enter_nmi(regs);
710+
panic_bad_stack(regs, esr, far);
711+
}
712+
#endif /* CONFIG_VMAP_STACK */

arch/arm64/kernel/traps.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -763,15 +763,11 @@ void bad_el0_sync(struct pt_regs *regs, int reason, unsigned int esr)
763763
DEFINE_PER_CPU(unsigned long [OVERFLOW_STACK_SIZE/sizeof(long)], overflow_stack)
764764
__aligned(16);
765765

766-
asmlinkage void noinstr handle_bad_stack(struct pt_regs *regs)
766+
void panic_bad_stack(struct pt_regs *regs, unsigned int esr, unsigned long far)
767767
{
768768
unsigned long tsk_stk = (unsigned long)current->stack;
769769
unsigned long irq_stk = (unsigned long)this_cpu_read(irq_stack_ptr);
770770
unsigned long ovf_stk = (unsigned long)this_cpu_ptr(overflow_stack);
771-
unsigned int esr = read_sysreg(esr_el1);
772-
unsigned long far = read_sysreg(far_el1);
773-
774-
arm64_enter_nmi(regs);
775771

776772
console_verbose();
777773
pr_emerg("Insufficient stack space to handle exception!");

0 commit comments

Comments
 (0)