Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Bart Van Assche" <bvanassche@acm.org>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v4 7/8] scsi: scsi_debug: Improve lock context annotations
Date: Wed, 07 Oct 2026 05:17:38 +0000	[thread overview]
Message-ID: <sashiko-outbox-162635@kernel.org> (raw)
In-Reply-To: <765bf3683555f3d7fbe8510cde1eb50d5f6d0c6f.1791349129.git.bvanassche@acm.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] scsi: deadlock or oops due to unprotected sdebug_no_rwlock modification
--

commit c129c8944c668498a44ba3a38c88f4214c8204f7
Author: Bart Van Assche <bvanassche@acm.org>

scsi: scsi_debug: Improve lock context annotations

Prepare the scsi_debug driver for enabling compiler-based lock context
analysis:

- Annotate the lock and unlock helper functions with __acquires,
  __releases, __acquires_shared, and __releases_shared.

- Remove sparse __acquire() and __release() calls from the helper
  functions since these mislead the lock context analyzer.

> diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
> index 244250ba460bc..2edb70013cbc2 100644
> --- a/drivers/scsi/scsi_debug.c
> +++ b/drivers/scsi/scsi_debug.c
> @@ -4052,42 +4052,43 @@ static inline struct sdeb_store_info *devip2sip(struct sdebug_dev_info *devip,
>  
>  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);
>  }

[Severity: High]
Does this conditional lock acquisition create a potential deadlock or oops?

The lock acquisition in sdeb_read_lock() is conditional on the unprotected
runtime value of sdebug_no_rwlock. If a user writes to the no_rwlock
attribute while I/O operations are actively being queued or processed, the
variable can change mid-flight.

drivers/scsi/scsi_debug.c:no_rwlock_store() {
	...
	if (kstrtobool(buf, &v))
		return -EINVAL;

	sdebug_no_rwlock = v;
	return count;
}

This sysfs store function modifies the global sdebug_no_rwlock variable
concurrently without any locking or quiescent state wait, allowing the race
condition to occur.

>  
>  static inline void
>  sdeb_read_unlock(rwlock_t *lock)
> +	__releases_shared(lock)
> +	__context_unsafe(/*conditional locking*/)
>  {
> -	if (sdebug_no_rwlock)
> -		__release(lock);
> -	else
> +	if (!sdebug_no_rwlock)
>  		read_unlock(lock);
>  }

[Severity: High]
Does this lock release rely on the same unprotected global variable?

If sdebug_no_rwlock changed to true since acquisition, the unlock is
skipped, causing a permanent deadlock. If changed to false while inside
a lockless critical section, read_unlock() is called without a prior
read_lock(), causing a kernel oops.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1791349129.git.bvanassche@acm.org?part=7

  reply	other threads:[~2026-10-07  5:17 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 [this message]
2026-10-07 13:14   ` Christoph Hellwig
2026-10-07 14:31     ` Marco Elver
2026-10-07 20:10     ` Bart Van Assche
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=sashiko-outbox-162635@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bvanassche@acm.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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