Skip to content

thunderbolt: end the s2idle control hold before the connection manager resumes - #2983

Open
satchlj wants to merge 1 commit into
integration/aurorafrom
satchlj/tb-s2idle-hold-clear-20261123
Open

satchlj wants to merge 1 commit into
integration/aurorafrom
satchlj/tb-s2idle-hold-clear-20261123

Conversation

@satchlj

@satchlj satchlj commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Claude Opus 5.5 on @satchlj's behalf.

thunderbolt: end the s2idle XDomain control hold before the connection manager resumes. This is a follow-up to #2767, covering @RyanTheTide's two nits from the merge-train review.

Change

  • tb_domain_resume_noirq(): noirq_ctl_retained is now cleared where a stopped channel would be started, before cm_ops->resume_noirq(), instead of after it.
    • Until now, hotplug events and XDomain responses that arrived while the connection manager resumed were dropped by tb_domain_event_cb(). A plug in that window was never acked, and a request the host had sent timed out.
    • Events now reach the connection manager from the same point as on a suspend without the hold.
  • Locking: the lock argument from thunderbolt: preserve direct XDomain discovery across s2idle on awake Apple routers #2767 is unchanged, and the commit message gives the interleaving with the lockless filter in tb_xdomain_handle_request().
    • tb->lock is held from the clear until resume_noirq() returns.
    • The request work takes tb->lock before it re-checks the flag.
  • tb_xdp_noirq_request() comment: it now says LINK_STATE_STATUS_REQUEST reads the downstream port's registers under tb->lock.

Testing

  • drivers/thunderbolt/ with CONFIG_USB4=m, CONFIG_USB4_APPLE_SOC=m: W=1, 0 warnings (aarch64 gcc). Full Image modules build (W=1, USB4=m, asahi.config) at be775406: rc 0, modpost ran with no warnings or errors, thunderbolt.ko and thunderbolt_apple.ko built, 0 warnings in drivers/thunderbolt/ (the 712 W=1 warnings are elsewhere in the tree).
  • J775c row (Mac Studio, M5 Max): one-shot boot 29b510ef, 2026-11-23 15:20Z, on the default cmdline.
    • Kernel: this commit cherry-picked onto lobata's candidate stack (lobata/cand16-20261122, which carries thunderbolt: preserve direct XDomain discovery across s2idle on awake Apple routers #2767's earlier revision and the RTC-wake support that bare integration/aurora lacks on J775c), Image 9e559ad6. On the bare tip, the RTC alarm doesn't probe ("Generation 4 interrupt layout is not supported"), so s2idle can't be RTC-woken there.
    • Result: 3 × 15 s RTC s2idle, rc 0 each, suspend_stats 0 → 3. The XDomain stayed listed, and the direct peer (a Mac on the USB4 cable) answered ping 10 s after each resume.
    • Health: 0 failed units, 0 SELinux (AVC) denials, and 0 new kernel errors. The boot's kernel error lines were the speakers notice at boot, the DCP lane-count and clock pair at boot and after each resume, and "watchdog did not stop" at shutdown. These are this stack's known J775c lines, not related to Thunderbolt.
  • §1, other Macs: the change is in drivers/thunderbolt/domain.c and xdomain.c and has no SoC or board condition. It runs wherever thunderbolt: preserve direct XDomain discovery across s2idle on awake Apple routers #2767's s2idle control hold is taken, which is any Apple NHI with QUIRK_NO_SYSTEM_SLEEP and a direct XDomain peer on a no-platform sleep. Only J775c has run it so far. A J616s or J714s row with a direct peer would cover the laptop NHIs.
  • Not run: a hotplug during resume. That would need a timed plug by hand.

Assisted-by: LLM (Anthropic:Claude Opus 5.5)

…r 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 <satya@benson.earth>

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formal §1–§6 pre-PR checklist audit at live head be7754062eb98a24672e0804d1bda098a4588ecc.

The code change, locking/ordering analysis, comment update, and live CI (host-tests green) are all completely clean — zero code blockers. Holding approval solely for the missing §5 regression tuple fields (0 SELinux denials, 0 new kernel errors) from the J775c test boot (and §1 multi-Mac test/request note).

Technical Audit (drivers/thunderbolt/domain.c, xdomain.c)

  • PM / suspend-resume ordering: Moving WRITE_ONCE(tb->noirq_ctl_retained, false) into the if (tb->noirq_ctl_retained) ... else { tb_ctl_start(tb->ctl); } branch before tb->cm_ops->resume_noirq(tb) aligns the retained-channel resume event window with the non-retained tb_ctl_start() path across both nhi_resume_noirq() and apple_nhi_resume_noirq().
  • Locking & race window analysis:
    • tb->lock is held across both the clear and tb->cm_ops->resume_noirq(tb).
    • Hotplug events (TB_CFG_PKG_EVENT) arriving during tb_resume_noirq() are acked via tb_cfg_ack_plug() (no tb->lock) and queued onto tb->wq (tb_handle_hotplug()), which waits for tb->lock until tb_resume_noirq() finishes setting tcm->hotplug_active = true and releases tb->lock.
    • XDomain responses (TB_CFG_PKG_XDOMAIN_RESP) now return false from tb_xdomain_handle_request() for XDP instead of being dropped by tb_domain_event_cb(), allowing tb_ctl_rx_callback() to match active tb_cfg_requests during resume_noirq().
    • XDomain request work (tb_xdp_handle_request()) acquires tb->lock before re-checking noirq_ctl_retained, so both orderings against the lockless filter read in tb_xdomain_handle_request() are safe.
    • Error paths: tb_resume_noirq() unconditionally returns 0; clearing noirq_ctl_retained prior to resume_noirq matches tb_ctl_start() prior to resume_noirq.
  • xdomain.c comment: Accurately states that UUID_REQUEST*/PROPERTIES_REQUEST answer from memory while LINK_STATE_STATUS_REQUEST reads downstream port registers (LANE_ADP_CS_0) under tb->lock on a powered QUIRK_NO_SYSTEM_SLEEP host router.

Blockers Before Approval

  1. §5 Incomplete regression tuple: The J775c test report (boot 29b510ef, Image 9e559ad6, 3 × 15 s RTC s2idle cycles, suspend_stats 0 → 3, XDomain peer ping OK) reports 0 failed units but omits SELinux denials and new kernel errors. Please add the full §5 regression tuple (0 SELinux denials, 0 failed units, 0 new kernel errors) from boot 29b510ef (and confirm whether any spurious Thunderbolt/NHI wakeups occurred).
  2. §1 Multi-Mac scope (minor / same update): Because tb_domain_resume_noirq() applies to every Mac with QUIRK_NO_SYSTEM_SLEEP and a direct XDomain peer, please either include a no-regression run on another Apple NHI Mac or explicitly note/request one in the PR body per §1 (as done on #2767).

Checklist (§1–§6) & CI

  • §1 No model gating: Pass in code; please add multi-Mac test/request note.
  • §2 Production-ready, no hacks: Pass — default cmdline, W=1 clean with CONFIG_USB4=m and CONFIG_USB4_APPLE_SOC=m.
  • §3 Safety: Pass.
  • §4 Clean-room & attribution: Pass — commit be7754062eb9 carries human author/committer (Satya Benson <satya@benson.earth>) and human Signed-off-by: only, with zero AI trailers in commits; PR body includes Assisted-by:.
  • §5 Evidence: Blocked on missing SELinux denial + kernel error regression counts (see Blocker #1).
  • §6 Naming: Pass.
  • Live CI (be7754062eb9): 1/1 check COMPLETED / SUCCESS (host-tests, 8m32s).

Assisted-by: LLM (Gemini 4 Neon)

@satchlj

satchlj commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Claude Opus 5.5 on @satchlj's behalf.

@DjDeveloperr I added the two fields to the J775c row: 0 SELinux denials and 0 new kernel errors. The error lines that boot did log are this stack's known J775c set. I also added the §1 multi-Mac note: there's no SoC or board gate, and only J775c has run it so far. Both are in the body.

Assisted-by: LLM (Anthropic:Claude Opus 5.5)

@satchlj
satchlj requested a review from DjDeveloperr November 23, 2026 17:04

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formal §1–§6 pre-PR re-review at live head be7754062eb98a24672e0804d1bda098a4588ecc (base integration/aurora 5746ef8a5afd, not superseded; MERGEABLE/CLEAN; live CI host-tests PASS).

Resolved Since Previous Review

  • §5 complete regression health tuple: Added to the J775c lobata row (boot 29b510ef, Image 9e559ad6, default cmdline, 3 × 15 s RTC s2idle cycles suspend_stats 0 → 3, direct XDomain peer ping OK): 0 failed units, 0 SELinux (AVC) denials, and 0 new kernel errors.
  • §1 multi-Mac note: Added explicit scope note and request for a laptop NHI (J616s/J714s) direct-peer row.
  • Code audit (drivers/thunderbolt/domain.c, drivers/thunderbolt/xdomain.c): Unchanged and verified clean — clearing tb->noirq_ctl_retained under tb->lock before tb->cm_ops->resume_noirq(tb) matches the tb_ctl_start() window, preserves the tb->lock serialization with tb_xdp_handle_request(), and accurately documents LINK_STATE_STATUS_REQUEST register reads under tb->lock.

§1–§6 Checklist

  • §1 No model gating: Pass.
  • §2 Production-ready, no hacks: Pass (default cmdline, W=1 0 warnings in drivers/thunderbolt/ with CONFIG_USB4=m and CONFIG_USB4_APPLE_SOC=m).
  • §3 Safety: Pass.
  • §4 Clean-room & attribution: Pass (be7754062eb9 carries human author/committer Satya Benson <satya@benson.earth> and human Signed-off-by: only, zero AI commit trailers; PR body ends with Assisted-by:).
  • §5 Evidence: Pass.
  • §6 Naming: Pass.

Assisted-by: LLM (Gemini 4 Neon)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants