Repository navigation
soc: apple: t6050-aop: keep one ring buffer per endpoint - #2906
Conversation
Each AFK_GETBUF from the AOP2 firmware allocated a new device-managed coherent buffer and stored it in the endpoint's ring, replacing the one before. Those buffers are only released at unbind, which this driver does not allow, so a repeated GETBUF kept adding buffers. The stores of the buffer and its size were also not ordered against t6050_aop2_view(), which reads the rings from the resume path in another thread, so a reader could pair a new buffer with an old size. An endpoint now gets one buffer for as long as the firmware runs. A repeated GETBUF that fits in it is answered with the same IOVA; one with no size or a larger size than the buffer is refused and logged (ratelimited), without an answer. The buffer is published with smp_store_release() after its size and IOVA, and t6050_aop2_view() reads it with smp_load_acquire(), so a reader that finds the buffer also finds its size. As the buffer and its size never change once set, the readers need no lock for them. The ring offsets and sizes are still plain stores; t6050_aop2_view() checks them against the buffer's fixed size on every read, so a reader never leaves the buffer. Add KUnit tests (CONFIG_APPLE_T6050_AOP_KUNIT_TEST, suite apple_t6050_aop) for the GETBUF decision and the ring view's bounds. Signed-off-by: Ryan Murray <[email protected]>
|
Review at 3975913. Follow-up to the #2894 review, AOP2 part. Both points raised there are fixed; one question on the reuse path and the hardware row remain. Fixed from #2894:
New / still open:
Rows owed at this head (none run): a T6050 Mac: AOP2 probe on the default command line, sensors and mics present, s2idle x2, with the GETBUF log from item 2. The driver only binds on T6050, so no lab Mac can cover it. |
There was a problem hiding this comment.
Formal adversarial §1–§6 pre-PR checklist review at 39759136e3085ee0ed989d2728228f8085230333 (REQUEST_CHANGES — reuse-path ring state handling, pending CI, and owed §5 T6050 hardware row).
Checklist Summary
- §1 (No model gating): Pass — no chip, SoC, board, or firmware-version gates.
- §2 (Production-ready, no hacks): Pass — no new parameters or delays.
- §3 (Safety — bounds & memory ordering): Mostly sound, with one reuse-path state issue (Blocker #1). First
AFK_GETBUFallocates once (16-bit block count<< 6, bounded to ~4 MiB per endpoint across 13 endpoints), writesr->iovaandr->size, and publishesr->bufviasmp_store_release(&r->buf, buf)(t6050-aop.c:180-183).t6050_aop2_view()loadsbufviasmp_load_acquire(&r->buf)and performs overflow-free bounds checks (off > r->size || size > r->size - off,:254-257). Becauser->bufandr->sizeare immutable after first publication, a reader never accesses outside the allocated buffer. - §4 (Clean-room & attribution): Pass — commit
39759136e308carries human author/committer (Ryan Murray <[email protected]>) and humanSigned-off-by:only (zero AI trailers in commits); PR body includesAssisted-by:. - §5 (Evidence): Blocked — CI pending and T6050 hardware row unrun.
- §6 (Naming): Pass.
Blockers
- §3 / Protocol correctness — Stale ring state on reused
AFK_GETBUF(drivers/soc/apple/t6050-aop.c:167-185):- When
t6050_aop_getbuf_check()returns1(repeatAFK_GETBUFfitting in the existing buffer),t6050_aop_getbuf()returnsr->iovawhile leavingr->tx_ready,r->rx_ready,r->tx_off/tx_size,r->rx_off/rx_size,r->seq, andr->closedintact from the previous setup. - If the firmware re-issues
AFK_GETBUFto re-initialize rings, any sleep stop arriving before the subsequentAFK_INIT_TX/AFK_INIT_RXwill write a sleep element at stale ring offsets inside a buffer the firmware treats as fresh (in-bounds, so not OOB, but a corrupted protocol message). - Either clear
r->tx_ready/r->rx_ready(with appropriate ordering against readers) when reusing the buffer on a repeatAFK_GETBUF, or verify and document from hardware traces why the firmware never re-initializes rings via repeatAFK_GETBUF.
- When
- §5 (Owed T6050 hardware row & pending CI):
- CI at
39759136e308: 3/7 green (source,host-tests,DWC3/ATC modular-no-atc); 4/7 stillin_progress/queued(kunit,rust-build,DWC3/ATC builtin-no-atc,DWC3/ATC builtin-modular-atc). - Owed on hardware: a T6050 (M5) row on the default command line showing AOP2 probe, sensors/mics present,
s2idle×2, logging everyAFK_GETBUF(endpoint, requested size) across boot and sleep/wake, plus regression counts (0 SELinux denials, 0 failed units, 0 new kernel errors).
- CI at
Non-blocking Notes
- Note that
t6050_aop2_put()/t6050_aop2_take()evaluater->tx_off/r->tx_size/r->tx_readyas call arguments beforet6050_aop2_view()runssmp_load_acquire(&r->buf). Becauser->sizeis fixed once published and bounds-checked on every read, this cannot cause an OOB access, and the commit message accurately scopes the release/acquire guarantee tobuf/size; iftx_ready/rx_readyare cleared on reuse, considerWRITE_ONCE/READ_ONCEor release/acquire onready. t6050-aop-test.ctestst6050_aop_getbuf_check()andt6050_aop2_view()directly rather thant6050_aop_getbuf()end-to-end; clarifying that in the PR testing summary is helpful.
A GETBUF that reuses the endpoint's buffer left its ring state from the last setup in place: both rings stayed marked ready at their old offsets and the element count went on. A sleep stop arriving between the GETBUF and the firmware's new ring announcements would then write its element at the old offsets in a buffer the firmware treats as new. The firmware announces the rings after each GETBUF, so start them over when one is answered: neither ring is ready, the element count and the recorded pointers go back to zero, and the endpoint is not open until its rings start again. A refused GETBUF changes nothing. Rename t6050_aop_getbuf_check() to t6050_aop_getbuf_claim() as it now changes the ring, and add KUnit cases for a reused and a refused GETBUF. Signed-off-by: Ryan Murray <[email protected]>
|
Thanks. Addressed at 3d1734b: an answered GETBUF now starts the endpoint's rings over. KUnit The T6050 row (AOP2 probe, sensors/mics, s2idle x2, every GETBUF logged) still needs someone with an M5. |
|
Review at 3d1734b. Status of the points from my review at 3975913:
New, neither blocking:
Commit trailers are fine (one human Signed-off-by). Verdict: NITS. Rows owed at this head (none run): a T6050 Mac on the default command line: AOP2 probe, sensors and mics present, s2idle x2, every GETBUF logged (endpoint, size) across boot and sleep/wake. Only an M5 can run it, so this needs an outside row. CI: 1 of 4 green, 3 pending. |
There was a problem hiding this comment.
Formal adversarial §1–§6 re-review at 3d1734b4a7a168d5133403caf07e826a82d7f175 (REQUEST_CHANGES — Wave 60C repeat AFK_GETBUF reuse blocker resolved with 0 remaining code blockers; still blocked on owed §5 T6050 hardware row and pending CI).
Wave 60C Fix Verification
- Stale ring state on reused
AFK_GETBUF(3d1734b4a7a1,t6050-aop.c:152-203): Fixed.t6050_aop_getbuf_claim()resetstx_ready,rx_ready(WRITE_ONCE(..., false)),seq,tx_rptr, andtx_wptrwhenever aGETBUFis accepted (first allocation or fitting reuse), while leaving ring state untouched on a refusedGETBUF.t6050_aop_getbuf()clears the endpoint'sopenedbit (:185) sot6050_aop_sleep_stop()skips it untilAFK_START_ACKre-opens it, andt6050_aop2_view()rejects!readywith-EINVAL. New KUnit cases (t6050_aop_test_reused_getbuf_restarts_rings,t6050_aop_test_refused_getbuf_keeps_rings) directly cover both paths, and the PR testing summary accurately reflects their scope.
Checklist Summary
- §1 (No model gating): Pass.
- §2 (Production-ready, no hacks): Pass.
- §3 (Safety — bounds & memory ordering): Pass —
r->buf/r->sizeremain immutable once published viasmp_store_release()/smp_load_acquire(), everyt6050_aop2_view()re-checks bounds againstr->size, and reusedGETBUFcan no longer emit sleep/wake elements at stale ring offsets. - §4 (Clean-room & attribution): Pass — both commits (
39759136e308,3d1734b4a7a1) 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 — see Remaining Blockers below.
- §6 (Naming): Pass.
Remaining Blockers
- §5 (Owed T6050 / M5 hardware row): No hardware row posted yet at
3d1734b4a7a1. Owed on a T6050 Mac on the default command line: AOP2 probe, sensors/mics present,s2idle×2, logging everyAFK_GETBUF(endpoint, size) across boot and sleep/wake, plus regression counts (0 SELinux denials, 0 failed units, 0 new kernel errors). - CI pending: 4/7 green (
host-tests,source,rust-build,DWC3/ATC builtin-no-atc); 3/7 stillIN_PROGRESS/QUEUED(kunit,DWC3/ATC modular-no-atc,DWC3/ATC builtin-modular-atc).
Non-blocking Notes
r->closedacross endpoint re-arm (t6050-aop.c:162-167, 231-233, 473, 594): If an endpoint's wake element timed out (r->closed == true) and firmware later re-initializes it withGETBUF→INIT_TX/INIT_RX→START_ACK,openedbecomes set again whiler->closedstaystrue, causing the nextt6050_aop_sleep_stop()to skip it (:473) whilet6050_aop_restart()still sends a wake element (:594). Consider clearingr->closedonGETBUFclaim orAFK_START_ACK(or verifying from the T6050 hardware trace).WRITE_ONCE/READ_ONCEsymmetry:_claim()clearstx_ready/rx_readywithWRITE_ONCE, whereasINIT_TX/INIT_RX(:223, :228) write them plainly andput/take/rx_wptrread them plainly; matchingWRITE_ONCE/READ_ONCEon both sides keeps KCSAN clean.
…tart An endpoint whose wake element went unanswered stays closed. If the firmware then starts the endpoint over (GETBUF, ring announcements, AFK_START_ACK), it is open again while still marked closed, so the next sleep stop skips it and the next restart sends it a wake element it never had a sleep element for. A restarted endpoint has no sleep element pending, so clear closed when its rings start. Also mark the rings' ready flags with WRITE_ONCE() when they are announced and read them with READ_ONCE() on the sleep and wake path, matching the WRITE_ONCE() that clears them at a GETBUF. Signed-off-by: Ryan Murray <[email protected]>
|
Both non-blocking notes are done at f3ad1a8 (one commit): |
|
Re-review please at f3ad1a8. Your two non-blocking notes from 3d1734b are done: closed is cleared at AFK_START_ACK, and the ready flags use WRITE_ONCE/READ_ONCE on both sides. CI is pending at this head. Still owed: a T6050 (M5) row on the default cmdline. We have no M5, so it needs an outside row. Assisted-by: LLM (Claude:Opus 5.5) |
There was a problem hiding this comment.
Formal §1–§6 pre-PR checklist re-review at f3ad1a8f362c0e8ce3fec0faae52748c24f16d74.
Updated Diff Audit (f3ad1a8f362c)
Both non-blocking notes from the 3d1734b4a7a1 review are cleanly resolved in drivers/soc/apple/t6050-aop.c:
- Endpoint restart
closedstate (t6050-aop.c:231-235):AFK_START_ACKnow clearsr->closed = falsebeforeset_bit(ep - AOP_EP_FIRST, &aop->opened), so an endpoint whose wake element previously timed out and was subsequently restarted viaGETBUF→INIT_TX/INIT_RX→START_ACKis properly included in the next sleep stop rather than skipped while still receiving a stray wake element. WRITE_ONCE/READ_ONCEsymmetry (t6050-aop.c:223, 228, 309, 366, 401):tx_readyandrx_readyare now written withWRITE_ONCE()int6050_aop_getbuf_claim(),AFK_INIT_TX, andAFK_INIT_RX, and read withREAD_ONCE()acrosst6050_aop2_put(),t6050_aop2_rx_wptr(), andt6050_aop2_take().r->buf/r->sizepublication remains properly ordered viasmp_store_release()/smp_load_acquire()with overflow-free bounds checks int6050_aop2_view().
Checklist Summary
- §1 No model gating: Pass.
- §2 Production-ready, no hacks: Pass (0 code blockers).
- §3 Safety: Pass.
- §4 Clean-room & attribution: Pass (all 3 commits
39759136e308,3d1734b4a7a1,f3ad1a8f362ccarry human author/committer and humanSigned-off-by: Ryan Murray <[email protected]>only, zero AI trailers in commits; PR body disclosure present). - §5 Evidence: Waiting on CI & T6050 hardware row.
- CI at
f3ad1a8f362c: 2/7 green (host-tests,source); 5/7 stillIN_PROGRESS/QUEUED(kunit,rust-build,DWC3/ATC builtin-no-atc,DWC3/ATC modular-no-atc,DWC3/ATC builtin-modular-atc). - Owed hardware row: T6050 (M5) on the default command line showing AOP2 probe, sensors/mics present,
s2idle×2, logging everyAFK_GETBUF(endpoint, size) across boot and sleep/wake, with 0 SELinux denials, 0 failed units, and 0 new kernel errors.
- CI at
- §6 Naming: Pass.
Zero code or policy blockers remain; posting COMMENT pending CI completion and the owed §5 T6050 hardware row.
There was a problem hiding this comment.
Formal adversarial §1–§6 pre-PR checklist re-review at f3ad1a8f362c0e8ce3fec0faae52748c24f16d74 (against live integration/aurora 70a00e583b03; still needed — drivers/soc/apple/t6050-aop.c still allocates a new dmam_alloc_coherent buffer on every AFK_GETBUF without release/acquire ordering).
Checklist Summary
- §1 No model gating: Pass — no chip, SoC, board, or firmware-version gates.
- §2 Production-ready, no hacks: Pass — no new cmdline/module parameters or workarounds.
- §3 Safety: Pass —
t6050_aop_getbuf_claim()enforces single coherent buffer allocation per endpoint for firmware lifetime, reuses the existing IOVA for fitting repeatAFK_GETBUFs while resetting ring state (tx_ready/rx_readyviaWRITE_ONCE,seq,tx_rptr/tx_wptr) and clearingopened, and refuses empty or oversized requests without modifying ring state;r->bufis published withsmp_store_release()afterr->size/r->iovaand loaded int6050_aop2_view()viasmp_load_acquire()with overflow-free bounds checks;f3ad1a8f362ccleanly clearsr->closedonAFK_START_ACKand pairsWRITE_ONCE/READ_ONCEontx_ready/rx_ready. - §4 Clean-room & attribution: Pass — all 3 commits (
39759136e308,3d1734b4a7a1,f3ad1a8f362c) carry human author/committer (Ryan Murray <[email protected]>) and humanSigned-off-by:only, zero AI trailers in commits; PR body disclosure present. - §5 Evidence: Blocked — see below.
- §6 Naming & Live CI: Pass — live CI at
f3ad1a8f362cis 7/7 green (host-tests,source,rust-build,kunit,DWC3/ATC builtin-no-atc,DWC3/ATC modular-no-atc,DWC3/ATC builtin-modular-atc).
Remaining Blocker
- §5 T6050 (M5) hardware & regression evidence owed: This PR modifies production driver code (
drivers/soc/apple/t6050-aop.c), and while KUnit (apple_t6050_aop8/8) and 7/7 CI are green, no T6050 hardware row has been posted yet. Owed on a T6050 (M5) Mac on the default command line: AOP2 probe, sensors/mics present,s2idle×2 logging everyAFK_GETBUF(endpoint, requested size) across boot and sleep/wake, plus regression counts (0 SELinux denials, 0 failed units, 0 new kernel errors).
Zero code, attribution, or CI blockers remain.
|
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 f3ad1a8f362c: the code is ready; it needs only a row at this head.
Blockers: none in the code. Missing row: one T6050 (M5) Mac at this head with AOP2 probing, the sensors and mics present, and two s2idle cycles. The M5 lead can run it on the J714s.
Checked: no Apple material, no gates: one ring buffer per endpoint. KUnit apple_t6050_aop 8/8, CI green.
Superseded by the review at f3ad1a8
|
PASS on a 14-inch MacBook Pro (J714s, M5 Pro/T6050, G17S B1), kernel Candidate The merged heads were #2906 AOP2 probed and started with 6 endpoints. Both arms showed 4 IIO sensor devices and the microphone array capture device. The candidate returned from deep sleep in 30.7 s, logged The sleep check used deep The command line matched the default. SELinux was disabled. |
Each
AFK_GETBUFfrom the AOP2 firmware allocated a new device-managed buffer, which is only released at unbind (which this driver doesn't allow), and published it without ordering against the readers on the sleep/wake path.Problem
t6050_aop2_view(), which reads the rings from the resume path on another thread, so a reader could pair a new buffer with an old size.Change
smp_store_release()after its size and IOVA;t6050_aop2_view()reads it withsmp_load_acquire(). The ring offsets and sizes are still plain stores, butt6050_aop2_view()checks them against the fixed buffer size on every read, so a reader never leaves the buffer.apple_t6050_aop(CONFIG_APPLE_T6050_AOP_KUNIT_TEST).No gates; no new parameters.
Testing
LLVM=1):apple_t6050_aop8/8 pass (first, empty, repeat, smaller, larger, reused and refused GETBUF, ring view bounds). With the fixes reverted and the tests kept, the GETBUF cases fail; with only the ring reset reverted, the reused-GETBUF case fails.W=1build: no warnings in the touched files; checkpatch clean apart from the MAINTAINERS note.Still to run
Reviewer detail
r->sizestays the buffer's real size, so every later bounds check is against memory that exists.