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 4/7] scsi: scsi_debug: Split resp_read_dt0()
Date: Tue, 22 Sep 2026 23:37:04 +0000	[thread overview]
Message-ID: <20260922233705.4DE7B1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <bcc45fcd315feaec1b033496444573723a5f081b.1790119506.git.bvanassche@acm.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] scsi_debug: early return of byte count in resp_read_dt0 fails IO
--

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

scsi: scsi_debug: Split resp_read_dt0()

This commit splits the `resp_read_dt0()` function to eliminate conditional
locking and prepare the code for context analysis.

> diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
> index fcfb49df9ee17..ac3b9bfa7e634 100644
> --- a/drivers/scsi/scsi_debug.c
> +++ b/drivers/scsi/scsi_debug.c
> @@ -4577,6 +4577,42 @@ static int resp_read_tape(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
>  	return 0;
>  }
>  
> +static int __resp_read_dt0(struct scsi_cmnd *scp, struct sdeb_store_info *sip,
> +			   u64 lba, u32 num, u32 ei_lba)
> +{
> +	u8 *cmd = scp->cmnd;
> +
> +	/* DIX + T10 DIF */
> +	if (unlikely(sdebug_dix && scsi_prot_sg_count(scp))) {
> +		switch (prot_verify_read(scp, lba, num, ei_lba)) {

[ ... ]

> +		}
> +	}
> +
> +	return do_device_access(sip, scp, 0, lba, num, 0, false, false);
> +}

[Severity: High]
Does returning the output of do_device_access() here cause successful reads
to return their byte count instead of zero?

Looking at do_device_access(), it returns the positive number of bytes copied
on success. Before this patch, the positive byte count was returned into
'ret', but it was ignored for successful reads.

>  static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
>  {
>  	bool check_prot;
> @@ -4668,46 +4703,17 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
>  	}
>  
>  	if (sdebug_dev_is_zoned(devip) ||
> -	    (sdebug_dix && scsi_prot_sg_count(scp)))  {
> +	    (sdebug_dix && scsi_prot_sg_count(scp))) {
>  		sdeb_meta_read_lock(sip);
> -		meta_data_locked = true;
> +		ret = __resp_read_dt0(scp, sip, lba, num, ei_lba);
> +		sdeb_meta_read_unlock(sip);
> +	} else {
> +		ret = __resp_read_dt0(scp, sip, lba, num, ei_lba);
>  	}
>  
> +	if (ret > 0)
> +		return ret;

[Severity: High]
Could this new check inadvertently cause successful IOs to fail?

Since __resp_read_dt0() returns the positive byte count on success
(e.g., 65536 bytes), this condition will evaluate to true. The function
will then return 65536 (0x10000) directly to the caller, bypassing
scsi_set_resid().

The SCSI midlayer appears to interpret a positive return value like 0x10000
as a SCSI result where the host byte is DID_NO_CONNECT (1), leading to a
complete failure of the IO operation.

(I verified that this issue remains present in the final commit of the series,
and the subsequent patch for writes also introduces the identical behavior in
resp_write_dt0().)

>  
> -	ret = do_device_access(sip, scp, 0, lba, num, 0, false, false);
> -	if (meta_data_locked)
> -		sdeb_meta_read_unlock(sip);
>  	if (unlikely(ret == -1))
>  		return DID_ERROR << 16;
>

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

  reply	other threads:[~2026-09-22 23:37 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22 23:26 [PATCH 0/7] scsi_debug: Enable lock context analysis Bart Van Assche
2026-09-22 23:26 ` [PATCH 1/7] scsi: scsi_debug: Fix a locking bug in resp_write_same() Bart Van Assche
2026-09-22 23:32   ` sashiko-bot
2026-09-23  7:37   ` John Garry
2026-09-23  7:44     ` John Garry
2026-09-23 19:39     ` Bart Van Assche
2026-09-22 23:26 ` [PATCH 2/7] scsi: scsi_debug: Split resp_write_same() Bart Van Assche
2026-09-22 23:38   ` sashiko-bot
2026-09-22 23:26 ` [PATCH 3/7] scsi: scsi_debug: Split corrupt_lbas() Bart Van Assche
2026-09-22 23:26 ` [PATCH 4/7] scsi: scsi_debug: Split resp_read_dt0() Bart Van Assche
2026-09-22 23:37   ` sashiko-bot [this message]
2026-09-22 23:26 ` [PATCH 5/7] scsi: scsi_debug: Split resp_write_dt0() Bart Van Assche
2026-09-22 23:41   ` sashiko-bot
2026-09-22 23:26 ` [PATCH 6/7] scsi: scsi_debug: Improve lock context annotations Bart Van Assche
2026-09-22 23:41   ` sashiko-bot
2026-09-22 23:26 ` [PATCH 7/7] 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=20260922233705.4DE7B1F000FF@smtp.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