Skip to contentSkip to conversation

Fix system resume for SCSI devices

PATCH Superseded Bart Van Assche 2 participants 5 messages Aug 7, 2024 – Aug 9, 2024 SCSI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Fix system resume for SCSI devices

Hi Martin,

This patch series fixes a particular type of system resume failure for SCSI devices. Please consider this patch series for the next merge window.

Thanks,

Bart.

Bart Van Assche (2):
scsi: core: Retry passthrough commands if SCMD_RETRY_PASST_ON_UA is
set
sd: Retry START STOP UNIT commands in case of a unit attention

 drivers/scsi/scsi_error.c | 5 ++++-
 drivers/scsi/sd.c         | 1 +
 include/scsi/scsi_cmnd.h  | 5 ++++-
 3 files changed, 9 insertions(+), 2 deletions(-)
#1 lore raw

PATCH 1/2 scsi: core: Retry passthrough commands if SCMD_RETRY_PASST_ON_UA is set

The SCSI core does not retry passthrough commands even if the SCSI device reports a retryable unit attention condition. Support retrying in this case by introducing the SCMD_RETRY_PASST_ON_UA flag.

Cc Damien Le Moal <[email protected]>
Cc Mike Christie <[email protected]>
---
 drivers/scsi/scsi_error.c | 5 ++++-
 include/scsi/scsi_cmnd.h  | 5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)
drivers/scsi/scsi_error.c +4 -1
index 612489afe8d2..38e3ea85e381 100644
@@ -1855,7 +1855,10 @@ bool scsi_noretry_cmd(struct scsi_cmnd *scmd)
 	 * assume caller has checked sense and determined
 	 * the check condition was retryable.
 	 */
-	if (req->cmd_flags & REQ_FAILFAST_DEV || blk_rq_is_passthrough(req))
+	if (req->cmd_flags & REQ_FAILFAST_DEV)
+		return true;
+	if (blk_rq_is_passthrough(req) &&
+	    !(scmd->flags & SCMD_RETRY_PASST_ON_UA))
 		return true;
 
 	return false;
include/scsi/scsi_cmnd.h +4 -1
index 45c40d200154..43c584fbeaca 100644
@@ -58,8 +58,11 @@ struct scsi_pointer {
  */
 #define SCMD_FORCE_EH_SUCCESS	(1 << 3)
 #define SCMD_FAIL_IF_RECOVERING	(1 << 4)
+/* If set, retry a passthrough command in case of a unit attention. */
+#define SCMD_RETRY_PASST_ON_UA	(1 << 5)
 /* flags preserved across unprep / reprep */
-#define SCMD_PRESERVED_FLAGS	(SCMD_INITIALIZED | SCMD_FAIL_IF_RECOVERING)
+#define SCMD_PRESERVED_FLAGS	\
+	(SCMD_INITIALIZED | SCMD_FAIL_IF_RECOVERING | SCMD_RETRY_PASST_ON_UA)
 
 /* for scmd->state */
 #define SCMD_STATE_COMPLETE	0
#2 lore raw

Re: [PATCH 1/2] scsi: core: Retry passthrough commands if SCMD_RETRY_PASST_ON_UA is set

Quoted 3 lines · Bart Van Assche

The SCSI core does not retry passthrough commands even if the SCSI device reports a retryable unit attention condition. Support retrying in this case by introducing the SCMD_RETRY_PASST_ON_UA flag.

This flag is badly named since nowhere it is checked that the retry happens on UNIT ATTENTION. The retry may happen with other sense key as well, no ?

So what about simply calling this: SCMD_RETRY_PASSTHROUGH ?

Quoted 43 lines
Cc Damien Le Moal <[email protected]>
Cc Mike Christie <[email protected]>
---
 drivers/scsi/scsi_error.c | 5 ++++-
 include/scsi/scsi_cmnd.h  | 5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)
drivers/scsi/scsi_error.c +4 -1
index 612489afe8d2..38e3ea85e381 100644
@@ -1855,7 +1855,10 @@ bool scsi_noretry_cmd(struct scsi_cmnd *scmd)
 	 * assume caller has checked sense and determined
 	 * the check condition was retryable.
 	 */
-	if (req->cmd_flags & REQ_FAILFAST_DEV || blk_rq_is_passthrough(req))
+	if (req->cmd_flags & REQ_FAILFAST_DEV)
+		return true;
+	if (blk_rq_is_passthrough(req) &&
+	    !(scmd->flags & SCMD_RETRY_PASST_ON_UA))
 		return true;
 
 	return false;
include/scsi/scsi_cmnd.h +4 -1
index 45c40d200154..43c584fbeaca 100644
@@ -58,8 +58,11 @@ struct scsi_pointer {
  */
 #define SCMD_FORCE_EH_SUCCESS	(1 << 3)
 #define SCMD_FAIL_IF_RECOVERING	(1 << 4)
+/* If set, retry a passthrough command in case of a unit attention. */
+#define SCMD_RETRY_PASST_ON_UA	(1 << 5)
 /* flags preserved across unprep / reprep */
-#define SCMD_PRESERVED_FLAGS	(SCMD_INITIALIZED | SCMD_FAIL_IF_RECOVERING)
+#define SCMD_PRESERVED_FLAGS	\
+	(SCMD_INITIALIZED | SCMD_FAIL_IF_RECOVERING | SCMD_RETRY_PASST_ON_UA)
 
 /* for scmd->state */
 #define SCMD_STATE_COMPLETE	0
Signature · 2 lines
Damien Le Moal
Western Digital Research
#3 lore raw

Re: [PATCH 1/2] scsi: core: Retry passthrough commands if SCMD_RETRY_PASST_ON_UA is set

Quoted 9 lines · Damien Le Moal
Quoted 3 lines · Bart Van Assche

The SCSI core does not retry passthrough commands even if the SCSI device reports a retryable unit attention condition. Support retrying in this case by introducing the SCMD_RETRY_PASST_ON_UA flag.

This flag is badly named since nowhere it is checked that the retry happens on UNIT ATTENTION. The retry may happen with other sense key as well, no ?

So what about simply calling this: SCMD_RETRY_PASSTHROUGH ?

That sounds good to me. See also v2 of this patch series.

Thanks,

Bart.

#4 lore raw

PATCH 2/2 sd: Retry START STOP UNIT commands in case of a unit attention

In reply to Bart Van Assche

During system resume, sd_start_stop_device() submits a START STOP UNIT command to the SCSI device that is being resumed. That command is not retried in case of a unit attention and hence may fail. An example:

[16575.983359] sd 0:0:0:3: [sdd] Starting disk
[16575.983693] sd 0:0:0:3: [sdd] Start/Stop Unit failed: Result: hostbyte=0x00 driverbyte=DRIVER_OK
[16575.983712] sd 0:0:0:3: [sdd] Sense Key : 0x6
[16575.983730] sd 0:0:0:3: [sdd] ASC=0x29 ASCQ=0x0
[16575.983738] sd 0:0:0:3: PM: dpm_run_callback(): scsi_bus_resume+0x0/0xa0 returns -5
[16575.983783] sd 0:0:0:3: PM: failed to resume async: error -5

Make the SCSI core retry the START STOP UNIT command if the device reports a unit attention.

Cc Damien Le Moal <[email protected]>
Cc Mike Christie <[email protected]>
---
 drivers/scsi/sd.c | 1 +
 1 file changed, 1 insertion(+)
drivers/scsi/sd.c +1 -0
index 718eb91ba9a5..1b6996b48c8b 100644
@@ -4093,6 +4093,7 @@ static int sd_start_stop_device(struct scsi_disk *sdkp, int start)
 	const struct scsi_exec_args exec_args = {
 		.sshdr = &sshdr,
 		.req_flags = BLK_MQ_REQ_PM,
+		.scmd_flags = SCMD_RETRY_PASST_ON_UA,
 	};
 	struct scsi_device *sdp = sdkp->device;
 	int res;