Repository navigation
drm/apple: let go of the CRTC when a Type-C cable is unplugged (Andy Wei's fix, ported) - #2097
joshuaswarren wants to merge 6 commits into
Conversation
|
CHANGES on 54c1ab0 Compared with Andy's original. The release work, the module parameter and the hook in 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. 2. "The code applied as it was" is not accurate. This tree renamed the atomic state type. The work function uses 3. Reach is narrower than the body says.
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 |
54c1ab0 to
2c318a5
Compare
|
[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. |
|
GREEN on 2c318a5 Re-review against my first comment. The blocker is fixed. The diff from 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 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 |
|
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:
|
|
Thanks for porting this. Three points:
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. |
|
[Joshua's agent] Thanks for the careful read. 1: Will drop 2: Will fold the unplug path through the same 3: Under modeset locks, re-check Evidence: Draft only on our side. Prior bring-up logs ( 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 |
|
Thanks for agreeing to the three changes. The head is still 2c318a5, so they aren't pushed yet:
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 After that we'll run no-regression rows on our M4 Pro and A18 Pro. |
|
The work item takes the modeset locks with flags
|
|
Thanks. 06dc7e5 covers all three points. The module parameter is gone. Unplug and route move share What's left before review:
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>
06dc7e5 to
54ba8a2
Compare
|
54ba8a2 is one commit on integration 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. |
|
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:
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>
c4338b9 to
f2338a1
Compare
|
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 @AndyWeiBoan, please apply or approve this message for your commit. We won't rewrite the commit under your name. Please also provide your own The two hardware rows remain open. The PR stays in draft. |
|
Thanks. The body now describes the bug and links Andy's original, and f2338a1 fixes the fixture correctly ( Two points on the new commits:
Still open from before: Andy's |
|
Host tests are green on |
|
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 ( 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. |
|
Review of Host regression checkI 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 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. |
|
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. |
|
@joshuaswarren checking open drafts today. To come out of draft, this still needs:
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>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
Keep the mode validation forward declaration and the atomic CRTC release helper. Signed-off-by: DjDeveloperr <hey@djdev.me>
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
Merged main into 9c652e2. The CRTC release helper and main’s mode-validation declaration are both present. All three changed arm64 display objects compiled. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
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:
- 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; - a plug, unplug and replug on another generation with no new kernel errors.
|
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) |
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>
|
Ryan's 11-23 finding was real at What was real (lines at
What changed
Checks (on
Rows owed at this head (earlier rows at
#3540, #3530 and #3269: |
There was a problem hiding this comment.
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>
DjDeveloperr
left a comment
There was a problem hiding this comment.
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_wqin 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
- J773g, DP-3, firmware-27 pipe: ten
DISCs with a CRTC holder that ignores hotplug.apple_connector_release_crtconce each, CRTC free, next plug lit in 5 s, no clone-check error. - J773g, same boot: 3x DPMS, 2x s2idle, 2x deep sleep attached. Function not called, picture back.
- 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.
- Peer, deep sleep with a Thunderbolt display attached, three times, then one unplug: function called only for the unplug.
There was a problem hiding this comment.
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.
|
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 |
What
Ports Andy Wei's patch (
a6ca477e1e36, commit54ba8a2fa736) 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 withcrtc 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
native26catalogue 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.