* [PATCH v4 rdma-rc] RDMA/iwcm: Handle CLOSE before passive establishment
@ 2026-12-02 17:53 Andrew Stellman
2026-12-02 18:07 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Andrew Stellman @ 2026-12-02 17:53 UTC (permalink / raw)
To: Jason Gunthorpe, Leon Romanovsky
Cc: Bernard Metzler, linux-rdma, linux-kernel
From: Andrew Stellman <astellman@stellman-greene.com>
An accepted siw MPA v2 connection enters RDMA mode before it receives
the peer's RTR frame. If that frame is malformed, siw reports CLOSE
while the passive IWCM ID is still in CONN_RECV, and cm_close_handler()
hits the BUG() for unexpected states:
[ 4.767386] ------------[ cut here ]------------
[ 4.767396] kernel BUG at drivers/infiniband/core/iwcm.c:966!
[ 4.767406] Internal error: Oops - BUG: 00000000f2000800 [#1] SMP
[ 4.770343] Modules linked in:
[ 4.770836] CPU: 0 UID: 0 PID: 60 Comm: kworker/u32:1 Not tainted 7.4.0-rc4-gf93eb7cfc4bf #14 PREEMPT(full)
[ 4.771994] Hardware name: linux,dummy-virt (DT)
[ 4.773423] Workqueue: iw_cm_wq cm_work_handler
[ 4.774044] pstate: 814000c5 (Nzcv daIF +PAN -UAO -TCO +DIT -SSBS BTYPE=--)
[ 4.774971] pc : cm_work_handler+0xf40/0x1098
[ 4.775547] lr : cm_work_handler+0x240/0x1098
[ 4.776080] sp : ffff800080ac79b0
[ 4.776589] x29: ffff800080ac7b60 x28: ffff0000e8473600 x27: ffff0000e6d87a98
[ 4.777487] x26: 0000000000000000 x25: ffff0000e8473948 x24: ffff0000e6d87800
[ 4.778315] x23: ffff0000e8473548 x22: ffff0000e83af000 x21: ffff0000e6d87a90
[ 4.779282] x20: 1ffff00010158f38 x19: ffff0000e6d87800 x18: ffff0000c8726f78
[ 4.780155] x17: ffffd479c0827da0 x16: ffffd479c2b66c44 x15: 0000000000000000
[ 4.784111] x14: 0000000000000000 x13: 0000000000000000 x12: ffff700010158f27
[ 4.784937] x11: 1ffff00010158f26 x10: ffff700010158f26 x9 : dfff800000000000
[ 4.785840] x8 : 0000000000000003 x7 : 0000000000000001 x6 : ffff700010158f26
[ 4.786664] x5 : ffff800080ac7930 x4 : 1fffe0001cdb0f48 x3 : 0000000000000003
[ 4.787577] x2 : 0000000000000000 x1 : 0000000000000000 x0 : 0000000000000002
[ 4.788589] Call trace:
[ 4.789495] cm_work_handler+0xf40/0x1098 (P)
[ 4.790774] process_one_work+0x5f0/0xcb8
[ 4.791270] worker_thread+0x3ac/0xaa0
[ 4.791781] kthread+0x36c/0x420
[ 4.792361] ret_from_fork+0x10/0x20
[ 4.792811] Code: 978e5ca5 17ffff33 978e5c73 17fffefa (d4210000)
[ 4.793544] ---[ end trace 0000000000000000 ]---
Handle CLOSE in CONN_RECV as a failed connection: move the ID to IDLE,
clear the connect wait flag, report -ECONNRESET if the provider gave
status zero, and wake any waiters. Also ignore an ESTABLISHED event that
arrives after CLOSE or a destroy has already moved the ID to IDLE or
DESTROYING.
Fixes: 6c52fdc244b5 ("rdma/siw: connection management")
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
---
Leon, here's v4 as a new thread with the full trace, like you asked.
Here's what this patch is about. cm_close_handler() only expects CLOSE
after the connection is established. When the peer sends a malformed RTR
frame, siw reports CLOSE while the passive ID is still in CONN_RECV, and
that lands in the BUG(). I didn't fix it in siw, because if siw reported
ESTABLISHED with an error status instead, cm_conn_est_handler() would
still move the ID to ESTABLISHED and the CMA would deliver
RDMA_CM_EVENT_ESTABLISHED.
The change in cm_conn_est_handler() is for an ESTABLISHED event that's
already queued when CLOSE gets there first. It then arrives after the ID
is IDLE or DESTROYING. I only saw that ordering with test-only delays in
siw and IWCM.
Like in my last patch, to be 100% transparent about AI use: OpenAI GPT-6
(Codex) found this while it was reproducing a different siw bug that my
Quality Playbook skill
(https://github.com/andrewstellman/quality-playbook) turned up, and
GPT-6 drafted the fix. I used Claude Opus 5.5 to help me read the BUG()
report and the code, and to help me write this up.
For the red-green test, the malformed RTR hit the BUG() above without
the patch. With it, the server got RDMA_CM_EVENT_DISCONNECTED with
status -104 and no BUG(). A valid RTR still got ESTABLISHED then
DISCONNECTED, and rping finished three exchanges.
I tested it on mainline ca20d5a011d3 (7.4.0-rc4) in arm64 QEMU with
KASAN, with the peer running as uid 1000 and no capabilities. The
unpatched BUG() above was at f93eb7cfc4bf.
v4: no code change from v3; new thread, full trace, new description.
v3: https://lore.kernel.org/r/20261130044601.28226-1-bugs@stellman-greene.com
v2: https://lore.kernel.org/r/20261129135257.80754-1-bugs@stellman-greene.com
v1: https://lore.kernel.org/r/20261129001745.78689-1-bugs@stellman-greene.com
A reproducer is available on request.
drivers/infiniband/core/iwcm.c | 26 +++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)
diff --git a/drivers/infiniband/core/iwcm.c b/drivers/infiniband/core/iwcm.c
index 4b05867dad895..e03e97cd98c8b 100644
--- a/drivers/infiniband/core/iwcm.c
+++ b/drivers/infiniband/core/iwcm.c
@@ -843,9 +843,10 @@ static void cm_conn_req_handler(struct iwcm_id_private *listen_id_priv,
* FPDU mode.
*
* This event can only be received in the CONN_RECV state. If the
- * remote peer closed, the ESTABLISHED event would be received followed
- * by the CLOSE event. If the app closes, it will block until we wake
- * it up after processing this event.
+ * remote peer closes after establishment, ESTABLISHED is followed by
+ * CLOSE. If it closes before establishment, CLOSE can arrive first.
+ * If the app closes, it will block until we wake it up after processing
+ * this event.
*/
static int cm_conn_est_handler(struct iwcm_id_private *cm_id_priv,
struct iw_cm_event *iw_event)
@@ -861,6 +862,12 @@ static int cm_conn_est_handler(struct iwcm_id_private *cm_id_priv,
* from a callback handler is not allowed.
*/
clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags);
+ if (cm_id_priv->state == IW_CM_STATE_IDLE ||
+ cm_id_priv->state == IW_CM_STATE_DESTROYING) {
+ /* CLOSE or destroy won the race with passive establishment. */
+ spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+ return 0;
+ }
BUG_ON(cm_id_priv->state != IW_CM_STATE_CONN_RECV);
cm_id_priv->state = IW_CM_STATE_ESTABLISHED;
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
@@ -950,6 +957,8 @@ static int cm_close_handler(struct iwcm_id_private *cm_id_priv,
struct ib_qp *qp;
unsigned long flags;
int ret = 0, notify_event = 0;
+ bool wake_connect = false;
+
spin_lock_irqsave(&cm_id_priv->lock, flags);
qp = cm_id_priv->qp;
cm_id_priv->qp = NULL;
@@ -960,6 +969,15 @@ static int cm_close_handler(struct iwcm_id_private *cm_id_priv,
cm_id_priv->state = IW_CM_STATE_IDLE;
notify_event = 1;
break;
+ case IW_CM_STATE_CONN_RECV:
+ /* The accepted connection closed before establishment. */
+ cm_id_priv->state = IW_CM_STATE_IDLE;
+ clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags);
+ if (!iw_event->status)
+ iw_event->status = -ECONNRESET;
+ notify_event = 1;
+ wake_connect = true;
+ break;
case IW_CM_STATE_DESTROYING:
break;
default:
@@ -971,6 +989,8 @@ static int cm_close_handler(struct iwcm_id_private *cm_id_priv,
cm_id_priv->id.device->ops.iw_rem_ref(qp);
if (notify_event)
ret = cm_id_priv->id.cm_handler(&cm_id_priv->id, iw_event);
+ if (wake_connect)
+ wake_up_all(&cm_id_priv->connect_wait);
return ret;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v4 rdma-rc] RDMA/iwcm: Handle CLOSE before passive establishment
2026-12-02 17:53 [PATCH v4 rdma-rc] RDMA/iwcm: Handle CLOSE before passive establishment Andrew Stellman
@ 2026-12-02 18:07 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-02 18:07 UTC (permalink / raw)
To: Andrew Stellman; +Cc: linux-rdma
> From: Andrew Stellman <astellman@stellman-greene.com>
>
> An accepted siw MPA v2 connection enters RDMA mode before it receives
> the peer's RTR frame. If that frame is malformed, siw reports CLOSE
> while the passive IWCM ID is still in CONN_RECV, and cm_close_handler()
> hits the BUG() for unexpected states:
>
> [ 4.767386] ------------[ cut here ]------------
> [ 4.767396] kernel BUG at drivers/infiniband/core/iwcm.c:966!
> [ 4.767406] Internal error: Oops - BUG: 00000000f2000800 [#1] SMP
> [ 4.770343] Modules linked in:
> [ 4.770836] CPU: 0 UID: 0 PID: 60 Comm: kworker/u32:1 Not tainted 7.4.0-rc4-gf93eb7cfc4bf #14 PREEMPT(full)
> [ 4.771994] Hardware name: linux,dummy-virt (DT)
> [ 4.773423] Workqueue: iw_cm_wq cm_work_handler
> [ 4.774044] pstate: 814000c5 (Nzcv daIF +PAN -UAO -TCO +DIT -SSBS BTYPE=--)
> [ ... ]
> arrives after CLOSE or a destroy has already moved the ID to IDLE or
> DESTROYING.
>
> Fixes: 6c52fdc244b5 ("rdma/siw: connection management")
> Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202175345.70627-1-bugs@stellman-greene.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-02 18:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 17:53 [PATCH v4 rdma-rc] RDMA/iwcm: Handle CLOSE before passive establishment Andrew Stellman
2026-12-02 18:07 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox