From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=111.22.67.151 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795945364; b=1qTblaueMiEBXF9jpEK6jYW95cJTIHBM6Gnu8T/t229tng7p9p5jyJFuMw3ZPonyofKn Uy+0Dqi//jU8BelDI7U7k0yAooT3lXs1/YTgmApvhQiNnw754aXE/k0qrHBkAEuZmL78i ejUnbCXs1Jz2fjeZY6C/tW6ge41yL3gTA3mX1g2BDExX0mPQc5HFokcnVtCFcTk6k8hq0 EDrwQ7ZESgNK+aVaNlM7htEKmaDJuvecIRUh0OhAb21FMNibrQmh1E6ofmB2t/wP1fEIZ wYQE4DVsrV5IYi71sUbdMaSE49Z3eIUufPekUiU+nk6L9085Ru7Lhp6DHJVSecCiXUQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795945364; 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=Yqyxp4oRleRbo5UxCxCekrbhNQ1uFrJ23ulTFkCK5Jg=; b=Ur3W+NmFP/IgEKMUw+hC1mP0OXrEvm74W8CSx/hVzCnB7nmTdaWY4hfy29Naafs2cwl4 z2CeOKdHxdmXVeldcs7Gwu+Gq2o8a6dXC5mgREm/f/EZNrScBB1vWnhuDHfkqb8ownV8x lyMpBi6Of+V76BSGtYBYqcoD3miyXsWlmRvxap2oLjHNrDjKmZEFdwaBWc3Um1svr3+pH 3xgS6i6RLJwBhZzcHj7RBxVh8nYjRmOqM44/uJ+EiffUjcYA0Raa6YqpAiBW3UzKM8NWQ YLNTzn/xDCb6i0Ht2B/V9WFEKOqC+5DWpMYNqqXuy7ybe2zU43Tm7H9XLaTtsyME61w== 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=CWWz8uLI; arc=none smtp.remote-ip=111.22.67.151 Received: from cmccmta8.chinamobile.com (cmccmta8.chinamobile.com [111.22.67.151]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 44EAB606A31C; Sun, 29 Nov 2026 09:42:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 44EAB606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmss.chinamobile.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmss.chinamobile.com 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=CWWz8uLI 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=CWWz8uLI7gATsYBONc+RDsZBRGvYFB2QeTk7SYLMbq62/TtkFzVUIzLz97vB3rRcRfraD4pReIf0B Sex9z4YptmDK5bTq1IRfo48rlZcIV8kyf+1qhhR60DSG00UQt5Rg51V9mi3suWgoe9IQ00tYfml3GD df40gJzngmBYL/P0= X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG:00000000 Received:from spf.mail.chinamobile.com (unknown[10.188.0.87]) by rmmx-syy-dmz-app02-12002 (RichMail) with SMTP id 2ee26b0bf38a728-ad27c; Sun, 29 Nov 2026 17:42:34 +0800 (CST) X-RM-TRANSID:2ee26b0bf38a728-ad27c X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG:00000000 Received:from FHD-W7400297 (unknown[10.55.1.70]) by rmsmtp-syy-appsvr09-12009 (RichMail) with SMTP id 2ee96b0bf387c36-cce06; Sun, 29 Nov 2026 17:42:34 +0800 (CST) X-RM-TRANSID:2ee96b0bf387c36-cce06 From: Aibing Chen To: achender@kernel.org 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, Aibing Chen , stable@vger.kernel.org Subject: [PATCH net v4] net/rds: defer CM id destruction to a workqueue Date: Sun, 29 Nov 2026 17:42:31 +0800 Message-ID: <20261129094231.1368-1-chenaibing@cmss.chinamobile.com> X-Mailer: git-send-email 2.50.1.windows.1 In-Reply-To: <20261117082145.1737-1-chenaibing@cmss.chinamobile.com> References: <20261117082145.1737-1-chenaibing@cmss.chinamobile.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Suggested-by: Jason Gunthorpe Suggested-by: Allison Henderson Fixes: ec16227e1414 ("RDS/IB: Infiniband transport") Cc: stable@vger.kernel.org Signed-off-by: Aibing Chen --- 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(); } -- 2.50.1.windows.1