Skip to contentSkip to conversation

scsi: Fix command pass through retry regression

PATCH Applied Mike Christie 4 participants 5 messages Jan 7, 2025 – Jan 10, 2025 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: Fix command pass through retry regression

scsi_check_passthrough is always called, but it doesn't check for if a command completed successfully. As a result, if a command was successful and the caller used SCMD_FAILURE_RESULT_ANY to indicate what failures it wanted to retry, we will end up retrying the command. This will cause delays during device discovery because of the command being sent multiple times. For some USB devices it can also cause the wrong device size to be used.

This patch adds a check for if the command was successful. If it is we return immediately instead of trying to match a failure.

Fixes 994724e6b3f0 ("scsi: core: Allow passthrough to request midlayer retries")
---
 drivers/scsi/scsi_lib.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/scsi/scsi_lib.c +3 -0
index adee6f60c966..0cc6a0f77b09 100644
@@ -210,6 +210,9 @@ static int scsi_check_passthrough(struct scsi_cmnd *scmd,
 	struct scsi_sense_hdr sshdr;
 	enum sam_status status;
 
+	if (!scmd->result)
+		return 0;
+
 	if (!failures)
 		return 0;
 
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Mike Christie

scsi_check_passthrough is always called, but it doesn't check for if a command completed successfully. As a result, if a command was successful and the caller used SCMD_FAILURE_RESULT_ANY to indicate what failures it wanted to retry, we will end up retrying the command. This will cause delays during device discovery because of the command being sent multiple times. For some USB devices it can also cause the wrong device size to be used.

This patch adds a check for if the command was successful. If it is we return immediately instead of trying to match a failure.

Reviewed-by on v1 1/1
#2 lore raw
In reply to Mike Christie
Quoted 1 line · Mike Christie

scsi_check_passthrough is always called

...upon completion?

Quoted 1 line

, but it doesn't check for if a

doesn't properly check

Quoted 24 lines

command completed successfully. As a result, if a command was successful and the caller used SCMD_FAILURE_RESULT_ANY to indicate what failures it wanted to retry, we will end up retrying the command. This will cause delays during device discovery because of the command being sent multiple times. For some USB devices it can also cause the wrong device size to be used.

This patch adds a check for if the command was successful. If it is we return immediately instead of trying to match a failure.

---
  drivers/scsi/scsi_lib.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/scsi/scsi_lib.c +0 -0
index adee6f60c966..0cc6a0f77b09 100644

drivers/scsi/scsi_lib.c static int scsi_check_passthrough(struct scsi_cmnd *scmd, · line 213

Quoted 4 lines
drivers/scsi/scsi_lib.c +1 -0
@@ -210,6 +210,9 @@ static int scsi_check_passthrough(struct scsi_cmnd *scmd,
  	struct scsi_sense_hdr sshdr;
  	enum sam_status status;
 
+	if (!scmd->result)

this could be combined into the !failures check to have a single return, but that's personal coding preference.

drivers/scsi/scsi_lib.c static int scsi_check_passthrough(struct scsi_cmnd *scmd, · line 214

Quoted 1 line
drivers/scsi/scsi_lib.c +1 -0
+		return 0;

Would it be messy to drop the separate SCMD_FAILURE_RESULT_ANY check at the start of the for loop and include that check in the individual result status and host byte checks? In that way we would not have the separate !scmd->result check, introduced here. I guess that it would (be messy).

Regardless of comments:

#3 lore raw
In reply to Mike Christie
Quoted 9 lines · Mike Christie

scsi_check_passthrough is always called, but it doesn't check for if a command completed successfully. As a result, if a command was successful and the caller used SCMD_FAILURE_RESULT_ANY to indicate what failures it wanted to retry, we will end up retrying the command. This will cause delays during device discovery because of the command being sent multiple times. For some USB devices it can also cause the wrong device size to be used.

[...]

Applied to 6.13/scsi-fixes, thanks!

[1/1] scsi: Fix command pass through retry regression

      https://git.kernel.org/mkp/scsi/c/8604f633f593
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#4 lore raw
In reply to Mike Christie

Mike,

Quoted 4 lines

scsi_check_passthrough is always called, but it doesn't check for if a command completed successfully. As a result, if a command was successful and the caller used SCMD_FAILURE_RESULT_ANY to indicate what failures it wanted to retry, we will end up retrying the command.

Please add a suitable kunit test for this case. Thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering