Re: [PATCH net v6 1/2] net/rds: drop rds_trans_sem around laddr_check()
From: netdev-bot+sashiko
Date: Wed Dec 02 2026 - 22:38:17 EST
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@xxxxxxxxxx/
> 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