From: Tobias Heath <heathtobias@gmail.com>
To: Andreas Noever <andreas.noever@gmail.com>,
Mika Westerberg <westeri@kernel.org>,
Yehezkel Bernat <YehezkelShB@gmail.com>,
Sukhdeep Singh <sukhdeeps@marvell.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>,
linux-usb@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] thunderbolt: add opt-in to preserve tunnels across s2idle
Date: Wed, 25 Nov 2026 12:45:36 +0000 [thread overview]
Message-ID: <31d3413a-9aa0-4208-8e15-3ba85829ef79@gmail.com> (raw)
In-Reply-To: <8fbb5876-e556-45a1-96b5-4a8061de9e5d@gmail.com>
The current implementation of tb_switch_suspend() / tb_switch_resume()
writes ROUTER_CS_5 SLP into each USB4 switch on entry to s2idle and
rebuilds the tunnel on resume, independently of whether the host router
and connected switches actually need that teardown. On AMD USB4 host
controllers (verified on Ryzen AI 9 HX 370; same expected on Phoenix /
Strix generation hardware), the switch config survives D3hot intact,
and the mandatory rebuild produces an entirely avoidable re-enumeration
cascade on wake:
* Every downstream USB device goes through USB disconnect + fresh add,
device numbers increment, open file descriptors onto those devices
are invalidated (audio streams interrupted, filesystem mounts
unmounted-and-remounted by udisks, etc.).
* PCIe hot-plug fires for the dock-side bridges.
* The dock's PD controller is reset, producing a 1 - 2 s
ADP1 ONLINE=0 blip that interferes with any userspace relying on
AC state at wake time (for instance systemd's HibernateOnACPower=
policy).
* resume_devices takes ~2 - 5 s of avoidable work.
Add a module parameter, thunderbolt.s2idle_preserve (default: off), which
skips both the tb_switch_suspend() teardown on suspend_noirq and the
tb_switch_resume() + tb_tunnel_activate() rebuild on resume_noirq, when
the sleep target is PM_SUSPEND_TO_IDLE. S3 and hibernate paths are
unaffected.
Measured on GPD Win Max 2 with CalDigit TS5 Plus dock:
Default upstream: resume_devices = 2.6 s; USB storm per wake; AC blip.
s2idle_preserve=1: resume_devices = 0.2 s; zero re-enumeration events;
AC stable; downstream connections (audio, storage,
keyboard) survive unchanged.
The opt-in gate is deliberate. Where the TB tree is not preserved by
hardware across s2idle (e.g. some Intel generations under specific
firmware configurations), enabling this would leave the kernel with
stale state at wake; users are expected to test on their own hardware
before enabling.
One known caveat: a wake event originating from a USB input device on
the host's own xHCI (not routed through the dock), while a TB dock is
connected and preserve is active, can produce a quiet resume hang on
some hardware. The resume path appears to enter but never completes;
no DPM watchdog or softlockup fires. We were unable to capture a panic
or stack for this case. Workaround for affected users: route input
devices through the dock. Likely root cause: tb_switch_set_wake() is
not called on dock-side routers when preserve skips tb_switch_suspend,
leaving the dock's routers unaware of a wake coming from elsewhere on
the system bus; a future refinement might split wake-arming from the
teardown path.
A second, more serious caveat is the reason the companion atlantic
patch exists: unplugging a Thunderbolt device during a preserved s2idle
window surfaces a pre-existing atlantic / pciehp deadlock that panics
the kernel after 120 s on DPM watchdog. See the cover letter.
Signed-off-by: Tobias Heath <heathtobias@gmail.com>
---
drivers/thunderbolt/tb.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c
index 57c11ba13..f48c365be 100644
--- a/drivers/thunderbolt/tb.c
+++ b/drivers/thunderbolt/tb.c
@@ -11,6 +11,7 @@
#include <linux/delay.h>
#include <linux/pm_runtime.h>
#include <linux/stringify.h>
+#include <linux/suspend.h>
#include "tb.h"
#include "tb_regs.h"
@@ -49,6 +50,22 @@ MODULE_PARM_DESC(asym_threshold,
"threshold (Mb/s) when to Gen 4 switch link symmetry. 0 disables. (default: "
__stringify(TB_ASYM_THRESHOLD) ")");
+/*
+ * Experimental: on s2idle entry, skip the tunnel teardown so the host router
+ * and downstream switches keep their state across Modern Standby. The TB
+ * switches stay in D3hot with their config registers intact; on wake no
+ * re-enumeration or tunnel rebuild is needed and downstream USB devices do
+ * not re-appear with new device numbers. Applies only when the sleep target
+ * is PM_SUSPEND_TO_IDLE; S3 and hibernate are never affected.
Runtime-writable.
+ * The suspend-time value is latched for the matching resume.
+ */
+static bool s2idle_preserve;
+module_param(s2idle_preserve, bool, 0644);
+MODULE_PARM_DESC(s2idle_preserve,
+ "preserve TB tunnels across s2idle (default: 0, off)");
+
+static bool s2idle_preserve_active;
+
/**
* struct tb_cm - Simple Thunderbolt connection manager
* @tunnel_list: List of active tunnels
@@ -3109,6 +3126,15 @@ static int tb_start(struct tb *tb, bool reset)
static int tb_suspend_noirq(struct tb *tb)
{
struct tb_cm *tcm = tb_priv(tb);
+ bool is_s2idle = (pm_suspend_target_state == PM_SUSPEND_TO_IDLE);
+
+ s2idle_preserve_active = is_s2idle && s2idle_preserve;
+
+ if (s2idle_preserve_active) {
+ tb_dbg(tb, "s2idle-preserve: skipping tunnel teardown on suspend\n");
+ tcm->hotplug_active = false;
+ return 0;
+ }
tb_dbg(tb, "suspending...\n");
tb_disconnect_and_release_dp(tb);
@@ -3175,8 +3201,17 @@ static int tb_resume_noirq(struct tb *tb)
struct tb_cm *tcm = tb_priv(tb);
struct tb_tunnel *tunnel, *n;
unsigned int usb3_delay = 0;
+ bool latched = s2idle_preserve_active;
LIST_HEAD(tunnels);
+ s2idle_preserve_active = false;
+
+ if (latched) {
+ tb_dbg(tb, "s2idle-preserve: skipping switch_resume and tunnel
re-activate\n");
+ tcm->hotplug_active = true;
+ return 0;
+ }
+
tb_dbg(tb, "resuming...\n");
/*
--
2.56.1
next prev parent reply other threads:[~2026-11-25 12:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 12:39 [PATCH 0/2] thunderbolt + atlantic: preserve dock across s2idle; fix surprise-removed deadlock Tobias Heath
2026-11-25 12:45 ` Tobias Heath [this message]
2026-11-25 12:48 ` [PATCH 2/2] atlantic: skip hardware teardown when PCIe parent is Tobias Heath
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=31d3413a-9aa0-4208-8e15-3ba85829ef79@gmail.com \
--to=heathtobias@gmail.com \
--cc=YehezkelShB@gmail.com \
--cc=andreas.noever@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=sukhdeeps@marvell.com \
--cc=westeri@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