Skip to content

thunderbolt: apple: refill the link-lost restart budget after a rebuilt domain - #3109

Merged
RyanTheTide merged 1 commit into
mainfrom
m2mini-usbc-full/tb-restart-budget
Nov 25, 2026
Merged

RyanTheTide merged 1 commit into
mainfrom
m2mini-usbc-full/tb-restart-budget

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What

thunderbolt_apple restarts a port, at most three times, when a USB4 peer drops the link with the cable attached. The budget is supposed to refill once a peer has been found again, but after a restart it never does. The restart rebuilds the NHI domain, whose remote activity count starts again at zero, while the saved value belongs to the old domain. This change resets the saved value to 0 when the domain is created (apple_nhi_probe(), before tb_domain_add()). It adds no gates or parameters, and the code is the same on every Mac with ACIO.

Tested: J473 M2 mini at 46ca1b6: 5/5 peer reboots restart at (1/3) and the host is back 5/5, 2/2 s2idle with an in-sleep peer reboot, 0 Oops/WARN; stock fleet89 control fails ((1/3), (2/3), (3/3), then "leaving the port alone" x3).

Risk: two-way · every Mac with ACIO (one store in the NHI probe; restarts stay bounded for a peer that never answers).

Not yet: a peer that needs the host-side restart (a dock); there is no dock in the lab.

Problem (detail)

When a USB4 peer drops the link with the cable still attached, thunderbolt_apple restarts the port, at most three times. The budget is supposed to refill once a peer has been found again. It never does after a restart. The restart rebuilds the NHI and its domain, and the new domain counts remote activity from zero again. The value saved at the restart still belongs to the old domain, so the "a peer was found since" check misses whenever the new count ends on the same number.

On the J473 (M2 mini) the lines read (1/3), (2/3), (3/3) and then "leaving the port alone" for every later drop, although the host was found again after each one. This shows up when the peer is a Mac being rebooted, as happened during a fleet rollout on the J616s at the other end of the cable. With a Mac peer the link still came back, because the peer's own boot brings it up. A peer that needs the host-side restart would stay down until the cable is replugged.

Change

apple_nhi_probe() resets the saved count to 0, the new domain's starting value, before tb_domain_add(). Any discovery on the new domain then counts as a restart that worked. A peer that shows up on the new domain but completes no discovery still uses up the budget. (The commit message words this as "a restart that finds nothing"; a restart that finds no peer at all never reports a link loss, so the port just stays down.) There are no gates or parameters. This is the same code on every Mac with ACIO.

Testing

J473, saved fleet89 (default cmdline), USB4 host-to-host to the J616s, which ran plain systemctl reboots:

  • Stock fleet89, 6 peer reboots: (1/3), (2/3), (3/3), then "leaving the port alone" three times. The host came back every time.
  • fleet89 with this commit (module one-shot, loaded build-id checked), 5 peer reboots: (1/3) on every cycle and the host back 5/5.
  • 2 s2idle cycles, each with the peer rebooting during the sleep: both resumed and the host came back.
  • 0 Oops/WARN in both arms.

Evidence: traces/usb/20261125-j473-tb-restart-budget (lab store).

Still to run

  • A peer that actually needs the host-side restart (a dock). There is no dock in the lab.
Details
  • Base: 645f7cd (the fleet89 source, an ancestor of main). The tested module was built from this exact commit against the fleet89 config (M=drivers/thunderbolt).
  • In the patched run, cycle 1 restarted twice. Both lines read (1/3) because the first restart's domain had seen the peer before the link dropped again. This is the existing "a peer was found" rule, now applied to the right domain. Restarts stay bounded for a peer that never answers.
  • Flap context: the 4 bursts of Gen2/3 link error, tps6598x: failed to configure Type-C connection: -67 and host disconnected seen on the J473 this morning line up to the second with J616s shutdowns. They are not a link-training regression.
  • checkpatch --strict: 0 errors, 0 warnings, 0 checks.

…lt domain

When the peer drops the link with the cable still attached, the port is
restarted up to three times. The count is reset once a peer has been
found since the last restart, by comparing the domain's remote activity
count with the value saved at that restart.

A restart rebuilds the NHI and its domain, and the new domain counts
remote activity from zero again. The saved value still belongs to the
domain that went away, so whenever the new domain's discoveries end on
the same number the reset is missed. On a J473 whose USB4 peer rebooted
four times in six minutes the lines read (1/3), (1/3), (2/3), (3/3)
although the host was found again after each one; the next peer reboot
would have left the port down until the cable is replugged.

Reset the saved value when the domain is created, to the new domain's
starting count. Any discovery on the new domain then counts as a
restart that worked, and a restart that finds nothing still uses up the
budget.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide
RyanTheTide requested review from a team as code owners November 25, 2026 01:24
@github-actions github-actions Bot added area:usb Area from CODEOWNERS (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 25, 2026
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Merge readiness at 46ca1b6a: not ready yet

Check Detail
CI at head no failing: pr-text / pr-text
Review no approved by satchlj, but GitHub does not count it yet (code owner from Core or Omarchy Mac needed, or approval went stale)
Requested changes ok none
Hardware row at head ok in the PR body at 46ca1b6a
Conflicts ok none
PR text ok Risk: two-way · every Mac with ACIO (one store in the NHI probe; restarts stay bounded for a peer that never answers).

Areas: area:usb

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@github-actions github-actions Bot added blast:all Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) and removed needs-hw-row No hardware row at the PR head (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 25, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Independent code review (non-author pass, code only) at 46ca1b6: no blocking finding.

Checked
  • The domain is rebuilt on a link-lost restart: apple_cio_stop() then apple_cio_start() re-probes the NHI, and tb_domain_alloc() zero-allocates the domain, so remote_activity starts at 0. If CD321x does not cycle the port, probe doesn't run and behaviour is unchanged. A sysfs rebind also builds a new domain, so 0 is right there too.
  • Ordering: the reset runs before tb_domain_add(), and link_lost can only fire once hotplug is active inside it. After tb_domain_remove() the old domain can't call link_lost. On the restart path probe runs under the caller's acio->lock. On a rebind, nhi_pdev stays NULL until probe ends, so the work exits without writing. The reset can't clobber a newer value.
  • Rules: no chip, board or firmware gate, no parameter, no delay.
  • Nit (not changed here): a peer that answers the UUID request and then drops again keeps refilling the budget. That is the existing "a peer was found since" rule. The old code refilled almost every time anyway, because the counts of the two domains usually differed. A hard cap would need a time window, which is a separate change.
  • Nit: the commit message says "a restart that finds nothing still uses up the budget". The accurate wording is "a peer that shows up but completes no discovery". The PR description is corrected; the commit is left alone (no force push).

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Gemini 4 Neon on @satchlj's behalf

Verdict at 46ca1b6a5718

APPROVE — Clean, minimal fix ensuring acio->link_lost_cycle_activity is reset with WRITE_ONCE(..., 0) before tb_domain_add() so the Thunderbolt link-lost restart budget starts from a known state on every domain bring-up, with all latest CI checks passing.

Blockers

None.

Checked

  • Diff scope: 1 file changed (drivers/thunderbolt/apple.c, +8/-1), 1 commit (46ca1b6a5718) with Signed-off-by: Ryan Murray <[email protected]>.
  • Source audit: Checked every access to link_lost_cycle_activity in drivers/thunderbolt/apple.c (READ_ONCE at line 2599, WRITE_ONCE at line 3819, and the added WRITE_ONCE(acio->link_lost_cycle_activity, 0) at line 2801 prior to tb_domain_add()). Consistent READ_ONCE/WRITE_ONCE pairing prevents stale activity state from prematurely exhausting or skewing the restart budget across domain initialization.
  • CI checks (all latest green):
    • Host tests/host-tests: SUCCESS (2026-11-25T01:31:45Z)
    • pr-readiness/readiness / readiness: SUCCESS (2026-11-25T01:26:22Z)
    • pr-text/pr-text / pr-text: SUCCESS (2026-11-25T01:26:12Z, superseding earlier 01:24:35Z failure prior to PR text update)
  • Untested scope: Live Thunderbolt dock hotplug / link-lost stress loop on hardware was not run in this pass.
Evidence
  • Audited drivers/thunderbolt/apple.c around lines 2599, 2801, and 3819 against commit 46ca1b6a5718.
  • Verified latest Host tests/host-tests, pr-readiness, and pr-text check runs all completed with SUCCESS on 46ca1b6a5718.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Rows at 46ca1b6 (module built from this commit, fleet89 kernel, default cmdline):

  • J473 M2 mini at 46ca1b6: pass. 5/5 peer reboots restart at (1/3) and the host is back 5/5; 2/2 s2idle with the peer rebooting in the sleep; 0 Oops/WARN. The stock control on the same boot setup goes (1/3), (2/3), (3/3), then "leaving the port alone" x3.
  • J616s M4 Pro (T6040) at 46ca1b6: pass, no regression. With the J473 as the rebooting peer the host came back 4/4 and there was 0 Oops/WARN. The restart path is not taken there, because a J473 reboot reads as a cable change on the J616s.
  • Stock fleet89 on the J473 (contains M2 Mac mini USB-C on the default boot; keep USB4 links across dwc3 role swaps #3040): 3/3 s2idle with an in-sleep peer reboot, 0 Oops/WARN.

Both Macs were restored to saved fleet89 and verified.

@RyanTheTide
RyanTheTide merged commit d3be108 into main Nov 25, 2026
7 of 8 checks passed
@RyanTheTide
RyanTheTide deleted the m2mini-usbc-full/tb-restart-budget branch November 27, 2026 13:21
RyanTheTide added a commit that referenced this pull request Nov 28, 2026
The branch's 11-24 link watchdog no longer applies to main, which has its
own link-loss restart budget since #3109. Replace it with three commits on
current main: pass link-loss events seen before peer discovery to the
NHI, recheck the peer after a requested restart, and keep restarting the
port slowly while the cable stays attached.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:usb Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants