Skip to content

Commit 5ef2279

Browse files
Peter ZijlstraKAGA-KOKO
authored andcommitted
x86/entry: Re-order #DB handler to avoid *SAN instrumentation
vmlinux.o: warning: objtool: exc_debug()+0xbb: call to clear_ti_thread_flag.constprop.0() leaves .noinstr.text section vmlinux.o: warning: objtool: noist_exc_debug()+0x55: call to clear_ti_thread_flag.constprop.0() leaves .noinstr.text section Rework things so that handle_debug() looses the noinstr and move the clear_thread_flag() into that. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 4b281e5 commit 5ef2279

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

arch/x86/kernel/traps.c

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -775,26 +775,44 @@ static __always_inline void debug_exit(unsigned long dr7)
775775
*
776776
* May run on IST stack.
777777
*/
778-
static void noinstr handle_debug(struct pt_regs *regs, unsigned long dr6,
779-
bool user_icebp)
778+
static void handle_debug(struct pt_regs *regs, unsigned long dr6, bool user)
780779
{
781780
struct task_struct *tsk = current;
781+
bool user_icebp;
782782
int si_code;
783783

784+
/*
785+
* The SDM says "The processor clears the BTF flag when it
786+
* generates a debug exception." Clear TIF_BLOCKSTEP to keep
787+
* TIF_BLOCKSTEP in sync with the hardware BTF flag.
788+
*/
789+
clear_thread_flag(TIF_BLOCKSTEP);
790+
791+
/*
792+
* If DR6 is zero, no point in trying to handle it. The kernel is
793+
* not using INT1.
794+
*/
795+
if (!user && !dr6)
796+
return;
797+
798+
/*
799+
* If dr6 has no reason to give us about the origin of this trap,
800+
* then it's very likely the result of an icebp/int01 trap.
801+
* User wants a sigtrap for that.
802+
*/
803+
user_icebp = user && !dr6;
804+
784805
/* Store the virtualized DR6 value */
785806
tsk->thread.debugreg6 = dr6;
786807

787-
instrumentation_begin();
788808
#ifdef CONFIG_KPROBES
789809
if (kprobe_debug_handler(regs)) {
790-
instrumentation_end();
791810
return;
792811
}
793812
#endif
794813

795814
if (notify_die(DIE_DEBUG, "debug", regs, (long)&dr6, 0,
796815
SIGTRAP) == NOTIFY_STOP) {
797-
instrumentation_end();
798816
return;
799817
}
800818

@@ -825,7 +843,6 @@ static void noinstr handle_debug(struct pt_regs *regs, unsigned long dr6,
825843

826844
out:
827845
cond_local_irq_disable(regs);
828-
instrumentation_end();
829846
}
830847

831848
static __always_inline void exc_debug_kernel(struct pt_regs *regs,
@@ -834,14 +851,6 @@ static __always_inline void exc_debug_kernel(struct pt_regs *regs,
834851
nmi_enter();
835852
instrumentation_begin();
836853
trace_hardirqs_off_finish();
837-
instrumentation_end();
838-
839-
/*
840-
* The SDM says "The processor clears the BTF flag when it
841-
* generates a debug exception." Clear TIF_BLOCKSTEP to keep
842-
* TIF_BLOCKSTEP in sync with the hardware BTF flag.
843-
*/
844-
clear_thread_flag(TIF_BLOCKSTEP);
845854

846855
/*
847856
* Catch SYSENTER with TF set and clear DR_STEP. If this hit a
@@ -850,14 +859,8 @@ static __always_inline void exc_debug_kernel(struct pt_regs *regs,
850859
if ((dr6 & DR_STEP) && is_sysenter_singlestep(regs))
851860
dr6 &= ~DR_STEP;
852861

853-
/*
854-
* If DR6 is zero, no point in trying to handle it. The kernel is
855-
* not using INT1.
856-
*/
857-
if (dr6)
858-
handle_debug(regs, dr6, false);
862+
handle_debug(regs, dr6, false);
859863

860-
instrumentation_begin();
861864
if (regs->flags & X86_EFLAGS_IF)
862865
trace_hardirqs_on_prepare();
863866
instrumentation_end();
@@ -868,14 +871,10 @@ static __always_inline void exc_debug_user(struct pt_regs *regs,
868871
unsigned long dr6)
869872
{
870873
idtentry_enter_user(regs);
871-
clear_thread_flag(TIF_BLOCKSTEP);
874+
instrumentation_begin();
872875

873-
/*
874-
* If dr6 has no reason to give us about the origin of this trap,
875-
* then it's very likely the result of an icebp/int01 trap.
876-
* User wants a sigtrap for that.
877-
*/
878-
handle_debug(regs, dr6, !dr6);
876+
handle_debug(regs, dr6, true);
877+
instrumentation_end();
879878
idtentry_exit_user(regs);
880879
}
881880

0 commit comments

Comments
 (0)