Repository navigation
drm/apple: invalidate mode state on disconnected HPD event - #3523
Conversation
disconnected_hpd_event() clears connector->connected and schedules hotplug_wq to notify userspace of an unplug, but previously left dcp->mode_state.valid set until the firmware finished tearing down the link and delivered cb_hotplug(0) tens of milliseconds later. On firmware-27 external pipes, userspace can disable the CRTC from that hotplug notification during the window where mode_state.valid is still true. iomfb_poweroff() then bypasses its !mode_state.valid guard and submits a clear swap into an external pipe the firmware has already powered down (fControllerPowerState == 0). The firmware swallows that clear swap without completing it, leaving present_state_h17p.pending stuck until setPowerState(0) times out and iomfb_queue_timeout() latches dcp->crashed = true, wedging that external DCP until reboot. Call dcp_mode_invalidate(&dcp->mode_state) in disconnected_hpd_event() before notifying userspace so CRTC power-off leaves an already-unplugged pipe to the firmware while preserving DPMS-off pipe stop when the cable remains connected. Add KUnit coverage in apple-display-hotplug for both idle and in-flight modesets. Fixes: ad937dc ("drm/apple: leave an external pipe without a valid mode to the firmware") Signed-off-by: Thomas Glanzmann <[email protected]>
There was a problem hiding this comment.
Verdict: MERGE at a5af61d67c
Blockers: None (wait for queued CI checks to go green before merge).
Checked:
- Reviewed
drivers/gpu/drm/apple/dcp-internal.h,dcp.c, andhotplug-test.c. - Confirmed
dcp_mode_invalidate(&dcp->mode_state)is safe indisconnected_hpd_event()(matching existing lockless callersdcp_external_link_fault()anddcp_swap_watchdog()) and runs beforeschedule_work(&con->hotplug_wq), closing the race where userspace disables the CRTC before firmware deliverscb_hotplug(0)andiomfb_poweroff()submits a clear swap into an already-unplugged pipe. - Confirmed connected DPMS-off behavior from
#3157is untouched becausedisconnected_hpd_event()only runs on physical/HPD disconnect. - Confirmed the two new KUnit tests (
hotplug_disconnected_hpd_invalidates_modeandhotplug_disconnected_hpd_invalidates_inflight_modeset) cover both idle and in-flight modeset invalidation cleanly.
Evidence
- Diff reviewed:
+45/-2across 3 files (MERGEABLEagainstmain). - Exact-head (
a5af61d67c3e) verification reported by author:apple-display-hotplug*12/12 PASS, fulldisplay.kunitconfig169/169 PASS,ARCH=arm64 W=10 warnings,checkpatch.pl --strictclean, and J813 (M5 MacBook Air, fw 27.2) live unplug/replug + DPMS off/on cycles PASS with 0swallowed swap/setPowerState(0) timeout/dcp->crashederrors.
|
Second-family hardware verification at exact head
|
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
The two patches worked together on the J313 (T8103) daily build
The combined run supports carrying both fixes in the J313 daily. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Disconnect clears the mode before notifying userspace, so CRTC disable no longer submits a clear swap to the unplugged pipe. The KUnit cases cover both an established mode and one still being programmed. The J813 and J313 unplug checks passed.
What:
disconnected_hpd_event()clearsconnector->connectedand scheduleshotplug_wqto notify userspace of an unplug, but leftdcp->mode_state.validset until the firmware finished tearing down the link and deliveredcb_hotplug(0)(~85 ms later).On firmware-27 external pipes, userspace (sway) can disable the CRTC from that hotplug notification during the window while
mode_state.validis stilltrue.iomfb_poweroff()then bypasses its!READ_ONCE(dcp->mode_state.valid)guard (added in #3157 /ad937dcfb227) and submits a clear swap into an external pipe whose firmware already setfControllerPowerState = 0insideVideoInterfaceIOAV::unplug. The firmware swallows the clear swap without completing it (IOMFB: swap_submit_dcp_main: swallowed swap ID N as fControllerPowerState is 0 for External Display), leavingpresent_state_h17p.pendingstuck untilsetPowerState(0) timeout 1000 msand 10 s lateriomfb_queue_timeout()latchesdcp->crashed = true, wedging that external DCP instance until reboot. Reproduced identically on both M1 MacBook Air (J313 / T8103, fw 27.2.1) and M5 MacBook Air (J813 / T8142, fw 27.2).Call
dcp_mode_invalidate(&dcp->mode_state)insidedisconnected_hpd_event()before schedulinghotplug_wqso CRTC power-off leaves an already-unplugged pipe to the firmware while preserving#3157's DPMS-off pipe stop when the cable stays connected. Add KUnit tests inapple-display-hotplugcovering both idle and in-flight modeset invalidation.Tested:
a5af61d67c3e:tools/testing/kunit/kunit.py run --arch=arm64 --kunitconfig=drivers/gpu/drm/apple/tests/display.kunitconfig 'apple-display-hotplug*': 12/12 passed (including newhotplug_disconnected_hpd_invalidates_modeandhotplug_disconnected_hpd_invalidates_inflight_modeset).display.kunitconfigKUnit run (--arch=arm64): 169/169 passed (1 skipped, 0 failed).make ARCH=arm64 W=1 drivers/gpu/drm/apple/dcp.o: 0 warnings, 0 errors.scripts/checkpatch.pl --strict --git origin/main..HEAD: clean.a5af61d67c3eon MacBook Air M5 (J813 / T8142, macOS 27.2 firmware, kernel7.3.0-aurora-j813-dcpunplug+, default cmdlineearlycon=dockchannel,0x38812c000 console=tty0 console=ttyDC0 keep_bootcon maxcpus=1 rdinit=/init root=LABEL=debian panic=0 rodata=on idle=nop arm64.nowfxt apple_sleep.deep=1 nvme_apple.sleep_untested=1 appledrm.s2r_untested=1, EIZO FlexScan EV27802560x1440@60 Hzover USB-C on3aae00000.dcp/DP-2; note 1 unrelated failed unit on base844781f1b56b:speakersafetyd.service):DP-2was actively presenting (825.670 s):dcp_hotplug() connected:0 valid_mode:0 nr_modes:18— 0swallowed swap, 0setPowerState(0) timeout, 0IOMFB transaction timed out, 0dcp->crashed(deterministic crash on every unplug before this fix).840.005 s):3aae00000.dcprecovered cleanly and completedset_digital_out_mode.526–529 s,901–905 s):dcp_poweroff() doneandset_digital_out_mode finished:2060with picture restored cleanly (verifying#3157DPMS pipe-off is preserved).a5af61d67c3e+ usb: typec: tipd: fix coalesced HPD drop recovery on dcp-fabric ports #3439 on J813): boot with EIZO attached, live unplug (93.5 s), live replug (106.8 s, picture and USB 2.0/3.0 + HID back automatically), and 2/2 DPMS off/on cycles (136–143 s) all passed with 0 DCP timeouts/errors.Risk: two-way door · all Apple Silicon Macs using
apple-dcpexternal display unplug (disconnected_hpd_event()).Not yet:
a5af61d67c3e.