* [PATCH] thunderbolt: Re-add host router DP IN adapters after DPRX failure
@ 2026-11-21 7:08 Alfonso Villalobos Ulate
[not found] ` <sashiko-outbox-226770@kernel.org>
0 siblings, 1 reply; 3+ messages in thread
From: Alfonso Villalobos Ulate @ 2026-11-21 7:08 UTC (permalink / raw)
To: westeri
Cc: andreas.noever, YehezkelShB, linux-usb, Alfonso Villalobos Ulate,
stable
When DPRX negotiation fails, the DP IN adapter is removed from the DP
resources and is only added back on a hotplug event for that adapter.
Host router DP IN adapters never get such events, so after one failure
(for example when the GPU feeding it is runtime suspended) the adapter
stays unused until the driver is reloaded.
Re-check the host router DP IN adapters when a DP OUT adapter appears
or a device router is plugged in, and skip adapters already on the
list. Keep host DP IN adapters in adapter order so a re-added one is
paired with the same DP OUT as before, instead of swapping monitors
with the other host DP IN.
Tested on an ASM4242 host with a CalDigit TS5 Plus dock.
Written with assistance from Claude Code (Claude Opus 5.5), which
proposed the code changes and drafted this message.
Fixes: d6d458d42e1e ("thunderbolt: Handle DisplayPort tunnel activation asynchronously")
Cc: stable@vger.kernel.org
Signed-off-by: Alfonso Villalobos Ulate <alfonsocvu@gmail.com>
---
drivers/thunderbolt/tb.c | 52 +++++++++++++++++++++++++++++++++++++---
1 file changed, 49 insertions(+), 3 deletions(-)
diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c
index 57c11ba13459..4a43da6817a2 100644
--- a/drivers/thunderbolt/tb.c
+++ b/drivers/thunderbolt/tb.c
@@ -109,6 +109,29 @@ static void tb_queue_hotplug(struct tb *tb, u64 route, u8 port, bool unplug)
/* enumeration & hot plug handling */
+/*
+ * Insert a host router DP IN adapter so that host DP IN adapters stay
+ * in adapter number order. A DP IN that is re-added after it was
+ * dropped (for example because DPRX negotiation failed) then gets
+ * paired with the same DP OUT as before, instead of swapping DP OUT
+ * adapters (and therefore monitors) with the other host DP IN.
+ */
+static void tb_add_host_dp_in(struct tb_cm *tcm, struct tb_port *port)
+{
+ struct tb_port *p;
+
+ list_for_each_entry(p, &tcm->dp_resources, list) {
+ if (tb_port_is_dpin(p) && !tb_route(p->sw) &&
+ p->port > port->port) {
+ /* Insert before the first higher numbered one */
+ list_add_tail(&port->list, &p->list);
+ return;
+ }
+ }
+
+ list_add_tail(&port->list, &tcm->dp_resources);
+}
+
static void tb_add_dp_resources(struct tb_switch *sw)
{
struct tb_cm *tcm = tb_priv(sw->tb);
@@ -118,6 +141,9 @@ static void tb_add_dp_resources(struct tb_switch *sw)
if (!tb_port_is_dpin(port))
continue;
+ if (!list_empty(&port->list))
+ continue;
+
if (!tb_switch_query_dp_resource(sw, port))
continue;
@@ -130,7 +156,7 @@ static void tb_add_dp_resources(struct tb_switch *sw)
if (tb_route(sw))
list_add(&port->list, &tcm->dp_resources);
else
- list_add_tail(&port->list, &tcm->dp_resources);
+ tb_add_host_dp_in(tcm, port);
tb_port_dbg(port, "DP IN resource available\n");
}
@@ -1421,6 +1447,16 @@ static void tb_scan_port(struct tb_port *port)
tb_sw_warn(sw, "USB3 tunnel creation failed\n");
tb_add_dp_resources(sw);
+
+ /*
+ * Host router DP IN adapters may have been dropped earlier
+ * (for example because DPRX negotiation failed) and they do
+ * not get hotplug events of their own, so re-check them now
+ * that there is potentially a new DP OUT to pair with.
+ */
+ if (tcm->hotplug_active)
+ tb_add_dp_resources(sw->tb->root_switch);
+
tb_scan_switch(sw);
out_rpm_put:
@@ -1971,8 +2007,10 @@ static void tb_dp_tunnel_active(struct tb_tunnel *tunnel, void *data)
* also tear down the tunnel and try to re-use the
* released DP OUT.
*
- * It will be added back only if there is hotplug for
- * the DP IN again.
+ * It will be added back if there is hotplug for the
+ * DP IN again. Host router DP IN adapters do not get
+ * such events, so they are re-checked whenever a new
+ * DP OUT or device router appears instead.
*/
tb_tunnel_warn(tunnel, "not active, tearing down\n");
tb_dp_resource_unavailable(tb, in, "DPRX negotiation failed");
@@ -2234,6 +2272,14 @@ static void tb_dp_resource_available(struct tb *tb, struct tb_port *port)
list_add_tail(&port->list, &tcm->dp_resources);
tb_exit_redrive(port);
+ /*
+ * Host router DP IN adapters removed because DPRX negotiation
+ * failed never get a hotplug event of their own. Give them
+ * another chance now that a DP OUT became available.
+ */
+ if (tb_port_is_dpout(port))
+ tb_add_dp_resources(tb->root_switch);
+
/* Look for suitable DP IN <-> DP OUT pairs now */
tb_tunnel_dp(tb);
}
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread[parent not found: <sashiko-outbox-226770@kernel.org>]
* Re: [PATCH] thunderbolt: Re-add host router DP IN adapters after DPRX failure [not found] ` <sashiko-outbox-226770@kernel.org> @ 2026-11-21 15:07 ` Alfonso Villalobos 2026-11-23 5:40 ` Mika Westerberg 0 siblings, 1 reply; 3+ messages in thread From: Alfonso Villalobos @ 2026-11-21 15:07 UTC (permalink / raw) To: sashiko-reviews, westeri Cc: linux-usb, andreas.noever, YehezkelShB, Alfonso Villalobos Ulate, stable Hi Mika, hope you're having a great day. I'd like to check the direction with you before doing v2. After the Sashiko review and looking closer at how host router DP IN adapters are handled, I'm not sure v1 fixes this in the right place. The DPRX failure happens when the RX 9070 XT feeding 0:10 is in BACO. With runtime PM disabled for the GPU it always works. After the failure the host router never sends a hotplug for 0:10, so it stays unused until something triggers the re-check from v1, here me replugging the dock at 00:27:26: [00:26:36] 0:10 <-> 1:11 (DP): activating [00:26:36] 0:11 <-> 1:12 (DP): activating [00:26:48] 0:10 <-> 1:11 (DP): not active, tearing down [00:26:48] 0:10: DP IN resource unavailable: DPRX negotiation failed [00:27:26] 0:10: DP IN resource available [00:27:26] 0:11 <-> 1:11 (DP): activating [00:27:26] 0:10 <-> 1:12 (DP): activating The DP OUTs also end up swapped, so the ordering part of v1 doesn't work as intended either. The comment in tb_dp_tunnel_active() and the redrive code both seem to expect a hotplug for host DP IN adapters. Is the ASM4242 supposed to send one once the GPU starts driving the DP IN? If this is ASM4242 specific I can limit the fix to it with a quirk. v1 also only recovers on a new event. The alternative I had in mind is retrying the DP IN a few times with a delay after DPRX fails, so it recovers without a replug. Which is better? I already have fixes for the Sashiko comments (the missing tb_exit_redrive() and the ordering in tb_dp_resource_available()) and one to skip DP IN adapters that are already in a tunnel, but I'd like your opinion before spending more time on it. Thanks, Alfonso On Sat, Nov 21, 2026 at 1:25 AM <sashiko-bot@kernel.org> wrote: > > Thank you for your contribution! Sashiko AI review found 2 potential > issues to consider: > - [Medium] thunderbolt: missing tb_exit_redrive() in > tb_add_dp_resources() leaks RPM ref > - [Medium] thunderbolt: list_add_tail() in tb_dp_resource_available() > breaks DP IN order > -- > > commit 4eedd8886dc180b45204d935f18725051dd0e6a0 > Author: Alfonso Villalobos Ulate <alfonsocvu@gmail.com> > > thunderbolt: Re-add host router DP IN adapters after DPRX failure > > This commit re-checks host router DP IN adapters when a new DP OUT adapter > becomes available or a device router is scanned, keeping host DP IN > adapters ordered by adapter number on tcm->dp_resources. > > > diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c > > index 418ad0a61a5de..1f3dea836067e 100644 > > --- a/drivers/thunderbolt/tb.c > > +++ b/drivers/thunderbolt/tb.c > > @@ -109,6 +109,29 @@ static void tb_queue_hotplug(struct tb *tb, u64 route, u8 port, bool unplug) > > > > /* enumeration & hot plug handling */ > > > > +/* > > + * Insert a host router DP IN adapter so that host DP IN adapters stay > > + * in adapter number order. A DP IN that is re-added after it was > > + * dropped (for example because DPRX negotiation failed) then gets > > + * paired with the same DP OUT as before, instead of swapping DP OUT > > + * adapters (and therefore monitors) with the other host DP IN. > > + */ > > +static void tb_add_host_dp_in(struct tb_cm *tcm, struct tb_port *port) > > +{ > > + struct tb_port *p; > > + > > + list_for_each_entry(p, &tcm->dp_resources, list) { > > + if (tb_port_is_dpin(p) && !tb_route(p->sw) && > > + p->port > port->port) { > > + /* Insert before the first higher numbered one */ > > + list_add_tail(&port->list, &p->list); > > + return; > > + } > > + } > > + > > + list_add_tail(&port->list, &tcm->dp_resources); > > +} > > + > > static void tb_add_dp_resources(struct tb_switch *sw) > > { > > struct tb_cm *tcm = tb_priv(sw->tb); > > @@ -118,6 +141,9 @@ static void tb_add_dp_resources(struct tb_switch *sw) > > if (!tb_port_is_dpin(port)) > > continue; > > > > + if (!list_empty(&port->list)) > > + continue; > > + > > if (!tb_switch_query_dp_resource(sw, port)) > > continue; > > > > @@ -130,7 +156,7 @@ static void tb_add_dp_resources(struct tb_switch *sw) > > if (tb_route(sw)) > > list_add(&port->list, &tcm->dp_resources); > > else > > - list_add_tail(&port->list, &tcm->dp_resources); > > + tb_add_host_dp_in(tcm, port); > > > > tb_port_dbg(port, "DP IN resource available\n"); > > } > > [Severity: Medium] > Does re-adding a host router DP IN port through tb_add_dp_resources() leak > the runtime PM reference on sw->dev when the port was in redrive mode? > > On host routers with QUIRK_KEEP_POWER_IN_DP_REDRIVE, tb_enter_redrive() > sets port->redrive and calls pm_runtime_get(&sw->dev). When > tb_add_dp_resources(tb->root_switch) now runs at runtime from > tb_scan_port() or tb_dp_resource_available(), it adds the host DP IN port > to tcm->dp_resources without calling tb_exit_redrive(port). Any later > tb_dp_resource_available() call for that DP IN port then returns early > because the port is already on tcm->dp_resources (or already enabled by > tb_tunnel_dp()), leaving port->redrive set and preventing the host router > from suspending. > > [ ... ] > > > @@ -2234,6 +2272,14 @@ static void tb_dp_resource_available(struct tb *tb, struct tb_port *port) > > list_add_tail(&port->list, &tcm->dp_resources); > > tb_exit_redrive(port); > > > > + /* > > + * Host router DP IN adapters removed because DPRX negotiation > > + * failed never get a hotplug event of their own. Give them > > + * another chance now that a DP OUT became available. > > + */ > > + if (tb_port_is_dpout(port)) > > + tb_add_dp_resources(tb->root_switch); > > + > > /* Look for suitable DP IN <-> DP OUT pairs now */ > > tb_tunnel_dp(tb); > > } > > [Severity: Medium] > Should tb_dp_resource_available() also use tb_add_host_dp_in() when adding > a host router DP IN port? > > When a lower-numbered host DP IN port becomes available via hotplug in > tb_dp_resource_available() (such as when exiting redrive mode or after > resume) while a higher-numbered host DP IN port is already on > tcm->dp_resources, list_add_tail() places the lower-numbered port after > the higher-numbered one, breaking the adapter ordering that > tb_add_host_dp_in() maintains. > > -- > Sashiko AI review · https://sashiko.dev/#/patchset/20261121070804.26185-1-alfonsocvu@gmail.com?part=1 ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] thunderbolt: Re-add host router DP IN adapters after DPRX failure 2026-11-21 15:07 ` Alfonso Villalobos @ 2026-11-23 5:40 ` Mika Westerberg 0 siblings, 0 replies; 3+ messages in thread From: Mika Westerberg @ 2026-11-23 5:40 UTC (permalink / raw) To: Alfonso Villalobos Cc: sashiko-reviews, westeri, linux-usb, andreas.noever, YehezkelShB, stable Hi, On Sat, Nov 21, 2026 at 09:07:04AM -0600, Alfonso Villalobos wrote: > Hi Mika, hope you're having a great day. > > I'd like to check the direction with you before doing v2. After the > Sashiko review and looking closer at how host router DP IN adapters > are handled, I'm not sure v1 fixes this in the right place. > > The DPRX failure happens when the RX 9070 XT feeding 0:10 is in BACO. > With runtime PM disabled for the GPU it always works. After the > failure the host router never sends a hotplug for 0:10, so it stays > unused until something triggers the re-check from v1, here me > replugging the dock at 00:27:26: > > [00:26:36] 0:10 <-> 1:11 (DP): activating > [00:26:36] 0:11 <-> 1:12 (DP): activating > [00:26:48] 0:10 <-> 1:11 (DP): not active, tearing down > [00:26:48] 0:10: DP IN resource unavailable: DPRX negotiation failed > [00:27:26] 0:10: DP IN resource available > [00:27:26] 0:11 <-> 1:11 (DP): activating > [00:27:26] 0:10 <-> 1:12 (DP): activating Does the RX 9070 driver poll for a new connections periodically like the i915/xe or it supports PME? The current DPRX timeout is pretty much following the i915 that has 10s polling period so simple way of working this around is to set thunderbolt.dprx_timeout= to match that. > The DP OUTs also end up swapped, so the ordering part of v1 doesn't > work as intended either. At the moment tunnels are created pretty much in the order the hotplugs arrive. > The comment in tb_dp_tunnel_active() and the redrive code both seem > to expect a hotplug for host DP IN adapters. Is the ASM4242 supposed > to send one once the GPU starts driving the DP IN? If this is > ASM4242 specific I can limit the fix to it with a quirk. The hotplugs should happen when the host router is enumerated so for example in your case it should work so that if graphics did not do DRPX capability exchange in time, the DP tunnel is torn down and if conditions are right the domain is put to sleep. When you wake it up there should be new hotplugs to DP INs so the resource is added back to the list. > v1 also only recovers on a new event. The alternative I had in mind > is retrying the DP IN a few times with a delay after DPRX fails, so > it recovers without a replug. Which is better? Can you first check if drpx_timeout= helps in your case? If it does, for simplicity one option is that we just make the default match the "biggest" and some slack. > I already have fixes for the Sashiko comments (the missing > tb_exit_redrive() and the ordering in tb_dp_resource_available()) and > one to skip DP IN adapters that are already in a tunnel, but I'd like > your opinion before spending more time on it. > > Thanks, > Alfonso > > On Sat, Nov 21, 2026 at 1:25 AM <sashiko-bot@kernel.org> wrote: > > > > Thank you for your contribution! Sashiko AI review found 2 potential > > issues to consider: > > - [Medium] thunderbolt: missing tb_exit_redrive() in > > tb_add_dp_resources() leaks RPM ref > > - [Medium] thunderbolt: list_add_tail() in tb_dp_resource_available() > > breaks DP IN order > > -- > > > > commit 4eedd8886dc180b45204d935f18725051dd0e6a0 > > Author: Alfonso Villalobos Ulate <alfonsocvu@gmail.com> > > > > thunderbolt: Re-add host router DP IN adapters after DPRX failure > > > > This commit re-checks host router DP IN adapters when a new DP OUT adapter > > becomes available or a device router is scanned, keeping host DP IN > > adapters ordered by adapter number on tcm->dp_resources. > > > > > diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c > > > index 418ad0a61a5de..1f3dea836067e 100644 > > > --- a/drivers/thunderbolt/tb.c > > > +++ b/drivers/thunderbolt/tb.c > > > @@ -109,6 +109,29 @@ static void tb_queue_hotplug(struct tb *tb, u64 route, u8 port, bool unplug) > > > > > > /* enumeration & hot plug handling */ > > > > > > +/* > > > + * Insert a host router DP IN adapter so that host DP IN adapters stay > > > + * in adapter number order. A DP IN that is re-added after it was > > > + * dropped (for example because DPRX negotiation failed) then gets > > > + * paired with the same DP OUT as before, instead of swapping DP OUT > > > + * adapters (and therefore monitors) with the other host DP IN. > > > + */ > > > +static void tb_add_host_dp_in(struct tb_cm *tcm, struct tb_port *port) > > > +{ > > > + struct tb_port *p; > > > + > > > + list_for_each_entry(p, &tcm->dp_resources, list) { > > > + if (tb_port_is_dpin(p) && !tb_route(p->sw) && > > > + p->port > port->port) { > > > + /* Insert before the first higher numbered one */ > > > + list_add_tail(&port->list, &p->list); > > > + return; > > > + } > > > + } > > > + > > > + list_add_tail(&port->list, &tcm->dp_resources); > > > +} > > > + > > > static void tb_add_dp_resources(struct tb_switch *sw) > > > { > > > struct tb_cm *tcm = tb_priv(sw->tb); > > > @@ -118,6 +141,9 @@ static void tb_add_dp_resources(struct tb_switch *sw) > > > if (!tb_port_is_dpin(port)) > > > continue; > > > > > > + if (!list_empty(&port->list)) > > > + continue; > > > + > > > if (!tb_switch_query_dp_resource(sw, port)) > > > continue; > > > > > > @@ -130,7 +156,7 @@ static void tb_add_dp_resources(struct tb_switch *sw) > > > if (tb_route(sw)) > > > list_add(&port->list, &tcm->dp_resources); > > > else > > > - list_add_tail(&port->list, &tcm->dp_resources); > > > + tb_add_host_dp_in(tcm, port); > > > > > > tb_port_dbg(port, "DP IN resource available\n"); > > > } > > > > [Severity: Medium] > > Does re-adding a host router DP IN port through tb_add_dp_resources() leak > > the runtime PM reference on sw->dev when the port was in redrive mode? > > > > On host routers with QUIRK_KEEP_POWER_IN_DP_REDRIVE, tb_enter_redrive() > > sets port->redrive and calls pm_runtime_get(&sw->dev). When > > tb_add_dp_resources(tb->root_switch) now runs at runtime from > > tb_scan_port() or tb_dp_resource_available(), it adds the host DP IN port > > to tcm->dp_resources without calling tb_exit_redrive(port). Any later > > tb_dp_resource_available() call for that DP IN port then returns early > > because the port is already on tcm->dp_resources (or already enabled by > > tb_tunnel_dp()), leaving port->redrive set and preventing the host router > > from suspending. > > > > [ ... ] > > > > > @@ -2234,6 +2272,14 @@ static void tb_dp_resource_available(struct tb *tb, struct tb_port *port) > > > list_add_tail(&port->list, &tcm->dp_resources); > > > tb_exit_redrive(port); > > > > > > + /* > > > + * Host router DP IN adapters removed because DPRX negotiation > > > + * failed never get a hotplug event of their own. Give them > > > + * another chance now that a DP OUT became available. > > > + */ > > > + if (tb_port_is_dpout(port)) > > > + tb_add_dp_resources(tb->root_switch); > > > + > > > /* Look for suitable DP IN <-> DP OUT pairs now */ > > > tb_tunnel_dp(tb); > > > } > > > > [Severity: Medium] > > Should tb_dp_resource_available() also use tb_add_host_dp_in() when adding > > a host router DP IN port? > > > > When a lower-numbered host DP IN port becomes available via hotplug in > > tb_dp_resource_available() (such as when exiting redrive mode or after > > resume) while a higher-numbered host DP IN port is already on > > tcm->dp_resources, list_add_tail() places the lower-numbered port after > > the higher-numbered one, breaking the adapter ordering that > > tb_add_host_dp_in() maintains. > > > > -- > > Sashiko AI review · https://sashiko.dev/#/patchset/20261121070804.26185-1-alfonsocvu@gmail.com?part=1 ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-23 5:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-21 7:08 [PATCH] thunderbolt: Re-add host router DP IN adapters after DPRX failure Alfonso Villalobos Ulate
[not found] ` <sashiko-outbox-226770@kernel.org>
2026-11-21 15:07 ` Alfonso Villalobos
2026-11-23 5:40 ` Mika Westerberg
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox