From: Bart Van Assche <bvanassche@acm.org>
To: Christoph Hellwig <hch@lst.de>
Cc: "Martin K . Petersen" <martin.petersen@oracle.com>,
linux-scsi@vger.kernel.org, John Garry <john.g.garry@oracle.com>,
Marco Elver <elver@google.com>,
llvm@lists.linux.dev
Subject: Re: [PATCH v4 7/8] scsi: scsi_debug: Improve lock context annotations
Date: Wed, 7 Oct 2026 13:10:27 -0700 [thread overview]
Message-ID: <cf697d5c-1b5d-4e3a-983b-f710eb41b5b6@acm.org> (raw)
In-Reply-To: <20261007131411.GE30647@lst.de>
On 10/7/26 6:14 AM, Christoph Hellwig wrote:
> On Tue, Oct 06, 2026 at 10:07:29PM -0700, Bart Van Assche wrote:
>> static inline void
>> sdeb_read_lock(rwlock_t *lock)
>> + __acquires_shared(lock)
>> + __context_unsafe(/*conditional locking*/)
>> {
>> - if (sdebug_no_rwlock)
>> - __acquire(lock);
>> - else
>> + if (!sdebug_no_rwlock)
>> read_lock(lock);
>> }
>
> Is there no way we can make the spare-style __acquire/__release work for
> clang? That would be this and similar patterns so much better and
> safer than the blanket __context_unsafe.
Hi Christoph,
Do you like the alternative below better? If so then I will replace
patch 7/8 with the changes below.
Thanks,
Bart.
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index b339f022af26..e8d8b693751e 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -4052,42 +4052,47 @@ static inline struct sdeb_store_info
*devip2sip(struct sdebug_dev_info *devip,
static inline void
sdeb_read_lock(rwlock_t *lock)
+ __acquires_shared(lock)
{
- if (sdebug_no_rwlock)
- __acquire(lock);
- else
+ if (!sdebug_no_rwlock)
read_lock(lock);
+ else
+ __acquire_shared(lock);
}
static inline void
sdeb_read_unlock(rwlock_t *lock)
+ __releases_shared(lock)
{
- if (sdebug_no_rwlock)
- __release(lock);
- else
+ if (!sdebug_no_rwlock)
read_unlock(lock);
+ else
+ __release_shared(lock);
}
static inline void
sdeb_write_lock(rwlock_t *lock)
+ __acquires(lock)
{
- if (sdebug_no_rwlock)
- __acquire(lock);
- else
+ if (!sdebug_no_rwlock)
write_lock(lock);
+ else
+ __acquire(lock);
}
static inline void
sdeb_write_unlock(rwlock_t *lock)
+ __releases(lock)
{
- if (sdebug_no_rwlock)
- __release(lock);
- else
+ if (!sdebug_no_rwlock)
write_unlock(lock);
+ else
+ __release(lock);
}
static inline void
sdeb_data_read_lock(struct sdeb_store_info *sip)
+ __acquires_shared(&sip->macc_data_lck)
{
BUG_ON(!sip);
@@ -4096,6 +4101,7 @@ sdeb_data_read_lock(struct sdeb_store_info *sip)
static inline void
sdeb_data_read_unlock(struct sdeb_store_info *sip)
+ __releases_shared(&sip->macc_data_lck)
{
BUG_ON(!sip);
@@ -4104,6 +4110,7 @@ sdeb_data_read_unlock(struct sdeb_store_info *sip)
static inline void
sdeb_data_write_lock(struct sdeb_store_info *sip)
+ __acquires(&sip->macc_data_lck)
{
BUG_ON(!sip);
@@ -4112,6 +4119,7 @@ sdeb_data_write_lock(struct sdeb_store_info *sip)
static inline void
sdeb_data_write_unlock(struct sdeb_store_info *sip)
+ __releases(&sip->macc_data_lck)
{
BUG_ON(!sip);
@@ -4120,6 +4128,7 @@ sdeb_data_write_unlock(struct sdeb_store_info *sip)
static inline void
sdeb_data_sector_read_lock(struct sdeb_store_info *sip)
+ __acquires_shared(&sip->macc_sector_lck)
{
BUG_ON(!sip);
@@ -4128,6 +4137,7 @@ sdeb_data_sector_read_lock(struct sdeb_store_info
*sip)
static inline void
sdeb_data_sector_read_unlock(struct sdeb_store_info *sip)
+ __releases_shared(&sip->macc_sector_lck)
{
BUG_ON(!sip);
@@ -4136,6 +4146,7 @@ sdeb_data_sector_read_unlock(struct
sdeb_store_info *sip)
static inline void
sdeb_data_sector_write_lock(struct sdeb_store_info *sip)
+ __acquires(&sip->macc_sector_lck)
{
BUG_ON(!sip);
@@ -4144,6 +4155,7 @@ sdeb_data_sector_write_lock(struct sdeb_store_info
*sip)
static inline void
sdeb_data_sector_write_unlock(struct sdeb_store_info *sip)
+ __releases(&sip->macc_sector_lck)
{
BUG_ON(!sip);
@@ -4165,102 +4177,122 @@ sdeb_data_sector_write_unlock(struct
sdeb_store_info *sip)
static inline void
sdeb_data_lock(struct sdeb_store_info *sip, bool atomic)
+ __acquires(&sip->macc_data_lck)
{
- if (atomic)
+ if (atomic) {
sdeb_data_write_lock(sip);
- else
+ } else {
sdeb_data_read_lock(sip);
+ __release_shared(&sip->macc_data_lck);
+ __acquire(&sip->macc_data_lck);
+ }
}
static inline void
sdeb_data_unlock(struct sdeb_store_info *sip, bool atomic)
+ __releases(&sip->macc_data_lck)
{
- if (atomic)
+ if (atomic) {
sdeb_data_write_unlock(sip);
- else
+ } else {
+ __release(&sip->macc_data_lck);
+ __acquire_shared(&sip->macc_data_lck);
sdeb_data_read_unlock(sip);
+ }
}
/* Allow many reads but only 1x write per sector */
static inline void
sdeb_data_sector_lock(struct sdeb_store_info *sip, bool do_write)
+ __acquires(&sip->macc_sector_lck)
{
- if (do_write)
+ if (do_write) {
sdeb_data_sector_write_lock(sip);
- else
+ } else {
sdeb_data_sector_read_lock(sip);
+ __release_shared(&sip->macc_sector_lck);
+ __acquire(&sip->macc_sector_lck);
+ }
}
static inline void
sdeb_data_sector_unlock(struct sdeb_store_info *sip, bool do_write)
+ __releases(&sip->macc_sector_lck)
{
- if (do_write)
+ if (do_write) {
sdeb_data_sector_write_unlock(sip);
- else
+ } else {
+ __release(&sip->macc_sector_lck);
+ __acquire_shared(&sip->macc_sector_lck);
sdeb_data_sector_read_unlock(sip);
+ }
}
static inline void
sdeb_meta_read_lock(struct sdeb_store_info *sip)
+ __acquires_shared(&sip->macc_meta_lck)
{
- if (sdebug_no_rwlock) {
- if (sip)
- __acquire(&sip->macc_meta_lck);
- else
- __acquire(&sdeb_fake_rw_lck);
- } else {
- if (sip)
+ if (!sdebug_no_rwlock) {
+ if (sip) {
read_lock(&sip->macc_meta_lck);
- else
+ } else {
read_lock(&sdeb_fake_rw_lck);
+ __release_shared(&sdeb_fake_rw_lck);
+ __acquire_shared(&sip->macc_meta_lck);
+ }
+ } else {
+ __acquire_shared(&sip->macc_meta_lck);
}
}
static inline void
sdeb_meta_read_unlock(struct sdeb_store_info *sip)
+ __releases_shared(&sip->macc_meta_lck)
{
- if (sdebug_no_rwlock) {
- if (sip)
- __release(&sip->macc_meta_lck);
- else
- __release(&sdeb_fake_rw_lck);
- } else {
- if (sip)
+ if (!sdebug_no_rwlock) {
+ if (sip) {
read_unlock(&sip->macc_meta_lck);
- else
+ } else {
+ __acquire_shared(&sdeb_fake_rw_lck);
read_unlock(&sdeb_fake_rw_lck);
+ __release_shared(&sip->macc_meta_lck);
+ }
+ } else {
+ __release_shared(&sip->macc_meta_lck);
}
}
static inline void
sdeb_meta_write_lock(struct sdeb_store_info *sip)
+ __acquires(&sip->macc_meta_lck)
{
- if (sdebug_no_rwlock) {
- if (sip)
- __acquire(&sip->macc_meta_lck);
- else
- __acquire(&sdeb_fake_rw_lck);
- } else {
- if (sip)
+ if (!sdebug_no_rwlock) {
+ if (sip) {
write_lock(&sip->macc_meta_lck);
- else
+ } else {
write_lock(&sdeb_fake_rw_lck);
+ __release(&sdeb_fake_rw_lck);
+ __acquire(&sip->macc_meta_lck);
+ }
+ } else {
+ __acquire(&sip->macc_meta_lck);
}
}
static inline void
sdeb_meta_write_unlock(struct sdeb_store_info *sip)
+ __releases(&sip->macc_meta_lck)
{
- if (sdebug_no_rwlock) {
- if (sip)
- __release(&sip->macc_meta_lck);
- else
- __release(&sdeb_fake_rw_lck);
- } else {
- if (sip)
+ if (!sdebug_no_rwlock) {
+ if (sip) {
write_unlock(&sip->macc_meta_lck);
- else
+ } else {
+ __acquire(&sdeb_fake_rw_lck);
write_unlock(&sdeb_fake_rw_lck);
+ __release(&sip->macc_meta_lck);
+ }
+ } else {
+ __release(&sip->macc_meta_lck);
}
}
next prev parent reply other threads:[~2026-10-07 20:10 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-07 5:07 [PATCH v4 0/8] scsi_debug: Enable lock context analysis Bart Van Assche
2026-10-07 5:07 ` [PATCH v4 1/8] scsi: scsi_debug: Fix a locking bug in resp_write_same() Bart Van Assche
2026-10-07 5:07 ` [PATCH v4 2/8] scsi: scsi_debug: Split resp_write_same() Bart Van Assche
2026-10-07 5:07 ` [PATCH v4 3/8] scsi: scsi_debug: Split corrupt_lbas() Bart Van Assche
2026-10-07 5:07 ` [PATCH v4 4/8] scsi: scsi_debug: Split resp_read_dt0() Bart Van Assche
2026-10-07 5:07 ` [PATCH v4 5/8] scsi: scsi_debug: Split resp_write_dt0() Bart Van Assche
2026-10-07 13:12 ` Christoph Hellwig
2026-10-07 20:08 ` Bart Van Assche
2026-10-08 7:09 ` Christoph Hellwig
2026-10-07 5:07 ` [PATCH v4 6/8] scsi: scsi_debug: Split resp_atomic_write() Bart Van Assche
2026-10-07 13:12 ` Christoph Hellwig
2026-10-07 5:07 ` [PATCH v4 7/8] scsi: scsi_debug: Improve lock context annotations Bart Van Assche
2026-10-07 5:17 ` sashiko-bot
2026-10-07 13:14 ` Christoph Hellwig
2026-10-07 14:31 ` Marco Elver
2026-10-07 20:10 ` Bart Van Assche [this message]
2026-10-08 7:10 ` Christoph Hellwig
2026-10-07 5:07 ` [PATCH v4 8/8] scsi: core: Enable lock context analysis for the scsi_debug driver Bart Van Assche
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=cf697d5c-1b5d-4e3a-983b-f710eb41b5b6@acm.org \
--to=bvanassche@acm.org \
--cc=elver@google.com \
--cc=hch@lst.de \
--cc=john.g.garry@oracle.com \
--cc=linux-scsi@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=martin.petersen@oracle.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