From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=111.22.67.135 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== 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== 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 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) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 814D5606A32C 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, unprotected) header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=uU9TPusE 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 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 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 From: Aibing Chen To: Allison Henderson Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org 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 Message-ID: <20261204022245.381-4-chenaibing@cmss.chinamobile.com> X-Mailer: git-send-email 2.50.1.windows.1 In-Reply-To: <20261204022245.381-1-chenaibing@cmss.chinamobile.com> References: <20261204022245.381-1-chenaibing@cmss.chinamobile.com> X-Mailing-List: netdev@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() 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 --- 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);