Skip to content

Commit fc5e5d0

Browse files
Ada Couprie Diazwilldeacon
authored andcommitted
arm64: debug: split bkpt32 exception entry
Currently all debug exceptions share common entry code and are routed to `do_debug_exception()`, which calls dynamically-registered handlers for each specific debug exception. This is unfortunate as different debug exceptions have different entry handling requirements, and it would be better to handle these distinct requirements earlier. The BKPT32 exception can only be triggered by a BKPT instruction. Thus, we know that the PC is a legitimate address and isn't being used to train a branch predictor with a bogus address : we don't need to call `arm64_apply_bp_hardening()`. The handler for this exception only pends a signal and doesn't depend on any per-CPU state : we don't need to inhibit preemption, nor do we need to keep the DAIF exceptions masked, so we can unmask them earlier. Split the BKPT32 exception entry and adjust function signatures and its behaviour to match its relaxed constraints compared to other debug exceptions. We can also remove `NOKRPOBE_SYMBOL`, as this cannot lead to a kprobe recursion. This replaces the last usage of `el0_dbg()`, so remove it. Signed-off-by: Ada Couprie Diaz <[email protected]> Tested-by: Luis Claudio R. Goncalves <[email protected]> Reviewed-by: Will Deacon <[email protected]> Acked-by: Mark Rutland <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 31575e1 commit fc5e5d0

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

arch/arm64/include/asm/exception.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ void do_el0_softstep(unsigned long esr, struct pt_regs *regs);
7474
void do_el1_softstep(unsigned long esr, struct pt_regs *regs);
7575
void do_el0_brk64(unsigned long esr, struct pt_regs *regs);
7676
void do_el1_brk64(unsigned long esr, struct pt_regs *regs);
77+
void do_bkpt32(unsigned long esr, struct pt_regs *regs);
7778
void do_fpsimd_acc(unsigned long esr, struct pt_regs *regs);
7879
void do_sve_acc(unsigned long esr, struct pt_regs *regs);
7980
void do_sme_acc(unsigned long esr, struct pt_regs *regs);

arch/arm64/kernel/debug-monitors.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,13 @@ void do_el1_brk64(unsigned long esr, struct pt_regs *regs)
270270
}
271271
NOKPROBE_SYMBOL(do_el1_brk64);
272272

273+
#ifdef CONFIG_COMPAT
274+
void do_bkpt32(unsigned long esr, struct pt_regs *regs)
275+
{
276+
arm64_notify_die("aarch32 BKPT", regs, SIGTRAP, TRAP_BRKPT, regs->pc, esr);
277+
}
278+
#endif /* CONFIG_COMPAT */
279+
273280
bool try_handle_aarch32_break(struct pt_regs *regs)
274281
{
275282
u32 arm_instr;

arch/arm64/kernel/entry-common.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -866,18 +866,6 @@ static void noinstr el0_brk64(struct pt_regs *regs, unsigned long esr)
866866
exit_to_user_mode(regs);
867867
}
868868

869-
static void noinstr __maybe_unused
870-
el0_dbg(struct pt_regs *regs, unsigned long esr)
871-
{
872-
/* Only watchpoints write FAR_EL1, otherwise its UNKNOWN */
873-
unsigned long far = read_sysreg(far_el1);
874-
875-
enter_from_user_mode(regs);
876-
do_debug_exception(far, esr, regs);
877-
local_daif_restore(DAIF_PROCCTX);
878-
exit_to_user_mode(regs);
879-
}
880-
881869
static void noinstr el0_svc(struct pt_regs *regs)
882870
{
883871
enter_from_user_mode(regs);
@@ -1038,6 +1026,14 @@ static void noinstr el0_svc_compat(struct pt_regs *regs)
10381026
exit_to_user_mode(regs);
10391027
}
10401028

1029+
static void noinstr el0_bkpt32(struct pt_regs *regs, unsigned long esr)
1030+
{
1031+
enter_from_user_mode(regs);
1032+
local_daif_restore(DAIF_PROCCTX);
1033+
do_bkpt32(esr, regs);
1034+
exit_to_user_mode(regs);
1035+
}
1036+
10411037
asmlinkage void noinstr el0t_32_sync_handler(struct pt_regs *regs)
10421038
{
10431039
unsigned long esr = read_sysreg(esr_el1);
@@ -1081,7 +1077,7 @@ asmlinkage void noinstr el0t_32_sync_handler(struct pt_regs *regs)
10811077
el0_watchpt(regs, esr);
10821078
break;
10831079
case ESR_ELx_EC_BKPT32:
1084-
el0_dbg(regs, esr);
1080+
el0_bkpt32(regs, esr);
10851081
break;
10861082
default:
10871083
el0_inv(regs, esr);

0 commit comments

Comments
 (0)