From be7754062eb98a24672e0804d1bda098a4588ecc Mon Sep 17 00:00:00 2001 From: Satya Benson Date: Sun, 22 Nov 2026 14:35:16 -0500 Subject: [PATCH] thunderbolt: end the s2idle control hold before the connection manager resumes tb_domain_resume_noirq() cleared noirq_ctl_retained only after cm_ops->resume_noirq(). Until then tb_domain_event_cb() kept dropping every packet but XDomain requests, so a hotplug event or an XDomain response that arrived while the connection manager resumed was lost: a plug in that window was never acked, and a request the host had sent timed out. Clear the flag where a stopped channel would be started, before resume_noirq(). Events then reach the connection manager from the same point as on a suspend without the hold. The lock argument is unchanged: tb->lock is held from the clear until resume_noirq() returns, and the XDomain request work takes tb->lock before it re-checks the flag, so a request queued during noirq still cannot act before the domain has resumed. The packet filter in tb_xdomain_handle_request() reads the flag without tb->lock. If the clear lands between that read and the request work: - the filter saw the hold, so only a discovery request was scheduled; its work then waits for tb->lock, sees the hold ended and answers it as on any resume, the same answer it would have had during the hold; - the filter saw no hold, so the clear came first and the work sees the same. Packets the filter drops while it still sees the hold are lost as before, in a window that now ends earlier. Events and protocol packets that arrive after the clear reach the connection manager and the protocol handlers while resume_noirq() runs, exactly as when the channel was stopped and tb_ctl_start() ran before resume_noirq(). Also say in the comment on the requests answered during the hold that LINK_STATE_STATUS_REQUEST reads the downstream port's registers, under tb->lock, rather than only stored state. Signed-off-by: Satya Benson --- drivers/thunderbolt/domain.c | 14 ++++++++++---- drivers/thunderbolt/xdomain.c | 5 ++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/thunderbolt/domain.c b/drivers/thunderbolt/domain.c index e77c0eab18cc4..c870fc456598f 100644 --- a/drivers/thunderbolt/domain.c +++ b/drivers/thunderbolt/domain.c @@ -604,14 +604,20 @@ int tb_domain_resume_noirq(struct tb *tb) int ret = 0; mutex_lock(&tb->lock); - if (!tb->noirq_ctl_retained) - tb_ctl_start(tb->ctl); - if (tb->cm_ops->resume_noirq) - ret = tb->cm_ops->resume_noirq(tb); + /* + * End the hold before resume_noirq(), where a stopped channel would be + * started: hotplug events and XDomain responses then reach the + * connection manager from the same point as without the hold. Requests + * still wait for tb->lock, which is held until the resume is done. + */ if (tb->noirq_ctl_retained) { WRITE_ONCE(tb->noirq_ctl_retained, false); tb_dbg(tb, "XDomain control channel remained active\n"); + } else { + tb_ctl_start(tb->ctl); } + if (tb->cm_ops->resume_noirq) + ret = tb->cm_ops->resume_noirq(tb); mutex_unlock(&tb->lock); return ret; diff --git a/drivers/thunderbolt/xdomain.c b/drivers/thunderbolt/xdomain.c index d174e7129191c..4d297d54626d3 100644 --- a/drivers/thunderbolt/xdomain.c +++ b/drivers/thunderbolt/xdomain.c @@ -761,7 +761,10 @@ static void stop_handshake(struct tb_xdomain *xd) /* * The XDomain discovery requests answered while the control channel is kept - * through s2idle (tb->noirq_ctl_retained): they only read state. + * through s2idle (tb->noirq_ctl_retained). They change no state: UUID and + * properties are answered from memory, and LINK_STATE_STATUS_REQUEST reads + * the downstream port's registers, under tb->lock, from a host router that + * stays powered (QUIRK_NO_SYSTEM_SLEEP). */ static bool tb_xdp_noirq_request(enum tb_xdp_type type) {