From: buckzhang1212@yeah.net
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
Boqun Feng <boqun.feng@gmail.com>,
Waiman Long <longman@redhat.com>,
linux-kernel@vger.kernel.org
Cc: buckzhang1212@yeah.net
Subject: [PATCH v3] locking/rwsem: add DEBUG_RWSEMS_WARN_ON to warn invalid rwsem
Date: Mon, 29 Sep 2025 07:48:12 -0700 [thread overview]
Message-ID: <20250929144812.2211-1-buckzhang1212@yeah.net> (raw)
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)))
--
2.17.1
next reply other threads:[~2025-09-29 14:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-29 14:48 buckzhang1212 [this message]
2025-09-30 3:09 ` Waiman Long
[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=20250929144812.2211-1-buckzhang1212@yeah.net \
--to=buckzhang1212@yeah.net \
--cc=boqun.feng@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--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®