Skip to content

drm/apple: update adaptive sync on an installed firmware-27 pair - #3113

Merged
DjDeveloperr merged 3 commits into
mainfrom
fix/dcp-paired-adaptive-sync
Nov 25, 2026
Merged

DjDeveloperr merged 3 commits into
mainfrom
fix/dcp-paired-adaptive-sync

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Risk: two-way · Reverting this commit restores full paired modesets for adaptive-sync changes. A rejected firmware command still takes the full modeset path.

What: Keep an installed firmware-27 display pair when the timing, color and HDR state still match and only the adaptive-sync minimum differs. Send the existing adaptive-sync parameter to both engines and preserve their frame completion state. Both engines must have completed their modesets. This applies to an active pair regardless of board.

Tested: J714s (T6050), b976c78a5b2d584c4ca79f850cd194b9bb60dff1 — PASS, 2/2 consecutive RTC0 +25 s deep-sleep wakes with DP-5 at 3840×2160/240 Hz. The second paired adaptive-sync update took 0.769 ms and 1.021 ms (baseline 881–897 ms). All three outputs, GPU compute, Wi-Fi, TB5/USB and WD2 returned. Zero new kernel error signatures and zero GPU faults. Hardware row.

Earlier comparison at cdfa82f58037. On J714s with the paired Samsung 4K240 output, each of five baseline wakes installed the same pair twice when the compositor enabled adaptive sync. The second install took 881–897 ms. One verification wake with this change used one full install and an adaptive-sync update under 3 ms. The longest sampled Hyprland IPC round trip during DP-5 setup fell from 1.804 s to 0.885 s. RTC0 +25 s woke from deep sleep, all three displays returned, GPU compute passed, Wi-Fi reassociated, and the TB5/USB dock and WD2 returned. Both builds used the same temporary G16 compile correction for the unrelated main build break. This PR contains only the paired-display change and its host regression test.

Native arm64 build passed. The paired-display host test passed with ASan and UBSan. Strict checkpatch reported 0 errors, 0 warnings, 0 checks.

Signed-off-by: Diljit Singh hey@djdev.me

The same 4K240 timing and color can be installed twice when a paired
display returns after resume. The second commit changes only the
adaptive-sync minimum. It rebuilds both engines and blocks the
compositor for almost another second.

Keep a working pair when the installed timing, color and HDR state
still match, and send the existing adaptive-sync parameter to both
engines. Preserve the frame completion state. A command failure falls
back to the full installation, as do changes to the installed mode.

Signed-off-by: Diljit Singh <hey@djdev.me>
@DjDeveloperr
DjDeveloperr requested a review from a team as a code owner November 25, 2026 02:31
@github-actions github-actions Bot added area:display Area from CODEOWNERS (bot) area:gpu Area from CODEOWNERS (bot) 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 25, 2026
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Merge readiness at b976c78a: not ready yet

Check Detail
CI at head no failing: kunit, apple-build, host-tests, pr-text / pr-text, pr-text / pr-text, KUnit ane-boot
Review ok approved by satchlj
Requested changes ok none
Hardware row at head ok in the PR body at b976c78a
Conflicts ok none
PR text ok Risk: two-way · Reverting this commit restores full paired modesets for adaptive-sync changes. A rejected firmware command still takes the full modeset path.

Areas: area:display, area:gpu

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

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Gemini 4 Neon on @satchlj's behalf — reviewed cdfa82f58037 (MERGEABLE, kunit / readiness / pr-text SUCCESS).

Verdict

REQUEST_CHANGES at cdfa82f58037 — the fast adaptive-sync update idea and host test look clean, and the behavior is properly board-agnostic across active firmware-27 pairs, but there is a lock-drop TOCTOU race in dcp_peer_modeset_v27() when committing the vrr_only fast path.

Blocker

  1. Stale modeset_complete / peer-state check after dropping dcp_peer_lock (drivers/gpu/drm/apple/dcp-peer-runtime-v27.inc:148-171):
    • At lines 148-151, vrr_only checks dcp->peer_tiling.modeset_complete && peer->peer_tiling.modeset_complete && dcp_peer_vrr_only_v27(...) while holding dcp_peer_lock.
    • dcp_peer_lock is then released at line 152 across the blocking dcp_peer_param_v27(dcp, peer, 15, 3, min_vrr) RPCs to both engines (line 162).
    • While dcp_peer_lock is unlocked, a concurrent dcp_peer_hints_v27() -> dcp_peer_release_locked(dcp) callback (drivers/gpu/drm/apple/dcp-peer-v27.inc:156-162, which takes only dcp_peer_lock, not device_lock(dcp->dev)) can clear dcp->peer_tiling.modeset_complete = false and peer->peer_tiling.modeset_complete = false without clearing dcp->peer_frames.active or setting dcp->peer_frames.failed (and the platform limit or peer_reserved/peer_owner state can also change while unlocked).
    • At lines 163-170, the post-RPC guard(mutex)(&dcp_peer_lock) block re-checks only dcp_peer_vrr_only_v27(&dcp->peer_frames, ...), omitting dcp->peer_tiling.modeset_complete && peer->peer_tiling.modeset_complete, dcp->peer_reserved == peer && peer->peer_owner == dcp, and !dcp_peer_limited_pair_locked(dcp, &prepared).
    • If dcp_peer_release_locked() ran during dcp_peer_param_v27(), dcp_peer_modeset_v27() still returns 0 claiming the pair is ready, after which dcp_peer_scanout_v27() (dcp-peer-runtime-v27.inc:333-336) returns -EIO on the next swap because modeset_complete is false, instead of falling through to rebuild the pair (or stopping it if limited).
    • Fix: Inside the post-RPC dcp_peer_lock section (dcp-peer-runtime-v27.inc:163-170), also re-verify dcp->peer_reserved == peer && peer->peer_owner == dcp && dcp->peer_tiling.modeset_complete && peer->peer_tiling.modeset_complete (and handle a newly active platform limit via dcp_peer_limited_stop_v27() rather than falling through to dcp_peer_prepare_v27()).

What Looks Good

  • dcp_peer_vrr_only_v27() (dcp-peer-frames-v27.h:17-24) cleanly checks active && !failed, timing, color, output_hdr, and min_vrr != min_vrr, with clean host unit-test coverage in tools/asahi/dcp-peer-shown-tests.py.
  • Reuses parameter 15 (A450) and falls back cleanly to the full dcp_peer_prepare_v27() / dcp_peer_install_video_v27() rebuild if either engine rejects the update.
  • Commit carries a valid Signed-off-by trailer.

@github-actions github-actions Bot added the changes-requested A reviewer requested changes (bot) label Nov 25, 2026
dcp_peer_modeset_v27() drops dcp_peer_lock across the blocking
dcp_peer_param_v27() calls to both engines. While unlocked,
dcp_peer_release_locked() or a platform-limit change can clear
modeset_complete, release the peer reservation, or impose the pair
limit without clearing peer_frames.active.

Re-verify peer ownership, platform limit, and both engines'
modeset_complete flags under dcp_peer_lock after dcp_peer_param_v27()
returns. Return -EBUSY if ownership was lost, stop a newly limited
pair outside dcp_peer_lock via dcp_peer_limited_stop_v27() (or return
-EOPNOTSUPP if already unprepared), and otherwise fall through to the
full pair rebuild when the fast path is no longer valid.

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

Copy link
Copy Markdown
Contributor Author

@satchlj Addressed the lock-drop TOCTOU race in 9fa8c0838f8c: after dcp_peer_param_v27() returns, dcp_peer_modeset_v27() now re-acquires dcp_peer_lock via scoped_guard to re-verify dcp->peer_reserved == peer && peer->peer_owner == dcp, dcp_peer_limited_pair_locked(dcp, &prepared), and both engines' modeset_complete flags before committing peer_frames.min_vrr. If ownership was lost it returns -EBUSY; if a platform limit became active it stops a prepared pair outside dcp_peer_lock via dcp_peer_limited_stop_v27() (or returns -EOPNOTSUPP if unprepared); otherwise it falls through cleanly to rebuild the pair. dcp-peer-shown-tests.py and strict checkpatch.pl pass.

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Gemini 4 Neon on @satchlj's behalf

Verified 9fa8c0838f8c (drm/apple: recheck paired DCP state after adaptive-sync RPC) against the dcp_peer_modeset_v27() lock-drop TOCTOU race:

  • All race windows closed (drivers/gpu/drm/apple/dcp-peer-runtime-v27.inc:162-193): After dcp_peer_param_v27() returns, dcp_peer_modeset_v27() now re-acquires dcp_peer_lock and re-verifies still_owned (dcp->peer_reserved == peer && peer->peer_owner == dcp), limited (dcp_peer_limited_pair_locked(dcp, &prepared)), both engines' peer_tiling.modeset_complete flags, and dcp_peer_vrr_only_v27(...).
  • Fallback paths: Lost ownership returns -EBUSY; a newly platform-limited pair stops cleanly outside dcp_peer_lock via dcp_peer_limited_stop_v27(dcp, peer) when prepared (or returns -EOPNOTSUPP otherwise); any other RPC failure or invalidated fast-path state falls through to the full dcp_peer_prepare_v27() pair rebuild.
  • CI (9fa8c0838f8c): kunit, host-tests, readiness, and pr-text still pending (host-tests=in_progress/-). Code looks solid — holding formal APPROVE strictly until remaining CI checks finish green.

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Gemini 4 Neon on @satchlj's behalf

All CI checks (kunit, host-tests, readiness, pr-text) are now green on 9fa8c0838f8c, confirming the dcp_peer_modeset_v27() lock-drop TOCTOU fix cleanly resolves the prior review comment.

LGTM — approving.

@github-actions github-actions Bot removed the changes-requested A reviewer requested changes (bot) label Nov 25, 2026
…ve-sync

Signed-off-by: Diljit Singh <hey@djdev.me>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 25, 2026 05:36
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Tested: J714s (T6050), b976c78a5b2d584c4ca79f850cd194b9bb60dff1 — PASS, 2/2 consecutive RTC0 +25 s deep-sleep wakes with DP-5 at 3840×2160/240 Hz. The second paired adaptive-sync update took 0.769 ms and 1.021 ms (baseline 881–897 ms). All three outputs, GPU compute, Wi-Fi, TB5/USB and WD2 returned. Zero new kernel error signatures and zero GPU faults.

Cycle Firmware wake to suspend exit Paired VRR update, kernel monotonic seconds Duration Longest sampled Hyprland IPC
1 5.669223 s 40.688142 → 40.688911 0.769 ms 880.6 ms
2 5.650661 s 85.977089 → 85.978110 1.021 ms 852.3 ms

Each wake performed one full paired modeset, then programmed the 48 Hz minimum on both DCP engines in the timed update. Both wakes reported the RTC source. The suspend success counter advanced from 0 to 2 and the failure counter stayed at 0. The RTC read six seconds past its alarm on return from each cycle.

DP-5 settled at 239.996 Hz on both wakes. Wi-Fi was associated by the +8.1 s sample on both. On cycle 1 the Dell DP-2 used its known USB3 replug recovery and was enabled again at +9.083 s. Both settled USB and Thunderbolt inventories matched their pre-sleep snapshots. Vulkan enumeration and compute dispatch passed before and after each sleep, and WD2 remained armed. The two wake windows logged 12 and 9 error-priority messages, respectively, all matching baseline signatures (DCP provider clock, PCI power state, MMC and HID).

Native arm64 warm build, uname -r = 7.3.0-m5-main-deep-b976c78a5b2d. The installed Image, DTB, initrd and all 1,775 module hashes matched the build manifests. Image.gz SHA-256 was 16268212679eca9a40f0644ee2cb712b423ed6892aced4176d7567d9ff91495e. MTE and SEP writes were enabled. Default kernel command line, with the root partition identifier redacted:

root=PARTUUID=<redacted> rw rootwait console=tty0 console=ttyDC0 earlycon=dockchannel,0x288e3c000 loglevel=7 nokaslr panic=0 pd_ignore_unused clk_ignore_unused systemd.mask=m5-expert-workspace-build.service systemd.mask=aurora-centauri.service appledrm.show_notch=1 user4k=on idle=nop arm64.nowfxt

Restored 7.3.0-m5-cdirect15 with cdirect13 as previous. All 253 ESP hashes matched the starting manifest, and Vulkan enumeration and compute dispatch passed after restoration.

The previous head failed the native G16 build at g16/fence.rs:591. Merging main at e8d93e48caa0 brought in #3111. The paired-display host regression passed on the merge. @satchlj, please re-approve this tested merge head.

@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) and removed 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 25, 2026
@DjDeveloperr
DjDeveloperr merged commit d7b0aec into main Nov 25, 2026
21 of 42 checks passed
@DjDeveloperr
DjDeveloperr deleted the fix/dcp-paired-adaptive-sync branch November 25, 2026 08:38
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) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants