From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796269089; b=5bb83LD7mQKEqQtsa2XdEP2/wRdQU5+Y6isnaxBJjCytu6sjSjPiIP+bph/5qMqMGEY2 PRx8MHckLrsI/T4UsqqexKBJxCLR/ysH7GpLByOb+NZM9mTJ17dqlvnAn5t0k7WiAiR8i LiBRIv1EK+Lpmebb/OwfNqkx7n43w2IQ+UVxJjdJCyAQf39fgw2rRSnRr9ps2yjcVRsx6 eE9G+wKWoShpXUcQ7dbfEEJs6WhE2OnRuVfT2g7JYr9RtrkdvLQM7TmrG7G0g06gAyLgb wyy8Y8c/1iGc4n93KxWBTxyFGW5XuiM8eM+bYOPEHSzH4+5CBgdOW7yUtEF1N6OlvVg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796269089; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=APMPKaOQWAQjNOpwNudo3iJ00eYdbNDrwsdPC7ApbVs=; b=vj+t6SUH1CkFWmO/GJ14qRRHQBuhdZFvNnITm/h+xgZ6cT8L4sICaZEPWh9m6vFHCdZa BzBrNw/OXcBMBCD/o7UggHFpnZ87h9+kqJuT0L+K8oyFwQ1WxZvUGEYNaxd8mNX+excsV mkd8ABNuOMfQFth34W2IBR/Ab1M+G2cJnioBsJRP2rmLmG1MFYyGCpMHNfoHPWGF3FVXQ 8PMSKT2Nr8PQFuzcuOL5jM6DnvuYxrrPqao980Fl9rVaANQElMZWFQxh0WeUVfLdZKEgl RGcdDH2kGjn614vpal78ZFIbnYERsutWZrQ8MwC+4Zh0PQBq7nx7nOfV7cR9zniGA+Q== 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=WdKy28FA; arc=none smtp.remote-ip=100.103.45.18 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 6C7AD606A682; Thu, 3 Dec 2026 03:38:09 +0000 (UTC) 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=WdKy28FA Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0002C1F00896; Thu, 3 Dec 2026 03:38:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796269089; bh=APMPKaOQWAQjNOpwNudo3iJ00eYdbNDrwsdPC7ApbVs=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=WdKy28FA9CoE1Y2wr7yXTDB8fQlvKRghzshMb0Foh5vpxe1GcT9udraAIbBFLEIUB rUoUS5dMxIStQGPH382tHpfSATRQ5ZwjoHBGOmE2eEfWE2KG5OSiLDm0GCB0GueylS QZcdZFozeEfLjC3dvGkD2lsWC3mp6NgiREA7NWdv3l8Fia0oumxcsG6kH4yQmPnOiX z6KguUoFG4CwsIv+TyCdhL/CGd3AmoCFAVwL6JHu8kQ7sawg1iW5xd/670vRpHz34j 4NHKFioBk4oWlrYDbR2a67LlX3pA0fu/4mVyG2b6KSbo4QWKpRGwJWBSKQi63N4TSV aQKaoYgZfuBtQ== Subject: Re: [PATCH net v6 1/2] net/rds: drop rds_trans_sem around laddr_check() From: netdev-bot+sashiko@kernel.org To: chenaibing@cmss.chinamobile.com Cc: achender@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kuba@kernel.org Date: Thu, 03 Dec 2026 03:38:08 +0000 Message-ID: <179626908850.3146.14670637682082504192@kernel.org> In-Reply-To: <20261202024054.1945-2-chenaibing@cmss.chinamobile.com> References: <20261202024054.1945-2-chenaibing@cmss.chinamobile.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit 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 Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 1 · Low: 0 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [Medium] rds_trans_get_preferred() (net/rds/transport.c) now takes the transport's module reference with try_module_get(), drops… -- net/rds: drop rds_trans_sem around laddr_check() This commit changes rds_trans_get_preferred() so that it takes the module reference for each candidate transport while holding rds_trans_sem. It then drops the semaphore before calling ->laddr_check(). The goal is to break a lockdep-reported circular dependency between rds_trans_sem and rdma_cm's handler_mutex. Link: https://lore.kernel.org/all/d83709308a038467b3a4849d814978b84328d2bc.camel@kernel.org/ > diff --git a/net/rds/transport.c b/net/rds/transport.c > index f8001ec808671..904b9351e7613 100644 > --- a/net/rds/transport.c > +++ b/net/rds/transport.c [ ... ] > @@ -101,15 +100,26 @@ struct rds_transport *rds_trans_get_preferred(struct net *net, > for (i = 0; i < RDS_TRANS_COUNT; i++) { > trans = transports[i]; > > - if (trans && (trans->laddr_check(net, addr, scope_id) == 0) && > - (!trans->t_owner || try_module_get(trans->t_owner))) { > - ret = trans; > - break; > - } > + if (!trans || > + (trans->t_owner && !try_module_get(trans->t_owner))) > + continue; > + > + /* > + * ->laddr_check() may create and destroy an rdma_cm id, which > + * takes rdma_cm's handler_mutex. Don't hold rds_trans_sem > + * across it: the module reference keeps trans alive. > + */ > + up_read(&rds_trans_sem); > + > + if (trans->laddr_check(net, addr, scope_id) == 0) > + return trans; [Severity: Medium] Does the module reference keep trans and ->laddr_check() alive while rds_rdma is still in MODULE_STATE_COMING? The commit message says: "The module reference keeps the transport and its callback alive" However, try_module_get() only refuses modules that are in MODULE_STATE_GOING: include/linux/module.h:module_is_live() { return mod->state != MODULE_STATE_GOING; } rds_ib_init() publishes rds_ib_transport through rds_trans_register() during module init. rds_rdma_init() can still fail after that point: net/rds/rdma_transport.c:rds_rdma_init() { ... ret = rds_ib_init(); if (ret) goto out; ret = rds_rdma_listen_init(); if (ret) rds_ib_exit(); ... } rds_rdma_listen_init() can fail with -ENOMEM from rdma_create_id(). It can also fail if rdma_bind_addr() or rdma_listen() fails, for example when RDS_PORT is already bound in RDMA_PS_TCP. On that failure, do_init_module() frees the module and does not wait for references taken by try_module_get() during COMING: kernel/module/main.c:do_init_module() { ... fail: mod->state = MODULE_STATE_GOING; synchronize_rcu(); module_put(mod); ... free_module(mod); } Before this patch, laddr_check ran under down_read(&rds_trans_sem). The down_write() in rds_trans_unregister() therefore waited for it to finish. Now that the semaphore is dropped, can this interleaving happen? CPU1 (unprivileged, bind() on AF_RDS without SO_RDS_TRANSPORT) rds_bind()->rds_trans_get_preferred() try_module_get(trans->t_owner) /* succeeds in COMING */ up_read(&rds_trans_sem); trans->laddr_check() /* rds_ib_laddr_check() */ CPU2 rds_rdma_init() rds_rdma_listen_init() /* fails */ rds_ib_exit() rds_trans_unregister() /* down_write no longer waits */ do_init_module() fail path free_module() In that case CPU1 would run freed module text and touch freed module data, such as rds_ib_devices and rds_rdma_cm_event_handler. The follow-up patch in this series, "net/rds: defer the probe cm_id destroy to rds_wq", seems to make the window larger. With that patch, rds_ib_laddr_check_cm() queues module text on rds.ko's workqueue: INIT_WORK(&pw->work, rds_ib_probe_work_fn); pw->cm_id = cm_id; queue_work(rds_wq, &pw->work); rds_ib_exit() flushes that workqueue right after unregistering: rds_trans_unregister(&rds_ib_transport); ... flush_workqueue(rds_wq); A probe that is still running in the window above can queue its work after that flush. rds_wq belongs to rds.ko and outlives rds_rdma. Could rds_ib_probe_work_fn() then run after rds_rdma has been freed? It would also be touching rds_ib_probe_pending. > + > + rds_trans_put(trans); > + down_read(&rds_trans_sem); > } > up_read(&rds_trans_sem); > > - return ret; > + return NULL; > } -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202024054.1945-1-chenaibing%40cmss.chinamobile.com