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 a preemptible kernel (e.g. 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 v2:
- Use a context-sensitive override map: LD_WAIT_SPIN in preemptible
  contexts, LD_WAIT_FREE in NMI/hardirq where the scheduler cannot run
  (patch 1).
- Merge the v1 printk/panic test files into one generic rv_reactors_kunit
  covering registration and dispatch, as the v1 tests were mostly not
  reactor-specific (patches 2-4).
- Export rv_register_reactor()/rv_unregister_reactor() so the tristate
  KUnit module can link against them (patch 3).
- Propagate rv_register_reactor() errors from the built-in reactor init
  functions instead of silently ignoring them (patch 2).
- KUnit tests are tristate (usable with CONFIG_KUNIT=m) and verify the
  callback is actually invoked (atomic counter), the exact -EINVAL on
  duplicate registration, and use mdelay(5) to exercise the lockdep
  context under load.  A teardown action unregisters the test reactor
  even if a test aborts.

Patch 1 fixes the lockdep warning.  Patches 2-3 make the registration
API usable by the test module and propagate its errors.  Patch 4 adds
the KUnit tests.

Tested with CONFIG_PROVE_LOCKING=y and CONFIG_KUNIT=y.



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       |  19 +++-
 kernel/trace/rv/rv_reactors_kunit.c | 143 ++++++++++++++++++++++++++++
 6 files changed, 172 insertions(+), 9 deletions(-)
 create mode 100644 kernel/trace/rv/rv_reactors_kunit.c

base-commit: 984b5a36fd12d1849511a45fda32036fe2b0d004
-- 
2.25.1


Reply via email to