Netdev List
 help / color / mirror / Atom feed
* [PATCH net] net/smc: abort old connection when peer reuses RMB element
@ 2026-11-29  0:17 Andrew Stellman
  2026-12-01  8:39 ` Mahanta Jambigi
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Stellman @ 2026-11-29  0:17 UTC (permalink / raw)
  To: D. Wythe, Dust Li, Sidraya Jayagond, Mahanta Jambigi
  Cc: Tony Lu, Wen Gu, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman, Willem de Bruijn, linux-rdma,
	linux-s390, netdev

From: Andrew Stellman <astellman@stellman-greene.com>

If a peer repeats an RMB rkey and DMA address in a later CLC handshake,
smc_rtoken_add() reuses the existing rtoken slot. If the peer also
repeats the RMB element index, two connections in the link group write
to the same peer buffer.

After resolving the rtoken, abort any existing connection that has the
same rtoken and element index. Set rtoken_idx to -1 in
smc_conn_create() so a connection still in its handshake can't match.
Both handshake paths already hold the new socket's lock, so take the
old one with lock_sock_nested(), and keep that lock class when
smc_close_active_abort() drops and retakes it.

The abort is synchronous because, from the source, queueing the old
connection's abort_work instead looks unsafe: a close path can call
smc_conn_free() with the socket lock held and wait in
cancel_work_sync() for that work, which needs the same lock, and a
cancelled work item never drops the socket reference taken for it.

This changes existing behaviour: when a peer presents an rtoken and
element index that another connection on the link group is using, the
older connection is now aborted.

Tested on mainline in arm64 QEMU with KASAN, lockdep and SoftRoCE. With
a test-only peer that repeated the first connection's rtoken and element
index in a second ACCEPT and a second CONFIRM, the old server socket
read the second connection's data before the patch; after it, send() on
both old sockets failed with EPIPE, with no lockdep or KASAN warning.
Ordinary two-connection traffic passed with and without the patch.

The issue was found by Claude Opus 5 running Quality Playbook, an
LLM-driven code review tool:
https://github.com/andrewstellman/quality-playbook
The fix was drafted with OpenAI GPT-6 (Codex) and this changelog with
Claude Opus 5.5, and both were reviewed by me.

Fixes: bd4ad57718cc ("smc: initialize IB transport incl. PD, MR, QP, CQ, event, WR")
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
---
A reproducer is available on request.

 net/smc/af_smc.c    |  2 +-
 net/smc/smc_close.c | 20 +++++++++++++-------
 net/smc/smc_close.h |  2 +-
 net/smc/smc_core.c  | 46 +++++++++++++++++++++++++++++++++++++++++----
 4 files changed, 57 insertions(+), 13 deletions(-)

diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index bfc0c7e71a12b4..fbf710f4308818 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -356,7 +356,7 @@ int smc_release(struct socket *sock)
 
 	if (old_state == SMC_INIT && sk->sk_state == SMC_ACTIVE &&
 	    !smc->use_fallback)
-		smc_close_active_abort(smc);
+		smc_close_active_abort(smc, false);
 
 	rc = __smc_release(smc);
 
diff --git a/net/smc/smc_close.c b/net/smc/smc_close.c
index 736abfbd2aafaa..88c82a7b74efd9 100644
--- a/net/smc/smc_close.c
+++ b/net/smc/smc_close.c
@@ -111,7 +111,7 @@ int smc_close_abort(struct smc_connection *conn)
 	return smc_cdc_get_slot_and_msg_send(conn);
 }
 
-static void smc_close_cancel_work(struct smc_sock *smc)
+static void smc_close_cancel_work(struct smc_sock *smc, bool nested)
 {
 	struct sock *sk = &smc->sk;
 
@@ -120,13 +120,16 @@ static void smc_close_cancel_work(struct smc_sock *smc)
 		sock_put(sk);
 	if (cancel_delayed_work_sync(&smc->conn.tx_work))
 		sock_put(sk);
-	lock_sock(sk);
+	if (nested)
+		lock_sock_nested(sk, SINGLE_DEPTH_NESTING);
+	else
+		lock_sock(sk);
 }
 
 /* terminate smc socket abnormally - active abort
  * link group is terminated, i.e. RDMA communication no longer possible
  */
-void smc_close_active_abort(struct smc_sock *smc)
+void smc_close_active_abort(struct smc_sock *smc, bool nested)
 {
 	struct sock *sk = &smc->sk;
 	bool release_clcsock = false;
@@ -141,7 +144,7 @@ void smc_close_active_abort(struct smc_sock *smc)
 	case SMC_APPCLOSEWAIT1:
 	case SMC_APPCLOSEWAIT2:
 		sk->sk_state = SMC_PEERABORTWAIT;
-		smc_close_cancel_work(smc);
+		smc_close_cancel_work(smc, nested);
 		if (sk->sk_state != SMC_PEERABORTWAIT)
 			break;
 		sk->sk_state = SMC_CLOSED;
@@ -151,7 +154,7 @@ void smc_close_active_abort(struct smc_sock *smc)
 	case SMC_PEERCLOSEWAIT2:
 	case SMC_PEERFINCLOSEWAIT:
 		sk->sk_state = SMC_PEERABORTWAIT;
-		smc_close_cancel_work(smc);
+		smc_close_cancel_work(smc, nested);
 		if (sk->sk_state != SMC_PEERABORTWAIT)
 			break;
 		sk->sk_state = SMC_CLOSED;
@@ -163,7 +166,7 @@ void smc_close_active_abort(struct smc_sock *smc)
 	case SMC_PROCESSABORT:
 	case SMC_APPFINCLOSEWAIT:
 		sk->sk_state = SMC_PEERABORTWAIT;
-		smc_close_cancel_work(smc);
+		smc_close_cancel_work(smc, nested);
 		if (sk->sk_state != SMC_PEERABORTWAIT)
 			break;
 		sk->sk_state = SMC_CLOSED;
@@ -183,7 +186,10 @@ void smc_close_active_abort(struct smc_sock *smc)
 	if (release_clcsock) {
 		release_sock(sk);
 		smc_clcsock_release(smc);
-		lock_sock(sk);
+		if (nested)
+			lock_sock_nested(sk, SINGLE_DEPTH_NESTING);
+		else
+			lock_sock(sk);
 	}
 }
 
diff --git a/net/smc/smc_close.h b/net/smc/smc_close.h
index 634fea2b7c95b1..1fa9bc211f4751 100644
--- a/net/smc/smc_close.h
+++ b/net/smc/smc_close.h
@@ -25,6 +25,6 @@ int smc_close_shutdown_write(struct smc_sock *smc);
 void smc_close_init(struct smc_sock *smc);
 void smc_clcsock_release(struct smc_sock *smc);
 int smc_close_abort(struct smc_connection *conn);
-void smc_close_active_abort(struct smc_sock *smc);
+void smc_close_active_abort(struct smc_sock *smc, bool nested);
 
 #endif /* SMC_CLOSE_H */
diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
index a3164201c14204..cb45c36cdce66d 100644
--- a/net/smc/smc_core.c
+++ b/net/smc/smc_core.c
@@ -1537,7 +1537,7 @@ static void smc_sk_wake_ups(struct smc_sock *smc)
 }
 
 /* kill a connection */
-static void smc_conn_kill(struct smc_connection *conn, bool soft)
+static void smc_conn_kill(struct smc_connection *conn, bool soft, bool nested)
 {
 	struct smc_sock *smc = container_of(conn, struct smc_sock, conn);
 
@@ -1571,7 +1571,7 @@ static void smc_conn_kill(struct smc_connection *conn, bool soft)
 		smc_cdc_wait_pend_tx_wr(conn);
 	}
 	smc_lgr_unregister_conn(conn);
-	smc_close_active_abort(smc);
+	smc_close_active_abort(smc, nested);
 }
 
 static void smc_lgr_cleanup(struct smc_link_group *lgr)
@@ -1625,7 +1625,7 @@ static void __smc_lgr_terminate(struct smc_link_group *lgr, bool soft)
 		 * link group by a retried handshake in the meantime.
 		 */
 		if (conn->lgr == lgr)
-			smc_conn_kill(conn, soft);
+			smc_conn_kill(conn, soft, false);
 		release_sock(&smc->sk);
 		sock_put(&smc->sk); /* sock_hold above */
 		read_lock_bh(&lgr->conns_lock);
@@ -1788,7 +1788,7 @@ static void smc_conn_abort_work(struct work_struct *work)
 	struct smc_sock *smc = container_of(conn, struct smc_sock, conn);
 
 	lock_sock(&smc->sk);
-	smc_conn_kill(conn, true);
+	smc_conn_kill(conn, true, false);
 	release_sock(&smc->sk);
 	sock_put(&smc->sk); /* sock_hold done by schedulers of abort_work */
 }
@@ -2024,6 +2024,7 @@ int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini)
 	spinlock_t *lgr_lock;
 	int rc = 0;
 
+	conn->rtoken_idx = -1;
 	lgr_list = ini->is_smcd ? &ini->ism_dev[ini->ism_selected]->lgr_list :
 				  &smc_lgr_list.list;
 	lgr_lock = ini->is_smcd ? &ini->ism_dev[ini->ism_selected]->lgr_lock :
@@ -2757,6 +2758,42 @@ int smc_rtoken_delete(struct smc_link *lnk, __be32 nw_rkey)
 	return -ENOENT;
 }
 
+/* Abort a connection if the peer reuses its RMB element for this handshake. */
+static void smc_rtoken_resolve_conflict(struct smc_connection *conn, u8 rmbe_idx)
+{
+	struct smc_link_group *lgr = conn->lgr;
+	struct smc_connection *old;
+	struct smc_sock *old_smc;
+	struct rb_node *node;
+
+	for (;;) {
+		read_lock_bh(&lgr->conns_lock);
+		for (node = rb_first(&lgr->conns_all); node; node = rb_next(node)) {
+			old = rb_entry(node, struct smc_connection, alert_node);
+			if (old != conn && !old->freed &&
+			    old->rtoken_idx >= 0 &&
+			    old->rtoken_idx == conn->rtoken_idx &&
+			    old->peer_rmbe_idx == rmbe_idx)
+				break;
+		}
+		if (!node) {
+			read_unlock_bh(&lgr->conns_lock);
+			return;
+		}
+		old_smc = container_of(old, struct smc_sock, conn);
+		sock_hold(&old_smc->sk);
+		read_unlock_bh(&lgr->conns_lock);
+
+		lock_sock_nested(&old_smc->sk, SINGLE_DEPTH_NESTING);
+		if (old->lgr == lgr && old->alert_token_local && !old->freed &&
+		    old->rtoken_idx == conn->rtoken_idx &&
+		    old->peer_rmbe_idx == rmbe_idx)
+			smc_conn_kill(old, true, true);
+		release_sock(&old_smc->sk);
+		sock_put(&old_smc->sk);
+	}
+}
+
 /* save rkey and dma_addr received from peer during clc handshake */
 int smc_rmb_rtoken_handling(struct smc_connection *conn,
 			    struct smc_link *lnk,
@@ -2766,6 +2803,7 @@ int smc_rmb_rtoken_handling(struct smc_connection *conn,
 					  clc->r0.rmb_rkey);
 	if (conn->rtoken_idx < 0)
 		return conn->rtoken_idx;
+	smc_rtoken_resolve_conflict(conn, clc->r0.rmbe_idx);
 	return 0;
 }
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net/smc: abort old connection when peer reuses RMB element
  2026-11-29  0:17 [PATCH net] net/smc: abort old connection when peer reuses RMB element Andrew Stellman
@ 2026-12-01  8:39 ` Mahanta Jambigi
  2026-12-01 13:33   ` Andrew Stellman
  0 siblings, 1 reply; 3+ messages in thread
From: Mahanta Jambigi @ 2026-12-01  8:39 UTC (permalink / raw)
  To: Andrew Stellman, D. Wythe, Dust Li, Sidraya Jayagond
  Cc: Tony Lu, Wen Gu, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman, Willem de Bruijn, linux-rdma,
	linux-s390, netdev



On 29/11/26 5:47 am, Andrew Stellman wrote:
> From: Andrew Stellman <astellman@stellman-greene.com>
> 
> If a peer repeats an RMB rkey and DMA address in a later CLC handshake,
> smc_rtoken_add() reuses the existing rtoken slot. If the peer also
> repeats the RMB element index, two connections in the link group write
> to the same peer buffer.

The rkey and DMA address are not per connection. The peer registers its
RMB once per link, and smc_tx_rdma_write() adds tx_off and the element
offset to lgr->rtokens[conn->rtoken_idx][link->link_idx].dma_addr. Every
connection to the same peer on that link therefore shares the rtoken
slot by design, and the duplicate that matters is only peer_rmbe_idx. As
written the paragraph reads like the shared rtoken is the bug; worth
rewording around the element index.

> 
> After resolving the rtoken, abort any existing connection that has the
> same rtoken and element index. Set rtoken_idx to -1 in
> smc_conn_create() so a connection still in its handshake can't match.
> Both handshake paths already hold the new socket's lock, so take the
> old one with lock_sock_nested(), and keep that lock class when
> smc_close_active_abort() drops and retakes it.
> 
> The abort is synchronous because, from the source, queueing the old
> connection's abort_work instead looks unsafe: a close path can call
> smc_conn_free() with the socket lock held and wait in
> cancel_work_sync() for that work, which needs the same lock, and a
> cancelled work item never drops the socket reference taken for it.

That cancelled-work reference leak is being fixed separately in
"net/smc: fix sock reference leak on abort_work cancel". Once it lands, the
asynchronous variant deserves another look, since it would remove the
lock nesting that the comment above is about.

> 
> This changes existing behaviour: when a peer presents an rtoken and
> element index that another connection on the link group is using, the
> older connection is now aborted.
> 
> Tested on mainline in arm64 QEMU with KASAN, lockdep and SoftRoCE. With
> a test-only peer that repeated the first connection's rtoken and element
> index in a second ACCEPT and a second CONFIRM, the old server socket
> read the second connection's data before the patch; after it, send() on
> both old sockets failed with EPIPE, with no lockdep or KASAN warning.
> Ordinary two-connection traffic passed with and without the patch.
> 
> The issue was found by Claude Opus 5 running Quality Playbook, an
> LLM-driven code review tool:
> https://github.com/andrewstellman/quality-playbook
> The fix was drafted with OpenAI GPT-6 (Codex) and this changelog with
> Claude Opus 5.5, and both were reviewed by me.
> 
> Fixes: bd4ad57718cc ("smc: initialize IB transport incl. PD, MR, QP, CQ, event, WR")
> Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
> ---
> A reproducer is available on request.
> 
>  net/smc/af_smc.c    |  2 +-
>  net/smc/smc_close.c | 20 +++++++++++++-------
>  net/smc/smc_close.h |  2 +-
>  net/smc/smc_core.c  | 46 +++++++++++++++++++++++++++++++++++++++++----
>  4 files changed, 57 insertions(+), 13 deletions(-)
> 
> diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
> index bfc0c7e71a12b4..fbf710f4308818 100644
> --- a/net/smc/af_smc.c
> +++ b/net/smc/af_smc.c
> @@ -356,7 +356,7 @@ int smc_release(struct socket *sock)
>  
>  	if (old_state == SMC_INIT && sk->sk_state == SMC_ACTIVE &&
>  	    !smc->use_fallback)
> -		smc_close_active_abort(smc);
> +		smc_close_active_abort(smc, false);
>  
>  	rc = __smc_release(smc);
>  
> diff --git a/net/smc/smc_close.c b/net/smc/smc_close.c
> index 736abfbd2aafaa..88c82a7b74efd9 100644
> --- a/net/smc/smc_close.c
> +++ b/net/smc/smc_close.c
> @@ -111,7 +111,7 @@ int smc_close_abort(struct smc_connection *conn)
>  	return smc_cdc_get_slot_and_msg_send(conn);
>  }
>  
> -static void smc_close_cancel_work(struct smc_sock *smc)
> +static void smc_close_cancel_work(struct smc_sock *smc, bool nested)
>  {
>  	struct sock *sk = &smc->sk;
>  
> @@ -120,13 +120,16 @@ static void smc_close_cancel_work(struct smc_sock *smc)
>  		sock_put(sk);
>  	if (cancel_delayed_work_sync(&smc->conn.tx_work))
>  		sock_put(sk);
> -	lock_sock(sk);
> +	if (nested)
> +		lock_sock_nested(sk, SINGLE_DEPTH_NESTING);
> +	else
> +		lock_sock(sk);
>  }
>  
>  /* terminate smc socket abnormally - active abort
>   * link group is terminated, i.e. RDMA communication no longer possible
>   */
> -void smc_close_active_abort(struct smc_sock *smc)
> +void smc_close_active_abort(struct smc_sock *smc, bool nested)
>  {
>  	struct sock *sk = &smc->sk;
>  	bool release_clcsock = false;
> @@ -141,7 +144,7 @@ void smc_close_active_abort(struct smc_sock *smc)
>  	case SMC_APPCLOSEWAIT1:
>  	case SMC_APPCLOSEWAIT2:
>  		sk->sk_state = SMC_PEERABORTWAIT;
> -		smc_close_cancel_work(smc);
> +		smc_close_cancel_work(smc, nested);
>  		if (sk->sk_state != SMC_PEERABORTWAIT)
>  			break;
>  		sk->sk_state = SMC_CLOSED;
> @@ -151,7 +154,7 @@ void smc_close_active_abort(struct smc_sock *smc)
>  	case SMC_PEERCLOSEWAIT2:
>  	case SMC_PEERFINCLOSEWAIT:
>  		sk->sk_state = SMC_PEERABORTWAIT;
> -		smc_close_cancel_work(smc);
> +		smc_close_cancel_work(smc, nested);
>  		if (sk->sk_state != SMC_PEERABORTWAIT)
>  			break;
>  		sk->sk_state = SMC_CLOSED;
> @@ -163,7 +166,7 @@ void smc_close_active_abort(struct smc_sock *smc)
>  	case SMC_PROCESSABORT:
>  	case SMC_APPFINCLOSEWAIT:
>  		sk->sk_state = SMC_PEERABORTWAIT;
> -		smc_close_cancel_work(smc);
> +		smc_close_cancel_work(smc, nested);
>  		if (sk->sk_state != SMC_PEERABORTWAIT)
>  			break;
>  		sk->sk_state = SMC_CLOSED;
> @@ -183,7 +186,10 @@ void smc_close_active_abort(struct smc_sock *smc)
>  	if (release_clcsock) {
>  		release_sock(sk);
>  		smc_clcsock_release(smc);
> -		lock_sock(sk);
> +		if (nested)
> +			lock_sock_nested(sk, SINGLE_DEPTH_NESTING);
> +		else
> +			lock_sock(sk);
>  	}
>  }
>  
> diff --git a/net/smc/smc_close.h b/net/smc/smc_close.h
> index 634fea2b7c95b1..1fa9bc211f4751 100644
> --- a/net/smc/smc_close.h
> +++ b/net/smc/smc_close.h
> @@ -25,6 +25,6 @@ int smc_close_shutdown_write(struct smc_sock *smc);
>  void smc_close_init(struct smc_sock *smc);
>  void smc_clcsock_release(struct smc_sock *smc);
>  int smc_close_abort(struct smc_connection *conn);
> -void smc_close_active_abort(struct smc_sock *smc);
> +void smc_close_active_abort(struct smc_sock *smc, bool nested);

Not a bug, but the flag is threaded through three shared helpers for one
new caller. A private __smc_close_active_abort(smc, nested) would keep
the existing signature and callers untouched.

>  
>  #endif /* SMC_CLOSE_H */
> diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
> index a3164201c14204..cb45c36cdce66d 100644
> --- a/net/smc/smc_core.c
> +++ b/net/smc/smc_core.c
> @@ -1537,7 +1537,7 @@ static void smc_sk_wake_ups(struct smc_sock *smc)
>  }
>  
>  /* kill a connection */
> -static void smc_conn_kill(struct smc_connection *conn, bool soft)
> +static void smc_conn_kill(struct smc_connection *conn, bool soft, bool nested)
>  {
>  	struct smc_sock *smc = container_of(conn, struct smc_sock, conn);
>  
> @@ -1571,7 +1571,7 @@ static void smc_conn_kill(struct smc_connection *conn, bool soft)
>  		smc_cdc_wait_pend_tx_wr(conn);
>  	}
>  	smc_lgr_unregister_conn(conn);
> -	smc_close_active_abort(smc);
> +	smc_close_active_abort(smc, nested);
>  }
>  
>  static void smc_lgr_cleanup(struct smc_link_group *lgr)
> @@ -1625,7 +1625,7 @@ static void __smc_lgr_terminate(struct smc_link_group *lgr, bool soft)
>  		 * link group by a retried handshake in the meantime.
>  		 */
>  		if (conn->lgr == lgr)
> -			smc_conn_kill(conn, soft);
> +			smc_conn_kill(conn, soft, false);
>  		release_sock(&smc->sk);
>  		sock_put(&smc->sk); /* sock_hold above */
>  		read_lock_bh(&lgr->conns_lock);
> @@ -1788,7 +1788,7 @@ static void smc_conn_abort_work(struct work_struct *work)
>  	struct smc_sock *smc = container_of(conn, struct smc_sock, conn);
>  
>  	lock_sock(&smc->sk);
> -	smc_conn_kill(conn, true);
> +	smc_conn_kill(conn, true, false);
>  	release_sock(&smc->sk);
>  	sock_put(&smc->sk); /* sock_hold done by schedulers of abort_work */
>  }
> @@ -2024,6 +2024,7 @@ int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini)
>  	spinlock_t *lgr_lock;
>  	int rc = 0;
>  
> +	conn->rtoken_idx = -1;
>  	lgr_list = ini->is_smcd ? &ini->ism_dev[ini->ism_selected]->lgr_list :
>  				  &smc_lgr_list.list;
>  	lgr_lock = ini->is_smcd ? &ini->ism_dev[ini->ism_selected]->lgr_lock :
> @@ -2757,6 +2758,42 @@ int smc_rtoken_delete(struct smc_link *lnk, __be32 nw_rkey)
>  	return -ENOENT;
>  }
>  
> +/* Abort a connection if the peer reuses its RMB element for this handshake. */
> +static void smc_rtoken_resolve_conflict(struct smc_connection *conn, u8 rmbe_idx)
> +{
> +	struct smc_link_group *lgr = conn->lgr;
> +	struct smc_connection *old;
> +	struct smc_sock *old_smc;
> +	struct rb_node *node;
> +
> +	for (;;) {
> +		read_lock_bh(&lgr->conns_lock);
> +		for (node = rb_first(&lgr->conns_all); node; node = rb_next(node)) {
> +			old = rb_entry(node, struct smc_connection, alert_node);
> +			if (old != conn && !old->freed &&
> +			    old->rtoken_idx >= 0 &&
> +			    old->rtoken_idx == conn->rtoken_idx &&
> +			    old->peer_rmbe_idx == rmbe_idx)
> +				break;
> +		}
> +		if (!node) {
> +			read_unlock_bh(&lgr->conns_lock);
> +			return;
> +		}
> +		old_smc = container_of(old, struct smc_sock, conn);
> +		sock_hold(&old_smc->sk);
> +		read_unlock_bh(&lgr->conns_lock);
> +
> +		lock_sock_nested(&old_smc->sk, SINGLE_DEPTH_NESTING);

Can two handshakes deadlock here?

Both handshake workers hold their own socket lock for the whole handshake:
smc_connect_work() takes smc->sk before __smc_connect(), and
smc_listen_work() holds new_smc->sk until smc_listen_out(). This takes
the second socket's lock while the first is still held, and
SINGLE_DEPTH_NESTING is a lockdep annotation, not a deadlock prevention.

Two connections that resolve the same peer element at the same time then
form a cycle: A holds sk(A) and takes sk(B), B holds sk(B) and takes
sk(A). The window is small, rtoken_idx is set just before the scan, but
the peer controls the timing: two connections opened together with the
same rmbe_idx put both workers into it, and both sleep in D state with
their locks held. That is a remote hang against smc_hs_wq, and it comes
from exactly the duplicated element this patch is about. A correct peer
never hands one element to two live connections, so this is buggy or
hostile peer territory rather than normal traffic, but it is the case
the patch has to survive.

> +		if (old->lgr == lgr && old->alert_token_local && !old->freed &&
> +		    old->rtoken_idx == conn->rtoken_idx &&
> +		    old->peer_rmbe_idx == rmbe_idx)
> +			smc_conn_kill(old, true, true);
> +		release_sock(&old_smc->sk);
> +		sock_put(&old_smc->sk);
> +	}
> +}
> +
>  /* save rkey and dma_addr received from peer during clc handshake */
>  int smc_rmb_rtoken_handling(struct smc_connection *conn,
>  			    struct smc_link *lnk,
> @@ -2766,6 +2803,7 @@ int smc_rmb_rtoken_handling(struct smc_connection *conn,
>  					  clc->r0.rmb_rkey);
>  	if (conn->rtoken_idx < 0)
>  		return conn->rtoken_idx;
> +	smc_rtoken_resolve_conflict(conn, clc->r0.rmbe_idx);

On the client this runs with smc_client_lgr_pending held:
smc_connect_rdma() takes the mutex before smc_conn_create() and releases
it after smc_rmb_rtoken_handling(). If the resolve blocks on an old
connection's socket lock, for example a passive connection still waiting
for its CONFIRM, which holds that lock for the CLC timeout, then every
client-side connect stalls behind the global mutex. Either move the
resolve outside the mutex or make it non-blocking for handshaking
connections, as above.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net/smc: abort old connection when peer reuses RMB element
  2026-12-01  8:39 ` Mahanta Jambigi
@ 2026-12-01 13:33   ` Andrew Stellman
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Stellman @ 2026-12-01 13:33 UTC (permalink / raw)
  To: Mahanta Jambigi, D. Wythe, Dust Li, Sidraya Jayagond
  Cc: Tony Lu, Wen Gu, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman, Willem de Bruijn, linux-rdma,
	linux-s390, netdev

On Tue, Dec 01, 2026 at 02:09:51PM +0530, Mahanta Jambigi wrote:
> Can two handshakes deadlock here?

Thanks for the careful review. I agree with all of it, and I'd like to
withdraw this version.

A follow-up test on my side also found that a connection killed this
way keeps its send buffer and RMB marked as in use on the link group,
the leak Sashiko flagged. Together with the deadlock you describe and
the stall behind smc_client_lgr_pending, I don't have a safe small fix
for this version.

I'll wait for "net/smc: fix sock reference leak on abort_work cancel"
to land and then look at the asynchronous approach. When I send that,
I'll word the changelog around the duplicated element index rather
than the shared rtoken.

Andrew

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-01 13:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29  0:17 [PATCH net] net/smc: abort old connection when peer reuses RMB element Andrew Stellman
2026-12-01  8:39 ` Mahanta Jambigi
2026-12-01 13:33   ` Andrew Stellman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox