Skip to content

Commit f0b67c3

Browse files
Peter ZijlstraKAGA-KOKO
authored andcommitted
x86/debug: Move cond_local_irq_enable() block into exc_debug_user()
The cond_local_irq_enable() block, dealing with vm86 and sending signals is only relevant for #DB-from-user, move it there. This then reduces handle_debug() to only the notifier call, so rename it to notify_debug(). 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.094265982@infradead.org
1 parent 4eb5acc commit f0b67c3

1 file changed

Lines changed: 29 additions & 29 deletions

File tree

arch/x86/kernel/traps.c

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -783,44 +783,20 @@ static __always_inline unsigned long debug_read_clear_dr6(void)
783783
*
784784
* May run on IST stack.
785785
*/
786-
static bool handle_debug(struct pt_regs *regs, unsigned long *dr6)
786+
787+
static bool notify_debug(struct pt_regs *regs, unsigned long *dr6)
787788
{
788789
struct task_struct *tsk = current;
789-
bool icebp;
790-
791-
/*
792-
* If dr6 has no reason to give us about the origin of this trap,
793-
* then it's very likely the result of an icebp/int01 trap.
794-
* User wants a sigtrap for that.
795-
*/
796-
icebp = !*dr6;
797790

798791
/* Store the virtualized DR6 value */
799792
tsk->thread.debugreg6 = *dr6;
800793

801794
if (notify_die(DIE_DEBUG, "debug", regs, (long)dr6, 0, SIGTRAP) == NOTIFY_STOP)
802795
return true;
803796

804-
/* It's safe to allow irq's after DR6 has been saved */
805-
cond_local_irq_enable(regs);
806-
807-
if (v8086_mode(regs)) {
808-
handle_vm86_trap((struct kernel_vm86_regs *) regs, 0,
809-
X86_TRAP_DB);
810-
goto out;
811-
}
812-
813-
/*
814-
* Reload dr6, the notifier might have changed it.
815-
*/
797+
/* Reload the DR6 value, the notifier might have changed it */
816798
*dr6 = tsk->thread.debugreg6;
817799

818-
if (*dr6 & (DR_STEP | DR_TRAP_BITS) || icebp)
819-
send_sigtrap(regs, 0, get_si_code(*dr6));
820-
821-
out:
822-
cond_local_irq_disable(regs);
823-
824800
return false;
825801
}
826802

@@ -864,7 +840,7 @@ static __always_inline void exc_debug_kernel(struct pt_regs *regs,
864840
if (!dr6)
865841
goto out;
866842

867-
if (handle_debug(regs, &dr6))
843+
if (notify_debug(regs, &dr6))
868844
goto out;
869845

870846
if (WARN_ON_ONCE(dr6 & DR_STEP)) {
@@ -889,6 +865,8 @@ static __always_inline void exc_debug_kernel(struct pt_regs *regs,
889865
static __always_inline void exc_debug_user(struct pt_regs *regs,
890866
unsigned long dr6)
891867
{
868+
bool icebp;
869+
892870
/*
893871
* If something gets miswired and we end up here for a kernel mode
894872
* #DB, we will malfunction.
@@ -907,8 +885,30 @@ static __always_inline void exc_debug_user(struct pt_regs *regs,
907885
irqentry_enter_from_user_mode(regs);
908886
instrumentation_begin();
909887

910-
handle_debug(regs, &dr6);
888+
/*
889+
* If dr6 has no reason to give us about the origin of this trap,
890+
* then it's very likely the result of an icebp/int01 trap.
891+
* User wants a sigtrap for that.
892+
*/
893+
icebp = !dr6;
894+
895+
if (notify_debug(regs, &dr6))
896+
goto out;
911897

898+
/* It's safe to allow irq's after DR6 has been saved */
899+
local_irq_enable();
900+
901+
if (v8086_mode(regs)) {
902+
handle_vm86_trap((struct kernel_vm86_regs *)regs, 0, X86_TRAP_DB);
903+
goto out_irq;
904+
}
905+
906+
if (dr6 & (DR_STEP | DR_TRAP_BITS) || icebp)
907+
send_sigtrap(regs, 0, get_si_code(dr6));
908+
909+
out_irq:
910+
local_irq_disable();
911+
out:
912912
instrumentation_end();
913913
irqentry_exit_to_user_mode(regs);
914914
}

0 commit comments

Comments
 (0)