Skip to content

Commit 4eb5acc

Browse files
Peter ZijlstraKAGA-KOKO
authored andcommitted
x86/debug: Move historical SYSENTER junk into exc_debug_kernel()
The historical SYSENTER junk is explicitly for from-kernel, so move it to the #DB-from-kernel handler. It is ordered after the notifier, which is important for KGDB which uses TF single-step and needs to consume the event before that point. 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> Link: https://lore.kernel.org/r/20200902133201.031099736@infradead.org
1 parent 4182e94 commit 4eb5acc

1 file changed

Lines changed: 25 additions & 24 deletions

File tree

arch/x86/kernel/traps.c

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ static __always_inline unsigned long debug_read_clear_dr6(void)
783783
*
784784
* May run on IST stack.
785785
*/
786-
static void handle_debug(struct pt_regs *regs, unsigned long dr6)
786+
static bool handle_debug(struct pt_regs *regs, unsigned long *dr6)
787787
{
788788
struct task_struct *tsk = current;
789789
bool icebp;
@@ -793,15 +793,13 @@ static void handle_debug(struct pt_regs *regs, unsigned long dr6)
793793
* then it's very likely the result of an icebp/int01 trap.
794794
* User wants a sigtrap for that.
795795
*/
796-
icebp = !dr6;
796+
icebp = !*dr6;
797797

798798
/* Store the virtualized DR6 value */
799-
tsk->thread.debugreg6 = dr6;
799+
tsk->thread.debugreg6 = *dr6;
800800

801-
if (notify_die(DIE_DEBUG, "debug", regs, (long)&dr6, 0,
802-
SIGTRAP) == NOTIFY_STOP) {
803-
return;
804-
}
801+
if (notify_die(DIE_DEBUG, "debug", regs, (long)dr6, 0, SIGTRAP) == NOTIFY_STOP)
802+
return true;
805803

806804
/* It's safe to allow irq's after DR6 has been saved */
807805
cond_local_irq_enable(regs);
@@ -815,25 +813,15 @@ static void handle_debug(struct pt_regs *regs, unsigned long dr6)
815813
/*
816814
* Reload dr6, the notifier might have changed it.
817815
*/
818-
dr6 = tsk->thread.debugreg6;
816+
*dr6 = tsk->thread.debugreg6;
819817

820-
if (WARN_ON_ONCE((dr6 & DR_STEP) && !user_mode(regs))) {
821-
/*
822-
* Historical junk that used to handle SYSENTER single-stepping.
823-
* This should be unreachable now. If we survive for a while
824-
* without anyone hitting this warning, we'll turn this into
825-
* an oops.
826-
*/
827-
tsk->thread.debugreg6 &= ~DR_STEP;
828-
set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
829-
regs->flags &= ~X86_EFLAGS_TF;
830-
}
831-
832-
if (dr6 & (DR_STEP | DR_TRAP_BITS) || icebp)
833-
send_sigtrap(regs, 0, get_si_code(dr6));
818+
if (*dr6 & (DR_STEP | DR_TRAP_BITS) || icebp)
819+
send_sigtrap(regs, 0, get_si_code(*dr6));
834820

835821
out:
836822
cond_local_irq_disable(regs);
823+
824+
return false;
837825
}
838826

839827
static __always_inline void exc_debug_kernel(struct pt_regs *regs,
@@ -876,7 +864,20 @@ static __always_inline void exc_debug_kernel(struct pt_regs *regs,
876864
if (!dr6)
877865
goto out;
878866

879-
handle_debug(regs, dr6);
867+
if (handle_debug(regs, &dr6))
868+
goto out;
869+
870+
if (WARN_ON_ONCE(dr6 & DR_STEP)) {
871+
/*
872+
* Historical junk that used to handle SYSENTER single-stepping.
873+
* This should be unreachable now. If we survive for a while
874+
* without anyone hitting this warning, we'll turn this into
875+
* an oops.
876+
*/
877+
dr6 &= ~DR_STEP;
878+
set_thread_flag(TIF_SINGLESTEP);
879+
regs->flags &= ~X86_EFLAGS_TF;
880+
}
880881

881882
out:
882883
instrumentation_end();
@@ -906,7 +907,7 @@ static __always_inline void exc_debug_user(struct pt_regs *regs,
906907
irqentry_enter_from_user_mode(regs);
907908
instrumentation_begin();
908909

909-
handle_debug(regs, dr6);
910+
handle_debug(regs, &dr6);
910911

911912
instrumentation_end();
912913
irqentry_exit_to_user_mode(regs);

0 commit comments

Comments
 (0)