From: sashiko-bot@kernel.org
To: "Mahanta Jambigi" <mjambigi@linux.ibm.com>, linux-rdma@vger.kernel.org
Subject: Re: [PATCH rdma-next v3] RDMA/mlx5: Read the CQ consumer index under cq->lock when arming
Date: Fri, 27 Nov 2026 08:09:58 +0000 [thread overview]
Message-ID: <sashiko-outbox-236868@kernel.org> (raw)
In-Reply-To: <20261127075323.4099367-1-mjambigi@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] RDMA/mlx5: stale cons_index and arm_db race in
mlx5_ib_arm_cq()
--
commit cd4a8e789a4da161bb086eeea0e1e95d45a10710
Author: Mahanta Jambigi <mjambigi@linux.ibm.com>
RDMA/mlx5: Read the CQ consumer index under cq->lock when arming
This commit snapshots cq->mcq.cons_index under cq->lock in
mlx5_ib_arm_cq() before unlocking and calling mlx5_cq_arm().
> diff --git a/drivers/infiniband/hw/mlx5/cq.c b/drivers/infiniband/hw/mlx5/cq.c
> index 2581a7693585b..65badcb90d34a 100644
> --- a/drivers/infiniband/hw/mlx5/cq.c
> +++ b/drivers/infiniband/hw/mlx5/cq.c
> @@ -651,6 +651,7 @@ int mlx5_ib_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags)
> struct mlx5_ib_cq *cq = to_mcq(ibcq);
> void __iomem *uar_page = mdev->priv.bfreg.up->map;
> unsigned long irq_flags;
> + u32 cons_index;
> int ret = 0;
>
> spin_lock_irqsave(&cq->lock, irq_flags);
> @@ -659,12 +660,16 @@ int mlx5_ib_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags)
>
> if ((flags & IB_CQ_REPORT_MISSED_EVENTS) && !list_empty(&cq->wc_list))
> ret = 1;
> + /* The poll path advances cons_index under cq->lock; take the
> + * snapshot here so the doorbell sees a consistent index.
> + */
> + cons_index = cq->mcq.cons_index;
> spin_unlock_irqrestore(&cq->lock, irq_flags);
>
> mlx5_cq_arm(&cq->mcq,
> (flags & IB_CQ_SOLICITED_MASK) == IB_CQ_SOLICITED ?
> MLX5_CQ_DB_REQ_NOT_SOL : MLX5_CQ_DB_REQ_NOT,
> - uar_page, to_mcq(ibcq)->mcq.cons_index);
> + uar_page, cons_index);
>
> return ret;
> }
[Severity: Medium]
Can snapshotting cons_index before spin_unlock_irqrestore() cause
mlx5_cq_arm() to overwrite *cq->mcq.arm_db and MLX5_CQ_DOORBELL with a
stale index?
Reading cons_index under cq->lock and dropping the lock before calling
mlx5_cq_arm() does not serialize the doorbell update against concurrent
polls and re-arms, and introduces a local-CPU race across interrupt
re-enablement when called from process context with softirqs enabled
(such as smc_wr_reg_send()):
mlx5_ib_arm_cq()
spin_lock_irqsave(&cq->lock, irq_flags)
cons_index = cq->mcq.cons_index /* N */
spin_unlock_irqrestore(&cq->lock, irq_flags)
<hardirq>
mlx5_eq_comp_int()
++cq->arm_sn
<softirq>
smc_wr_tx_tasklet_fn()
ib_poll_cq() /* cons_index -> N + k */
ib_req_notify_cq()
mlx5_cq_arm(..., N + k)
mlx5_cq_arm(..., N) <-- rewinds arm_db to N
Before this change, cons_index was read after spin_unlock_irqrestore()
returned and observed N + k on the local CPU. Across CPUs, if the first
caller also reads cq->mcq.arm_sn in mlx5_cq_arm() before
mlx5_eq_comp_int() increments it and the tasklet re-arms the CQ at
(sn + 1, N + k), the delayed caller overwrites *cq->mcq.arm_db in DMA
memory with the already-fired sequence number sn and stale index N,
which can cause spurious interrupts or a lost completion notification
during doorbell recovery.
Calling mlx5_cq_arm() while holding cq->lock before
spin_unlock_irqrestore() would keep cons_index, *cq->mcq.arm_db, and the
doorbell write serialized with the poll path.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127075323.4099367-1-mjambigi@linux.ibm.com?part=1
prev parent reply other threads:[~2026-11-27 8:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 7:53 [PATCH rdma-next v3] RDMA/mlx5: Read the CQ consumer index under cq->lock when arming Mahanta Jambigi
2026-11-27 8:09 ` sashiko-bot [this message]
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=sashiko-outbox-236868@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=mjambigi@linux.ibm.com \
--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