lockdep: Fix TRACE_IRQFLAGS vs NMIs
Subsystems (5)
[email protected]
maintainerPATCH 1/1 lockdep: Fix TRACE_IRQFLAGS vs NMIs
Prior to commit 859d069ee1dd ("lockdep: Prepare for NMI IRQ state tracking") IRQ state tracking was disabled in NMIs due to nmi_enter() doing lockdep_off() -- with the obvious requirement that NMI entry call nmi_enter() before trace_hardirqs_off().
[ afaict, PowerPC and SH violate this order on their NMI entry ]
However, that commit explicitly changed lockdep_hardirqs_*() to ignore lockdep_off() and breaks every architecture that has irq-tracing in it's NMI entry that hasn't been fixed up (x86 being the only fixed one at this point).
The reason for this change is that by ignoring lockdep_off() we can:
- get rid of 'current->lockdep_recursion' in lockdep_assert_irqs*() which was going to to give header-recursion issues with the seqlock rework.
- allow these lockdep_assert_*() macros to function in NMI context.
Restore the previous state of things and allow an architecture to opt-in to the NMI IRQ tracking support, however instead of relying on lockdep_off(), rely on in_nmi(), both are part of nmi_enter() and so over-all entry ordering doesn't need to change.
--- arch/x86/Kconfig.debug | 3 +++ kernel/locking/lockdep.c | 8 +++++++- lib/Kconfig.debug | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-)
arch/x86/Kconfig.debug +3 -0
@@ -3,6 +3,9 @@ config TRACE_IRQFLAGS_SUPPORT def_bool y +config TRACE_IRQFLAGS_NMI_SUPPORT + def_bool y + config EARLY_PRINTK_USB bool
kernel/locking/lockdep.c +7 -1
@@ -3712,6 +3712,9 @@ void noinstr lockdep_hardirqs_on(unsigne* and not rely on hardware state like normal interrupts. */ if (unlikely (in_nmi ())) { +if (!IS_ENABLED (CONFIG_TRACE_IRQFLAGS_NMI )) +return ; +/* * Skip: * - recursion check, because NMI can hit lockdep;
@@ -3773,7 +3776,10 @@ void noinstr lockdep_hardirqs_off(unsign* they will restore the software state. This ensures the software * state is consistent inside NMIs as well. */ -if (unlikely (!in_nmi () && (current->lockdep_recursion &LOCKDEP_RECURSION_MASK ))) +if (in_nmi ()) { +if (!IS_ENABLED (CONFIG_TRACE_IRQFLAGS_NMI )) +return ; + }else if (current->lockdep_recursion &LOCKDEP_RECURSION_MASK )return ;/*
lib/Kconfig.debug +6 -0
@@ -1325,11 +1325,17 @@ config WW_MUTEX_SELFTEST endmenu # lock debugging config TRACE_IRQFLAGS + depends on TRACE_IRQFLAGS_SUPPORT bool help Enables hooks to interrupt enabling and disabling for either tracing or lock debugging. +config TRACE_IRQFLAGS_NMI + def_bool y + depends on TRACE_IRQFLAGS + depends on TRACE_IRQFLAGS_NMI_SUPPORT + config STACKTRACE bool "Stack backtrace support" depends on STACKTRACE_SUPPORT
Quoted 26 lines · * [email protected] <[email protected]> wrote:
Prior to commit
859d069ee1dd("lockdep: Prepare for NMI IRQ state tracking") IRQ state tracking was disabled in NMIs due tonmi_enter()doinglockdep_off()-- with the obvious requirement that NMI entry callnmi_enter()beforetrace_hardirqs_off().[ afaict, PowerPC and SH violate this order on their NMI entry ]
However, that commit explicitly changed lockdep_hardirqs_*() to ignore
lockdep_off()and breaks every architecture that has irq-tracing in it's NMI entry that hasn't been fixed up (x86 being the only fixed one at this point).The reason for this change is that by ignoring
lockdep_off()we can:- get rid of '
current->lockdep_recursion' in lockdep_assert_irqs*() which was going to to give header-recursion issues with the seqlock rework.- allow these lockdep_assert_*() macros to function in NMI context.
Restore the previous state of things and allow an architecture to opt-in to the NMI IRQ tracking support, however instead of relying on
lockdep_off(), rely onin_nmi(), both are part ofnmi_enter()and so over-all entry ordering doesn't need to change.
Quoted 6 lines
Signed-off-by Peter Zijlstra (Intel) <[email protected]>--- arch/x86/Kconfig.debug | 3 +++ kernel/locking/lockdep.c | 8 +++++++- lib/Kconfig.debug | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-)
Tree management side note: to apply this I've created a new tip:locking/nmi branch, which is based off the existing NMI vs. IRQ tracing commits included in locking/core:
ed00495333cc: ("locking/lockdep: Fix TRACE_IRQFLAGS vs. NMIs")ba1f2b2eaa2a: ("x86/entry: Fix NMI vs IRQ state tracking")859d069ee1dd: ("lockdep: Prepare for NMI IRQ state tracking")248591f5d257: ("kcsan: Make KCSAN compatible with new IRQ state tracking")e1bcad609f5a: ("Merge branch 'tip/x86/entry'")b037b09b9058: ("x86/entry: Rename idtentry_enter/exit_cond_rcu() to idtentry_enter/exit()")dcb7fd82c75e: ("Linux 5.8-rc4")
This locking/nmi branch can then be merged into irq/entry (there's a bunch of conflicts between them), without coupling all of v5.9's locking changes to Thomas's generic entry work.
Thanks,
Ingo
[tip: locking/nmi] locking/lockdep: Fix TRACE_IRQFLAGS vs. NMIs
In reply to [email protected]The following commit has been merged into the locking/nmi branch of tip:
The following commit has been merged into the locking/nmi branch of tip:
Commit-ID: ed00495333ccc80fc8fb86fb43773c3c2a499466 Gitweb: https://git.kernel.org/tip/ed00495333ccc80fc8fb86fb43773c3c2a499466 Author: [email protected] <[email protected]> AuthorDate: Mon, 27 Jul 2020 14:48:52 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Mon, 27 Jul 2020 15:13:29 +02:00
locking/lockdep: Fix TRACE_IRQFLAGS vs. NMIs
Prior to commit:
859d069ee1dd ("lockdep: Prepare for NMI IRQ state tracking")
IRQ state tracking was disabled in NMIs due to nmi_enter() doing lockdep_off() -- with the obvious requirement that NMI entry call nmi_enter() before trace_hardirqs_off().
[ AFAICT, PowerPC and SH violate this order on their NMI entry ]
However, that commit explicitly changed lockdep_hardirqs_*() to ignore lockdep_off() and breaks every architecture that has irq-tracing in it's NMI entry that hasn't been fixed up (x86 being the only fixed one at this point).
The reason for this change is that by ignoring lockdep_off() we can:
- get rid of 'current->lockdep_recursion' in lockdep_assert_irqs*() which was going to to give header-recursion issues with the seqlock rework.
- allow these lockdep_assert_*() macros to function in NMI context.
Restore the previous state of things and allow an architecture to opt-in to the NMI IRQ tracking support, however instead of relying on lockdep_off(), rely on in_nmi(), both are part of nmi_enter() and so over-all entry ordering doesn't need to change.
--- arch/x86/Kconfig.debug | 3 +++ kernel/locking/lockdep.c | 8 +++++++- lib/Kconfig.debug | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-)
arch/x86/Kconfig.debug +3 -0
@@ -3,6 +3,9 @@ config TRACE_IRQFLAGS_SUPPORT def_bool y +config TRACE_IRQFLAGS_NMI_SUPPORT + def_bool y + config EARLY_PRINTK_USB bool
kernel/locking/lockdep.c +7 -1
@@ -3712,6 +3712,9 @@ void noinstr lockdep_hardirqs_on(unsigned long ip)* and not rely on hardware state like normal interrupts. */ if (unlikely (in_nmi ())) { +if (!IS_ENABLED (CONFIG_TRACE_IRQFLAGS_NMI )) +return ; +/* * Skip: * - recursion check, because NMI can hit lockdep;
@@ -3773,7 +3776,10 @@ void noinstr lockdep_hardirqs_off(unsigned long ip)* they will restore the software state. This ensures the software * state is consistent inside NMIs as well. */ -if (unlikely (!in_nmi () && (current->lockdep_recursion &LOCKDEP_RECURSION_MASK ))) +if (in_nmi ()) { +if (!IS_ENABLED (CONFIG_TRACE_IRQFLAGS_NMI )) +return ; + }else if (current->lockdep_recursion &LOCKDEP_RECURSION_MASK )return ;/*
lib/Kconfig.debug +6 -0
@@ -1325,11 +1325,17 @@ config WW_MUTEX_SELFTEST endmenu # lock debugging config TRACE_IRQFLAGS + depends on TRACE_IRQFLAGS_SUPPORT bool help Enables hooks to interrupt enabling and disabling for either tracing or lock debugging. +config TRACE_IRQFLAGS_NMI + def_bool y + depends on TRACE_IRQFLAGS + depends on TRACE_IRQFLAGS_NMI_SUPPORT + config STACKTRACE bool "Stack backtrace support" depends on STACKTRACE_SUPPORT