]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
scsi: libsas: terminate deferred commands on time out
authorDamien Le Moal <dlemoal@kernel.org>
Thu, 9 Jul 2026 07:02:23 +0000 (16:02 +0900)
committerDamien Le Moal <dlemoal@kernel.org>
Wed, 29 Jul 2026 01:52:04 +0000 (10:52 +0900)
If a command times out while we have deferred non-NCQ commands waiting to
be issued, the SCSI EH task is not immediately woken up as the waiting
deferred commands are never issued nor completed, thus leaving the SCSI
host in a busy state (shost->host_failed != scsi_host_busy(shost)) which
prevents the SCSI EH task from being woken up. Eventually, when the
deferred commands also time out, the SCSI EH task is woken up and the
timeout processing occurs.

Avoid this unnecessary additional SCSI EH wake up time with the same
method as implemented in libata-scsi, using the eh_timed_out SCSI host
template operation. The function sas_eh_timed_out() implements this
operation and executes the function ata_scsi_retry_deferred_qc()
for SATA devices.

Co-developed-by: Igor Pylypiv <ipylypiv@google.com>
Signed-off-by: Igor Pylypiv <ipylypiv@google.com>
Fixes: 0ea84089dbf6 ("ata: libata-scsi: avoid Non-NCQ command starvation")
Cc: stable@vger.kernel.org
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Hannes Reinecke <hare@kernel.org>
Tested-by: Igor Pylypiv <ipylypiv@google.com>
Reviewed-by: Niklas Cassel <cassel@kernel.org>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/ata/libata-scsi.c
drivers/scsi/libsas/sas_scsi_host.c
include/linux/libata.h
include/scsi/libsas.h

index cd64787c47728bca4463291e953d680f5069d159..d2160ee7ca7d4b38dced0dc207c477b2de157067 100644 (file)
@@ -1784,8 +1784,8 @@ static void ata_scsi_schedule_deferred_qc(struct ata_link *link)
                queue_work(system_highpri_wq, &link->deferred_qc_work);
 }
 
-static enum scsi_timeout_action
-ata_scsi_retry_deferred_qc(struct ata_port *ap, struct scsi_cmnd *scmd)
+enum scsi_timeout_action ata_scsi_retry_deferred_qc(struct ata_port *ap,
+                                                   struct scsi_cmnd *scmd)
 {
        enum scsi_timeout_action action;
        unsigned long flags;
@@ -1796,6 +1796,7 @@ ata_scsi_retry_deferred_qc(struct ata_port *ap, struct scsi_cmnd *scmd)
 
        return action;
 }
+EXPORT_SYMBOL_GPL(ata_scsi_retry_deferred_qc);
 
 enum scsi_timeout_action ata_scsi_eh_timed_out(struct scsi_cmnd *scmd)
 {
index c83282733ec4c8a648e5f1d550bb44a69c11a18e..97ac3db5dccb3fb9859fe58e7431354dfb0ee7f5 100644 (file)
@@ -502,6 +502,21 @@ int sas_eh_target_reset_handler(struct scsi_cmnd *cmd)
 }
 EXPORT_SYMBOL_GPL(sas_eh_target_reset_handler);
 
+/*
+ * Handle deferred QCs in case of a command timeout.
+ * See ata_scsi_eh_timed_out() for details.
+ */
+enum scsi_timeout_action sas_eh_timed_out(struct scsi_cmnd *cmd)
+{
+       struct domain_device *dev = cmd_to_domain_dev(cmd);
+
+       if (dev_is_sata(dev))
+               return ata_scsi_retry_deferred_qc(dev->sata_dev.ap, cmd);
+
+       return SCSI_EH_NOT_HANDLED;
+}
+EXPORT_SYMBOL_GPL(sas_eh_timed_out);
+
 /* Try to reset a device */
 static int try_to_reset_cmd_device(struct scsi_cmnd *cmd)
 {
index f10b3287b50748728c391be315dc195ee52a5790..1827502b9cf2a4115fb2298b8ce6f398d70677e4 100644 (file)
@@ -1153,6 +1153,8 @@ extern int ata_scsi_ioctl(struct scsi_device *dev, unsigned int cmd,
 #endif
 extern enum scsi_qc_status ata_scsi_queuecmd(struct Scsi_Host *h,
                                             struct scsi_cmnd *cmd);
+enum scsi_timeout_action ata_scsi_retry_deferred_qc(struct ata_port *ap,
+                                                   struct scsi_cmnd *scmd);
 enum scsi_timeout_action ata_scsi_eh_timed_out(struct scsi_cmnd *cmd);
 #if IS_REACHABLE(CONFIG_ATA)
 bool ata_scsi_dma_need_drain(struct request *rq);
index 163f23c92b4119bec2d226abeba79bc5ba863e74..c7017ae76c61576d6a91f719b477dc7f56dd5c38 100644 (file)
@@ -705,6 +705,7 @@ void sas_task_abort(struct sas_task *);
 int sas_eh_abort_handler(struct scsi_cmnd *cmd);
 int sas_eh_device_reset_handler(struct scsi_cmnd *cmd);
 int sas_eh_target_reset_handler(struct scsi_cmnd *cmd);
+enum scsi_timeout_action sas_eh_timed_out(struct scsi_cmnd *cmd);
 
 extern void sas_target_destroy(struct scsi_target *);
 extern int sas_sdev_init(struct scsi_device *);
@@ -743,6 +744,7 @@ void sas_notify_phy_event(struct asd_sas_phy *phy, enum phy_event event,
        .this_id                        = -1,                           \
        .eh_device_reset_handler        = sas_eh_device_reset_handler,  \
        .eh_target_reset_handler        = sas_eh_target_reset_handler,  \
+       .eh_timed_out                   = sas_eh_timed_out,             \
        .target_destroy                 = sas_target_destroy,           \
        .ioctl                          = sas_ioctl,                    \