Netdev List
 help / color / mirror / Atom feed
* [PATCH net v3 0/2] net: thunderbolt: two fixes for the failed bring-up path
@ 2026-08-11 13:20 Fan Ye via B4 Relay
  2026-08-11 13:20 ` [PATCH net v3 1/2] net: thunderbolt: Release the Rx HopID that was handed out on mismatch Fan Ye via B4 Relay
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Fan Ye via B4 Relay @ 2026-08-11 13:20 UTC (permalink / raw)
  To: Mika Westerberg, Yehezkel Bernat, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Andy Shevchenko
  Cc: Mika Westerberg, netdev, linux-kernel, stable, Fan Ye

Two separate defects reached through the same branch in
tbnet_connected_work(), found on an ASMedia ASM4242 host-to-host link
when the peer drops out while a connection is being brought up.

  1 releases the HopID the allocator handed out when it is not the one
    that was asked for.  Today it stays allocated for the rest of the
    XDomain connection.

  2 marks the connection down on the failure paths, so the next
    tbnet_tear_down() does not run a second teardown over work that was
    already undone: stopping rings that are already stopped, which is
    fatal under panic_on_warn, and handing back a HopID this connection
    never owned.

Patch 2 edits the lines patch 1 adds, so it has to come second.

Changes in v3:
- Cut both commit messages down after review; the code is unchanged
  apart from the comment on the new helper in patch 2, now one line.
- Link to v2: https://lore.kernel.org/netdev/20260810-b4-tbnet-hopid-v2-0-0eee557e75df@gmail.com/

---
Fan Ye (2):
      net: thunderbolt: Release the Rx HopID that was handed out on mismatch
      net: thunderbolt: Mark the connection down when bringing it up fails

 drivers/net/thunderbolt/main.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
---
base-commit: d58772d8520c7ef247c4b95c9bd76d3a25da9ff5
change-id: 20260811-b4-tbnet-hopid-d542741b363d

Best regards,
--  
Fan Ye <fy15309206903@gmail.com>



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net v3 1/2] net: thunderbolt: Release the Rx HopID that was handed out on mismatch
  2026-08-11 13:20 [PATCH net v3 0/2] net: thunderbolt: two fixes for the failed bring-up path Fan Ye via B4 Relay
@ 2026-08-11 13:20 ` Fan Ye via B4 Relay
  2026-08-11 13:20 ` [PATCH net v3 2/2] net: thunderbolt: Mark the connection down when bringing it up fails Fan Ye via B4 Relay
  2026-08-13 13:10 ` [PATCH net v3 0/2] net: thunderbolt: two fixes for the failed bring-up path Simon Horman
  2 siblings, 0 replies; 4+ messages in thread
From: Fan Ye via B4 Relay @ 2026-08-11 13:20 UTC (permalink / raw)
  To: Mika Westerberg, Yehezkel Bernat, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Andy Shevchenko
  Cc: Mika Westerberg, netdev, linux-kernel, stable, Fan Ye

From: Fan Ye <fy15309206903@gmail.com>

tb_xdomain_alloc_in_hopid() passes the wanted HopID to ida_alloc_range()
as the lower bound, so a taken id is not an error there: the allocator
returns the next free one above it. tbnet_connected_work() asks for the
peer's transmit path, treats any other id as a failure and returns
without releasing what it got, so that allocation stays live for the rest
of the XDomain connection with nothing left holding a reference to it.

Release the id when it is not the one we asked for, the same way the
error unwind at the end of the function releases the expected one.

Fixes: 180b0689425c ("thunderbolt: Allow multiple DMA tunnels over a single XDomain connection")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-5
Signed-off-by: Fan Ye <fy15309206903@gmail.com>
Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
Reached without fault injection on an ASMedia ASM4242 host-to-host link
when the peer drops out mid bring-up: 23 times across two hosts in one
run of interface down/up cycling. Each one ended in the XDomain
connection being rebuilt, which recreates the ida and disposes of the
leaked id, so what I am claiming here is the leak, not a symptom.

Patch 2/2 edits the lines this one adds and will not apply without it.

v3:
- Rewrote the commit message; dropped the quoted source and probe output.

v2: https://lore.kernel.org/netdev/20260810-b4-tbnet-hopid-v2-0-0eee557e75df@gmail.com/
---
 drivers/net/thunderbolt/main.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/thunderbolt/main.c b/drivers/net/thunderbolt/main.c
index 98893732bc6e..e5199a87ea7a 100644
--- a/drivers/net/thunderbolt/main.c
+++ b/drivers/net/thunderbolt/main.c
@@ -647,6 +647,8 @@ static void tbnet_connected_work(struct work_struct *work)
 	ret = tb_xdomain_alloc_in_hopid(net->xd, net->remote_transmit_path);
 	if (ret != net->remote_transmit_path) {
 		netdev_err(net->dev, "failed to allocate Rx HopID\n");
+		if (ret >= 0)
+			tb_xdomain_release_in_hopid(net->xd, ret);
 		return;
 	}
 

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH net v3 2/2] net: thunderbolt: Mark the connection down when bringing it up fails
  2026-08-11 13:20 [PATCH net v3 0/2] net: thunderbolt: two fixes for the failed bring-up path Fan Ye via B4 Relay
  2026-08-11 13:20 ` [PATCH net v3 1/2] net: thunderbolt: Release the Rx HopID that was handed out on mismatch Fan Ye via B4 Relay
@ 2026-08-11 13:20 ` Fan Ye via B4 Relay
  2026-08-13 13:10 ` [PATCH net v3 0/2] net: thunderbolt: two fixes for the failed bring-up path Simon Horman
  2 siblings, 0 replies; 4+ messages in thread
From: Fan Ye via B4 Relay @ 2026-08-11 13:20 UTC (permalink / raw)
  To: Mika Westerberg, Yehezkel Bernat, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Andy Shevchenko
  Cc: Mika Westerberg, netdev, linux-kernel, stable, Fan Ye

From: Fan Ye <fy15309206903@gmail.com>

Every failure path in tbnet_connected_work() undoes its own work and
returns without clearing login_sent, so the connection still looks
established. The next tbnet_tear_down() therefore takes its main branch
and repeats a teardown that already happened: it stops rings that are
already stopped, which is a dev_WARN() and fatal under panic_on_warn,
and it releases net->remote_transmit_path even on the HopID mismatch
path, where this connection never owned that id, silently freeing one
that someone else is still using.

Clear login_sent on those paths. That is enough for tbnet_tear_down() to
leave the unwound state alone, and login_received has to stay set: it
records that the peer has logged in and carries the transmit path it gave
us, which nothing on this side can make the peer send again. Two things
change beyond keeping the teardown out of the way: the logout request in
that block is no longer sent, and the peer's next login request now
re-queues our login work rather than connected_work, giving the
connection a fresh login instead of a retry on stale state.

Fixes: e69b6c02b4c3 ("net: Add support for networking over Thunderbolt cable")
Cc: <stable@vger.kernel.org> # 5.13+
Assisted-by: Claude:claude-opus-5
Signed-off-by: Fan Ye <fy15309206903@gmail.com>
Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
Two ASMedia ASM4242 hosts, interface cycled down and up, cold boot, only
thunderbolt-net differing between the runs. Unpatched, every mismatch is
followed in the same second by exactly two "ring already stopped"
warnings - host A 11 and 22, host B 12 and 24. Patched, 9 and 13
mismatches produce none.

Applies on top of patch 1/2, which adds the lines this one edits.

v3:
- Rewrote the commit message; dropped the quoted logs.
- Cut the comment in tbnet_connect_failed() to one line.

v2: https://lore.kernel.org/netdev/20260810-b4-tbnet-hopid-v2-0-0eee557e75df@gmail.com/
---
 drivers/net/thunderbolt/main.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/net/thunderbolt/main.c b/drivers/net/thunderbolt/main.c
index e5199a87ea7a..2a1728621887 100644
--- a/drivers/net/thunderbolt/main.c
+++ b/drivers/net/thunderbolt/main.c
@@ -626,6 +626,14 @@ static int tbnet_alloc_tx_buffers(struct tbnet *net)
 	return 0;
 }
 
+static void tbnet_connect_failed(struct tbnet *net)
+{
+	/* Leave login_received set: only the peer can make it true again. */
+	mutex_lock(&net->connection_lock);
+	net->login_sent = false;
+	mutex_unlock(&net->connection_lock);
+}
+
 static void tbnet_connected_work(struct work_struct *work)
 {
 	struct tbnet *net = container_of(work, typeof(*net), connected_work);
@@ -649,6 +657,7 @@ static void tbnet_connected_work(struct work_struct *work)
 		netdev_err(net->dev, "failed to allocate Rx HopID\n");
 		if (ret >= 0)
 			tb_xdomain_release_in_hopid(net->xd, ret);
+		tbnet_connect_failed(net);
 		return;
 	}
 
@@ -693,6 +702,7 @@ static void tbnet_connected_work(struct work_struct *work)
 	tb_ring_stop(net->rx_ring.ring);
 	tb_ring_stop(net->tx_ring.ring);
 	tb_xdomain_release_in_hopid(net->xd, net->remote_transmit_path);
+	tbnet_connect_failed(net);
 }
 
 static void tbnet_login_work(struct work_struct *work)

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net v3 0/2] net: thunderbolt: two fixes for the failed bring-up path
  2026-08-11 13:20 [PATCH net v3 0/2] net: thunderbolt: two fixes for the failed bring-up path Fan Ye via B4 Relay
  2026-08-11 13:20 ` [PATCH net v3 1/2] net: thunderbolt: Release the Rx HopID that was handed out on mismatch Fan Ye via B4 Relay
  2026-08-11 13:20 ` [PATCH net v3 2/2] net: thunderbolt: Mark the connection down when bringing it up fails Fan Ye via B4 Relay
@ 2026-08-13 13:10 ` Simon Horman
  2 siblings, 0 replies; 4+ messages in thread
From: Simon Horman @ 2026-08-13 13:10 UTC (permalink / raw)
  To: fy15309206903
  Cc: Mika Westerberg, Yehezkel Bernat, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Andy Shevchenko,
	Mika Westerberg, netdev, linux-kernel, stable

On Tue, Aug 11, 2026 at 01:20:48PM +0000, Fan Ye via B4 Relay wrote:
> Two separate defects reached through the same branch in
> tbnet_connected_work(), found on an ASMedia ASM4242 host-to-host link
> when the peer drops out while a connection is being brought up.
> 
>   1 releases the HopID the allocator handed out when it is not the one
>     that was asked for.  Today it stays allocated for the rest of the
>     XDomain connection.
> 
>   2 marks the connection down on the failure paths, so the next
>     tbnet_tear_down() does not run a second teardown over work that was
>     already undone: stopping rings that are already stopped, which is
>     fatal under panic_on_warn, and handing back a HopID this connection
>     never owned.
> 
> Patch 2 edits the lines patch 1 adds, so it has to come second.
> 
> Changes in v3:
> - Cut both commit messages down after review; the code is unchanged
>   apart from the comment on the new helper in patch 2, now one line.
> - Link to v2: https://lore.kernel.org/netdev/20260810-b4-tbnet-hopid-v2-0-0eee557e75df@gmail.com/

For the series:

Reviewed-by: Simon Horman <horms@kernel.org>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-08-13 13:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-11 13:20 [PATCH net v3 0/2] net: thunderbolt: two fixes for the failed bring-up path Fan Ye via B4 Relay
2026-08-11 13:20 ` [PATCH net v3 1/2] net: thunderbolt: Release the Rx HopID that was handed out on mismatch Fan Ye via B4 Relay
2026-08-11 13:20 ` [PATCH net v3 2/2] net: thunderbolt: Mark the connection down when bringing it up fails Fan Ye via B4 Relay
2026-08-13 13:10 ` [PATCH net v3 0/2] net: thunderbolt: two fixes for the failed bring-up path Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox