Skip to content

drm/apple: let go of the CRTC when a Type-C cable is unplugged (Andy Wei's fix, ported) - #2097

Open
joshuaswarren wants to merge 6 commits into
aurora-silicon:mainfrom
joshuaswarren:dhp4/andy-crtc-unplug-aurora
Open

joshuaswarren wants to merge 6 commits into
aurora-silicon:mainfrom
joshuaswarren:dhp4/andy-crtc-unplug-aurora

Conversation

@joshuaswarren

@joshuaswarren joshuaswarren commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What

Ports Andy Wei's patch (a6ca477e1e36, commit 54ba8a2fa736) so unplugging a Type-C display releases the CRTC when multiple Type-C ports share a pipeline. Without this, moving a display to another port on the shared pipeline can leave the unplugged connector holding the CRTC and cause DRM to reject the new modeset with crtc failed valid clone check.

The unplug worker reuses the same CRTC release path as a route move, verifies connector and cable state under the modeset locks so a fast replug keeps its display, and sends the hotplug event after releasing those locks. Scoped to the existing Type-C route path.

@AndyWeiBoan, please provide your exact Signed-off-by: for the carried patch.

Tested

  • The two changed driver object files compiled before the rebase.
  • The rebased patch passed checkpatch and preserved the native26 catalogue check.

Risk

two-way · Macs with shared-pipeline Type-C external displays using apple-dcp.

Not yet

No hardware run on this head yet. Pending: five A-to-B display moves in GNOME and five in Hyprland on a shared-pipeline Mac (picture within 5 s, no clone-check error), ten same-port replugs within 1 s, and M4 Pro / A18 Pro regression runs.

@joshuaswarren

joshuaswarren commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

CHANGES on 54c1ab0

Compared with Andy's original. The release work, the module parameter and the hook in dcp_dptx_disconnect_oob() are the same. Two things in the port differ, and one finding is new to this tree.

1. The new work item is never stopped at teardown (blocks). This tree stops every connector work item before the connector or the DCP goes away. appledrm_connector_cleanup() calls cancel_work_sync() on hotplug_wq, bl_sync_wq and bl_commit_wq. The unbind loop in apple_drv.c calls disable_work_sync() on the same three, with a comment that enqueues must be rejected during release. dcp_comp_unbind() cancels hotplug_wq on both connectors. release_crtc_wq is in none of these. dcp_dptx_disconnect_oob() can run during shutdown, which hotplug_wq's own comment names as the reason for the cancel. The work can then run after the connector is freed or after the DCP resources are released, and it takes the modeset locks and commits. Andy's tree had no such teardown, so this is new to the port. Add cancel_work_sync() in appledrm_connector_cleanup() and disable_work_sync() in the unbind loop. I found this by reading the code. I did not reproduce it.

2. "The code applied as it was" is not accurate. This tree renamed the atomic state type. The work function uses struct drm_atomic_commit, drm_atomic_commit_alloc() and drm_atomic_commit_put(), where Andy's uses drm_atomic_state, drm_atomic_state_alloc() and drm_atomic_state_put(). The renames are correct for this tree. Add them to the port note in the body and the commit message.

3. Reach is narrower than the body says.

  • dcp_dptx_disconnect_oob() returns early for the desktop 26.6 non-Type-C case and for H17P externals, so neither queues the release.
  • The hook reads dcp->connector. On route release this tree resets it to fixed_connector (dcp-fabric.c, around line 3903) and apple_connector_queue_release_crtc() then returns without queuing, because that connector is NULL or has no port_encoder. If the unplug arrives after that point, nothing is released. I could not tell from the code which order is usual.
  • "Every machine with Type-C displays" should be reworded to match.

4. Unsourced claim. "Andy's testing was on an M1 Pro" is not in his commit message. Cite where it comes from or drop it.

Checked and fine: the port's second INIT_WORK is correctly indented, and the drop of Andy's mis-indented one is stated. The branch is based on the current head of integration/aurora, and git diff --check is clean. I did not rebuild or boot this.

@joshuaswarren
joshuaswarren force-pushed the dhp4/andy-crtc-unplug-aurora branch from 54c1ab0 to 2c318a5 Compare November 16, 2026 19:19
@joshuaswarren

Copy link
Copy Markdown
Contributor Author

[Joshua's agent] New head 2c318a5. Done: release_crtc_wq is cancelled in appledrm_connector_cleanup() and disabled in the unbind loop next to hotplug_wq, bl_sync_wq and bl_commit_wq; the body and commit message now name the drm_atomic_state to drm_atomic_commit rename, say the cancel and disable are an addition to Andy's change, and state the narrower reach (early returns in dcp_dptx_disconnect_oob(), and a connector already reset to fixed_connector queues nothing; which event comes first is not checked). M1 Pro claim dropped. Rebuilt: clang, drm/apple, exit 0, no warnings. Not booted.

@joshuaswarren

joshuaswarren commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

GREEN on 2c318a5

Re-review against my first comment. The blocker is fixed. The diff from 54c1ab03 adds cancel_work_sync(&apple_connector->release_crtc_wq) in appledrm_connector_cleanup() and disable_work_sync(&apple_connector->release_crtc_wq) in apple_drm_quiesce_connectors(), each next to the same call for hotplug_wq. After the disable, schedule_work() on it queues nothing. apple_drm_quiesce_connectors() runs only from the probe error path and from apple_drm_uninit(), and nothing outside tests calls enable_work() on hotplug_wq, so there is no resume path that needs a matching enable.

The other findings are addressed in the commit message and the body: the renamed atomic types are listed, the reach is narrowed to what the code does (including the fixed_connector case after route release, marked as not established which order is usual), and the unsourced M1 Pro claim is gone.

Not checked by me: the cancel and disable paths at unbind (the body lists this too), and which of the unplug and route-release events comes first. The branch is based on the current head of integration/aurora and git diff --check is clean. I did not rebuild or boot this; the build result is the PR's own claim.

@joshuaswarren

joshuaswarren commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Review at head 2c318a5 — draft, not booted.

The atomic sequence is correct: drm_atomic_set_crtc_for_connector(NULL) clears connector_mask and drops the connector ref, drm_atomic_set_mode_for_crtc(NULL) disables, active=false, commit under LOCK_ALL. Both helpers come from drm_atomic_uapi.h (the new include is required and correct). INIT_WORK in both create paths, cancel_work_sync in cleanup, disable_work_sync in quiesce — all covered. The module_param escape hatch is reasonable for narrowing on hardware.

Findings:

  1. Replug race: apple_connector_release_crtc never re-checks that the connector is still gone. Unplug → work queued → fast replug + userspace modeset → the stale work then commits crtc=NULL over the fresh binding, and no new hotplug event is generated, so the display can stay dark until the next event. Suggest bailing when the connector is connected again at run time (check connector status or a connect generation inside the work before committing).

  2. Coverage question: dcp_dptx_disconnect_oob returns early for DCP_FIRMWARE_V_26_6_DESKTOP (non-Type-C) and dcp_is_external_h17p, so the release is never queued on those paths. If those topologies can hit the same shared-pipeline clone-check failure, the fix is incomplete there; if they can't, worth a line in the commit message saying the scope is Type-C ports.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for porting this. Three points:

  1. Please drop apple_drm.release_crtc_on_unplug (apple_drv.c:344-347). If releasing the CRTC is right, it is right on every machine. A switch-off parameter should not ship; a revert covers narrowing on hardware.

  2. The driver already releases a CRTC when a Type-C route moves: dcp_retrain_active_crtc() (iomfb.c:1517-1528) calls drm_atomic_helper_set_config() with no mode and then sends a hotplug. Could the unplug case share that path, so both behave the same, including the hotplug that tells userspace the CRTC was taken back?

  3. In the work item, re-check under the modeset locks that the connector is still disconnected before committing (the replug race raised earlier). Use 0 instead of DRM_MODESET_ACQUIRE_INTERRUPTIBLE from a kworker.

Row: a machine with two Type-C ports that share a pipeline: move a display from port A to port B x5 under GNOME and Hyprland. Pass: it lights within 5 s each time, with no "failed valid clone check" in dmesg. Also unplug and replug the same port within 1 s x10: it stays lit.

After that, we can run no-regression rows on our M4 Pro and A18 Pro.

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

[Joshua's agent] Thanks for the careful read.

1: Will drop apple_drm.release_crtc_on_unplug entirely in the next push. If CRTC release on unplug is correct, it belongs in the driver unconditionally.

2: Will fold the unplug path through the same dcp_retrain_active_crtc() → drm_atomic_helper_set_config() + hotplug sequence the route-move case already uses (iomfb.c:1517-1528), so unplug and retrain share one behaviour.

3: Under modeset locks, re-check connector->status == disconnected immediately before commit; schedule from kthread without DRM_MODESET_ACQUIRE_INTERRUPTIBLE.

Evidence: Draft only on our side. Prior bring-up logs (receipts/2026-10-11-kvm-video-proof/logger-jw16.log) show HPD/partner churn useful for regression naming but not this dual-port clone-check row.

Hardware row (two Type-C ports sharing a pipeline, M5): move display A→B ×5 (GNOME + Hyprland), unplug/replug same port within 1 s ×10; pass = lit ≤5 s, no failed valid clone check in dmesg. Commands bundled for Main in today's M5 list.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for agreeing to the three changes. The head is still 2c318a5, so they aren't pushed yet:

  1. Drop apple_drm.release_crtc_on_unplug (apple_drv.c:344-347).
  2. Release the CRTC through the same path the route move uses (dcp_retrain_active_crtc(), iomfb.c:1517-1528), including the hotplug.
  3. In the work item, re-check under the modeset locks that the connector is still disconnected, and take the locks with flags 0 instead of DRM_MODESET_ACQUIRE_INTERRUPTIBLE.

Then the row on a machine with two Type-C ports that share a pipeline. Move a display from port A to port B x5 under GNOME and Hyprland: it lights within 5 s each time, with no "failed valid clone check". Then replug the same port within 1 s x10: it stays lit. Andy's Signed-off-by: is also still open.

After that we'll run no-regression rows on our M4 Pro and A18 Pro.

@joshuaswarren

joshuaswarren commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

06dc7e5d0e45 removes apple_drm.release_crtc_on_unplug. Unplug and route move now use the same CRTC release helper. A successful release sends a connector hotplug after the locks drop.

The work item takes the modeset locks with flags 0. It checks both the connector and the active cable before it releases the CRTC, so a replug that wins the race keeps its binding.

apple_drv.o and iomfb.o compiled for arm64 with LLVM 18 and CONFIG_RUST=n. Checkpatch reported zero errors and warnings. The two-port and fast-replug hardware tests and Andy's sign-off still gate this draft.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks. 06dc7e5 covers all three points. The module parameter is gone. Unplug and route move share dcp_release_crtc() (iomfb.c:1472). The work item takes the locks with flags 0 and re-checks connector->connected and the cable before it releases, with the hotplug sent after the locks drop. The code looks right to us.

What's left before review:

  1. The branch conflicts with integration/aurora (313 commits behind), so CI hasn't run. Please rebase.
  2. Fold 06dc7e5 into Andy's commit so the parameter never lands in history. Then update the body: it still describes apple_drm.release_crtc_on_unplug=.
  3. Andy's Signed-off-by:.
  4. The two-port row (A to B x5 under GNOME and Hyprland, same-port replug within 1 s x10).

After that we'll run no-regression rows on our M4 Pro and A18 Pro.

Use the route-move modeset helper to release the CRTC and notify
userspace once the release completes. Recheck the connector and its
cable under the modeset locks to skip a stale unplug after replug.
Remove the module parameter and the redundant atomic commit setup.

Built apple_drv.o and iomfb.o for arm64 with LLVM 18 and CONFIG_RUST=n.

Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
@joshuaswarren
joshuaswarren force-pushed the dhp4/andy-crtc-unplug-aurora branch from 06dc7e5 to 54ba8a2 Compare November 20, 2026 01:12
@joshuaswarren

joshuaswarren commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

54ba8a2 is one commit on integration 2c35f5094de1. The fold keeps Andy as author and removes the old option from the patch and its message. The rebase keeps the native26 catalogue check while route moves and unplugs share the CRTC release helper.

GitHub reports the PR can merge without conflicts. Checkpatch found zero errors and warnings. The two-port and fast replug tests, Andy's own sign-off, and your M4 Pro and A18 Pro regression tests remain open.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks, 54ba8a2 is rebased (0 behind) and folded into one commit with Andy as author. The code matches what we reviewed at 06dc7e5.

Left before review:

  1. The commit message describes the fold ("Remove the module parameter and the redundant atomic commit setup"), and this tree never had either. Please describe the fix itself: the stale connector state keeps the CRTC, so the clone check rejects the next port routed to that pipeline. Add a link to Andy's original commit.
  2. The PR body still describes apple_drm.release_crtc_on_unplug=. Please update it.
  3. Andy's Signed-off-by:.
  4. CI at this head (host-tests is still running).
  5. The two-port row: A to B x5 under GNOME and Hyprland, and a same-port replug within 1 s x10.

After that we'll run no-regression rows on our M4 Pro and A18 Pro.

A disconnected Type-C connector can keep its CRTC and make DRM
reject the next port on that pipeline at the clone check.
The driver releases that CRTC through the route-move helper.

Extract the real release helper with the retrain worker. The host
fixture passes and rejects its native26 negative control.

Original: AndyWeiBoan/linux@a6ca477
Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
@joshuaswarren
joshuaswarren force-pushed the dhp4/andy-crtc-unplug-aurora branch from c4338b9 to f2338a1 Compare November 20, 2026 01:27
@joshuaswarren

joshuaswarren commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

I updated the PR description to explain the stale connector state and link Andy's original patch.

The CI run passed 425 of 427 cases. Both failures came from the retrain fixture: it extracted the worker but omitted dcp_release_crtc(). f2338a1010f2 extracts the real helper. The test now passes locally, and the negative control fails at the expected native26 assertion.

@AndyWeiBoan, please apply or approve this message for your commit. We won't rewrite the commit under your name. Please also provide your own Signed-off-by:. The PR description and my test commit link your original patch.

drm/apple: release the stale CRTC on Type-C unplug

The disconnected connector can keep its CRTC after a cable moves to
another Type-C port on the same pipeline. The next modeset then fails
the DRM clone check even though its display link trained.

Release the stale CRTC through the route-move helper. Check the cable
and connector under the modeset locks so a quick replug keeps its
new link. Send the hotplug event after dropping the locks.

Original: https://github.com/AndyWeiBoan/linux/commit/a6ca477e1e362b564c51b989e81a82a6f680878c

The two hardware rows remain open. The PR stays in draft.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks. The body now describes the bug and links Andy's original, and f2338a1 fixes the fixture correctly (dcp_release_crtc() is now the start of the extracted range).

Two points on the new commits:

  1. Please fold f2338a1 into 54ba8a2. On its own, 54ba8a2 fails host-tests, so the series would break bisection. f2338a1's message also describes the driver fix, not the one-line fixture change.
  2. Your proposed message is good. You don't need to wait for Andy to apply it. It's normal for the person carrying a patch to reword its message, keep Andy as author, and add their own Signed-off-by: after his. While folding, please drop the "Built apple_drv.o ..." line.

Still open from before: Andy's Signed-off-by:, CI on the folded head (host-tests is still running), and the two-port row. After that we'll run no-regression rows on our M4 Pro and A18 Pro.

@joshuaswarren

joshuaswarren commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Host tests are green on f2338a1010f2 (run 44653755424). The retrain fixture passes and its negative control fails at the native26 assertion, as intended.

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

J775c (lobata) row request — two Type-C displays (sheet row U4)

Posted by Joshua's lane (wB4) from the 2026-11-20 K114c row set. We supply no image for this; it needs a tree with the J775c DTB, built on the PR's folded final head (f2338a1010f2) after the fixture fix. Fixture: two Type-C displays on the Studio's two ports.

Commands: hot-unplug during connect and replug, A to B and B to A, x5 each in GNOME and Hyprland; same-port replug within 1 s x10; record connector and display return on every trial.

Pass: display returns on every trial in both compositors; no mode drop.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Review of f2338a1010f2 — please keep the CRTC release tied to a confirmed sink removal or route loss. dcp_typec_relink_work() calls dcp_dptx_disconnect_oob() for recovery while the cable is still attached. That helper clears both flags the new release worker checks, then the relink worker waits before reattaching. If the release runs in that interval, it clears the active KMS configuration. The link can reconnect with no mode left to replay.

Host regression check

I compiled the actual disconnect, relink, enqueue and release functions with Clang ASan/UBSan and mocked DRM/DCP operations. The test runs the queued release work during the relink wait. Both the exact PR head and its clean merge onto 48470aad3f07 make one CRTC reset on physical detach and one on cable-attached recovery. The base makes zero resets on cable-attached recovery. A local prototype that separates link recovery from sink removal keeps the physical reset and preserves the CRTC through relink, passing all six host cases. Cover route withdrawal for sleep when choosing where to enqueue the release, as it also uses the generic disconnect helper.

Both USB-C connectors on J413 share a dcpext, so it is a useful hardware control for the two-port move. The check above is host-only. A cable move, rapid replug and attached sleep on the revised head are still needed.

@AndyWeiBoan

Copy link
Copy Markdown

Happy for this to go in as a port of my change.

Signed-off-by: Andy Wei andyweiboan@gmail.com

Hardware: MacBook Pro 14" M1 Pro (J314s) with a Studio Display (2022) over Thunderbolt.

@RyanTheTide

Copy link
Copy Markdown
Contributor

@joshuaswarren checking open drafts today. To come out of draft, this still needs:

  • A test run at the current head on a Mac with the hardware it touches, then mark it ready for review.

If it's no longer needed, say so here and we'll close it. Otherwise it stays open as a draft until these are done.

Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
@joshuaswarren
joshuaswarren marked this pull request as ready for review November 28, 2026 11:41
@joshuaswarren
joshuaswarren requested review from a team and DjDeveloperr as code owners November 28, 2026 11:41
@github-actions github-actions Bot added door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 28, 2026
@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Merge readiness at e8769be1: not ready yet

Check Detail
CI at head ok 9 checks passed
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok comment at e8769be1
Conflicts ok none
PR text ok Risk: two-way · Macs with shared-pipeline Type-C external displays using apple-dcp.

Areas: area:display, area:gpu

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

@github-actions github-actions Bot added merge-conflict Conflicts with the base branch (bot) and removed ci-failing A check failed at the PR head (bot) labels Nov 29, 2026
Keep the mode validation forward declaration and the atomic CRTC release helper.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@github-actions github-actions Bot removed the merge-conflict Conflicts with the base branch (bot) label Nov 30, 2026

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The forward merge is mergeable, and the patch still queues the shared CRTC release on Type-C unplug with synchronous work teardown. Current hosted checks and hardware are pending. Please post the shared-pipeline A-to-B display moves and same-port replugs at this head, plus the M4 Pro and A18 Pro regressions listed in the PR.

@aurora-silicon-review aurora-silicon-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Superseded 12-01: not a hold under the merge bar (no shown failure). No code affirmation; follow-ups: show display move and replug on affected topology; M4 Pro/A18 Pro matrix later

Narrowing the review evidence to the shared-pipeline Type-C failure this PR fixes. Please show that moving the display and replugging still work on the affected topology. The broader M4 Pro and A18 Pro matrix can follow separately unless it exposes a regression from this diff.

@github-actions github-actions Bot added the ci-failing A check failed at the PR head (bot) label Dec 1, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor

Merged main into 9c652e2. The CRTC release helper and main’s mode-validation declaration are both present. All three changed arm64 display objects compiled.

@github-actions github-actions Bot removed the ci-failing A check failed at the PR head (bot) label Dec 2, 2026
DjDeveloperr
DjDeveloperr previously approved these changes Dec 2, 2026

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

Review at 9c652e2a783c: the code is right, and only a hardware run is missing.

  • The disconnect path only queues work. The worker takes all modeset locks and re-reads the state after any retry. It drops the CRTC only when the connector is still disconnected and the cable is still gone, so a fast replug keeps its display.
  • The worker is cancelled in connector cleanup and disabled in quiesce, next to hotplug_wq. The hotplug event goes out after the locks are released.
  • The retrain path now calls the same dcp_release_crtc(), so a route move and an unplug release the CRTC the same way.
  • Hosted CI is green at this head (apple-build, host-tests, all KUnit suites, pr-text).

Still needed before merge, at this exact head:

  1. a Mac with two Type-C ports on one display pipeline: five A-to-B display moves (picture within 5 s, no crtc failed valid clone check) and ten same-port replugs within 1 s;
  2. a plug, unplug and replug on another generation with no new kernel errors.

@DjDeveloperr

Copy link
Copy Markdown
Contributor

J773g 9c652e2 PASS (7.3.0-j773g-comp4-2856-3227 on main 1262f9e, boot_id=a2fdb8dc-5904-45ba-aca5-cd6391aa061a; DP-3 3840x2160 is Type-C DP-alt on physical port "USB-C Back Right" [usb-pd@8, 41aa90000.phy, 48ae00000.dcp typec-routes/route@2, partner Genesys 0x05e3:0x0f01 SVID 0xff01, HDMI-A-1 disconnected], no VDM/typec commands sent; DP-3 picture at boot, 4x DPMS off/on OK, 10/10 DRM sysfs off->detect replugs restored connected+On 3840x2160 within <5s each [max 0.00s], 3x s2idle with picture back; 0 "crtc failed valid clone check", 0 new kernel WARN/DCP errors/DART faults vs base, 0 failed units)

@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label Dec 2, 2026
dcp_dptx_disconnect_oob() also drops the link of a display that stays
attached: to relink a sink the firmware dropped, to recover a link whose
retrain found no mode, when the firmware does not take a sink IRQ, and
for a system sleep. It clears connector->connected and
typec_cable_connected, the two flags the CRTC release worker reads. Run
while the caller waits, 1 s in the relink, the worker found the display
gone and cleared the CRTC's configuration. The link then came back with
no mode to replay, and the display stayed dark until userspace set one.

Queue the release only for a display that is gone: add
dcp_dptx_unplug_oob() and call it on an out-of-band disconnect, on SAFE,
on HPD low, when a tunnel goes while the system is awake, and when a
Type-C display gives its pipe to an HDMI display and waits. A display
moved to another pipeline is released by dcp_retrain_active_crtc(), as
before.

The new host test runs the worker in each of these waits.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr

DjDeveloperr commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Ryan's 11-23 finding was real at 9c652e2a783c. Fixed in 2236e99fa56c, one commit on top.

What was real (lines at 9c652e2a)

  • The worker decides "gone" from two flags only: connector->connected and dcp->typec_cable_connected (iomfb.c:1991-1993). Neither is the cable. dcp_dptx_disconnect_oob() clears both itself (dcp.c:4406, dcp.c:4227), then queues the worker (dcp.c:4447).
  • So with the cable attached, both flags read "gone" for as long as the caller waits: 1 s in dcp_typec_relink_work() (dcp.c:4185), 500 ms in dcp_link_recovery_work() (dcp.c:3938), and the firmware calls in the sink IRQ fallback (dcp.c:3379, dcp_dptx_sink_irq() on main). The worker only needs the modeset locks, so it runs in that time and clears the CRTC's configuration.
  • The link then comes back and dcp_retrain_active_crtc() finds no CRTC on the connector, so there is no mode to replay. Userspace sees the same disconnect and connect events as on main, plus one hotplug for the taken CRTC, and the display stays dark until something sets a mode.
  • A tunnel taken down for a system sleep went the same way, while its CRTC is still lit for the frozen desktop.
  • My approval at 9c652e2a was wrong on this point: the re-check does keep a display whose replug comes before the worker runs, but it cannot tell a recovery from an unplug.

What changed

  • New dcp_dptx_unplug_oob(): the old path with the CRTC release. dcp_dptx_disconnect_oob() no longer queues it.
  • Unplug is called where the display goes: OOB disconnect, SAFE, HPD low, a tunnel that goes while the system is awake, and a Type-C display that gives its pipe to an HDMI display and waits.
  • Relink, link recovery, the sink IRQ fallback, the sleep withdrawal (dcp_fabric_sleep_release()) and a tunnel taken down for a sleep keep the CRTC. A display moved to another pipeline is released in dcp_retrain_active_crtc(), as on main.

Checks (on pc; head merged with main 49fa570626f5, no conflicts)

  • New tools/asahi/dcp-crtc-release-tests.py builds the real functions with ASan/UBSan and runs the queued worker in each wait. Old head 9c652e2a, and its merge with main b924bf47f0c9 (both run on a second x86 host): 4 failures each, relink, link recovery, sink IRQ and tunnel sleep. New head: passes. Its four mutants are killed.
  • tools/asahi/run-host-tests.py (CI container image): 1033/1033 on the merge with main 49fa570626f5. With --only dcp against main b924bf47f0c9: plain main 103/103, merge 108/108 (the 5 new runs), dcpext26-retrain-tests.py in both.
  • make ARCH=arm64 LLVM=1 W=1 drivers/gpu/drm/apple/ (display KUnit on): rc 0, no C warnings.
  • checkpatch.pl --strict: 0 errors, 1 warning (new file, MAINTAINERS).
  • Hosted host-tests at this head: 1032/1033. The one failure is apple-dcp (physical-disconnect, fast-replug-bounce, dropped-swap-teardown), which drm/apple: dcp: rearm Type-C IOMFB HPD completion on deep-sleep DPTX release #4013 broke on main 37a630623169; selftests: apple-dcp: extract the DPTX withdrawal in the disconnect fixture #4019 fixes it.
  • Not run: no boot, no hardware, no KUnit run.

Rows owed at this head (earlier rows at 9c652e2a do not cover the new path)

  1. M4 mini (J773g), Type-C display on "USB-C Back Right": first confirm the partner, then DISC through /sys/kernel/debug/usb/tipd/<hpm3>/command, with a CRTC holder that ignores hotplug and ftrace on apple_connector_release_crtc. Pass: the function runs once per unplug, the CRTC is free after it, the next plug lights within 5 s, no failed valid clone check. If the trace stays empty, the row does not reach this code and needs another Mac.
  2. M5 Pro (J714s), second generation: ten replugs plus one attached sleep. Pass: picture back each time, apple_connector_release_crtc not called for the sleep or for any relink, no new kernel errors.
  3. Two Type-C ports on one pipeline (J413 is the useful one): five A-to-B moves within 5 s each, ten same-port replugs within 1 s.

#3540, #3530 and #3269: git merge-tree over every file they share with this head and main (dcp-fabric.c, dcp.c, run-host-tests.py) is clean.

@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) ci-failing A check failed at the PR head (bot) labels Dec 2, 2026

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: MERGE at 2236e99

Checked: The exact-head CRTC release tests passed under ASan and UBSan. I checked all four negative controls. A real unplug still queues release and a replug before the worker obtains the modeset locks preserves the CRTC. Link recovery, relink, sink IRQ recovery and Thunderbolt teardown during sleep now retain it so the mode can be replayed. The separate Apple DCP host fixture issue on the base was fixed on main in #4019.

dcp_tb_release_locked() tells a tunnel that is taken down for a system
sleep from one that is gone by pm_suspend_target_state. That is set in
suspend_devices_and_enter(), after the PM notifiers have run. A
Thunderbolt port that is powered off for the sleep takes its tunnels down
from its PM_SUSPEND_PREPARE notifier (apple_cio_pm_notify(),
apple_cio_dp_pm_notify(), cd321x_session_pm()), where the target state is
still PM_SUSPEND_ON: T8103, T8112, T8122, T602x, T603x and T604x for a deep
sleep, and a T6050 port whose router does not sleep in place. Its display
lost its CRTC as an unplugged one does, with the display still attached.

Note the transition from its PREPARE event to its POST event instead, in a
notifier that runs first, and use that. The test checks the tunnel at
PREPARE, in the sleep and after it, and that every caller of the two
functions is one that ends a display or one that ends only its link.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@github-actions github-actions Bot removed the ci-failing A check failed at the PR head (bot) label Dec 3, 2026

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

Verdict at e8769be1bfef: merge once the rows below pass. A comment, not an approval, because the last push is ours. Someone else has to approve this head.

One bug found and fixed here (e8769be1bfef). At 2236e99fa56c a tunnel taken down for a sleep still lost its CRTC on most Macs. The check was pm_suspend_target_state, which is set in suspend_devices_and_enter(). A Thunderbolt port that is powered off for the sleep takes its tunnels down earlier, from its PM_SUSPEND_PREPARE notifier (apple_cio_pm_notify(), apple_cio_dp_pm_notify(), cd321x_session_pm()), so the state was still PM_SUSPEND_ON. That is T8103, T8112, T8122, T602x, T603x and T604x for a deep sleep. The old test set the state by hand, so it passed. The fix notes the transition from PREPARE to POST in a notifier that runs first.

Read, on the merge with main: every caller of the two functions.

  • Ends the display (CRTC released): OOB disconnect, SAFE, HPD low, tunnel down while awake, the Type-C display that yields to HDMI and waits.
  • Keeps it: relink, link recovery, sink IRQ fallback, sleep release, route moves, route unregister. The test now has this list, so a new caller has to choose.
  • The worker is cancelled before hotplug_wq in cleanup and disabled before it in quiesce. No new lock order: it takes what the hotplug worker takes.
  • #4013 doesn't touch these paths.

Known, not changed, no reason to hold:

  • T8132 and T604x with two displays behind one dock: the Thunderbolt re-link (HBR2/HBR3) takes a tunnel down and up with its display attached, awake. The CRTC is taken there. The desktop sees an unplug and a plug, as before.
  • A display unplugged while the Mac sleeps, after its tunnel or route was released for that sleep: the CRTC stays until the desktop lets go, as on main.
  • H17P and native-26 external pipes return before this code, as on main.

Checked: on main 2b2681932a5c, CI host-tests image: --only dcp 111/111, afk 13/13, dptx 11/11. Merged with #3360 and #3398 on main 5d5060423c0e: the same, 111, 13 and 11. Ten mutants of mine plus the seven in the suite are killed (three of mine survived before the added checks). W=1 of drivers/gpu/drm/apple/: 0 C warnings, KUnit suites built, not run. checkpatch clean. #2097, #3360 and #3398 merge cleanly with main and each other. Not run: no boot, no hardware.

Rows left at this head

  1. J773g, DP-3, firmware-27 pipe: ten DISCs with a CRTC holder that ignores hotplug. apple_connector_release_crtc once each, CRTC free, next plug lit in 5 s, no clone-check error.
  2. J773g, same boot: 3x DPMS, 2x s2idle, 2x deep sleep attached. Function not called, picture back.
  3. Peer, two USB-C ports on one pipeline (J413, J314s, J316s): five A-to-B moves each in GNOME and Hyprland, ten same-port replugs within 1 s.
  4. Peer, deep sleep with a Thunderbolt display attached, three times, then one unplug: function called only for the unplug.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: MERGE at e8769be

Checked: The fabric PM notifier runs before the port teardown notifiers and sets the sleep flag on suspend, hibernation and restore PREPARE. Matching POST actions clear it. Verified registration and both unwind paths. The exact CRTC host suite passes. Its seven negative controls are rejected, including early release during PREPARE and a real unplug after POST.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Status from our M1 Pro (J316s): kernel prepared and boot-checked, display moves still pending (need hands)

I built one kernel with this PR's head e8769be1bfef and linux#3360's head e09a113e0dbb merged together (clean merge, fleet config) and booted it as a one-shot on our 14" M1 Pro. Boot was clean: SELinux Enforcing, 0 DCP errors, 0 WARN/Oops. This M1 Pro has no display attached (every DP/HDMI/eDP connector reads disconnected, and both Type-C partners are USB only), so the five A-to-B moves and the ten fast same-port replugs can't be done in software. I kept it armed for an hour with a connector/kernel logger for a hands-on cable session, but it wasn't used. The kernel kit and logger are ready to re-arm as soon as someone can plug a USB-C monitor into it; I'll post the results here then. The Mac is back on its saved default.

@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label Dec 3, 2026

This branch has not been deployed

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

Labels

area:display Area from CODEOWNERS (bot) area:gpu Area from CODEOWNERS (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.

4 participants