entry: Fix the incorrect ordering of lockdep and RCU check
Subsystems (2)
When an exception/interrupt hits kernel space and the kernel is not currently in the idle task then RCU must be watching.
irqentry_enter() validates this via rcu_irq_enter_check_tick(), which in turn invokes lockdep when taking a lock. But at that point lockdep does not yet know about the fact that interrupts have been disabled by the CPU, which triggers a lockdep splat complaining about inconsistent state.
Invoking trace_hardirqs_off() before rcu_irq_enter_check_tick() defeats the point of rcu_irq_enter_check_tick() because trace_hardirqs_off() uses RCU.
So use the same sequence as for the idle case and tell lockdep about the irq state change first, invoke the RCU check and then do the lockdep and tracer update.
--- kernel/entry/common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/entry/common.c +2 -2
@@ -337,10 +337,10 @@ noinstr irqentry_state_t irqentry_enter(* already contains a warning when RCU is not watching, so no point * in having another one here. */ +lockdep_hardirqs_off (CALLER_ADDR0 );instrumentation_begin ();rcu_irq_enter_check_tick (); -/* Use the combo lockdep/tracing function */ -trace_hardirqs_off (); +trace_hardirqs_off_finish ();instrumentation_end ();return ret;
Mark Rutland
Tested-byQuoted 11 lines · Thomas Gleixner
When an exception/interrupt hits kernel space and the kernel is not currently in the idle task then RCU must be watching.
irqentry_enter()validates this viarcu_irq_enter_check_tick(), which in turn invokes lockdep when taking a lock. But at that point lockdep does not yet know about the fact that interrupts have been disabled by the CPU, which triggers a lockdep splat complaining about inconsistent state.Invoking
trace_hardirqs_off()beforercu_irq_enter_check_tick()defeats the point ofrcu_irq_enter_check_tick()becausetrace_hardirqs_off()uses RCU.
Quoted 8 lines
So use the same sequence as for the idle case and tell lockdep about the irq state change first, invoke the RCU check and then do the lockdep and tracer update.
Fixes a5497bab5f72 ("entry: Provide generic interrupt entry/exit code")Reported-by Mark Rutland <[email protected]>Signed-off-by Thomas Gleixner <[email protected]>
I just gave this a spin on x86_64 defconfig + PROVE_LOCKING + DEBUG_LOCKDEP + NO_HZ_FULL + CONTEXT_TRACKING_FORCE, and it gets rid of the boot-time splat. So FWIW:
Mark.
Quoted 19 lines
--- kernel/entry/common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kernel/entry/common.c +2
-2@@ -337,10 +337,10 @@ noinstr irqentry_state_t irqentry_enter(* already contains a warning when RCU is not watching, so no point * in having another one here. */ +lockdep_hardirqs_off (CALLER_ADDR0 );instrumentation_begin ();rcu_irq_enter_check_tick (); -/* Use the combo lockdep/tracing function */ -trace_hardirqs_off (); +trace_hardirqs_off_finish ();instrumentation_end ();return ret;
The following commit has been merged into the core/urgent branch of tip:
The following commit has been merged into the core/urgent branch of tip:
Commit-ID: 9d820f68b2bdba5b2e7bf135123c3f57c5051d05 Gitweb: https://git.kernel.org/tip/9d820f68b2bdba5b2e7bf135123c3f57c5051d05 Author: Thomas Gleixner <[email protected]> AuthorDate: Wed, 04 Nov 2020 14:06:23 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Wed, 04 Nov 2020 18:06:14 +01:00
entry: Fix the incorrect ordering of lockdep and RCU check
When an exception/interrupt hits kernel space and the kernel is not currently in the idle task then RCU must be watching.
irqentry_enter() validates this via rcu_irq_enter_check_tick(), which in turn invokes lockdep when taking a lock. But at that point lockdep does not yet know about the fact that interrupts have been disabled by the CPU, which triggers a lockdep splat complaining about inconsistent state.
Invoking trace_hardirqs_off() before rcu_irq_enter_check_tick() defeats the point of rcu_irq_enter_check_tick() because trace_hardirqs_off() uses RCU.
So use the same sequence as for the idle case and tell lockdep about the irq state change first, invoke the RCU check and then do the lockdep and tracer update.
--- kernel/entry/common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/entry/common.c +2 -2
@@ -337,10 +337,10 @@ noinstr irqentry_state_t irqentry_enter(struct pt_regs *regs)* already contains a warning when RCU is not watching, so no point * in having another one here. */ +lockdep_hardirqs_off (CALLER_ADDR0 );instrumentation_begin ();rcu_irq_enter_check_tick (); -/* Use the combo lockdep/tracing function */ -trace_hardirqs_off (); +trace_hardirqs_off_finish ();instrumentation_end ();return ret;