Skip to content

Commit dd8e2d9

Browse files
committed
x86/entry: Move irq tracing on syscall entry to C-code
Now that the C entry points are safe, move the irq flags tracing code into the entry helper: - Invoke lockdep before calling into context tracking - Use the safe trace_hardirqs_on_prepare() trace function after context tracking established state and RCU is watching. enter_from_user_mode() is also still invoked from the exception/interrupt entry code which still contains the ASM irq flags tracing. So this is just a redundant and harmless invocation of tracing / lockdep until these are removed as well. Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Alexandre Chartre <[email protected]> Acked-by: Peter Zijlstra <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 8f159f1 commit dd8e2d9

File tree

4 files changed

+19
-34
lines changed

4 files changed

+19
-34
lines changed

arch/x86/entry/common.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,36 @@
4040
#include <trace/events/syscalls.h>
4141

4242
#ifdef CONFIG_CONTEXT_TRACKING
43-
/* Called on entry from user mode with IRQs off. */
43+
/**
44+
* enter_from_user_mode - Establish state when coming from user mode
45+
*
46+
* Syscall entry disables interrupts, but user mode is traced as interrupts
47+
* enabled. Also with NO_HZ_FULL RCU might be idle.
48+
*
49+
* 1) Tell lockdep that interrupts are disabled
50+
* 2) Invoke context tracking if enabled to reactivate RCU
51+
* 3) Trace interrupts off state
52+
*/
4453
__visible noinstr void enter_from_user_mode(void)
4554
{
4655
enum ctx_state state = ct_state();
4756

57+
lockdep_hardirqs_off(CALLER_ADDR0);
4858
user_exit_irqoff();
4959

5060
instrumentation_begin();
5161
CT_WARN_ON(state != CONTEXT_USER);
62+
trace_hardirqs_off_prepare();
5263
instrumentation_end();
5364
}
5465
#else
55-
static inline void enter_from_user_mode(void) {}
66+
static __always_inline void enter_from_user_mode(void)
67+
{
68+
lockdep_hardirqs_off(CALLER_ADDR0);
69+
instrumentation_begin();
70+
trace_hardirqs_off_prepare();
71+
instrumentation_end();
72+
}
5673
#endif
5774

5875
static noinstr void exit_to_user_mode(void)

arch/x86/entry/entry_32.S

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -967,12 +967,6 @@ SYM_FUNC_START(entry_SYSENTER_32)
967967
jnz .Lsysenter_fix_flags
968968
.Lsysenter_flags_fixed:
969969

970-
/*
971-
* User mode is traced as though IRQs are on, and SYSENTER
972-
* turned them off.
973-
*/
974-
TRACE_IRQS_OFF
975-
976970
movl %esp, %eax
977971
call do_fast_syscall_32
978972
/* XEN PV guests always use IRET path */
@@ -1082,12 +1076,6 @@ SYM_FUNC_START(entry_INT80_32)
10821076

10831077
SAVE_ALL pt_regs_ax=$-ENOSYS switch_stacks=1 /* save rest */
10841078

1085-
/*
1086-
* User mode is traced as though IRQs are on, and the interrupt gate
1087-
* turned them off.
1088-
*/
1089-
TRACE_IRQS_OFF
1090-
10911079
movl %esp, %eax
10921080
call do_int80_syscall_32
10931081
.Lsyscall_32_done:

arch/x86/entry/entry_64.S

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,6 @@ SYM_INNER_LABEL(entry_SYSCALL_64_after_hwframe, SYM_L_GLOBAL)
167167

168168
PUSH_AND_CLEAR_REGS rax=$-ENOSYS
169169

170-
TRACE_IRQS_OFF
171-
172170
/* IRQs are off. */
173171
movq %rax, %rdi
174172
movq %rsp, %rsi

arch/x86/entry/entry_64_compat.S

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,6 @@ SYM_FUNC_START(entry_SYSENTER_compat)
129129
jnz .Lsysenter_fix_flags
130130
.Lsysenter_flags_fixed:
131131

132-
/*
133-
* User mode is traced as though IRQs are on, and SYSENTER
134-
* turned them off.
135-
*/
136-
TRACE_IRQS_OFF
137-
138132
movq %rsp, %rdi
139133
call do_fast_syscall_32
140134
/* XEN PV guests always use IRET path */
@@ -247,12 +241,6 @@ SYM_INNER_LABEL(entry_SYSCALL_compat_after_hwframe, SYM_L_GLOBAL)
247241
pushq $0 /* pt_regs->r15 = 0 */
248242
xorl %r15d, %r15d /* nospec r15 */
249243

250-
/*
251-
* User mode is traced as though IRQs are on, and SYSENTER
252-
* turned them off.
253-
*/
254-
TRACE_IRQS_OFF
255-
256244
movq %rsp, %rdi
257245
call do_fast_syscall_32
258246
/* XEN PV guests always use IRET path */
@@ -403,12 +391,6 @@ SYM_CODE_START(entry_INT80_compat)
403391
xorl %r15d, %r15d /* nospec r15 */
404392
cld
405393

406-
/*
407-
* User mode is traced as though IRQs are on, and the interrupt
408-
* gate turned them off.
409-
*/
410-
TRACE_IRQS_OFF
411-
412394
movq %rsp, %rdi
413395
call do_int80_syscall_32
414396
.Lsyscall_32_done:

0 commit comments

Comments
 (0)