Netdev List
 help / color / mirror / Atom feed
From: Aibing Chen <chenaibing@cmss.chinamobile.com>
To: Allison Henderson <achender@kernel.org>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net v7 1/3] net/rds: register the IB transport last
Date: Fri,  4 Dec 2026 10:22:42 +0800	[thread overview]
Message-ID: <20261204022245.381-2-chenaibing@cmss.chinamobile.com> (raw)
In-Reply-To: <20261204022245.381-1-chenaibing@cmss.chinamobile.com>

rds_rdma_init() calls rds_ib_init(), which registers rds_ib_transport,
and only then creates the RDMA CM listener.  If the listener setup fails,
rds_ib_exit() unregisters the transport again.  Between the two calls the
transport is visible to rds_trans_get_preferred() while the module is
still being initialized, and try_module_get() succeeds for a module in
MODULE_STATE_COMING.  A bind() that races with a failed initialization
can then run ->laddr_check() after do_init_module() freed the module.

Register the transport only once the listener is up, so that it is never
reachable from a module that can still fail to initialize, and unregister
it in rds_rdma_exit() before the transport is torn down.

Signed-off-by: Aibing Chen <chenaibing@cmss.chinamobile.com>
---
 net/rds/ib.c             | 3 ---
 net/rds/rdma_transport.c | 7 ++++++-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/net/rds/ib.c b/net/rds/ib.c
index 4ea9838d0..784d358fe 100644
--- a/net/rds/ib.c
+++ b/net/rds/ib.c
@@ -541,7 +541,6 @@ void rds_ib_exit(void)
 	rds_ib_destroy_nodev_conns();
 	rds_ib_sysctl_exit();
 	rds_ib_recv_exit();
-	rds_trans_unregister(&rds_ib_transport);
 	rds_ib_mr_exit();
 }
 
@@ -605,8 +604,6 @@ int rds_ib_init(void)
 	if (ret)
 		goto out_sysctl;
 
-	rds_trans_register(&rds_ib_transport);
-
 	rds_info_register_func(RDS_INFO_IB_CONNECTIONS, rds_ib_ic_info);
 #if IS_ENABLED(CONFIG_IPV6)
 	rds_info_register_func(RDS6_INFO_IB_CONNECTIONS, rds6_ib_ic_info);
diff --git a/net/rds/rdma_transport.c b/net/rds/rdma_transport.c
index 75532734c..690b8a211 100644
--- a/net/rds/rdma_transport.c
+++ b/net/rds/rdma_transport.c
@@ -344,8 +344,12 @@ static int __init rds_rdma_init(void)
 		goto out;
 
 	ret = rds_rdma_listen_init();
-	if (ret)
+	if (ret) {
 		rds_ib_exit();
+		goto out;
+	}
+
+	rds_trans_register(&rds_ib_transport);
 out:
 	return ret;
 }
@@ -355,6 +359,7 @@ static void __exit rds_rdma_exit(void)
 {
 	/* stop listening first to ensure no new connections are attempted */
 	rds_rdma_listen_stop();
+	rds_trans_unregister(&rds_ib_transport);
 	rds_ib_exit();
 }
 module_exit(rds_rdma_exit);



  reply	other threads:[~2026-12-04  2:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  2:22 [PATCH net v7 0/3] net/rds: fix the probe cm_id lock ordering Aibing Chen
2026-12-04  2:22 ` Aibing Chen [this message]
2026-12-05  3:05   ` [PATCH net v7 1/3] net/rds: register the IB transport last netdev-bot+sashiko
2026-12-04  2:22 ` [PATCH net v7 2/3] net/rds: drop rds_trans_sem around laddr_check() Aibing Chen
2026-12-05  3:05   ` netdev-bot+sashiko
2026-12-04  2:22 ` [PATCH net v7 3/3] net/rds: defer the probe cm_id destroy to rds_wq Aibing Chen
2026-12-05  3:05   ` netdev-bot+sashiko

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=20261204022245.381-2-chenaibing@cmss.chinamobile.com \
    --to=chenaibing@cmss.chinamobile.com \
    --cc=achender@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /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