From: Yunseong Kim <ysk@kzalloc.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Dmitry Vyukov <dvyukov@google.com>,
Andrey Konovalov <andreyknvl@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Thomas Gleixner <tglx@linutronix.de>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>,
Byungchul Park <byungchul@sk.com>,
max.byungchul.park@gmail.com, Yeoreum Yun <yeoreum.yun@arm.com>,
ppbuk5246@gmail.com, linux-usb@vger.kernel.org,
linux-rt-devel@lists.linux.dev, syzkaller@googlegroups.com,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v3 0/4] kcov, usb: Fix invalid context sleep in softirq path on PREEMPT_RT
Date: Wed, 6 Aug 2025 00:27:01 +0900 [thread overview]
Message-ID: <ddd14f62-b6c9-4984-84be-6c999ea92e30@kzalloc.com> (raw)
In-Reply-To: <20250804122405.3e9d83ed@gandalf.local.home>
Hi Steve,
You're absolutely right to ask for clarification, and I now realize that
I didn’t explain the background clearly enough in my cover letter.
On 8/5/25 1:24 오전, Steven Rostedt wrote:
> On Sun, 3 Aug 2025 07:20:41 +0000
> Yunseong Kim <ysk@kzalloc.com> wrote:
>
>> This patch series resolves a sleeping function called from invalid context
>> bug that occurs when fuzzing USB with syzkaller on a PREEMPT_RT kernel.
>>
>> The regression was introduced by the interaction of two separate patches:
>> one that made kcov's internal locks sleep on PREEMPT_RT for better latency
>
> Just so I fully understand this change. It is basically reverting the
> "better latency" changes? That is, with KCOV anyone running with PREEMPT_RT
> can expect non deterministic latency behavior?
The regression results from the interaction of two changes — and in my original
description, I inaccurately characterized one of them as being
"for better latency." That was misleading.
The first change d5d2c51 replaced spin_lock_irqsave() with local_lock_irqsave()
in KCOV to ensure compatibility with PREEMPT_RT. This avoided using a
potentially sleeping lock with interrupts disabled.
At the time, as Sebastian noted:
"There is no compelling reason to change the lock type to raw_spin_lock_t...
Changing it would require to move memory allocation and deallocation outside
of the locked section."
However, the situation changed after another patch 8fea0c8 converted the USB
HCD tasklet to a BH workqueue. As a result, usb_giveback_urb_bh() began running
with interrupts enabled, and the KCOV remote coverage collection section in
this path became re-entrant. To prevent nested coverage sections — which KCOV
doesn’t support — kcov_remote_start_usb_softirq() was updated to explicitly
disable interrupts during coverage collection f85d39d.
This combination — using a local_lock (which can sleep on RT) alongside
local_irq_save() — inadvertently created a scenario where a sleeping lock was
acquired in atomic context, triggering a kernel BUG on PREEMPT_RT.
So while the original KCOV locking change didn't require raw spinlocks at
the time, it became effectively incompatible with the USB softirq use case once
that path began relying on interrupt disabling for correctness. In this sense,
the "no compelling reason" eventually turned into a "necessary compromise."
To clarify: this patch series doesn't revert the previous change entirely.
It keeps the local_lock behavior for task context (where it's safe and
appropriate), but ensures atomic safety in interrupt/softirq contexts by
using raw spinlocks selectively where needed.
> This should be fully documented. I assume this will not be a problem as
> kcov is more for debugging and should not be enabled in production.
>
> -- Steve
>
Thanks again for raising this — I’ll make sure the changelog documents this
interaction more clearly.
Best regards,
Yunseong Kim
prev parent reply other threads:[~2025-08-05 15:27 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-03 7:20 [PATCH v3 0/4] kcov, usb: Fix invalid context sleep in softirq path on PREEMPT_RT Yunseong Kim
2025-08-03 7:20 ` [PATCH 1/4] kcov: Use raw_spinlock_t for kcov->lock and kcov_remote_lock Yunseong Kim
2025-08-03 7:23 ` kernel test robot
2025-08-04 16:27 ` Steven Rostedt
2025-08-05 15:33 ` Yunseong Kim
2025-08-03 7:20 ` [PATCH 2/4] kcov: Replace per-CPU local_lock with local_irq_save/restore Yunseong Kim
2025-08-04 16:37 ` Steven Rostedt
2025-08-05 15:41 ` Yunseong Kim
2025-08-03 7:20 ` [PATCH 3/4] kcov: Separate KCOV_REMOTE_ENABLE ioctl helper function Yunseong Kim
2025-08-03 7:20 ` [PATCH 4/4] kcov: move remote handle allocation outside raw spinlock Yunseong Kim
2025-08-04 16:24 ` [PATCH v3 0/4] kcov, usb: Fix invalid context sleep in softirq path on PREEMPT_RT Steven Rostedt
2025-08-05 15:27 ` Yunseong Kim [this message]
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=ddd14f62-b6c9-4984-84be-6c999ea92e30@kzalloc.com \
--to=ysk@kzalloc.com \
--cc=andreyknvl@gmail.com \
--cc=bigeasy@linutronix.de \
--cc=byungchul@sk.com \
--cc=dvyukov@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=linux-usb@vger.kernel.org \
--cc=max.byungchul.park@gmail.com \
--cc=penguin-kernel@i-love.sakura.ne.jp \
--cc=ppbuk5246@gmail.com \
--cc=rostedt@goodmis.org \
--cc=stable@vger.kernel.org \
--cc=syzkaller@googlegroups.com \
--cc=tglx@linutronix.de \
--cc=yeoreum.yun@arm.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