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 1/4] kcov: Use raw_spinlock_t for kcov->lock and kcov_remote_lock
Date: Wed, 6 Aug 2025 00:33:14 +0900 [thread overview]
Message-ID: <d08de0fa-9dfd-4fc4-b9c0-ff181df8d459@kzalloc.com> (raw)
In-Reply-To: <20250804122758.620f934a@gandalf.local.home>
Hi Steve,
Thanks for the review and the suggestion.
On 8/5/25 1:27 오전, Steven Rostedt wrote:
> On Sun, 3 Aug 2025 07:20:43 +0000
> Yunseong Kim <ysk@kzalloc.com> wrote:
>
>> The locks kcov->lock and kcov_remote_lock can be acquired from
>> atomic contexts, such as instrumentation hooks invoked from interrupt
>> handlers.
>>
>> On PREEMPT_RT-enabled kernels, spinlock_t is typically implemented
>
> On PREEMPT_RT is implemented as a sleeping lock. You don't need to say
> "typically".
You're right — the phrase "typically implemented as a sleeping lock" was
inaccurate. On PREEMPT_RT, spinlock_t is implemented as a sleeping lock, and
I'll make sure to correct that wording in the next version.
>> as a sleeping lock (e.g., mapped to an rt_mutex). Acquiring such a
>> lock in atomic context, where sleeping is not allowed, can lead to
>> system hangs or crashes.
>>
>> To avoid this, convert both locks to raw_spinlock_t, which always
>> provides non-sleeping spinlock semantics regardless of preemption model.
>>
>> Signed-off-by: Yunseong Kim <ysk@kzalloc.com>
>> ---
>> kernel/kcov.c | 58 +++++++++++++++++++++++++--------------------------
>> 1 file changed, 29 insertions(+), 29 deletions(-)
>>
>> diff --git a/kernel/kcov.c b/kernel/kcov.c
>> index 187ba1b80bda..7d9b53385d81 100644
>> --- a/kernel/kcov.c
>> +++ b/kernel/kcov.c
>> @@ -54,7 +54,7 @@ struct kcov {
>> */
>> refcount_t refcount;
>> /* The lock protects mode, size, area and t. */
>> - spinlock_t lock;
>> + raw_spinlock_t lock;
>> enum kcov_mode mode;
>> /* Size of arena (in long's). */
>> unsigned int size;
>> @@ -84,7 +84,7 @@ struct kcov_remote {
>> struct hlist_node hnode;
>> };
>>
>> -static DEFINE_SPINLOCK(kcov_remote_lock);
>> +static DEFINE_RAW_SPINLOCK(kcov_remote_lock);
>> static DEFINE_HASHTABLE(kcov_remote_map, 4);
>> static struct list_head kcov_remote_areas = LIST_HEAD_INIT(kcov_remote_areas);
>>
>> @@ -406,7 +406,7 @@ static void kcov_remote_reset(struct kcov *kcov)
>> struct hlist_node *tmp;
>> unsigned long flags;
>>
>> - spin_lock_irqsave(&kcov_remote_lock, flags);
>> + raw_spin_lock_irqsave(&kcov_remote_lock, flags);
>
> Not related to these patches, but have you thought about converting some of
> these locks over to the "guard()" infrastructure provided by cleanup.h?
Also, I appreciate your note about the guard() infrastructure from cleanup.h.
I'll look into whether it's applicable in this context, and plan to adopt it
where appropriate in the next iteration of the series.
>> hash_for_each_safe(kcov_remote_map, bkt, tmp, remote, hnode) {
>> if (remote->kcov != kcov)
>> continue;
>
> Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
>
> -- Steve
Thanks again for the feedback and for the Reviewed-by tag!
Best regards,
Yunseong Kim
next prev parent reply other threads:[~2025-08-05 15:33 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 [this message]
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
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=d08de0fa-9dfd-4fc4-b9c0-ff181df8d459@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