FAILED: patch "[PATCH] scsi: libsas: terminate deferred commands on time out" failed to apply to 6.12-stable tree
Subsystems (4)
[email protected]
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x de202d2251bc181c6019b1ad3c0ba8133e5ec68d
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026080542-large-pod-5622@gregkh' --subject-prefix 'PATCH 6.12.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From de202d2251bc181c6019b1ad3c0ba8133e5ec68d Mon Sep 17 00:00:00 2001
From: Damien Le Moal <[email protected]>
Date: Thu, 9 Jul 2026 16:02:23 +0900
Subject: [PATCH] scsi: libsas: terminate deferred commands on time out
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.
drivers/ata/libata-scsi.c +3 -2
@@ -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) {
drivers/scsi/libsas/sas_scsi_host.c +15 -0
@@ -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) {
include/linux/libata.h +2 -0
@@ -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);
include/scsi/libsas.h +2 -0
@@ -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, \
Sasha Levin
maintainerPATCH 1/2 ata: libata-scsi: terminate deferred commands on time out
From: Damien Le Moal <[email protected]>
[ Upstream commit 2e1d2e65e773d67dab163127f11a47dab0fbca9f ]
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 SCSI EH task wake-up additional time by scheduling a retry of all waiting deferred QCs, using the eh_timed_out SCSI host template operation. The function ata_scsi_eh_timed_out() is introduced to implement this operation.
However, terminating deferred commands with DID_REQUEUE to force a retry by calling the function ata_scsi_requeue_deferred_qc() may still keep the SCSI host in a busy state because the block layer may immediately re-issue these commands. The solution to this is to schedule libata EH for the port which suffered the command timeout to prevent accepting any new command. ata_scsi_requeue_deferred_qc() is modified to add a call to ata_port_schedule_eh() for this purpose.
In addition to this change, ata_scsi_requeue_deferred_qc() is also modified to take a new timedout_scmd scsi command argument which indicates the SCSI command that timed out. With this additional argument, ata_scsi_requeue_deferred_qc() can now also terminate with DID_TIME_OUT any timed out deferred qc, which simplifies ata_scsi_cmd_error_handler(). In this case, ata_scsi_requeue_deferred_qc() returns SCSI_EH_DONE, with this return value propagated back to the ata_scsi_eh_timed_out() operation to indicate to scsi_timeout() that the timed out command was handled and no further processing is needed.
For non-timed out deferred qc that need to be retried, ata_scsi_requeue_deferred_qc() returns SCSI_EH_NOT_HANDLED, thus indicating to scsi_timeout() that the timed out command needs to go through the SCSI EH (and libata EH) processing by adding it to the EH work queue with scsi_eh_scmd_add().
One side effect of these changes is that the function atapi_qc_complete() needs to be modified to ensure that a deferred ATAPI command that needs to be retried is completed with DID_REQUEUE instead of the default SAM_STAT_GOOD status, and a command that timed out is completed with DID_TIME_OUT instead of SAM_STAT_CHECK_CONDITION.
Stable-dep-of: de202d2251bc ("scsi: libsas: terminate deferred commands on time out")
--- drivers/ata/libata-eh.c | 29 ++------- drivers/ata/libata-scsi.c | 130 ++++++++++++++++++++++++++++++++------ drivers/ata/libata.h | 3 +- include/linux/libata.h | 5 +- 4 files changed, 121 insertions(+), 46 deletions(-)
drivers/ata/libata-eh.c +6 -23
@@ -650,29 +650,12 @@ void ata_scsi_cmd_error_handler(struct Scsi_Host *host, struct ata_port *ap,set_host_byte (scmd,DID_OK );ata_qc_for_each_raw (ap, qc, i) { -if (qc->scsicmd != scmd) -continue ; -if ((qc->flags &ATA_QCFLAG_ACTIVE ) || - qc == qc->dev->link->deferred_qc) +if (qc->scsicmd == scmd && + qc->flags &ATA_QCFLAG_ACTIVE )break ; } -if (i <ATA_MAX_QUEUE && qc == qc->dev->link->deferred_qc) { -/* -* This is a deferred command that timed out while -* waiting for the command queue to drain. Since the qc -* is not active yet (deferred_qc is still set, so the -* deferred qc work has not issued the command yet), -* simply signal the timeout by finishing the SCSI -* command and clear the deferred qc to prevent the -* deferred qc work from issuing this qc. -*/ -WARN_ON_ONCE (qc->flags &ATA_QCFLAG_ACTIVE ); - qc->dev->link->deferred_qc =NULL ; -cancel_work (&qc->dev->link->deferred_qc_work); -set_host_byte (scmd,DID_TIME_OUT ); -scsi_eh_finish_cmd (scmd, &ap->eh_done_q); - }else if (i <ATA_MAX_QUEUE ) { +if (i <ATA_MAX_QUEUE ) {/* the scmd has an associated qc */ if (!(qc->flags &ATA_QCFLAG_EH )) {/* which hasn't failed yet, timeout */
@@ -946,10 +929,10 @@ static void ata_eh_set_pending(struct ata_port *ap, int fastdrain) ap->pflags |=ATA_PFLAG_EH_PENDING ;/* -* If we have a deferred qc, requeue it so that it is retried once EH -* completes. +* If we have deferred QCs, requeue them so that the SCSI EH task can +* run. */ -ata_scsi_requeue_deferred_qc (ap); +ata_scsi_requeue_deferred_qc (ap,NULL );if (!fastdrain)return ;
drivers/ata/libata-scsi.c +109 -21
188 lines not on this page · raw message
drivers/ata/libata.h +2 -1
@@ -176,7 +176,8 @@ int ata_scsi_dev_config(struct scsi_device *sdev, struct queue_limits *lim, struct ata_device *dev);int __ata_scsi_queuecmd (struct scsi_cmnd *scmd,struct ata_device *dev);void ata_scsi_deferred_qc_work (struct work_struct *work); -void ata_scsi_requeue_deferred_qc (struct ata_port *ap); +enum scsi_timeout_action ata_scsi_requeue_deferred_qc (struct ata_port *ap, +struct scsi_cmnd *scmd);/* libata-eh.c */ extern unsigned int ata_internal_cmd_timeout (struct ata_device *dev,u8 cmd);
include/linux/libata.h +4 -1
@@ -1147,7 +1147,9 @@ extern int ata_scsi_ioctl(struct scsi_device *dev, unsigned int cmd,#else #define ATA_SCSI_COMPAT_IOCTL /* empty */ #endif -extern int ata_scsi_queuecmd (struct Scsi_Host *h,struct scsi_cmnd *cmd); +extern int ata_scsi_queuecmd (struct Scsi_Host *h, +struct scsi_cmnd *cmd); +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);#else
@@ -1461,6 +1463,7 @@ extern const struct attribute_group *ata_common_sdev_groups[]; .ioctl = ata_scsi_ioctl, \ATA_SCSI_COMPAT_IOCTL \ .queuecommand = ata_scsi_queuecmd, \ + .eh_timed_out = ata_scsi_eh_timed_out, \ .dma_need_drain = ata_scsi_dma_need_drain, \ .this_id = ATA_SHT_THIS_ID, \ .emulated = ATA_SHT_EMULATED, \
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 scsi: libsas: terminate deferred commands on time out
From: Damien Le Moal <[email protected]>
[ Upstream commit de202d2251bc181c6019b1ad3c0ba8133e5ec68d ]
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.
--- drivers/ata/libata-scsi.c | 5 +++-- drivers/scsi/libsas/sas_scsi_host.c | 15 +++++++++++++++ include/linux/libata.h | 2 ++ include/scsi/libsas.h | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-)
drivers/ata/libata-scsi.c +3 -2
@@ -1797,8 +1797,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;
@@ -1809,6 +1809,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) {
drivers/scsi/libsas/sas_scsi_host.c +15 -0
@@ -500,6 +500,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) {
include/linux/libata.h +2 -0
@@ -1149,6 +1149,8 @@ extern int ata_scsi_ioctl(struct scsi_device *dev, unsigned int cmd,#endif extern int 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);
include/scsi/libsas.h +2 -0
@@ -700,6 +700,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_slave_alloc (struct scsi_device *);
@@ -738,6 +739,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, \
Signature · 1 line
2.53.0