Skip to content

Commit 5dd11d5

Browse files
committed
mips,kgdb: kdb low level trap catch and stack trace
The only way the debugger can handle a trap in inside rcu_lock, notify_die, or atomic_notifier_call_chain without a recursive fault is to have a low level "first opportunity handler" do_trap_or_bp() handler. Generally this will be something the vast majority of folks will not need, but for those who need it, it is added as a kernel .config option called KGDB_LOW_LEVEL_TRAP. Also added was a die notification for oops such that kdb can catch an oops for analysis. There appeared to be no obvious way to pass the struct pt_regs from the original exception back to the stack back tracer, so a special case was added to show_stack() for when kdb is active because you generally desire to generally look at the back trace of the original exception. Signed-off-by: Jason Wessel <[email protected]> Acked-by: Ralf Baechle <[email protected]>
1 parent ba797b2 commit 5dd11d5

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

arch/mips/include/asm/kgdb.h

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ extern int kgdb_early_setup;
3838
extern void *saved_vectors[32];
3939
extern void handle_exception(struct pt_regs *regs);
4040
extern void breakinst(void);
41+
extern int kgdb_ll_trap(int cmd, const char *str,
42+
struct pt_regs *regs, long err, int trap, int sig);
4143

4244
#endif /* __KERNEL__ */
4345

arch/mips/kernel/kgdb.c

+21-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ static int kgdb_mips_notify(struct notifier_block *self, unsigned long cmd,
203203
if (atomic_read(&kgdb_active) != -1)
204204
kgdb_nmicallback(smp_processor_id(), regs);
205205

206-
if (kgdb_handle_exception(trap, compute_signal(trap), 0, regs))
206+
if (kgdb_handle_exception(trap, compute_signal(trap), cmd, regs))
207207
return NOTIFY_DONE;
208208

209209
if (atomic_read(&kgdb_setting_breakpoint))
@@ -217,6 +217,26 @@ static int kgdb_mips_notify(struct notifier_block *self, unsigned long cmd,
217217
return NOTIFY_STOP;
218218
}
219219

220+
#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
221+
int kgdb_ll_trap(int cmd, const char *str,
222+
struct pt_regs *regs, long err, int trap, int sig)
223+
{
224+
struct die_args args = {
225+
.regs = regs,
226+
.str = str,
227+
.err = err,
228+
.trapnr = trap,
229+
.signr = sig,
230+
231+
};
232+
233+
if (!kgdb_io_module_registered)
234+
return NOTIFY_DONE;
235+
236+
return kgdb_mips_notify(NULL, cmd, &args);
237+
}
238+
#endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */
239+
220240
static struct notifier_block kgdb_notifier = {
221241
.notifier_call = kgdb_mips_notify,
222242
};

arch/mips/kernel/traps.c

+13
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/kgdb.h>
2727
#include <linux/kdebug.h>
2828
#include <linux/notifier.h>
29+
#include <linux/kdb.h>
2930

3031
#include <asm/bootinfo.h>
3132
#include <asm/branch.h>
@@ -185,6 +186,11 @@ void show_stack(struct task_struct *task, unsigned long *sp)
185186
regs.regs[29] = task->thread.reg29;
186187
regs.regs[31] = 0;
187188
regs.cp0_epc = task->thread.reg31;
189+
#ifdef CONFIG_KGDB_KDB
190+
} else if (atomic_read(&kgdb_active) != -1 &&
191+
kdb_current_regs) {
192+
memcpy(&regs, kdb_current_regs, sizeof(regs));
193+
#endif /* CONFIG_KGDB_KDB */
188194
} else {
189195
prepare_frametrace(&regs);
190196
}
@@ -360,6 +366,8 @@ void __noreturn die(const char * str, struct pt_regs * regs)
360366
unsigned long dvpret = dvpe();
361367
#endif /* CONFIG_MIPS_MT_SMTC */
362368

369+
notify_die(DIE_OOPS, str, (struct pt_regs *)regs, SIGSEGV, 0, 0);
370+
363371
console_verbose();
364372
spin_lock_irq(&die_lock);
365373
bust_spinlocks(1);
@@ -704,6 +712,11 @@ static void do_trap_or_bp(struct pt_regs *regs, unsigned int code,
704712
siginfo_t info;
705713
char b[40];
706714

715+
#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
716+
if (kgdb_ll_trap(DIE_TRAP, str, regs, code, 0, 0) == NOTIFY_STOP)
717+
return;
718+
#endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */
719+
707720
if (notify_die(DIE_TRAP, str, regs, code, 0, 0) == NOTIFY_STOP)
708721
return;
709722

lib/Kconfig.kgdb

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ config KGDB_TESTS_BOOT_STRING
5959

6060
config KGDB_LOW_LEVEL_TRAP
6161
bool "KGDB: Allow debugging with traps in notifiers"
62-
depends on X86
62+
depends on X86 || MIPS
6363
default n
6464
help
6565
This will add an extra call back to kgdb for the breakpoint

0 commit comments

Comments
 (0)