Netdev List
 help / color / mirror / Atom feed
From: Mahanta Jambigi <mjambigi@linux.ibm.com>
To: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
	kuba@kernel.org, pabeni@redhat.com, alibuda@linux.alibaba.com,
	dust.li@linux.alibaba.com, sidraya@linux.ibm.com
Cc: hidayath@linux.ibm.com, pasic@linux.ibm.com, horms@kernel.org,
	tonylu@linux.alibaba.com, guwen@linux.alibaba.com,
	netdev@vger.kernel.org, linux-s390@vger.kernel.org,
	linux-rdma@vger.kernel.org,
	Mahanta Jambigi <mjambigi@linux.ibm.com>
Subject: [PATCH net-next 1/3] net/smc: keep clcsock until socket release
Date: Fri, 20 Nov 2026 13:45:32 +0100	[thread overview]
Message-ID: <20261120124534.430200-2-mjambigi@linux.ibm.com> (raw)
In-Reply-To: <20261120124534.430200-1-mjambigi@linux.ibm.com>

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)


  reply	other threads:[~2026-11-20 12:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 12:45 [PATCH net-next 0/3] net/smc: fix clcsock lifetime vs asynchronous paths Mahanta Jambigi
2026-11-20 12:45 ` Mahanta Jambigi [this message]
2026-11-20 12:45 ` [PATCH net-next 2/3] net/smc: remove the clcsock release lock Mahanta Jambigi
2026-11-20 12:45 ` [PATCH net-next 3/3] net/smc: document the clcsock lifetime Mahanta Jambigi

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=20261120124534.430200-2-mjambigi@linux.ibm.com \
    --to=mjambigi@linux.ibm.com \
    --cc=alibuda@linux.alibaba.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=dust.li@linux.alibaba.com \
    --cc=edumazet@google.com \
    --cc=guwen@linux.alibaba.com \
    --cc=hidayath@linux.ibm.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pasic@linux.ibm.com \
    --cc=sidraya@linux.ibm.com \
    --cc=tonylu@linux.alibaba.com \
    /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