From: Niklas Cassel <cassel@kernel.org>
To: Tommy Kelly <linux@tkel.ly>, Damien Le Moal <dlemoal@kernel.org>,
Niklas Cassel <cassel@kernel.org>, Tejun Heo <htejun@gmail.com>,
Jeff Garzik <jeff@garzik.org>
Cc: linux-ide@vger.kernel.org
Subject: [PATCH 1/3] ata: libata-pmp: fix ata_pmp_qc_defer_cmd_switch()
Date: Fri, 1 May 2026 14:54:11 +0200 [thread overview]
Message-ID: <20260501125410.1204490-6-cassel@kernel.org> (raw)
In-Reply-To: <20260501125410.1204490-5-cassel@kernel.org>
When using Port Multipliers (PMPs) with Command-Based Switching (CBS), you
can only issue commands to one link at a time.
This is implemented in sata_pmp_qc_defer_cmd_switch() by setting
ap->excl_link if there is no link currently being exclusive, and setting
qc->flags ATA_QCFLAG_CLEAR_EXCL to clear the exlusive link in
__ata_qc_complete().
ATA_QCFLAG_CLEAR_EXCL is only set if this is the first link to become
active, or if (since CBS can only have one active link) the current link
is active. __ata_qc_complete() clears ap->excl_link as long as
ATA_QCFLAG_CLEAR_EXCL is set, it does not matter if there are still
outstanding requests to the same link. This works because
sata_pmp_qc_defer_cmd_switch() will only allow new commands to be queued
if (ap->nr_active_links == 0 || ata_link_active(link)).
However, since sata_pmp_qc_defer_cmd_switch() does a:
return ata_std_qc_defer(qc); before setting ap->excl_link, this means that
in the case where ap->excl_link == NULL and ata_std_qc_defer() returns 0
(i.e. the QC should not be deferred), we would not set ap->excl_link.
Additionally, think of the following example:
NCQ command1 to drive1 issued:
sets ATA_QCFLAG_CLEAR_EXCL
does not set ap->excl_link
NCQ command2 to drive1 issued:
sets ATA_QCFLAG_CLEAR_EXCL
does not set ap->excl_link
NCQ command3 to drive2 issued:
ap->excl_link gets set
does not set ATA_QCFLAG_CLEAR_EXCL
returns ATA_DEFER_PORT
For command3, it seems wrong to set ap->excl_link while also deferring the
command with ATA_DEFER_PORT.
Modify sata_pmp_qc_defer_cmd_switch() to only set ap->excl_link if we can
actually issue a command (i.e. if we don't return ATA_DEFER_PORT or
ATA_DEFER_LINK).
Fixes: 31f88384443b ("libata-pmp: implement qc_defer for command switching PMP support")
Signed-off-by: Niklas Cassel <cassel@kernel.org>
---
drivers/ata/libata-pmp.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/ata/libata-pmp.c b/drivers/ata/libata-pmp.c
index e3adc008fed1..0575e1e283d8 100644
--- a/drivers/ata/libata-pmp.c
+++ b/drivers/ata/libata-pmp.c
@@ -113,11 +113,14 @@ int sata_pmp_qc_defer_cmd_switch(struct ata_queued_cmd *qc)
if (ap->excl_link == NULL || ap->excl_link == link) {
if (ap->nr_active_links == 0 || ata_link_active(link)) {
+ int ret;
+
qc->flags |= ATA_QCFLAG_CLEAR_EXCL;
- return ata_std_qc_defer(qc);
+ ret = ata_std_qc_defer(qc);
+ if (!ret)
+ ap->excl_link = link;
+ return ret;
}
-
- ap->excl_link = link;
}
return ATA_DEFER_PORT;
--
2.54.0
next prev parent reply other threads:[~2026-05-01 12:54 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-01 12:54 [PATCH 0/3] ata: fix deferred QC handling for port multipliers Niklas Cassel
2026-05-01 12:54 ` Niklas Cassel [this message]
2026-05-01 12:54 ` [PATCH 2/3] ata: libata-scsi: do not use the deferred QC feature on PMPs with CBS Niklas Cassel
2026-05-01 12:54 ` [PATCH 3/3] ata: libata-scsi: do not needlessly defer commands when using PMP with FBS Niklas Cassel
2026-05-01 14:19 ` [PATCH 0/3] ata: fix deferred QC handling for port multipliers John Garry
2026-05-01 18:42 ` Niklas Cassel
2026-05-04 7:27 ` John Garry
2026-05-08 19:23 ` Niklas Cassel
2026-05-03 0:59 ` Tommy Kelly
2026-05-06 0:13 ` Tommy Kelly
2026-05-06 8:45 ` Heiko Stuebner
2026-05-06 15:00 ` Niklas Cassel
2026-05-06 14:52 ` Niklas Cassel
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=20260501125410.1204490-6-cassel@kernel.org \
--to=cassel@kernel.org \
--cc=dlemoal@kernel.org \
--cc=htejun@gmail.com \
--cc=jeff@garzik.org \
--cc=linux-ide@vger.kernel.org \
--cc=linux@tkel.ly \
/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