From: Douglas Gilbert <dgilbert@interlog.com>
To: Damien Le Moal <Damien.LeMoal@wdc.com>,
Bart Van Assche <bvanassche@acm.org>,
"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
"Martin K . Petersen" <martin.petersen@oracle.com>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"usb-storage@lists.one-eyed-alien.net"
<usb-storage@lists.one-eyed-alien.net>,
Alan Stern <stern@rowland.harvard.edu>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Justin Piszcz <jpiszcz@lucidpixels.com>
Subject: Re: [PATCH] scsi: Fix scsi_get/set_resid() interface
Date: Tue, 29 Oct 2019 13:59:58 -0400 [thread overview]
Message-ID: <4eb733b9-8f52-a6c2-eb56-f0759113dc1e@interlog.com> (raw)
In-Reply-To: <BYAPR04MB5816FF25422E60C168F78308E7610@BYAPR04MB5816.namprd04.prod.outlook.com>
On 2019-10-29 4:17 a.m., Damien Le Moal wrote:
> Bart,
>
> On 2019/10/28 21:38, Bart Van Assche wrote:
>> On 10/28/19 3:57 AM, Damien Le Moal wrote:
>>> struct scsi_cmnd cmd->req.resid_len which is returned and set
>>> respectively by the helper functions scsi_get_resid() and
>>> scsi_set_resid() is an unsigned int. Reflect this fact in the interface
>>> of these helper functions.
>>> [ ... ]
>>> -static inline void scsi_set_resid(struct scsi_cmnd *cmd, int resid)
>>> +static inline void scsi_set_resid(struct scsi_cmnd *cmd, unsigned int resid)
>>> {
>>> cmd->req.resid_len = resid;
>>> }
>>>
>>> -static inline int scsi_get_resid(struct scsi_cmnd *cmd)
>>> +static inline unsigned int scsi_get_resid(struct scsi_cmnd *cmd)
>>> {
>>> return cmd->req.resid_len;
>>> }
>>
>> From the iSCSI RFC:
>>
>> SCSI-Presented Data Transfer Length (SPDTL) is the term this document
>> uses (see Section 1.1 for definition) to represent the aggregate data
>> length that the target SCSI layer attempts to transfer using the
>> local iSCSI layer for a task. Expected Data Transfer Length (EDTL)
>> is the iSCSI term that represents the length of data that the iSCSI
>> layer expects to transfer for a task. EDTL is specified in the SCSI
>> Command PDU.
>>
>> When SPDTL = EDTL for a task, the target iSCSI layer completes the
>> task with no residuals. Whenever SPDTL differs from EDTL for a task,
>> that task is said to have a residual.
>>
>> If SPDTL > EDTL for a task, iSCSI Overflow MUST be signaled in the
>> SCSI Response PDU as specified in [RFC3720]. The Residual Count MUST
>> be set to the numerical value of (SPDTL - EDTL).
>>
>> If SPDTL < EDTL for a task, iSCSI Underflow MUST be signaled in the
>> SCSI Response PDU as specified in [RFC3720]. The Residual Count MUST
>> be set to the numerical value of (EDTL - SPDTL).
>>
>> Note that the Overflow and Underflow scenarios are independent of
>> Data-In and Data-Out. Either scenario is logically possible in
>> either direction of data transfer.
>>
>> If the residual is changed from signed into unsigned, how is a SCSI LLD
>> expected to report the difference between residual overflow and residual
>> underflow to the SCSI core?
> As mentioned in the commit message, cmd->req.resid_len where the resid
> is stored is an unsigned int. And it has been an unsigned int forever as
> far as I know.
If my memory serves, I put it in over 20 years ago, about the same time
as the sg v2 interface (struct sg_io_hdr) was implemented. And when I
put it in it was a (signed) int and this is why:
struct ccb_accept_targ3 {
.....
CAM_I32 cam_resid; /* Transfer residual length: 2's comp */
.....
};
[from cam3r03.pdf]
So it coped with both underflow and the less likely case of overflow.
Notice in:
struct sg_io_hdr {
.....
int resid; /* [o] dxfer_len - actual_transferred */
...
};
At the time the SCSI mid-level and the block layer didn't bother about
resid, only some LLDs which is where the sg driver picked it up from.
So some ignoramus changed it to unsigned since then, probably before
git strangled the kernel source tree.
> So I think changing the interface to unsigned int makes sense in that
> context. Also, unless I am reading this wrong, the above definition you
> quote always lead to resid >= 0, so I do not see what problem you are
> worried about. Could you elaborate your concerns please ?
Linux's internal representation is wrong and should be fixed to match
its exposed interface (struct sg_io_hdr) which predates the breakage.
Doug Gilbert
next prev parent reply other threads:[~2019-10-29 18:00 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-28 10:57 [PATCH] scsi: Fix scsi_get/set_resid() interface Damien Le Moal
2019-10-28 20:38 ` Bart Van Assche
2019-10-29 8:17 ` Damien Le Moal
2019-10-29 15:14 ` Bart Van Assche
2019-10-29 17:59 ` Douglas Gilbert [this message]
2019-10-30 1:00 ` Bart Van Assche
2019-10-30 8:30 ` Hannes Reinecke
2019-10-30 15:12 ` Bart Van Assche
2019-10-30 15:18 ` Hannes Reinecke
2019-10-30 15:24 ` Bart Van Assche
2019-10-30 16:18 ` Douglas Gilbert
2019-10-31 7:51 ` Hannes Reinecke
2019-10-31 8:28 ` Hannes Reinecke
2019-10-30 1:07 ` kbuild test robot
2019-10-30 22:56 ` kbuild test robot
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=4eb733b9-8f52-a6c2-eb56-f0759113dc1e@interlog.com \
--to=dgilbert@interlog.com \
--cc=Damien.LeMoal@wdc.com \
--cc=bvanassche@acm.org \
--cc=gregkh@linuxfoundation.org \
--cc=jpiszcz@lucidpixels.com \
--cc=linux-scsi@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=stern@rowland.harvard.edu \
--cc=usb-storage@lists.one-eyed-alien.net \
/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