From: Wen Yang <[email protected]>
We occasionally hit a lockdep "Invalid wait context" warning in
production when a reactor callback is preempted by a timer interrupt.
On interrupt exit the scheduler takes rq->__lock (LD_WAIT_SPIN) while
rv_react() still holds its wait-type-override map, which declared
LD_WAIT_FREE. On any kernel where the task context has preemption
enabled (not just CONFIG_PREEMPT_RT) this triggers a spurious lockdep
report:
[ BUG: Invalid wait context ]
1 lock held by kunit_try_catch/209:
#0: (rv_react_map-wait-type-override){+.+.}-{1:1}
kunit_try_catch/209 is trying to lock:
ffff8a743ed3e8a0 (&rq->__lock){-...}-{2:2}
Changes in v3:
Patch 1:
- Rewrite commit message to clarify that the bug is not
PREEMPT_RT-specific: any preemptible task context can be interrupted
by a timer, and the scheduler acquires rq->__lock (LD_WAIT_SPIN) on
interrupt exit while rv_react() still holds its LD_WAIT_FREE override
map.
- Rewrite the inline comment in rv_react() to make clear.
Patch 3:
- Fix commit message: missing EXPORT_SYMBOL_GPL() is caught by modpost
at link time, not at load time.
Patch 4:
- Drop test_reactor_registered bool and the unregister_test_reactor()
wrapper entirely.
- Remove test_register_unregister(); the teardown already covers the
unregister path, and test_double_register() exercises the full
register->verify->unregister-via-teardown flow.
- Replace the runtime KUNIT_ASSERT_EQ(strlen(...)) guard in
test_name_too_long() with a _Static_assert on the name array size.
- In test_react_no_callback(): reuse the existing react_call_count
atomic to assert that the callback was never invoked.
This catches a broader class of regressions — e.g.
an inverted or missing NULL guard that does not cause a NULL dereference.
No functional change to patches 2-3; the series structure is unchanged.
Tested with CONFIG_PROVE_LOCKING=y and CONFIG_KUNIT=y.
v2: https://lore.kernel.org/lkml/[email protected]/
v1: https://lore.kernel.org/lkml/[email protected]/
Wen Yang (4):
rv/reactors: use context-sensitive lockdep wait type in rv_react()
rv/reactors: propagate rv_register_reactor() error from reactor init
rv/reactors: export rv_register_reactor() and rv_unregister_reactor()
rv/reactors: add KUnit tests for reactor registration and dispatch
kernel/trace/rv/Kconfig | 12 +++
kernel/trace/rv/Makefile | 1 +
kernel/trace/rv/reactor_panic.c | 3 +-
kernel/trace/rv/reactor_printk.c | 3 +-
kernel/trace/rv/rv_reactors.c | 22 +++--
kernel/trace/rv/rv_reactors_kunit.c | 119 ++++++++++++++++++++++++++++
6 files changed, 151 insertions(+), 9 deletions(-)
create mode 100644 kernel/trace/rv/rv_reactors_kunit.c
base-commit: 785095112f4198de49760552374f364043c8dbdf
--
2.25.1