From: Nam Cao <namcao@linutronix.de>
To: Yunseong Kim <ysk@kzalloc.com>, Nam Cao <nam.cao@linaro.org>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Tomas Glozar <tglozar@redhat.com>,
Shung-Hsi Yu <shung-hsi.yu@suse.com>,
Byungchul Park <byungchul@sk.com>,
syzkaller@googlegroups.com, linux-rt-devel@lists.linux.dev,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [Question] Detecting Sleep-in-Atomic Context in PREEMPT_RT via RV (Runtime Verification) monitor rtapp:sleep
Date: Wed, 05 Nov 2025 10:10:39 +0100 [thread overview]
Message-ID: <87fraslu9c.fsf@yellow.woof> (raw)
In-Reply-To: <32839fb6-dbcb-4c5c-9e3f-d46f27ae9a73@kzalloc.com>
Yunseong Kim <ysk@kzalloc.com> writes:
> Hi Nam,
>
> I've been very interested in RV (Runtime Verification)
Cool, happy to learn you find it interesting.
> to proactively detect
> "sleep in atomic" scenarios on PREEMPT_RT kernels. Specifically, I'm looking
> for ways to find cases where sleeping spinlocks or memory allocations are used
> within preemption-disabled or irq-disabled contexts. While searching for
> solutions, I discovered the RV subsystem.
...
> Here are my questions:
>
> 1. Does the rtapp:sleep monitor proactively detect scenarios that
> could lead to sleeping in atomic context, perhaps before
> CONFIG_DEBUG_ATOMIC_SLEEP (enabled) would trigger at the actual point of
> sleeping?
No it does not, as explained by Gabriele.
I am a bit confused, because CONFIG_DEBUG_ATOMIC_SLEEP seems to already
do what you need. CONFIG_DEBUG_ATOMIC_SLEEP does warn before the actual
point of sleeping. Sleeping locks and memory allocations are marked with
might_sleep(). When they are called in atomic context, we have a warning
regardless of whether actual sleep happens. See the comment above
might_sleep():
"This is a useful debugging help to be able to catch problems early and
not be bitten later when the calling function happens to sleep when it
is not supposed to"
For sure you can implement this functionality in RV, but I don't think
RV can do more. An advantage of doing it in RV is the ability to toggle
at run-time, but that's a different discussion.
> 2. Is there a way to enable this monitor (e.g., rtapp:sleep)
> immediately as soon as the RV subsystem is loaded during boot time?
> (How to make this "default turn on"?)
At the moment, no. But if you need this, we could look into implementing it.
> 3. When a "violation detected" message occurs at runtime, is it
> possible to get a call stack of the location that triggered the
> violation? The panic reactor provides a full stack, but I'm
> wondering if this is also possible with the printk reactor.
You can use monitor's tracepoint to get the stacktrace, as mentioned by Gabriele.
> This led me to research ways to find these issues proactively at a
> static analysis level, and I created some regex and coccinelle scripts
> to detect them.
...
> Tomas, the author of the rtlockscope project, also gave me some deep
> insights into this static analysis approach.
RV is not a static checker, it is a run-time checker.
Just in case you are not aware yet, there is also Smatch:
https://github.com/error27/smatch. But I can't offer much help there.
Nam
next prev parent reply other threads:[~2025-11-05 9:10 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-27 6:54 [Question] Detecting Sleep-in-Atomic Context in PREEMPT_RT via RV (Runtime Verification) monitor rtapp:sleep Yunseong Kim
2025-10-27 12:20 ` Gabriele Monaco
2025-10-28 22:53 ` Yunseong Kim
2025-10-29 9:24 ` Gabriele Monaco
2025-11-05 9:10 ` Nam Cao [this message]
2025-12-02 11:14 ` Nam Cao
2025-12-02 11:26 ` Sebastian Andrzej Siewior
2025-12-11 4:30 ` Yunseong Kim
2025-12-11 5:42 ` Nam Cao
2025-12-11 7:58 ` Yunseong Kim
2025-12-22 7:40 ` Gabriele Monaco
2025-12-23 14:31 ` Yunseong Kim
2025-12-23 15:21 ` Gabriele Monaco
2025-12-12 7:02 ` Dan Carpenter
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=87fraslu9c.fsf@yellow.woof \
--to=namcao@linutronix.de \
--cc=bigeasy@linutronix.de \
--cc=byungchul@sk.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=nam.cao@linaro.org \
--cc=shung-hsi.yu@suse.com \
--cc=syzkaller@googlegroups.com \
--cc=tglozar@redhat.com \
--cc=ysk@kzalloc.com \
/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