The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: wen.yang@linux.dev
To: Gabriele Monaco <gmonaco@redhat.com>
Cc: Nam Cao <namcao@linutronix.de>,
	linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org,
	Wen Yang <wen.yang@linux.dev>
Subject: [PATCH v2 0/4] rv/reactors: fix lockdep warning and add KUnit tests
Date: Mon,  3 Aug 2026 02:43:01 +0800	[thread overview]
Message-ID: <cover.1785695669.git.wen.yang@linux.dev> (raw)

From: Wen Yang <wen.yang@linux.dev>

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	other threads:[~2026-08-02 18:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-02 18:43 wen.yang [this message]
2026-08-02 18:43 ` [PATCH v2 1/4] rv/reactors: use context-sensitive lockdep wait type in rv_react() wen.yang
2026-08-03 15:39   ` Gabriele Monaco
2026-08-02 18:43 ` [PATCH v2 2/4] rv/reactors: propagate rv_register_reactor() error from reactor init wen.yang
2026-08-03  6:35   ` Gabriele Monaco
2026-08-02 18:43 ` [PATCH v2 3/4] rv/reactors: export rv_register_reactor() and rv_unregister_reactor() wen.yang
2026-08-03  6:32   ` Gabriele Monaco
2026-08-02 18:43 ` [PATCH v2 4/4] rv/reactors: add KUnit tests for reactor registration and dispatch wen.yang
2026-08-03 12:49   ` Gabriele Monaco

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1785695669.git.wen.yang@linux.dev \
    --to=wen.yang@linux.dev \
    --cc=gmonaco@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=namcao@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox