From: Leon Romanovsky <leon@kernel.org>
To: Mahanta Jambigi <mjambigi@linux.ibm.com>
Cc: linux-rdma@vger.kernel.org, Jason Gunthorpe <jgg@ziepe.ca>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH rdma-next] RDMA/mlx5: Read the CQ consumer index under cq->lock when arming
Date: Thu, 26 Nov 2026 20:59:02 +0200 [thread overview]
Message-ID: <20261126185902.GW774860@unreal> (raw)
In-Reply-To: <20261125084054.1349677-1-mjambigi@linux.ibm.com>
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
>
prev parent reply other threads:[~2026-11-26 18:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 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=20261126185902.GW774860@unreal \
--to=leon@kernel.org \
--cc=jgg@ziepe.ca \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=mjambigi@linux.ibm.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