Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: Damien Le Moal <dlemoal@kernel.org>
To: Niklas Cassel <cassel@kernel.org>
Cc: "James E.J. Bottomley" <James.Bottomley@hansenpartnership.com>,
	"Martin K. Petersen" <mkp@kernel.org>,
	linux-scsi@vger.kernel.org, John Garry <john.garry@linux.dev>
Subject: Re: [PATCH v9 05/11] scsi: scsi_debug: Report the residual of a write
Date: Mon, 28 Sep 2026 09:51:19 +0200	[thread overview]
Message-ID: <ef31de9c-a138-42ea-943d-979ee3a64919@kernel.org> (raw)
In-Reply-To: <aroT_W6PzdiUeUBd@ryzen>

On 2026/09/28 9:15, Niklas Cassel wrote:
> On Mon, Sep 28, 2026 at 08:45:30AM +0200, Damien Le Moal wrote:
>> On 2026/09/27 7:26, Niklas Cassel wrote:
>>> A write whose data buffer is larger than its transfer length leaves a
>>> residual that the initiator is entitled to be told about. resp_read_dt0()
>>> and resp_write_tape() report it, but the write paths for a disk do not,
>>> so such a write completes with GOOD status and a residual of zero while
>>> a READ of the same length into the same buffer reports it correctly.
>>
>> I am not convinced this is correct. resid (residual count) is supposed to
>> indicate the amount of data that was *not* transferred. So if the buffer size is
>> larger that the command cdb transfer count, all data can be transferred and
>> resid should be 0. Which would mean that for this case, the write processing is
>> correct but the read side is not.
>>
>> The SBC and SPC specs are very silent about this though, I do not think that the
>> resid is actually standardized. And I do not see a clear definition for it in
>> the documentation/code comments.
> 
> The definition is in Documentation/scsi/scsi_mid_low_api.rst,
> under resid_len: "an LLD should set this unsigned integer to the requested
> transfer length (i.e. 'request_bufflen') less the number of bytes that are
> actually transferred".
> 
> Also in include/scsi/sg.h: "resid; /* [o] dxfer_len - actual_transferred */".
> 
> Both measure it against the buffer, not the CDB.
> 
> That is also what iSCSI reports: RFC 7143 11.4.5.1 measures the residual
> against the Expected Data Transfer Length, which the initiator sets from the
> buffer.
> 
> And it is what scsi_debug has always done for reads, in fill_from_dev_buffer().
> This patch just does the same for writes.

Hmm. OK. But then that really should be set automatically by the sd/st/sr
drivers and sg driver. scsi_debug emulates a device, which does not give the
residual. So scsi_debug has no business setting that command residual at all,
for any command.

> 
> 
> Let me clarify the commit message in v10 to actually reference
> Documentation/scsi/scsi_mid_low_api.rst.
> 
> 
> Kind regards,
> Niklas


-- 
Damien Le Moal
Western Digital Research

  reply	other threads:[~2026-09-28  7:51 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-27  5:26 [PATCH v9 00/11] scsi: scsi_debug: fix zoned write validation Niklas Cassel
2026-09-27  5:26 ` [PATCH v9 01/11] scsi: scsi_debug: Refuse a zoned device with a non-zero lowest aligned LBA Niklas Cassel
2026-09-27  5:26 ` [PATCH v9 02/11] scsi: scsi_debug: Make atomic writes and ZBC emulation mutually exclusive Niklas Cassel
2026-09-27  5:26 ` [PATCH v9 03/11] scsi: scsi_debug: Take the zone metadata lock before the data lock Niklas Cassel
2026-09-27  5:26 ` [PATCH v9 04/11] scsi: scsi_debug: Evaluate scsi_debug_lbp() only once Niklas Cassel
2026-09-27  5:26 ` [PATCH v9 05/11] scsi: scsi_debug: Report the residual of a write Niklas Cassel
2026-09-27  5:40   ` sashiko-bot
2026-09-27  7:01     ` Niklas Cassel
2026-09-28  6:45   ` Damien Le Moal
2026-09-28  7:15     ` Niklas Cassel
2026-09-28  7:51       ` Damien Le Moal [this message]
2026-09-28  8:15         ` Damien Le Moal
2026-09-27  5:26 ` [PATCH v9 06/11] scsi: scsi_debug: Enforce physical block alignment of zoned writes Niklas Cassel
2026-09-27  5:26 ` [PATCH v9 07/11] scsi: scsi_debug: Do not write a partial physical block to a zoned device Niklas Cassel
2026-09-27  5:26 ` [PATCH v9 08/11] scsi: scsi_debug: Advance the write pointer over the data written Niklas Cassel
2026-09-27  5:27 ` [PATCH v9 09/11] scsi: scsi_debug: Refuse a short WRITE ATOMIC (16) before writing it Niklas Cassel
2026-09-27  5:27 ` [PATCH v9 10/11] scsi: scsi_debug: Map the region written by WRITE ATOMIC (16) Niklas Cassel
2026-09-27  5:27 ` [PATCH v9 11/11] scsi: scsi_debug: Validate the access parameters of " Niklas Cassel

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=ef31de9c-a138-42ea-943d-979ee3a64919@kernel.org \
    --to=dlemoal@kernel.org \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=cassel@kernel.org \
    --cc=john.garry@linux.dev \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mkp@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