From: Gabriele Monaco <gmonaco@redhat.com>
To: "Wen Yang" <wen.yang@linux.dev>,
"Thomas Weißschuh" <thomas.weissschuh@linutronix.de>
Cc: Nam Cao <namcao@linutronix.de>,
linux-trace-kernel@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 1/4] rv/reactors: use context-sensitive lockdep wait type in rv_react()
Date: Tue, 25 Aug 2026 16:43:34 +0200 [thread overview]
Message-ID: <1b3bb36a8acfa64dd250482e92a23dadcc8a6329.camel@redhat.com> (raw)
In-Reply-To: <d72daef4-5d68-49e4-a264-3f813d897813@linux.dev>
On Thu, 2026-08-20 at 01:28 +0800, Wen Yang wrote:
> So I don't think LD_WAIT_SPIN for everything is safe, it's not just
> "less strict on paper".
Yes it won't be safe, we could have wrong reactors not reported by lockdep, but
so would your conditional check. We'd be catching everything in interrupts, but
if a model never runs in interrupt context, we'd be demoted to LD_WAIT_SPIN
nonetheless.
Your condition is kind of a best-effort to do a bit better than just
LD_WAIT_SPIN. Again, I'm not completely against it, but it isn't a final
solution (not that I can think of a better one) and if most people find it
confusing, we're probably better off without it.
Or am I missing something?
> If a reactor ever does raw_spin_lock() by mistake while running from
> nrp's path, check_wait_context() takes the wait type straight from the
> override map:
>
> if (unlikely(class->lock_type == LD_LOCK_WAIT_OVERRIDE))
> curr_inner = prev_inner; /* SPIN */
> if (next_outer > curr_inner)
> return print_lock_invalid_wait_context(...);
>
> SPIN nested in SPIN is 2 > 2, which is false, so it just passes.
> We'd be silently giving up the one case (hardirq/NMI) where the "no
> locks" rule for reactors actually matters, which is the same thing that
> bit you with the signal reactor.
True, that is one, but it isn't the only case where using locks can be an issue,
namely sched_switch is particularly hard to please (interrupts are disabled for
a reason).
> And for what it's worth, checking context to decide the wait type isn't
> something we'd be introducing -- lockdep does the same thing to get the
> baseline before any override is applied, in the exact function that
> produced this splat:
>
> static inline short task_wait_context(struct task_struct *curr)
> {
> if (lockdep_hardirq_context()) {
> if (curr->hardirq_threaded || curr->irq_config)
> return LD_WAIT_CONFIG;
> return LD_WAIT_SPIN;
> } else if (curr->softirq_context) {
> return LD_WAIT_CONFIG;
> }
> return LD_WAIT_MAX;
> }
>
> That's four cases. Our in_nmi() || in_hardirq() is a simplification of
> what's already there, not a new habit.
I'm not familiar with the lockdep code, so I may be missing something here, but
isn't this function getting the current context? It isn't used to tune the
lockdep logic for some specific function, it /is/ the lockdep logic itself.
Is this really comparable?
> Thomas, on disabling preemption instead: it does fix the pagefault
> case, and it's a no-op for nrp since preempt_count is already elevated
> there. But it changes what a reactor is allowed to do, for every
> reactor, not just the two above.cspin_lock() on RT checks
> might_resched() before it even looks at thevlock:
>
> static __always_inline void __rt_spin_lock(spinlock_t *lock)
> {
> rtlock_might_resched(); /* unconditional */
> rtlock_lock(&lock->lock);
> }
>
> so any future reactor using a plain spinlock would hit that every single
> time, lock contended or not, on top of whatever it's already called for.
> That seems worse than the thing we're trying to fix.
I'm also against disabling preemption, we may even be able to avoid scheduling
by also disabling interrupts in a convenient order, but in principle I'd avoid
that like plague. RV was born as a tool for real-time and disabling preemption
only to get better lockdep reporting doesn't look right to me.
Sure we could do it only with lockdep and assume lockdep's overhead is already
enough, but we're again complicating things.
> Since neither struct rv_reactor nor rv_react() actually documents what
> context a callback may run in, maybe that's worth spelling out
> separately regardless of what we do here -- something close to what
> printk already does for the same reason (reactor_printk's
> vprintk_deferred() leans on this internally: is_printk_legacy_deferred()
> checks in_nmi() to decide whether it's safe to take console_lock or
> whether it has to go through the lock-free irq_work path instead).
You raise a fair point though, we should document all this somewhere. I believe
this is the best thing we can do at this point.
The peculiarity of reactors and RV in general is that we run from tracepoints,
so we could run virtually from anywhere, that's why there's no one size fits
all..
Overall I'm now leaning towards using only LD_WAIT_SPIN and carefully document
why we had to do this.
What do you all think?
Thanks,
Gabriele
next prev parent reply other threads:[~2026-08-25 14:43 UTC|newest]
Thread overview: 15+ 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 ` [PATCH v3 1/4] rv/reactors: use context-sensitive lockdep wait type in rv_react() wen.yang
2026-08-12 12:34 ` Gabriele Monaco
2026-08-17 8:18 ` Nam Cao
2026-08-19 7:12 ` Gabriele Monaco
2026-08-19 9:24 ` Thomas Weißschuh
2026-08-19 17:28 ` Wen Yang
2026-08-25 14:43 ` Gabriele Monaco [this message]
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=1b3bb36a8acfa64dd250482e92a23dadcc8a6329.camel@redhat.com \
--to=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 \
--cc=wen.yang@linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.