From: Timothy Day <timday@thelustrecollective.com>
To: Michael Margolin <mrgolin@amazon.com>,
Jason Gunthorpe <jgg@nvidia.com>,
Leon Romanovsky <leon@kernel.org>,
linux-rdma@vger.kernel.org
Cc: Gal Pressman <gal.pressman@linux.dev>,
Yossi Leybovich <sleybo@amazon.com>,
Marco Elver <elver@google.com>,
Timothy Day <timday@thelustrecollective.com>
Subject: [PATCH v1 3/5] RDMA/efa: mark admin CQ consumer state as guarded by the ACQ lock
Date: Thu, 16 Jul 2026 23:16:56 -0400 [thread overview]
Message-ID: <20260717031658.477397-4-timday@thelustrecollective.com> (raw)
In-Reply-To: <20260717031658.477397-1-timday@thelustrecollective.com>
The admin completion queue consumer counter and phase bit are
accessed with the ACQ lock held. Annotate both fields with
__guarded_by() and annotate the completion handling helpers:
efa_com_handle_admin_completion()
efa_com_handle_single_admin_completion()
efa_com_cqe_checksum_valid()
with __must_hold() for Clang's context analysis.
The initialisation in efa_com_admin_init_cq() runs before the
admin queue is live. No concurrent access is possible. The
ACQ lock is marked guard(spinlock_init) to silence the context
analysis warning.
The prints in efa_com_wait_and_process_admin_cq_interrupts() are
diagnostics on the error path, where a racy read of the
consumer counter is acceptable. Since the lock isn't being taken,
wrap them in context_unsafe().
Signed-off-by: Timothy Day <timday@thelustrecollective.com>
---
drivers/infiniband/hw/efa/efa_com.c | 10 +++++++---
drivers/infiniband/hw/efa/efa_com.h | 4 ++--
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/drivers/infiniband/hw/efa/efa_com.c b/drivers/infiniband/hw/efa/efa_com.c
index 4ef5ac363800d..27be07e757e26 100644
--- a/drivers/infiniband/hw/efa/efa_com.c
+++ b/drivers/infiniband/hw/efa/efa_com.c
@@ -184,7 +184,7 @@ static int efa_com_admin_init_cq(struct efa_com_dev *edev)
if (!cq->entries)
return -ENOMEM;
- spin_lock_init(&cq->lock);
+ guard(spinlock_init)(&cq->lock);
EFA_SET(&crc_min_ver, EFA_REGS_VERSION_MAJOR_VERSION, EFA_CRC_MIN_ADMIN_API_VERSION_MAJOR);
EFA_SET(&crc_min_ver, EFA_REGS_VERSION_MINOR_VERSION, EFA_CRC_MIN_ADMIN_API_VERSION_MINOR);
@@ -424,6 +424,7 @@ static int efa_com_submit_admin_cmd(struct efa_com_admin_queue *aq,
static bool efa_com_cqe_checksum_valid(struct efa_com_admin_queue *aq,
struct efa_admin_acq_entry *cqe)
+ __must_hold(&aq->cq.lock)
{
u16 cqe_checksum = cqe->acq_common_descriptor.checksum;
u16 calc_checksum;
@@ -444,6 +445,7 @@ static bool efa_com_cqe_checksum_valid(struct efa_com_admin_queue *aq,
static int efa_com_handle_single_admin_completion(struct efa_com_admin_queue *aq,
struct efa_admin_acq_entry *cqe)
+ __must_hold(&aq->cq.lock)
{
struct efa_comp_ctx *comp_ctx;
u16 cmd_id;
@@ -473,6 +475,7 @@ static int efa_com_handle_single_admin_completion(struct efa_com_admin_queue *aq
}
static void efa_com_handle_admin_completion(struct efa_com_admin_queue *aq)
+ __must_hold(&aq->cq.lock)
{
struct efa_admin_acq_entry *cqe;
u16 queue_size_mask;
@@ -589,6 +592,7 @@ static int efa_com_wait_and_process_admin_cq_interrupts(struct efa_comp_ctx *com
atomic64_inc(&aq->stats.no_completion);
+ /* racy reads of the queue counters for diagnostics only */
if (comp_ctx->status == EFA_CMD_COMPLETED)
ibdev_err_ratelimited(
aq->efa_dev,
@@ -596,7 +600,7 @@ static int efa_com_wait_and_process_admin_cq_interrupts(struct efa_comp_ctx *com
efa_com_cmd_str(comp_ctx->cmd_opcode),
comp_ctx->cmd_opcode, comp_ctx->status,
comp_ctx->cmd_id, aq->sq.pc, aq->sq.cc,
- aq->cq.cc);
+ context_unsafe(aq->cq.cc));
else
ibdev_err_ratelimited(
aq->efa_dev,
@@ -604,7 +608,7 @@ static int efa_com_wait_and_process_admin_cq_interrupts(struct efa_comp_ctx *com
efa_com_cmd_str(comp_ctx->cmd_opcode),
comp_ctx->cmd_opcode, comp_ctx->status,
comp_ctx->cmd_id, aq->sq.pc, aq->sq.cc,
- aq->cq.cc);
+ context_unsafe(aq->cq.cc));
clear_bit(EFA_AQ_STATE_RUNNING_BIT, &aq->state);
return -ETIME;
diff --git a/drivers/infiniband/hw/efa/efa_com.h b/drivers/infiniband/hw/efa/efa_com.h
index bf2c0a0f0d9e1..39302559a7a98 100644
--- a/drivers/infiniband/hw/efa/efa_com.h
+++ b/drivers/infiniband/hw/efa/efa_com.h
@@ -28,8 +28,8 @@ struct efa_com_admin_cq {
spinlock_t lock; /* Protects ACQ */
bool validate_checksum;
- u16 cc; /* consumer counter */
- u8 phase;
+ u16 cc __guarded_by(&lock); /* consumer counter */
+ u8 phase __guarded_by(&lock);
};
struct efa_com_admin_sq {
--
2.39.5
next prev parent reply other threads:[~2026-07-17 3:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-17 3:16 [PATCH v1 0/5] Support Clang context analysis for RDMA/efa Timothy Day
2026-07-17 3:16 ` [PATCH v1 1/5] RDMA/efa: mark mmio_read seq_num as guarded by mmio_read lock Timothy Day
2026-07-17 3:16 ` [PATCH v1 2/5] RDMA/efa: mark comp_ctx_pool* as guarded by comp_ctx_lock Timothy Day
2026-07-17 3:16 ` Timothy Day [this message]
2026-07-17 3:16 ` [PATCH v1 4/5] RDMA/efa: mark admin SQ producer state as guarded by the ASQ lock Timothy Day
2026-07-17 3:16 ` [PATCH v1 5/5] RDMA/efa: enable context analysis support for efa driver Timothy Day
2026-07-21 11:10 ` [PATCH v1 0/5] Support Clang context analysis for RDMA/efa Leon Romanovsky
2026-07-21 20:27 ` Timothy Day
2026-07-22 7:21 ` Leon Romanovsky
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=20260717031658.477397-4-timday@thelustrecollective.com \
--to=timday@thelustrecollective.com \
--cc=elver@google.com \
--cc=gal.pressman@linux.dev \
--cc=jgg@nvidia.com \
--cc=leon@kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=mrgolin@amazon.com \
--cc=sleybo@amazon.com \
/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