From: Mahanta Jambigi <mjambigi@linux.ibm.com>
To: linux-rdma@vger.kernel.org
Cc: Leon Romanovsky <leon@kernel.org>, Jason Gunthorpe <jgg@ziepe.ca>,
Mahanta Jambigi <mjambigi@linux.ibm.com>
Subject: [PATCH rdma-next v3] RDMA/mlx5: Read the CQ consumer index under cq->lock when arming
Date: Fri, 27 Nov 2026 08:53:23 +0100 [thread overview]
Message-ID: <20261127075323.4099367-1-mjambigi@linux.ibm.com> (raw)
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():
[ 312.234586] ==================================================================
[ 312.234707] BUG: KCSAN: data-race in mlx5_ib_arm_cq [mlx5_ib] / mlx5_poll_one [mlx5_ib]
[ 312.234933] write to 0x00000000956c9dc8 of 4 bytes by interrupt on cpu 1:
[ 312.234951] mlx5_poll_one+0xa0/0xed0 [mlx5_ib]
[ 312.235066] mlx5_ib_poll_cq+0xda/0x340 [mlx5_ib]
[ 312.235181] smc_wr_tx_tasklet_fn+0x92/0x1d0 [smc]
[ 312.235259] tasklet_action_common+0x150/0x450
[ 312.235277] handle_softirqs+0x144/0x5a0
[ 312.235294] irq_exit_rcu+0x1ba/0x1f0
[ 312.235309] do_io_irq+0xd2/0x1b0
[ 312.235326] io_int_handler+0xec/0x118
[ 312.235344] arch_cpu_idle+0xf4/0x100
[ 312.235363] arch_cpu_idle+0x48/0x100
[ 312.235382] default_idle_call+0xea/0x2d0
[ 312.235398] do_idle+0xfe/0x1e0
[ 312.235412] cpu_startup_entry+0x40/0x50
[ 312.235428] smp_start_secondary+0x218/0x250
[ 312.235447] restart_int_handler+0x72/0x88
[ 312.235475] read to 0x00000000956c9dc8 of 4 bytes by task 6316 on cpu 2:
[ 312.235492] mlx5_ib_arm_cq+0xe8/0x180 [mlx5_ib]
[ 312.235614] smc_wr_tx_send+0x6a/0x140 [smc]
[ 312.235691] smc_cdc_msg_send+0x2a4/0x360 [smc]
[ 312.235770] smcr_tx_sndbuf_nonempty+0x1f4/0x520 [smc]
[ 312.235848] smc_tx_sndbuf_nonempty+0x238/0x2e0 [smc]
[ 312.235926] smc_tx_sendmsg+0x92a/0xa80 [smc]
[ 312.236003] smc_sendmsg+0x160/0x310 [smc]
[ 312.236078] __sock_sendmsg+0x96/0x110
[ 312.236098] sock_write_iter+0x102/0x180
[ 312.236115] vfs_write+0x3fe/0x740
[ 312.236131] ksys_write+0x10e/0x150
[ 312.236147] __s390x_sys_write+0x5e/0x70
[ 312.236163] __do_syscall+0x1b4/0x580
[ 312.236181] system_call+0x72/0x90
[ 312.236206] locks held by iperf3/6316: 2, on CPU#2:
[ 312.236221] #0: 00000001018dbe58 (sk_lock-AF_SMC){+.+.}-{0:0}, at: smc_sendmsg+0x46/0x310 [smc]
[ 312.236321] #1: 00000001018dc358 (&smc->conn.send_lock){+.-.}-{2:2}, at: smcr_tx_sndbuf_nonempty+0x17c/0x520 [smc]
[ 312.236423] irq event stamp: 45730
[ 312.236435] hardirqs last enabled at (45729): [<000003a606250966>] _raw_spin_unlock_irqrestore+0x66/0x80
[ 312.236461] hardirqs last disabled at (45730): [<000003a604e5d228>] kcsan_setup_watchpoint+0x4f8/0x590
[ 312.236485] softirqs last enabled at (45723): [<000003a605d3aaae>] lock_sock_nested+0x8e/0xb0
[ 312.236509] softirqs last disabled at (45725): [<000003a5857d155c>] smcr_tx_sndbuf_nonempty+0x17c/0x520 [smc]
[ 312.236601] value changed: 0x0000063d -> 0x0000063e
[ 312.236623] Reported by Kernel Concurrency Sanitizer on:
[ 312.236636] CPU: 2 UID: 0 PID: 6316 Comm: iperf3 Kdump: loaded Not tainted 7.4.0-rc3-kcsan-00406-g65e4fd942f72 #1 PREEMPT
[ 312.236674] ==================================================================
Read the index under cq->lock, which every runtime writer already holds,
so the value handed to mlx5_cq_arm() is a synchronized snapshot. A stale
index can cause a spurious completion event, never a lost one.
Signed-off-by: Mahanta Jambigi <mjambigi@linux.ibm.com>
---
Changes in v3:
- Add the full untrimmed KCSAN report to the commit message, as
requested.
Changes in v2:
- Drop the Fixes: tag. The unlocked read predates ce0f75093282; the race
is as old as the driver and this is a KCSAN annotation rather than a
regression fix.
- Reword the justification to cover only what the change does: the value
handed to mlx5_cq_arm() is a synchronized snapshot. The arm record and
the doorbell can still be overwritten by concurrent arm callers, which
is a separate pre-existing issue and not addressed here.
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
next reply other threads:[~2026-11-27 7:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 7:53 Mahanta Jambigi [this message]
2026-11-27 8:09 ` [PATCH rdma-next v3] RDMA/mlx5: Read the CQ consumer index under cq->lock when arming sashiko-bot
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=20261127075323.4099367-1-mjambigi@linux.ibm.com \
--to=mjambigi@linux.ibm.com \
--cc=jgg@ziepe.ca \
--cc=leon@kernel.org \
--cc=linux-rdma@vger.kernel.org \
/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