From: Damien Le Moal <dlemoal@kernel.org>
To: Mike Christie <michael.christie@oracle.com>,
mwilck@suse.com, john.g.garry@oracle.com, bvanassche@acm.org,
hch@lst.de, martin.petersen@oracle.com,
linux-scsi@vger.kernel.org,
james.bottomley@hansenpartnership.com
Subject: Re: [PATCH v2 08/12] scsi: sd: Fix scsi_mode_sense caller's sshdr use
Date: Fri, 6 Oct 2023 10:12:33 +0900 [thread overview]
Message-ID: <83ac5491-f73d-c446-e3e2-68641ce6347c@kernel.org> (raw)
In-Reply-To: <c630ca48-7747-40a2-8c12-d1b212f07c07@oracle.com>
On 10/6/23 09:36, Mike Christie wrote:
> On 10/4/23 5:37 PM, Damien Le Moal wrote:
>> On 10/5/23 06:00, Mike Christie wrote:
>>> The sshdr passed into scsi_execute_cmd is only initialized if
>>> scsi_execute_cmd returns >= 0, and scsi_mode_sense will convert all non
>>> good statuses like check conditions to -EIO. This has scsi_mode_sense
>>> callers that were possibly accessing an uninitialized sshdrs to only
>>> access it if we got -EIO.
>>>
>>> Signed-off-by: Mike Christie <michael.christie@oracle.com>
>>> Reviewed-by: Christoph Hellwig <hch@lst.de>
>>> Reviewed-by: Martin Wilck <mwilck@suse.com>
>>> ---
>>> drivers/scsi/sd.c | 4 ++--
>>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
>>> index 6d4787ff6e96..538ebdf42c69 100644
>>> --- a/drivers/scsi/sd.c
>>> +++ b/drivers/scsi/sd.c
>>> @@ -2942,7 +2942,7 @@ sd_read_cache_type(struct scsi_disk *sdkp, unsigned char *buffer)
>>> }
>>>
>>> bad_sense:
>>> - if (scsi_sense_valid(&sshdr) &&
>>> + if (res == -EIO && scsi_sense_valid(&sshdr) &&
>>
>> if (ret < 0 && ...
>>
>> would be safer and avoid any issue if we ever change scsi_execute_cmd() to
>> return other error codes than -EIO, no ?
>
> If we do that, then we will have the same problem we have today
> where we can access the sshdr when it's not setup.
>
> If scsi_execute_cmd returns < 0, then the sshdr is not setup, so
> we shouldn't access it. The res value above is from scsi_mode_sense
> which actually does the scsi_execute_cmd call, but it doesn't always
> pass the return vale from scsi_execute_cmd directly to its callers.
>
> If there is valid sense then scsi_mode_sense returns -EIO so above
> that's why we check for that return code.
>
> As far as future safety goes, this patch is not great. Right now
> we assume scsi_execute_cmd and the functions it calls does not
> return -EIO. To make it safer we could change scsi_mode_sense to
> return 1 for the case there is sense or add another arg which
> gets set when there is sense.
Indeed, that would be better because scsi does not prevent a device from
returning sense data for successfull commands as well (see device statistics or
CDL as examples). So that would be a better solution than relying on -EIO for
sense data validity.
>
>
>
--
Damien Le Moal
Western Digital Research
next prev parent reply other threads:[~2023-10-06 1:12 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-04 21:00 [PATCH v2 00/12] scsi: sshdr and retry fixes Mike Christie
2023-10-04 21:00 ` [PATCH v2 01/12] scsi: sd: Fix sshdr use in read_capacity_16 Mike Christie
2023-10-04 21:00 ` [PATCH v2 02/12] scsi: sd: Fix sshdr use in sd_spinup_disk Mike Christie
2023-10-04 21:00 ` [PATCH v2 03/12] scsi: hp_sw: Fix sshdr use Mike Christie
2023-10-04 21:00 ` [PATCH v2 04/12] scsi: rdac: Fix send_mode_select retry handling Mike Christie
2023-10-04 21:00 ` [PATCH v2 05/12] scsi: rdac: Fix sshdr use Mike Christie
2023-10-04 21:12 ` Bart Van Assche
2023-10-04 21:00 ` [PATCH v2 06/12] scsi: spi: " Mike Christie
2023-10-04 21:00 ` [PATCH v2 07/12] scsi: sd: Fix sshdr use in sd_suspend_common Mike Christie
2023-10-04 21:15 ` Bart Van Assche
2023-10-04 21:00 ` [PATCH v2 08/12] scsi: sd: Fix scsi_mode_sense caller's sshdr use Mike Christie
2023-10-04 22:37 ` Damien Le Moal
2023-10-06 0:36 ` Mike Christie
2023-10-06 1:12 ` Damien Le Moal [this message]
2023-10-06 22:39 ` Mike Christie
2023-10-04 21:00 ` [PATCH v2 09/12] scsi: Fix sshdr use in scsi_test_unit_ready Mike Christie
2023-10-04 21:00 ` [PATCH v2 10/12] scsi: Fix sshdr use in scsi_cdl_enable Mike Christie
2023-10-04 21:00 ` [PATCH v2 11/12] scsi: sd: Fix sshdr use in cache_type_store Mike Christie
2023-10-04 21:00 ` [PATCH v2 12/12] scsi: sr: Fix sshdr use in sr_get_events Mike Christie
2023-10-13 20:54 ` [PATCH v2 00/12] scsi: sshdr and retry fixes Martin K. Petersen
2023-10-17 1:11 ` Martin K. Petersen
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=83ac5491-f73d-c446-e3e2-68641ce6347c@kernel.org \
--to=dlemoal@kernel.org \
--cc=bvanassche@acm.org \
--cc=hch@lst.de \
--cc=james.bottomley@hansenpartnership.com \
--cc=john.g.garry@oracle.com \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=michael.christie@oracle.com \
--cc=mwilck@suse.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