Repository navigation
Apple drivers: KUnit coverage for RTKit, DART page tables, SMC children, DCP parsers, AVE and macaudio, plus 2 fixes - #2902
Conversation
ave_smalloc_get() rounds the size the firmware asks for on the SHAREDMALLOC ring up to whole granules with DIV_ROUND_UP() in 32 bits. A request of 0xfffff001..0xffffffff bytes wraps to 0 units, passes the "units > total" check and is answered with the first free block and a length of about 4 GiB, while nothing is reserved: the bound on the pool is defeated and the same block is lent again to the next request. Round in 64 bits so such a request needs more units than the pool has and is refused. Fixes: 01d0284 ("media: apple: ave: serve the 6070 firmware channels") Signed-off-by: Ryan Murray <[email protected]>
parse_nchans_mask() sets "1 << nchans" for every channel count in an AudioChannelLayoutElements array. The count comes from the firmware's dictionary as a 64-bit integer and is truncated to int on the way, so a count of 32 or more, or a negative one, is an undefined shift, and a count above U32_MAX aliases a small one (2^32 + 2 becomes 2). Pass counts outside the u32 range on as U32_MAX, which matches no channel sieve, and only set a mask bit for a count the mask has a bit for. Every count from 0 to 31 is handled as before. Fixes: 2c7e3ca ("drm: apple: Add sound mode parsing") Signed-off-by: Ryan Murray <[email protected]>
The RTKit IPC library and its crashlog parser have no tests. Add two suites, included from the drivers so they reach the static handlers: apple-rtkit (27 cases) feeds apple_rtkit_rx_dispatch() the messages a co-processor sends: HELLO version negotiation (accepted, capped, refused, client versions), the endpoint map (multipart, base offsets, EARLY_CRASHLOG and CoreAnalytics flags, retained state), IOP/AP power ACKs, idle notification, buffer requests, syslog, ioreport, kdebug, CoreAnalytics and crash reports, and checks the replies. A static stub on apple_rtkit_send_message() records them, after the crashed and running checks, so no mailbox is touched. apple-rtkit-crashlog (11 cases) checks that the parser follows the containers to the right log and never reads past a truncated or malformed crashlog: each log is placed flush against the end of a vzalloc'd area, so a read past it faults the case. Mutations caught: endpoint map base, crashlog size against the space left, the footer margin and the syslog index bound. Signed-off-by: Ryan Murray <[email protected]>
The Apple DART page table code has no tests; apple-dart-test.c maps a single page. Add the io-pgtable-dart suite (15 cases, 31 with parameters), included from io-pgtable-dart.c: - the table layout chosen for DART1 4K/16K and DART2 16K granules and input sizes (levels, bits per level, 1 or 4 TTBRs), and the refused configurations; - exact leaf and table PTE encodings for both formats, against hand-computed values; - map/unmap/iova_to_phys across leaf table ends, at the top of an L1 table, through four levels and across the TTBR split, with -EEXIST, -EINVAL and -ERANGE refusals that write nothing; - that teardown frees every table page (NR_IOMMU_PAGES back to the baseline). Mutations caught: the DART2 output address shift, the index mask, the DART2 read/write bits swapped and a table page leaked at teardown. Signed-off-by: Ryan Murray <[email protected]>
Add tests for the time and alarm arithmetic: the 48-bit tick offset with its sign extension and wrap, the 64-bit seconds offset and its rounding to the nearest second, and the PMU alarm's value, mask and control byte writes. A static stub replaces the SMC counter read and a RAM-backed NVMEM device holds the offset and alarm cells. The tick case expects set_time to return 0 on success, so it needs "rtc: macsmc: return 0 from a successful set_time" first; without it the case fails on the byte count (6). Signed-off-by: Ryan Murray <[email protected]>
Add tests for the gPxx key names of the pins, the output command words, the J700 pcIO and J713 radio lines with their remembered levels, the DT output and pcIO templates, the valid line mask and the pcIO output-command chip. A static stub replaces SMC writes. Not covered: lookups that go through apple_smc_get_key_by_index() and apple_smc_rw(), which have no stub reachable from outside the MFD. Signed-off-by: Ryan Murray <[email protected]>
Add tests for the MBSE key and the boot_stage and shutdown_flag writes before a restart or power off, the clearing of the boot error and panic counters, the refusal of atomic writes from a non-atomic SMC, and the ac_power_mode attribute's read-modify-write of the power-on policy byte. A static stub replaces SMC writes and a RAM-backed NVMEM device holds the PMU cells. Signed-off-by: Ryan Murray <[email protected]>
Add tests for the decoding of the SMC's power button and lid notifications and their handling as wake events while the system goes to sleep, including the lid-open check against MSLD and the settle time. A static stub replaces SMC reads. The tests report KEY_POWER and SW_LID through a real input device and touch global suspend state (pm_wakeup_clear(), pm_system_wakeup()), so they skip once the system is running and only run at boot, before user space. Not covered: the MSLD resync after resume and the dark-wake refusal in .prepare, which need apple_smc_key_exists() to succeed. Signed-off-by: Ryan Murray <[email protected]>
parse_display_metadata(), parse_panel_product_metadata(), parse_array_count(), parse_dptx_caps(), the system log mnits parsers, the timing colour and id catalogs, parse_panel_edid_data(), dcp_mode_default_above() and the audio element parsers had no tests. Add the apple-dcp-parser-bounds suite (22 cases). Besides the decoded values, every case feeds each strict prefix of a valid blob and expects a clean error, so a parser that reads past the end of a truncated blob fails. It also covers the framing and depth limits of the skipper, and channel layouts whose counts the u32 mask has no bit for (fixed earlier in this series): 32, 33, 34, 63, 64, -1, -31 and 2^32 + 1 must neither set a bit nor alias a small count, and a layout claiming 2^32 + 8 channels must not be taken for the 8-channel one. Mutations caught: the depth limit off by one, an id list bound off by one, raw EDID bytes beyond the length kept and a one-byte over-read in parse_bytes(). Signed-off-by: Ryan Murray <[email protected]>
Add two suites for the input the AVE driver takes from the firmware and from user space: apple-ave-ipc (20 cases), included from ave-ipc.c: hello words, channel tables with overlapping or out-of-range rings, ring index wrap, full and empty rings, command acks and messages outside the shared window, log lines and shared-memory requests, including the near-4 GiB requests fixed earlier in this series. apple-ave-writer (8 cases): the 6070 Start and Process builders refuse out-of-range session counts, unaligned buffers and short codec state before they write anything. The shared window and the mailbox are kernel memory; no firmware or encoder hardware is needed. Signed-off-by: Ryan Murray <[email protected]>
The "Speaker Volume Unlock" lease (macaudio_vlimit_update(), the slk_* control and the timeout work) has no direct tests. Add the apple-speaker-volume-unlock suite (9 cases) on the card of the pm-volumes tests: the speaker volumes leave the safe ceiling only while one process holds the lock control and every speaker volume, and only while it pings within SPEAKER_LOCK_TIMEOUT while speaker playback runs; a missed ping or a volume with another owner relocks them, and the lease is kept while idle. Mutations caught: mixed volume owners no longer relock, and the timeout work keeping the lease. Signed-off-by: Ryan Murray <[email protected]>
dcp_cec_test_setup() allocates the fake apple_dcp and AFK endpoint with kunit_kzalloc() after kunit_device_register(). KUnit releases resources in reverse order, so both are freed before the device is unregistered, and the device's devres action dcp_cec_devm_release() then reads them: KASAN reports a use-after-free in dcp_cec_unregister() and UBSAN an invalid bool load in afk_service_retry() for the apple-dcp-cec-adap cases. Allocate the fakes before the device. Fixes: 7577337 ("drm/apple: add native HDMI-CEC and 2 ms IRQ_HPD pulse tracking") Signed-off-by: Ryan Murray <[email protected]>
|
Non-author review of 20783b6. I covered the two fixes and every non-test line; I skimmed the test files and didn't re-run them. Verdict: no blocker. Fixes
Non-test changes
Points
|
|
Thanks @RyanTheTide.
Assisted-by: LLM (Claude:Opus 5.5) |
There was a problem hiding this comment.
Adversarial pre-PR checklist (§1–§6) review at 20783b6037135144085d525726ba868b624c8c1e (CI: 6/7 green, host-tests FAILED — job 137427336617).
Verdict: REQUEST CHANGES — the two driver fixes (bc2883e5 AVE smalloc 64-bit rounding and 7a7a7d40 DCP nchans bounds/clamp), the existing cec_adap_test.c KASAN/UBSAN lifetime fix (20783b60), the new KUnit suites, and §4/§6 hygiene are solid, but CI host-tests is red due to an #if IS_ENABLED(...) guard in drivers/soc/apple/rtkit-crashlog.c, and the macsmc-rtc tick test depends on unmerged PR #2616.
Blocking findings
-
CI
host-testsfailure (drivers/soc/apple/rtkit-crashlog.c:496):tools/asahi/rtkit-crashlog-tests.pycompilesdrivers/soc/apple/rtkit-crashlog.cdirectly on the host with clang against its minimal userspace stub header (without<linux/kconfig.h>), whereIS_ENABLED()is not defined:rtkit-crashlog.c:496:5: error: function-like macro 'IS_ENABLED' is not defined 496 | #if IS_ENABLED(CONFIG_APPLE_RTKIT_KUNIT_TEST)- Since
CONFIG_APPLE_RTKIT_KUNIT_TESTisbool(never=m), switching line 496 to#ifdef CONFIG_APPLE_RTKIT_KUNIT_TESTfixeshost-testswithout modifying the host test harness.
-
Unmerged merge-order prerequisite (
#2616):drivers/rtc/rtc-macsmc-test.c:289(macsmc_rtc_test_tick_set) and:308(macsmc_rtc_test_tick_negative) assertmacsmc_rtc_set_time() == 0, which currently fails onintegration/aurora(returns6) because #2616 (rtc: macsmc: return 0 from a successful set_time, head078f441ec9) is stillOPEN.- Do not merge #2902 before #2616 lands (sequence strictly
#2616->#2902inMERGETRAIN-LINUX4).
Verified good
bc2883e5(ave-ipc.c:393):DIV_ROUND_UP_ULL(bytes, AVE_SMALLOC_GRANULE)cleanly prevents 32-bit wrap to0units for0xfffff001..0xfffffffffirmware requests; max result0x100000fits inu32and is rejected byunits > total.7a7a7d40(parser.c:2194,2217): clamping out-of-ranges64channel counts toU32_MAXand guardingBIT(nchans)withnchans < BITS_PER_TYPE(*mask)eliminates UB shifts andu32truncation aliasing without affecting valid0..31counts.20783b60(cec_adap_test.c:165): allocating fakedcp/epbeforekunit_device_register()fixes the LIFO teardown UAF cleanly (test-only).- All new KUnit Kconfig symbols are
bool, depend onKUNIT=yand<driver>=y, and default toKUNIT_ALL_TESTS, so fleet builds (CONFIG_KUNIT=m) are unaffected.
§1–§6 Checklist Summary
- §1 No model gating: Pass (no chip/board/firmware gates added).
- §2 Production-ready: Blocked —
rtkit-crashlog.c:496breaks host-tests CI; merge-order dependency on open PR #2616. - §3 Safety: Pass (two defensive firmware-input bounds fixes + test-only suites).
- §4 Clean-room & attribution: Pass (all 12 commits carry human author/committer + human
Signed-off-by:only, zero AI trailers in commits,Assisted-by:in PR body). - §5 Evidence: Pass for scope (host/KUnit-only tests + malformed-firmware-input refusals; strong mutant negative controls and KASAN/UBSAN/lockdep runs documented).
- §6 Naming: Pass.
|
Review at 20783b6. Second pass, non-author. I read every non-test line and all the test files against the driver code. I couldn't run KUnit: every buildslot was held for more than 30 minutes. The configs are saved for a rerun (16K + KASAN/UBSAN/lockdep, and a 4K variant). The two fixes are right. In
Verdict: nits. Nothing blocks. Please fix the count in point 1 before the merge train picks it up. |
RyanTheTide
left a comment
There was a problem hiding this comment.
Independent source review at 20783b603713. The RTC fixture assumes the normalized set_time return from #2616 and will otherwise leave the new suite red. Land that dependency first or split the RTC test. Keep the DCP and AVE parser tests independent, then rerun all new suites on the actual integration tip.
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at 20783b603713
Blockers:
- CI is red:
tools/asahi/rtkit-crashlog-tests.pycompilesdrivers/soc/apple/rtkit-crashlog.con the host without<linux/kconfig.h>, so the new#if IS_ENABLED(…)at:496doesn't build there. Fix: give the host stub anIS_ENABLED, or test the config another way.
Rows before merging: the AVE and DCP parser fixes change built code, and the DCP parser runs on every Mac, so at the new head it needs one boot on each of two generations with the display up and an AVE encode working.
Checked: no Apple material, no gates. The two driver fixes are right (AVE smalloc 64-bit rounding, DCP nchans clamp at parser.c:2193), and the new KUnit suites only expose internals.
Superseded by the review at 20783b6
Preserve the AVE command tests in the driver object and include the new writer suite under its test option. The RTC set_time prerequisite is already on main. Signed-off-by: Ryan Murray <[email protected]>
The standalone crashlog tests compile the production parser without kernel Kconfig helpers. Guard the included test by its boolean Kconfig symbol directly. Signed-off-by: Ryan Murray <[email protected]>
DjDeveloperr
left a comment
There was a problem hiding this comment.
Code approved at ffc9e90a9513. The crashlog test hook now uses a config guard that the standalone C harness can compile. The RTKit fixture passed all eight checks, and hosted host tests passed. Before merging the AVE and DCP runtime changes, record a working encode and display on two generations.
Superseded by the review at ffc9e90
|
ffc9e90 J616s (T6040, M4 Pro) + J700 (Neo, T8140) PASS (2 generations): guarded one-shot combined batch (427b2c2dc67c over main 8f99a85, 0 merge-tree diffs on 38 changed files, default cmdline): J616s (boot c03a4ac6-7a26-444a-b5d3-cddf0c5d9bdc) eDP-1 connected, Apple AVE H.264 60f 640x360 (906 KB, 0.070 s) + HEVC 60f (917 KB, 0.083 s) + post-2x-rtc1-s2idle H.264 30f (0.048 s), 0 AVE/DART/GPU errors, 0 failed units, Enforcing, 0 new AVC, 0 new kernel errors; J700 (boot 3f98d23f-1816-4823-8fa0-0857950bb565) eDP-1 + DP-1 connected, Apple AVE H.264 60f (906 KB, 0.089 s) + HEVC 60f (917 KB, 0.111 s), 0 AVE/DART/GPU errors, 0 failed units, Enforcing, 0 new AVC, 0 new kernel errors; stock 7.3.0-aurora-fleet89 restored on both. |
What: Add KUnit coverage for Apple RTKit, DART page tables, SMC children, DCP parsers, AVE and macaudio. Validate DCP channel counts before building the layout mask, and round AVE shared-memory requests without arithmetic overflow.
Tested: At
ffc9e90a9513, the standalone RTKit crashlog suite passed 8/8 including seven negative controls, the Apple DCP host group passed, and four arm64 LLVM objects compiled with the relevant KUnit options enabled. The original arm64 QEMU results are below.Risk: two-way door · Macs with Apple DCP or AVE. The other changes add test coverage.
Not yet: Hosted CI on the forwarded head, normal DCP/AVE operation on a target Mac, and a same-path regression Mac.
Details
Evidence
The earlier arm64 QEMU run recorded these positive cases. Each group was also checked against a negative control.
The combined sanitizer build ran 836 tests. All new suites passed with KASAN, UBSAN, lockdep and debugobjects enabled. Two existing CEC fixture failures passed after the lifetime correction (10/10). The unrelated
apple-dcpaud-no-siosuite reached a different error code on that earlier configuration.At
ffc9e90a9513, compiledrtkit-crashlog.o,rtc-macsmc.o,ave-ipc.oandave-writer-test.owith LLVM for arm64 and the corresponding built-in test options.