Skip to content

accel/ane: h16: keep a refused SHAREDMALLOC off the fatal path - #2854

Open
joshuaswarren wants to merge 2 commits into
mainfrom
aurora-silicon/ane/shared-refusal-h16
Open

joshuaswarren wants to merge 2 commits into
mainfrom
aurora-silicon/ane/shared-refusal-h16

Conversation

@joshuaswarren

@joshuaswarren joshuaswarren commented Nov 22, 2026 •

Copy link
Copy Markdown

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 then h16_fail(), quarantining the session. Quarantined sessions skip cleanup, so the five resident programs kept their firmware-visible memory pinned and every later H16_LOAD failed EIO until reboot.

A refused alloc is the firmware's problem, not a fault of the transport or the session. This makes -ENOSPC/-ENOMEM transient 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 a refusal_dies flag. Only a wait whose command can itself park behind SHAREDMALLOC — the program LOAD and CREATE — 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, as session_close does) 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 == -28 after a refused alloc, a refused settle fails, and the program test quarantines with t.error == -110 when 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 pass
  • ane-h16-boot: 48/48 pass
  • checkpatch.pl --strict: clean
  • Hardware validation pending on the M5 (k114c): reproduce the residency probe, confirm -ENOSPC leaves the device usable — held programs execute at the cap, CmaFree recovers 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).
  • H16 no-regression on M4 (J616s/J713): load/execute/close + s2idle.
  • ane-h16-hwx's hwx_import_bounds_test segfaults 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.
  • A wait that died on a refusal reclaims the slot its published-but-unanswered command sat in. Per the reviewer note, a command parked behind a refused request never completes, so no late reply lands there; a header that is not the published command is treated as a protocol violation instead. If hardware shows otherwise the reclaim needs revisiting — that is exactly what the M5 script checks.

Assisted-by: LLM (Cognition:swe-2-high)

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-22T19:37:29.063243Z
We couldn’t complete this review. Comment @codex review to try again.
c16a72b PR opened
🔒 Security Review ❌ Failed 2026-11-22T19:37:34.375177Z
We couldn’t complete this review. Comment @codex security review to try again.
c16a72b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

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.

@RyanTheTide

Copy link
Copy Markdown

Executed non-author pass at c16a72b, merged onto integration/aurora 000ab96 (UML KUnit with KASAN/UBSAN, drivers/accel/ane/transport.kunitconfig). Verdict: changes requested for one path. The rest looks right.

Reproduced.

  • With the fix: ane-fw-transport 51/51, ane-h16-program 60/60, ane-fw-cold 12/12, ane-h16-boot 50/50.
  • Test-first holds. With only the tests commit (46783f8) on integration/aurora, ane_transport_shared_refused_test, ane_transport_settle_refused_test and program_shared_refused_test fail, and nothing else does.
  • The hwx_import_bounds_test UML segfault happens here too and stops the all-suite run before ane-h16-program, so I ran the suites one by one.

1. Should fix: the -EREMOTEIO arm of h16_failed_load() (ane_h16_program.c:1108). An UNLOAD NAK can't be "refusal-class". ane_fw_transport_poll() turns a non-zero status into ane_fw_transport_fail(t, ret) (ane_fw_transport.h:596), so by the time h16_failed_load() sees -EREMOTEIO, the transport is already sticky-failed. To check this, I wrote a probe test (review-only, not for merge): the fake firmware NAKs every UNLOAD, in FW_CREATE_SHARED with alloc_error = -ENOSPC. Three loads in a row give:

round 0: ret=-28  quarantined=0 t.error=-121 held=1 pinned=128 KiB
round 1: ret=-121 quarantined=1 t.error=-121 held=2 pinned=256 KiB
round 2: ret=-5   quarantined=1 t.error=-121 held=2

The first caller is told -ENOSPC ("retry later") although the transport is dead. The next unrelated caller pays the quarantine and loses a second program's memory to held. Suggest dropping -EREMOTEIO from that list, so an UNLOAD NAK quarantines at once, as ane_h16_session_close() already does for the same NAK. More generally, check s->transport->error before treating any failure as transient. The PR body also says "NAKs ... still quarantine", which this arm contradicts.

2. Please make the two descriptions agree. The comment in ane_fw_transport_shared() says the refused request "stays un-answered so firmware can retry it ... a wrap serves it again from scratch, granted if room freed up". The reviewer note says "a refused CREATE's firmware waiter never completes anyway". If the first is true, the firmware can still answer the CREATE after ane_fw_transport_wait() has handed its slot back and the UNLOAD or the next LOAD sits there. As far as I can see this fails closed: ane_h16_id_reply() and the LOAD/CREATE reply checks compare length and command id, so a stray CREATE answer becomes a reply error and a quarantine, not a silent mismatch. But no test covers it. A KUnit case where the fake answers the parked CREATE after the UNLOAD is posted would pin that down. The M5 row should also say whether the firmware ever answers a refused CREATE.

3. Note: programs held without quarantine stay pinned for the boot. s->held is only freed by ane_h16_session_recovered(), and that runs only on a recovery of a quarantined session. The "LOAD sent, answer lost" hold and the refused-UNLOAD hold both keep their memory, unquarantined, until reboot. That is the same class of leak this PR fixes, at a smaller scale. Either quarantine there (so recovery can run), or say in the comment that it is bounded and why.

4. Minor. The debugfs recover write bypasses hung_stop, a module parameter someone set off on purpose. It is root-only and logged, which is fine for a lab tool. It is separate from the refusal fix, though, and could be its own commit so the fix can land without it.

Still to run: the M5 hardware row from the PR's test plan.

@RyanTheTide

Copy link
Copy Markdown

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:

  1. ane_fw_transport.h:845-848: a refused request is consumed but never answered, so the firmware-side waiter (the CREATE's EXPP pool) stays blocked. The fixture accepts an UNLOAD while that CREATE is parked (ane_h16_program_test.c, create_blocked = false in the UNLOAD case), but on hardware the IO ring may be serialized behind the stuck CREATE. Then the UNLOAD in h16_failed_load() just times out, and we quarantine anyway, only later. This needs a hardware row before the design can be judged.
  2. ane_fw_transport.h:1000-1010: the wait writes the free marker into an IO slot the firmware still owns (header == tx->dva) and re-publishes into it. If the firmware ever completes the parked CREATE (e.g. after the "wrap serves it again" path grants the pool), its reply lands on the UNLOAD or the next LOAD, or it builds a process over program memory that has gone back to the spare pool. That is device-side use-after-free, not just a stale reply.
  3. Same hunk: ane_fw_transport_wait() now returns on any SHAREDMALLOC refusal, whatever the command being waited on, and it is shared with H16 startup/SUSPEND (ane_h16_boot.h:697, ane_h16_backend.c:287/304) and the H17 cold path (ane_fw_cold.c:444/1876). An EXECUTE/UNLOAD/SUSPEND that firmware is legitimately running gets retired. Keep polling until the deadline instead, and let only the command whose own request was refused fail. ane_fw_suspend_wait() (ane_fw_cold.c) also breaks on -ENOSPC now and never retires its slot.
  4. ane_h16_program.c:1086-1090: LOAD sent with its answer lost is "ownership unknown", which is exactly what quarantine exists for. Holding the program without quarantine means nothing ever frees it: s->held is only drained in ane_h16_session_recovered(). Repeat refusals fill the 128 records, and h16_load_room() then returns -ENOSPC for the rest of the boot. That is the same wedge, quieter.
  5. ane_h16_program.c:1108: -EREMOTEIO is a firmware NAK (ane_h16_id_reply()), so a NAKed UNLOAD is held without quarantine. That contradicts the PR text ("NAKs still quarantine") and hits the same leak as 4. -ENOSPC here can also be host arena exhaustion from h16_send(), not a refusal.
  6. Scope: the transport and ane_h16_program.c are shared by H16 (M4) and H17 (M5, via ane_fw_cold.c). The recover debugfs file exists only in the H16 backend, so it does nothing on the M5 where the bug was seen. A write that bypasses hung_stop is also a lab knob. Please drop it, or split it into its own PR.
  7. Root cause: ANE_FW_SHARED_TOTAL (12 MiB) is a host-side constant, not something the firmware reported. The refusal is ours. It may be worth checking whether that cap should be raised or derived before teaching every layer to survive it.
  8. Rows owed at this head: the M5 residency-probe repro (the pending item), plus a no-regression load/execute/close and s2idle row on an H16 M4 (J616s, J713), since the transport change reaches them too.
  9. Nit: the PR body ends with "Generated with [Devin]". Please make that an Assisted-by: line instead.

@joshuaswarren
joshuaswarren force-pushed the aurora-silicon/ane/shared-refusal-h16 branch from c16a72b to ff4b0a4 Compare November 22, 2026 20:00

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. §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. Keeping Assisted-by: at the end of the PR body is right; please strip it from both commits.
  2. h16_failed_load() returns -ENOSPC unquarantined 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 calls ane_fw_transport_fail(t, -EREMOTEIO), setting the sticky fatal t->error = -EREMOTEIO.
    • h16_failed_load() then excludes ret == -EREMOTEIO from h16_fail(), leaves s->quarantined = false, puts p on s->held, and returns error (-ENOSPC) — telling the caller to retry on a dead transport so the next unrelated caller takes the quarantine and leaks a second program into s->held (also contradicting the PR summary's claim that NAKs still quarantine).
    • Drop -EREMOTEIO from that arm and check s->transport->error (as well as s->quarantined, since h16_gate_release() at line 1099 already calls h16_fail() on error) before ever treating a failure as transient. Note also that h16_send() can return -ENOSPC from host command-arena exhaustion (__ane_fw_transport_publish() lines 424-428), not just a SHAREDMALLOC refusal.
  3. 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 to 1 without advancing t->head[ch], while h16_failed_load() sends UNLOAD into that slot and h16_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 = false when UNLOAD arrives (ane_h16_program_test.c:240). Nothing yet shows real M5/H17 firmware accepts UNLOAD on IO while CREATE is 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 across ane_h16_startup_commands() (ane_h16_boot.h:697, 726), ane_fw_exclave_mode_stop() (ane_fw_cold.c:444), h16_gate(), TERMINATE, UNLOAD, and EXECUTE. Additionally, ane_fw_suspend_wait() (ane_fw_cold.c:401-405) calls ane_fw_transport_shared() directly and breaks out on -ENOSPC/-ENOMEM without setting t->error or clearing t->pending[ANE_FW_IO].active, leaving the IO channel permanently stuck -EBUSY.
  4. Unquarantined s->held leaks memory and exhausts the 128 record slots (drivers/accel/ane/ane_h16_program.c:1086-1096, 1106-1111):

    • s->held is only drained in ane_h16_session_recovered() (after quarantine recovery). Appending p to s->held without quarantining — both on LOAD sent with answer lost (!loaded && sent) and on a failed fallback UNLOAD — permanently pins the program's DMA memory and its s->records bitmap bit for the rest of the boot. Repeated refusals exhaust ANE_H16_RECORDS (128) and wedge h16_load_room() with -ENOSPC until reboot.
    • Minor hygiene: bool sent in ane_h16_session_load() (ane_h16_program.c:1212-1231) is not reset to false before CREATE (and h16_send_at() only sets *sent = true, never false).
  5. <debugfs>/ane-h16/<dev>/recover is broken when hung_stop is off and out of scope (drivers/accel/ane/ane_h16_backend.c:1453-1466, 1508-1522, 2102-2158):

    • Direct bug: ane_h16_recover_work() uses h->recover_manual to bypass !ane_t6021_hung_stop, immediately clears h->recover_manual = false, and calls ane_t6021_restart_run(). Inside the restart sequence, ane_h16_rs_halt() (ane_h16_backend.c:1448) writes 0 to f->cpu_control (clearing RUN) and returns ANE_T6021_ASC_BUSY, after which ane_h16_rs_contain() (ane_h16_backend.c:1459-1460) still checks if (!ane_t6021_hung_stop) return -EOPNOTSUPP; — aborting recovery after halting the CPU, incrementing recover_failures, and leaving the session quarantined with RUN cleared 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).
  6. 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 debugfs recover knob, and host-side ANE_FW_SHARED_TOTAL root-cause question.
  • §3 Safety: Blocked — firmware-owned IO slot overwrite + spare-pool DMA UAF hazard, sticky-failed transport masked as -ENOSPC, unquarantined s->held leak, and ane_h16_rs_halt() clearing RUN before -EOPNOTSUPP abort.
  • §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 ff4b0a4d is 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>
@joshuaswarren
joshuaswarren force-pushed the aurora-silicon/ane/shared-refusal-h16 branch from ff4b0a4 to 71edfc6 Compare November 22, 2026 21:02
@joshuaswarren

Copy link
Copy Markdown
Author

Revised at 71edfc62ec2d (tests 6772cd6ca8d5). Per-finding:

  1. §4 trailers — stripped from both commits; Signed-off-by only. Assisted-by: stays in the PR body.
  2. h16_failed_load UNLOAD arm — now unconditional: any UNLOAD failure (NAK → sticky -EREMOTEIO, arena -ENOSPC, timeout, a gate-release failure that already quarantined) goes held + h16_fail. No unquarantined return on this arm; h16_fail is idempotent so a transport already sticky-failed still lands correctly.
  3. Transport wait/shared — wait() now takes refusal_dies; only LOAD/CREATE (which can park behind their own EXPP SHAREDMALLOC) opt in, on the load path and on replay. All other callers — suspend_wait's drain, exclave_mode_stop, startup commands, TERMINATE/UNLOAD/EXECUTE, backend waits — pass false and ride refusals out. New ane_transport_wait_refused_test covers a non-sensitive wait surviving a refusal mid-flight. Slot reclaim is now guarded: pending[ch] retires and the free marker is written only while the header still shows the published command; anything else is -EPROTO. The shared() comment no longer speculates about re-serve on wrap — consumed un-answered, the parked waiter never completes. Serialization of UNLOAD behind a parked CREATE is the open firmware question; it is now called out in the PR notes and is exactly what the M5 run must show.
  4. s->held leak — all three held arms now quarantine, so every held program drains through ane_h16_session_recovered() instead of pinning a record bit for the boot. *sent is reset at the top of h16_send_at().
  5. debugfs recover — dropped from this PR, along with recover_manual. The rs_contain hung_stop re-check behind rs_halt is real; if the knob comes back it needs its own change and its own test.
  6. ANE_FW_SHARED_TOTAL — it is a host-side constant taken from the k114c trace; the firmware does not report its quota, so refusals can only be observed, not anticipated — the transient path is needed whatever the value. Noted in the PR body.

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; checkpatch.pl --strict clean.

@RyanTheTide

Copy link
Copy Markdown

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, refusal_dies keeping refusals away from unrelated waits (and the suspend drain), the debugfs recover removal, the commit trailers and the PR footer. The ANE_FW_SHARED_TOTAL answer is fine.

Still open or new:

  • H17 cannot recover from a quarantine. ane_fw_cold.c has no .hung op, ane_fw_quarantine() says "reboot required" (ane_fw_cold.c:206), and ane_h16_session_recovered() is only reached from the H16 backend (ane_h16_backend.c:583). So on the M5 the quarantine arms in h16_failed_load() (ane_h16_program.c:1092, 1111) still wedge the device for the boot. If UNLOAD queues behind the parked CREATE, the M5 case is unchanged. Please say this in the h16_failed_load() comment and the PR text, and have the M5 row report which arm the probe takes.
  • After a successful UNLOAD, the program's surfaces go back to the spares (ane_h16_program.c:1115-1118) while the refused CREATE is still published and unanswered. The new header guard (ane_fw_transport.h:1020-1026) only checks the moment of reclaim. Whether the firmware ever completes that CREATE is still the M5 question. A KUnit case where the fake answers the parked CREATE after the UNLOAD is posted would at least pin down the host side.
  • A reply that arrives in the same pass as a refusal becomes fatal. If the command completes while alloc() runs, the header reads dva|1, and the reclaim fails the transport with -EPROTO (ane_fw_transport.h:1022-1026). Re-polling once before the reclaim would take the valid reply. reply_in_alloc with refusal_dies = true would test it.
  • h16_replay() passes refusal_dies = true (ane_h16_program.c:2158, 2167), but it quarantines on any error (2173). The early exit only frees a slot the firmware may still be parked on. false looks right there.
  • Nit: the comment above h16_failed_load() still says a host-side UNLOAD refusal "keeps the program held until close" (ane_h16_program.c:1069). The code now quarantines.

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)

@joshuaswarren

Copy link
Copy Markdown
Author

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, HEAD=71edfc62ec2d ./run.sh. It smokes LOAD/EXEC/close on a 64 KiB H16 program, suspends to s2idle for 20 s via rtcwake, reruns the smoke after wake, and writes a paste-ready REPORT-*.md. A SKIP report is evidence too — it means the ANE never reached the program stage on that boot.

If anyone with an M4 can run it, that closes the last hardware row.

@RyanTheTide

Copy link
Copy Markdown

H16 row at 71edfc6 on our J616s (M4 Pro, T6041), as asked above. The fleet81 default kernel with this PR's drivers/accel/ane built against it and loaded as modules, one boot per arm. Full logs are on our side, summary here.

m4-ane-packet-1. It runs, but the result comes from the packet, not the PR:

  • ane-h16-noregress.py:151 passes a c_uint32 as the memmove source. Python 3.15 (Fedora) raises TypeError: 'c_uint' object cannot be interpreted as ctypes.c_void_p right after LOAD. ctypes.byref(ctypes.c_uint32(...)) fixes it.
  • With that fixed, H16_LOAD passes but H16_EXEC of obj/add64-h16.hwx times out (-ETIMEDOUT). The driver then resets the engine (about 120 ms). This happens on this PR, on another ANE branch, and on the stock fleet81 driver, so the object hangs this engine. It doesn't look like a accel/ane: h16: keep a refused SHAREDMALLOC off the fatal path #2854 regression. The engine is fine afterwards (20/20 cycles with our add128 program).
  • s2idle: 20 s via rtcwake -d rtc1 -m freeze (rtc0 has no wake on these Macs; -m mem picks rtc0). Suspend and resume were clean, with no warnings, and LOAD works after wake.

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:

  • programs 1-4 load and run. LOAD 5 is the refused SHAREDMALLOC: SHAREDMALLOC refused ... error -28, then CREATE refused. The LOAD then waits about 3 s and returns -ETIMEDOUT, the session is quarantined (-110), the engine is reset, and all five programs are closed (0 programs replayed). The four resident programs' EXECs then fail with -EIO (80/80), and the later LOADs on the same files return -EIO.
  • Fresh programs work again after close (20/20), and so do the edge churn and 200 cycles.

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 CREATE refused. The journal ends there, and USB3 PHY RTKit timeouts were logged at the same moment. The watchdog reset it. A second, clean boot did not hang, so 1 of 2 runs.

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 DjDeveloperr left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. §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) causes h16_failed_load()'s fallback UNLOAD to time out after ~3 s (-ETIMEDOUT), quarantine the session (-110), reset the engine, and close all 5 programs with 0 programs replayed (all 4 resident programs then fail EXEC with -EIO 80/80 — worse than tip, which replayed the 4 residents). Moreover, 1 of 2 runs hung the machine outright ~6 s after CREATE refused and triggered a watchdog reset.
    • This shows real firmware's IO ring is serialized behind the parked CREATE (unlike the KUnit fixture's artificial f->create_blocked = false on UNLOAD at ane_h16_program_test.c:243).
    • On H17 (M5 k114c), ane_fw_cold.c has no .hung recovery op (ane_fw_quarantine() requires reboot; ane_h16_session_recovered() is only wired in ane_h16_backend.c), so the quarantine arms in h16_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 #2897 keeping residents intact with 0 refusals and 0 quarantines on the same J616s repro), the post-refusal UNLOAD/slot-reclaim design needs to be reconciled against real H16 and H17 firmware behavior before landing.
  2. §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 (the reply_in_alloc window with refusal_dies == true), the loop exits at line 990 with ret = -ENOSPC/-ENOMEM, enters lines 1010-1028, sees slot header dva | 1 != dva, and fatally fails the transport with -EPROTO instead of re-polling ane_fw_transport_poll(t, ch) to take the valid reply.
    • Even when header equals dva at line 1021, writing the free marker 1 into a firmware-owned IO slot without advancing t->head[ch] (and returning surfaces to spares on UNLOAD at ane_h16_program.c:1115-1118) still relies on firmware never later writing to that slot or using those surfaces.
  3. §2 Logic bug in h16_replay() (drivers/accel/ane/ane_h16_program.c:2158, 2167):
    • h16_replay() passes refusal_dies = true to h16_send_at() for both LOAD and CREATE, yet line 2172-2173 unconditionally calls h16_fail(s, ret) on any error. Passing true provides no recovery and only prematurely reclaims a firmware-owned IO slot right before quarantining; pass false there.

Non-blocking Nit

  • drivers/accel/ane/ane_h16_program.c:1068-1070: the comment above h16_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 UNLOAD behind the parked CREATE (3 s timeout, 0 programs replayed); h16_replay() passes refusal_dies = true unnecessarily.
  • §3 Safety: Blocked — reply_in_alloc race triggers fatal -EPROTO; firmware-owned IO slot overwrite / late-completion hazard; 1/2 J616s watchdog hang after CREATE refused.
  • §4 Clean-room & attribution: Pass — both commits (6772cd6ca8d5, 71edfc62ec2d) carry human author/committer and human Signed-off-by: only.
  • §5 Evidence: Blocked — Host tests and 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)

@github-actions github-actions Bot added area:media Area from CODEOWNERS (bot) changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:media Area from CODEOWNERS (bot) changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants