[patch V4 part 5 30/31] x86/entry: Move paranoid irq tracing out of ASM code

Thomas Gleixner
2020-05-05T14:18:13Z

arch/x86/entry/entry_64.S | 13 -------------
arch/x86/kernel/nmi.c | 11 +++++++----
2 files changed, 7 insertions(+), 17 deletions(-)

--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -16,7 +16,6 @@
*
* Some macro usage:
* - SYM_FUNC_START/END:Define functions in the symbol table.
- * - TRACE_IRQ_*: Trace hardirq state for lock debugging.
* - idtentry: Define exception entry points.
*/
#include <linux/linkage.h>
@@ -107,11 +106,6 @@ SYM_CODE_END(native_usergs_sysret64)

SYM_CODE_START(entry_SYSCALL_64)
UNWIND_HINT_EMPTY
- /*
- * Interrupts are off on entry.
- * We do not frame this tiny irq-off block with TRACE_IRQS_OFF/ON,
- * it is too small to ever cause noticeable irq latency.
- */

swapgs
/* tss.sp2 is scratch space. */
@@ -463,8 +457,6 @@ SYM_CODE_START(\asmsym)

UNWIND_HINT_REGS

- TRACE_IRQS_OFF
-
movq %rsp, %rdi /* pt_regs pointer */

.if \vector == X86_TRAP_DB
@@ -842,17 +834,13 @@ SYM_CODE_END(paranoid_entry)
*/
SYM_CODE_START_LOCAL(paranoid_exit)
UNWIND_HINT_REGS
- DISABLE_INTERRUPTS(CLBR_ANY)
- TRACE_IRQS_OFF
testl %ebx, %ebx /* swapgs needed? */
jnz .Lparanoid_exit_no_swapgs
- TRACE_IRQS_IRETQ
/* Always restore stashed CR3 value (see paranoid_entry) */
RESTORE_CR3 scratch_reg=%rbx save_reg=%r14
SWAPGS_UNSAFE_STACK
jmp restore_regs_and_return_to_kernel
.Lparanoid_exit_no_swapgs:
- TRACE_IRQS_IRETQ
/* Always restore stashed CR3 value (see paranoid_entry) */
RESTORE_CR3 scratch_reg=%rbx save_reg=%r14
jmp restore_regs_and_return_to_kernel
@@ -1254,7 +1242,6 @@ SYM_CODE_START(asm_exc_nmi)
call paranoid_entry
UNWIND_HINT_REGS

- /* paranoidentry exc_nmi(), 0; without TRACE_IRQS_OFF */
movq %rsp, %rdi
movq $-1, %rsi
call exc_nmi
--- a/arch/x86/kernel/nmi.c
+++ b/arch/x86/kernel/nmi.c
@@ -334,6 +334,8 @@ static noinstr void default_do_nmi(struc
__this_cpu_write(last_nmi_rip, regs->ip);

instr_begin();
+ trace_hardirqs_off_prepare();
+
handled = nmi_handle(NMI_LOCAL, regs);
__this_cpu_add(nmi_stats.normal, handled);
if (handled) {
@@ -347,8 +349,7 @@ static noinstr void default_do_nmi(struc
*/
if (handled > 1)
__this_cpu_write(swallow_nmi, true);
- instr_end();
- return;
+ goto out;
}

/*
@@ -380,8 +381,7 @@ static noinstr void default_do_nmi(struc
#endif
__this_cpu_add(nmi_stats.external, 1);
raw_spin_unlock(&nmi_reason_lock);
- instr_end();
- return;
+ goto out;
}
raw_spin_unlock(&nmi_reason_lock);

@@ -419,6 +419,9 @@ static noinstr void default_do_nmi(struc
__this_cpu_add(nmi_stats.swallow, 1);
else
unknown_nmi_error(reason, regs);
+out:
+ if (regs->flags & X86_EFLAGS_IF)
+ trace_hardirqs_on_prepare();
instr_end();
}