mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
	Boqun Feng <boqun@kernel.org>, Waiman Long <longman@redhat.com>,
	linux-kernel@vger.kernel.org, Marco Elver <elver@google.com>,
	Christoph Hellwig <hch@lst.de>,
	Bart Van Assche <bvanassche@acm.org>
Subject: [PATCH 2/2] locking/rwlock: Report lock acquisition in non-debug do_raw_*_trylock()
Date: Fri,  4 Dec 2026 13:58:07 -0800	[thread overview]
Message-ID: <191260628fd9444b1e3ed202cdd1ef52eefe4ec5.1796421357.git.bvanassche@acm.org> (raw)
In-Reply-To: <cover.1796421357.git.bvanassche@acm.org>

Report lock acquisition explicitly in the !CONFIG_DEBUG_SPINLOCK
definitions of do_raw_{read,write}_trylock() instead of using
__no_context_analysis. This allows the compiler to verify that the
function bodies match their __cond_acquires*() annotations and matches
do_raw_spin_trylock() in include/linux/spinlock.h.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 include/linux/rwlock.h | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/include/linux/rwlock.h b/include/linux/rwlock.h
index 396eb022bbd1..beae43c4655c 100644
--- a/include/linux/rwlock.h
+++ b/include/linux/rwlock.h
@@ -39,17 +39,25 @@ extern int do_raw_write_trylock(rwlock_t *lock) __cond_acquires(true, lock);
 # define do_raw_read_lock(rwlock)	do {__acquire_shared(rwlock); arch_read_lock(&(rwlock)->raw_lock); } while (0)
 static inline int do_raw_read_trylock(rwlock_t *rwlock)
 	__cond_acquires_shared(true, rwlock)
-	__no_context_analysis
 {
-	return arch_read_trylock(&(rwlock)->raw_lock);
+	int ret = arch_read_trylock(&(rwlock)->raw_lock);
+
+	if (ret)
+		__acquire_shared(rwlock);
+
+	return ret;
 }
 # define do_raw_read_unlock(rwlock)	do {arch_read_unlock(&(rwlock)->raw_lock); __release_shared(rwlock); } while (0)
 # define do_raw_write_lock(rwlock)	do {__acquire(rwlock); arch_write_lock(&(rwlock)->raw_lock); } while (0)
 static inline int do_raw_write_trylock(rwlock_t *rwlock)
 	__cond_acquires(true, rwlock)
-	__no_context_analysis
 {
-	return arch_write_trylock(&(rwlock)->raw_lock);
+	int ret = arch_write_trylock(&(rwlock)->raw_lock);
+
+	if (ret)
+		__acquire(rwlock);
+
+	return ret;
 }
 # define do_raw_write_unlock(rwlock)	do {arch_write_unlock(&(rwlock)->raw_lock); __release(rwlock); } while (0)
 #endif

      parent reply	other threads:[~2026-12-04 21:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 21:58 [PATCH 0/2] locking/rwlock: Fix non-debug lock context annotations Bart Van Assche
2026-12-04 21:58 ` [PATCH 1/2] locking/rwlock: Pass rwlock to __acquire*() and __release*() Bart Van Assche
2026-12-04 21:58 ` Bart Van Assche [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=191260628fd9444b1e3ed202cdd1ef52eefe4ec5.1796421357.git.bvanassche@acm.org \
    --to=bvanassche@acm.org \
    --cc=boqun@kernel.org \
    --cc=elver@google.com \
    --cc=hch@lst.de \
    --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®