From: Waiman Long <llong@redhat.com>
To: buckzhang1212@yeah.net, Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
Boqun Feng <boqun.feng@gmail.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] locking/rwsem: add DEBUG_RWSEMS_WARN_ON to warn invalid rwsem
Date: Mon, 29 Sep 2025 23:09:19 -0400 [thread overview]
Message-ID: <b315b9e6-4373-4891-ac94-48da275f9909@redhat.com> (raw)
In-Reply-To: <20250929144812.2211-1-buckzhang1212@yeah.net>
On 9/29/25 10:48 AM, buckzhang1212@yeah.net wrote:
> From: "buck.zhang" <buckzhang1212@yeah.net>
>
> Add the lock->magic check to warn invalid rwsem without initialization
>
> Signed-off-by: buck.zhang <buckzhang1212@yeah.net>
>
> ---
> Changes in v3:
> - Use the lock->magic check in __down_read_common/__down_write_common
> - (Suggested by Waiman Long)
> ---
> kernel/locking/rwsem.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c
> index 24df4d98f..38d884643 100644
> --- a/kernel/locking/rwsem.c
> +++ b/kernel/locking/rwsem.c
> @@ -1256,6 +1256,9 @@ static __always_inline int __down_read_common(struct rw_semaphore *sem, int stat
> int ret = 0;
> long count;
>
> + /* add the lock->magic check to warn the invalid rwsem without initialization */
> + DEBUG_RWSEMS_WARN_ON(sem->magic != sem, sem);
> +
> preempt_disable();
> if (!rwsem_read_trylock(sem, &count)) {
> if (IS_ERR(rwsem_down_read_slowpath(sem, count, state))) {
> @@ -1312,6 +1315,9 @@ static __always_inline int __down_write_common(struct rw_semaphore *sem, int sta
> {
> int ret = 0;
>
> + /* add the lock->magic check to warn the invalid rwsem without initialization */
> + DEBUG_RWSEMS_WARN_ON(sem->magic != sem, sem);
> +
> preempt_disable();
> if (unlikely(!rwsem_write_trylock(sem))) {
> if (IS_ERR(rwsem_down_write_slowpath(sem, state)))
Just to confirm that this patch will generate the needed warning for
your test case. Right?
Acked-by: Waiman Long <longman@redhat.com>
next prev parent reply other threads:[~2025-09-30 3:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-29 14:48 buckzhang1212
2025-09-30 3:09 ` Waiman Long [this message]
[not found] ` <78363f7b.34166.19998b29e71.Coremail.buckzhang1212@yeah.net>
2025-09-30 14:36 ` Waiman Long
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=b315b9e6-4373-4891-ac94-48da275f9909@redhat.com \
--to=llong@redhat.com \
--cc=boqun.feng@gmail.com \
--cc=buckzhang1212@yeah.net \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=will@kernel.org \
/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
all inboxes | Powered by JetHome®