Hi, On Tue, May 12, 2020 at 11:17 PM Will Deacon <will@xxxxxxxxxx> wrote: > > Hey Doug, > > On Tue, May 12, 2020 at 08:27:50AM -0700, Doug Anderson wrote: > > On Tue, May 12, 2020 at 12:36 AM Will Deacon <will@xxxxxxxxxx> wrote: > > > On Mon, May 11, 2020 at 03:45:02PM -0700, Doug Anderson wrote: > > > > On Mon, May 11, 2020 at 7:59 AM Will Deacon <will@xxxxxxxxxx> wrote: > > > > > On Tue, Apr 28, 2020 at 02:13:45PM -0700, Douglas Anderson wrote: > > > > > > diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c > > > > > > index cf402be5c573..a8173f0c1774 100644 > > > > > > --- a/arch/arm64/kernel/traps.c > > > > > > +++ b/arch/arm64/kernel/traps.c > > > > > > @@ -1044,6 +1044,9 @@ int __init early_brk64(unsigned long addr, unsigned int esr, > > > > > > if ((comment & ~KASAN_BRK_MASK) == KASAN_BRK_IMM) > > > > > > return kasan_handler(regs, esr) != DBG_HOOK_HANDLED; > > > > > > #endif > > > > > > + if (call_break_hook(regs, esr) == DBG_HOOK_HANDLED) > > > > > > + return 0; > > > > > > > > > > I think this just means we're not running debug_traps_init() early enough, > > > > > and actually the KASAN early handler is unnecessary too. > > > > > > > > > > If we call debug_traps_init() directly from setup_arch() and drop the > > > > > arch_initcall(), can we then drop early_brk64 entirely? > > > > > > > > It seems to work in my testing. ...but the worry I have is the > > > > comment right before trap_init(). It says: > > > > > > > > /* This registration must happen early, before debug_traps_init(). */ > > > > > > I /think/ the reason for this is because debug_traps_init() replaces the > > > BRK vector, so if that runs before the break hooks have been registered > > > for e.g. BUG() then BUG() won't work during that window. Hmm, so dropping > > > early_brk64 is problematic after all. Damn. > > > > > > Is trap_init() early enough for you? If so, we could call debug_traps_init() > > > from traps_init() after registering the break hooks. > > > > "Early enough" is a subjective term, of course. The earlier we can > > init, the earlier we can drop into the debugger. ...but, of course, > > everyone thinks their feature is the most important and should be > > first, so let's see... > > > > Certainly if we waited until trap_init() it wouldn't be early enough > > to set "ARCH_HAS_EARLY_DEBUG". Setting that means that debugging is > > ready when early params are parsed and those happen at the start of > > setup_arch(). The call to trap_init() happens a bit later. > > > > If we decide that we just don't care about getting > > "ARCH_HAS_EARLY_DEBUG" to work then the earliest we'll be able to > > break into the debugger (via kgdbwait) is dbg_late_init(). That > > _does_ happen after trap_init() so your solution would work. > > > > As a person who spends most of his time in driver land, it wouldn't be > > the end of the world to wait for dbg_late_init(). That's still much > > earlier than most code I'd ever debug. ...and, bonus points is that > > if we hit a crash any time after earlyparams we _will_ still drop into > > the debugger. It's only breakpoints that won't be available until > > dbg_late_init(). > > > > > > tl;dr: > > > > * If we care about "kgdbwait" and breakpoints working as early as > > possible then we need my patch. > > > > * If we are OK w/ a slightly later "kgdbwait" then I think we can move > > debug_traps_init() to trap_init() and get rid of the early version. > > > > > > Please let me know which way you'd like to proceed. > > Let's go with the trap_init() approach for now, and we can revisit it later > if somebody has a compelling reason to initialise things earlier. However, > I don't think you can remove early_brk64(), as it's needed for BUG() to > work correctly. Posted at: https://lore.kernel.org/r/20200513160501.1.I0b5edf030cc6ebef6ab4829f8867cdaea42485d8@changeid I'll also reply to the v4 version of this patch to point at it. -Doug