[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <b315b9e6-4373-4891-ac94-48da275f9909@redhat.com>
Date: Mon, 29 Sep 2025 23:09:19 -0400
From: Waiman Long <llong@...hat.com>
To: buckzhang1212@...h.net, Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>, Will Deacon <will@...nel.org>,
Boqun Feng <boqun.feng@...il.com>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v3] locking/rwsem: add DEBUG_RWSEMS_WARN_ON to warn
invalid rwsem
On 9/29/25 10:48 AM, buckzhang1212@...h.net wrote:
> From: "buck.zhang" <buckzhang1212@...h.net>
>
> Add the lock->magic check to warn invalid rwsem without initialization
>
> Signed-off-by: buck.zhang <buckzhang1212@...h.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@...hat.com>
Powered by blists - more mailing lists