Article View: linux.kernel.netdev
Article #24952Re: [PATCH net v4] net/rds: defer CM id destruction to a workqueue
From: Allison Henderson
Date: Tue, 01 Dec 2026 03:56
Date: Tue, 01 Dec 2026 03:56
186 lines
14684 bytes
14684 bytes
On Sun, 2026-11-29 at 17:42 +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 is allocated
> before the CM id is created and owns the id until rdma_destroy_id()
> has run; if the allocation fails, the address check fails with
> -ENOMEM rather than falling back to the synchronous destroy, which
> would bring the deadlock back under memory pressure.
>
> Deferring the destruction leaves each probe cm_id alive on rds_wq
> until the worker runs. rds_wq is an ordered single-worker queue
> shared with the rest of RDS, and each pending item holds a
> rdma_id_private, a cma_dev reference and an ephemeral RDMA_PS_TCP
> port, so an unprivileged bind() loop could pin memory, exhaust ports
> needed by other RDMA users (NVMe-oF, iSER, NFS/RDMA) and delay IB
> device removal. Bound the number of pending probe destroys with an
> atomic counter: rds_ib_laddr_check_cm() returns -EAGAIN once
> RDS_IB_MAX_PROBE_PENDING (64) destroys are queued, and the counter is
> released on every error path and in the worker.
>
> 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>
Hi Aibing,
I'm presuming this patch must have gone out by mistake since it looks like
it still has build errors, and doesnt cover the findings from the last review:
ttps://lore.kernel.org/r/d83709308a038467b3a4849d814978b84328d2bc.camel@kernel.org
No worries, just send v5 when it's ready.
Thanks!
pw-bot: cr
> ---
> v4:
> - bound the number of pending probe destroys with an atomic counter
> (cap 64, -EAGAIN above it); the deferred destroy leaves each probe
> cm_id, its cma_dev reference and an ephemeral RDMA_PS_TCP port alive
> on the ordered rds_wq until the worker runs, and nothing previously
> limited the backlog (Allison Henderson).
>
> v3:
> - allocate the work item before rdma_create_id() and fail with -ENOMEM
> instead of falling back to the synchronous destroy, which would bring
> the deadlock back under memory pressure.
> - free the work item when rdma_create_id() fails and drop the now
> redundant fallback in the out path.
>
> 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 | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 63 insertions(+), 2 deletions(-)
>
> diff --git a/net/rds/ib.c b/net/rds/ib.c
> index 4ea9838d0..b83220de9 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
>
> +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);
> +
> + /* Matched by the decrement in this function. */
> + atomic_dec(&rds_ib_probe_pending);
> +}
> +
> +/*
> + * Bound the number of probe cm_ids pending destruction on rds_wq: each
> + * holds a rdma_id_private, a cma_dev reference and an ephemeral
> + * RDMA_PS_TCP port until the worker runs.
> + */
> +#define RDS_IB_MAX_PROBE_PENDING 64
> +static atomic_t rds_ib_probe_pending = ATOMIC_INIT(0);
> +
> /*
> * Early RDS/IB was built to only bind to an address if there is an IPoIB
> * device with that address set.
> @@ -411,14 +436,42 @@ 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;
>
> + /*
> + * Bound the probe backlog: each queued destroy pins the cm_id, a
> + * cma_dev reference and an ephemeral RDMA_PS_TCP port until the
> + * worker runs.
> + */
> + if (atomic_inc_return(&rds_ib_probe_pending) > RDS_IB_MAX_PROBE_PENDING) {
> + atomic_dec(&rds_ib_probe_pending);
> + return -EAGAIN;
> + }
> +
> isv4 = ipv6_addr_v4mapped(addr);
> +
> + w = kzalloc_obj(*w, GFP_KERNEL);
> + if (!w) {
> + atomic_dec(&rds_ib_probe_pending);
> + 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(w);
> + atomic_dec(&rds_ib_probe_pending);
> 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.
> + */
> ret = rdma_restrict_node_type(cm_id, RDMA_NODE_IB_CA);
> if (ret)
> goto out;
> @@ -484,7 +537,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(&w->work, rds_ib_destroy_id_work);
> + w->cm_id = cm_id;
> + queue_work(rds_wq, &w->work);
>
> return ret;
> }
> @@ -542,6 +597,12 @@ 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:
<1c10ee0b0af0c0656ca8d6b972d7e077238ac688.camel@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374684-linux-kernel-netdev=dewy.ruReferences:
<20261117082145.1737-1-chenaibing@cmss.chinamobile.com> <20261129094231.1368-1-chenaibing@cmss.chinamobile.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374684-linux-kernel-netdev=dewy.ru From: achender@kernel.org (Allison Henderson) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v4] net/rds: defer CM id destruction to a workqueue Date: Mon, 30 Nov 2026 20:56:32 -0700 Organization: Usenet Network Message-ID: <1c10ee0b0af0c0656ca8d6b972d7e077238ac688.camel@kernel.org> References: <20261117082145.1737-1-chenaibing@cmss.chinamobile.com> <20261129094231.1368-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="1607860"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:kXTk2PNb4NfrySjebM96BzLb0dw= sha256:+zJL9L9JMV9SuQLHiT31ZpC/fAclWBFp100A+onNWQk= sha1:xdbpzH0mPhzvrzCP8GkZtA6TybQ= sha256:I2IyO8Mxj/b7llQ0hXYfAVsedkVItV4ZL+R6hx1k2qY= 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 8185D12601A; Tue, 1 Dec 2026 06:56:58 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 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] 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 W5QBV_e11Ga8; Tue, 1 Dec 2026 06:56:50 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-374684-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 21CC6126019; Tue, 1 Dec 2026 06:56:40 +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 85135230BA; Tue, 1 Dec 2026 03:56:39 +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=1796097396; b=1ndJ8JhmJ7Capohh4czPTE2wPmbs5TxszH17ZxpIDKYyt9qQuRl5m4okK860m/WX46mr Q2s2ntUfuZFTO+y+eoEEzSdWwZQawk4RTz1GR/25n9F8wawEQCWLgBV/HH1YDJ91m9O/V shCcZaI9gGsOOx7gz/szZU4YW1XyhCIrGYSYJpgrSG/+l0uJbL4DCLdj99ZZoF4x1VO0F Zg/GT/9ktm2YVed78p4XLRe80AieMB+CTAeRKj2uDsuPA338BNJ99h0wFm209YiTstoA0 tGzGsN6s+vf+bsHlBxW7Yd4G45o74KHePbZciLzBEnC0gnfELexydbhjSqYDuEeyJDA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796097396; 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=mSlz1HqyNR2cEULjCpHCA7fAga87X17sGf8xbuGAz6M=; b=p4iF8eJvZZnHxH2s4FNM7r2dUh4ZzSS+3anY/mTxsHqSQX+SjU4HN9ZuDt3p6pu5Uan8 R+KVuoNZ2tZ120YIOFZyjFcy9ZyOQoY45vJnKEJwsiOrbkPBlzNr4j7xwXDUQRfaKrnpd Dwo95vqyvtBCDLsBGSaHeXtPzxVQvMYIcJY3/Q5jW5DaYwGzqeQBArXNB4b1nvxuyRfsv LIp4FNDvq59q0UaGdFvg6V4efd/P5VoObeGwey/EdjszLPgCBsrfwL/LaLavJ0Y69xXgB ghJ54b3EQPaeQYRrbJs5NiPQM6Rau86ms/0+oYVBOadKDafqiPKPTl+/JZDd1jQqf1A== 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=g3fKG16T; 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 53BA1606A336; Tue, 1 Dec 2026 03:56:36 +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=g3fKG16T 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=1796097394; b=pIJu9tYBMDSqYOMJbSbvhDSvXlcrOLXgSEYC6I7MEJLP9AUz5nzJWuiSeKSTvDzRDRnD 0tkaBTGfnhyAuqSefVyHIZDVZIm8sH57lI2FK1sE/fPNMQ9osRTl9sp20LwUQfsh/xB82 XiuOmSFffSVVszKF+u670jQbfY50eyLmjkJP2p/XrIkCdfPNJ1qUAOFuJozgL6UlhVajP LAPn03QHXLD2DP5Zbi/Y19JPsrMSba4DqbZkoFxKtp06IIHG+9LOwbCTMzAamcpNK712a 64H15aDJMrEuzTZF/bwIAlW++bs76v8CoG33/OBEziz/qn7t7BD3dpNzMvJ7uEJ5coQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796097394; 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=mSlz1HqyNR2cEULjCpHCA7fAga87X17sGf8xbuGAz6M=; b=3Wn9A/QWNFyHJ6m2QyE0WaO01oVbot+xJQHWOOiuWTub5TBzI1ayAmWAjNuQCF+xe2cd Bhng33BG10fD5aMJpqhFOgAGUYEcynXsp2Pv9ENa9R2PX7KhrPCaKMoPcptoWWUO3M14M J7aoqWjF93VAor8fU/mfiod44FAmdmWU0hr52lZeyn6YrYpTrJ6UA3YvpogStzfRjP5BM HLrPw0i0ZJkV9N9HKT/PB/D1nT7n3DYB3bptqpe8/hG4GX2JEP/L5qV/hyp3OM216ktBT 4+1vXl8U8PH+HIi8K6OIaVozCJvsEZBQptDjVSHtHJWicu4UFoFGZwaWs2cpbBkdbVA== 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=g3fKG16T; 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 53E12606A31A; Tue, 1 Dec 2026 03:56:34 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CC2A1F00893; Tue, 1 Dec 2026 03:56:33 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796097393; bh=mSlz1HqyNR2cEULjCpHCA7fAga87X17sGf8xbuGAz6M=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=g3fKG16TgCmFBgjvU0bAkXxwvaeq81ldgMMODv26jLCxQ0qI/gcjiV9gVbLNamsa1 e5cT/4Im6V3C15oHhOuf22rngBroswFpgthcV5EZmjR/L0MJ83PiBjH1Hlpj7g+n31 2U5HnUUJ5eU1WKL4Ma5ifny/yL9Gaci1soanhlDVVZM5jOzMye6bCvTB6c3cWbQSMB rsbUi9kvjeDeAh+PfS4XSeksG1C2spMpVyXqOUIVGcOu0lhV1kkQepY21aQ1AXBZxb JhP4xNbhwEc96JMqRyKzOraL6a86J6VvlKZ/xAxhiB/Xdi0irvZmm5cFiKGWyPI/X1 dECfgC87b+6TA== X-Cc: jgg@ziepe.ca, leon@kernel.org, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, netdev@vger.kernel.org, linux-rdma@vger.kernel.org, rds-devel@oss.oracle.com, linux-kernel@vger.kernel.org, hdanton@sina.com, syzbot+ccdb5058c3df2d94811c@syzkaller.appspotmail.com, stable@vger.kernel.org X-In-Reply-To: <20261129094231.1368-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