Repository navigation
Apple drivers: bound firmware-sized work and fix teardown and restore lifetimes (admac, macsmc, aop_motion, aop_devmotion, aop_lpai, afk) - #2911
Conversation
…inter admac_device_config() saves the whole dma_slave_config so that a channel can be set up again after a system sleep took its registers. The copy includes peripheral_config, a pointer to memory the client only guarantees for the duration of the call: the AOP audio driver passes the address of a local variable. admac_restore_chan() then calls admac_device_config() on the saved copy and reads the realign frame size through that pointer again, long after the client returned. Split the register programming out into admac_program_config(), which the restore calls on the saved copy. admac_device_config() takes the frame size from the client's config once (it was assigned twice) and stores the copy with peripheral_config cleared, so a restore keeps the frame size the client configured and never touches the client's memory. Add a KUnit case that configures a capture channel, overwrites the client's frame size, marks the channel lost and restores it. Fixes: d9b438c ("arm64: apple: support coordinated suspend-to-RAM on T8140") Signed-off-by: Ryan Murray <[email protected]>
apple_smc_probe() initialised init_done and cmd_done only after the RTKit was initialised, woken and the SMC endpoint started. The receive callback is live from the RTKit's initialisation on, and it completes init_done for the first message on the SMC endpoint, so a message that arrives before the probe got that far completes a completion that is still all zeroes. Initialise both completions together with the mutex and the spinlock, before the RTKit is initialised, in a helper, apple_smc_init_state(). Add a KUnit case that takes the first message with only that state set up. Fixes: e038d98 ("mfd: Add Apple Silicon System Management Controller") Signed-off-by: Ryan Murray <[email protected]>
The triggered buffer and the trigger of each sensor are resources of the platform device, and the release of the triggered buffer reads the poll function and the buffer out of the IIO device. The IIO device, though, was freed when the driver's data was dropped, which the driver core does before it releases the resources of the device, both on unbind and when a probe fails after the buffer is set up. The buffer release then read an IIO device that was already freed. Hand the IIO device, its private data and the channel table it points to to the resources of the platform device, right after the allocation and before the trigger and the buffer are set up. Resources are released in reverse order, so the buffer and the trigger now go first and the IIO device last. Dropping the driver's data only unregisters the device. MotionIio::new() takes the bound device instead of the platform device, so that a KUnit test can run it on a faux device: the test checks that the private data of the IIO device is still there when the release of the device's resources begins and gone when it has ended. Signed-off-by: Ryan Murray <[email protected]>
A scan is a quaternion and a timestamp: 24 bytes, which the 16-byte alignment of the quaternion rounds up to 32. The IIO core computes the same 32 bytes and copies them all into the buffer, but the last eight were padding of the scan structure, which nothing wrote. Make the tail a field and build the scan in one place that zeroes it, as the accelerometer, gyroscope and temperature drivers already do for their scans. Add a KUnit test that derives the scan size from the channels as the IIO core does, compares it with the structure, and checks that every byte after the timestamp of a freshly built scan is zero. Signed-off-by: Ryan Murray <[email protected]>
…format The low-power microphone takes its stream format and, on T6041, its ring geometry from properties of the AOP's audio service. The PCM limits are computed from the rate: the shortest period is PERIOD_MS_MIN of frames, and the most periods is the buffer limit divided by it. A rate that gives no whole frame in that time made the shortest period zero and the division one by zero, and a rate large enough overflowed the product; both stop the kernel when the PCM is opened. Compute the shortest period with checked arithmetic when the format is read, and refuse a format whose shortest period is empty or longer than the longest period the PCM offers. Such a format leaves the PCM out, as the other unusable formats do. The host ring was sized as frames times frame bytes with only a 4 GiB limit, and was allocated before the binding. The ring only feeds the ALSA buffer, so a ring of more than twice that buffer's limit serves no stream the PCM can offer; the firmware's own geometry (four seconds of its format) lies between one and two buffers. Refuse a larger ring before anything is allocated, together with the report-interval checks that were already there, in one helper. Add KUnit cases for formats with and without a valid period range and for ring geometries on both sides of the limit. Signed-off-by: Ryan Murray <[email protected]>
Every compact service call from the firmware gets a reply buffer of the call's size, which is queued on the endpoint's ordered transmit queue. A reply can wait there for transmit ring space for up to five seconds while the receive worker keeps taking calls, and nothing limits how many replies, or how many bytes of them, are queued in the meantime. A firmware that keeps calling while it does not drain its ring makes the queue grow without bound. Count the payload bytes of the replies that are queued and not yet sent, under the endpoint lock, and take a call only while its reply fits. The room is AFK_COMPACT_MESSAGE_MAX, the largest single message, which is also what the receive side holds in assembly: one call of any valid size is always taken when nothing is queued, and the short calls the display services receive stay far below it. A call beyond that is dropped with a rate-limited warning before its buffer is allocated and before the service handler runs, so it is not counted as a pending job either. The reply worker returns the room once the send has finished or failed, which covers the queue flush at teardown as well. Add a KUnit case that stalls the transmit queue, feeds calls until the room is used up and checks that later calls are dropped until the queue has drained. Signed-off-by: Ryan Murray <[email protected]>
|
Review at 4bbeec8. All six fixes are real and correctly ordered. I checked the admac restore, the macsmc completion init, and the aop_motion devres order against device_unbind_cleanup(): drvdata is dropped before devres_release_all(), and iio_triggered_buffer_cleanup() reads indio_dev. Findings:
Rows owed at this head (none posted): an s2r speaker-sense capture with V/I aligned on one realign_sense board, plus s2r MCA playback on J616s or M2; boot with SMC sensors/fans up on J616s and on one saved_enabled board (J714s or J813); aop_motion unbind/rebind with KASAN, plus a devmotion buffered read, on J616s, J713 and M1 Pro; an lpai microphone open with the ring geometry logged on J616s and J713; an external display with hotplug on J713 and on a desktop 26.x DCP. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Formal adversarial §1–§6 pre-PR checklist review at 4bbeec89c25598093770f7e9e0d6177c96f10892 (REQUEST_CHANGES — 2 code blockers in afk.c and aop_lpai.rs, 0 hardware rows run across 5 subsystems, and incomplete CI coverage).
Checklist Summary
- §1 (No model gating): Blocked —
aop_lpai.rshardcodesRING_BYTES_MAX = 2 * BUFFER_BYTES_MAX(1 MiB) tuned to a single 16 kHz / 3-ch observation (Blocker #2). - §2 (Production-ready, no hacks): Blocked —
afk.cdrops compact calls without poisoningv27_sleep_transport(Blocker #1). - §3 (Safety): Mixed —
apple-admac.c(admac_program_configsplit + clearingperipheral_configin saved copy),macsmc.c(initializinginit_done/cmd_donebefore RTKit init),aop_motion.rs(IioAllocdevres ordering before trigger/buffer), andaop_devmotion.rs(explicit zeroedpad: u64tail inScan) are all sound on code inspection;afk.candaop_lpai.rshave blockers below. - §4 (Clean-room & attribution): Pass — all 6 commits carry human author/committer (
Ryan Murray <[email protected]>) and humanSigned-off-by:only (zero AI trailers in commits); PR body includesAssisted-by:. - §5 (Evidence): Blocked — 0 hardware rows run across 5 subsystems (
dmaengine,mfd,iio,ASoC,drm), and GitHub CI only reportshost-tests(SUCCESS) with nokunit,rust-build,source, orDWC3/ATCchecks recorded. - §6 (Naming): Pass.
Blockers
- §2 / §3 (
drivers/gpu/drm/apple/afk.c:1196-1206): Dropping a compact service call leavesv27_sleep_transportunpoisoned:- In
afk_compact_reply_worker()(afk.c:1155-1158), a failed compact reply send onv27_sleep_transportsetsr->ep->sleep_poisoned = trueunderep->lockso coordinated sleep does not proceed against firmware with an unanswered call. - In
afk_recv_handle_compact_call(), both the new budget-exhaustion drop path (!afk_compact_reply_reserve()) and thekvzalloc()OOM path silently leave a firmware call unanswered without settingep->sleep_poisoned = truewhenep->dcp->v27_sleep_transportis enabled. Poisonep->sleep_poisonedunderep->lockon those drop paths too.
- In
- §1 / §3 (
sound/soc/apple/aop_lpai.rs:126, 435): HardcodedRING_BYTES_MAX(1 MiB) risks breaking legitimate higher-rate / 4-channelt6041-aop-audiorings:RING_BYTES_MAX = 2 * BUFFER_BYTES_MAX(1,048,576 B) is checked only against one geometry (16 kHz × 3 ch × 4 B × 4 s = 768,000 B). Four channels at 16 kHz is already 1,024,000 B, and any 48 kHz 4-second ring (e.g. 2,304,000 B for 3 ch) would be refused with-EIO, causing the low-power microphone to disappear.- The T6041 ring path also runs on
t6040andt8132(t6041-aop-audio). Measure/log live ring geometries across all chips using this path, and tie the ring cap to the stream format's byte rate (e.g., max ring duration × byte rate with a generous upper safety ceiling) rather than a tight fixed 1 MiB cap.
- §5 (Owed hardware verification rows across 5 subsystems):
- No on-hardware rows have been posted yet. Owed on the default command line (with 0 SELinux denials, 0 failed units, 0 new kernel errors):
admac: s2r speaker-sense capture with V/I alignment verified on arealign_senseboard (J813/J815/J714s), plus s2r MCA playback on J616s or M2;macsmc: boot with SMC sensors/fans up on J616s and asaved_enabledboard (J714s or J813);aop_motion+aop_devmotion: unbind/rebind (ideally under KASAN) +aop_devmotionbuffered read on M1 Pro/M2/J616s/J713;aop_lpai: low-power microphone open with live ring geometry logged ont6041-aop-audioboards (J616s, J713);afk: external display + hotplug on J713 and a desktop 26.x DCP Mac.
- Strongly recommend splitting this 6-commit bundle by subsystem (
admac+aop_lpai,macsmc,aop_motion+aop_devmotion,afk) so low-risk fixes can land on their own rows without being blocked byafk/aop_lpai.
- No on-hardware rows have been posted yet. Owed on the default command line (with 0 SELinux denials, 0 failed units, 0 new kernel errors):
Non-blocking Notes
drivers/mfd/macsmc-test.c:415-418asserts onswaitinternal fields (wait.task_list.next);completion_done()+apple_smc_rtkit_recv_early()already verifies completion initialization without coupling to wait-queue internals.drivers/mfd/macsmc.c:679-686:smc->boot_stage = APPLE_SMC_BOOTINGis still set afterdevm_apple_rtkit_init*(); moving it ahead of RTKit init (alongsideapple_smc_init_state()) closes any remaining early-callback window.
Assisted-by: LLM (Gemini 4 Neon)
|
Split by subsystem as both reviews asked, rebased on integration/aurora a7638d5, with the review points addressed:
Hardware rows (fleet82 + the series as a one-shot on M1 Pro, M2, J616s, J473, against the same rows on production) go on the new PRs. Closing this one as superseded. |
Six small robustness fixes in Apple SoC drivers, found by reading the code. Each commit carries a KUnit case that fails without its fix and passes with it.
Problem and change, per commit
peripheral_configpointer, and the restore after a system sleep read the realign frame size through it again. The AOP audio driver passes a pointer to a local variable, so that memory is long gone by then. The frame size is now taken once, the saved copy carries no pointer, and the restore only programs the registers.AFK_COMPACT_MESSAGE_MAX, the largest single message. A call over that is dropped with a rate-limited warning before anything is allocated.There are no new parameters and no chip, board or firmware gates. Every limit comes from an existing driver constant or the PCM's own buffer limit.
Testing
integration/aurora13e494a plus this series. All new cases pass in both groups:apple_g17_rx_util_min_test, needsCONFIG_UCLAMP_TASK).admac_restore_keeps_the_frame_sizemacsmc_early_message_testiio_device_is_freed_with_the_device_resourcesscan_is_written_in_fulla_format_without_a_valid_period_range_is_refusedthe_ring_geometry_is_bounded_by_the_pcm_bufferafk_compact_call_reply_budget_testStill to run
realign_sense.Reviewer detail
admac_program_config()is the old register part ofadmac_device_config().admac_device_config()setsrealign_bytesonce (the duplicate assignment is gone), then saves the config withperipheral_config = NULLandperipheral_size = 0.admac_restore_chan()callsadmac_program_config()on the saved copy, sorealign_bytesstays as the client set it.apple_smc_init_state()runs before the SRAM map and before either RTKit init variant. The KUnit case builds a zeroedapple_smcwith a fake SRAM resource. It checks that both wait lists are initialised, then delivers a shared-buffer message throughapple_smc_rtkit_recv_early().IioAllocowns theiio_dev, theArc<State>inpriv_and the channel table (Spec). It is registered withdevres::register()right afteriio_device_alloc(); if that registration fails, the allocation is dropped and freed. Devres releases in reverse order: buffer, then trigger, thenIioAlloc.MotionIio::droponly unregisters.MotionIio::new()now takes&Device<Bound>, so the KUnit test can run it on a faux device. The test checks that the private data is still alive when devres release begins and gone when it ends.Scan::new()zeroes the tail. The test derives the scan size the wayiio_compute_scan_bytes()does, compares it withsize_of::<Scan>(), and checks that the bytes after the timestamp are zero over a 0xa5-filled slot.StreamFormat::period_bytes_min()returnsNoneoutside1..=PERIOD_BYTES_MAX, andStreamFormat::new()refuses such a format.hw()uses the checked value.ring_geometry()folds the existing quantum checks together with the newRING_BYTES_MAX = 2 * BUFFER_BYTES_MAXbound.ring_step()is untouched.afk_compact_reply_reserve()andafk_compact_reply_release()work underep->lock.sleep_jobs.destroy_workqueue(tx_wq)) drains through the worker, so the count returns to zero.dptxport_*,panelav_sac_call_v2,ext26_aux_call) take short calls, far below the cap.Assisted-by: LLM (Claude:Opus 5.5)