Skip to content

Commit 20a6e35

Browse files
Peter ZijlstraKAGA-KOKO
authored andcommitted
x86/debug: Move kprobe_debug_handler() into exc_debug_kernel()
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
1 parent c182487 commit 20a6e35

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

arch/x86/include/asm/kprobes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,9 @@ extern int kprobe_exceptions_notify(struct notifier_block *self,
106106
extern int kprobe_int3_handler(struct pt_regs *regs);
107107
extern int kprobe_debug_handler(struct pt_regs *regs);
108108

109+
#else
110+
111+
static inline int kprobe_debug_handler(struct pt_regs *regs) { return 0; }
112+
109113
#endif /* CONFIG_KPROBES */
110114
#endif /* _ASM_X86_KPROBES_H */

arch/x86/kernel/traps.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -806,12 +806,6 @@ static void handle_debug(struct pt_regs *regs, unsigned long dr6, bool user)
806806
/* Store the virtualized DR6 value */
807807
tsk->thread.debugreg6 = dr6;
808808

809-
#ifdef CONFIG_KPROBES
810-
if (kprobe_debug_handler(regs)) {
811-
return;
812-
}
813-
#endif
814-
815809
if (notify_die(DIE_DEBUG, "debug", regs, (long)&dr6, 0,
816810
SIGTRAP) == NOTIFY_STOP) {
817811
return;
@@ -877,8 +871,12 @@ static __always_inline void exc_debug_kernel(struct pt_regs *regs,
877871
if ((dr6 & DR_STEP) && is_sysenter_singlestep(regs))
878872
dr6 &= ~DR_STEP;
879873

874+
if (kprobe_debug_handler(regs))
875+
goto out;
876+
880877
handle_debug(regs, dr6, false);
881878

879+
out:
882880
instrumentation_end();
883881
idtentry_exit_nmi(regs, irq_state);
884882

0 commit comments

Comments
 (0)