🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #17643

Re: [PATCH net v2] net/rds: defer CM id destruction to a workqueue

#17643
From: Allison Henderson
Date: Tue, 17 Nov 2026 06:15
138 lines
12623 bytes
On Mon, 2026-11-16 at 15:54 +0800, Aibing Chen wrote:
> rds_ib_laddr_check_cm() destroys the RDMA CM id it created while
> rds_trans_get_preferred() holds rds_trans_sem for reading.  The bind
> path then takes rds_trans_sem and afterwards handler_mutex in
> rdma_destroy_id(), while the CM callback path takes handler_mutex in
> cma_ib_req_handler() and afterwards rds_trans_sem through
> rds_conn_create().  lockdep reports the resulting cycle.
> 
> Queue the destruction on rds_wq instead, so that rds_trans_sem is
> released before handler_mutex is taken.  The work item allocated here
> owns the cm_id until rdma_destroy_id() has run; if the allocation fails,
> the id is destroyed synchronously as before.
> 
> rds_ib_exit() flushes rds_wq after rds_trans_unregister() so that no
> queued destroy runs after the module text is gone.
> 
> Reported-by: syzbot+ccdb5058c3df2d94811c@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=ccdb5058c3df2d94811c
> Suggested-by: Hillf Danton <hdanton@sina.com>
> Suggested-by: Jason Gunthorpe <jgg@ziepe.ca>
> Suggested-by: Allison Henderson <achender@kernel.org>
> Fixes: ec16227e1414 ("RDS/IB: Infiniband transport")
> Cc: stable@vger.kernel.org
> Signed-off-by: Aibing Chen <chenaibing@cmss.chinamobile.com>
> ---
> v2:
> - move the workqueue from RDMA core into RDS, as suggested in review.
> - flush rds_wq in rds_ib_exit() so a queued destroy cannot run after
>   the module text is freed.
> - add the Fixes tag, drop the Tested-by tags.
> 
>  net/rds/ib.c | 37 ++++++++++++++++++++++++++++++++++++-
>  1 file changed, 36 insertions(+), 1 deletion(-)
> 
> diff --git a/net/rds/ib.c b/net/rds/ib.c
> index 4ea9838d0..66af4a72a 100644
> --- a/net/rds/ib.c
> +++ b/net/rds/ib.c
> @@ -391,6 +391,20 @@ static void rds6_ib_ic_info(struct socket *sock, unsigned int len,
>  }
>  #endif
>  
> +struct rds_ib_destroy_work {
> +	struct work_struct work;
> +	struct rdma_cm_id *cm_id;
> +};
> +
> +static void rds_ib_destroy_id_work(struct work_struct *work)
> +{
> +	struct rds_ib_destroy_work *w =
> +		container_of(work, struct rds_ib_destroy_work, work);
> +
> +	rdma_destroy_id(w->cm_id);
> +	kfree(w);
> +}
> +
>  /*
>   * Early RDS/IB was built to only bind to an address if there is an IPoIB
>   * device with that address set.
> @@ -411,6 +425,7 @@ static int rds_ib_laddr_check_cm(struct net *net, const struct in6_addr *addr,
>  #endif
>  	struct sockaddr_in sin;
>  	struct sockaddr *sa;
> +	struct rds_ib_destroy_work *w;
>  	bool isv4;
>  
Hi Aibing,

Thanks for the quick turn around, this is looking much better.  Just a few things to get this
through: we cant fall back to the synchronous destroy if alloc fails, or the same bug
will come back under memory pressure.  Lets hoist the alloc up here before the
rdma_create_id().  If alloc fails, just return -ENOMEM right away.

>  	isv4 = ipv6_addr_v4mapped(addr);
> @@ -419,6 +434,15 @@ static int rds_ib_laddr_check_cm(struct net *net, const struct in6_addr *addr,
>  			       NULL, RDMA_PS_TCP, IB_QPT_RC);
>  	if (IS_ERR(cm_id))
Then add a kfree(w) here before returning on this error case

>  		return PTR_ERR(cm_id);
> +
> +	/*
> +	 * The id is destroyed from rds_wq: rds_trans_get_preferred() calls this
> +	 * function with rds_trans_sem held for reading, and rdma_destroy_id()
> +	 * takes handler_mutex, which the CM callback path acquires before
> +	 * taking rds_trans_sem.  If the allocation fails, fall back to the
> +	 * synchronous destroy.
> +	 */
> +	w = kzalloc_obj(*w, GFP_KERNEL);
>  	ret = rdma_restrict_node_type(cm_id, RDMA_NODE_IB_CA);
>  	if (ret)
>  		goto out;
> @@ -484,7 +508,13 @@ 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);
> +	if (w) {
> +		INIT_WORK(&w->work, rds_ib_destroy_id_work);
> +		w->cm_id = cm_id;
> +		queue_work(rds_wq, &w->work);
> +	} else {
> +		rdma_destroy_id(cm_id);
> +	}
And then this else part can be removed since w is guaranteed here

Other than that, this looking really good.
Thanks for working on this!
Allison

>  
>  	return ret;
>  }
> @@ -542,6 +572,11 @@ void rds_ib_exit(void)
>  	rds_ib_sysctl_exit();
>  	rds_ib_recv_exit();
>  	rds_trans_unregister(&rds_ib_transport);
> +	/*
> +	 * rds_ib_laddr_check_cm() may have queued rdma_destroy_id() on rds_wq;
> +	 * wait for it before the module text goes away.
> +	 */
> +	flush_workqueue(rds_wq);
>  	rds_ib_mr_exit();
>  }
>  
> 
> 
> 
Technical Details
Message-ID: <6f4cebe1dae4c25d7618f0a08c1412cd0c68faeb.camel@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364978-linux-kernel-netdev=dewy.ru
References: <20261114150541.1908-1-chenaibing@cmss.chinamobile.com> <20261116075423.782-1-chenaibing@cmss.chinamobile.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364978-linux-kernel-netdev=dewy.ru
From: achender@kernel.org (Allison Henderson)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2] net/rds: defer CM id destruction to a workqueue
Date: Mon, 16 Nov 2026 23:15:46 -0700
Organization: Usenet Network
Message-ID: <6f4cebe1dae4c25d7618f0a08c1412cd0c68faeb.camel@kernel.org>
References: <20261114150541.1908-1-chenaibing@cmss.chinamobile.com>
	 <20261116075423.782-1-chenaibing@cmss.chinamobile.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="2255931"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:pW2H0aMGEQXx7x4SqKHFvXxuINo= sha256:iR5San9XZiypumbyf9HgnjwsNdoNWZlNtKuvmruRwU8=
	sha1:P8baEndnT2SCQMtI7NdFlfkZmt4= sha256:m60gGiwFq1aHC+Tlo/M+i+hVIEKaV355N0vRt/+NEps=
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 F2CF5114E5D; Tue, 17 Nov 2026 09:16:11 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	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=pass (2048-bit key)
	header.d=kernel.org
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 DP-8FJMCx8oy;
	Tue, 17 Nov 2026 09:16:03 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-364978-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 4FF9E114E55; Tue, 17 Nov 2026 09:15:52 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 36DE62F5E7; Tue, 17 Nov 2026 06:15:50 +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=1794896149;
	b=ZhojV2GoqanIiXXGdpNrHQdVDcUlQ0VeLb9qtANyfcRuGvlxHRs8sexZBHO7Lkmsz1Y6
	 kHEnDRSLdsdTK++NtDNATkEcLsaY4q9/uw3Ub0sLV3YHhpHYR9sP2DK5ktU5fhLuZtAHa
	 /wkNZ5ZMNybdG4k47538hahVLxkpPciDHrT74g4HO3qAyf33CD/t/vIZY08tUNCWVUR/M
	 GxZF5Svi8AJ82PQRWfwfU4koSmGNEf1EwOngq3PwRKsR6q4Zf3b+BALCAnOp4a0EN8Hcc
	 S03dtA/ZXvh8rVlD0sUFp2tNw/qmHHxN0MoUC22Rn4wXWK8Wo4cxXvRzImcVFTN3lfw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794896149;
	h=X-Original-To:Received:Received:DKIM-Signature:Message-ID:Subject:
	 From:To:Cc:Date:In-Reply-To:References:Content-Type:
	 Content-Transfer-Encoding:User-Agent:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version;
	bh=77exyfdtiO92nBdMS15TrDt356pTZ+Pg32vOrZO0z0Q=;
	b=RxPw1pnlQ2e68S1/L41Ae6g9cMooBx0godDt/eboSD40Ma7kxPk7yyXEni+cI9FmAvtr
	 oTDi47yAtFSIdz2UbRUSDIzwvmMUr2BI5u9Lr9TgLbVcvzW0ROeyZtnzkS843NdjdqKFm
	 9uuDzOUxJKEjoUy7TXVSdL+lVzmgPBDx36OH5fxdGoscbOZ2cnPCMCj7KYtKcwkumXDjT
	 w98AgbLSNb14njaCEXh71BQ4V2tSrfR6YXd02wrND6pM3HWO0PMsBXbk6K+KhSti5qOP1
	 89rjhlMOUrM8ROTH+0hw9wThFbsLi6QxDqdbLJli+4EupH7aFt9RamtfhwNlmk2BMaQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kLIJvECu;
	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 80AFE606A339;
	Tue, 17 Nov 2026 06:15:49 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kLIJvECu
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794896148;
	b=ZiqHHSrd2720aZUz7coG+mDmiOsHJ8tTY1G93dN6uxMcOfQwrRFxozSpp0KKKbXWgx7f
	 M/wZc6iFGuYliAE61mtai0IKbj1ZUbP9iD2d00Y/AsrvoIHiyZleBBfGYV1/HPRmsdOaj
	 iudVj+E6bUXQXDOtKY17ZFXHpEX279aVEw8i52nnq9lO9LtJDC5x6nbEdD9TQs0NNboGW
	 HqQv84vlDzVwPBcHgQlmwjWXnL+5ScYImcGsnmRbLIQly+V56OwAwe4onQuuxfo7LBv8o
	 7JwxgSCFwDA5JRvI6IwhFDXNvr0wgFHGddgPaXs8U+XXO3xtkNpz67PDcbfhjgp3UPQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794896148;
	h=Received:DKIM-Signature:Message-ID:Subject:From:To:Cc:Date:
	 In-Reply-To:References:Content-Type:Content-Transfer-Encoding:
	 User-Agent:MIME-Version;
	bh=77exyfdtiO92nBdMS15TrDt356pTZ+Pg32vOrZO0z0Q=;
	b=hOx7N6V+oCRKLXAjrV5Gze4+O6Mqer69pC8aImgk2VTp9Rs21rQFX1PAKgel7kVYPBZ3
	 Q8AcaxAJzk+LXT3oMuAi/TRntASwk9YSw/iV4oW8yJEWgybTjJj35dsBmzPHKJDYb/XjY
	 upTUtb0gqrukJSaz+SFRZDaMVL7Co7uwJRkvUEteMagAf8K/+hXmimqbr0JopniCPvcOJ
	 jR2Hh946m6sZYXU4gxhT94PSA43h+tC6mxs1S6ascrGM4vLpbVXSraZCXrybwfcMKBOOL
	 H3GTMSvBoPSYows7fvfp0NzPEecd18MrHQlX8O0OFjaHC7wL++jZnt2DokPNZ4VTaXw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kLIJvECu;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F713606A329;
	Tue, 17 Nov 2026 06:15:48 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7E751F000C4;
	Tue, 17 Nov 2026 06:15:47 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794896148;
	bh=77exyfdtiO92nBdMS15TrDt356pTZ+Pg32vOrZO0z0Q=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=kLIJvECuQQoZoW6ujqEW2ygTN456z2D797kWRlr4xc9nmluypmCUCF0GERs42MiWZ
	 h7u2nonnD9CQrQKVR3fVFix4qQkkuZ22NOcsb9xXl6m6CQr+pmCjJVoJCUiPYrhlWF
	 dri2fOjcj89I3qq/RiYB63GRx+dDh9lVj7giwrz59nsI3ubuPnC0JoBFeuyRkM+Mgv
	 2nJ2F74NeIJk4koN5onTp7JZsRuqQckp4loi2bPkLL33cEWteMFP4Gin0l4z9nfDuI
	 v4Z8reYuO2r5l8qeZ/EhbML8njpgirjiv53XkQGZLI7aMC4LS0uZusse4oGHl1w/VV
	 O1yXiTOV8HsiQ==
X-Cc: "David S . Miller" <davem@davemloft.net>, Eric Dumazet
 <edumazet@kernel.org>,  Jakub Kicinski <kuba@kernel.org>, Paolo Abeni
 <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
 netdev@vger.kernel.org, linux-rdma@vger.kernel.org, 
 rds-devel@oss.oracle.com, linux-kernel@vger.kernel.org
X-In-Reply-To: <20261116075423.782-1-chenaibing@cmss.chinamobile.com>
X-User-Agent: Evolution 3.52.3-0ubuntu1.1 
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