Repository navigation
Apple drivers: KUnit coverage for RTKit, DART page tables, SMC children, DCP parsers, AVE and macaudio, plus 2 fixes - #2902
RyanTheTide wants to merge 12 commits into
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 <ryan@aurorasilicon.org>
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 <ryan@aurorasilicon.org>
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 <ryan@aurorasilicon.org>
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 <ryan@aurorasilicon.org>
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 <ryan@aurorasilicon.org>
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 <ryan@aurorasilicon.org>
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 <ryan@aurorasilicon.org>
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 <ryan@aurorasilicon.org>
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 <ryan@aurorasilicon.org>
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 <ryan@aurorasilicon.org>
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 <ryan@aurorasilicon.org>
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 <ryan@aurorasilicon.org>
|
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) |
DjDeveloperr
left a comment
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.
Assisted-by: LLM (Gemini 4 Neon)
|
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.
Problem
Several Apple drivers have no KUnit coverage at all: the RTKit IPC library and its crashlog parser, the DART page table code, the SMC RTC/GPIO/reboot/input children, most DCP dictionary parsers, the AVE firmware/userspace input paths and the macaudio "Speaker Volume Unlock" lease. Writing the tests turned up two real bugs.
Change
Two driver fixes, each with a
Fixes:tag, then nine test-only commits, then one fix to an existing test. Each commit is one driver and can be reviewed alone.DIV_ROUND_UPin u32 turns a firmware SHAREDMALLOC request of 0xfffff001..0xffffffff bytes into 0 units. The request passes the bound and is answered with a ~4 GiB block while nothing is reserved. Now rounded in 64 bits.1 << nchanswith a firmware count ≥ 32 or negative is UB, and counts above U32_MAX aliased small ones. Such counts now match no sieve. Counts 0..31 behave as before.apple-rtkit(27 cases: HELLO, epmap, power ACKs, buffers, syslog/ioreport/kdebug/CoreAnalytics/crash) andapple-rtkit-crashlog(11 cases, logs flush against a vmalloc guard page so any over-read faults).io-pgtable-dart(15 cases / 31 with params): layouts, exact PTE encodings for DART1/DART2, map/unmap/iova_to_phys across tables, levels and TTBRs, refusals, teardown frees every page.apple-dcp-parser-bounds(22 cases): every strict prefix of a valid blob must fail cleanly, plus the channel-count cases.apple-ave-ipc(20) andapple-ave-writer(8).apple-speaker-volume-unlock(9 cases) on the pm-volumes test card. Nothing is played.apple-dcp-cec-adapcases freed their fake DCP and endpoint before the device's devres used them. KASAN (use-after-free indcp_cec_unregister()) and UBSAN (invalid bool inafk_service_retry()) flagged it in the debug run below. Only the test was wrong:dcp_cec_unregister()and the driver are unchanged.Test hooks are
#include "...-test.c"underIS_ENABLED(CONFIG_..._KUNIT_TEST)andKUNIT_STATIC_STUB_REDIRECT, the same pattern as apple-dart. They compile to nothing when the test symbol is off. Every test symbol isbool, depends onKUNIT=yand the driver=y, and defaults toKUNIT_ALL_TESTS. The changes add no driver behaviour, gates, parameters or constants beyond the two fixes.Dependency: the RTC tick case expects
set_timeto return 0. That fix is #2616 (open, CI green), so it is not duplicated here. Until #2616 lands,macsmc-rtchas one failing case.Testing
arm64 QEMU,
kunit.py --arch=arm64, on integration/aurora 110861f. The branch is rebased onto e892113; the 31 commits in between touch only soc/apple clpc/display-gate. Every suite has a negative control: a mutation of the driver, or the unfixed driver code, that the new tests must catch.checkpatch
--strict: 0 errors. The remaining warnings are the MAINTAINERS notes for new files and the filename comment in the.kunitconfigfiles, which matches the existing ones.Also run:
.kunitconfig: each new file alone (no lane fragment, so 4K pages for io-pgtable-dart). Results: rtkit 38/38, io-pgtable-dart 31/31, rtc 16/16, gpio 11/11, reboot 13/13, input 12/12.apple-dcp-cec-adapcases, fixed by the last commit (10/10 clean afterwards under the same options);apple-dcpaud-no-sio, an existing suite this PR does not touch (expects -ENXIO, gets -ENODEV in this config).Still to run
KUNIT_ALL_TESTS.Details for reviewers
boot_stage = INITIALIZED, so it tests the atomic-mode check itself.system_state == SYSTEM_RUNNING(boot-time only).__forcecasts on the fake shmem.1 << get_order(granule)pages.APPLE_RTKIT_NEEDS_COREANALYTICS, as the PMP does. soc: apple: rtkit: allocate endpoint 7 buffers only for clients that ask for them #2776 serves endpoint 7 only for such clients.software_node_notify_remove(). The node is now registered before the test device and unregistered after it is gone.software_node_notify_remove()readsswnode->managedafterswnode_put(), so the read is a use-after-free whenever that put is the last one. For a managed node it also drops the managed reference once per device that carries the node, not just for its owner. Any driver that registers a gpiochip (or another child that inherits the fwnode) on a device with a software node can reach this on unbind. It deserves its own fix.apple_smc_get_key_by_index()/apple_smc_key_exists()to succeed, and no stub reaches them from outside the MFD.traces/ci/20261123-kunit-apple/on the lab store.Assisted-by: LLM (Claude:Opus 5.5)