From c9c4d38aa84d87a4d24a7857e98bfa7b6dff1f68 Mon Sep 17 00:00:00 2001 From: Andriy Gapon Date: Wed, 16 May 2018 06:52:08 +0000 Subject: [PATCH] followup to r332730/r332752: set kdb_why to "trap" for fatal traps This change updates arm, arm64 and mips achitectures. Additionally, it removes redundant checks for kdb_active where it already results in kdb_reenter() and adds kdb_reenter() calls where they were missing. Some architectures check the return value of kdb_trap(), but some don't. I haven't changed any of that. Some trap handling routines have a return code. I am not sure if I provided correct ones for returns after kdb_reenter(). kdb_reenter should never return unless kdb_jmpbufp is NULL for some reason. Only compile tested for all affected architectures. There can be bugs resulting from my poor understanding of architecture specific details. Reported by: jhb Reviewed by: jhb, eadler MFC after: 4 weeks Differential Revision: https://reviews.freebsd.org/D15431 --- sys/arm/arm/trap-v4.c | 17 +++++++++++++++-- sys/arm/arm/trap-v6.c | 5 ++++- sys/arm64/arm64/trap.c | 12 ++++++++++-- sys/mips/mips/trap.c | 11 +++++++++-- 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/sys/arm/arm/trap-v4.c b/sys/arm/arm/trap-v4.c index bec22abf0dcd..3ee730432e75 100644 --- a/sys/arm/arm/trap-v4.c +++ b/sys/arm/arm/trap-v4.c @@ -404,7 +404,16 @@ dab_fatal(struct trapframe *tf, u_int fsr, u_int far, struct thread *td, struct ksig *ksig) { const char *mode; +#ifdef KDB + bool handled; +#endif +#ifdef KDB + if (kdb_active) { + kdb_reenter(); + return (0); + } +#endif #ifdef KDTRACE_HOOKS if (!TRAP_USERMODE(tf)) { if (dtrace_trap_func != NULL && (*dtrace_trap_func)(tf, far & FAULT_TYPE_MASK)) @@ -447,9 +456,13 @@ dab_fatal(struct trapframe *tf, u_int fsr, u_int far, struct thread *td, printf(", pc =%08x\n\n", tf->tf_pc); #ifdef KDB - if (debugger_on_panic || kdb_active) - if (kdb_trap(fsr, 0, tf)) + if (debugger_on_panic) { + kdb_why = KDB_WHY_TRAP; + handled = kdb_trap(fsr, 0, tf); + kdb_why = KDB_WHY_UNSET; + if (handled) return (0); + } #endif panic("Fatal abort"); /*NOTREACHED*/ diff --git a/sys/arm/arm/trap-v6.c b/sys/arm/arm/trap-v6.c index d3efc0c0ee53..ae78401e91a3 100644 --- a/sys/arm/arm/trap-v6.c +++ b/sys/arm/arm/trap-v6.c @@ -599,8 +599,11 @@ abort_fatal(struct trapframe *tf, u_int idx, u_int fsr, u_int far, printf(", pc =%08x\n\n", tf->tf_pc); #ifdef KDB - if (debugger_on_panic || kdb_active) + if (debugger_on_panic) { + kdb_why = KDB_WHY_TRAP; kdb_trap(fsr, 0, tf); + kdb_why = KDB_WHY_UNSET; + } #endif panic("Fatal abort"); /*NOTREACHED*/ diff --git a/sys/arm64/arm64/trap.c b/sys/arm64/arm64/trap.c index 71237bb98e4f..e0f2f448c445 100644 --- a/sys/arm64/arm64/trap.c +++ b/sys/arm64/arm64/trap.c @@ -156,6 +156,9 @@ data_abort(struct thread *td, struct trapframe *frame, uint64_t esr, vm_prot_t ftype; vm_offset_t va; int error, sig, ucode; +#ifdef KDB + bool handled; +#endif /* * According to the ARMv8-A rev. A.g, B2.10.5 "Load-Exclusive @@ -226,9 +229,14 @@ data_abort(struct thread *td, struct trapframe *frame, uint64_t esr, printf(" esr: %.8lx\n", esr); #ifdef KDB - if (debugger_on_panic || kdb_active) - if (kdb_trap(ESR_ELx_EXCEPTION(esr), 0, frame)) + if (debugger_on_panic) { + kdb_why = KDB_WHY_TRAP; + handled = kdb_trap(ESR_ELx_EXCEPTION(esr), 0, + frame); + kdb_why = KDB_WHY_UNSET; + if (handled) return; + } #endif panic("vm_fault failed: %lx", frame->tf_elr); } diff --git a/sys/mips/mips/trap.c b/sys/mips/mips/trap.c index a796c6bd8ccb..746208e521fd 100644 --- a/sys/mips/mips/trap.c +++ b/sys/mips/mips/trap.c @@ -530,7 +530,12 @@ trap(struct trapframe *trapframe) register_t *frame_regs; trapdebug_enter(trapframe, 0); - +#ifdef KDB + if (kdb_active) { + kdb_reenter(); + return (0); + } +#endif type = (trapframe->cause & MIPS_CR_EXC_CODE) >> MIPS_CR_EXC_CODE_SHIFT; if (TRAPF_USERMODE(trapframe)) { type |= T_USER; @@ -1095,8 +1100,10 @@ trap(struct trapframe *trapframe) #endif #ifdef KDB - if (debugger_on_panic || kdb_active) { + if (debugger_on_panic) { + kdb_why = KDB_WHY_TRAP; kdb_trap(type, 0, trapframe); + kdb_why = KDB_WHY_UNSET; } #endif panic("trap");