From: Ionut Nechita When the firmware completes a read/write with MFI_STAT_SCSI_DONE_WITH_ERROR (0x2d), a GOOD SCSI status and DataLength 0, map_cmd_status() returns DID_OK and sets the residual to the full transfer length. sd_done() then reports zero good bytes, scsi_end_request() completes nothing, and scsi_io_completion() sees result == 0 with bytes left. It requeues the command with scsi_mq_requeue_cmd(), which does not consume a retry. If the firmware keeps answering the same way, the command is resubmitted forever and every task waiting on the I/O hangs. This reproduces deterministically in a kdump kernel on an Intel S2600WFQ with a MegaRAID SAS3508 (1000:0016, 8086:9461) and two SATA SSDs exposed as JBOD. With reset_devices on the command line, the driver disables the JBOD sequence map and every 4 KiB read is completed this way, alternating between both disks about every 90 ms with no end: sd 0:0:12:0: [sda] tag#60 BRCM Debug mfi stat 0x2d, data len requested/completed 0x1000/0x0 sd 0:0:13:0: [sdb] tag#61 BRCM Debug mfi stat 0x2d, data len requested/completed 0x1000/0x0 sd 0:0:12:0: [sda] tag#62 BRCM Debug mfi stat 0x2d, data len requested/completed 0x1000/0x0 The same pattern was seen on production systems as hung tasks: INFO: task systemd-udevd:267 blocked for more than 245 seconds. INFO: task modprobe:296 blocked for more than 246 seconds. Return DID_SOFT_ERROR in that case so that scsi_decide_disposition() retries the command up to cmd->allowed times and then fails it, instead of looping. A non-GOOD status is left unchanged: it already makes the result non-zero and is handled by the midlayer, and CHECK_CONDITION keeps its sense data. Partial transfers still make progress and are not affected. The legacy MFI completion path does not set a residual, so it cannot loop and is not changed. Fixes: 31d9a57b419d ("scsi: megaraid_sas: set residual bytes count during IO completion") Cc: stable@vger.kernel.org Signed-off-by: Ionut Nechita --- Changes in v2: - Only handle the GOOD-status case. v1 matched any status other than CHECK_CONDITION and overwrote BUSY/TASK SET FULL/etc. with DID_SOFT_ERROR, although those already make the result non-zero and are retried by the midlayer. - Drop the megaraid_sas_base.c hunk. The MFI completion path never sets a residual, so it cannot hit the requeue loop. - Rate-limit the new warning and keep the existing debug print for partial transfers. - Describe the requeue mechanism and add a deterministic reproducer (kdump with reset_devices on SAS3508 + SATA JBOD). - New patch 2/2 fixes the cause of the zero-byte completions in that reproducer. drivers/scsi/megaraid/megaraid_sas_fusion.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c index 056cbe50e..2877b3829 100644 --- a/drivers/scsi/megaraid/megaraid_sas_fusion.c +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -2064,7 +2065,24 @@ map_cmd_status(struct fusion_context *fusion, resid = (scsi_bufflen(scmd) - data_length); scsi_set_resid(scmd, resid); - if (resid && + /* + * A GOOD status with nothing transferred makes the SCSI + * midlayer requeue the remaining bytes without consuming a + * retry, so the command would be resubmitted forever. Ask + * for a bounded retry instead. + */ + if (ext_status == SAM_STAT_GOOD && data_length == 0 && + scsi_bufflen(scmd)) { + static DEFINE_RATELIMIT_STATE(rs, + DEFAULT_RATELIMIT_INTERVAL, + DEFAULT_RATELIMIT_BURST); + + scmd->result = DID_SOFT_ERROR << 16; + if (__ratelimit(&rs)) + scmd_printk(KERN_WARNING, scmd, + "mfi stat 0x%x with no data transferred (requested 0x%x), retrying\n", + status, scsi_bufflen(scmd)); + } else if (resid && ((cmd_type == READ_WRITE_LDIO) || (cmd_type == READ_WRITE_SYSPDIO))) scmd_printk(KERN_INFO, scmd, "BRCM Debug mfi stat 0x%x, data len" -- 2.55.0