From: Mahanta Jambigi <mjambigi@linux.ibm.com>
To: sashiko-reviews@lists.linux.dev, linux-rdma@vger.kernel.org
Subject: Re: [PATCH rdma-next v2] RDMA/mlx5: Read the CQ consumer index under cq->lock when arming
Date: Thu, 26 Nov 2026 13:03:06 +0530 [thread overview]
Message-ID: <f3facfd4-56f7-42fe-a98a-78e983e2f36b@linux.ibm.com> (raw)
In-Reply-To: <sashiko-outbox-234933@kernel.org>
On 26/11/26 12:39 pm, sashiko-bot@kernel.org wrote:
> 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 8599d5eedfaa0e58f45970b9ef54ea48dbceee76
> 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 passing it to 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 releasing cq->lock before calling mlx5_cq_arm() overwrite *cq->mcq.arm_db
> and MLX5_CQ_DOORBELL with a stale cons_index and arm_sn?
>
> Because cq->mcq.cons_index is an aligned u32, reading it under cq->lock and
> dropping the lock before mlx5_cq_arm() does not serialize the doorbell update
> against concurrent polling and re-arming. Moving the read before
> spin_unlock_irqrestore() also opens a window on the local CPU when a
> completion interrupt arrives while IRQs are disabled under cq->lock:
>
> smc_wr_tx_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()
> mlx5_ib_poll_cq() /* advances cons_index to N + k */
> mlx5_ib_arm_cq()
> mlx5_cq_arm(..., N + k) /* writes arm_db with N + k */
> mlx5_cq_arm(..., N) <-- rewinds arm_db and doorbell to N
>
> If the outer caller is delayed between reading cq->arm_sn in mlx5_cq_arm()
> and writing *cq->arm_db while an EQE increments cq->arm_sn and the tasklet
> polls and re-arms the CQ, the delayed write also overwrites *cq->arm_db with
> an already-fired sequence number, which can lose a completion notification
> during doorbell recovery.
>
> Should mlx5_cq_arm() be called before spin_unlock_irqrestore(&cq->lock,
> irq_flags) so that reading cons_index, updating *cq->mcq.arm_db, and ringing
> MLX5_CQ_DOORBELL are serialized by cq->lock?
That ordering is *pre-existing* and outside this change: the arm record
and the doorbell have always been written after cq->lock is dropped, and
the v2 changelog already records it as a separate issue. Calling
mlx5_cq_arm() under cq->lock would not close it either, because
cq->arm_sn is incremented by mlx5_eq_comp_int() in the EQ hardirq
without that lock, so the stale-sn case remains. A complete fix has to
serialize arm_sn, *arm_db and the doorbell write against the EQ handler;
that is mlx5 work, not part of this cons_index cleanup.
prev parent reply other threads:[~2026-11-26 7:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 6:52 [PATCH rdma-next v2] RDMA/mlx5: Read the CQ consumer index under cq->lock when arming Mahanta Jambigi
2026-11-26 7:09 ` sashiko-bot
2026-11-26 7:33 ` Mahanta Jambigi [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=f3facfd4-56f7-42fe-a98a-78e983e2f36b@linux.ibm.com \
--to=mjambigi@linux.ibm.com \
--cc=linux-rdma@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