* [PATCH rdma-next] RDMA/mlx5: Read the CQ consumer index under cq->lock when arming
@ 2026-11-25 8:40 Mahanta Jambigi
2026-11-26 18:59 ` Leon Romanovsky
0 siblings, 1 reply; 2+ messages in thread
From: Mahanta Jambigi @ 2026-11-25 8:40 UTC (permalink / raw)
To: linux-rdma
Cc: Leon Romanovsky, Jason Gunthorpe, linux-kernel, Mahanta Jambigi
mlx5_ib_arm_cq() reads cq->mcq.cons_index after dropping cq->lock, while
the poll path advances the index under that lock. A ULP that arms the CQ
from process context while the completion tasklet polls races on the
index, as SMC-R does from smc_wr_tx_send():
BUG: KCSAN: data-race in mlx5_ib_arm_cq [mlx5_ib] / mlx5_poll_one
[mlx5_ib]
Read the index under cq->lock, which every writer of it already holds,
so the doorbell is programmed with a consistent value. A stale index can
only cause a spurious completion event, never a lost one.
Fixes: ce0f75093282 ("net/mlx5_core: Modify arm CQ in preparation for upcoming Ethernet driver")
Signed-off-by: Mahanta Jambigi <mjambigi@linux.ibm.com>
---
Note: mlx5_cq_arm() also reads cq->arm_sn, which eq.c increments without
cq->lock. That pair is pre-existing and separate from the race fixed here;
this patch does not change it, and I have not analyzed what a stale sn
does to the arm protocol.
drivers/infiniband/hw/mlx5/cq.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/infiniband/hw/mlx5/cq.c b/drivers/infiniband/hw/mlx5/cq.c
index 55ffd7d4de51..8f4389b4eb6f 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;
}
--
2.39.2
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH rdma-next] RDMA/mlx5: Read the CQ consumer index under cq->lock when arming
2026-11-25 8:40 [PATCH rdma-next] RDMA/mlx5: Read the CQ consumer index under cq->lock when arming Mahanta Jambigi
@ 2026-11-26 18:59 ` Leon Romanovsky
0 siblings, 0 replies; 2+ messages in thread
From: Leon Romanovsky @ 2026-11-26 18:59 UTC (permalink / raw)
To: Mahanta Jambigi; +Cc: linux-rdma, Jason Gunthorpe, linux-kernel
On Wed, Nov 25, 2026 at 09:40:54AM +0100, Mahanta Jambigi wrote:
> mlx5_ib_arm_cq() reads cq->mcq.cons_index after dropping cq->lock, while
> the poll path advances the index under that lock. A ULP that arms the CQ
> from process context while the completion tasklet polls races on the
> index, as SMC-R does from smc_wr_tx_send():
>
> BUG: KCSAN: data-race in mlx5_ib_arm_cq [mlx5_ib] / mlx5_poll_one
> [mlx5_ib]
Please add full non-trimmed dmesg stack trace to the commit message and
resend.
Thanks
>
> Read the index under cq->lock, which every writer of it already holds,
> so the doorbell is programmed with a consistent value. A stale index can
> only cause a spurious completion event, never a lost one.
>
> Fixes: ce0f75093282 ("net/mlx5_core: Modify arm CQ in preparation for upcoming Ethernet driver")
> Signed-off-by: Mahanta Jambigi <mjambigi@linux.ibm.com>
> ---
> Note: mlx5_cq_arm() also reads cq->arm_sn, which eq.c increments without
> cq->lock. That pair is pre-existing and separate from the race fixed here;
> this patch does not change it, and I have not analyzed what a stale sn
> does to the arm protocol.
>
> drivers/infiniband/hw/mlx5/cq.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/infiniband/hw/mlx5/cq.c b/drivers/infiniband/hw/mlx5/cq.c
> index 55ffd7d4de51..8f4389b4eb6f 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;
> }
> --
> 2.39.2
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-26 18:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 8:40 [PATCH rdma-next] RDMA/mlx5: Read the CQ consumer index under cq->lock when arming Mahanta Jambigi
2026-11-26 18:59 ` Leon Romanovsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®