Skip to content

drm/apple: invalidate mode state on disconnected HPD event - #3523

Merged
DjDeveloperr merged 1 commit into
mainfrom
fix/dcp-unplug-mode-invalidate
Dec 1, 2026
Merged

DjDeveloperr merged 1 commit into
mainfrom
fix/dcp-unplug-mode-invalidate

Conversation

@sithglan

Copy link
Copy Markdown
Contributor

What:
disconnected_hpd_event() clears connector->connected and schedules hotplug_wq to notify userspace of an unplug, but left dcp->mode_state.valid set until the firmware finished tearing down the link and delivered cb_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.valid is still true. 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 set fControllerPowerState = 0 inside VideoInterfaceIOAV::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), leaving present_state_h17p.pending stuck until setPowerState(0) timeout 1000 ms and 10 s later iomfb_queue_timeout() latches dcp->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) inside disconnected_hpd_event() before scheduling hotplug_wq so 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 in apple-display-hotplug covering both idle and in-flight modeset invalidation.

Tested:

  • Local checks at exact head a5af61d67c3e:
    • tools/testing/kunit/kunit.py run --arch=arm64 --kunitconfig=drivers/gpu/drm/apple/tests/display.kunitconfig 'apple-display-hotplug*': 12/12 passed (including new hotplug_disconnected_hpd_invalidates_mode and hotplug_disconnected_hpd_invalidates_inflight_modeset).
    • Full display.kunitconfig KUnit 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.
  • Hardware verification at exact head a5af61d67c3e on MacBook Air M5 (J813 / T8142, macOS 27.2 firmware, kernel 7.3.0-aurora-j813-dcpunplug+, default cmdline earlycon=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 EV2780 2560x1440@60 Hz over USB-C on 3aae00000.dcp / DP-2; note 1 unrelated failed unit on base 844781f1b56b: speakersafetyd.service):
    • Live unplug while DP-2 was actively presenting (825.670 s): dcp_hotplug() connected:0 valid_mode:0 nr_modes:18 — 0 swallowed swap, 0 setPowerState(0) timeout, 0 IOMFB transaction timed out, 0 dcp->crashed (deterministic crash on every unplug before this fix).
    • Replug (840.005 s): 3aae00000.dcp recovered cleanly and completed set_digital_out_mode.
    • DPMS off/on cycles (526–529 s, 901–905 s): dcp_poweroff() done and set_digital_out_mode finished:2060 with picture restored cleanly (verifying #3157 DPMS pipe-off is preserved).
  • Additional combined check (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-dcp external display unplug (disconnected_hpd_event()).

Not yet:

  • Second-family hardware verification on M1 MacBook Air (J313 / T8103, fw 27.2.1) at exact head a5af61d67c3e.

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]>
@sithglan
sithglan requested review from a team as code owners November 28, 2026 12:05

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

Blockers: None (wait for queued CI checks to go green before merge).

Checked:

  • Reviewed drivers/gpu/drm/apple/dcp-internal.h, dcp.c, and hotplug-test.c.
  • Confirmed dcp_mode_invalidate(&dcp->mode_state) is safe in disconnected_hpd_event() (matching existing lockless callers dcp_external_link_fault() and dcp_swap_watchdog()) and runs before schedule_work(&con->hotplug_wq), closing the race where userspace disables the CRTC before firmware delivers cb_hotplug(0) and iomfb_poweroff() submits a clear swap into an already-unplugged pipe.
  • Confirmed connected DPMS-off behavior from #3157 is untouched because disconnected_hpd_event() only runs on physical/HPD disconnect.
  • Confirmed the two new KUnit tests (hotplug_disconnected_hpd_invalidates_mode and hotplug_disconnected_hpd_invalidates_inflight_modeset) cover both idle and in-flight modeset invalidation cleanly.
Evidence
  • Diff reviewed: +45/-2 across 3 files (MERGEABLE against main).
  • Exact-head (a5af61d67c3e) verification reported by author: apple-display-hotplug* 12/12 PASS, full display.kunitconfig 169/169 PASS, ARCH=arm64 W=1 0 warnings, checkpatch.pl --strict clean, and J813 (M5 MacBook Air, fw 27.2) live unplug/replug + DPMS off/on cycles PASS with 0 swallowed swap / setPowerState(0) timeout / dcp->crashed errors.

@sithglan

Copy link
Copy Markdown
Contributor Author

Second-family hardware verification at exact head a5af61d67c3e:

  • MacBook Air M1 (J313 / T8103, macOS 27.2.1 firmware), kernel 7.3.0-j313-pr3523+, cmdline BOOT_IMAGE=/vmlinuz-7.3.0-j313-pr3523+ root=UUID=dbd36156-5a27-466c-b892-cb6fb94dcc2a ro rootflags=subvol=root plymouth.ignore-serial-consoles user4k=on quiet loglevel=3 rd.udev.log_level=3 systemd.show_status=auto console=tty0, EIZO FlexScan EV2780 (2560x1440@60 Hz) over USB-C on 271c00000.dcp / DP-2 (1 unrelated pre-existing failed unit: aurora-touchid-setup.service):
    • Active disconnect (19.989 s), live unplug (170.184 s), and tps6598x module reload disconnect (509.217 s) all logged dcp_hotplug() connected:0 valid_mode:0 nr_modes:18 with 0 swallowed swap, 0 setPowerState(0) timeout, 0 IOMFB transaction timed out, and 0 dcp->crashed (vs deterministic crash on every HPD=0 before this fix).
    • Replug (182.725 s) and DPMS off/on (255.67–258.19 s): dcp_poweroff() done and set_digital_out_mode finished:8274 with 0 timeouts (#3157 DPMS pipe-off preserved).
    • Additional combined check (a5af61d67c3e + usb: typec: tipd: fix coalesced HPD drop recovery on dcp-fabric ports #3439 tps6598x*.ko on J313): live active unplug (607.26 s) -> monitor standby -> replug (627.06 s) -> EIZO ~248 ms standby HPD drop (631.03 s) replayed HPD=0 (valid_mode:0, 0 DCP errors) -> HPD=1 (631.35 s) -> set_digital_out_mode finished:8274 (631.60 s, picture restored in 569 ms).

@github-actions github-actions Bot added area:display Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (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 a5af61d6: not ready yet

Check Detail
CI at head no failing: KUnit asahi, KUnit spi-hid-apple, KUnit avd, KUnit ave, KUnit isp, KUnit jpeg
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok in the PR body at a5af61d6
Conflicts ok not computed yet
PR text ok Risk: two-way · all Apple Silicon Macs using apple-dcp external display unplug (disconnectedhpdevent()).

Areas: area:display

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

@erikwb

erikwb commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

The two patches worked together on the J313 (T8103) daily build c78766a6b703, based on ee2c37398e47 with #3523 at a5af61d67c3e, #3655 at 4261e69d1e9a, and the IOMFB channel wait-queue prerequisite.

  • Docked deep sleep: 1/1 RTC wake with the CalDigit TS5 attached and its external display active. DP-2 returned at 3840×2160 at 120 Hz.
  • Awake reconnect: The display lit on all three observed reconnects. One restored 4K120 and two selected 1080p120. USB4, PCIe and 2.5 Gb/s Ethernet recovered. No DCP power-off or IOMFB transaction timeouts were observed.
  • Mode follow-up: A further reconnect selected 4K60 because DRM marked it preferred. An explicit 4K120 request worked on the same connection. On another reconnect DRM preferred 1080p120 and omitted 4K120 from its mode list, with the same USB4 link rate and lane count.

The combined run supports carrying both fixes in the J313 daily.

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

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.

@DjDeveloperr
DjDeveloperr merged commit b32acf0 into main Dec 1, 2026
30 of 43 checks passed
@DjDeveloperr
DjDeveloperr deleted the fix/dcp-unplug-mode-invalidate branch December 1, 2026 07:17
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) 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.

3 participants