Skip to content

Commit 4182e94

Browse files
Peter ZijlstraKAGA-KOKO
authored andcommitted
x86/debug: Simplify #DB signal code
There's no point in calculating si_code if it's not going to be used. 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/20200902133200.967434217@infradead.org
1 parent 7043679 commit 4182e94

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

arch/x86/kernel/traps.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -786,15 +786,14 @@ static __always_inline unsigned long debug_read_clear_dr6(void)
786786
static void handle_debug(struct pt_regs *regs, unsigned long dr6)
787787
{
788788
struct task_struct *tsk = current;
789-
bool user_icebp;
790-
int si_code;
789+
bool icebp;
791790

792791
/*
793792
* If dr6 has no reason to give us about the origin of this trap,
794793
* then it's very likely the result of an icebp/int01 trap.
795794
* User wants a sigtrap for that.
796795
*/
797-
user_icebp = !dr6;
796+
icebp = !dr6;
798797

799798
/* Store the virtualized DR6 value */
800799
tsk->thread.debugreg6 = dr6;
@@ -813,6 +812,11 @@ static void handle_debug(struct pt_regs *regs, unsigned long dr6)
813812
goto out;
814813
}
815814

815+
/*
816+
* Reload dr6, the notifier might have changed it.
817+
*/
818+
dr6 = tsk->thread.debugreg6;
819+
816820
if (WARN_ON_ONCE((dr6 & DR_STEP) && !user_mode(regs))) {
817821
/*
818822
* Historical junk that used to handle SYSENTER single-stepping.
@@ -825,9 +829,8 @@ static void handle_debug(struct pt_regs *regs, unsigned long dr6)
825829
regs->flags &= ~X86_EFLAGS_TF;
826830
}
827831

828-
si_code = get_si_code(tsk->thread.debugreg6);
829-
if (tsk->thread.debugreg6 & (DR_STEP | DR_TRAP_BITS) || user_icebp)
830-
send_sigtrap(regs, 0, si_code);
832+
if (dr6 & (DR_STEP | DR_TRAP_BITS) || icebp)
833+
send_sigtrap(regs, 0, get_si_code(dr6));
831834

832835
out:
833836
cond_local_irq_disable(regs);

0 commit comments

Comments
 (0)