From: Damien Le Moal <dlemoal@kernel.org>
To: Niklas Cassel <cassel@kernel.org>
Cc: sashiko-reviews@lists.linux.dev, linux-ide@vger.kernel.org,
linux-scsi@vger.kernel.org, Igor Pylypiv <ipylypiv@google.com>
Subject: Re: [PATCH v1 1/2] ata: libata-scsi: terminate deferred commands on time out
Date: Fri, 10 Jul 2026 09:00:38 +0900 [thread overview]
Message-ID: <5cab2d52-5100-4dd8-aff7-f0927777041d@kernel.org> (raw)
In-Reply-To: <ak_gsY5YvMBC-0M_@fedora>
On 7/10/26 02:56, Niklas Cassel wrote:
> On Thu, Jul 09, 2026 at 06:14:08PM +0900, Damien Le Moal wrote:
>> On 7/9/26 18:00, sashiko-bot@kernel.org wrote:
>>> [Severity: High]
>>> Does calling ata_scsi_qc_done() here prematurely complete the timed-out
>>> deferred command and free the libata qc?
>>
>> Yes it does. But unless it is the deferred QC that suffered the timeout, the
>> scsi command will be requeued and retried.
>
> I think Sashiko has a good point.
>
>
> After this patch:
>
> We will have some deferred QC handling in ata_scsi_eh_timed_out(scmd):
>
> -Sets link->deferred_qc = NULL;
>
> -Cancels the workqueue.
>
> ata_scsi_eh_timed_out() will do the following:
> If scmd (the QC that timed out) was the deferred QC:
> -Sets DID_REQUEUE on the deferred QC.
> Else:
> -Sets DID_TIMEOUT on the deferred QC.
>
> -Calls ata_scsi_qc_done(), which frees the deferred QC and calls scsi_done()
>
> -scsi_done() will call scsi_done_internal(cmd, false);
> scsi_done_internal(cmd, false) will set SCMD_STATE_COMPLETE,
> but will defer the actual completion (scsi_complete() to softirq context.
> -ata_scsi_eh_timed_out() will return SCSI_EH_NOT_HANDLED to scsi_timeout(),
> which will break; and will then evaluate if SCMD_STATE_COMPLETE is set,
> if it is, it will do nothing.
> (If it is not set it will add the scmd to the list of failed scmds.)
>
> In case scmd == the deferred QC, since scsi_done_internal() will set
> SCMD_STATE_COMPLETE, before deferring the completion to softirq context,
> the code in scsi_timeout() will not add the scmd to the error list using
> scsi_eh_scmd_add(), instead it will return BLK_EH_DONE;
>
> Thus, Sashikos comment can not happen in realtity, because if the deferred
> QC timed out, it will never be added to the list of scmds which
> ata_scsi_cmd_error_handler() will loop over.
>
> I think it would be cleaner if we:
>
> 1) Modify ata_scsi_eh_timed_out():
> if scmd == the deferred QC, set DID_TIMEOUT, but return SCSI_EH_DONE.
> This way it is more obvious that no further EH will be done. (Instead of
> relying on SCMD_STATE_COMPLETE already have been set, even though the
> completion was deferred to softirq context.)
Yes, you are right. For a timedout command, we always get +1 to the scsi host
failed counter, so we do not need to do anything special to decrement the busy
counter for a deferred QC when it times out.
As for the change, since ata_scsi_cmd_error_handler() already correctly handles
timed-out deferred QCs, when we have scmd == the deferred QC, we should just
not do anything at all in ata_scsi_requeue_deferred_qc().
ata_scsi_cmd_error_handler() will take care of it.
Sending a v2 with that change.
--
Damien Le Moal
Western Digital Research
next prev parent reply other threads:[~2026-07-10 0:00 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 8:39 [PATCH v1 0/2] fixup handling of timeouts with deferred QCs Damien Le Moal
2026-07-09 8:39 ` [PATCH v1 1/2] ata: libata-scsi: terminate deferred commands on time out Damien Le Moal
2026-07-09 9:00 ` sashiko-bot
2026-07-09 9:14 ` Damien Le Moal
2026-07-09 17:27 ` Niklas Cassel
2026-07-09 17:56 ` Niklas Cassel
2026-07-09 18:02 ` Niklas Cassel
2026-07-10 0:00 ` Damien Le Moal [this message]
2026-07-09 8:39 ` [PATCH v1 2/2] scsi: libsas: " Damien Le Moal
2026-07-09 17:36 ` [PATCH v1 0/2] fixup handling of timeouts with deferred QCs Igor Pylypiv
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5cab2d52-5100-4dd8-aff7-f0927777041d@kernel.org \
--to=dlemoal@kernel.org \
--cc=cassel@kernel.org \
--cc=ipylypiv@google.com \
--cc=linux-ide@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox