From: Niklas Cassel <cassel@kernel.org>
To: Damien Le Moal <dlemoal@kernel.org>
Cc: Bart Van Assche <bvanassche@acm.org>,
Marco Elver <elver@google.com>,
linux-ide@vger.kernel.org, Niklas Cassel <cassel@kernel.org>
Subject: [PATCH 3/3] ata: Annotate functions in the issuing path with __must_hold()
Date: Thu, 28 May 2026 19:28:59 +0200 [thread overview]
Message-ID: <20260528172855.703631-8-cassel@kernel.org> (raw)
In-Reply-To: <20260528172855.703631-5-cassel@kernel.org>
From: Bart Van Assche <bvanassche@acm.org>
Annotate the following functions used in the issuing path:
ata_qc_issue(), ata_sas_queuecmd(), ata_scsi_qc_issue(),
ata_scsi_translate(), __ata_scsi_queuecmd()
These functions are all used in the issuing path, so context analysis will
be able to verify that the ap lock is held, from it is taken in
sas_queuecommand() or ata_scsi_queuecmd() all the way down to
ata_qc_issue().
Commenting out the spin_lock_irqsave() successfully results in a compiler
error on Clang 23.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Co-developed-by: Niklas Cassel <cassel@kernel.org>
Signed-off-by: Niklas Cassel <cassel@kernel.org>
---
drivers/ata/libata-core.c | 1 +
drivers/ata/libata-sata.c | 1 +
drivers/ata/libata-scsi.c | 3 +++
drivers/ata/libata.h | 6 ++++--
include/linux/libata.h | 3 ++-
5 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 830ce49587f3..6ff61eff245b 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -5161,6 +5161,7 @@ EXPORT_SYMBOL_GPL(ata_qc_get_active);
* spin_lock_irqsave(host lock)
*/
void ata_qc_issue(struct ata_port *ap, struct ata_queued_cmd *qc)
+ __must_hold(ap->lock)
{
struct ata_link *link = qc->dev->link;
u8 prot = qc->tf.protocol;
diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c
index 5e5be6bbf32a..b0706c30da05 100644
--- a/drivers/ata/libata-sata.c
+++ b/drivers/ata/libata-sata.c
@@ -1377,6 +1377,7 @@ EXPORT_SYMBOL_GPL(ata_sas_sdev_configure);
*/
int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap)
+ __must_hold(ap->lock)
{
if (likely(ata_dev_enabled(ap->link.device)))
return __ata_scsi_queuecmd(cmd, ap->link.device, ap);
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index c4b53c94c82b..b82a421e2242 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -1763,6 +1763,7 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc)
}
static int ata_scsi_qc_issue(struct ata_port *ap, struct ata_queued_cmd *qc)
+ __must_hold(ap->lock)
{
int ret;
@@ -1848,6 +1849,7 @@ static int ata_scsi_qc_issue(struct ata_port *ap, struct ata_queued_cmd *qc)
*/
static int ata_scsi_translate(struct ata_device *dev, struct scsi_cmnd *cmd,
ata_xlat_func_t xlat_func, struct ata_port *ap)
+ __must_hold(ap->lock)
{
struct ata_queued_cmd *qc;
@@ -4505,6 +4507,7 @@ static void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd)
enum scsi_qc_status __ata_scsi_queuecmd(struct scsi_cmnd *scmd,
struct ata_device *dev,
struct ata_port *ap)
+ __must_hold(ap->lock)
{
u8 scsi_op = scmd->cmnd[0];
ata_xlat_func_t xlat_func;
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
index 7f9b889c9239..902c53baa109 100644
--- a/drivers/ata/libata.h
+++ b/drivers/ata/libata.h
@@ -88,7 +88,8 @@ extern int ata_down_xfermask_limit(struct ata_device *dev, unsigned int sel);
extern unsigned int ata_dev_set_feature(struct ata_device *dev,
u8 subcmd, u8 action);
extern void ata_qc_free(struct ata_queued_cmd *qc);
-extern void ata_qc_issue(struct ata_port *ap, struct ata_queued_cmd *qc);
+extern void ata_qc_issue(struct ata_port *ap, struct ata_queued_cmd *qc)
+ __must_hold(ap->lock);
extern void __ata_qc_complete(struct ata_queued_cmd *qc);
extern int atapi_check_dma(struct ata_queued_cmd *qc);
extern void swap_buf_le16(u16 *buf, unsigned int buf_words);
@@ -167,7 +168,8 @@ int ata_scsi_dev_config(struct scsi_device *sdev, struct queue_limits *lim,
struct ata_device *dev);
enum scsi_qc_status __ata_scsi_queuecmd(struct scsi_cmnd *scmd,
struct ata_device *dev,
- struct ata_port *ap);
+ struct ata_port *ap)
+ __must_hold(ap->lock);
void ata_scsi_deferred_qc_work(struct work_struct *work);
void ata_scsi_requeue_deferred_qc(struct ata_port *ap);
diff --git a/include/linux/libata.h b/include/linux/libata.h
index 5f6bbe5d504f..c400aa3af93f 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -1314,7 +1314,8 @@ extern int ata_tport_add(struct device *parent, struct ata_port *ap);
extern void ata_tport_delete(struct ata_port *ap);
int ata_sas_sdev_configure(struct scsi_device *sdev, struct queue_limits *lim,
struct ata_port *ap);
-extern int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap);
+extern int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap)
+ __must_hold(ap->lock);
extern void ata_tf_to_fis(const struct ata_taskfile *tf,
u8 pmp, int is_cmd, u8 *fis);
extern void ata_tf_from_fis(const u8 *fis, struct ata_taskfile *tf);
--
2.54.0
next prev parent reply other threads:[~2026-05-28 17:29 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-28 17:28 [PATCH 0/3] ata: add __must_hold(ap->lock) annotations in issuing path Niklas Cassel
2026-05-28 17:28 ` [PATCH 1/3] ata: libata-scsi: Remove lockdep_assert_held() in ata_scsi_translate() Niklas Cassel
2026-05-28 17:33 ` Bart Van Assche
2026-05-28 17:54 ` Niklas Cassel
2026-05-28 19:48 ` Bart Van Assche
2026-05-28 17:51 ` sashiko-bot
2026-05-29 6:22 ` Hannes Reinecke
2026-05-29 6:42 ` Damien Le Moal
2026-05-31 13:47 ` Niklas Cassel
2026-05-28 17:28 ` [PATCH 2/3] ata: libata: Pass ap parameter directly to functions in the issuing path Niklas Cassel
2026-05-29 6:22 ` Hannes Reinecke
2026-05-28 17:28 ` Niklas Cassel [this message]
2026-05-29 6:23 ` [PATCH 3/3] ata: Annotate functions in the issuing path with __must_hold() Hannes Reinecke
2026-05-31 14:00 ` (subset) [PATCH 0/3] ata: add __must_hold(ap->lock) annotations in issuing path 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=20260528172855.703631-8-cassel@kernel.org \
--to=cassel@kernel.org \
--cc=bvanassche@acm.org \
--cc=dlemoal@kernel.org \
--cc=elver@google.com \
--cc=linux-ide@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.