Skip to content

Commit b322c65

Browse files
dianderswilldeacon
authored andcommitted
arm64: Call debug_traps_init() from trap_init() to help early kgdb
A new kgdb feature will soon land (kgdb_earlycon) that lets us run kgdb much earlier. In order for everything to work properly it's important that the break hook is setup by the time we process "kgdbwait". Right now the break hook is setup in debug_traps_init() and that's called from arch_initcall(). That's a bit too late since kgdb_earlycon really needs things to be setup by the time the system calls dbg_late_init(). We could fix this by adding call_break_hook() into early_brk64() and that works fine. However, it's a little ugly. Instead, let's just add a call to debug_traps_init() straight from trap_init(). There's already a documented dependency between trap_init() and debug_traps_init() and this makes the dependency more obvious rather than just relying on a comment. NOTE: this solution isn't early enough to let us select the "ARCH_HAS_EARLY_DEBUG" KConfig option that is introduced by the kgdb_earlycon patch series. That would only be set if we could do breakpoints when early params are parsed. This patch only enables "late early" breakpoints, AKA breakpoints when dbg_late_init() is called. It's expected that this should be fine for most people. It should also be noted that if you crash you can still end up in kgdb earlier than debug_traps_init(). Since you don't need breakpoints to debug a crash that's fine. Suggested-by: Will Deacon <[email protected]> Signed-off-by: Douglas Anderson <[email protected]> Acked-by: Will Deacon <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/20200513160501.1.I0b5edf030cc6ebef6ab4829f8867cdaea42485d8@changeid Signed-off-by: Will Deacon <[email protected]>
1 parent ab8ad27 commit b322c65

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

arch/arm64/include/asm/debug-monitors.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,7 @@ static inline int reinstall_suspended_bps(struct pt_regs *regs)
125125

126126
int aarch32_break_handler(struct pt_regs *regs);
127127

128+
void debug_traps_init(void);
129+
128130
#endif /* __ASSEMBLY */
129131
#endif /* __ASM_DEBUG_MONITORS_H */

arch/arm64/kernel/debug-monitors.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,15 +376,13 @@ int aarch32_break_handler(struct pt_regs *regs)
376376
}
377377
NOKPROBE_SYMBOL(aarch32_break_handler);
378378

379-
static int __init debug_traps_init(void)
379+
void __init debug_traps_init(void)
380380
{
381381
hook_debug_fault_code(DBG_ESR_EVT_HWSS, single_step_handler, SIGTRAP,
382382
TRAP_TRACE, "single-step handler");
383383
hook_debug_fault_code(DBG_ESR_EVT_BRK, brk_handler, SIGTRAP,
384384
TRAP_BRKPT, "ptrace BRK handler");
385-
return 0;
386385
}
387-
arch_initcall(debug_traps_init);
388386

389387
/* Re-enable single step for syscall restarting. */
390388
void user_rewind_single_step(struct task_struct *task)

arch/arm64/kernel/traps.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,11 +1047,11 @@ int __init early_brk64(unsigned long addr, unsigned int esr,
10471047
return bug_handler(regs, esr) != DBG_HOOK_HANDLED;
10481048
}
10491049

1050-
/* This registration must happen early, before debug_traps_init(). */
10511050
void __init trap_init(void)
10521051
{
10531052
register_kernel_break_hook(&bug_break_hook);
10541053
#ifdef CONFIG_KASAN_SW_TAGS
10551054
register_kernel_break_hook(&kasan_break_hook);
10561055
#endif
1056+
debug_traps_init();
10571057
}

0 commit comments

Comments
 (0)