Skip to content

accel/ane: h17: recover a hung engine at runtime and across system sleep - #3030

Open
niteria wants to merge 4 commits into
aurora-silicon:integration/aurorafrom
niteria:ane/h17-hung-recover-rpm
Open

niteria wants to merge 4 commits into
aurora-silicon:integration/aurorafrom
niteria:ane/h17-hung-recover-rpm

Conversation

@niteria

@niteria niteria commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Problem

On H17 ANE, a request that never completes quarantines the session (h16_fail()), and the backend has no ops->hung handler: every later LOAD fails with -EIO until reboot. System sleep does not clear it either — the sleep path sends a STOP the hung firmware never answers, powers the engine off on the deep path and cold-boots it from the preload on resume, but never ends the session quarantine so the freshly booted firmware sits unused.

This replaces draft PR #1768 on top of integration/aurora (which now includes runtime PM / idle parking from #1863), incorporating @RyanTheTide's review feedback:

  • Dropped the failed-boot retry commit (keep hung-engine recovery focused).
  • Removed all new module parameters (hung_stop, hung_settle_ms, recover_burst, recover_window_s, recover_backoff_ms, recover_off_ms, recover_quiet_ms).
  • Replaced the fixed pre-powerdown sleep with bounded per-port DART-idle polling (ane_fw_dart_idle_wait(), 100 ms per port) so DMA is not cut off mid-flight.
  • Handled runtime PM interaction cleanly: ane_fw_staged_runtime_suspend() returns -EBUSY for a quarantined session without calling pm_runtime_mark_last_busy() or permanently quarantining the backend, and runtime recovery hands the device back to runtime PM idle parking once recovered.

Change

Four commits on drivers/accel/ane/ (ane_fw_cold.c, ane_fw_cold.h, ane_fw_cold_test.c, ane_h16_program_test.c):

  1. accel/ane: h17: recover a hung engine instead of keeping it until reboot
    • Wire ops->hung to queue recovery work (ane_fw_recover_work()), closing session admission, polling every ANE DART port for idle (up to 100 ms per port), and powering the engine down using the existing sleep/park power-down sequence (sub-block, PWGATE + ack, CPU, ANE_SYS via genpd; no new MMIO writes). Busy DART ports or a stuck power word fail runtime recovery and leave recovery to the next system sleep.
    • Require positive proof that the old firmware is gone (ane_fw_hung_gone(): GENPD_NOTIFY_OFF after power-down began with ANE_SYS PMGR actual state off, no active power references, and CPU + sub-block PMGR off) before clearing pool/IPC/heap/heap_tail, reloading digest-checked preload TEXT/DATA, ending session quarantine (ane_h16_session_recovered()), and replaying open programs behind their handles.
    • Handle a quarantined session on system sleep (skip futile STOP, request deep sleep, prove off on resume, cold boot and replay) and return -EBUSY from ane_fw_staged_runtime_suspend() while quarantined.
    • Expose recoveries and recover_failures in debugfs/ane-h17/<dev>/.
  2. accel/ane: h17: limit hung-engine recoveries
    • Pure state machine in ane_fw_cold.h with fixed circuit-breaker policy (max 5 recoveries in a 60 s sliding window, doubling backoff starting at 1 s) to prevent an ANE_SYS power-cycle storm from locking up the SoC (reproduced on J700 at 8 recoveries in 6 s). A 6th hang within 60 s keeps the session quarantined (-EIO) until the next system sleep, which recovers the engine and resets the limit.
    • Expose recover_limited in debugfs/ane-h17/<dev>/.
  3. accel/ane: h17: keep a hung engine off before booting it again
    • Enforce a 100 ms minimum ANE_SYS off hold after GENPD_NOTIFY_OFF before re-powering the engine during runtime recovery (matching normal power-cycle hysteresis rather than ~1 ms back-to-back cycles).
  4. accel/ane: h17: let a recovered engine settle before requests
    • Drain firmware posts until 100 ms quiet (bounded at +1 s) and verify ANE_SYS/CPU PMGR on, zero DART error bits, and healthy transport (ane_fw_recover_settled()) before replaying open programs and reopening the session.

Fixed constants rationale

  • ANE_FW_HUNG_DRAIN_MS (100 ms per DART port): matches macOS's DART-idle check before power-down with bounded polling so in-flight DMA finishes before ANE_SYS is cut.
  • ANE_FW_RECOVER_BURST / ANE_FW_RECOVER_WINDOW_S / ANE_FW_RECOVER_BACKOFF_MS (5 in 60 s, 1 s doubling backoff): crash-loop circuit breaker sized below the J700 storm failure threshold (8 rapid cycles in 6 s locked up the SoC) while allowing transient hangs to recover immediately.
  • ANE_FW_RECOVER_OFF_MS (100 ms): minimum ANE_SYS off-time hysteresis so runtime recovery does not bounce ANE_SYS back on within ~1 ms.
  • ANE_FW_RECOVER_QUIET_MS (100 ms): post-boot firmware settle quiet period before replaying programs and admitting waiting clients.

Testing

Local checks & unit tests

  • scripts/checkpatch.pl --strict --git 056cd33ebfde..HEAD: 0 errors, 0 warnings, 0 checks across all 4 commits.
  • arm64 W=1 builds of drivers/accel/ane/ (CONFIG_DRM_ACCEL_ANE=y, =m, and !CONFIG_PM): 0 new warnings.
  • arm64 QEMU KUnit (drivers/accel/ane/boot.kunitconfig): 270/270 passed (including 7 new tests: ane_cold_hung_gone_test, program_sleep_gate_quarantine_test, ane_cold_recover_storm_test, ane_cold_recover_backoff_test, ane_cold_recover_off_test, ane_cold_recover_settled_test, program_recover_gate_test).
  • tools/asahi/ane-tm-transient-fault-tests.py: PASS.

Live hardware testing — MacBook Neo (J700 / T8132)

Booted 7.3.0-pr-bdf20d05f7b4 cleanly on the default kernel command line (zero ANE/debug boot params, zero out-of-tree patches) via a one-shot test entry (pr-ane-hung-recover), then restored baseline gen 69 afterwards.

  • Boot & idle park: 400000000.ane starts suspended (recoveries=0, recover_failures=0, recover_limited=0).
  • Row 1 (runtime recovery + open-program replay + idle park): Loaded & ran add1024 (1024/1024 exact, 0 ulp), triggered hang on a second fd (ETIMEDOUT in 3.00 s) → runtime recovery completed in 229 ms (off 82 ms, 101 ms quiet settle, 1 programs replayed, recovery 1 of 5 within 60 s) → same open add1024 fd ran 0.81 ms, 1024/1024 exact, 0 ulp → closing fd cleanly stopped firmware (status 0x6e) and parked (suspended).
  • Row 2 (active sleep + 6-hang burst cap + exponential backoff + sleep recovery + limit reset):
    • Active rtcwake -m mem -s 8: deep sleep cleanly parked on resume (resume ok: parked until the next request), reset recovery window, and unparked + replayed add1024 (18.75 ms, 1024/1024 exact, 0 ulp).
    • Burst hangs 1–5 within 60 s: recovered 1/5, 2/5, 3/5, 4/5 (backs off 733 ms), 5/5 (backs off 4745 ms); add1024 bit-exact (1024/1024 exact, 0 ulp) after every recovery.
    • Hang 6 within 60 s: burst cap tripped (5 recoveries within 60 s: no more runtime recoveries; quarantined until the next system sleep, recover_limited=1, recover_failures=0); subsequent H16_EXEC immediately failed with -EIO.
    • rtcwake -m mem -s 12 while quarantined: deep sleep ran (hung engine powered off for system sleep (0)), resumed with quarantined engine recovered by system sleep; recovery limit reset (firmware ready 117 ms, 1 programs replayed), and the still-open add1024 fd ran 0.49 ms, 1024/1024 exact, 0 ulp.
    • Post-reset hang: recovered immediately (227 ms, off 81 ms, recovery 1 of 5 within 60 s, 0 ms backoff), add1024 0.50 ms, 1024/1024 exact, 0 ulp, then cleanly parked (suspended). Final counters: recoveries=8, recover_failures=0, recover_limited=1.
  • Regression tuple: 0 failed systemd units, 0 AVC / SELinux N/A (lsm=landlock,yama,bpf), 0 unexpected ANE/DART/PMGR kernel errors (only the intentional burst-cap line at hang 6).
Full J700 live test output and ANE/sleep dmesg excerpt
Found H17 device: /dev/accel/accel0
  [boot] rpm=suspended recoveries=0 recover_failures=0 recover_limited=0

=== ROW 1: Runtime recovery + open-program replay + idle park ===
  Initial add1024: load=13.0ms exec=1.58ms 1024/1024 exact max_ulp=0
  Hang #1 triggered: errno=ETIMEDOUT (110) in 3.00s
  Recovery #1 observed in 0.25s after hang close
  [after-row1-recover] rpm=active recoveries=1 recover_failures=0 recover_limited=0
  Post-recovery add1024 (same open fd): exec=0.81ms 1024/1024 exact max_ulp=0
  [after-row1-park] rpm=suspended recoveries=1 recover_failures=0 recover_limited=0

=== ROW 2: Active sleep sanity (resets window) + 6-hang burst cap + backoff + sleep recovery + limit reset ===
  Pre-sleep add1024 (keeps engine active for sleep): load=20.9ms exec=0.39ms 1024/1024 exact max_ulp=0
  Running rtcwake -m mem -s 8...
  [after-active-sanity-sleep] rpm=suspended recoveries=1 recover_failures=0 recover_limited=0
  Post-sleep add1024 (unpark + replay): exec=18.75ms 1024/1024 exact max_ulp=0
  Burst hang 1/5: hang_err=ETIMEDOUT (3.01s), recover_wait=0.25s, add1024=2.52ms 1024/1024 exact ulp=0
  Burst hang 2/5: hang_err=ETIMEDOUT (3.00s), recover_wait=0.25s, add1024=0.36ms 1024/1024 exact ulp=0
  Burst hang 3/5: hang_err=ETIMEDOUT (3.00s), recover_wait=0.25s, add1024=0.68ms 1024/1024 exact ulp=0
  Burst hang 4/5: hang_err=ETIMEDOUT (3.00s), recover_wait=1.00s, add1024=0.40ms 1024/1024 exact ulp=0
  Burst hang 5/5: hang_err=ETIMEDOUT (3.00s), recover_wait=5.11s, add1024=2.52ms 1024/1024 exact ulp=0
  [after-5-burst] rpm=active recoveries=6 recover_failures=0 recover_limited=0
  Burst hang 6 (expect cap): hang_err=ETIMEDOUT (3.00s)
  [after-6th-hang-quarantined] rpm=active recoveries=6 recover_failures=0 recover_limited=1
  Exec while quarantined: errno=EIO (5)
  Running rtcwake -m mem -s 12...
  [after-sleep-recovery] rpm=active recoveries=7 recover_failures=0 recover_limited=1
  Post-sleep-recovery add1024 (same open fd): exec=0.49ms 1024/1024 exact max_ulp=0
  Post-reset hang: hang_err=ETIMEDOUT (3.01s), recover_wait=0.25s, add1024=0.50ms 1024/1024 exact ulp=0
  [final] rpm=suspended recoveries=8 recover_failures=0 recover_limited=1

ALL LIVE J700 TESTS PASSED!
[   67.460678] ane_t6021 400000000.ane: H17 ANE: firmware recovered after a hung request in 229 ms (off 82 ms), 1 programs replayed; recovery 1 of 5 within 60 s
[   70.936882] ane_t6021 400000000.ane: H17 ANE: resume ok: parked until the next request
[   75.207174] ane_t6021 400000000.ane: H17 ANE: firmware recovered after a hung request in 230 ms (off 81 ms), 1 programs replayed; recovery 1 of 5 within 60 s
[   78.472823] ane_t6021 400000000.ane: H17 ANE: firmware recovered after a hung request in 228 ms (off 84 ms), 1 programs replayed; recovery 2 of 5 within 60 s
[   81.746740] ane_t6021 400000000.ane: H17 ANE: firmware recovered after a hung request in 233 ms (off 82 ms), 1 programs replayed; recovery 3 of 5 within 60 s
[   84.779728] ane_t6021 400000000.ane: H17 ANE: hung again within 60 s: recovery backs off 733 ms
[   85.774103] ane_t6021 400000000.ane: H17 ANE: firmware recovered after a hung request in 230 ms (off 81 ms), 1 programs replayed; recovery 4 of 5 within 60 s
[   88.798965] ane_t6021 400000000.ane: H17 ANE: hung again within 60 s: recovery backs off 4745 ms
[   93.906158] ane_t6021 400000000.ane: H17 ANE: firmware recovered after a hung request in 234 ms (off 81 ms), 1 programs replayed; recovery 5 of 5 within 60 s
[   96.931002] ane_t6021 400000000.ane: H17 ANE: 5 recoveries within 60 s: no more runtime recoveries; quarantined until the next system sleep
[   96.962106] ane_t6021 400000000.ane: H17 ANE: hung engine powered off for system sleep (0)
[   98.210219] ane_t6021 400000000.ane: H17 ANE: quarantined engine recovered by system sleep; recovery limit reset
[   98.210224] ane_t6021 400000000.ane: H17 ANE: resume ok: firmware ready 117 ms, first program ready 117 ms, node reopened 117 ms, 1 programs replayed
[  102.954280] ane_t6021 400000000.ane: H17 ANE: firmware recovered after a hung request in 227 ms (off 81 ms), 1 programs replayed; recovery 1 of 5 within 60 s
[  105.455751] ane_t6021 400000000.ane: H17 ANE: idle: parked until the next request

Still to run

  • Live hang-recovery hardware test on M5 MacBook Air (J813 / T8142) — shares the same H17 ane_fw_cold.c path with zero model gating.

Pre-PR Checklist

  • No model/board/firmware gating
  • Production-ready, zero new module parameters, default kernel command line tested
  • Clean-room verified; no AI commit trailers; human Signed-off-by only
  • checkpatch.pl --strict: 0 errors, 0 warnings, 0 checks
  • W=1 arm64 builds (=y, =m, !CONFIG_PM): 0 new warnings
  • KUnit (boot.kunitconfig, 270/270) and live J700 hardware test pass with baseline restored

Assisted-by: LLM (Gemini 4 Neon)

On H17 a request that never completes quarantines the session
(h16_fail()), and the backend has no ops->hung: every later LOAD fails
with -EIO until reboot. A system sleep does not help either. The sleep
path sends a STOP the hung firmware never answers, powers the engine
off on the deep path and boots it again from the preload on resume, but
nothing ends the session's quarantine, so the new firmware sits unused.

macOS restarts the firmware after a request timeout: it powers the
engine off, going on when the firmware never answers the stop, starts
it again cold and reloads the open programs. The H16 and T8112 paths do
the same. Do it on H17, at runtime and across a system sleep:

- ops->hung queues a recovery. It closes the session, polls every ANE
  DART port for idle (up to 100 ms per port) so no DMA is cut off
  mid-flight, and powers the engine off under the firmware with the
  power-down a sleep and a park already use: sub-block, PWGATE and its
  ack, CPU, then ANE_SYS through genpd, which deactivates the DARTs
  right before it goes off. The firmware is not asked to stop, and no
  new register is written. Outside a sleep, busy DART ports or a stuck
  power word fail the runtime recovery and leave recovery to the next
  system sleep instead of deferring to a deep path that does not come.

- A system sleep with a quarantined session (or one the closing gate
  release quarantines) powers the engine off the same way, without the
  futile STOP, and takes the deep path as the failed STOP made it do.

- Runtime suspend checks the session before and after closing it and
  returns -EBUSY without permanently quarantining the backend, leaving
  a quarantined session to the recovery work or the next system sleep.

Nothing the old firmware could reach is reused until it is proven gone:
after our power-down began, genpd must report ANE_SYS off with its PMGR
actual state (bits 7:4) reading off, nothing may hold ANE_SYS or the
child power states again, and the ANE CPU and sub-block power states
must read off now (PMGR, readable in any power state). We hold ANE_SYS
until the power-down puts it, so no earlier OFF can count. Only then
does the cold boot clear and reuse the pool, IPC ring, heap and heap
tail, copy TEXT and DATA from the kernel-held preload again (their
digests checked), and does ane_h16_session_recovered() end the
quarantine and give back the memory of programs closed while it lasted;
the open programs are then replayed behind their handles. The power-up
before the boot repeats the cold PMGR, PWGATE and DART checks of every
boot. Without that proof the session stays quarantined, its memory
held, and the next sleep tries again; a resume that cannot prove it
does not boot the engine at all. A boot or replay that fails after the
proof quarantines the engine until reboot, as any failed boot does.

debugfs ane-h17/<dev>/ gains recoveries and recover_failures.

Signed-off-by: Bartosz Nitka <niteria@gmail.com>
Every runtime recovery of a quarantined H17 session powers the engine
off under its firmware and boots it again, at once and as often as the
session is quarantined. On the J700 a client that kept loading programs
past the shared quota had its session quarantined again 0.6-1.2 s after
each recovery: eight recoveries in six seconds, each a forced ANE_SYS
power cycle, and right after the eighth the whole SoC locked up (no
network, a hard reset needed). Single recoveries had worked all day.

Limit them. The first recovery in a 60 s window runs at once; each later
one in the window waits 1 s after the one before, twice that for every
recovery already in the window, at most the window. A sixth hang within
the window stops runtime recoveries: the engine stays quarantined,
requests fail with -EIO and nothing reaches it, until a system sleep
powers it off and boots it again (which also resets the limit). While a
recovery waits out its backoff the session stays quarantined the same
way; a sleep drops the waiting recovery and recovers the engine itself.

Recoveries are logged with their place in the window, a backoff and the
stop each once; debugfs recover_limited counts refused recoveries. The
storm above would have recovered at 0, 1, 3, 7 and 15 s and stopped at
its sixth hang.

The limit is a pure state machine in ane_fw_cold.h. KUnit: the storm's
timeline, backoff doubling and its cap, the sliding window, the burst
bounds, a clock that went back, and reset.

Signed-off-by: Bartosz Nitka <niteria@gmail.com>
A runtime recovery booted the engine again as soon as genpd reported
ANE_SYS off: the proof was followed by the cold boot's power-up at
once, so the domain stayed off for about a millisecond. Every other
power cycle of this engine keeps it off for seconds (an idle park for
at least its autosuspend delay, a system sleep for the whole sleep). On
the J700 a storm of eight such recoveries in six seconds, each with
ANE_SYS back on within a millisecond, ended in a SoC lockup.

Record when genpd's OFF proved the hung engine gone and keep ANE_SYS
off for 100 ms from then before the proof is checked and the engine
booted again. The recovery log line gives the time waited.

KUnit: the wait from the OFF, with no OFF recorded, one in the future,
and no minimum.

Signed-off-by: Bartosz Nitka <niteria@gmail.com>
After a recovery's cold boot the session reopened at once: open
programs were replayed and waiting requests went in right after the
firmware's startup commands, with nothing checked of the engine the
power cycle left behind. On the J700, after the eighth recovery of a
storm a waiting client sent LOAD and CREATE within a millisecond of
the reopen; its log ends at the third LOAD, where the SoC locked up.

Before the replay and before the session reopens, serve what the new
firmware posts (its own SHAREDMALLOCs) until it has been quiet for
100 ms (at most a second more), then read the engine: ANE_SYS and the
ANE CPU power state on, no DART fault, and the transport not failed.
The sub-block power state and CE are not judged: the running firmware
gates the engine itself. Requests wait in ane_h16_session_enter()
meanwhile, as during the rest of the recovery. An engine that reads
anything else fails the recovery and is quarantined, with what it read
logged. A system sleep that recovers a quarantined engine takes the
same step.

KUnit: the health check, field by field; and at the session level,
what the gating relies on: while a recovery waits out its backoff the
quarantined session refuses requests with -EIO and no traffic; while
it runs, a client's LOAD waits, also through the cold boot and the
replay, and goes through on the new firmware only once the session
reopens.

Signed-off-by: Bartosz Nitka <niteria@gmail.com>

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Formal §1–§6 pre-PR review at verified head 3963bf32061eeadc813163dee370cdf80ae51348.

  • Code, concurrency & safety (§2–§3):
    • Bounded per-port DART-idle polling (ane_fw_dart_idle_wait, 100 ms/port) before cutting power prevents mid-flight DMA abort; busy DARTs or stuck power words safely abort runtime recovery and defer to deep system sleep.
    • Positive off-proof (ane_fw_hung_gone(): hung_down release -> GENPD_NOTIFY_OFF + ane_fw_sys_off acquire/release -> hung_off_at + live PMGR CPU/sub-block check) ensures no pool/IPC/heap/DATA or closed-program memory is reused while old firmware could still touch it.
    • Runtime PM and sleep interaction are deadlock-free: ane_fw_recover_work() runs pm_runtime_get_noresume() + pm_runtime_barrier() before b->lock, ane_fw_staged_runtime_suspend() returns -EBUSY cleanly while quarantined, and PM_SUSPEND_PREPARE / ane_fw_staged_exit() call cancel_delayed_work_sync(&b->recover) outside b->lock.
    • Circuit breaker (5 in 60 s, 1 s doubling backoff capped at window, reset on sleep), 100 ms ANE_SYS off hold, and 100 ms post-boot quiet settle + health check (ane_fw_recover_settled()) are cleanly separated into pure KUnit-tested helpers (ane_fw_cold.h).
  • §1 / §4 / §6: Zero model/board gating, zero new module parameters, all 4 commits carry human author/committer + human Signed-off-by: only (0 AI trailers), checkpatch.pl --strict 0/0/0, W=1 0 warnings, host-tests SUCCESS (MERGEABLE/CLEAN).
  • §5: KUnit 270/270 + live J700 exact-head default-cmdline test covering runtime recovery, open-program replay, 6-hang burst cap/backoff, sleep recovery + limit reset, post-reset recovery, idle park (1024/1024 exact max_ulp=0, 0 failed units, 0 unexpected errors).

Approved for the merge train.

Assisted-by: LLM (Gemini 4 Neon)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants