Skip to content

soc: apple: rtkit, drm/apple: iomfb_m4: expose read-only dcp_ioreport debugfs - #4175

Open
IronsideXXVI wants to merge 2 commits into
aurora-silicon:mainfrom
IronsideXXVI:j604/dcp-m4-ioreport-debugfs
Open

IronsideXXVI wants to merge 2 commits into
aurora-silicon:mainfrom
IronsideXXVI:j604/dcp-m4-ioreport-debugfs

Conversation

@IronsideXXVI

Copy link
Copy Markdown
Contributor

What: Expose on-demand, read-only DCP hardware scanout and swap counters from the RTKit IOReport shared-memory buffer (APPLE_RTKIT_EP_IOREPORT = 4) under each M4 connector debugfs directory as dcp_ioreport (0444):

  • Add apple_rtkit_ioreport_size() and apple_rtkit_ioreport_snapshot() to drivers/soc/apple/rtkit.c (serialized by ioreport_lock, with ioreport_completion completed on APPLE_RTKIT_IOREPORT_SAMPLE (0x4) replies). Sample requests are issued strictly on demand when userspace reads debugfs, leaving zero background polling overhead when unread.
  • Add pure-logic IORb shared-memory buffer parser drivers/gpu/drm/apple/dcp-m4-ioreport.h decoding display stats (IOMFBFCC frame_count, IOMFBBLF bl_frame_count), scanout duration expirations (IOMFBDUR duration_exp), and the 25-bucket scanout/swap subframe histograms (IOMFBSWP / IOMFBUSR) with strict header, type, element-count, and payload bounds checks.
  • Wire read-only dcp_ioreport (0444) into iomfb_m4_debugfs_init() (guarded by dcp->lock and returning -EAGAIN whenever the display is gated, off, powered off, or in error).
  • Add KUnit coverage in drivers/gpu/drm/apple/dcp-m4-ioreport-test.c (CONFIG_DRM_APPLE_M4_IOREPORT_KUNIT_TEST, apple-dcp-m4-ioreport).

Tested:

  • Offline at exact head 7dba9f2b4517 on origin/main (62c60d13d4d8, 0 merge-tree conflicts):
    • scripts/checkpatch.pl --strict --ignore FILE_PATH_CHANGES --git origin/main..HEAD: 0 errors, 0 warnings, 0 checks (531 lines checked; MAINTAINERS already covers drivers/gpu/drm/apple/).
    • Clang 18.1.8 ARM64 (aurora_defconfig) W=1 KCFLAGS="-Werror": drivers/soc/apple/rtkit.o (640800 bytes) and drivers/gpu/drm/apple/iomfb_m4.o (1054808 bytes), 0 warnings, 0 errors.
    • QEMU ARM64 KUnit (kunit.py run --arch=arm64 "apple-dcp-m4-ioreport*"): 2/2 PASSED (dcp_m4_ioreport_parse_valid, dcp_m4_ioreport_rejects_malformed), plus dcp-m4-ioreport-test.o verified under W=1 KCFLAGS="-Werror".
    • 0 module_param additions.
  • Live Apple M4 MacBook Pro 14" (J604, T8132) hardware validation on linux-aurora-next 7.3.0.aurora1-1.1692 (boot 00c9b9bf) and primary release ship linux-aurora 7.3.0.aurora1-1.1694 (957908b7bd99, boot 29379f09):
    • 58 live hardware IOReport channels parsed cleanly from eDP-1/dcp_ioreport with 0 DCP crashes and 0 kernel faults.
    • Active 120 Hz scanout reports 120.000 Hz; static idle (2 x 15.001 s windows) reports 3600 240 Hz VRR clock ticks (239.986 Hz, 4.167 ms), duration_exp=360, scanout_sum=360 with sf9=360 (100% 10-subframe bucket = 23.998 Hz panel refresh, matching native macOS 24.049 Hz idle floor) and swaps=0.
    • Integrated release ship 1.1694 (boot 29379f09) passed all boot, ESP, thermal (34.0 C, PMPEV=0), display/GPU (1640.8 fps), and runtime health gates with 0 failed units and 0 faults.

Risk: two-way door · Apple Silicon RTKit + M4 DCP (8 files, +460 / -1 lines). Read-only 0444 debugfs file and on-demand RTKit helper with zero runtime work unless explicitly read. A plain revert removes the debugfs entry and helper cleanly.

Not yet:

  • Standalone verification on non-T8132 M4/M5 DCP firmware variants (T6040/T6041/T8152) or external DCP connectors.
  • Standalone hardware read at exact origin/main head 7dba9f2b4517 (hardware validation ran on integrated 1.1692 and primary ship 1.1694).
Details and verification

Scope (j604/dcp-m4-ioreport-debugfs, head 7dba9f2b4517 on main 62c60d13d4d8)

  • drivers/gpu/drm/Makefile (+1)
  • drivers/gpu/drm/apple/Kconfig.tests (+10)
  • drivers/gpu/drm/apple/dcp-m4-ioreport-test.c (+140, new)
  • drivers/gpu/drm/apple/dcp-m4-ioreport.h (+150, new)
  • drivers/gpu/drm/apple/iomfb_m4.c (+60)
  • drivers/soc/apple/rtkit-internal.h (+5)
  • drivers/soc/apple/rtkit.c (+80 / -1)
  • include/linux/soc/apple/rtkit.h (+14)
  • Sign-off: Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
  • scripts/checkpatch.pl --strict --ignore FILE_PATH_CHANGES --git origin/main..HEAD: 0 errors, 0 warnings, 0 checks (531 lines checked).
  • git merge-tree --write-tree origin/main HEAD: clean (07d0e7ebf16a).
  • Clang 18.1.8 ARM64 (aurora_defconfig) W=1 KCFLAGS="-Werror": drivers/soc/apple/rtkit.o (640800 bytes), drivers/gpu/drm/apple/iomfb_m4.o (1054808 bytes), 0 warnings.
  • QEMU ARM64 KUnit (apple-dcp-m4-ioreport*): 2/2 PASSED (dcp_m4_ioreport_parse_valid, dcp_m4_ioreport_rejects_malformed).
  • Live J604 (1.1692 boot 00c9b9bf / 1.1694 boot 29379f09): 58 channels, active 120.000 Hz, idle 23.998 Hz (sf9=360/360 = 100%, matching native macOS 24.049 Hz), 0 DCP crashes / 0 faults.

… debugfs

Expose on-demand, read-only DCP hardware scanout and swap counters from
the RTKit IOReport shared-memory buffer (APPLE_RTKIT_EP_IOREPORT = 4)
under each M4 connector debugfs directory as dcp_ioreport (0444).

Add apple_rtkit_ioreport_size() and apple_rtkit_ioreport_snapshot() to
drivers/soc/apple/rtkit.c. The helper only sends the IOReport sample
request (type 0x4) and waits for its completion when explicitly read by
userspace, keeping zero background polling overhead when unused.

Parse the firmware IORb shared-memory buffer in dcp-m4-ioreport.h for
display stats (frame_count, bl_frame_count), scanout stats
(duration_exp), and the 25-bucket scanout/swap subframe histograms
(IOMFBSWP / IOMFBUSR), and add KUnit coverage in dcp-m4-ioreport-test.c.

Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
@IronsideXXVI
IronsideXXVI requested review from a team as code owners December 3, 2026 09:41
@github-actions github-actions Bot added area:display Area from CODEOWNERS (bot) area:platform Area from CODEOWNERS (bot) blast:m4 Macs affected, from Merge risk (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 Dec 3, 2026
@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Merge readiness at 4d5e9c73: ready to merge

Check Detail
CI at head ok 4 checks passed
Review ok approved by RyanTheTide
Requested changes ok none
Hardware row at head ok comment at 4d5e9c73
Conflicts ok none
PR text ok Risk: two-way · Apple Silicon RTKit + M4 DCP (8 files, +460 / -1 lines). Read-only 0444 debugfs file and on-demand RTKit helper with zero runtime work unless explicitly read. A plain revert removes the debugfs entry and helper cleanly.

Areas: area:display, area:platform
Merge: gh pr merge 4175 --merge (Owners and Core through the bypass: add --admin).

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

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

A late reply can complete the next debugfs read with stale data. If request A times out, the function releases the lock and leaves A in flight. Request B reinitializes the same completion and sends a sample. A’s late reply then completes B before B’s own sample arrives. The reply has no request identifier and the mutex only serializes callers. Keep a timed-out request pending until it is drained, or otherwise prevent a new request from accepting its reply.

APPLE_RTKIT_IOREPORT_SAMPLE replies carry no request identifier, so
releasing ioreport_lock after a timeout while the firmware request is
still in flight allowed a subsequent apple_rtkit_ioreport_snapshot()
call to reinitialize ioreport_completion and complete early with stale
data from the earlier timed-out request.

Track the single in-flight IOReport sample state (idle, waiting, or
timed out) alongside ioreport_completion under a spinlock:

- On timeout, transition waiting -> timed_out unless the reply already
  completed in the narrow post-timeout race window.
- Reject new snapshot callers with -EBUSY without sending another
  SAMPLE message while a timed-out request is still pending.
- Drain a late reply received in timed_out back to idle without
  signaling ioreport_completion, and ignore unsolicited replies in idle.
- Reset IOReport state and completion under ioreport_lock during
  apple_rtkit_reset_session() so a firmware reset clears any pending
  request cleanly.

Add apple-rtkit KUnit coverage for normal snapshots, late-reply
rejection until drained, unsolicited replies, and send failures.

Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
@IronsideXXVI

Copy link
Copy Markdown
Contributor Author

Thanks for catching that, @RyanTheTide.

Addressed in 4d5e9c737d96:

  • Added an explicit IOReport request state (IDLE / WAITING / TIMED_OUT) protected alongside ioreport_completion by ioreport_state_lock.
  • If apple_rtkit_ioreport_snapshot() times out before a reply arrives, the state transitions from WAITING to TIMED_OUT (if the reply won the narrow post-timeout race, the completion is consumed cleanly).
  • While a timed-out request is still pending, new snapshot callers return -EBUSY without reinitializing the completion or sending another APPLE_RTKIT_IOREPORT_SAMPLE message.
  • When the late reply arrives in apple_rtkit_ioreport_rx(), TIMED_OUT drains back to IDLE without signaling ioreport_completion; unsolicited replies in IDLE are also ignored.
  • apple_rtkit_reset_session() wakes any waiter and resets the IOReport state/completion under ioreport_lock so a firmware reset clears any pending timed-out request.

Verified on 4d5e9c737d96:

  • QEMU ARM64 KUnit (LLVM=1): apple-dcp-m4-ioreport* 2/2 PASS, apple-rtkit* 41/41 PASS (including 3 new rtk_test_ioreport_* tests covering normal snapshot, late-reply rejection until drained, unsolicited reply, and send failure).
  • Clang ARM64 LLVM=1 W=1 KCFLAGS="-Werror": 0 warnings on rtkit.o (both CONFIG_APPLE_RTKIT_KUNIT_TEST=y and =n), iomfb_m4.o, and dcp-m4-ioreport-test.o.
  • scripts/checkpatch.pl --strict --git HEAD~1..HEAD: 0 errors, 0 warnings, 0 checks.

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

The timeout case from the previous review is fixed. A timed-out request keeps the slot until its reply drains, so the next reader cannot send a request that the old reply could complete. Checked the timeout/receive boundary and the KUnit case that verifies the next send is held until the drain. Exact-head build, KUnit execution and hardware read remain tracked separately.

@github-actions github-actions Bot removed the needs-review No approving review from Core or Omarchy Mac yet (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.

Offline review and test at head 4d5e9c737d96d2437e65e80b1ff39bd1acda3deb, merged on main a05d99c9dbc2 (clean merge, tree a64188677e4e). Not merged: it still owes a hardware read at this head, which we are arranging on J773g (HDMI) and J713.

Results

  • KUnit on UML (x86_64, KASAN + PROVE_LOCKING + DEBUG_ATOMIC_SLEEP, kunit.filter_glob='apple-rtkit*' and 'apple-dcp-m4-ioreport*'): apple-rtkit 30/30 (with the 3 new ioreport cases), apple-rtkit-crashlog 11/11, apple-dcp-m4-ioreport 2/2. No splat. The only local edit was default y on UML_DMA_EMULATION. KUnit was not run on arm64.
  • arm64 objects, clang 23.1.3, LLVM=1 W=1 KCFLAGS=-Werror, 16K pages: drivers/soc/apple/rtkit.o, drivers/gpu/drm/apple/iomfb_m4.o, drivers/gpu/drm/apple/connector.o, dcp-m4-ioreport-test.o: no warnings. (T8132 display depends on the Rust PMP driver; that one Kconfig line was dropped locally to build without Rust.)
  • checkpatch.pl --strict --ignore FILE_PATH_CHANGES: 0 errors, 0 warnings, 0 checks (829 lines).

rtkit.c, for Macs that never read the file

  • Receive path: one change. An unasked-for 0x4 message used to print a rate-limited "Unknown ioreport message" and is now dropped. 0x8 and 0xc are still acknowledged, the buffer request handling is untouched, and 0x4 still gets no reply. The state lock is a spinlock taken with irqsave, so the early receive path is fine.
  • apple_rtkit_reset_session(): takes the new mutex and spinlock with no one else holding them. It already sleeps there (flush_workqueue, cancel_delayed_work_sync), so the mutex is fine for ANS reset and the CIO cold restart. The ioreport buffer is now freed first and under ioreport_lock, so shmem_destroy runs under that mutex. No consumer takes a lock there that is held around a snapshot (M4's shmem_destroy is empty), so no inversion.
  • Buffer ownership: apple_rtkit_memcpy() already covers DMA buffers, iomem buffers (the M4 borrowed case) and needs_dma_sync.
  • Timeout race: I checked reply vs timeout, late reply, send error and reset during a wait. Reset moves WAITING to IDLE and completes, so a waiter wakes and returns -EAGAIN because shutting_down is set. A reader that gets past the checks just before the reset holds ioreport_lock for up to 1 s, and the reset waits for it. That only happens with a reader present.
  • M4: a reader holds dcp->lock while it waits, and no work on the RTKit queue takes dcp->lock, so the reply can arrive. With silent firmware one read can hold off a swap for 1 s, then later reads get -EBUSY.

Two things worth a small fix (not blocking, your call)

  1. The M4 DCP never goes through apple_rtkit_reset_session() (only apple_rtkit_wake_retained()), so a sample lost across a display power-down leaves the file at -EBUSY until reboot. The CPU is stopped and RX drained there, so the pending slot can be dropped in apple_rtkit_wake_retained():
+	/* The CPU was stopped with RX drained: an unanswered sample is not owed any more. */
+	spin_lock_irqsave(&rtk->ioreport_state_lock, flags);
+	if (rtk->ioreport_state == APPLE_RTKIT_IOREPORT_TIMED_OUT)
+		rtk->ioreport_state = APPLE_RTKIT_IOREPORT_IDLE;
+	spin_unlock_irqrestore(&rtk->ioreport_state_lock, flags);
 	reinit_completion(&rtk->epmap_completion);

(with unsigned long flags; added). apple_rtkit_warm_restart() has the same gap for other users.
2. has_frame_count, has_bl_frame_count and has_duration_exp are filled but not used: a channel missing from the buffer prints 0, which reads as a real counter. For example if (sample.has_frame_count) seq_printf(...), the same for the other two.

@DjDeveloperr

Copy link
Copy Markdown
Contributor

The remaining row at 4d5e9c737d96 is a J604 run by IronsideXXVI reading dcp_ioreport during active and idle scanout, with live counters and zero DCP/RTKit errors.

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-hw-row No hardware row at the PR head (bot) labels 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:platform Area from CODEOWNERS (bot) blast:m4 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants