From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: linux-usb@vger.kernel.org
Cc: Yehezkel Bernat <YehezkelShB@gmail.com>,
Lukas Wunner <lukas@wunner.de>,
Andreas Noever <andreas.noever@gmail.com>,
Gil Fine <gil.fine@linux.intel.com>,
Rene Sapiens <rene.sapiens@linux.intel.com>,
Pooja Katiyar <pooja.katiyar@intel.com>,
Mika Westerberg <mika.westerberg@linux.intel.com>
Subject: [PATCH 02/18] thunderbolt: Tear down DMA tunnels on every XDomain removal
Date: Thu, 19 Nov 2026 18:12:16 +0100 [thread overview]
Message-ID: <20261119171232.1616316-3-mika.westerberg@linux.intel.com> (raw)
In-Reply-To: <20261119171232.1616316-1-mika.westerberg@linux.intel.com>
From: "Mika Westerberg (Intel)" <westeri@kernel.org>
Currently we only tear down DMA tunnels when the XDomain is unplugged
(and when service drivers explicitly do that) but not when the XDomain
is removed as part of resume or replaced by a router in tb_scan_port().
The tunnel then stays in the tunnel list until the driver is unloaded
(or the router it goes through is removed).
Fix this by always tearing down the tunnels when XDomain is removed.
Fixes: 7ea4cd6b2010 ("thunderbolt: Add support for XDomain connections")
Signed-off-by: Mika Westerberg (Intel) <westeri@kernel.org>
---
drivers/thunderbolt/tb.c | 47 ++++++++++++++++++++--------------------
1 file changed, 24 insertions(+), 23 deletions(-)
diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c
index 655bcc699410..680ed23db0bf 100644
--- a/drivers/thunderbolt/tb.c
+++ b/drivers/thunderbolt/tb.c
@@ -83,6 +83,9 @@ struct tb_hotplug_event {
int retry;
};
+static void __tb_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
+ int transmit_path, int transmit_ring,
+ int receive_path, int receive_ring);
static void tb_scan_port(struct tb_port *port);
static void tb_handle_hotplug(struct work_struct *work);
static void tb_dp_resource_unavailable(struct tb *tb, struct tb_port *port,
@@ -456,6 +459,23 @@ static void tb_scan_xdomain(struct tb_port *port)
}
}
+static void tb_remove_xdomain(struct tb_port *port)
+{
+ struct tb_xdomain *xd = tb_xdomain_get(port->xdomain);
+ struct tb *tb = xd->tb;
+
+ /*
+ * Paths are torn down here so make tb_xdomain_disable_paths()
+ * from the service drivers no-op.
+ */
+ xd->is_unplugged = true;
+ tb_xdomain_remove(port->xdomain);
+ port->xdomain = NULL;
+ __tb_disconnect_xdomain_paths(tb, xd, -1, -1, -1, -1);
+ tb_port_unconfigure_xdomain(port);
+ tb_xdomain_put(xd);
+}
+
/*
* Returns the first inactive port on @sw.
*/
@@ -1352,11 +1372,8 @@ static void tb_scan_port(struct tb_port *port)
* If there was previously another domain connected remove it
* first.
*/
- if (port->xdomain) {
- tb_xdomain_remove(port->xdomain);
- tb_port_unconfigure_xdomain(port);
- port->xdomain = NULL;
- }
+ if (port->xdomain)
+ tb_remove_xdomain(port);
/*
* Do not send uevents until we have discovered all existing
@@ -2491,22 +2508,8 @@ static void tb_handle_hotplug(struct work_struct *work)
tb_recalc_estimated_bandwidth(tb);
tb_tunnel_dp(tb);
} else if (port->xdomain) {
- struct tb_xdomain *xd = tb_xdomain_get(port->xdomain);
-
tb_port_dbg(port, "xdomain unplugged\n");
- /*
- * Service drivers are unbound during
- * tb_xdomain_remove() so setting XDomain as
- * unplugged here prevents deadlock if they call
- * tb_xdomain_disable_paths(). We will tear down
- * all the tunnels below.
- */
- xd->is_unplugged = true;
- tb_xdomain_remove(xd);
- port->xdomain = NULL;
- __tb_disconnect_xdomain_paths(tb, xd, -1, -1, -1, -1);
- tb_xdomain_put(xd);
- tb_port_unconfigure_xdomain(port);
+ tb_remove_xdomain(port);
} else if (tb_port_is_dpout(port) || tb_port_is_dpin(port)) {
tb_dp_resource_unavailable(tb, port, "adapter unplug");
} else if (!port->port) {
@@ -3167,9 +3170,7 @@ static void tb_free_unplugged_xdomains(struct tb_switch *sw)
continue;
if (port->xdomain && port->xdomain->is_unplugged) {
tb_retimer_remove_all(port);
- tb_xdomain_remove(port->xdomain);
- tb_port_unconfigure_xdomain(port);
- port->xdomain = NULL;
+ tb_remove_xdomain(port);
} else if (port->remote) {
tb_free_unplugged_xdomains(port->remote->sw);
}
--
2.50.1
next prev parent reply other threads:[~2026-11-19 17:19 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 17:12 [PATCH 00/18] thunderbolt: Add support for shared buffering Mika Westerberg
2026-11-19 17:12 ` [PATCH 01/18] thunderbolt: Avoid leaking of DMA tunnel after XDomain removal Mika Westerberg
2026-11-19 17:12 ` Mika Westerberg [this message]
2026-11-19 17:12 ` [PATCH 03/18] thunderbolt: Delay re-pairing DP IN/OUT if DPRX negotiation fails Mika Westerberg
2026-11-19 17:12 ` [PATCH 04/18] thunderbolt: Call DP tunnel activation callback with tb->lock held Mika Westerberg
2026-11-19 17:12 ` [PATCH 05/18] thunderbolt: Re-apply Alpine/Titan Ridge flow on resume Mika Westerberg
2026-11-19 17:12 ` [PATCH 06/18] thunderbolt: Return -ESHUTDOWN when control channel is not running Mika Westerberg
2026-11-19 17:12 ` [PATCH 07/18] thunderbolt: Add usb4_port_hotplug_disable() Mika Westerberg
2026-11-19 17:12 ` [PATCH 08/18] thunderbolt: Move tb_plug_events_active() before tb_switch_reset_host() Mika Westerberg
2026-11-19 17:12 ` [PATCH 09/18] thunderbolt: Add tb_port_state_is_up() Mika Westerberg
2026-11-19 17:12 ` [PATCH 10/18] thunderbolt: Split host router port reset into a separate function Mika Westerberg
2026-11-19 17:12 ` [PATCH 11/18] thunderbolt: Reset topology after suspend-to-disk Mika Westerberg
2026-11-19 17:12 ` [PATCH 12/18] thunderbolt: Drop tunnel discovery without HopID allocation Mika Westerberg
2026-11-19 17:12 ` [PATCH 13/18] thunderbolt: Always take domain lock when tb_tunnel_put() is called Mika Westerberg
2026-11-19 17:12 ` [PATCH 14/18] thunderbolt: Assign domain to the routers in KUnit tests Mika Westerberg
2026-11-19 17:12 ` [PATCH 15/18] thunderbolt: Rework tunnel credit allocation Mika Westerberg
2026-11-19 17:12 ` [PATCH 16/18] thunderbolt: Add support for shared flow control Mika Westerberg
2026-11-19 17:12 ` [PATCH 17/18] thunderbolt: Use restricted shared flow control for DMA tunnels on intra-domain links Mika Westerberg
2026-11-19 17:12 ` [PATCH 18/18] thunderbolt: Add KUnit tests for shared buffering Mika Westerberg
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=20261119171232.1616316-3-mika.westerberg@linux.intel.com \
--to=mika.westerberg@linux.intel.com \
--cc=YehezkelShB@gmail.com \
--cc=andreas.noever@gmail.com \
--cc=gil.fine@linux.intel.com \
--cc=linux-usb@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=pooja.katiyar@intel.com \
--cc=rene.sapiens@linux.intel.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