🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
1 messages
1 total messages Started by Mahanta Jambigi Fri, 20 Nov 2026 12:45
[PATCH net-next 1/3] net/smc: keep clcsock until socket release
#19805
Author: Mahanta Jambigi
Date: Fri, 20 Nov 2026 12:45
90 lines
15139 bytes
The clcsock of an SMC socket can be freed from asynchronous contexts:
link group termination reaches smc_close_active_abort() and peer close
reaches smc_close_passive_work(), and both can run while the socket is
referenced by an open file. A task that uses the fd then operates on a
released socket.

Free the clcsock only when no socket file can reference it: from the
release paths, and from the abnormal close paths only once the socket
has no file left. __smc_release() now tears the connection down before
it releases the clcsock: smc_conn_kill() and smc_close_passive_work()
check conn->freed and return early once the connection has been freed.

Signed-off-by: Mahanta Jambigi <mjambigi@linux.ibm.com>
---
 net/smc/af_smc.c    |  4 ++--
 net/smc/smc_close.c | 16 +++++++++++++---
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index bfc0c7e71a12..1d8a602729c1 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -313,13 +313,13 @@ static int __smc_release(struct smc_sock *smc)
 	sk->sk_prot->unhash(sk);

 	if (sk->sk_state == SMC_CLOSED) {
+		if (!smc->use_fallback)
+			smc_conn_free(&smc->conn);
 		if (smc->clcsock) {
 			release_sock(sk);
 			smc_clcsock_release(smc);
 			lock_sock(sk);
 		}
-		if (!smc->use_fallback)
-			smc_conn_free(&smc->conn);
 	}

 	return rc;
diff --git a/net/smc/smc_close.c b/net/smc/smc_close.c
index 736abfbd2aaf..cf1add1ffda6 100644
--- a/net/smc/smc_close.c
+++ b/net/smc/smc_close.c
@@ -36,6 +36,14 @@ void smc_clcsock_release(struct smc_sock *smc)
 	mutex_unlock(&smc->clcsock_release_lock);
 }

+/* The clcsock can be released once no socket file can reach it; while a
+ * file is still open, smc_release() releases it.
+ */
+static bool smc_clcsock_can_release(struct smc_sock *smc)
+{
+	return smc->clcsock && !smc->sk.sk_socket;
+}
+
 static void smc_close_cleanup_listen(struct sock *parent)
 {
 	struct sock *sk;
@@ -157,7 +165,8 @@ void smc_close_active_abort(struct smc_sock *smc)
 		sk->sk_state = SMC_CLOSED;
 		sk->sk_prot->unhash(sk);
 		smc_conn_free(&smc->conn);
-		release_clcsock = true;
+		if (smc_clcsock_can_release(smc))
+			release_clcsock = true;
 		sock_put(sk); /* passive closing */
 		break;
 	case SMC_PROCESSABORT:
@@ -169,7 +178,8 @@ void smc_close_active_abort(struct smc_sock *smc)
 		sk->sk_state = SMC_CLOSED;
 		sk->sk_prot->unhash(sk);
 		smc_conn_free(&smc->conn);
-		release_clcsock = true;
+		if (smc_clcsock_can_release(smc))
+			release_clcsock = true;
 		break;
 	case SMC_INIT:
 	case SMC_PEERABORTWAIT:
@@ -452,7 +462,7 @@ static void smc_close_passive_work(struct work_struct *work)
 		    (sock_flag(sk, SOCK_DEAD) || !sk->sk_socket)) {
 			sk->sk_prot->unhash(sk);
 			smc_conn_free(conn);
-			if (smc->clcsock)
+			if (smc_clcsock_can_release(smc))
 				release_clcsock = true;
 		}
 	}
-- 
2.50.1 (Apple Git-155)
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads