scsi: sshdr and retry fixes
v2 cover scsi: sshdr and retry fixes
The following patches were made over Linus tree (Martin's 6.7 branch was missing some changes to sd.c). They only contain the sshdr and rdac retry fixes from the "Allow scsi_execute users to control retries" patchset.
The patches in this set are reviewed and tested but the changes to how we do retries will take a little longer and require more testing, so I broke up the series to make them easier to review.
PATCH v2 1/12 scsi: sd: Fix sshdr use in read_capacity_16
If scsi_execute_cmd returns < 0, it doesn't initialize the sshdr, so we shouldn't access the sshdr. If it returns 0, then the cmd executed successfully, so there is no need to check the sshdr. This has us access the sshdr when we get a return value > 0.
--- drivers/scsi/sd.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/scsi/sd.c +3 -4
@@ -2435,11 +2435,10 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp, the_result =scsi_execute_cmd (sdp, cmd,REQ_OP_DRV_IN , buffer,RC16_LEN ,SD_TIMEOUT , sdkp->max_retries, &exec_args); - -if (media_not_present (sdkp, &sshdr)) -return -ENODEV ; -if (the_result >0 ) { +if (media_not_present (sdkp, &sshdr)) +return -ENODEV ; + sense_valid =scsi_sense_valid (&sshdr); if (sense_valid && sshdr.sense_key == ILLEGAL_REQUEST &&
Signature · 1 line
2.34.1
PATCH v2 2/12 scsi: sd: Fix sshdr use in sd_spinup_disk
In reply to Mike ChristieIf scsi_execute_cmd returns < 0, it doesn't initialize the sshdr, so we shouldn't access the sshdr. If it returns 0, then the cmd executed successfully, so there is no need to check the sshdr. This has us access the sshdr when we get a return value > 0.
--- drivers/scsi/sd.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
drivers/scsi/sd.c +13 -11
@@ -2227,19 +2227,21 @@ sd_spinup_disk(struct scsi_disk *sdkp) sdkp->max_retries, &exec_args); -/* -* If the drive has indicated to us that it -* doesn't have any media in it, don't bother -* with any more polling. -*/ -if (media_not_present (sdkp, &sshdr)) { -if (media_was_present) -sd_printk (KERN_NOTICE , sdkp,"Media removed, stopped polling\n" ); -return ; - } +if (the_result >0 ) { +/* +* If the drive has indicated to us that it +* doesn't have any media in it, don't bother +* with any more polling. +*/ +if (media_not_present (sdkp, &sshdr)) { +if (media_was_present) +sd_printk (KERN_NOTICE , sdkp, +"Media removed, stopped polling\n" ); +return ; + } -if (the_result) sense_valid =scsi_sense_valid (&sshdr); + } retries++; } while (retries < 3 && (!scsi_status_is_good(the_result) ||
Signature · 1 line
2.34.1
PATCH v2 3/12 scsi: hp_sw: Fix sshdr use
In reply to Mike ChristieIf scsi_execute_cmd returns < 0, it doesn't initialize the sshdr, so we shouldn't access the sshdr. If it returns 0, then the cmd executed successfully, so there is no need to check the sshdr. This has us access the sshdr when we get a return value > 0.
--- drivers/scsi/device_handler/scsi_dh_hp_sw.c | 79 +++++++++++---------- 1 file changed, 40 insertions(+), 39 deletions(-)
drivers/scsi/device_handler/scsi_dh_hp_sw.c +40 -39
@@ -82,7 +82,7 @@ static int hp_sw_tur(struct scsi_device *sdev, struct hp_sw_dh_data *h) {unsigned char cmd[6 ] = {TEST_UNIT_READY };struct scsi_sense_hdr sshdr; -int ret =SCSI_DH_OK , res; +int ret, res;blk_opf_t opf =REQ_OP_DRV_IN |REQ_FAILFAST_DEV |REQ_FAILFAST_TRANSPORT |REQ_FAILFAST_DRIVER ;const struct scsi_exec_args exec_args = {
@@ -92,19 +92,18 @@ static int hp_sw_tur(struct scsi_device *sdev, struct hp_sw_dh_data *h) retry: res =scsi_execute_cmd (sdev, cmd, opf,NULL ,0 ,HP_SW_TIMEOUT ,HP_SW_RETRIES , &exec_args); -if (res) { -if (scsi_sense_valid (&sshdr)) - ret =tur_done (sdev, h, &sshdr); -else { -sdev_printk (KERN_WARNING , sdev, -"%s: sending tur failed with %x\n" , -HP_SW_NAME , res); - ret =SCSI_DH_IO ; - } - }else { +if (res >0 &&scsi_sense_valid (&sshdr)) { + ret =tur_done (sdev, h, &sshdr); + }else if (res ==0 ) { h->path_state =HP_SW_PATH_ACTIVE ; ret =SCSI_DH_OK ; + }else { +sdev_printk (KERN_WARNING , sdev, +"%s: sending tur failed with %x\n" , +HP_SW_NAME , res); + ret =SCSI_DH_IO ; } +if (ret ==SCSI_DH_IMM_RETRY ) goto retry;
@@ -122,7 +121,7 @@ static int hp_sw_start_stop(struct hp_sw_dh_data *h)unsigned char cmd[6 ] = {START_STOP ,0 ,0 ,0 ,1 ,0 };struct scsi_sense_hdr sshdr;struct scsi_device *sdev = h->sdev; -int res, rc =SCSI_DH_OK ; +int res, rc;int retry_cnt =HP_SW_RETRIES ;blk_opf_t opf =REQ_OP_DRV_IN |REQ_FAILFAST_DEV |REQ_FAILFAST_TRANSPORT |REQ_FAILFAST_DRIVER ;
@@ -133,35 +132,37 @@ static int hp_sw_start_stop(struct hp_sw_dh_data *h) retry: res =scsi_execute_cmd (sdev, cmd, opf,NULL ,0 ,HP_SW_TIMEOUT ,HP_SW_RETRIES , &exec_args); -if (res) { -if (!scsi_sense_valid (&sshdr)) { -sdev_printk (KERN_WARNING , sdev, -"%s: sending start_stop_unit failed, " -"no sense available\n" ,HP_SW_NAME ); -return SCSI_DH_IO ; - } -switch (sshdr.sense_key) { -case NOT_READY : -if (sshdr.asc ==0x04 && sshdr.ascq ==3 ) { -/* -* LUN not ready - manual intervention required -* -* Switch-over in progress, retry. -*/ -if (--retry_cnt) - goto retry; - rc =SCSI_DH_RETRY ; -break ; - } - fallthrough; -default : -sdev_printk (KERN_WARNING , sdev, -"%s: sending start_stop_unit failed, " -"sense %x/%x/%x\n" ,HP_SW_NAME , - sshdr.sense_key, sshdr.asc, sshdr.ascq); - rc =SCSI_DH_IO ; +if (!res) { +return SCSI_DH_OK ; + }else if (res <0 || !scsi_sense_valid (&sshdr)) { +sdev_printk (KERN_WARNING , sdev, +"%s: sending start_stop_unit failed, " +"no sense available\n" ,HP_SW_NAME ); +return SCSI_DH_IO ; + } + +switch (sshdr.sense_key) { +case NOT_READY : +if (sshdr.asc ==0x04 && sshdr.ascq ==3 ) { +/* +* LUN not ready - manual intervention required +* +* Switch-over in progress, retry. +*/ +if (--retry_cnt) + goto retry; + rc =SCSI_DH_RETRY ; +break ; } + fallthrough; +default : +sdev_printk (KERN_WARNING , sdev, +"%s: sending start_stop_unit failed, " +"sense %x/%x/%x\n" ,HP_SW_NAME , + sshdr.sense_key, sshdr.asc, sshdr.ascq); + rc =SCSI_DH_IO ; } +return rc; }
Signature · 1 line
2.34.1
PATCH v2 4/12 scsi: rdac: Fix send_mode_select retry handling
In reply to Mike ChristieIf send_mode_select retries scsi_execute_cmd it will leave err set to SCSI_DH_RETRY/SCSI_DH_IMM_RETRY. If on the retry, the command is successful, then SCSI_DH_RETRY/SCSI_DH_IMM_RETRY will be returned to the scsi_dh activation caller. On the retry, we will then detect the previous MODE SELECT had worked, and so we will return success.
This patch has us return the correct return value, so we can avoid the extra scsi_dh activation call and to avoid failures if the caller had hit its activation retry limit and does not end up retrying.
--- drivers/scsi/device_handler/scsi_dh_rdac.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/scsi/device_handler/scsi_dh_rdac.c +9 -9
@@ -530,7 +530,7 @@ static void send_mode_select(struct work_struct *work) container_of(work, struct rdac_controller, ms_work);struct scsi_device *sdev = ctlr->ms_sdev;struct rdac_dh_data *h = sdev->handler_data; -int err =SCSI_DH_OK , retry_cnt =RDAC_RETRY_COUNT ; +int err, retry_cnt =RDAC_RETRY_COUNT ;struct rdac_queue_data *tmp, *qdata;LIST_HEAD (list);unsigned char cdb[MAX_COMMAND_SIZE ];
@@ -558,20 +558,20 @@ static void send_mode_select(struct work_struct *work) (char *) h->ctlr->array_name, h->ctlr->index, (retry_cnt == RDAC_RETRY_COUNT) ? "queueing" : "retrying"); -if (scsi_execute_cmd (sdev, cdb, opf, &h->ctlr->mode_select, data_size, -RDAC_TIMEOUT *HZ ,RDAC_RETRIES , &exec_args)) { +if (!scsi_execute_cmd (sdev, cdb, opf, &h->ctlr->mode_select, data_size, +RDAC_TIMEOUT *HZ ,RDAC_RETRIES , &exec_args)) { + h->state =RDAC_STATE_ACTIVE ; +RDAC_LOG (RDAC_LOG_FAILOVER , sdev,"array %s, ctlr %d, " +"MODE_SELECT completed" , + (char *) h->ctlr->array_name, h->ctlr->index); + err =SCSI_DH_OK ; + }else { err =mode_select_handle_sense (sdev, &sshdr);if (err ==SCSI_DH_RETRY && retry_cnt--) goto retry;if (err ==SCSI_DH_IMM_RETRY ) goto retry; } -if (err ==SCSI_DH_OK ) { - h->state =RDAC_STATE_ACTIVE ; -RDAC_LOG (RDAC_LOG_FAILOVER , sdev,"array %s, ctlr %d, " -"MODE_SELECT completed" , - (char *) h->ctlr->array_name, h->ctlr->index); - }list_for_each_entry_safe (qdata, tmp, &list, entry) {list_del (&qdata->entry);
Signature · 1 line
2.34.1
PATCH v2 5/12 scsi: rdac: Fix sshdr use
In reply to Mike ChristieIf scsi_execute_cmd returns < 0, it doesn't initialize the sshdr, so we shouldn't access the sshdr. If it returns 0, then the cmd executed successfully, so there is no need to check the sshdr. This has us access the sshdr when we get a return value > 0.
--- drivers/scsi/device_handler/scsi_dh_rdac.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/scsi/device_handler/scsi_dh_rdac.c +6 -3
@@ -530,7 +530,7 @@ static void send_mode_select(struct work_struct *work) container_of(work, struct rdac_controller, ms_work);struct scsi_device *sdev = ctlr->ms_sdev;struct rdac_dh_data *h = sdev->handler_data; -int err, retry_cnt =RDAC_RETRY_COUNT ; +int rc, err, retry_cnt =RDAC_RETRY_COUNT ;struct rdac_queue_data *tmp, *qdata;LIST_HEAD (list);unsigned char cdb[MAX_COMMAND_SIZE ];
@@ -558,13 +558,16 @@ static void send_mode_select(struct work_struct *work) (char *) h->ctlr->array_name, h->ctlr->index, (retry_cnt == RDAC_RETRY_COUNT) ? "queueing" : "retrying"); -if (!scsi_execute_cmd (sdev, cdb, opf, &h->ctlr->mode_select, data_size, -RDAC_TIMEOUT *HZ ,RDAC_RETRIES , &exec_args)) { + rc =scsi_execute_cmd (sdev, cdb, opf, &h->ctlr->mode_select, data_size, +RDAC_TIMEOUT *HZ ,RDAC_RETRIES , &exec_args); +if (!rc) { h->state =RDAC_STATE_ACTIVE ;RDAC_LOG (RDAC_LOG_FAILOVER , sdev,"array %s, ctlr %d, " "MODE_SELECT completed" , (char *) h->ctlr->array_name, h->ctlr->index); err =SCSI_DH_OK ; + }else if (rc <0 ) { + err =SCSI_DH_IO ; }else { err =mode_select_handle_sense (sdev, &sshdr);if (err ==SCSI_DH_RETRY && retry_cnt--)
Signature · 1 line
2.34.1
Re: [PATCH v2 05/12] scsi: rdac: Fix sshdr use
Quoted 4 lines · Mike Christie
If
scsi_execute_cmdreturns < 0, it doesn't initialize the sshdr, so we shouldn't access the sshdr. If it returns 0, then the cmd executed successfully, so there is no need to check the sshdr. This has us access the sshdr when we get a return value > 0.
PATCH v2 6/12 scsi: spi: Fix sshdr use
In reply to Mike ChristieIf scsi_execute_cmd returns < 0, it doesn't initialize the sshdr, so we shouldn't access the sshdr. If it returns 0, then the cmd executed successfully, so there is no need to check the sshdr. This has us access the sshdr when we get a return value > 0.
--- drivers/scsi/scsi_transport_spi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/scsi_transport_spi.c +2 -2
@@ -676,10 +676,10 @@ spi_dv_device_echo_buffer(struct scsi_device *sdev, u8 *buffer,for (r =0 ; r < retries; r++) { result =spi_execute (sdev, spi_write_buffer,REQ_OP_DRV_OUT , buffer, len, &sshdr); -if (result || !scsi_device_online (sdev)) { +if (result || !scsi_device_online (sdev)) {scsi_device_set_state (sdev,SDEV_QUIESCE ); -if (scsi_sense_valid (&sshdr) +if (result >0 &&scsi_sense_valid (&sshdr) && sshdr.sense_key ==ILLEGAL_REQUEST /* INVALID FIELD IN CDB */ && sshdr.asc ==0x24 && sshdr.ascq ==0x00 )
Signature · 1 line
2.34.1
PATCH v2 7/12 scsi: sd: Fix sshdr use in sd_suspend_common
In reply to Mike ChristieIf scsi_execute_cmd returns < 0, it doesn't initialize the sshdr, so we shouldn't access the sshdr. If it returns 0, then the cmd executed successfully, so there is no need to check the sshdr. sd_sync_cache will only access the sshdr if it's been setup because it calls scsi_status_is_check_condition before accessing it. However, the sd_sync_cache caller, sd_suspend_common, does not check.
sd_suspend_common is only checking for ILLEGAL_REQUEST which it's using to determine if the command is supported. If it's not it just ignores the error. So to fix its sshdr use this patch just moves that check to sd_sync_cache where it converts ILLEGAL_REQUEST to success/0. sd_suspend_common was ignoring that error and sd_shutdown doesn't check for errors so there will be no behavior changes.
--- drivers/scsi/sd.c | 53 ++++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 30 deletions(-)
drivers/scsi/sd.c +23 -30
@@ -1611,24 +1611,21 @@ static unsigned int sd_check_events(struct gendisk *disk, unsigned int clearing)return disk_changed ?DISK_EVENT_MEDIA_CHANGE :0 ; } -static int sd_sync_cache (struct scsi_disk *sdkp,struct scsi_sense_hdr *sshdr) +static int sd_sync_cache (struct scsi_disk *sdkp) {int retries, res;struct scsi_device *sdp = sdkp->device;const int timeout = sdp->request_queue->rq_timeout *SD_FLUSH_TIMEOUT_MULTIPLIER ; -struct scsi_sense_hdr my_sshdr; +struct scsi_sense_hdr sshdr;const struct scsi_exec_args exec_args = { .req_flags =BLK_MQ_REQ_PM , -/* caller might not be interested in sense, but we need it */ - .sshdr = sshdr ? : &my_sshdr, + .sshdr = &sshdr, };if (!scsi_device_online (sdp))return -ENODEV ; - sshdr = exec_args.sshdr; -for (retries =3 ; retries >0 ; --retries) {unsigned char cmd[16 ] = {0 };
@@ -1653,15 +1650,23 @@ static int sd_sync_cache(struct scsi_disk *sdkp, struct scsi_sense_hdr *sshdr)return res;if (scsi_status_is_check_condition (res) && -scsi_sense_valid (sshdr)) { -sd_print_sense_hdr (sdkp, sshdr); +scsi_sense_valid (&sshdr)) { +sd_print_sense_hdr (sdkp, &sshdr);/* we need to evaluate the error return */ -if (sshdr->asc ==0x3a ||/* medium not present */ - sshdr->asc ==0x20 ||/* invalid command */ - (sshdr->asc ==0x74 && sshdr->ascq ==0x71 ))/* drive is password locked */ +if (sshdr.asc ==0x3a ||/* medium not present */ + sshdr.asc ==0x20 ||/* invalid command */ + (sshdr.asc ==0x74 && sshdr.ascq ==0x71 ))/* drive is password locked */ /* this is no error here */ return 0 ; +/* +* This drive doesn't support sync and there's not much +* we can do because this is called during shutdown +* or suspend so just return success so those operations +* can proceed. +*/ +if (sshdr.sense_key ==ILLEGAL_REQUEST ) +return 0 ; }switch (host_byte (res)) {
@@ -3817,7 +3822,7 @@ static void sd_shutdown(struct device *dev)if (sdkp->WCE && sdkp->media_present) {sd_printk (KERN_NOTICE , sdkp,"Synchronizing SCSI cache\n" ); -sd_sync_cache (sdkp,NULL ); +sd_sync_cache (sdkp); } if (system_state != SYSTEM_RESTART &&
@@ -3836,7 +3841,6 @@ static inline bool sd_do_start_stop(struct scsi_device *sdev, bool runtime)static int sd_suspend_common (struct device *dev,bool runtime) {struct scsi_disk *sdkp =dev_get_drvdata (dev); -struct scsi_sense_hdr sshdr;int ret =0 ;if (!sdkp)/* E.g.: runtime suspend following sd_remove() */
@@ -3845,24 +3849,13 @@ static int sd_suspend_common(struct device *dev, bool runtime)if (sdkp->WCE && sdkp->media_present) {if (!sdkp->device->silence_suspend)sd_printk (KERN_NOTICE , sdkp,"Synchronizing SCSI cache\n" ); - ret =sd_sync_cache (sdkp, &sshdr); - -if (ret) { -/* ignore OFFLINE device */ -if (ret == -ENODEV ) -return 0 ; - -if (!scsi_sense_valid (&sshdr) || - sshdr.sense_key !=ILLEGAL_REQUEST ) -return ret; + ret =sd_sync_cache (sdkp); +/* ignore OFFLINE device */ +if (ret == -ENODEV ) +return 0 ; -/* -* sshdr.sense_key == ILLEGAL_REQUEST means this drive -* doesn't support sync. There's not much to do and -* suspend shouldn't fail. -*/ - ret =0 ; - } +if (ret) +return ret; }if (sd_do_start_stop (sdkp->device, runtime)) {
Signature · 1 line
2.34.1
Re: [PATCH v2 07/12] scsi: sd: Fix sshdr use in sd_suspend_common
Quoted 7 lines · Mike Christie
If
scsi_execute_cmdreturns < 0, it doesn't initialize the sshdr, so we shouldn't access the sshdr. If it returns 0, then the cmd executed successfully, so there is no need to check the sshdr.sd_sync_cachewill only access the sshdr if it's been setup because it callsscsi_status_is_check_conditionbefore accessing it. However, thesd_sync_cachecaller,sd_suspend_common, does not check.
Quoted 6 lines
sd_suspend_commonis only checking forILLEGAL_REQUESTwhich it's using to determine if the command is supported. If it's not it just ignores the error. So to fix its sshdr use this patch just moves that check tosd_sync_cachewhere it convertsILLEGAL_REQUESTto success/0.sd_suspend_commonwas ignoring that error andsd_shutdowndoesn't check for errors so there will be no behavior changes.
PATCH v2 8/12 scsi: sd: Fix scsi_mode_sense caller's sshdr use
In reply to Mike ChristieThe 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.
--- drivers/scsi/sd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/sd.c +2 -2
@@ -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) && sshdr.sense_key ==ILLEGAL_REQUEST && sshdr.asc ==0x24 && sshdr.ascq ==0x0 )/* Invalid field in CDB */
@@ -2990,7 +2990,7 @@ static void sd_read_app_tag_own(struct scsi_disk *sdkp, unsigned char *buffer)sd_first_printk (KERN_WARNING , sdkp,"getting Control mode page failed, assume no ATO\n" ); -if (scsi_sense_valid (&sshdr)) +if (res == -EIO &&scsi_sense_valid (&sshdr))sd_print_sense_hdr (sdkp, &sshdr);return ;
Signature · 1 line
2.34.1
Re: [PATCH v2 08/12] scsi: sd: Fix scsi_mode_sense caller's sshdr use
Quoted 18 lines · Mike Christie
The sshdr passed into
scsi_execute_cmdis only initialized ifscsi_execute_cmdreturns >= 0, andscsi_mode_sensewill convert all non good statuses like check conditions to-EIO. This hasscsi_mode_sensecallers that were possibly accessing an uninitialized sshdrs to only access it if we got-EIO.Signed-off-by Mike Christie <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Reviewed-by Martin Wilck <[email protected]>--- drivers/scsi/sd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/scsi/sd.c +0
-0
drivers/scsi/sd.c sd_read_cache_type(struct scsi_disk *sdkp, unsigned char *buffer) · line 2945
Quoted 5 lines
drivers/scsi/sd.c +1
-1@@ -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 ?
Quoted 12 lines
drivers/scsi/sd.c +1
-1sshdr.sense_key ==ILLEGAL_REQUEST && sshdr.asc == 0x24 && sshdr.ascq == 0x0)/* Invalid field in CDB */ @@ -2990,7 +2990,7 @@ static void sd_read_app_tag_own(struct scsi_disk *sdkp, unsigned char *buffer)sd_first_printk (KERN_WARNING , sdkp,"getting Control mode page failed, assume no ATO\n" ); -if (scsi_sense_valid (&sshdr)) +if (res == -EIO &&scsi_sense_valid (&sshdr))sd_print_sense_hdr (sdkp, &sshdr);return ;
Signature · 2 lines
Damien Le Moal Western Digital Research
Re: [PATCH v2 08/12] scsi: sd: Fix scsi_mode_sense caller's sshdr use
Quoted 21 lines · Damien Le Moal
Quoted 20 lines · Mike Christie
The sshdr passed into
scsi_execute_cmdis only initialized ifscsi_execute_cmdreturns >= 0, andscsi_mode_sensewill convert all non good statuses like check conditions to-EIO. This hasscsi_mode_sensecallers that were possibly accessing an uninitialized sshdrs to only access it if we got-EIO.Signed-off-by Mike Christie <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Reviewed-by Martin Wilck <[email protected]>--- drivers/scsi/sd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/scsi/sd.c +0
-0@@ -2942,7 +2942,7 @@ sd_read_cache_type(struct scsi_disk *sdkp, unsigned char *buffer) }
Quoted 8 lines
drivers/scsi/sd.c sd_read_cache_type(struct scsi_disk *sdkp, unsigned char *buffer) · line 2945
Quoted 3 lines
drivers/scsi/sd.c +1
-1bad_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.
Re: [PATCH v2 08/12] scsi: sd: Fix scsi_mode_sense caller's sshdr use
Quoted 39 lines · Mike Christie
Quoted 21 lines · Damien Le Moal
Quoted 20 lines · Mike Christie
The sshdr passed into
scsi_execute_cmdis only initialized ifscsi_execute_cmdreturns >= 0, andscsi_mode_sensewill convert all non good statuses like check conditions to-EIO. This hasscsi_mode_sensecallers that were possibly accessing an uninitialized sshdrs to only access it if we got-EIO.Signed-off-by Mike Christie <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Reviewed-by Martin Wilck <[email protected]>--- drivers/scsi/sd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/scsi/sd.c +0
-0@@ -2942,7 +2942,7 @@ sd_read_cache_type(struct scsi_disk *sdkp, unsigned char *buffer) }Quoted 8 lines
drivers/scsi/sd.c sd_read_cache_type(struct scsi_disk *sdkp, unsigned char *buffer) · line 2945
Quoted 3 lines
drivers/scsi/sd.c +1
-1bad_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_cmdreturns < 0, then the sshdr is not setup, so we shouldn't access it. The res value above is fromscsi_mode_sensewhich actually does thescsi_execute_cmdcall, but it doesn't always pass the return vale fromscsi_execute_cmddirectly to its callers.
Quoted 8 lines
If there is valid sense then
scsi_mode_sensereturns-EIOso 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_cmdand the functions it calls does not return-EIO. To make it safer we could changescsi_mode_senseto 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.
Quoted 3 lines
Signature · 2 lines
Damien Le Moal Western Digital Research
Re: [PATCH v2 08/12] scsi: sd: Fix scsi_mode_sense caller's sshdr use
Quoted 9 lines · Damien Le Moal
Quoted 5 lines
As far as future safety goes, this patch is not great. Right now we assume
scsi_execute_cmdand the functions it calls does not return-EIO. To make it safer we could changescsi_mode_senseto 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
-EIOfor sense data validi
For the sd_read_app_tag_own case and similar ones are you wanting to log the sense for cases like the CDL where scsi_execute_cmd returns 0?
The thing is that this patches uses -EIO to indicate if the sshdr is setup (not exactly that sense is valid). If it is then we check if the sense is valid and if is then sd_read_app_tag_own will log it.
In other places we do something similar and check if scsi_execute_cmd returns > 0. If it does then we know the sshdr is setup and will do something with it like print it. Those cases will not work for your CDL example because scsi_execute_cmd returns 0.
PATCH v2 9/12 scsi: Fix sshdr use in scsi_test_unit_ready
In reply to Mike ChristieIf scsi_execute_cmd returns < 0, it doesn't initialize the sshdr, so we shouldn't access the sshdr. If it returns 0, then the cmd executed successfully, so there is no need to check the sshdr. This has us access the sshdr when we get a return value > 0.
--- drivers/scsi/scsi_lib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/scsi_lib.c +2 -2
@@ -2299,10 +2299,10 @@ scsi_test_unit_ready(struct scsi_device *sdev, int timeout, int retries,do { result =scsi_execute_cmd (sdev, cmd,REQ_OP_DRV_IN ,NULL ,0 , timeout,1 , &exec_args); -if (sdev->removable &&scsi_sense_valid (sshdr) && +if (sdev->removable && result >0 &&scsi_sense_valid (sshdr) && sshdr->sense_key ==UNIT_ATTENTION ) sdev->changed =1 ; - }while (scsi_sense_valid (sshdr) && + }while (result >0 &&scsi_sense_valid (sshdr) && sshdr->sense_key ==UNIT_ATTENTION && --retries);return result;
Signature · 1 line
2.34.1
PATCH v2 10/12 scsi: Fix sshdr use in scsi_cdl_enable
In reply to Mike ChristieIf scsi_execute_cmd returns < 0, it doesn't initialize the sshdr, so we shouldn't access the sshdr. If it returns 0, then the cmd executed successfully, so there is no need to check the sshdr. This has us access the sshdr when we get a return value > 0.
--- drivers/scsi/scsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/scsi.c +1 -1
@@ -703,7 +703,7 @@ int scsi_cdl_enable(struct scsi_device *sdev, bool enable) ret =scsi_mode_select (sdev,1 ,0 , buf_data, len,5 *HZ ,3 , &data, &sshdr);if (ret) { -if (scsi_sense_valid (&sshdr)) +if (ret >0 &&scsi_sense_valid (&sshdr))scsi_print_sense_hdr (sdev,dev_name (&sdev->sdev_gendev), &sshdr);return ret;
Signature · 1 line
2.34.1
PATCH v2 11/12 scsi: sd: Fix sshdr use in cache_type_store
In reply to Mike ChristieIf scsi_execute_cmd returns < 0, it doesn't initialize the sshdr, so we shouldn't access the sshdr. If it returns 0, then the cmd executed successfully, so there is no need to check the sshdr. This has us access the sshdr when we get a return value > 0.
--- drivers/scsi/sd.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/scsi/sd.c +5 -4
@@ -143,7 +143,7 @@ cache_type_store(struct device *dev, struct device_attribute *attr,struct scsi_mode_data data;struct scsi_sense_hdr sshdr;static const char temp[] ="temporary " ; -int len; +int len, ret;if (sdp->type !=TYPE_DISK && sdp->type !=TYPE_ZBC )/* no cache control on RBC devices; theoretically they
@@ -190,9 +190,10 @@ cache_type_store(struct device *dev, struct device_attribute *attr,*/ data.device_specific =0 ; -if (scsi_mode_select (sdp,1 , sp, buffer_data, len,SD_TIMEOUT , - sdkp->max_retries, &data, &sshdr)) { -if (scsi_sense_valid (&sshdr)) + ret =scsi_mode_select (sdp,1 , sp, buffer_data, len,SD_TIMEOUT , + sdkp->max_retries, &data, &sshdr); +if (ret) { +if (ret >0 &&scsi_sense_valid (&sshdr))sd_print_sense_hdr (sdkp, &sshdr);return -EINVAL ; }
Signature · 1 line
2.34.1
PATCH v2 12/12 scsi: sr: Fix sshdr use in sr_get_events
In reply to Mike ChristieIf scsi_execute_cmd returns < 0, it doesn't initialize the sshdr, so we shouldn't access the sshdr. If it returns 0, then the cmd executed successfully, so there is no need to check the sshdr. This has us access the sshdr when we get a return value > 0.
--- drivers/scsi/sr.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/scsi/sr.c +2 -1
@@ -177,7 +177,8 @@ static unsigned int sr_get_events(struct scsi_device *sdev) result =scsi_execute_cmd (sdev, cmd,REQ_OP_DRV_IN , buf,sizeof (buf),SR_TIMEOUT ,MAX_RETRIES , &exec_args); -if (scsi_sense_valid (&sshdr) && sshdr.sense_key ==UNIT_ATTENTION ) +if (result >0 &&scsi_sense_valid (&sshdr) && + sshdr.sense_key ==UNIT_ATTENTION )return DISK_EVENT_MEDIA_CHANGE ;if (result ||be16_to_cpu (eh->data_len) <sizeof (*med))
Signature · 1 line
2.34.1
Martin K. Petersen
AppliedMike,
Quoted 8 lines
The following patches were made over Linus tree (Martin's 6.7 branch was missing some changes to
sd.c). They only contain the sshdr and rdac retry fixes from the "Allowscsi_executeusers to control retries" patchset.The patches in this set are reviewed and tested but the changes to how we do retries will take a little longer and require more testing, so I broke up the series to make them easier to review.
Applied to 6.7/scsi-staging, thanks! Patch #7 will have to wait until -rc1.
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Martin K. Petersen
AppliedQuoted 10 lines · Mike Christie
The following patches were made over Linus tree (Martin's 6.7 branch was missing some changes to
sd.c). They only contain the sshdr and rdac retry fixes from the "Allowscsi_executeusers to control retries" patchset.The patches in this set are reviewed and tested but the changes to how we do retries will take a little longer and require more testing, so I broke up the series to make them easier to review.
[...]
Applied to 6.7/scsi-queue, thanks!
[01/12] scsi: sd: Fix sshdr use in read_capacity_16
https://git.kernel.org/mkp/scsi/c/bd593bd2c1e6 [02/12] scsi: sd: Fix sshdr use in sd_spinup_disk https://git.kernel.org/mkp/scsi/c/b4d0c33a32c3 [03/12] scsi: hp_sw: Fix sshdr use https://git.kernel.org/mkp/scsi/c/5759a5650d45 [04/12] scsi: rdac: Fix send_mode_select retry handling https://git.kernel.org/mkp/scsi/c/2274bd5e3a2c [05/12] scsi: rdac: Fix sshdr use https://git.kernel.org/mkp/scsi/c/87e145a29363 [06/12] scsi: spi: Fix sshdr use https://git.kernel.org/mkp/scsi/c/0b149cee836a [07/12] scsi: sd: Fix sshdr use in sd_suspend_common (no commit info) [08/12] scsi: sd: Fix scsi_mode_sense caller's sshdr use https://git.kernel.org/mkp/scsi/c/add2c24d32a3 [09/12] scsi: Fix sshdr use in scsi_test_unit_ready https://git.kernel.org/mkp/scsi/c/f43158eefd65 [10/12] scsi: Fix sshdr use in scsi_cdl_enable https://git.kernel.org/mkp/scsi/c/8f0017694c54 [11/12] scsi: sd: Fix sshdr use in cache_type_store https://git.kernel.org/mkp/scsi/c/c8b7ef36da03 [12/12] scsi: sr: Fix sshdr use in sr_get_events https://git.kernel.org/mkp/scsi/c/f7d7129c6c24
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering