From: Damien Le Moal <dlemoal@kernel.org>
To: sashiko-reviews@lists.linux.dev
Cc: linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org, cassel@kernel.org
Subject: Re: [PATCH v1 1/2] ata: libata-scsi: terminate deferred commands on time out
Date: Thu, 9 Jul 2026 18:14:08 +0900 [thread overview]
Message-ID: <dcc4f558-7b6e-4193-a943-036255fc202f@kernel.org> (raw)
In-Reply-To: <20260709090006.F317F1F00A3A@smtp.kernel.org>
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.
> When a deferred command times out, ata_scsi_eh_timed_out() calls this function
> which sets the host byte to DID_TIME_OUT and calls ata_scsi_qc_done().
> ata_scsi_qc_done() then frees the qc and invokes the qc->scsidone callback.
>
> Later, when the SCSI completion softirq routes the DID_TIME_OUT command to the
> EH queue and the EH thread runs ata_scsi_cmd_error_handler():
>
> drivers/ata/libata-eh.c:ata_scsi_cmd_error_handler() {
> ...
> 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)
> break;
> }
> ...
> }
>
> Because the qc was already freed, the ATA_QCFLAG_ACTIVE flag is cleared
> and deferred_qc is NULL. The loop will fail to find the active command.
>
> It seems this causes the handler to fall into the 'raced completion' branch:
>
> drivers/ata/libata-eh.c:ata_scsi_cmd_error_handler() {
> ...
> } else {
> /* Normal completion occurred after
> * SCSI timeout but before this point.
> * Successfully complete it.
> */
> scmd->retries = scmd->allowed;
> scsi_eh_finish_cmd(scmd, &ap->eh_done_q);
> }
> ...
> }
And after this, scsi_eh_flush_done_q() will retry the command.
Tested and I do not see failure of the deferred QC :)
--
Damien Le Moal
Western Digital Research
next prev parent reply other threads:[~2026-07-09 9:14 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 [this message]
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
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=dcc4f558-7b6e-4193-a943-036255fc202f@kernel.org \
--to=dlemoal@kernel.org \
--cc=cassel@kernel.org \
--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