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>,
"Thomas Weißschuh" <thomas.weissschuh@linutronix.de>
Subject: [PATCH v3 1/4] rv/reactors: use context-sensitive lockdep wait type in rv_react()
Date: Mon, 10 Aug 2026 01:10:38 +0800 [thread overview]
Message-ID: <26526e555baa5118325b2383e9f7f0f8f9b6a199.1786294920.git.wen.yang@linux.dev> (raw)
In-Reply-To: <cover.1786294920.git.wen.yang@linux.dev>
From: Wen Yang <wen.yang@linux.dev>
Reactors must not explicitly take locks, so they should comply with
LD_WAIT_FREE. However, reactor callbacks can run with preemption
enabled on any kernel (not just PREEMPT_RT). If a timer interrupt
fires during the callback, the interrupt exit path schedules and
acquires rq->__lock (LD_WAIT_SPIN) while the lockdep override map that
declared LD_WAIT_FREE is still held, triggering a spurious
"Invalid wait context" warning:
[ BUG: Invalid wait context ]
context-{5:5}
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}
Fixes: 69d8895cb9a9 ("rv: Add explicit lockdep context for reactors")
Suggested-by: Gabriele Monaco <gmonaco@redhat.com>
Signed-off-by: Wen Yang <wen.yang@linux.dev>
Cc: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
kernel/trace/rv/rv_reactors.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/kernel/trace/rv/rv_reactors.c b/kernel/trace/rv/rv_reactors.c
index 2f5fc8d18dea..5830229210e8 100644
--- a/kernel/trace/rv/rv_reactors.c
+++ b/kernel/trace/rv/rv_reactors.c
@@ -465,18 +465,28 @@ int init_rv_reactors(struct dentry *root_dir)
void rv_react(struct rv_monitor *monitor, const char *msg, ...)
{
- static DEFINE_WAIT_OVERRIDE_MAP(rv_react_map, LD_WAIT_FREE);
+ /*
+ * Reactors must not explicitly take locks, so they should be
+ * LD_WAIT_FREE. However, reactor callbacks can run with preemption
+ * enabled, meaning the preempting code (e.g. the scheduler taking
+ * rq->__lock at LD_WAIT_SPIN) may violate that constraint. Use
+ * LD_WAIT_SPIN in preemptible contexts to avoid false-positive lockdep
+ * reports; keep LD_WAIT_FREE in NMI/hardirq where preemption is
+ * disabled and the scheduler cannot run.
+ */
+ static DEFINE_WAIT_OVERRIDE_MAP(rv_react_map, LD_WAIT_SPIN);
+ static DEFINE_WAIT_OVERRIDE_MAP(rv_react_map_atomic, LD_WAIT_FREE);
+ struct lockdep_map * __maybe_unused map;
va_list args;
if (!rv_reacting_on() || !monitor->react)
return;
+ map = (in_nmi() || in_hardirq()) ? &rv_react_map_atomic : &rv_react_map;
va_start(args, msg);
-
- lock_map_acquire_try(&rv_react_map);
+ lock_map_acquire_try(map);
monitor->react(msg, args);
- lock_map_release(&rv_react_map);
-
+ lock_map_release(map);
va_end(args);
}
EXPORT_SYMBOL_GPL(rv_react);
--
2.25.1
next prev parent reply other threads:[~2026-08-09 17:11 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-09 17:10 [PATCH v3 0/4] rv/reactors: fix lockdep warning and add KUnit tests wen.yang
2026-08-09 17:10 ` wen.yang [this message]
2026-08-12 12:34 ` [PATCH v3 1/4] rv/reactors: use context-sensitive lockdep wait type in rv_react() Gabriele Monaco
2026-08-17 8:18 ` Nam Cao
2026-08-09 17:10 ` [PATCH v3 2/4] rv/reactors: propagate rv_register_reactor() error from reactor init wen.yang
2026-08-17 10:54 ` Nam Cao
2026-08-09 17:10 ` [PATCH v3 3/4] rv/reactors: export rv_register_reactor() and rv_unregister_reactor() wen.yang
2026-08-09 17:10 ` [PATCH v3 4/4] rv/reactors: add KUnit tests for reactor registration and dispatch wen.yang
2026-08-12 12:58 ` Gabriele Monaco
2026-08-17 10:52 ` Nam Cao
2026-08-17 11:05 ` 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=26526e555baa5118325b2383e9f7f0f8f9b6a199.1786294920.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 \
--cc=thomas.weissschuh@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
all inboxes | Powered by JetHome®