Skip to content

thunderbolt: apple: let T6020 DP IN tunnels wait for a display pipeline - #2636

Closed
RyanTheTide wants to merge 1 commit into
integration/aurorafrom
rescue/pr426-t6020-dp-in-retry-rebase-20261121
Closed

RyanTheTide wants to merge 1 commit into
integration/aurorafrom
rescue/pr426-t6020-dp-in-retry-rebase-20261121

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

Replaces #1692, rebased onto current integration/aurora (conflicts in drivers/thunderbolt/apple.c: the base now pauses DP IN retries in apple_nhi_prepare() on every sleep and gates the resume in apple_nhi_complete() on pm_dark_wake() after apple_nhi_cio_complete(); prepare keeps the base code, which now also pauses M2 through apple_dpin_pm_gated(), and complete keeps the PR's early resume before tb_domain_complete() for policies without defer_new_bringup, after apple_nhi_cio_complete() and skipped on a dark wake like the base's).

Let T6020/T6021 (M2 Pro/Max) DP IN tunnels wait for a free display pipeline, so a Thunderbolt display comes back after resume. Rebased onto integration/aurora at 78ea426.

This is nekolyanich's change from #426, as ported in review/pr426-integration-t3094-v3 (bb91b3f). Authorship and sign-off are unchanged; the port applies to current integration without conflicts.

Problem

apple_dpin_m2 leaves capacity_retry off, so a DP IN tunnel that finds no free pipeline gets -EBUSY once and that is final (dpin0: DP tunnel setup failed: -16). The connection manager keeps the tunnel through the DPRX timeout, but nothing asks again and the display stays dark. On a MacBook Pro 16" M2 Pro (j416s) with a monitor on Thunderbolt and a TV on a USB-C to HDMI adapter, the TV takes dcpext0 first after resume and the tunnel is refused; the fabric frees a pipeline a few seconds later, too late.

Change

  • capacity_retry = true on apple_dpin_m2: a refused tunnel waits and retries as on M1. -EAGAIN waits too. TB_HOST_DP_KEEP_DPRX_TIMEOUT already keeps M2 tunnels, so there is no dp_tunnel_awaits_display hook.
  • The PM gate (pause/resume of retries, end of the gate at NHI removal) covers capacity_retry policies too. M2 pauses at prepare also at the default resume_recovery=0 and resumes when complete starts, so a tunnel refused inside complete retries in time. M1 and M3 at the default are unchanged.
  • apple_dpin_end_pm_gate() pauses both adapters before draining, so work in flight cannot rearm the retry it just cancelled.
  • KUnit: the M2 row of apple_dpin_all_policy_fields, the t602x rearm trace, the capacity trace for M2, terminal errors ending an M2 wait, and apple_dpin_m2_capacity_suspend.

Base M2 (T8112) uses apple_dpin_m1 and is unchanged.

Testing

On this branch:

  • Rebased onto integration/aurora c3d01cb (2026-11-21): KUnit (kunit.py, arm64 qemu, LLVM=1) apple-dpin-lifecycle 37/37 including apple_dpin_m2_capacity_suspend, 108 of 109 overall (same CONFIG_UCLAMP_TASK skip); drivers/thunderbolt/ builds with W=1 (defconfig + asahi.config, arm64), no warnings; checkpatch.pl --strict: no code findings; run-host-tests.py --only cio-native 1/1, pciec-policy 1/1, tb-dock-pm 1/1, tb-cio-sleep 1/1, tb-dp-repair 2/2.
  • KUnit (kunit.py, arm64 qemu): apple-dpin-lifecycle 37/37 including apple_dpin_m2_capacity_suspend, thunderbolt suite passing; 108 of 109 overall, the one skip is an unrelated G17 mailbox case that needs CONFIG_UCLAMP_TASK.
  • checkpatch.pl --strict: clean.

Hardware, by nekolyanich on J416s (M2 Pro) with this port (bb91b3f) under the m1n1 hypervisor, monitor on TB plus TV on an adapter:

  • Capacity retry: the monitor came back after 5/5 resumes over 3 boots, routed 6.3–6.6 s after the refusal and 3.4–3.7 s before the DPRX deadline; 0 DPRX timeouts. Without the change it came back after 0 of 2.
  • Suspend with no sink: 3/3. Unplug: 11/11 replugs came back, 0 -95, 0 DPRX timeouts.
  • NHI removal with the monitor: clean unbind (tunnel down, crossbar released, no retry left waiting). The ACIO firmware crash on the following bind happens on the base without this change too.

Still to run: a native (non-hypervisor) J414s/J416s row, and a no-regression boot and resume on base M2 (T8112) and M1.

Thanks to nekolyanich for finding, fixing and testing this.

Assisted-by: LLM (Claude:Opus 5.5)

apple_dpin_m2, the T6020/T6021 (M2 Pro/Max) ACIO policy, leaves
capacity_retry off "pending M2 hardware qualification". A DP IN tunnel
that finds no free display pipeline gets -EBUSY once and that is final
("dpin0: DP tunnel setup failed: -16"). The connection manager keeps
the tunnel through the DPRX timeout (TB_HOST_DP_KEEP_DPRX_TIMEOUT), but
nothing asks for a pipeline again, so the display stays dark.

On a MacBook Pro 16" M2 Pro (j416s) with a monitor on a Thunderbolt
cable and a TV on a USB-C to HDMI adapter (DP Alt Mode), the fabric
moves the TV to dcpext1 at boot and gives the tunnel dcpext0. After a
system resume the TV comes back first on dcpext0 and the tunnel's
request is refused. The fabric moves the TV to the other pipeline
a few seconds later, too late for a request that is not retried.

Set capacity_retry on apple_dpin_m2. A refused tunnel then waits as on
M1: the DP IN work arms its retry and routes the tunnel once a pipeline
comes free. M2 needs no dp_tunnel_awaits_display hook, which is set up
for the APPLE_DPIN_CHANGED flow only: KEEP_DPRX_TIMEOUT already keeps
its tunnels. As on M1, -EAGAIN waits too: an attempt that prepare cut
short returns it and has to ask again after complete. A DCP service
that is never published then waits until unplug, with a 120 s readiness
wait per retry, where it used to fail once.

Pause these retries across system sleep and at NHI removal. The PM gate
(apple_dpin_pause_retries(), apple_dpin_resume_retries(),
apple_dpin_end_pm_gate()) now applies wherever the policy has
capacity_retry or defer_new_bringup, not defer_new_bringup only.
apple_nhi_prepare() pauses the retries of a gated policy without
defer_new_bringup (M2) before its resume_recovery=0 return, so at the
default a waiting M2 tunnel stops asking at prepare; with
resume_recovery set it pauses where M1 does. Either way its pause ends
when complete starts, before tb_domain_complete(): every device has
resumed by then, and the tunnel that the domain's complete brings back
makes its first attempt there, since M2 does not defer it. Its retries
then run from the refusal on, as before, and do not wait for the end of
complete, which can take seconds. M1 and M3 at the default are
unchanged: their pause stays behind resume_recovery (6ceb98a).
Without the gate a waiting M2 tunnel would keep calling into appledrm on
the non-freezable dp_wq while the DCPs power off, and after the NHI is
removed. M2 does not get defer_new_bringup: that would defer every first
M2 handoff across sleep, which has not been tested, and DPRX retention
for a deferred handoff goes through the hook M2 does not install.

apple_dpin_end_pm_gate() now pauses both adapters before it drains
them, as apple_dpin_pause_retries() does: work in flight at NHI removal
could otherwise get -EBUSY and rearm the retry it had just cancelled.
On M1 this is the only change: a bring-up in flight at NHI removal is
deferred and then dropped instead of attaching. Base M2 (T8112) uses
apple_dpin_m1, and M3 is unchanged.

Update the comments above apple_dpin_work_fn() and
apple_dpin_pause_retries(), which named M1-family hosts. Tests: the M2
row of apple_dpin_all_policy_fields; the t602x rearm trace, whose -EBUSY
now waits and recovers; the capacity trace run for M2 as well; terminal
errors end an M2 wait; apple_dpin_m2_capacity_suspend (pause, resume, a
refusal after the pause has ended, resume with no pause, -EAGAIN under
pause, unplug while waiting, end of the gate).

In omacom/linux-aurora, commit 068fd09 ("thunderbolt: apple: let
T6030 DP IN tunnels wait for a display pipeline") restores the same
flag for M3 after the #139 merge dropped it; M2 never had it.

Testing: j416s, DCP firmware 13.5, under the m1n1 hypervisor,
pm_test=platform, with a bench-only DT change that keeps the
hypervisor's USB-C port out of the DCP routes. Monitor and TV: the
monitor came back after 6 of 6 resumes with this change (0 of 2 without,
on aurora 7.3 ac6b017, same thunderbolt and appledrm code), routed
6.2-6.5 s after the refusal and 3.4-3.8 s ahead of the DPRX timeout; no
DPRX timeout, no kernel WARNINGs. Monitor alone: back after 4 of 4
resumes, no wait. KUnit apple-dpin-lifecycle 35 of 35.
Not tested: natively, a suspend while a tunnel waits (KUnit only),
j414s, j414c, j416c, other firmware, a wait past the DPRX timeout, NHI
removal while waiting.

Assisted-by: Claude:claude-opus-5-5 checkpatch
Signed-off-by: nekolyanich <me@nekolyanich.com>
Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Looks good; approve once the native J414s/J416s resume row is in.

I checked the PM gate ordering in drivers/thunderbolt/apple.c:

  • apple_nhi_prepare() pauses every gated policy before apple_nhi_cio_prepare(), and resumes it on failure.
  • apple_nhi_complete() (3078-3086) resumes M2 (no defer_new_bringup) before tb_domain_complete(). It still resumes M1/M3 after it, and skips both on a dark wake.
  • apple_dpin_end_pm_gate() (2822-2846) now pauses both adapters under their locks before it cancels and flushes, so a work item in flight cannot rearm the retry it just lost.
  • apple_dpin_pm_gated() is the only predicate for all three entry points.

The KUnit traces cover pause/resume, -EAGAIN under pause, unplug while waiting and the end of the gate.

  1. Commit be80190 carries Assisted-by: Claude:claude-opus-5-5 checkpatch and Assisted-by: LLM trailers.

HW row: J416s or J414s booted natively (no hypervisor, no bench DT change) on the default command line, this kernel, monitor on Thunderbolt plus TV on a USB-C/HDMI adapter. 10 real s2idle resumes: the monitor comes back every time, 0 DPRX timeouts, 0 new kernel errors, 0 failed units. Also one resume row each on M1 Pro (J316s) and base M2 (J413) showing no change.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Merge-train adversarial review (MERGETRAIN-LINUX2) at be80190: BLOCKERS.

Not merging until the blockers below are fixed or answered; the details give file:line and a failure case.

Full review

#2636 thunderbolt: apple: let T6020 DP IN tunnels wait for a display pipeline @be801904

VERDICT: BLOCKERS

Blockers

  1. Commit hygiene: be80190 carries Assisted-by: Claude:claude-opus-5-5 checkpatch and Assisted-by: LLM trailers. Binding rule 4 forbids agent trailers in commits. Reword the message, keeping the author's and Ryan's Signed-off-by.

Nits

  • The commit message says apple_nhi_prepare() pauses M2 "before its resume_recovery=0 return", but neither the code nor the diff has such a return. apple.c:2945-2946 pauses unconditionally ("required on every sleep"). The message describes code that does not exist. Fix the message.
  • apple.c:3086-3090 makes the place where complete() resumes retries depend on defer_new_bringup. That is correct for today's policies, but a future policy with capacity_retry=0 and defer_new_bringup=1 is handled implicitly. A one-line comment that apple_dpin_pm_gated() covers both cases would make that explicit.
  • apple.c:2831-2837 (end_pm_gate now pauses first) changes behaviour on every gated policy: M1, M3, M4, T6050. A bring-up in flight at NHI removal is now deferred and dropped instead of attaching. That looks right, but nothing on hardware covers it.
  • A DCP service that is never published now leaves an M2 Pro/Max dp_wq worker waiting, APPLE_DP_CONNECT_WAIT_MS per try, until unplug (apple.c:1013-1058). It used to fail once. The PR acknowledges this; it is a behaviour change on a non-freezable workqueue.

Missing rows

  • The only hardware evidence is a J416s under the m1n1 hypervisor with pm_test=platform and a bench-only DT change. Nothing ran natively on the default cmdline. Needed: native J414s/J416s (T6020) with a TB monitor plus a USB-C/HDMI TV, 10 real s2idle resumes, monitor back every time, 0 DPRX timeouts. Also J414c/J416c (T6021). The lab has no T6020/T6021, so this needs an owner.
  • The end_pm_gate change runs on M1 (J313/J316s), M3 (J615) and M4 (J713/J616s) and has no rows on any of them: one TB-display resume row plus an NHI unbind/rebind with a tunnel up. M2 (T8112) uses apple_dpin_m1 and is unchanged except for end_pm_gate.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Correction to my merge-train review above: the commit trailer is not a merge blocker. Our rule for already-pushed commits is to leave history alone (no force push), so the code verdict stands as NO BLOCKERS. The missing rows listed there still apply, and Dj's verdict is still needed. For new commits, please keep agent trailers out.

@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.

Pre-PR checklist review (§1–§6) at be80190452f4ab420c2e57648ac46cfe6db3242e: code changes look sound, but requesting changes for a §4 commit-attribution violation and an inaccurate commit message / PR body, plus missing native §5 hardware rows.

Blockers

  1. §4 Attribution (hard rule): Commit be80190452f4ab420c2e57648ac46cfe6db3242e carries prohibited AI trailers inside the commit message:
    • Assisted-by: Claude:claude-opus-5-5 checkpatch
    • Assisted-by: LLM
      Per §4 of the pre-PR checklist, commits must carry human author/committer and human Signed-off-by: only (zero Co-Authored-By: or Assisted-by: trailers in commits). Because rescue/pr426-t6020-dp-in-retry-rebase-20261121 is an unmerged PR branch freshly rebased onto integration/aurora, please strip both Assisted-by: lines from the commit message while preserving Author: nekolyanich <me@nekolyanich.com> and both human Signed-off-by: lines. (The Assisted-by: line at the end of the PR body already handles disclosure.)
  2. Inaccurate commit message and PR body: Both state that apple_nhi_prepare() pauses M2 "before its resume_recovery=0 return" and that "M1 and M3 at the default are unchanged: their pause stays behind resume_recovery (6ceb98a238d8)." On current integration/aurora, drivers/thunderbolt/apple.c:2945-2946 has no resume_recovery=0 early return — apple_dpin_pause_retries(acio) already runs unconditionally on every sleep for all gated policies, and this diff does not modify apple_nhi_prepare(). Please update the commit message and PR body to match the rebased diff (and replace m1n1 hypervisor wording if rewording under §6).

Verified (code)

  • apple_dpin_m2.capacity_retry = true and apple_dpin_pm_gated() (p->capacity_retry || p->defer_new_bringup) cleanly cover apple_dpin_pause_retries(), apple_dpin_resume_retries(), and apple_dpin_end_pm_gate().
  • apple_dpin_end_pm_gate() (drivers/thunderbolt/apple.c:2831-2846) pausing both adapters under c->lock before cancel_delayed_work_sync(&c->retry) + flush_work(&c->work) closes the race where in-flight work returning -EBUSY could rearm the cancelled retry.
  • apple_nhi_complete() (drivers/thunderbolt/apple.c:3086-3090) resumes non-deferred policies (M2) before tb_domain_complete() and deferred policies (M1/M3/M4/M5) after it, skipping both on pm_dark_wake().
  • KUnit additions in apple-dpin-test.c cover the new transitions well, and host-tests CI is green.

Missing §5 hardware evidence (needed on the updated head)

The only hardware runs attached so far are pre-rebase (bb91b3fceaae) under a hypervisor with pm_test=platform and a bench-only DT change. Before approval:

  1. Native T6020/T6021 (J414s/J416s, and J414c/J416c if available): default kernel command line (no hypervisor, no bench DT change), monitor on Thunderbolt + TV on USB-C/HDMI adapter, real s2idle resumes (e.g. 10x) — monitor recovers every time, 0 DPRX timeouts, 0 SELinux denials, 0 failed units, 0 new kernel errors.
  2. Regression row on a defer_new_bringup host (M1/M3/M4) + base M2 (T8112): boot, s2idle resume, and NHI unbind/rebind with a DP tunnel active to cover apple_dpin_end_pm_gate()'s pause-before-drain change.

Assisted-by: LLM (Gemini 4 Neon)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Superseded by #2790. The replacement retains the patch and both human sign-offs, corrects the sleep prepare and completion descriptions, and removes the AI trailers from the commit message. Arm64 KUnit passed 39 cases with one skip. Native resume and regression rows remain pending on the replacement.

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