Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: achender@kernel.org
Cc: netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
	pabeni@redhat.com, edumazet@google.com, kuba@kernel.org,
	horms@kernel.org
Subject: Re: [PATCH net-next v6 07/12] net/rds: unlink transport nodes before a possibly deferred connection free
Date: Sat, 26 Sep 2026 09:48:40 +0000	[thread overview]
Message-ID: <179041612062.2160803.18299462555335020383@kernel.org> (raw)
In-Reply-To: <20260922085410.391323-8-achender@kernel.org>

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] Stale/unreachable justification for the new per-connection
  reference in rds_ib_destroy_nodev_conns(): both the commit message ("A…

--

net/rds: unlink transport nodes before a possibly deferred connection free

The RDS transport teardown helpers now unlink each per-connection
transport node under the transport lock right before calling
rds_conn_destroy(), so a conn_free() that runs after the helper has
returned does not touch a list head on a dead stack frame.  IB gets an
explicit i_ib_node_detached flag, and the gather loops take a reference
on each connection they move onto the stack list.

> The walk itself must not lose the entries either.  A connection that
> was destroyed earlier - dropped for a protocol version mismatch, then
> found again at module unload - is kept alive only by whatever
> reference is still pending, and that can be dropped at any point
> during the walk, freeing the transport node the iterator is about to
> read.

[Severity: Low]
Is this scenario reachable in this tree?  A grep for rds_conn_destroy()
callers at this commit finds only the five teardown helpers:

  net/rds/ib_rdma.c:  rds_ib_destroy_nodev_conns()
  net/rds/loop.c:     rds_loop_destroy_gathered_conns()
  net/rds/tcp.c:      rds_tcp_destroy_gathered_conns()

There is no protocol-version-mismatch caller of rds_conn_destroy() any
more - net/rds/ib_cm.c has none, that path was converted to
rds_conn_drop() upstream by f97d8c7bab78 - so a connection cannot have
been "destroyed earlier ... for a protocol version mismatch".

The same commit message also says two paragraphs earlier:

> That is fine for as long as rds_conn_destroy() frees the connection
> before it returns, which is still the case at this point in the
> series: the initial reference is the only one.

and the sibling patch "net/rds: make rds_destroy_pending() report a
connection's own destroy" states that "Today every rds_conn_destroy()
does happen on one of those two global paths".

Could this paragraph be reworded to say that the reference is
preparation for the later patches that hand out references, rather than
describing a use-after-free that exists today?  As written, and with no
Fixes: tag, it reads like a fix for a live bug.

> diff --git a/net/rds/ib_rdma.c b/net/rds/ib_rdma.c
> index a9b27f06cbfcf..1548e5be0e559 100644
> --- a/net/rds/ib_rdma.c
> +++ b/net/rds/ib_rdma.c

[ ... ]

> @@ -163,13 +173,40 @@ void rds_ib_destroy_nodev_conns(void)
>  	struct rds_ib_connection *ic, *_ic;
>  	LIST_HEAD(tmp_list);
>  
> -	/* avoid calling conn_destroy with irqs off */
> +	struct rds_connection *conn;
> +
> +	/* Gather the connections and take a reference on each, so that
> +	 * none is freed under the walk below (a connection destroyed
> +	 * earlier, for a protocol version mismatch, can be on this list
> +	 * with only a socket's reference still pending).  One whose free

[Severity: Low]
The same claim is repeated here in the comment on
rds_ib_destroy_nodev_conns(), so the stale justification ends up in the
source tree and stays there through the rest of the series.  Since
nothing calls rds_conn_destroy() for a protocol version mismatch, and
rds_ib_destroy_nodev_conns() is only reached from rds_ib_exit() and its
resweep, is there a caller that can drop a pending reference under this
walk today?

Would it be clearer to describe the rds_conn_get_unless_zero() here as
guarding against the deferred frees introduced later in the series?

> +	 * is already running gets no reference: its free unlinks the
> +	 * node itself, under this lock, once we drop it.  Marking the
> +	 * node detached claims it for this sweep: rds_ib_add_conn(),
> +	 * rds_ib_remove_conn() and rds_ib_conn_free() leave a claimed
> +	 * node alone, so the walk over tmp_list below needs no lock.
> +	 * Avoid calling conn_destroy with irqs off.
> +	 */
>  	spin_lock_irq(&ib_nodev_conns_lock);
> -	list_splice_init(&ib_nodev_conns, &tmp_list);
> +	list_for_each_entry_safe(ic, _ic, &ib_nodev_conns, ib_node) {
> +		if (rds_conn_get_unless_zero(ic->conn)) {
> +			ic->i_ib_node_detached = true;
> +			list_move_tail(&ic->ib_node, &tmp_list);
> +		}
> +	}
>  	spin_unlock_irq(&ib_nodev_conns_lock);
>  
> -	list_for_each_entry_safe(ic, _ic, &tmp_list, ib_node)
> -		rds_conn_destroy(ic->conn);
> +	/* rds_conn_destroy() can return before the connection is freed,
> +	 * and it is the free - rds_ib_conn_free() - that would unlink
> +	 * ib_node.  tmp_list lives on this stack frame, so take each node
> +	 * off it before its destroy; the free then leaves it alone.
> +	 */
> +	list_for_each_entry_safe(ic, _ic, &tmp_list, ib_node) {
> +		conn = ic->conn;
> +		list_del_init(&ic->ib_node);
> +
> +		rds_conn_destroy(conn);
> +		rds_conn_put(conn);
> +	}
>  }

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260922085410.391323-1-achender%40kernel.org

  reply	other threads:[~2026-09-26  9:48 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22  8:53 [PATCH net-next v6 00/12] net/rds: make connection lifetime reference-counted Allison Henderson
2026-09-22  8:53 ` [PATCH net-next v6 01/12] net/rds: ib: don't enable interrupts in rds_ib_conn_free() Allison Henderson
2026-09-22  8:54 ` [PATCH net-next v6 02/12] net/rds: undo conn_alloc() the same way on every __rds_conn_create() exit Allison Henderson
2026-09-22  8:54 ` [PATCH net-next v6 03/12] net/rds: guard every work-requeueing site with rds_destroy_pending() Allison Henderson
2026-09-22  8:54 ` [PATCH net-next v6 04/12] net/rds: make rds_destroy_pending() report a connection's own destroy Allison Henderson
2026-09-26  9:48   ` netdev-bot+sashiko
2026-09-22  8:54 ` [PATCH net-next v6 05/12] net/rds: split connection destroy into quiesce and kref-governed free Allison Henderson
2026-09-26  9:48   ` netdev-bot+sashiko
2026-09-22  8:54 ` [PATCH net-next v6 06/12] net/rds: wait for connections to be freed on transport unload Allison Henderson
2026-09-26  9:48   ` netdev-bot+sashiko
2026-09-22  8:54 ` [PATCH net-next v6 07/12] net/rds: unlink transport nodes before a possibly deferred connection free Allison Henderson
2026-09-26  9:48   ` netdev-bot+sashiko [this message]
2026-09-22  8:54 ` [PATCH net-next v6 08/12] net/rds: hold connection references in lookup, sockets and c_passive Allison Henderson
2026-09-26  9:48   ` netdev-bot+sashiko
2026-09-22  8:54 ` [PATCH net-next v6 09/12] net/rds: take cp_lock to purge cp_send_queue in the quiesce Allison Henderson
2026-09-26  9:48   ` netdev-bot+sashiko
2026-09-22  8:54 ` [PATCH net-next v6 10/12] net/rds: pin the connection across RDMA-CM event handling Allison Henderson
2026-09-26  9:48   ` netdev-bot+sashiko
2026-09-22  8:54 ` [PATCH net-next v6 11/12] net/rds: drop rds_conn_count in favor of t_conn_count Allison Henderson
2026-09-22  8:54 ` [PATCH net-next v6 12/12] net/rds: hold a connection reference from struct rds_incoming Allison Henderson

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=179041612062.2160803.18299462555335020383@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=achender@kernel.org \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /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