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 3/3] net/smc: document the clcsock lifetime
Date: Fri, 20 Nov 2026 13:45:34 +0100	[thread overview]
Message-ID: <20261120124534.430200-4-mjambigi@linux.ibm.com> (raw)
In-Reply-To: <20261120124534.430200-1-mjambigi@linux.ibm.com>

The clcsock is freed only when no socket file can reference it. Record
that invariant where it is relied upon: at the clcsock field, at the
release helper, at the diag dump, which can find a socket before its
clcsock has been created, at the accept cleanup, which must not wait for
the listen work with the child and listener locks held, and in the
destructor, which warns if a clcsock is left.

Freeing the clcsock from the destructor is not possible: it can run from
an RCU callback or a softirq.

Signed-off-by: Mahanta Jambigi <mjambigi@linux.ibm.com>
---
 net/smc/af_smc.c    | 13 +++++++++++++
 net/smc/smc.h       |  4 +++-
 net/smc/smc_close.c |  7 ++++++-
 net/smc/smc_diag.c  |  3 +++
 4 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index cc7fb2d90637..dfe34b5fdc93 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -373,6 +373,14 @@ int smc_release(struct socket *sock)

 static void smc_destruct(struct sock *sk)
 {
+	struct smc_sock *smc = smc_sk(sk);
+
+	/* The destructor can run from an RCU callback or a softirq, where
+	 * sock_release() must not be called. Every path that drops an SMC
+	 * socket therefore releases its clcsock before the final
+	 * sock_put().
+	 */
+	WARN_ON_ONCE(smc->clcsock);
 	if (sk->sk_state != SMC_CLOSED)
 		return;
 	if (!sock_flag(sk, SOCK_DEAD))
@@ -1825,6 +1833,11 @@ struct sock *smc_accept_dequeue(struct sock *parent,
 		lock_sock(new_sk);
 		if (new_sk->sk_state == SMC_CLOSED) {
 			new_sk->sk_prot->unhash(new_sk);
+			/* The child is on the accept queue, so its
+			 * smc_listen_work() no longer uses the clcsock. Do not
+			 * wait for that work here, the child and listener locks
+			 * are held.
+			 */
 			tcp = xchg(&isk->clcsock, NULL);
 			release_sock(new_sk);
 			if (tcp)
diff --git a/net/smc/smc.h b/net/smc/smc.h
index 616bb3245f7b..c6bfe63a947a 100644
--- a/net/smc/smc.h
+++ b/net/smc/smc.h
@@ -288,7 +288,9 @@ struct smc_sock {				/* smc sock container */
 		struct sock		sk;
 		struct inet_sock	icsk_inet;
 	};
-	struct socket		*clcsock;	/* internal tcp socket */
+	struct socket		*clcsock;	/* internal tcp socket, freed
+						 * when no file can use it
+						 */
 	void			(*clcsk_state_change)(struct sock *sk);
 						/* original stat_change fct. */
 	void			(*clcsk_data_ready)(struct sock *sk);
diff --git a/net/smc/smc_close.c b/net/smc/smc_close.c
index e71245dbb296..d359436e5304 100644
--- a/net/smc/smc_close.c
+++ b/net/smc/smc_close.c
@@ -20,7 +20,12 @@
 #include "smc_cdc.h"
 #include "smc_close.h"

-/* release the clcsock that is assigned to the smc_sock */
+/* Release the clcsock.  Call this only after the socket has been
+ * unhashed, and only when no socket file can reach the clcsock: from
+ * smc_release(), from the listener cleanup, and from the abnormal
+ * close paths once the socket has no file left. While a file is open,
+ * the clcsock stays in place until smc_release() runs.
+ */
 void smc_clcsock_release(struct smc_sock *smc)
 {
 	struct socket *tcp;
diff --git a/net/smc/smc_diag.c b/net/smc/smc_diag.c
index 15485a08d9a0..42828ffe90b8 100644
--- a/net/smc/smc_diag.c
+++ b/net/smc/smc_diag.c
@@ -39,6 +39,9 @@ static void smc_diag_msg_common_fill(struct smc_diag_msg *r, struct sock *sk)
 	memset(r, 0, sizeof(*r));
 	r->diag_family = sk->sk_family;
 	sock_diag_save_cookie(sk, r->id.idiag_cookie);
+	/* The socket is hashed in smc_sk_init(), before its clcsock is
+	 * created, so a dump can find it without one.
+	 */
 	if (!smc->clcsock)
 		return;
 	r->id.idiag_sport = htons(smc->clcsock->sk->sk_num);
-- 
2.50.1 (Apple Git-155)


      parent reply	other threads:[~2026-11-20 12:46 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 ` [PATCH net-next 1/3] net/smc: keep clcsock until socket release Mahanta Jambigi
2026-11-20 12:45 ` [PATCH net-next 2/3] net/smc: remove the clcsock release lock Mahanta Jambigi
2026-11-20 12:45 ` Mahanta Jambigi [this message]

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-4-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