Linux real-time development
 help / color / mirror / Atom feed
From: Yunseong Kim <ysk@kzalloc.com>
To: Nam Cao <namcao@linutronix.de>, Gabriele Monaco <gmonaco@redhat.com>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	rostedt@goodmis.org, 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>,
	Dan Carpenter <dan.carpenter@linaro.org>
Subject: Re: [Question] Detecting Sleep-in-Atomic Context in PREEMPT_RT via RV (Runtime Verification) monitor rtapp:sleep
Date: Thu, 11 Dec 2025 13:30:19 +0900	[thread overview]
Message-ID: <53f17978-40e5-4b2e-b719-552612b0e775@kzalloc.com> (raw)
In-Reply-To: <20251202112644.YUux4LKd@linutronix.de>

Hi Nam and Gabriele,

Thanks for the great presentation at LPC 2025.

I have a follow-up question during the Gabriele's Session RV and 
real-time properties, regarding spinlock behavior in atomic
contexts (IRQ/preempt disabled) on the PREEMPT_RT kernel.

On 12/2/25 20:26, Sebastian Andrzej Siewior wrote:
> On 2025-12-02 12:14:09 [+0100], Nam Cao wrote:
>>> 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.
>>
>> I was looking up something unrelated, and I found that Smatch does
>> detect this sleep-in-atomic problem:
>> https://staticthinking.wordpress.com/2024/05/24/sleeping-in-atomic-warnings/
>>
>> I'm not sure if its design takes PREEMPT_RT into consideration. But
>> seems worth having a look.
> 
> It does not look like it does. Judging from
> 	https://github.com/error27/smatch/blob/master/check_preempt_info.c
> 
> it increments the preempt-counter on preempt_disable() and spin_lock().
> So it won't yell at
> 	preempt_disable();
> 	spin_lock();
> 
> while CONFIG_DEBUG_ATOMIC_SLEEP would.

I specifically believe that RV can encompass the role of
CONFIG_DEBUG_ATOMIC_SLEEP and even go beyond it.

My reasoning is that even if a sleepable (PREEMPT_RT) spinlock is used 
within an IRQ/preemption disabled section, CONFIG_DEBUG_ATOMIC_SLEEP 
might not trigger a warning if scheduling does not actually occur (i.e., 
if there is no contention for that spinlock). This is because the actual 
debugging check happens in __might_resched().

Therefore, I think RV could catch these potential bugs that might
otherwise be missed. Is my understanding in the right direction?

>> Nam
> 
> Sebastian

I really appreciate Nam and Sebastian for sharing valuable insights on
static analysis tools again.

I recently discussed this with the Kernel CVE team, and Greg confirmed
that such usage (sleepable spinlocks in IRQ/preempt disabled sections)
is handled as a CVE.

I would appreciate your insights on this matter.

Best regards,
Yunseong Kim

  reply	other threads:[~2025-12-11  4:30 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
2025-12-02 11:14   ` Nam Cao
2025-12-02 11:26     ` Sebastian Andrzej Siewior
2025-12-11  4:30       ` Yunseong Kim [this message]
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=53f17978-40e5-4b2e-b719-552612b0e775@kzalloc.com \
    --to=ysk@kzalloc.com \
    --cc=bigeasy@linutronix.de \
    --cc=byungchul@sk.com \
    --cc=dan.carpenter@linaro.org \
    --cc=gmonaco@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=namcao@linutronix.de \
    --cc=rostedt@goodmis.org \
    --cc=shung-hsi.yu@suse.com \
    --cc=syzkaller@googlegroups.com \
    --cc=tglozar@redhat.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