Skip to content

Commit ba797b2

Browse files
committed
powerpc,kgdb: Introduce low level trap catching
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 allow the kernel debugger to handle the exception first in program_check_exception(). The other change here is to make sure that kgdb_handle_exception() is called with correct parameters when catching an oops, because kdb needs to know if the entry was an oops, single step, or breakpoint exception. [[email protected]: move debugger_bpt instead of #ifdef] CC: Paul Mackerras <[email protected]> Signed-off-by: Jason Wessel <[email protected]> Acked-by: Benjamin Herrenschmidt <[email protected]>
1 parent f503b5a commit ba797b2

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

arch/powerpc/kernel/kgdb.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/smp.h>
2121
#include <linux/signal.h>
2222
#include <linux/ptrace.h>
23+
#include <linux/kdebug.h>
2324
#include <asm/current.h>
2425
#include <asm/processor.h>
2526
#include <asm/machdep.h>
@@ -115,15 +116,16 @@ void kgdb_roundup_cpus(unsigned long flags)
115116
/* KGDB functions to use existing PowerPC64 hooks. */
116117
static int kgdb_debugger(struct pt_regs *regs)
117118
{
118-
return kgdb_handle_exception(0, computeSignal(TRAP(regs)), 0, regs);
119+
return !kgdb_handle_exception(1, computeSignal(TRAP(regs)),
120+
DIE_OOPS, regs);
119121
}
120122

121123
static int kgdb_handle_breakpoint(struct pt_regs *regs)
122124
{
123125
if (user_mode(regs))
124126
return 0;
125127

126-
if (kgdb_handle_exception(0, SIGTRAP, 0, regs) != 0)
128+
if (kgdb_handle_exception(1, SIGTRAP, 0, regs) != 0)
127129
return 0;
128130

129131
if (*(u32 *) (regs->nip) == *(u32 *) (&arch_kgdb_ops.gdb_bpt_instr))

arch/powerpc/kernel/traps.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,12 +815,15 @@ void __kprobes program_check_exception(struct pt_regs *regs)
815815
return;
816816
}
817817
if (reason & REASON_TRAP) {
818+
/* Debugger is first in line to stop recursive faults in
819+
* rcu_lock, notify_die, or atomic_notifier_call_chain */
820+
if (debugger_bpt(regs))
821+
return;
822+
818823
/* trap exception */
819824
if (notify_die(DIE_BPT, "breakpoint", regs, 5, 5, SIGTRAP)
820825
== NOTIFY_STOP)
821826
return;
822-
if (debugger_bpt(regs))
823-
return;
824827

825828
if (!(regs->msr & MSR_PR) && /* not user-mode */
826829
report_bug(regs->nip, regs) == BUG_TRAP_TYPE_WARN) {

0 commit comments

Comments
 (0)