Netdev List
 help / color / mirror / Atom feed
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
Subject: Re: [PATCH net v7 3/3] net/rds: defer the probe cm_id destroy to rds_wq
Date: Sat, 05 Dec 2026 03:05:37 +0000	[thread overview]
Message-ID: <179643993741.3146.5379085669209427809@kernel.org> (raw)
In-Reply-To: <20261204022245.381-4-chenaibing@cmss.chinamobile.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 2 · Low: 1

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).

- [High] The patch adds a global cap of 64 pending probe destroys
  (`rds_ib_probe_pending` / `RDS_IB_MAX_PROBE_PENDING`).
- [Medium] Deferring `rdma_destroy_id()` keeps a successfully bound probe
  cm_id attached to its `cma_device` until the shared single-threaded…
- [Medium] rds: unaddressed v6 request to use local-addr check in
  __rds_conn_create()
- [Low] The rewritten comment in the generic `rds_trans_get_preferred()`
  loop (net/rds/transport.c:107-112) says '->laddr_check() creates an…

--

net/rds: defer the probe cm_id destroy to rds_wq

This patch moves rdma_destroy_id() of the probe cm_id in
rds_ib_laddr_check_cm() onto rds_wq. The goal is to avoid a lockdep
recursive handler_mutex report on the passive connection path. It
preallocates one work item per probe and caps pending destroys at 64,
failing the address check with -ENOMEM above that. It also flushes rds_wq
in rds_ib_exit().

> diff --git a/net/rds/ib.c b/net/rds/ib.c
> index 784d358fe657e..a3ee52fa927e4 100644
> --- a/net/rds/ib.c
> +++ b/net/rds/ib.c

[ ... ]

> @@ -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;
> +	}

[Severity: High]
Can this cap make a valid IB address look like it is not on IB?

Once rds_ib_probe_pending goes above 64, rds_ib_laddr_check_cm() returns
-ENOMEM before it looks at the address at all. The counter is only
decremented in rds_ib_probe_work_fn(), and rds_wq is ordered:

net/rds/threads.c:rds_threads_init() {
    ...
	rds_wq = create_singlethread_workqueue("krdsd");
    ...
}

rds_wq is also shared with rds_tcp_accept_w, rds_ibdev->free_work,
m_unpin_work and the fallback per-path connection workers. The destroys
therefore drain one at a time, behind unrelated work.

rds_trans_get_preferred() only checks for zero:

		if (trans->laddr_check(net, addr, scope_id) == 0)
			return trans;

		rds_trans_put(trans);
		down_read(&rds_trans_sem);

So the -ENOMEM from the cap is treated as "try the next transport". These
are the outcomes:

- rds_bind() with no transport set: rds_tcp_laddr_check() accepts a local
  IPoIB address, so the socket is silently bound to rds_tcp_transport and
  later RDMA operations fail. If rds_tcp is not loaded, bind fails with
  -EADDRNOTAVAIL.

- rds_bind() with SO_RDS_TRANSPORT set to IB fails with -ENOPROTOOPT.

- __rds_conn_create() probes faddr through rds_trans_get_preferred() for
  every new connection. A spurious NULL there leaves c_loopback unset for
  a local faddr for the life of the conn.

The rds_ib_get_device() fast path in rds_ib_laddr_check() only covers IPv4
addresses that are already in an rds_ib_device ipaddr list. IPv6 binds,
first IPv4 binds and every new-conn faddr probe all use a slot.

The counter is global. Creating an RDS socket and calling bind() need no
capability, and a failed bind leaves the socket unbound so it can retry.
Could an unprivileged user looping bind() from several CPUs hold the
counter at the cap for everyone else in init_net?

rds_tcp_accept_worker() also runs on rds_wq and loops
rds_tcp_accept_one()->rds_conn_create(). None of the destroys it queues
can run until it returns.

The commit message says:

    Above the bound the check fails with -ENOMEM; callers treat that like
    any other unsuccessful laddr_check().

It does not mention the silent move to TCP or the dependency on the
shared queue. Once the cap is reached there is no wait, reclaim or
synchronous fallback. Is there a way to avoid failing the check outright
here?

> +
>  	/* 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);

[ ... ]

> @@ -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);

[Severity: Medium]
Was the v6 review feedback on this approach addressed?

On v6, Allison asked for __rds_conn_create() to stop calling
rds_trans_get_preferred() and to use a direct local-address check
instead. v7 doesn't seem to reflect that. net/rds/connection.c is
unchanged, and this patch still works around the recursion inside
rds_ib_laddr_check_cm().

Only one caller of rds_trans_get_preferred() runs with rdma_cm's
handler_mutex held, the passive connect path:

  rds_rdma_cm_event_handler_cmn()
    rds_ib_cm_handle_connect()
      rds_conn_create()
        __rds_conn_create()
          rds_trans_get_preferred()

The other caller, rds_bind(), runs from the bind() syscall and not
from an rdma_cm handler.

In __rds_conn_create(), the transport returned for faddr is dropped
with rds_trans_put() right away. It is only used to decide whether
faddr is local, so that c_loopback gets set and the
t_prefer_loopback handling either switches to rds_loop_transport or
returns -EOPNOTSUPP.

A small helper could answer that question directly. It would check
IN_LOOPBACKNET, inet_addr_type() == RTN_LOCAL, ipv6_addr_loopback()
and ipv6_chk_addr() under rcu_read_lock(). Those are the same checks
that rds_tcp_laddr_check() and the loopback shortcut in
rds_trans_get_preferred() already make. It would not take
rds_trans_sem and would not create a probe cm_id under
handler_mutex.

That single change would remove both problems at once:

- the rds_trans_sem/handler_mutex ordering problem handled by "drop
  rds_trans_sem around laddr_check()" and "register the IB transport
  last";

- the recursive handler_mutex report handled here.

It would also make the deferred destroy unnecessary, along with the
64-entry cap, its spurious -ENOMEM failures and the new dependency
on rds_wq.

On Kconfig: CONFIG_IPV6 is bool on mainline, so calling
ipv6_chk_addr() from connection.c needs no change there. Stable
trees where IPV6 can still be modular would need "depends on IPV6 ||
!IPV6" on RDS.

Is there a reason the local-address helper doesn't work for this
path? If so, could the changelog explain why the asynchronous destroy
was chosen instead?

[Severity: Medium]
Does deferring the destroy here make HCA removal wait on whatever else is
queued on rds_wq?

After a successful rdma_bind_addr(), the probe id is attached to its
cma_device in _cma_attach_to_dev():

	cma_dev_get(cma_dev);
	id_priv->cma_dev = cma_dev;

That reference is only dropped by cma_release_dev() when the id is
destroyed.

On device removal, cma_process_remove() sends
RDMA_CM_EVENT_DEVICE_REMOVAL to each id. For the probe id,
rds_rdma_cm_event_handler_cmn() has no conn and returns 0:

	case RDMA_CM_EVENT_DEVICE_REMOVAL:
	case RDMA_CM_EVENT_ADDR_CHANGE:
		if (conn)
			rds_conn_drop(conn);
		break;

So rdma_cm does not destroy the id itself, and cma_process_remove() then
waits with no timeout:

	cma_dev_put(cma_dev);
	wait_for_completion(&cma_dev->comp);

That wait can now only finish after rds_ib_probe_work_fn() runs on the
ordered rds_wq. Anything queued ahead of it delays it: the TCP accept loop
(which keeps running while remote connects arrive), rds_ib_dev_free,
unpin work and fallback connection workers. Before this patch the destroy
ran inline, right after the bind.

The existing flush_workqueue(rds_wq) calls in rds_ib_unregister_client()
and rds_tcp_listen_stop() also now wait for up to 64 rdma_destroy_id()
calls.

I couldn't show a closed deadlock cycle. Is this new dependency of a
synchronous RDMA core wait on unrelated RDS work intended?

>  
>  	return ret;
>  }

[ ... ]

> diff --git a/net/rds/transport.c b/net/rds/transport.c
> index 4e667580f8739..cb37d9b08f12c 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.
>  		 */

[Severity: Low]
This isn't a bug, but is this comment accurate for every transport the
loop visits?

rds_tcp_laddr_check() only uses inet_addr_type(), dev_get_by_index_rcu()
and ipv6_chk_addr(). It creates no rdma_cm id and defers nothing.

rds_ib_laddr_check() can also return 0 from the rds_ib_get_device() fast
path without creating an id.

The old "may create" wording was accurate. The new text also presents the
deferral as the reason for dropping rds_trans_sem, but the real constraint
is the IB-specific rdma_cm locking inside the check itself.

>  		up_read(&rds_trans_sem);
>

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204022245.381-1-chenaibing%40cmss.chinamobile.com

      reply	other threads:[~2026-12-05  3:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  2:22 [PATCH net v7 0/3] net/rds: fix the probe cm_id lock ordering Aibing Chen
2026-12-04  2:22 ` [PATCH net v7 1/3] net/rds: register the IB transport last Aibing Chen
2026-12-05  3:05   ` netdev-bot+sashiko
2026-12-04  2:22 ` [PATCH net v7 2/3] net/rds: drop rds_trans_sem around laddr_check() Aibing Chen
2026-12-05  3:05   ` netdev-bot+sashiko
2026-12-04  2:22 ` [PATCH net v7 3/3] net/rds: defer the probe cm_id destroy to rds_wq Aibing Chen
2026-12-05  3:05   ` netdev-bot+sashiko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179643993741.3146.5379085669209427809@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=achender@kernel.org \
    --cc=chenaibing@cmss.chinamobile.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox