Skip to contentSkip to conversation

net/smc: fix link group ownership in handshake abort

PATCH New Mahanta Jambigi 2 participants 2 messages Nov 6

Subsystems (6)
lore
Share & tools
lore

Mahanta Jambigi

author maintainer
#0 lore raw

PATCH v2 1/1 net/smc: fix link group ownership in handshake abort

An aborted first-contact handshake can hang the handshake worker on the socket lock it already holds, reset the clcsock of a socket that has fallen back to TCP, or corrupt the alert-node lookup when the handshake retries with the same connection.

The abort leaves a connection registered in a link group that another context has already unlinked for termination: smc_conn_free() skips the unregister when lgr->list is empty, so the alert token and alert node stay in lgr->conns_all. If the handshake retries another device or SMC version, smc_conn_create() creates a second link group and smc_lgr_register_conn() inserts the same alert node into it: the token loop is skipped, rb_link_node() links a node that is still in the old tree into the new one, and a second sock_hold() is taken where only one sock_put() will follow. The old group's terminator then keeps returning that node from rb_first() and can kill a connection that now belongs to the new group.

smc_lgr_cleanup_early() also starts a second termination of the link group that is already being terminated, which takes lock_sock() on the socket the handshake worker holds; if the termination work wins the race instead, it later kills the freed connection and aborts the clcsock of a socket that has fallen back to TCP. Making the unregister unconditional also lets smc_conn_free() reach the delayed free work on a claimed link group, where the lockless freeing check can arm it after the owner has cancelled it.

Always unregister the connection, claim a link group for termination once under lgr_lock, keep the link group alive across the abort, and arm the delayed free work only under the same lock and cancel it synchronously before the teardown. Drop an already freed connection in smc_conn_kill() without running the connection and socket teardown.

Fixes 2a0674fffb6b ("net/smc: improve abnormal termination of link groups")
Fixes f9aab6f2ce57 ("net/smc: immediate freeing in smc_lgr_cleanup_early()")
---
 net/smc/af_smc.c   | 11 ++++----
 net/smc/smc_core.c | 78 +++++++++++++++++++++++++++++++++++++++---------------
 net/smc/smc_core.h |  6 ++---
 3 files changed, 65 insertions(+), 30 deletions(-)

Changelog:
v2:
- Always unregister the connection in smc_conn_free(), so a handshake that retries another device or SMC version cannot leave a stale alert node in a link group it is leaving.
- Claim link group termination once, under lgr_lock, in a helper shared by smc_lgr_cleanup_early() and smc_lgr_terminate_sched(); testing list_empty() alone missed a link group another context had already unlinked.
- Hold a link group reference across smc_conn_free() and smc_lgr_cleanup_early().
- Arm the delayed free work under lgr_lock, cancel it synchronously before the teardown, and skip a connection that was re-registered in another link group.
- Do not share one storage unit between sync_err, terminating and freeing.

net/smc/af_smc.c +6 -5
index d10244af5bd2..db93cbeee9c8 100644
@@ -1013,14 +1013,15 @@ static void smc_conn_abort(struct smc_sock *smc, int local_first)
 {
 	struct smc_connection *conn = &smc->conn;
 	struct smc_link_group *lgr = conn->lgr;
-	bool lgr_valid = false;
-
-	if (smc_conn_lgr_valid(conn))
-		lgr_valid = true;
+	bool lgr_valid = local_first && smc_conn_lgr_valid(conn);
 
+	if (lgr_valid)
+		smc_lgr_hold(lgr);	/* lgr_put below */
 	smc_conn_free(conn);
-	if (local_first && lgr_valid)
+	if (lgr_valid) {
 		smc_lgr_cleanup_early(lgr);
+		smc_lgr_put(lgr);
+	}
 }
 
 /* check if there is a rdma device available for this connection. */
net/smc/smc_core.c +56 -22

143 lines not on this page · raw message

net/smc/smc_core.h +3 -3
index 5c18f08a4c8a..bff4c9e17792 100644
@@ -301,9 +301,9 @@ struct smc_link_group {
 	struct delayed_work	free_work;	/* delayed freeing of an lgr */
 	struct work_struct	terminate_work;	/* abnormal lgr termination */
 	struct workqueue_struct	*tx_wq;		/* wq for conn. tx workers */
-	u8			sync_err : 1;	/* lgr no longer fits to peer */
-	u8			terminating : 1;/* lgr is terminating */
-	u8			freeing : 1;	/* lgr is being freed */
+	u8			sync_err;	/* lgr no longer fits to peer */
+	u8			terminating;	/* lgr is terminating */
+	u8			freeing;	/* lgr is being freed */
 
 	refcount_t		refcnt;		/* lgr reference count */
 	bool			is_smcd;	/* SMC-R or SMC-D */
#1 lore raw
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

- Whether the issue was actually triggered, or is only theoretical (e.g. found by code inspection). If it was triggered please include the symptoms, like the stack trace or error messages.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.

The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.