Skip to content

Commit

Permalink
x86/debug: Move kprobe_debug_handler() into exc_debug_kernel()
Browse files Browse the repository at this point in the history
Kprobes are on kernel text, and thus only matter for #DB-from-kernel.
Kprobes are ordered before the generic notifier, preserve that order.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Daniel Thompson <daniel.thompson@linaro.org>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Acked-by: Andy Lutomirski <luto@kernel.org>
Link: https://lore.kernel.org/r/20200902133200.847465360@infradead.org
  • Loading branch information
Peter Zijlstra authored and Thomas Gleixner committed Sep 4, 2020
1 parent c182487 commit 20a6e35
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 4 additions & 0 deletions arch/x86/include/asm/kprobes.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,9 @@ extern int kprobe_exceptions_notify(struct notifier_block *self,
extern int kprobe_int3_handler(struct pt_regs *regs);
extern int kprobe_debug_handler(struct pt_regs *regs);

#else

static inline int kprobe_debug_handler(struct pt_regs *regs) { return 0; }

#endif /* CONFIG_KPROBES */
#endif /* _ASM_X86_KPROBES_H */
10 changes: 4 additions & 6 deletions arch/x86/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -806,12 +806,6 @@ static void handle_debug(struct pt_regs *regs, unsigned long dr6, bool user)
/* Store the virtualized DR6 value */
tsk->thread.debugreg6 = dr6;

#ifdef CONFIG_KPROBES
if (kprobe_debug_handler(regs)) {
return;
}
#endif

if (notify_die(DIE_DEBUG, "debug", regs, (long)&dr6, 0,
SIGTRAP) == NOTIFY_STOP) {
return;
Expand Down Expand Up @@ -877,8 +871,12 @@ static __always_inline void exc_debug_kernel(struct pt_regs *regs,
if ((dr6 & DR_STEP) && is_sysenter_singlestep(regs))
dr6 &= ~DR_STEP;

if (kprobe_debug_handler(regs))
goto out;

handle_debug(regs, dr6, false);

out:
instrumentation_end();
idtentry_exit_nmi(regs, irq_state);

Expand Down

0 comments on commit 20a6e35

Please sign in to comment.