* [PATCH v2 00/12] scsi: sshdr and retry fixes
@ 2023-10-04 21:00 Mike Christie
2023-10-04 21:00 ` [PATCH v2 01/12] scsi: sd: Fix sshdr use in read_capacity_16 Mike Christie
` (13 more replies)
0 siblings, 14 replies; 21+ messages in thread
From: Mike Christie @ 2023-10-04 21:00 UTC (permalink / raw)
To: mwilck, john.g.garry, bvanassche, hch, martin.petersen,
linux-scsi, james.bottomley
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.
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v2 01/12] scsi: sd: Fix sshdr use in read_capacity_16
2023-10-04 21:00 [PATCH v2 00/12] scsi: sshdr and retry fixes Mike Christie
@ 2023-10-04 21:00 ` Mike Christie
2023-10-04 21:00 ` [PATCH v2 02/12] scsi: sd: Fix sshdr use in sd_spinup_disk Mike Christie
` (12 subsequent siblings)
13 siblings, 0 replies; 21+ messages in thread
From: Mike Christie @ 2023-10-04 21:00 UTC (permalink / raw)
To: mwilck, john.g.garry, bvanassche, hch, martin.petersen,
linux-scsi, james.bottomley
Cc: Mike Christie
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.
Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Martin Wilck <mwilck@suse.com>
---
drivers/scsi/sd.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 83b6a3f3863b..0754949c9f55 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -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 &&
--
2.34.1
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v2 02/12] scsi: sd: Fix sshdr use in sd_spinup_disk
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 ` Mike Christie
2023-10-04 21:00 ` [PATCH v2 03/12] scsi: hp_sw: Fix sshdr use Mike Christie
` (11 subsequent siblings)
13 siblings, 0 replies; 21+ messages in thread
From: Mike Christie @ 2023-10-04 21:00 UTC (permalink / raw)
To: mwilck, john.g.garry, bvanassche, hch, martin.petersen,
linux-scsi, james.bottomley
Cc: Mike Christie
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.
Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Martin Wilck <mwilck@suse.com>
---
drivers/scsi/sd.c | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 0754949c9f55..6e306fe8cb5a 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -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) ||
--
2.34.1
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v2 03/12] scsi: hp_sw: Fix sshdr use
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 ` Mike Christie
2023-10-04 21:00 ` [PATCH v2 04/12] scsi: rdac: Fix send_mode_select retry handling Mike Christie
` (10 subsequent siblings)
13 siblings, 0 replies; 21+ messages in thread
From: Mike Christie @ 2023-10-04 21:00 UTC (permalink / raw)
To: mwilck, john.g.garry, bvanassche, hch, martin.petersen,
linux-scsi, james.bottomley
Cc: Mike Christie
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.
Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Martin Wilck <mwilck@suse.com>
---
drivers/scsi/device_handler/scsi_dh_hp_sw.c | 79 +++++++++++----------
1 file changed, 40 insertions(+), 39 deletions(-)
diff --git a/drivers/scsi/device_handler/scsi_dh_hp_sw.c b/drivers/scsi/device_handler/scsi_dh_hp_sw.c
index 5f2f943d926c..944ea4e0cc45 100644
--- a/drivers/scsi/device_handler/scsi_dh_hp_sw.c
+++ b/drivers/scsi/device_handler/scsi_dh_hp_sw.c
@@ -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;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v2 04/12] scsi: rdac: Fix send_mode_select retry handling
2023-10-04 21:00 [PATCH v2 00/12] scsi: sshdr and retry fixes Mike Christie
` (2 preceding siblings ...)
2023-10-04 21:00 ` [PATCH v2 03/12] scsi: hp_sw: Fix sshdr use Mike Christie
@ 2023-10-04 21:00 ` Mike Christie
2023-10-04 21:00 ` [PATCH v2 05/12] scsi: rdac: Fix sshdr use Mike Christie
` (9 subsequent siblings)
13 siblings, 0 replies; 21+ messages in thread
From: Mike Christie @ 2023-10-04 21:00 UTC (permalink / raw)
To: mwilck, john.g.garry, bvanassche, hch, martin.petersen,
linux-scsi, james.bottomley
Cc: Mike Christie
If 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.
Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: Martin Wilck <mwilck@suse.com>
---
drivers/scsi/device_handler/scsi_dh_rdac.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/scsi/device_handler/scsi_dh_rdac.c b/drivers/scsi/device_handler/scsi_dh_rdac.c
index c5538645057a..b65586d6649c 100644
--- a/drivers/scsi/device_handler/scsi_dh_rdac.c
+++ b/drivers/scsi/device_handler/scsi_dh_rdac.c
@@ -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);
--
2.34.1
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v2 05/12] scsi: rdac: Fix sshdr use
2023-10-04 21:00 [PATCH v2 00/12] scsi: sshdr and retry fixes Mike Christie
` (3 preceding siblings ...)
2023-10-04 21:00 ` [PATCH v2 04/12] scsi: rdac: Fix send_mode_select retry handling Mike Christie
@ 2023-10-04 21:00 ` Mike Christie
2023-10-04 21:12 ` Bart Van Assche
2023-10-04 21:00 ` [PATCH v2 06/12] scsi: spi: " Mike Christie
` (8 subsequent siblings)
13 siblings, 1 reply; 21+ messages in thread
From: Mike Christie @ 2023-10-04 21:00 UTC (permalink / raw)
To: mwilck, john.g.garry, bvanassche, hch, martin.petersen,
linux-scsi, james.bottomley
Cc: Mike Christie
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.
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/device_handler/scsi_dh_rdac.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/device_handler/scsi_dh_rdac.c b/drivers/scsi/device_handler/scsi_dh_rdac.c
index b65586d6649c..1ac2ae17e8be 100644
--- a/drivers/scsi/device_handler/scsi_dh_rdac.c
+++ b/drivers/scsi/device_handler/scsi_dh_rdac.c
@@ -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--)
--
2.34.1
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v2 06/12] scsi: spi: Fix sshdr use
2023-10-04 21:00 [PATCH v2 00/12] scsi: sshdr and retry fixes Mike Christie
` (4 preceding siblings ...)
2023-10-04 21:00 ` [PATCH v2 05/12] scsi: rdac: Fix sshdr use Mike Christie
@ 2023-10-04 21:00 ` Mike Christie
2023-10-04 21:00 ` [PATCH v2 07/12] scsi: sd: Fix sshdr use in sd_suspend_common Mike Christie
` (7 subsequent siblings)
13 siblings, 0 replies; 21+ messages in thread
From: Mike Christie @ 2023-10-04 21:00 UTC (permalink / raw)
To: mwilck, john.g.garry, bvanassche, hch, martin.petersen,
linux-scsi, james.bottomley
Cc: Mike Christie
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.
Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Martin Wilck <mwilck@suse.com>
---
drivers/scsi/scsi_transport_spi.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/scsi_transport_spi.c b/drivers/scsi/scsi_transport_spi.c
index 2442d4d2e3f3..f668c1c0a98f 100644
--- a/drivers/scsi/scsi_transport_spi.c
+++ b/drivers/scsi/scsi_transport_spi.c
@@ -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)
--
2.34.1
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v2 07/12] scsi: sd: Fix sshdr use in sd_suspend_common
2023-10-04 21:00 [PATCH v2 00/12] scsi: sshdr and retry fixes Mike Christie
` (5 preceding siblings ...)
2023-10-04 21:00 ` [PATCH v2 06/12] scsi: spi: " Mike Christie
@ 2023-10-04 21:00 ` 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
` (6 subsequent siblings)
13 siblings, 1 reply; 21+ messages in thread
From: Mike Christie @ 2023-10-04 21:00 UTC (permalink / raw)
To: mwilck, john.g.garry, bvanassche, hch, martin.petersen,
linux-scsi, james.bottomley
Cc: Mike Christie
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. 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.
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 | 53 ++++++++++++++++++++---------------------------
1 file changed, 23 insertions(+), 30 deletions(-)
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 6e306fe8cb5a..6d4787ff6e96 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -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)) {
--
2.34.1
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v2 08/12] scsi: sd: Fix scsi_mode_sense caller's sshdr use
2023-10-04 21:00 [PATCH v2 00/12] scsi: sshdr and retry fixes Mike Christie
` (6 preceding siblings ...)
2023-10-04 21:00 ` [PATCH v2 07/12] scsi: sd: Fix sshdr use in sd_suspend_common Mike Christie
@ 2023-10-04 21:00 ` Mike Christie
2023-10-04 22:37 ` Damien Le Moal
2023-10-04 21:00 ` [PATCH v2 09/12] scsi: Fix sshdr use in scsi_test_unit_ready Mike Christie
` (5 subsequent siblings)
13 siblings, 1 reply; 21+ messages in thread
From: Mike Christie @ 2023-10-04 21:00 UTC (permalink / raw)
To: mwilck, john.g.garry, bvanassche, hch, martin.petersen,
linux-scsi, james.bottomley
Cc: Mike Christie
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) &&
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;
--
2.34.1
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v2 09/12] scsi: Fix sshdr use in scsi_test_unit_ready
2023-10-04 21:00 [PATCH v2 00/12] scsi: sshdr and retry fixes Mike Christie
` (7 preceding siblings ...)
2023-10-04 21:00 ` [PATCH v2 08/12] scsi: sd: Fix scsi_mode_sense caller's sshdr use Mike Christie
@ 2023-10-04 21:00 ` Mike Christie
2023-10-04 21:00 ` [PATCH v2 10/12] scsi: Fix sshdr use in scsi_cdl_enable Mike Christie
` (4 subsequent siblings)
13 siblings, 0 replies; 21+ messages in thread
From: Mike Christie @ 2023-10-04 21:00 UTC (permalink / raw)
To: mwilck, john.g.garry, bvanassche, hch, martin.petersen,
linux-scsi, james.bottomley
Cc: Mike Christie
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.
Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Martin Wilck <mwilck@suse.com>
---
drivers/scsi/scsi_lib.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index c2f647a7c1b0..195ca80667d0 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -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;
--
2.34.1
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v2 10/12] scsi: Fix sshdr use in scsi_cdl_enable
2023-10-04 21:00 [PATCH v2 00/12] scsi: sshdr and retry fixes Mike Christie
` (8 preceding siblings ...)
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 ` Mike Christie
2023-10-04 21:00 ` [PATCH v2 11/12] scsi: sd: Fix sshdr use in cache_type_store Mike Christie
` (3 subsequent siblings)
13 siblings, 0 replies; 21+ messages in thread
From: Mike Christie @ 2023-10-04 21:00 UTC (permalink / raw)
To: mwilck, john.g.garry, bvanassche, hch, martin.petersen,
linux-scsi, james.bottomley
Cc: Mike Christie
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.
Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Martin Wilck <mwilck@suse.com>
---
drivers/scsi/scsi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 89367c4bf0ef..76d369343c7a 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -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;
--
2.34.1
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v2 11/12] scsi: sd: Fix sshdr use in cache_type_store
2023-10-04 21:00 [PATCH v2 00/12] scsi: sshdr and retry fixes Mike Christie
` (9 preceding siblings ...)
2023-10-04 21:00 ` [PATCH v2 10/12] scsi: Fix sshdr use in scsi_cdl_enable Mike Christie
@ 2023-10-04 21:00 ` Mike Christie
2023-10-04 21:00 ` [PATCH v2 12/12] scsi: sr: Fix sshdr use in sr_get_events Mike Christie
` (2 subsequent siblings)
13 siblings, 0 replies; 21+ messages in thread
From: Mike Christie @ 2023-10-04 21:00 UTC (permalink / raw)
To: mwilck, john.g.garry, bvanassche, hch, martin.petersen,
linux-scsi, james.bottomley
Cc: Mike Christie
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.
Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Martin Wilck <mwilck@suse.com>
---
drivers/scsi/sd.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 538ebdf42c69..8c10b99c5ec1 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -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;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v2 12/12] scsi: sr: Fix sshdr use in sr_get_events
2023-10-04 21:00 [PATCH v2 00/12] scsi: sshdr and retry fixes Mike Christie
` (10 preceding siblings ...)
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 ` 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
13 siblings, 0 replies; 21+ messages in thread
From: Mike Christie @ 2023-10-04 21:00 UTC (permalink / raw)
To: mwilck, john.g.garry, bvanassche, hch, martin.petersen,
linux-scsi, james.bottomley
Cc: Mike Christie
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.
Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Martin Wilck <mwilck@suse.com>
---
drivers/scsi/sr.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 07ef3db3d1a1..d093dd187b2f 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -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))
--
2.34.1
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH v2 05/12] scsi: rdac: Fix sshdr use
2023-10-04 21:00 ` [PATCH v2 05/12] scsi: rdac: Fix sshdr use Mike Christie
@ 2023-10-04 21:12 ` Bart Van Assche
0 siblings, 0 replies; 21+ messages in thread
From: Bart Van Assche @ 2023-10-04 21:12 UTC (permalink / raw)
To: Mike Christie, mwilck, john.g.garry, hch, martin.petersen,
linux-scsi, james.bottomley
On 10/4/23 14:00, Mike Christie wrote:
> 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.
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 07/12] scsi: sd: Fix sshdr use in sd_suspend_common
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
0 siblings, 0 replies; 21+ messages in thread
From: Bart Van Assche @ 2023-10-04 21:15 UTC (permalink / raw)
To: Mike Christie, mwilck, john.g.garry, hch, martin.petersen,
linux-scsi, james.bottomley
On 10/4/23 14:00, Mike Christie wrote:
> 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. 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.
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 08/12] scsi: sd: Fix scsi_mode_sense caller's sshdr use
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
0 siblings, 1 reply; 21+ messages in thread
From: Damien Le Moal @ 2023-10-04 22:37 UTC (permalink / raw)
To: Mike Christie, mwilck, john.g.garry, bvanassche, hch,
martin.petersen, linux-scsi, james.bottomley
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 ?
> 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;
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 08/12] scsi: sd: Fix scsi_mode_sense caller's sshdr use
2023-10-04 22:37 ` Damien Le Moal
@ 2023-10-06 0:36 ` Mike Christie
2023-10-06 1:12 ` Damien Le Moal
0 siblings, 1 reply; 21+ messages in thread
From: Mike Christie @ 2023-10-06 0:36 UTC (permalink / raw)
To: Damien Le Moal, mwilck, john.g.garry, bvanassche, hch,
martin.petersen, linux-scsi, james.bottomley
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.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 08/12] scsi: sd: Fix scsi_mode_sense caller's sshdr use
2023-10-06 0:36 ` Mike Christie
@ 2023-10-06 1:12 ` Damien Le Moal
2023-10-06 22:39 ` Mike Christie
0 siblings, 1 reply; 21+ messages in thread
From: Damien Le Moal @ 2023-10-06 1:12 UTC (permalink / raw)
To: Mike Christie, mwilck, john.g.garry, bvanassche, hch,
martin.petersen, linux-scsi, james.bottomley
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
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 08/12] scsi: sd: Fix scsi_mode_sense caller's sshdr use
2023-10-06 1:12 ` Damien Le Moal
@ 2023-10-06 22:39 ` Mike Christie
0 siblings, 0 replies; 21+ messages in thread
From: Mike Christie @ 2023-10-06 22:39 UTC (permalink / raw)
To: Damien Le Moal, mwilck, john.g.garry, bvanassche, hch,
martin.petersen, linux-scsi, james.bottomley
On 10/5/23 8:12 PM, Damien Le Moal wrote:
>> 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 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.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 00/12] scsi: sshdr and retry fixes
2023-10-04 21:00 [PATCH v2 00/12] scsi: sshdr and retry fixes Mike Christie
` (11 preceding siblings ...)
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 ` Martin K. Petersen
2023-10-17 1:11 ` Martin K. Petersen
13 siblings, 0 replies; 21+ messages in thread
From: Martin K. Petersen @ 2023-10-13 20:54 UTC (permalink / raw)
To: Mike Christie
Cc: mwilck, john.g.garry, bvanassche, hch, martin.petersen,
linux-scsi, james.bottomley
Mike,
> 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.
Applied to 6.7/scsi-staging, thanks! Patch #7 will have to wait until
-rc1.
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v2 00/12] scsi: sshdr and retry fixes
2023-10-04 21:00 [PATCH v2 00/12] scsi: sshdr and retry fixes Mike Christie
` (12 preceding siblings ...)
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
13 siblings, 0 replies; 21+ messages in thread
From: Martin K. Petersen @ 2023-10-17 1:11 UTC (permalink / raw)
To: mwilck, john.g.garry, bvanassche, hch, linux-scsi,
james.bottomley, Mike Christie
Cc: Martin K . Petersen
On Wed, 04 Oct 2023 16:00:01 -0500, Mike Christie wrote:
> 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.
>
> [...]
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
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 21+ messages in thread
end of thread, other threads:[~2023-10-17 1:12 UTC | newest]
Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox