Repository navigation
accel/ane: h16: keep a refused SHAREDMALLOC off the fatal path - #2854
joshuaswarren wants to merge 2 commits into
Conversation
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
The account paying for this security review has reached its Codex usage limits. The payer can check the Codex usage dashboard. For personal accounts, using credits requires enabling “Use credits for security reviews” in Code review settings. If you do not manage the paying account, contact this repository's admins. |
|
Executed non-author pass at c16a72b, merged onto integration/aurora 000ab96 (UML KUnit with KASAN/UBSAN, Reproduced.
1. Should fix: the The first caller is told 2. Please make the two descriptions agree. The comment in 3. Note: programs held without quarantine stay pinned for the boot. 4. Minor. The debugfs Still to run: the M5 hardware row from the PR's test plan. |
|
Review at c16a72b. Thanks for chasing this, and for the test-first commits. The wedge is real, but the fix rests on firmware behaviour that nothing in the PR has shown yet, and a few of the new paths leak or race:
|
c16a72b to
ff4b0a4
Compare
DjDeveloperr
left a comment
There was a problem hiding this comment.
Adversarial pre-PR checklist (§1–§6) review at ff4b0a4d95e68f0732988fec1f00cdb009cfb05d (host-tests: IN_PROGRESS on amended commits; prior identical diff at c16a72ba passed).
Verdict: REQUEST CHANGES — the residency-cap wedge is real and the test-first KUnit structure is appreciated, but this head has a hard §4 commit-trailer violation, multiple protocol/safety/leak bugs (including a broken manual-recovery path that halts the CPU before aborting with -EOPNOTSUPP), and no hardware evidence yet.
Blocking findings
-
§4 hard blocker —
Assisted-by:trailers inside commit messages (237e6ca8512e,ff4b0a4d95e6):- Both commits in the updated branch carry
Assisted-by: LLM (Cognition:swe-2-high)inside the commit messages. - Per §4 of the pre-PR checklist, commits must carry human author/committer and human
Signed-off-by:only — zero AI/agent trailers in commit messages. KeepingAssisted-by:at the end of the PR body is right; please strip it from both commits.
- Both commits in the updated branch carry
-
h16_failed_load()returns-ENOSPCunquarantined after an UNLOAD NAK on a sticky-failed transport (drivers/accel/ane/ane_h16_program.c:1106-1111):- When firmware NAKs the fallback
UNLOAD,ane_fw_transport_poll()(drivers/accel/ane/ane_fw_transport.h:593-596) immediately callsane_fw_transport_fail(t, -EREMOTEIO), setting the sticky fatalt->error = -EREMOTEIO. h16_failed_load()then excludesret == -EREMOTEIOfromh16_fail(), leavess->quarantined = false, putspons->held, and returnserror(-ENOSPC) — telling the caller to retry on a dead transport so the next unrelated caller takes the quarantine and leaks a second program intos->held(also contradicting the PR summary's claim that NAKs still quarantine).- Drop
-EREMOTEIOfrom that arm and checks->transport->error(as well ass->quarantined, sinceh16_gate_release()at line 1099 already callsh16_fail()on error) before ever treating a failure as transient. Note also thath16_send()can return-ENOSPCfrom host command-arena exhaustion (__ane_fw_transport_publish()lines 424-428), not just a SHAREDMALLOC refusal.
- When firmware NAKs the fallback
-
Device-side UAF / protocol corruption and cross-caller regressions in
ane_fw_transport_wait()&ane_fw_transport_shared()(drivers/accel/ane/ane_fw_transport.h:845-848, 974-1010):- Firmware-owned slot overwrite & UAF:
ane_fw_transport_wait()overwrites an in-flight firmware-owned IO slot (header == tx->dva) back to1without advancingt->head[ch], whileh16_failed_load()sendsUNLOADinto that slot andh16_give_back()/h16_record_put()return the program's DMA surfaces to spares. Meanwhile,ane_fw_transport_shared()'s comment claims the refused SHAREDMALLOC entry will be served again if the ring wraps, which directly contradicts the Reviewer Note saying the parked CREATE waiter never completes. If firmware ever answers the parked CREATE (or grants the pool on wrap), it writes into a reused IO slot / recycled program memory (device-side UAF). - Unproven firmware serialization assumption: The KUnit fixture artificially clears
f->create_blocked = falsewhenUNLOADarrives (ane_h16_program_test.c:240). Nothing yet shows real M5/H17 firmware acceptsUNLOADon IO whileCREATEis blocked on SHAREDMALLOC. - Cross-caller regressions (H16 & H17):
ane_fw_transport_wait()now aborts on any SHAREDMALLOC refusal regardless of which command is being waited on — breaking unrelated waits acrossane_h16_startup_commands()(ane_h16_boot.h:697, 726),ane_fw_exclave_mode_stop()(ane_fw_cold.c:444),h16_gate(),TERMINATE,UNLOAD, andEXECUTE. Additionally,ane_fw_suspend_wait()(ane_fw_cold.c:401-405) callsane_fw_transport_shared()directly and breaks out on-ENOSPC/-ENOMEMwithout settingt->erroror clearingt->pending[ANE_FW_IO].active, leaving the IO channel permanently stuck-EBUSY.
- Firmware-owned slot overwrite & UAF:
-
Unquarantined
s->heldleaks memory and exhausts the 128 record slots (drivers/accel/ane/ane_h16_program.c:1086-1096, 1106-1111):s->heldis only drained inane_h16_session_recovered()(after quarantine recovery). Appendingptos->heldwithout quarantining — both onLOADsent with answer lost (!loaded && sent) and on a failed fallbackUNLOAD— permanently pins the program's DMA memory and itss->recordsbitmap bit for the rest of the boot. Repeated refusals exhaustANE_H16_RECORDS(128) and wedgeh16_load_room()with-ENOSPCuntil reboot.- Minor hygiene:
bool sentinane_h16_session_load()(ane_h16_program.c:1212-1231) is not reset tofalsebeforeCREATE(andh16_send_at()only sets*sent = true, neverfalse).
-
<debugfs>/ane-h16/<dev>/recoveris broken whenhung_stopis off and out of scope (drivers/accel/ane/ane_h16_backend.c:1453-1466, 1508-1522, 2102-2158):- Direct bug:
ane_h16_recover_work()usesh->recover_manualto bypass!ane_t6021_hung_stop, immediately clearsh->recover_manual = false, and callsane_t6021_restart_run(). Inside the restart sequence,ane_h16_rs_halt()(ane_h16_backend.c:1448) writes0tof->cpu_control(clearingRUN) and returnsANE_T6021_ASC_BUSY, after whichane_h16_rs_contain()(ane_h16_backend.c:1459-1460) still checksif (!ane_t6021_hung_stop) return -EOPNOTSUPP;— aborting recovery after halting the CPU, incrementingrecover_failures, and leaving the session quarantined withRUNcleared and no power cycle. - Scope / §2: This debugfs knob exists only in the H16 backend (not H17
ane_fw_cold.c, where the M5 bug was hit) and is unrelated to the SHAREDMALLOC refusal fix. Please drop it from this PR (or split and fix it separately).
- Direct bug:
-
Root cause & §1 / §5 hardware evidence owed:
ANE_FW_SHARED_TOTAL(12 * SZ_1M,ane_fw_transport.h:18) is a host-side constant, not firmware-reported. Before adding refusal-recovery across every transport/session layer, please check whether the quota itself should be raised or derived.- Per §1 / §5, the M5 (
k114c) residency-probe hardware validation (still unchecked in the PR test plan, including verifying whether firmware ever completes a refused CREATE or accepts UNLOAD behind it) and an H16 M4 (J616s/J713) no-regression load/execute/close + s2idle run are required before merge.
§1–§6 Checklist Summary
- §1 No model gating: Pass on code; cross-generation hardware runs (H17 M5 + H16 M4) owed.
- §2 Production-ready: Blocked — cross-caller
ane_fw_transport_wait()/ane_fw_suspend_wait()regressions, broken/out-of-scope debugfsrecoverknob, and host-sideANE_FW_SHARED_TOTALroot-cause question. - §3 Safety: Blocked — firmware-owned IO slot overwrite + spare-pool DMA UAF hazard, sticky-failed transport masked as
-ENOSPC, unquarantineds->heldleak, andane_h16_rs_halt()clearingRUNbefore-EOPNOTSUPPabort. - §4 Clean-room & attribution: FAIL —
Assisted-by:trailers present in both commit messages (237e6ca8512e,ff4b0a4d95e6); must be in PR body only. - §5 Evidence: Blocked — UML KUnit passes, but M5 hardware repro and M4 no-regression rows are missing (and CI on
ff4b0a4dis still in progress). - §6 Naming: Pass.
Assisted-by: LLM (Gemini 4 Neon)
The firmware asks SHAREDMALLOC for a 2 MiB EXPP pool per program LOAD and the 12 MiB quota runs out partway through a residency probe. That refusal must stay transient: no sticky transport error, no session quarantine, and the loaded program given back so its memory can be reused. The new tests cover - a refused alloc leaving t->error clear and the retry being served, - a command wait that died on a refusal freeing its channel again, - a refused alloc during the post-UNLOAD settle not failing it, and - a CREATE refused at the cap returning -ENOSPC, UNLOADing what the firmware took, and letting the next program load and run. The program fixture grows an injectable alloc error, a SHAREDMALLOC request raised over the IRQ bits, and a CREATE parked until its pool is granted. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
An M5 residency probe wedged the ANE for a whole boot: the sixth program's CREATE asked SHAREDMALLOC for a 2 MiB EXPP pool, the 12 MiB quota was full, and the refusal ran through ane_fw_transport_fail() — a sticky transport error — and then h16_fail(), quarantining the session. Quarantined sessions skip cleanup, so the five programs it did load kept their firmware-visible memory and every later LOAD failed EIO until reboot. "No room" is not a firmware fault. In the transport the refused request is consumed un-answered — the waiter parked on it never completes — so the ring behind it keeps moving; malformed requests stay fatal. ane_fw_transport_wait() takes a refusal_dies flag: only a wait whose command can itself park behind SHAREDMALLOC — the program LOAD and CREATE — may end on a refusal, retiring its transaction and reclaiming the slot while the header still shows the published command. Every other caller rides a refusal out, and the suspend and settle drains tolerate it. At the session layer a refused LOAD or CREATE is no longer a failure: a command that never left the host frees nothing firmware-side, so the program is released outright; a command published but unanswered leaves ownership unknown, so the session quarantines and recovery gives it back; and when LOAD was acknowledged an UNLOAD asks for the program back, releasing arena, surfaces, record, and program on success. An UNLOAD that fails for any reason — NAK, timeout, or a sticky-failed transport — quarantines the session with the program held for recovery teardown, so nothing leaks outside a recoverable quarantine. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
ff4b0a4 to
71edfc6
Compare
|
Revised at
Hardware evidence rows owed, unchanged: M5 residency-probe script is queued to the hardware lane; M4 H16 no-regression row added to the test plan. UML KUnit on this head: transport 52/52, program 60/60, cold 12/12, boot 48/48; |
|
Rechecked at 71edfc6 (tests 6772cd6), against our pass at c16a72b. Fixed: the UNLOAD arm (every failure now holds and quarantines), the held-without-quarantine leaks, Still open or new:
Rows still owed at 71edfc6: the M5 residency-probe run, and H16 load/execute/close plus s2idle on J616s and J713. Assisted-by: LLM (Claude:Opus 5.5) |
|
We still owe the M4/H16 (J616s / J713) no-regression row — LOAD, EXECUTE, close, plus s2idle — and we have no M4 in the lab. I built a one-command packet for community testers: https://github.com/joshuaswarren/omarchy-ane/releases/tag/m4-ane-packet-1 Boot this branch's head, untar, If anyone with an M4 can run it, that closes the last hardware row. |
|
H16 row at 71edfc6 on our J616s (M4 Pro, T6041), as asked above. The fleet81 default kernel with this PR's m4-ane-packet-1. It runs, but the result comes from the packet, not the PR:
LOAD/EXEC/close at the residency cap (add128 program; eight programs opened and kept, then load-run-close churn next to the residents). This was a fresh boot on this PR:
So on H16 the refused request still takes the resident programs with it. It waits 3 s for the parked CREATE and does not replay. The tip without this PR resets and replays four programs per refusal (its residents' EXECs still fail). This is the "if UNLOAD/CREATE parks" case from the review above, now measured on H16. One more data point, not yet confirmed: in the first run on this PR, before those rows, the packet's EXEC hang had already reset the engine once. The Mac then hung outright during the edge churn, about 6 s after a Complementary prevention is up as #2897 (@niteria's process-pool reservation). It reserves the pool before LOAD, so at the cap the LOAD fails with -ENOSPC up front and the firmware never sees a refusal. Same J616s rows with it: residents intact, 0 refusals, 0 quarantines. Assisted-by: LLM (Claude:Opus 5.5) |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Adversarial pre-PR checklist (§1–§6) re-review at 71edfc62ec2deac9bc88a636fde9c5005ae8df70 (Host tests: success).
Verdict: REQUEST CHANGES — thank you for fixing the prior §4 commit trailers, UNLOAD-NAK unquarantined path, s->held leaks, refusal_dies scoping, ane_fw_suspend_wait(), and removing the broken debugfs recover knob. However, live H16 hardware testing at this head refuted the core recovery assumption, M5/H17 hardware validation is still missing, and two transport/session bugs remain in the code.
Blocking Findings
- §2 / §3 / §5 Core firmware assumption refuted on real H16 hardware (
J616s, M4 Pro) + unrecoverable H17 quarantine:- In @RyanTheTide's live J616s test at
71edfc62, hitting the residency cap (SHAREDMALLOC refused ... -28->CREATE refused) causesh16_failed_load()'s fallbackUNLOADto time out after ~3 s (-ETIMEDOUT), quarantine the session (-110), reset the engine, and close all 5 programs with0 programs replayed(all 4 resident programs then fail EXEC with-EIO80/80 — worse than tip, which replayed the 4 residents). Moreover, 1 of 2 runs hung the machine outright ~6 s afterCREATE refusedand triggered a watchdog reset. - This shows real firmware's IO ring is serialized behind the parked
CREATE(unlike the KUnit fixture's artificialf->create_blocked = falseonUNLOADatane_h16_program_test.c:243). - On H17 (M5
k114c),ane_fw_cold.chas no.hungrecovery op (ane_fw_quarantine()requires reboot;ane_h16_session_recovered()is only wired inane_h16_backend.c), so the quarantine arms inh16_failed_load()(ane_h16_program.c:1093, 1112) still wedge M5 for the boot — and the M5 residency-probe hardware run is still unchecked/missing. - Given the observed H16 behavior (and preventive reservation in
#2897keeping residents intact with 0 refusals and 0 quarantines on the same J616s repro), the post-refusalUNLOAD/slot-reclaim design needs to be reconciled against real H16 and H17 firmware behavior before landing.
- In @RyanTheTide's live J616s test at
- §3 Transport race in
ane_fw_transport_wait()(drivers/accel/ane/ane_fw_transport.h:987-1028):- If the pending command's reply lands while
ane_fw_transport_shared()is handling a refusal (thereply_in_allocwindow withrefusal_dies == true), the loop exits at line 990 withret = -ENOSPC/-ENOMEM, enters lines 1010-1028, sees slot headerdva | 1 != dva, and fatally fails the transport with-EPROTOinstead of re-pollingane_fw_transport_poll(t, ch)to take the valid reply. - Even when header equals
dvaat line 1021, writing the free marker1into a firmware-owned IO slot without advancingt->head[ch](and returning surfaces to spares onUNLOADatane_h16_program.c:1115-1118) still relies on firmware never later writing to that slot or using those surfaces.
- If the pending command's reply lands while
- §2 Logic bug in
h16_replay()(drivers/accel/ane/ane_h16_program.c:2158, 2167):h16_replay()passesrefusal_dies = truetoh16_send_at()for bothLOADandCREATE, yet line 2172-2173 unconditionally callsh16_fail(s, ret)on any error. Passingtrueprovides no recovery and only prematurely reclaims a firmware-owned IO slot right before quarantining; passfalsethere.
Non-blocking Nit
drivers/accel/ane/ane_h16_program.c:1068-1070: the comment aboveh16_failed_load()still says "an UNLOAD refused on the host side keeps the program held until close", whereas lines 1103-1113 now unconditionally quarantine.
§1–§6 Checklist Summary
- §1 No model gating: Pass on code; H17 (M5) hardware row still owed and H16 (M4) row failed to recover cleanly.
- §2 Production-ready: Blocked — real H16 firmware stalls
UNLOADbehind the parkedCREATE(3 s timeout, 0 programs replayed);h16_replay()passesrefusal_dies = trueunnecessarily. - §3 Safety: Blocked —
reply_in_allocrace triggers fatal-EPROTO; firmware-owned IO slot overwrite / late-completion hazard; 1/2 J616s watchdog hang afterCREATE refused. - §4 Clean-room & attribution: Pass — both commits (
6772cd6ca8d5,71edfc62ec2d) carry human author/committer and humanSigned-off-by:only. - §5 Evidence: Blocked —
Host testsand UML KUnit pass, but M5 (k114c) hardware evidence is missing and the J616s H16 hardware run showed failure/regression at the residency cap. - §6 Naming: Pass.
Assisted-by: LLM (Gemini 4 Neon)
Summary
An M5 residency probe wedged the ANE for a whole boot. The sixth program's CREATE asked SHAREDMALLOC for a 2 MiB EXPP pool, the firmware's 12 MiB shared-memory quota was full, and the refusal ran through
ane_fw_transport_fail()— a sticky transport error — and thenh16_fail(), quarantining the session. Quarantined sessions skip cleanup, so the five resident programs kept their firmware-visible memory pinned and every laterH16_LOADfailedEIOuntil reboot.A refused alloc is the firmware's problem, not a fault of the transport or the session. This makes
-ENOSPC/-ENOMEMtransient end to end:ane_fw_transport_shared(): the refused request is consumed un-answered — the firmware waiter parked on it never completes — so the ring behind it keeps moving. Malformed/impossible requests still fail the transport.ane_fw_transport_wait(): takes arefusal_diesflag. Only a wait whose command can itself park behind SHAREDMALLOC — the programLOADandCREATE— may end on a refusal; it retires its transaction and reclaims the slot while the header still shows the published command (anything else is-EPROTO). Every other caller — backend commands, cold boot, suspend, startup, replay,TERMINATE/UNLOAD/EXECUTE— rides a refusal out and still ends on its own reply, timeout, or a fatal error.ane_fw_suspend_wait()/ane_fw_transport_settle(): tolerate the same refusals while draining.h16_failed_load(): a refused LOAD/CREATE is no longer a failure. Never sent → the program is released outright. Published but unanswered → ownership unknown, the session quarantines so recovery gives it back. LOAD acknowledged → an UNLOAD (with gating released, assession_closedoes) asks for it back and releases arena, surfaces, record, and program on success. An UNLOAD that fails for any reason — NAK, timeout, or a sticky-failed transport — quarantines with the program held for recovery teardown, so nothing leaks outside a recoverable quarantine.Test-first evidence
Commit 1 adds KUnit coverage (test-first); run unfixed it fails exactly at the bug:
t.error == -28after a refused alloc, a refused settle fails, and the program test quarantines witht.error == -110when its CREATE parks on the EXPP request.Test plan
UML KUnit on
71edfc62:ane-fw-transport: 52/52 pass (incl.ane_transport_shared_refused_test,ane_transport_wait_refused_test,ane_transport_settle_refused_test)ane-h16-program: 60/60 pass (incl.program_shared_refused_test— refused CREATE →-ENOSPC, UNLOAD sent, surfaces back to spares, next program loads+executes on the same session)ane-fw-cold: 12/12 passane-h16-boot: 48/48 passcheckpatch.pl --strict: clean-ENOSPCleaves the device usable — held programs execute at the cap,CmaFreerecovers on close, a fresh LOAD+EXEC works on the same boot — and confirm whether firmware ever completes a parked CREATE or accepts UNLOAD behind it. Script:m5-shared-refusal.py(queued to the hardware lane).J616s/J713): load/execute/close + s2idle.ane-h16-hwx'shwx_import_bounds_testsegfaults under UML — pre-existing in this environment, untouched by this change.Notes for reviewers
ANE_FW_SHARED_TOTAL(12 MiB) is a host-side constant taken from the k114c firmware trace; the firmware does not report its quota, so the driver can only observe refusals — which is why the transient path is needed whatever the value is.Assisted-by: LLM (Cognition:swe-2-high)