🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26665

[PATCH net v7 3/3] net/rds: defer the probe cm_id destroy to rds_wq

#26665
From: Aibing Chen
Date: Fri, 04 Dec 2026 02:22
150 lines
13554 bytes
rds_ib_laddr_check() is called from rds_trans_get_preferred(), which runs
both on the bind path and from the passive connection path, where
rdma_cm's handler_mutex is already held:

  cma_ib_req_handler()
    rds_ib_cm_handle_connect()
      rds_conn_create()
        rds_trans_get_preferred()
          rds_ib_laddr_check()
            rdma_destroy_id()
              mutex_lock(&id_priv->handler_mutex)

rdma_destroy_id() takes the handler mutex of the probe id, which is a
different instance of the same lock class, so lockdep reports a recursive
locking dependency as soon as a connection is established.

Destroy the probe id from rds_wq instead, so that the destroy runs without
either rds_trans_sem or handler_mutex held.  The work item is allocated
before rdma_create_id(), so an allocation failure fails the address check
instead of falling back to the synchronous destroy, and the number of
pending destroys is bounded by RDS_IB_MAX_PROBE_PENDING (64).  Above the
bound the check fails with -ENOMEM; callers treat that like any other
unsuccessful laddr_check().

rds_ib_exit() flushes rds_wq before the transport is torn down, so a
queued destroy cannot run after the module text is gone.

Fixes: ec16227e1414 ("RDS/IB: Infiniband transport")
Cc: stable@vger.kernel.org
Signed-off-by: Aibing Chen <chenaibing@cmss.chinamobile.com>
---
 net/rds/ib.c        | 53 +++++++++++++++++++++++++++++++++++++++++++--
 net/rds/transport.c |  7 +++---
 2 files changed, 55 insertions(+), 5 deletions(-)

diff --git a/net/rds/ib.c b/net/rds/ib.c
index 784d358fe..a3ee52fa9 100644
--- a/net/rds/ib.c
+++ b/net/rds/ib.c
@@ -391,6 +391,31 @@ static void rds6_ib_ic_info(struct socket *sock, unsigned int len,
 }
 #endif
 
+/*
+ * The probe cm_id must not be destroyed from the caller's context:
+ * rds_ib_laddr_check() may run while rdma_cm's handler_mutex is held (the
+ * passive connection path), and rdma_destroy_id() takes the handler_mutex
+ * of the probe id, which is a different instance of the same lock class.
+ * Queue the destruction on rds_wq, which runs without either that mutex
+ * or rds_trans_sem.
+ */
+struct rds_ib_probe_work {
+	struct work_struct work;
+	struct rdma_cm_id *cm_id;
+};
+
+static atomic_t rds_ib_probe_pending = ATOMIC_INIT(0);
+#define RDS_IB_MAX_PROBE_PENDING 64
+
+static void rds_ib_probe_work_fn(struct work_struct *work)
+{
+	struct rds_ib_probe_work *pw =
+		container_of(work, struct rds_ib_probe_work, work);
+
+	rdma_destroy_id(pw->cm_id);
+	kfree(pw);
+	atomic_dec(&rds_ib_probe_pending);
+}
 /*
  * Early RDS/IB was built to only bind to an address if there is an IPoIB
  * device with that address set.
@@ -406,6 +431,7 @@ static int rds_ib_laddr_check_cm(struct net *net, const struct in6_addr *addr,
 {
 	int ret;
 	struct rdma_cm_id *cm_id;
+	struct rds_ib_probe_work *pw;
 #if IS_ENABLED(CONFIG_IPV6)
 	struct sockaddr_in6 sin6;
 #endif
@@ -414,11 +440,25 @@ static int rds_ib_laddr_check_cm(struct net *net, const struct in6_addr *addr,
 	bool isv4;
 
 	isv4 = ipv6_addr_v4mapped(addr);
+
+	pw = kzalloc_obj(*pw);
+	if (!pw)
+		return -ENOMEM;
+
+	if (atomic_inc_return(&rds_ib_probe_pending) > RDS_IB_MAX_PROBE_PENDING) {
+		atomic_dec(&rds_ib_probe_pending);
+		kfree(pw);
+		return -ENOMEM;
+	}
+
 	/* Create a CMA ID restricted to IB devices and try to bind it. */
 	cm_id = rdma_create_id(&init_net, rds_rdma_cm_event_handler,
 			       NULL, RDMA_PS_TCP, IB_QPT_RC);
-	if (IS_ERR(cm_id))
+	if (IS_ERR(cm_id)) {
+		kfree(pw);
+		atomic_dec(&rds_ib_probe_pending);
 		return PTR_ERR(cm_id);
+	}
 	ret = rdma_restrict_node_type(cm_id, RDMA_NODE_IB_CA);
 	if (ret)
 		goto out;
@@ -484,7 +524,9 @@ static int rds_ib_laddr_check_cm(struct net *net, const struct in6_addr *addr,
 		 cm_id->device ? cm_id->device->node_type : -1);
 
 out:
-	rdma_destroy_id(cm_id);
+	INIT_WORK(&pw->work, rds_ib_probe_work_fn);
+	pw->cm_id = cm_id;
+	queue_work(rds_wq, &pw->work);
 
 	return ret;
 }
@@ -541,6 +583,13 @@ void rds_ib_exit(void)
 	rds_ib_destroy_nodev_conns();
 	rds_ib_sysctl_exit();
 	rds_ib_recv_exit();
+
+	/*
+	 * rds_ib_laddr_check_cm() may have queued a probe destroy on rds_wq;
+	 * wait for it before the module text goes away.
+	 */
+	flush_workqueue(rds_wq);
+
 	rds_ib_mr_exit();
 }
 
diff --git a/net/rds/transport.c b/net/rds/transport.c
index 4e667580f..cb37d9b08 100644
--- a/net/rds/transport.c
+++ b/net/rds/transport.c
@@ -105,9 +105,10 @@ struct rds_transport *rds_trans_get_preferred(struct net *net,
 			continue;
 
 		/*
-		 * ->laddr_check() may create an rdma_cm id and take
-		 * rdma_cm's handler_mutex.  Don't hold rds_trans_sem
-		 * across it: the module reference keeps trans alive.
+		 * ->laddr_check() creates an rdma_cm id and may reach into
+		 * rdma_cm's locking.  Its destruction is deferred to rds_wq,
+		 * but don't hold rds_trans_sem across the check itself: the
+		 * module reference keeps trans alive.
 		 */
 		up_read(&rds_trans_sem);
 
Technical Details
Message-ID: <20261204022245.381-4-chenaibing@cmss.chinamobile.com>
Path: mbox-mo1.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-nl.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376977-linux-kernel-netdev=dewy.ru
References: <20261204022245.381-1-chenaibing@cmss.chinamobile.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-nl.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376977-linux-kernel-netdev=dewy.ru
From: chenaibing@cmss.chinamobile.com (Aibing Chen)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v7 3/3] net/rds: defer the probe cm_id destroy to rds_wq
Date: Fri,  4 Dec 2026 10:22:44 +0800
Organization: Usenet Network
Message-ID: <20261204022245.381-4-chenaibing@cmss.chinamobile.com>
References: <20261204022245.381-1-chenaibing@cmss.chinamobile.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2655175"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:GsuSsBGfiRSg9hovnzqdw0iz20I= sha256:Y6wnkGWTgh4WTKoue+FkAa9Xd9uhtT4GokrDxehRW9Y=
	sha1:3P+J+dQnKiFGt4UF4CeMJg+q3L4= sha256:BeQrF89RpdRcD6TSqsDIDfqPDAK5QFcwcQXMQEjZ/v8=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id F2F09117AB6; Fri,  4 Dec 2026 05:23:22 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.098
X-Spam-Status: No, score=-3.098 tagged_above=-9999 required=6.31
	tests=[DKIM_INVALID=0.1, DKIM_SIGNED=0.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.001, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
	URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=fail (1024-bit key)
	reason="fail (body has been altered)" header.d=cmss.chinamobile.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id kA1ecCTKY7YT;
	Fri,  4 Dec 2026 05:23:18 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-376977-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=cmss.chinamobile.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id AA0E9117A7E; Fri,  4 Dec 2026 05:23:09 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 3E20726A10; Fri,  4 Dec 2026 02:23:03 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796350980;
	b=a67SWjQ58G3L5ziUJpOTt9STBCcaasfUVC8caCvfqZQxQON8sdjJJNPdjsP5AdNObBqg
	 IaAPRrqAdOk2TQKVIuLaQ5E/lWEP2S1BMB7qbtHeLL59EWoVeRhx5OaNyRH+651XXeviz
	 V4+eUicVQwu5PeEVKS4eoQxAHWd8Hhx9SphiG55/SwPRBQuaqNMdRWWhNUwbuoGf6Ywuy
	 V2I7COQJ8S4EC8jKg8rpTFZap+VQhwciqJ9qnXadu6GIj/KfHjfmB2XwNNnM0+MpcQQ6Y
	 diqCmBuZBisWhZfEXk8XFJyDCWwyCTRS31I2XItU3KLkngvrGWv0U0DZXLbgVgBdN+w==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796350980;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:X-RM-TagInfo:
	 X-RM-SPAM-FLAG:Received:X-RM-TRANSID:X-RM-TagInfo:X-RM-SPAM-FLAG:
	 Received:X-RM-TRANSID:From:To:Cc:Subject:Date:Message-ID:X-Mailer:
	 In-Reply-To:References:X-Mailing-List:List-Id:List-Post:List-Help:
	 List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=fwTdutUREqDT/9y/IC7hjqRbjFmoWvP+fr7umGsx2+E=;
	b=Xh3pTHDC1Fm4g/4CKrBk3tjLXDNCil/BHyDQLFPIiT2h+Lt0inNfm3uXqaP/gRfiUk/R
	 seW9MSh7zH3Qe0XONxkpA2/7Y1Kh7+8GSLFMk3yXeNLLgdGCF2RYc78Cu79GSe6qKD0ro
	 fqT8bPZfwri+bhKfjgL8QJkcL+U8UX70Vvxn5Ib5CfSvhqklpliL7V7mTkFw5kqb/R/KA
	 jpqWDDEJ2EveBIUnZVqNh6sdnH4tmo6Y9CXSUn2tgYkX+PnR2Is4rJk+jFz8xLIyPU4ln
	 ACj9JtH5Wp3EuaSKxSGki4Lr8p2oehKQt7o0uw4w67IJqcl/4Yif9e8I8Nlb7FJarLw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=uU9TPusE;
	dmarc=pass header.from=cmss.chinamobile.com;
	spf=pass smtp.mailfrom=cmss.chinamobile.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 51AB1606A332;
	Fri,  4 Dec 2026 02:23:00 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key) header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=uU9TPusE
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=111.22.67.135
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796350974;
	b=rzwtTw5ua7C0BQZV6/VFLpmVlAKu668glhPS5mmGi078G9jWWGEiodnI7DR99SeaL3dQ
	 vcGlgSyiH0T0lVa+igy0zjVEKJ7KBe9l7fpx++3yNl8jtZ0fwXbqbPM4sINpPh+riz68b
	 arjVok6v+SMeJgGQZMpWWqJz14syUMqWePCAuMBSweW+16Dmxz+jxk5CfdNOb1tfT6CQq
	 Pu94sG/KYVYO7FDMyIHUjbe8eujPdxejHSFWxUOpJsJOwyYyMGZTjjvIDcfDojpEgjeZp
	 zKkh0BmcRK2sxieGSGdheS5mr8cpk8IY2dZJOv70CW4D+qrXhmXCmBlR4mwdM6XB3aA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796350974;
	h=DMARC-Filter:DKIM-Signature:X-RM-TagInfo:X-RM-SPAM-FLAG:Received:
	 X-RM-TRANSID:X-RM-TagInfo:X-RM-SPAM-FLAG:Received:X-RM-TRANSID:From:
	 To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:
	 MIME-Version:Content-Transfer-Encoding;
	bh=fwTdutUREqDT/9y/IC7hjqRbjFmoWvP+fr7umGsx2+E=;
	b=oBzrAlZOwNqdaOkfmVAS+puSGgRWjo+M6wW35YmldLnYH0kIgI5EYhvreEspDc0hh0Ub
	 WVtTb8bWRjwbLMksq8Vhc/hFyUr7HQZvfHvRLEGiTXLUfcdFlrFaRdi75Mc4M7LqiO5MN
	 Ov28nVE7Zyy/zRkuVOMWCecaOIQeCDCR88atzBZZFIGiK1BXaKcQp9vLtdkgUBxCrjBVG
	 8GwimQGZu9Mm0gQZAHkzXUV0Hb8ht39nWi/joFJfwPIK6I0Q1q2xylEJx6YpH4qZ7/CAZ
	 wrIpFcZkKTdI5KpZbK16M+P9KCAF2M9sgznNOfi+pqwkGeJjb7NiV/R3MOh8C7AN8Qg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=cmss.chinamobile.com;
	spf=pass smtp.mailfrom=cmss.chinamobile.com;
	dkim=pass header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=uU9TPusE;
	arc=none smtp.remote-ip=111.22.67.135
X-Received: from cmccmta2.chinamobile.com (cmccmta2.chinamobile.com [111.22.67.135])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 814D5606A32C;
	Fri,  4 Dec 2026 02:22:52 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 814D5606A32C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmss.chinamobile.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmss.chinamobile.com
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=cmss.chinamobile.com; s=default; l=0;
	h=from:subject:message-id:to:cc:mime-version;
	bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=;
	b=uU9TPusEXAUrQN3Q7DfW5uL2H8bOFfwEnEs6WKXxoEo9R/bAl2ULDwAQIENQ2miBAbIQ+xFsgLvmU
	 MZKiVMVwdau3WcUyTna5f+ckxEuRIFOH2ZSs46ACsFVtOUThoxpunA6ioAeQkhredmn2pBhvUMzL/7
	 OHJ8I0UUOVNriHFw=
X-RM-TagInfo: emlType=0                                       
X-RM-SPAM-FLAG: 00000000
X-Received: from spf.mail.chinamobile.com (unknown[10.188.0.87])
	by rmmx-syy-dmz-app03-12003 (RichMail) with SMTP id 2ee36b1223f9e58-6b759;
	Fri, 04 Dec 2026 10:22:50 +0800 (CST)
X-RM-TRANSID: 2ee36b1223f9e58-6b759
X-RM-TagInfo: emlType=0                                       
X-RM-SPAM-FLAG: 00000000
X-Received: from  (unknown[10.55.1.70])
	by rmsmtp-syy-appsvr01-12001 (RichMail) with SMTP id 2ee16b1223f64fe-846d1;
	Fri, 04 Dec 2026 10:22:50 +0800 (CST)
X-RM-TRANSID: 2ee16b1223f64fe-846d1
X-Cc: netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
X-Mailer: git-send-email 2.50.1.windows.1
X-In-Reply-To: <20261204022245.381-1-chenaibing@cmss.chinamobile.com>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list