🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #22499

[PATCH 1/2] thunderbolt: add opt-in to preserve tunnels across s2idle

#22499
From: Tobias Heath
Date: Wed, 25 Nov 2026 12:45
135 lines
16557 bytes
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
Technical Details
Message-ID: <31d3413a-9aa0-4208-8e15-3ba85829ef79@gmail.com>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-371314-linux-kernel-netdev=dewy.ru
References: <8fbb5876-e556-45a1-96b5-4a8061de9e5d@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-371314-linux-kernel-netdev=dewy.ru
From: heathtobias@gmail.com (Tobias Heath)
Newsgroups: linux.kernel.netdev
Subject: [PATCH 1/2] thunderbolt: add opt-in to preserve tunnels across s2idle
Date: Wed, 25 Nov 2026 12:45:36 +0000
Organization: Usenet Network
Message-ID: <31d3413a-9aa0-4208-8e15-3ba85829ef79@gmail.com>
References: <8fbb5876-e556-45a1-96b5-4a8061de9e5d@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="206628"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:pEb+z8+rB3jDasJlIR1+yNJycWU= sha256:zKepdHfDvpE6AvaJg8ufN/fCAyOfGsOuST3kZ5Pf064=
	sha1:tqVq3ejpxJ9VgqdadQxYBkpHKFg= sha256:XbL8CUMuJXRmQEmG905q9tGDzuBaKJ8PZU+12Rhmw5o=
Content-Language: en-US
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 3B9B2125E57; Wed, 25 Nov 2026 15:46:10 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id XdL091_iPU0k;
	Wed, 25 Nov 2026 15:46:06 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-371314-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 2116E125E66; Wed, 25 Nov 2026 15:45:57 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 841F53B0D4; Wed, 25 Nov 2026 12:45:47 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail;
	t=1795610740;
	b=17gDDhhuYT/7gEBJRdm5Ek2HXLMjxJTRSqNhxlnlvPBHE64jz5V0Dph0PLPF/dtaQv9e
	 f24BwG8mR925zc07xjGaAQ4EHAJ+dhPa1LBitN9bAKyVJkdYa+yWFe8N9B4xVoIaBW+nM
	 ztp7A/MjqVfhe/xlmLb+59PfUQgb65BXVwFl2PvsibshyznMBto6pG4mZrnJecjolBifS
	 3I68VLFBYHUsV9Byj8Hh4F3yYXTMX1QNQWSSt5KG03t0NpW/4FGFhR3oxhUjxwMGZEs1X
	 5k7eQ6twzaNsfhQOTcsJ0zTD5fNs4pCnvJd9XjCZn5fGA9+AIb3U9zv9bWvQ47WTrjQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795610740;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
	 X-Gm-Gg:X-Received:Received:Message-ID:Date:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version:User-Agent:Subject:From:To:Cc:References:
	 Content-Language:In-Reply-To:Content-Type:Content-Transfer-Encoding;
	bh=qCN9DtRdE/+gcLb8xRI6LYPt6eU/gxBRp9uUHYDGFwU=;
	b=oGmf9wY9tqsBRW6kTosyjQXaxRio+9ECOWLsO3SAguCCAfp15UBzRKLA079x1+eFdYfD
	 zERlhBP0fyokkD+ytOLlGNTbDvfNFneawmoNWqOnjksNBds9ZijWuN9UgbBvHQBYiIvUU
	 DAc/0j6AIQGLYfrf1zYpTF2RPwBKQBv9Nl5MPJJPSldwaaystRtVD+ZsDuleEXLXyRERk
	 ifsQ35jtCaMdJQNIvS7ukyykHy/+OHi7OHxcvmXrCx51q14rqsRU1Jl+QWRDO+enc6RAb
	 oksHLGF48cUU/RIiWMHpjo2mW9XJz/If4kkY+HVIv+cFDFUbrQ/JokvVp7zMQqxvJUg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Vud2LTlg;
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	arc=fail smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id B42D8606A688;
	Wed, 25 Nov 2026 12:45:40 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Vud2LTlg
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.51
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795610739;
	b=lQf2rOc4a2RMXUvz4/9TDOKFmV1lJf90RHT2XeesiqrHZ8HDBpfY9hcYrB/b0YJ6ASfO
	 CvNqgIPZGGBRzoRG44kUTazACumq7AOud28DLE7RmmOTA/jNd+vE8b4zIlGYhJ+z+sCl7
	 gSPiZ4dQMClGW/hYBsnXEcGkJ+Sx0Q7Gx01STJXtFZTW+g2TfWxQOekGAXtnaDvJhUujF
	 G3s0ijGlC3yVGcsHCtpHExP9Mz5SiTEUVLfxwKP4xQ0R2Wd1oNs1pJCG0JBZY8tI+fwOc
	 zEbuVkaKZWlig1EDBXbuwoM8jL0RsuYyfvK3DK9wZQyAnf+GUwNmG+n4Yc+cPP2/b5A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795610739;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
	 Message-ID:Date:MIME-Version:User-Agent:Subject:From:To:Cc:References:
	 Content-Language:In-Reply-To:Content-Type:Content-Transfer-Encoding;
	bh=qCN9DtRdE/+gcLb8xRI6LYPt6eU/gxBRp9uUHYDGFwU=;
	b=Dp4Au7CBlFbRNFE749UpYo10No/XT23oZZjihlHHv/S2XE1KnEo8t8I3jZyiiq7n9WhL
	 druMHnw84dhj9oyKq2EsjP0gA7+MK5YfYuKT7oFzHRXCcPMWckmMdN48hW+klvCLVs1/c
	 /Wt6rYZE+/oTtg5VFx9NhmpNWTp3pQr9lK6zZyJLztlSOeoDRJ/1FCzL3zYzKnsR9aLq5
	 2gfHqtMZZSgznHLzieSDjJPvfwqnCAqCenIZcKtoLnX3Ln6Xt/hV5htRvzEAXRbr4LUhr
	 OpxrvNp655M/S/YxYez96kBgArQXxasMCJbVACNeq25KXN0fjQbyYwXbkKvZv0xLT5Q==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Vud2LTlg;
	arc=none smtp.remote-ip=209.85.128.51
X-Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83A03606A332
	for <netdev@vger.kernel.org>; Wed, 25 Nov 2026 12:45:39 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 83A03606A332
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4a9a8d6cea8so73673535e9.1
        for <netdev@vger.kernel.org>; Wed, 25 Nov 2026 04:45:39 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1795610738; x=1796215538; darn=vger.kernel.org;
        h=content-transfer-encoding:content-type:in-reply-to:content-language
         :references:cc:to:from:subject:user-agent:mime-version:date
         :message-id:from:to:cc:subject:date:message-id:reply-to:content-type;
        bh=qCN9DtRdE/+gcLb8xRI6LYPt6eU/gxBRp9uUHYDGFwU=;
        b=Vud2LTlg4bg+1/37o+Cst/0aGdxrJ6W3Tp/rVd6l2vVhvG4dFi3TP84W8UhlkRa4td
         +64nQiKhh/jBsVID2R3Ud4zwks1TJP6oDt30N+qHCzT7MVd87U31fZ4WGJNYfoMeJbPT
         Ngz+Ro6FI0edvNEiJG8sPHIy0I+c7lBshMWlM+cFNaE223Obwrrw4tCKFAzjrb65gl8H
         AGdXlyrHueMZb+UvN4yF81GbdMCB5yp2LgksHKzQRhb84YCQvkzwLfAsvJqs29CoqD8i
         zmuPB6WrWXVF7E9jyFuyNI1PXxER2zZcT4WaM33KpCL2qby8Y+Iq1UHJpjx8ZeLoVtcF
         PlQA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1795610738; x=1796215538;
        h=content-transfer-encoding:content-type:in-reply-to:content-language
         :references:cc:to:from:subject:user-agent:mime-version:date
         :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
         :message-id:reply-to:content-type;
        bh=qCN9DtRdE/+gcLb8xRI6LYPt6eU/gxBRp9uUHYDGFwU=;
        b=CJY33rSCWxLlepVq5qGZN1rPLs/XyqQcsMJeFKloG+fv49G97L/7HDAJ3ms31Vab4r
         RoQTKPlSsCfBNSUS6rP69kKhL9wlpXhlH47VUVC/DdoouuOljfAee3U/pnhi2dhXcFKA
         ke6dHIRrN7PKzATsgGh+YEB3UUoRMUklB6HJxYJJx/ZIlBqCOpX0FQo6hxDaOgG+10RS
         g6hZxk90JqrUfALw/tyeiXUOEdBfet7pq935WtuSfu807sBjFuLNw/hzpWYRclgfWk9Z
         9M/DIPqH2wHKeckq/t8qp7sV51WZcycT8utTTgmr/ZJ3KNPS8inZzq92kOFthELNfQ07
         DWSQ==
X-Forwarded-Encrypted: i=1; AL+hErEjT5SUGcViYpdHQdZYpNhYmgAnB/j1MixUnnbFnSa7sb/kW2c2zGnby3IKnWkFohKcTewFFEQ=@vger.kernel.org
X-Gm-Message-State: APuU4Z8EkvzFwr03coq8rAidAl7X6a6T9idfxcbLnediIVqeQd0md/HC
	S0aA2p8m3nuI+/PpIa7taiko69wRWnVa6+Oqho8+yzA0HXh4AB/5yuJ0
X-Gm-Gg: AZFdTZcFf/6nMEbIWIs4UKMod4IA/dEq6qry//Isd0WA6MhoWyu/PUwhbWvCjkLR6Rp
	rpCjv39aE+hKPnnDsP6z0jnq6q3d22bkd1S6uHddCddv+QJzgd1Vu4ACP/3ynbME9IwjPG0t9ER
	IBnCxkpAMenlWJAQK9vTmv02nDNjulKXwCMFk3j92ZvefHhpiq3/QFGcPFSGeyEzIxvZcB/X1QL
	x+RckH1LQgKywqfECJZaVDBWmuXkTTIWLFjAVX7yfRjdmeMb5UHHjwulTR2q4PfYlSWKfxS0KtK
	KjI6gWflZBQZfUK2Z/yD//4Q1bIK03zmBxSM3hcYtIAqLJwbvpU3K3P64MFEwwoMIhwhNKFzCET
	WSamSCwX+UhhXwBrJ94TpUgo+FMi00GrHE6ZS1W6cWxnaGIVQybkcuW8RWlcCsKKSqRUDhoh2GT
	CagJWgF19Se1GWp49X8rICT/3niiDuxuve7lU52D9WR4g+3AwNgnt+/eMJNST51zbt0pDV0680Y
	EY41t9863orhAe+3I9YH9evN6XFpbdSW4KQWvR5edFu13TdPCEnwPD24jJ608aJR+0Ycmb5r3/C
	kXXf7nzb47tpjrrYBCLUhCEyQ9bG4cFi108ZUNf3OutEHnm09u/zlkvr6PX3vhSAIbzQRcheJBy
	6QfO+2uA10q8=
X-Received: by 2002:a05:600c:8905:b0:4bb:6816:127c with SMTP id 5b1f17b1804b1-4bb861468cdmr344483245e9.8.1795610737633;
        Wed, 25 Nov 2026 04:45:37 -0800 (PST)
X-Received: from [192.168.0.36] (firewall-214-232.seh.ox.ac.uk. [163.1.214.232])
        by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab65cb4341sm34358805f8f.4.2026.11.25.04.45.36
        (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
        Wed, 25 Nov 2026 04:45:37 -0800 (PST)
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-User-Agent: Mozilla Thunderbird
X-Cc: Richard Cochran <richardcochran@gmail.com>, linux-usb@vger.kernel.org,
 netdev@vger.kernel.org, linux-kernel@vger.kernel.org
X-In-Reply-To: <8fbb5876-e556-45a1-96b5-4a8061de9e5d@gmail.com>