Skip to content

accel/ane: check H16/H17 DMA bases and LOAD sections against the program, and pin EXECUTE buffers before locking - #2876

Merged
RyanTheTide merged 5 commits into
aurora-silicon:mainfrom
funkzy:pr/ane-h16h17-checks
Nov 26, 2026
Merged

RyanTheTide merged 5 commits into
aurora-silicon:mainfrom
funkzy:pr/ane-h16h17-checks

Conversation

@funkzy

@funkzy funkzy commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

What: Validate H15/H16/H17 ANE DMA bases per task against each bound buffer (refusing zero widths and unifying the H15 8-word / H16–H17 9-word task framing walk), require LOAD procedure and text-properties sections to match the validated program byte for byte, and pin or bounce EXECUTE user buffers before taking the driver locks.

Tested: J775D M5 Ultra at cd4666bbd23e: exact-head A/B row on main 8f99a858b456 plus local die-0 ANE DT opt-in df27feb3e7ab (27.2 stub, published Aura aura-main-7bf44a63): on-hardware ANE KUnit 304 pass / 0 fail / 1 skip (16 modules, ane-h16-tasks 17/17), A.hwx 1000/1000 & B.hwx 200/200 bit-exact, h17-mobilenet 16/16 top-1, dma-buf heap 50/50 + 20/20, 5/5 hostile DMA bases and 7/7 malformed LOAD sections refused (ENOEXEC), 5 s FUSE fault unblocked (25.0 ms vs 4726.0 ms baseline), 0 new kernel errors (8 vs 8), 2/2 baseline failed units (ALARM, no SELinux). host_tests_vm.sh 686/686 pass; mil-hwx-compiler corpus 222/224 pass (s_mm_256 real OOB and matmul_gelu_256 omitted widths refused), 3,786/3,786 mutations refused.

Risk: two-way door · M3 (H15), M4 (H16), and M5 (H17) Macs using the accel/ane H16 backend; per-task register reset is measured on H17 (J775D), inferred for H16 from the compiler corpus, and unmeasured on H15 (fails closed if a real H15 stream relocates on slot 5 or omits required DMA fields).

Not yet: H16 (M4 / M4 Pro, e.g. J616s or J713) hardware row at cd4666bbd23e (MobileNet, #1882/#2748 programs, s_mm_256 baseline check, and 2-task reset probe); M3 (H15) hardware LOAD row; tree-supported J775D die-0 ANE DT opt-in (local commit df27feb3e7ab is not a PR yet).

Details

Problem

Three gaps in the H15/H16/H17 LOAD and EXECUTE paths:

  • DMA bases. The task-stream validator checks a program's framing, register allowlist, BAR table, and operation-section slot bindings, but did not bound DMA base records against the buffers their slots bind.
  • LOAD sections. The procedure and text-properties sections went to firmware after a size check only, and reserved bytes in the generic and operation sections were unchecked.
  • EXECUTE copies. Without DRM_ANE_H16_EXEC_IN_PLACE, input/output user copies ran under the node lock, where a slow page fault stalls every other client and PM drain, and nests mmap_lock inside the driver locks (inverting ane_h16_mmap()).

Why this shape

  • One source for sizes and framing: ane_h16_operation_validate() builds the bound-slot table once, and all three passes (structural gate, HWX relocation check, DMA check) now share one framing walker ane_hx_task_frame() and one record counter ane_hx_record_count(), parameterized by hwx->task_header_words from the HWX target table (8 on H15, 9 on H16/H17). Removing the separate 9-word copy fixes an out-of-step walk on live M3 (H15) streams.
  • Per-task reset model instead of a cross-task image: J775D two-task probes showed that an omitted output base or row stride runs with reset value 0 rather than carrying over from an earlier task, and valid L2-resident/multi-task schedules omit reset-valued words. Checking each task strictly on its own words over reset values accepts all 8 corpus programs previously refused by the cross-task image while also requiring enabled coefficient DMAs (and slot-4 relocated config words) to bind their base in the same task.
  • Fail closed on unbounded extents: refusing zero width on enabled input/output DMAs, zero depth/group/output-channel counts with non-zero strides, zero coefficient lane sizes, and conflicting duplicate writes within a task ensures the kernel never admits a transfer it cannot bound or one that stalls H17.
  • Lock-free EXECUTE pinning/bouncing: user pages are pinned before taking any driver lock and copied through kmap_local_page() under the node lock; unpinnable VM_PFNMAP/VM_IO ranges are validated across every VMA and bounced outside both locks.
  • Selection without chip gates: checks follow the HWX target table, program format, and ioctl, with no per-chip special cases.

Change

  1. d80bb1356d30 accel/ane: keep every H16/H17 DMA base inside the buffer its slot binds: LOAD-time DMA base and transfer-extent validation against bound slot buffers (ENOEXEC before mapping).
  2. 68bc9a8c583c accel/ane: send H16/H17 LOAD only the section bytes the validator checked: derive expected procedure and text-properties sections from the validated program and require reserved bytes in generic/operation sections to be zero.
  3. 35b9d3b40af5 accel/ane: h16: copy EXECUTE buffers without user faults under the node lock: pin user pages (or bounce validated VM_PFNMAP/VM_IO ranges) outside the file and node locks.
  4. cd4666bbd23e accel/ane: bound each H15/H16/H17 task's DMAs on its own words (after merge 7b774dee929b of main):
    • Check each task on its own words over reset values, accepting all 8 previously refused mil-hwx-compiler H16G programs (space-to-depth, depth-to-space, attention fixture, 5 L2-resident MobileNet schedules) and closing the single-task unbased coefficient DMA gap (idle LUT lanes 0x20 allowed; active lanes require a relocated base).
    • Unify task framing across structural gate, HWX relocation check, and DMA check into ane_hx_task_frame() using hwx->task_header_words (8 on H15, 9 on H16/H17), with H15 KUnit coverage.
    • Refuse zero width on enabled input/output DMAs (fixes the H17 stall/quarantine case), zero depth/group/output-channel counts when their stride is non-zero, zero coefficient lane sizes, slot-4 relocated config words that do not already enable their DMA, and differing duplicate writes within one task.
    • Corpus diagnosis (224 mil-hwx-compiler programs): 222/224 pass; s_mm_256 is a real OOB read (0x40000 past its coefficient base on a 0x20000 buffer; bit 2 of word 0x3c does not change stride units, confirmed by the attention fixture's two coefficient DMAs); matmul_gelu_256 omits its widths and is refused per the zero-width rule.
Evidence

Testing

  • Own-base J775D A/B row at cd4666bbd23e — kit pr2876-m7 (window pr2876m7@20261125-1729) vs baseline kit pr2876-m7b (window pr2876m7@20261125-1729), built on main 8f99a858b456 with one local need: df27feb3e7ab (arm64: dts: apple: t6050-j775d: enable the Neural Engine on die 0, the J775D die 0 Neural Engine opt-in, local, not yet a PR) plus CONFIG_KUNIT=m and the ANE KUnit test modules as =m. Booted on the 27.2 stub with published Aura aura-main-7bf44a63 (ro), default command line:
Check pr2876-m7 (PR) pr2876-m7b (base)
Boot & ANE bring-up BOOT-OK, firmware_stage=program, accel0 BOOT-OK, firmware_stage=program, accel0
On-hardware ANE KUnit (16 modules) 304 pass, 0 fail, 1 skip (ane-h16-tasks 17/17, ane-h16-program 65/65, ane-h16-hwx 20/20, ane-h16-accel 4/4) 289 pass, 0 fail, 1 skip
part1.py (A.hwx × 1000 / B.hwx × 200) 1000/1000 (p50 125.7 us), 200/200 (p50 163.5 us) bit-exact 1000/1000, 200/200 (p50 158.1 us) bit-exact
h17-mobilenet (16 images, 50 timing runs) 16/16 top-1 (p50 2.618 ms) 16/16 top-1 (p50 2.494 ms)
dma-buf heap (plain/all/inputs/output) 50/50 (A), 20/20 (B), 0 errors / 0 inexact 50/50 (A), 20/20 (B), 0 errors / 0 inexact
Hostile DMA bases (s26) 5/5 OOB refused (ENOEXEC), A7 in-range +0x2000 ok (0 quarantine) —
LOAD section mutations (sections) 7/7 mutated sections refused (ENOEXEC), controls ok (0 quarantine) 4/4 baseline accepted, controls ok
5 s FUSE page-fault stall (fuse) a_still_stalled_when_b_done=true, b_wall_ms=25.0, load_ms=4.3, 20/20 ok a_still_stalled_when_b_done=false, b_wall_ms=4726.0, load_ms=4702.7
Failed units / kernel errors 2/2 baseline (iwd, systemd-networkd-persistent-storage), 8 errors (0 new); ALARM (no SELinux) 2 failed units, 8 errors
  • VM & host verification at cd4666bbd23e:
    • host_tests_vm.sh (ht-2876m2): 686/686 passed (rc 0).
    • Host KUnit (ane_h16_tasks_test): 17/17 pass (0 fail).
    • mil-hwx-compiler corpus: 222/224 pass (s_mm_256 real OOB and matmul_gelu_256 omitted widths refused); 3,786/3,786 mutations refused.
    • checkpatch.pl --strict: 0 errors, 0 warnings, 0 checks; W=1 ANE build: 0 warnings.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Review at b29dac1.

Thanks for this, the DMA model and the lockdep/fault-hold rows are well done. Some things I'd like settled before merge:

  1. ane_h16_tasks.h:269-274, 336-399: each task's bases are checked against that task's words over the engine defaults, and the PR says carry-over between tasks was not checked. If the engine does keep registers, the check can be bypassed: task N sets large strides/dims and writes no base (so nothing is checked), then task N+1 writes an in-range base and leaves the strides out (defaults, small extent). It also works the other way round, with the base kept and the geometry changed. Could you either show on hardware that each task starts from defaults (a two-task program that would fault if state carried over), or also check each written base against a running image across tasks? Real programs repeat every word, so the running image should only refuse programs that are already out of bounds. A KUnit case for either form would help.
  2. ane_h16_tasks.h:392-394: offset + round_up(extent, 64) is only the end of the last line touched when the offset is 64-byte aligned. With offset 1 and extent 64 the engine reads [0, 128) but the check computes 65. Either refuse unaligned bases or compare ALIGN(offset + extent, 64). With bytes == allocation the extra bytes go into the next DVA page.
  3. Compatibility: the check refuses every DMA register it does not model (bias, post-scale and palette tables, compression, crop and so on). The accel/ane: accept H17 programs from Apple's zin_ane_compiler 10.205 (on #1790) #1882 zin 10.205 programs and the accel/ane: h16, h17: load programs with int8 and uint8 surfaces #2748 int8/uint8 programs are real inputs that load today and have not been run through it. Quantized or palettized models seem the most likely to use those registers. I think that corpus run (and the same corpus against the exact-form procedure/text-properties check) is needed before merge, not after. Separately, is the refused H16G matmul example a real out-of-bounds write by the compiler (did it run correctly before?) or a gap in the model? Either answer is useful, but it should be stated.
  4. ane_h16_accel.c:193: pin_user_pages_fast() fails on VM_PFNMAP/VM_IO mappings, where copy_from_user() used to work. drm_gem_shmem mmaps (drm_gem_shmem_helper.c:1044, used by the GPU driver) and CMA-heap dma-buf mmaps are VM_PFNMAP, so EXECUTE from a mapped GPU buffer now returns EFAULT. If that's intended, please say so in the commit. Otherwise, falling back to a bounce copy done outside both locks for such ranges would keep the old behaviour.
  5. ane_h16_program.c:968-971: the new comment says the node lock must never be taken under the mmap lock, but ane_h16_mmap() (ane_h16_accel.c:401-417) takes f->lock and, via ane_h16_session_enter(), the node lock under it. The constraint after this change is the reverse: nothing may fault or take the mmap lock while holding the node lock. Could the comment say what the work-item deferral actually still avoids?
  6. Rows: the only hardware row is J775D die 0, with arm64: dts: apple: t6050: share the Neural Engine with every board #2293 and an unposted DT commit on top. Still needed at this head: an H17 row on a tree-supported M5 without extra DT, and H16 rows (J616s and J713) running a real model (mobilenet plus one zin-compiled program) bit-exact, plus one refused out-of-bounds LOAD. The H16 path has only the host corpus check so far.

The pin/unpin error paths look right to me: every exit after a pin goes through unpin:, the second check under f->lock covers a reload in between, and outputs are only marked dirty after a successful run.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Review notes on the DMA base check (commit 1). I read it; no build.

  1. Please also require, in every task, a relocated base record for each DMA that the task enables (TileDMA source/destination, KernelDMA, NLut). As written, the extent check runs only where a relocated base pair is present (ane_h16_tasks.h around 381-395), so a task that enables a DMA without writing its base is not bounded. The base it uses then depends on engine defaults or on the previous task, which the PR text says was not checked.
  2. The allowed register blocks that the check does not model (0x4100-0x41a4, 0x44d0, 0x4500-0x453c, 0x4900-0x4930, 0x5900-0x5930) accept any value. Could these be held to zero as the other unmodelled DMA registers are, or could the commit message say why each holds no address?
  3. Small hardening, same reasoning as the strict choice for unmodelled registers: refuse zero dimensions instead of treating them as 1, bound the channel-group field (common 0x40 & 7) to what the compiler emits, and refuse format bits the compiler never sets, so the extent rules cannot be under-estimated by a decoding difference.

Commits 2 and 3 look right to me. A minor point: buffers backed by VM_PFNMAP mappings now fail to pin where they used to be copied. That seems acceptable, but it might be worth a line in the commit message.

A task names each buffer the engine reads or writes as a relocated
[lo, hi] record, whose 64-bit offset is taken relative to the DVA of the
buffer bound to the record's BAR slot. The validator checked that each
register lies in a known block and that the operation section binds
each slot to the right resource, but not the offset, nor that the slot
is bound, nor that a base is relocated at all.

At LOAD, once the operation section is checked and before anything is
mapped, walk every task:

- A DMA base (the input DMA's sources 1 and 2, the output DMA, the
  coefficient DMA and the lookup table) is written only by a relocated
  record covering exactly its lo and hi words, on a slot the operation
  section binds.
- The end of the last 64-byte line its transfer touches,
  ALIGN(offset + extent, 64), stays inside that buffer: a surface's
  declared size, the scratch's __bss size, or the kernel section to the
  end of its last 16 KiB page, which is what the kernel slot maps. The
  offset is unsigned, so a negative one fails; products and sums are
  overflow-checked.
- An input or output extent is width x element bytes x interleave, plus
  (rows - 1) x row stride, (channel groups - 1) x plane stride,
  (depth - 1) x depth stride and (groups - 1) x group stride, the
  interleave packing that many channels per plane. The coefficient
  extent is its furthest lane (offset plus size, at least the aligned
  per-channel size) plus each further group and output channel group, a
  channel group being 16 << (common word 0x40 & 7) channels. The lookup
  table is its size word, at least 64.
- A task that enables an input DMA source, the output DMA or the lookup
  table (a non-zero configuration word) writes that DMA's base in the
  same task, and a height and channel count that are not zero. A zero
  width, depth or group count is read as one: the compiler writes 0
  there, and a zero width is in a 256 x 256 matmul that runs correctly
  on an M4 Pro. Lookup-table tasks configure the coefficient DMA without
  a base, so that DMA is bounded by the running image below instead.
- Fields the extent rules decode stay within what the compiler writes:
  the output channel group (0x40 & 7) at most 5, and no format bits
  besides the interleave, the element size and the bits every program
  sets.
- The only other relocated records are the cache-allocation words on
  the custom BAR slot 4. Dense header bits 21, 22 and 30, and a slot
  without the relocation bit, are refused.
- The DMA registers the bound does not model stay zero: metadata and
  compression, texture, crop and wrap, the bias, post-scale and
  palette tables, the destination pixel offset, and the wrap and
  offset fields beside the cache hints and formats. They stay refused
  until a program needs them. Outside the DMA blocks, 0x44d0 stays zero
  and the cache DMA block takes only the six words the compiler
  writes. The L2, planar engine and neural engine blocks configure
  on-chip buffers and arithmetic, and cannot be relocated, so they hold
  no buffer address.

Whether the engine starts each task from its defaults or keeps
registers from the task before is not known, so both readings are
checked: each task over the defaults, and a running image carried
across the stream, against which every base written so far is checked
after each task with the geometry in force then. Programs leave a word
out wherever it holds the default, also when an earlier task set
another value. Where that leaves an earlier base with a larger extent,
the stream fits only the first reading and is refused. Refusals are
ENOEXEC, as for the validator's other program checks.

No register documentation is available. The extent rules are read from
the encoder of aurora-silicon/mil-hwx-compiler and checked against
programs whose bound lands exactly on their buffer.

Of the 224 H16G and H17 programs that aurora-silicon/mil-hwx-compiler
builds from its fixtures and examples, a mobilenet in every schedule it
accepts and the two KUnit fixtures, 215 pass, most of them with the
bound exactly equal to the buffer, and every H17 program among them.
The running image refuses 8 H16G programs (space-to-depth,
depth-to-space, an attention fixture and five L2-resident schedules of
the linked mobilenet). One H16G matrix-multiply example is refused
under both readings: it gives two 128-channel output groups a channel
group stride of 0x40000 over a 0x20000 scratch.

KUnit: ane_hx_dma_bound_test and ane_hx_dma_kernel_test cover a base
exactly at the end of its buffer, one line past it, negative, wrapping
64 bits, on an unbound slot, unrelocated, scattered, relocated off its
pair, and beside an unmodelled register. ane_hx_dma_carry_test covers
geometry in one task with the bases in the next, and a base kept while
a later task enlarges its geometry. ane_hx_dma_strict_test covers an
enabled DMA without its base or with a zero size, the channel group,
a format bit and the registers outside the DMA blocks.
ane_hx_dma_align_test covers a lookup table at offset 1, which touches
two lines. program_add128_dma_test runs the cases through the add-128
fixture's LOAD checks. The mobilenet and add-128 fixture cases still
pass.

On a J775D (die 0, 27.2 firmware) add-128 x1000 and a [1,128,16,16] add
x200 stay bit exact, the linked mobilenet program classifies 16 of 16
images, and programs whose bases leave their buffers are refused at LOAD
before anything is mapped.

Reported-by: Erik Bourget <[email protected]>
Suggested-by: Erik Bourget <[email protected]>
Signed-off-by: Jeff Queisser <[email protected]>
…cked

H16_LOAD takes four host-built sections. The generic and operation
sections were checked against the HWX field by field, but not their
reserved bytes, and the procedure and text-properties sections only for
their size. The text properties give the firmware the task stream's
framing: segment offset, segment size and task count. The kernel
validates the stream as it frames it, from its prologue with the HWX's
task count, so properties that frame it differently describe a stream
nobody checked.

Both sections have one form, which the selftests' h16-sections.py writes
and the kernel now derives from the validated program: one procedure,
and one text segment covering the whole task stream with its task count.
H16_LOAD refuses any other size or byte. The reserved bytes of the
generic header and of each entry, and an operation record's bytes after
its last reference, must be zero, and an entry's tail word must be
ANE_H16_GENERIC_ENTRY_TAIL, as h16-sections.py writes them. Refusals are
ENOEXEC, before anything is mapped or sent.

The add-128 and mobilenet sections that h16-sections.py builds, which
the KUnit fixtures carry, are exactly the kernel's form.

KUnit: program_sections_exact_test refuses another task count, segment
offset or size, a longer section, a changed procedure, and a nonzero
reserved byte in each place above, and refuses such a LOAD before any
mapping or firmware traffic. The session tests now pass the procedure
and text properties h16-sections.py writes instead of zeroes.

On a J775D (die 0, 27.2 firmware) add-128 x1000 and a [1,128,16,16]
add x200 stay bit exact and the linked mobilenet program classifies 16
of 16 images; sections in any other form are refused at LOAD.

Reported-by: Erik Bourget <[email protected]>
Suggested-by: Erik Bourget <[email protected]>
Signed-off-by: Jeff Queisser <[email protected]>

@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 review at b29dac1a746c.

The overall architecture (LOAD-time DMA base bounding, exact-form section validation, and lock-free user page pinning in EXECUTE) is strong, lockdep/fault-hold testing on J775D is thorough, and §1 (no chip gates), §4 (human commits + Signed-off-by/Reported-by/Suggested-by, clean-room, PR Assisted-by), §6 (naming), and CI (host-tests) pass.

Blockers to address before merge:

  1. Blocker — Commit 1 (ane_h16_tasks.h:269-274, 336-399): Unverified cross-task register carry-over and missing required-base enforcement:
    • ane_hx_dma_image() resets img[] to defaults on every task, and the PR notes that register carry-over across tasks was not checked on hardware.
    • If the engine retains state across tasks, the validator is bypassable in both directions: task N writes large dims/strides with no base record (nothing checked), and task N+1 writes a base while omitting strides (validated against small defaults, executed with task N's strides), or vice versa.
    • Similarly, ane_hx_task_stream_dma_validate() only checks extent where a relocated [lo, hi] base record is written, without requiring every DMA enabled by a task to write a relocated base.
    • Fix: either prove on hardware (e.g. a two-task fault test) that hardware resets DMA/common state per task and require a relocated base for each enabled DMA, or maintain a running register image across tasks and validate every enabled DMA on every task.
  2. Blocker — Commit 1 (ane_h16_tasks.h:392-394): Unaligned base offset breaks 64-byte line rounding:
    • Checking offset + ALIGN(extent, 64) <= bound[slot] under-estimates the last byte touched when offset is not 64-byte aligned (e.g. offset = 1, extent = 64 computes last = 65, while 64-byte DMA lines covering [offset, offset + extent) span [0, 128)). Either reject unaligned offsets (offset & 63) or bound ALIGN(offset + extent, 64) with overflow checking.
  3. Blocker — Commit 1 compatibility corpus & unmodelled blocks:
    • The strict allowlist rejects registers it does not model, yet existing supported #2748 int8/uint8 programs and #1882 zin-compiled programs have not been checked against the new DMA and exact-section validators, and the refused H16G matmul example has not been diagnosed (real compiler OOB vs. extent-model gap). Please run that corpus check before merge so working userspace is not regressed.
    • Also document (or bound) why the other allowed blocks in ane_h16_register_valid() (0x4100-0x41a4, 0x44d0, 0x4500-0x453c, 0x4900-0x4930, 0x5900-0x5930) cannot carry DMA addresses or offsets.
  4. Blocker — Commit 3 (ane_h16_accel.c:193, ane_h16_user_pin wrap edge case, ane_h16_program.c:968-971):
    • pin_user_pages_fast() returns -EFAULT on VM_PFNMAP/VM_IO mappings (such as drm_gem_shmem GPU mmaps or CMA dma-buf mmaps) where copy_from_user()/copy_to_user() previously worked. Either explicitly document this UAPI change in the commit message or provide an unlocked bounce-copy fallback for VM_PFNMAP ranges.
    • In ane_h16_user_pin() (ane_h16_accel.c:42-45): DIV_ROUND_UP(u->offset + size, PAGE_SIZE) > INT_MAX can wrap to 0 when u->offset + size > SIZE_MAX - (PAGE_SIZE - 1) (e.g. ptr = PAGE_SIZE - 1, size = SIZE_MAX - (PAGE_SIZE - 1) passes ptr + size >= ptr, overflows DIV_ROUND_UP to 0, and returns 0 with u->count = 0). Bounded by surface size in the ioctl path today, but the helper itself should check size > (size_t)INT_MAX * PAGE_SIZE - u->offset (or check_add_overflow) cleanly.
    • ane_h16_program.c:968-971: the updated comment says the node lock must never be taken under the mmap lock, which contradicts ane_h16_mmap() (ane_h16_accel.c:300-316) taking f->lock and a->lock under the mmap lock. The actual ordering after commit 3 is mmap_lock -> f->lock -> a->lock (nothing may fault/take mmap_lock under a->lock, and ane_h16_export_put() defers because h16_give_back() calls it under a->lock and vma_close under mmap_lock).
  5. Blocker — §5 hardware coverage:
    • Only J775D die 0 (with #2293 + an unposted DT commit, ALARM without SELinux AVC counts) has been tested. Still needed: a tree-supported H17/M5 row without out-of-tree DT, and H16 hardware rows (M4 / M4 Pro) running real models (MobileNet + zin/int8) plus out-of-bounds LOAD refusal with full regression counts.

@funkzy
funkzy force-pushed the pr/ane-h16h17-checks branch from b29dac1 to 1c027e7 Compare November 23, 2026 16:36
@funkzy

funkzy commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks to both of you. This covers Ryan's two comments and dj's review together. The new head is 1c027e7. Points follow Ryan's first comment; his second is marked R2, and dj's blockers 1-5 map to Ryan's 1, 2, 3 with R2-2, 4 with 5, and 6.

1, R2-1: task state and enabled DMAs. Both readings are now checked. Each task is checked on its own words over the defaults, as before. A running image carried across the stream is checked as well: after each task, every base written so far is checked against the geometry in force then. In addition, a task that enables an input DMA source, the output DMA or the lookup table (any non-zero configuration word) must write that DMA's base in the same task, with a non-zero height and channel count. ane_hx_dma_carry_test covers your two forms. Geometry in task N with the bases alone in N+1 is now refused by the enable rule. A base kept while task N+1 enlarges the geometry is refused by the running image.

Two limits:

  • Real programs don't repeat every word, it turns out. The encoder leaves out words that hold the default, even when an earlier task set another value. The running image therefore refuses 8 of the 224 compiler programs: H16G space-to-depth, depth-to-space, an attention fixture and five L2-resident schedules of the linked mobilenet. Every H17 program and the default H16G mobilenet pass. The commit message says so.
  • The coefficient DMA can't be held to the enable rule. Lookup-table tasks set its configuration word without writing a base (46 tasks across the corpus). It is bounded by the running image instead.

To check per-task register reset directly on the J775D's H17, I ran two-task variants of the [1,128,16,16] fp16 add program (task 0 computes z + z = 0 into output0 with full registers; task 1 computes x + z with x rows 0..15 set to 1.0..16.0, omitting one register at a time):

  • Control (task 1 writes all registers): rows 0..15 = [1.0, 2.0, ..., 16.0] bit-exact, 0 DART faults.
  • Omit output row stride 0x5110 in task 1 (on anechk6): rows 0..15 = [16.0, 0.0, ..., 0.0] (all 16 rows wrote to row 0, leaving task 0's zeros in rows 1..15; 0 faults, 0 timeouts).
  • Omit input0 row stride 0x4d18 in task 1 (on anechk6): rows 0..15 = [1.0, 1.0, ..., 1.0] (task 1 read row 0 for all 16 rows; 0 faults, 0 timeouts).
  • Omit common widths 0x04/0x14 in task 1 (on anechk6): EXECUTE timed out and the firmware quarantined the program (firmware_stage program wedged, quarantine count 1), with 0 DART faults (widths did not carry 16 from task 0). That also leaves an open question in Still to run: on H17 an omitted width stalls rather than running as width 1, and whether width 0 can reach past its buffer before stalling is not yet checked.
  • Omit output DMA base 0x5108 in task 1 (on base kernel anechk6b): output0 stayed 0.0 with IOMMU write faults from IOVA 0x0, showing 0x5108 reset to 0 at the task boundary.
  • Omit input0 DMA base 0x4d10 in task 1 (on anechk6b): inconclusive. output0 stayed 0.0, which carrying task 0's zero input base also predicts, and the IOMMU fault log was rate-limited after 0x5108 logged 10 lines immediately before it.

This confirms H17 resets the output DMA base and the output and input0 row strides, and does not carry common widths, while input-base reset remains unproven. The running image stays enabled on every chip (no chip gate): on H17 it refuses nothing, and it is what bounds the coefficient DMA in lookup-table tasks as well as any unproven input-base carry.

2: line end. ALIGN(offset + extent, 64) (overflow-checked) is now compared with the buffer size. ane_hx_dma_align_test covers a 64-byte table at offset 1: refused at 100 bytes, accepted at 128. It fails on the old check.

R2-2: unmodelled blocks. Zero isn't possible for most of them, since every program writes them. Instead:

  • 0x44d0 is never written by the compiler and must now be zero.
  • The cache DMA block (0x5900-0x5930) takes only the six words the compiler writes. None of them is an address.
  • The L2 (0x4100), planar engine (0x4500) and neural engine (0x4900) blocks configure on-chip buffers and arithmetic: L2 offsets and strides, operation selectors, fp32 and fp16 constants, mode bits. None of their records may carry the relocation bit, so none of them is given a buffer's address.

The commit message gives the per-block reason.

R2-3: decode hardening.

  • An enabled DMA with a zero height or channel count is refused.
  • A zero width, depth or group count is still read as one. The compiler writes 0 for depth and groups in nearly every task, and width 0 appears in the 256 x 256 matmul that ran correctly on an M4 Pro (the compiler's J616s receipt), so refusing it would refuse a working program.
  • The output channel group (0x40 & 7) above 5 is refused; 5 is the largest the corpus uses.
  • Format bits are now limited to the interleave, the element size (kept for 8-bit surfaces) and the bits every program sets.

ane_hx_dma_strict_test covers each refusal.

3: corpus. I don't have the #1882 programs or the #2748 int8/uint8 programs. The tree has only synthetic fixtures for both, and mil-hwx-compiler builds int8 only for H13/H14. So neither ran here, on the host or on hardware. This stays open before merge.

  • DMA check, with everything above: 215 of 224 compiler programs pass. The 8 are listed in point 1, plus the matmul below.
  • Exact-form sections: for all 225 programs (the 224 plus the rank-3 matmul below), the tree's h16-sections.py builds the procedure and text-properties sections byte-for-byte equal to the form the kernel derives.

The refused H16G matmul (s_mm_256, one of the compiler's chain examples) has no hardware run, so I can't say whether it ran correctly before. The same-size rank-3 matmul that ran correctly on an M4 Pro (mm256 in that receipt, rebuilt bit-identical) passes. In the coefficient registers, the refused program differs from it only in bit 2 of word 0x3c and in an output-group stride of 0x40000 against 0x10000, the group size. If that bit changes the stride's unit, this is a gap in the model, and the fix is a rule taken from the encoder. Otherwise the program reads past its scratch. A run of s_mm_256 on an M4 under a kernel without the check, compared with a CPU reference, would settle it; it is in the H16 rows below.

4, R2 note: unpinnable buffers. Not intended, thanks. When pinning fails and the range reaches a VM_PFNMAP or VM_IO mapping, the buffer is bounced:

  • An input is copied into a kernel buffer when it is taken, with no lock held.
  • An output is copied back after both locks drop, and only if the request ran.
  • Unmapped memory and read-only outputs still fail before the request.

ane_h16_accel_user_bounce_test marks a mapping VM_IO to cover this.

dj's wrap case in ane_h16_user_pin() is fixed. The size is now checked against INT_MAX pages before the page count is computed, so DIV_ROUND_UP() can no longer wrap to 0. ane_h16_accel_user_pages_test covers your example (ptr = PAGE_SIZE - 1, size = SIZE_MAX - (PAGE_SIZE - 1)) and one page past the limit. On the J775D, EXECUTE stays bit exact with its buffers in a dma-buf system heap mmap: all buffers there, only the inputs, or only the output.

5: comment. The comment now gives the order that must not happen: the mmap lock, or a user fault, taken under the node lock. Taking the node lock under the mmap lock is what ane_h16_mmap() does. It also says what the work item still avoids: a last put from h16_give_back(), which already holds the node lock, and a munmap() or exit that would otherwise wait under the mmap lock for a running request.

6: rows. The J775D row at the new head is in the body. KUnit passes 279/0/1. The add programs stay bit exact, the mobilenet classifies 16/16, and every out-of-bounds and section case is refused at LOAD. A second client's LOAD takes 4.7 ms while one client's page fault is held, and the lockdep run reports nothing. It still needs #2293 and our J775D die 0 Neural Engine opt-in, e9754164afe3. That is a DT-only commit enabling die 0's ANE in t6050-j775d.dts; it is not posted, and nothing else in the row depends on it. Still to run: the H16 rows (J616s and J713, the mobilenet and one program from the #1882 set, bit-exact, plus one refused out-of-bounds LOAD, the two-task per-task reset probe above, and s_mm_256 under a kernel without the check for point 3), an H17 row on a tree-supported M5 without extra DT, and the #1882 and #2748 programs through both checks. I'll add each as it comes in.

Assisted-by: LLM (Claude:Opus 5.5), LLM (Gemini:Neon)

@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.

Re-review of 1c027e781aaa86cde7e21f92135b6f4467281a77 against pre-pr-checklist.md (§1–§6) (CI: Host tests / host-tests SUCCESS; MERGEABLE / CLEAN, non-draft).

Resolved since b29dac1a746c

  • Dual per-task + running-image DMA checks, enabled-DMA base requirement, overflow-checked ALIGN(offset + extent, 64), unmodelled-block audit (0x44d0 zeroed, cache DMA allowlist, non-relocatable L2/PE/NE blocks), decode hardening (ane_hx_dma_strict_test), ane_h16_user_pin() INT_MAX * PAGE_SIZE wrap fix, VM_PFNMAP/VM_IO bounce path, corrected ane_h16_export_put() lock-order comment, and J775D per-task reset probes are all solid improvements.
  • §1, §4, §6: Clean — no chip gates; all 3 commits carry human author/committer + human Signed-off-by: (Reported-by:/Suggested-by:) only, zero AI commit trailers; PR body discloses Assisted-by:; naming clean.

Remaining blockers before approval

  1. New code bug — drivers/accel/ane/ane_h16_accel.c:74-125 (ane_h16_user_unpinnable() / ane_h16_user_bounce() / ane_h16_user_get()):
    • ane_h16_user_unpinnable(ptr, size) returns true as soon as it sees any VM_PFNMAP | VM_IO VMA in [ptr, ptr + size) without checking VM_WRITE or verifying that the entire [ptr, ptr + size) range is mapped with no holes.
    • For a read-only VM_PFNMAP/VM_IO output (or a VM_PFNMAP/VM_IO VMA followed by an unmapped hole or read-only VMA), ane_h16_user_pin(..., write=true) returns -EFAULT, ane_h16_user_unpinnable() returns true, and ane_h16_user_bounce(..., write=true) skips copy_from_user() and returns 0. The ANE request then executes on hardware before ane_h16_user_put() fails on copy_to_user(), contradicting the commit message and ane_h16_user_get() doc comment ("Unmapped memory and read-only outputs still fail before the request"). (ane_h16_accel_user_bounce_test missed this because ro did not have VM_IO set.)
    • Fix: pass write to ane_h16_user_unpinnable(), walk the full [ptr, ptr + size) range with no gaps, require VM_WRITE on every VMA when write is true (and VM_READ when !write), return true only if the entire range is validly mapped and at least one VMA has VM_PFNMAP | VM_IO, and add KUnit coverage for a read-only VM_IO output and a VM_IO + unmapped-hole range.
  2. Compatibility corpus blockers (open before merge):
    • #1882 (zin-compiled) programs and #2748 (int8/uint8) programs have still not been run through the DMA or exact-section checks (host or hardware).
    • The running image refuses 8 mil-hwx-compiler H16G programs (space-to-depth, depth-to-space, attention fixture, and 5 L2-resident MobileNet schedules) that omit default words after an earlier task set them, and the refused H16G matmul s_mm_256 remains undiagnosed (real compiler OOB vs missing stride-unit rule for word 0x3c bit 2).
  3. §3 H17 zero-width hazard: The J775D probe showed omitting common widths (0x04/0x14) on H17 stalls and quarantines the program (firmware_stage program wedged), while ane_hx_dma_tile() still accepts width 0 as 1; confirm whether width 0 on H17 can reach past its buffer before stalling (or tighten accordingly once H16 mm256 vs H17 behavior is settled).
  4. §5 Hardware coverage: Still only tested on J775D die 0 with #2293 + an unposted out-of-tree DT commit (e9754164afe3, ALARM/no SELinux). Still needed before merge: a tree-supported H17/M5 row without out-of-tree DT, and H16 hardware rows (M4 / M4 Pro, e.g., J616s and J713) running MobileNet + #1882/#2748 programs bit-exact, refused OOB LOAD, s_mm_256 baseline check, and the two-task per-task reset probe with full regression counts.

…de lock

Without DRM_ANE_H16_EXEC_IN_PLACE, H16_EXEC copied each input from user
memory into its surface, and each output back, with the node lock held
and the request counted active. A page fault in those copies waits for
whatever backs the page, and for that long every other client's LOAD,
EXECUTE, mmap and close waited on the lock, as did the PM notifier's
drain at suspend, which waits for no request to be active. The fault
also takes the mmap lock, while mmap() of a surface takes the file and
node locks under it.

Pin the user pages of every buffer with no driver lock held: outputs
with FOLL_WRITE, so a buffer that cannot be written fails here with
EFAULT instead of after the request ran. The buffers are checked against
the loaded program before pinning, and again under the file lock after
it, since the program may have changed in between. Under the node lock
the copies go through the kernel mapping of the pinned pages and cannot
fault; the pages are unpinned, outputs marked dirty, after both locks
are dropped. There is still one copy each way.

Pages in a VM_PFNMAP or VM_IO mapping cannot be pinned, and EXECUTE
from a mapped GEM-shmem or dma-buf heap buffer worked with
copy_from_user() before. A buffer that reaches such a mapping is bounced
instead: an input is copied into a kernel buffer when it is taken, with
no lock held, and an output is copied back to user memory after both
locks are dropped, only if the request ran. Unmapped memory and
read-only outputs still fail before the request.

The comment on ane_h16_export_put() said an EXECUTE may wait for the
mmap lock while holding the node lock, which is no longer true. It now
gives the order that must not happen, the mmap lock or a user fault
under the node lock, and what the deferral to a work item still avoids:
a last put from h16_give_back(), which holds the node lock, and a
munmap() that would wait under the mmap lock for a running request.

KUnit: ane_h16_accel_user_pages_test pins an input and an output that
cross a page boundary, compares the copies with copy_from_user() and
copy_to_user(), and fails the pin, holding nothing, for an unmapped
buffer, a read-only output, a range that wraps and a size whose page
count would wrap;
ane_h16_accel_user_bounce_test finds a VM_IO mapping in a range, takes
an input and an output through the bounce copy, leaves an output the
request did not write unchanged, and still fails a read-only output
when taken.

On a J775D (die 0, 27.2 firmware) another client's LOAD and EXECUTEs
complete while one client's input page fault is outstanding, where they
waited for it before. The add programs stay bit exact, and the
mobilenet program classifies 16 of 16 images at a p50 request latency
of 2.55 ms, as before (2.56 to 2.59 ms). EXECUTE with its buffers in a
dma-buf system heap mmap stays bit exact (all buffers, only the inputs,
only the output).

Reported-by: Erik Bourget <[email protected]>
Suggested-by: Erik Bourget <[email protected]>
Suggested-by: Bartosz Nitka <[email protected]>
Signed-off-by: Jeff Queisser <[email protected]>
@funkzy
funkzy force-pushed the pr/ane-h16h17-checks branch from 1c027e7 to 35b9d3b Compare November 23, 2026 23:56
@funkzy

funkzy commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Updated in 35b9d3b40af5 to fix item 1 (ane_h16_user_unpinnable()):

  • ane_h16_user_unpinnable(ptr, size, write) now walks the full [ptr, ptr + size) range with no gaps (!vma || vma->vm_start > addr), requires VM_WRITE when write is set (and VM_READ otherwise) on every VMA in the range, and returns true only if the entire range is validly mapped and at least one VMA carries VM_PFNMAP | VM_IO. Read-only VM_IO/VM_PFNMAP outputs and VM_IO ranges extending into an unmapped hole now fail ane_h16_user_get() with -EFAULT before bouncing or executing.
  • ane_h16_accel_user_bounce_test (ane-h16-accel) now covers both a read-only VM_IO output and a VM_IO mapping followed by an unmapped hole, verifying ane_h16_user_unpinnable() and ane_h16_user_get(..., true) == -EFAULT with u.bounce == NULL and u.pages == NULL.

Arm64 KUnit on 35b9d3b40af5 (base 110861f4333e4, CONFIG_DRM_ACCEL_ANE=y with DRM_ACCEL_ANE_KUNIT_TEST, DRM_ACCEL_ANE_FW_KUNIT_TEST, and DRM_ACCEL_ANE_PM_KUNIT_TEST built in):

  • ANE suites (18/18): 302 of 303 cases pass, 0 fail, 1 skip (ane-fw-cold/ane_cold_no_clpc_test: CLPC enabled; absence is covered by the CLPC suite).
  • Suites modified by this PR: ane-h16-accel 4/4 (ane_h16_accel_user_pages_test, ane_h16_accel_user_bounce_test pass), ane-h16-tasks 11/11, ane-h16-program 61/61.
  • Full boot KUnit total: 28 suites, 344 of 346 cases pass, 0 fail, 2 skip (apple_mbox_g17_stall/apple_g17_rx_util_min_test needing CONFIG_UCLAMP_TASK, plus ane_cold_no_clpc_test above).

Items 2–4 (the #1882/#2748 corpus checks, the 8 refused mil-hwx-compiler H16G programs and s_mm_256 diagnosis, the H17 zero-width check, and the remaining H16 and tree-supported H17 hardware rows) remain open and will be added as they come in.

Assisted-by: LLM (Gemini:Neon)

@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 checklist re-review at verified live head 35b9d3b40af538b0a912a2d2851a125149920806 (MERGEABLE / CLEAN, CI 1/1 green: Host tests / host-tests).

Resolved Since 1c027e781aaa

  • Prior Blocker #1 (ane_h16_user_unpinnable() / bounce validation) — FIXED: drivers/accel/ane/ane_h16_accel.c:77-100 now walks the entire [ptr, ptr + size) range with no gaps (!vma || vma->vm_start > addr), requires VM_WRITE when write is set (VM_READ otherwise) on every VMA in the range, and returns true only when the entire range is validly mapped and at least one VMA carries VM_PFNMAP | VM_IO. ane_h16_accel_user_bounce_test covers both a read-only VM_IO output and a VM_IO + unmapped-hole range, and arm64 KUnit at 35b9d3b40af5 passes 302/303 ANE cases (0 fail, 1 skip) including ane-h16-accel 4/4, ane-h16-tasks 11/11, ane-h16-program 61/61.

Checklist Summary

  • §1 No model gating: Pass (program-format/ioctl-driven, no chip gates).
  • §2 Production-ready, no hacks: Code in commit 3 is clean; compatibility corpus questions remain open (Blocker 1).
  • §3 Safety: Strong LOAD-time DMA bounding and lock-free user pinning/bouncing; H17 zero-width hazard remains open (Blocker 2).
  • §4 Clean-room & attribution: Pass — all 3 commits carry human author/committer (Jeff Queisser <[email protected]>) and human Signed-off-by: / Reported-by: / Suggested-by: only, zero AI trailers in commits; PR body disclosure present.
  • §5 Evidence: Blocked — see Blockers 1–3.
  • §6 Naming: Pass.

Remaining Blockers (acknowledged open in 23:57Z comment)

  1. §2 / §5 — Compatibility corpus & refused H16G programs:
    • #1882 (zin-compiled) and #2748 (int8/uint8) programs have still not been run through the DMA or exact-section validators (host or hardware).
    • 8 mil-hwx-compiler H16G programs (space-to-depth, depth-to-space, attention fixture, 5 L2-resident MobileNet schedules) are refused by the running-image check, and the refused H16G matmul s_mm_256 remains undiagnosed (real compiler OOB vs missing stride-unit rule for word 0x3c bit 2).
  2. §3 — H17 zero-width behavior: Omitting common widths (0x04/0x14) on J775D H17 stalled and quarantined the program (firmware_stage program wedged), while ane_hx_dma_tile() accepts width 0 as 1. Confirm whether width 0 on H17 can touch past its buffer before stalling (or tighten once H16 mm256 vs H17 behavior is settled).
  3. §5 — Multi-Mac & exact-head hardware coverage: No hardware run at 35b9d3b40af5 yet; still needed before merge: a tree-supported H17/M5 row without out-of-tree DT, and H16 hardware rows (M4 / M4 Pro, e.g., J616s and J713) running MobileNet + #1882/#2748 programs bit-exact, refused OOB LOAD, s_mm_256 baseline check, and the two-task per-task reset probe with full regression counts.

@github-actions github-actions Bot added area:media Area from CODEOWNERS (bot) changes-requested A reviewer requested changes (bot) needs-hw-row No hardware row at the PR head (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

@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.

Verdict: FINISH, then merge at 35b9d3b40af5

Blockers:

  1. Shown on the J775D: a program that leaves out the common widths (0x04/0x14) stalled the H17 and quarantined it (firmware_stage program wedged), yet ane_hx_dma_tile() accepts width 0 as 1. So the new validator lets through a program that wedges the engine. Fix: refuse width 0 on H17 (or wherever the firmware doesn't define it) at LOAD, with a KUnit case.
  2. The new running-image check refuses 8 mil-hwx-compiler H16G programs (space-to-depth, depth-to-space, the attention fixture and 5 L2-resident MobileNet schedules), plus s_mm_256. If those run on main, this turns working programs into refusals. Fix: show for each that it really reaches outside its buffers (then the refusal is right), or adjust the rule (for example the stride unit for word 0x3c bit 2).
  3. Missing row at this head: an H16 Mac (J616s or J713) running MobileNet bit-exact with an out-of-bounds LOAD refused, and the M5 row without out-of-tree DT once the T6050 ANE is in the tree.

Checked: no Apple material, no gates. The LOAD-time DMA bounding and the user-buffer pinning and bouncing are a solid design, and the KUnit coverage is broad. This replaces my earlier review. You listed these as open in your 11-23 note, so this is the same list in short form.

Evidence

Read the three commits and your 11-23 23:57 note.

@DjDeveloperr
DjDeveloperr dismissed stale reviews from themself November 24, 2026 19:56

Superseded by the review at 35b9d3b

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merge readiness at cd4666bb: ready to merge

Check Detail
CI at head ok 19 checks passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok in the PR body at cd4666bb
Conflicts ok none
PR text ok Risk: two-way · M3 (H15), M4 (H16), and M5 (H17) Macs using the accel/ane H16 backend; per-task register reset is measured on H17 (J775D), inferred for H16 from the compiler corpus, and unmeasured on H15 (fails closed if a real H15 stream relocates on slot 5 or omits required DMA fields).

Areas: area:media
Merge: gh pr merge 2876 --merge (Owners and Core through the bypass: add --admin).

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

The DMA check also carried a register image across the tasks of a stream
and, after each task, checked every base written so far against the
geometry in force then. That models an engine that keeps the registers a
task leaves out. The engine starts each task from the reset values: on
the J775D's H17, a second task that leaves out the output base or a row
stride runs with the reset value 0, and one that leaves out the widths
does not run with the first task's. Valid programs rely on this: they may
leave out any word that holds its reset value, even after an earlier task
wrote another value there. So the carried image refused eight programs of
the corpus below that stay inside their buffers. An L2-resident task
that takes its input from L2 was checked against the earlier task's input
base. A task that leaves a group count or a plane stride at its reset
value was checked with the earlier task's value.

Check each task on its own words over the reset values only. No base can
reach a later task, because every DMA a task enables must have its base
in that task. That rule now covers the coefficient DMA too, which only
the carried image bounded, because lookup-table tasks set its lane
configuration words without a base. Those lanes are idle: 0x20 in the
low half (0x30020 and 0x50020 in the corpus). Any other non-zero lane
word enables the DMA and needs the base. Before this, a one-task stream
could enable the coefficient DMA without a base and nothing checked it.

Walk the stream with the header words of the program's target. The DMA
check had its own copy of the task framing, fixed at the nine header
words of H16 and H17. H15 tasks have eight, so on an H15 stream it read
each task's first record as a header word and the records after it out
of step: a row stride written in that first record went unchecked, and
the rest of the task could be hidden in what it read as L2 values. The
structural gate, the HWX validator's relocation check and the DMA check
each walked the framing in their own code. They now share one walk,
ane_hx_task_frame(), and one record count, with the header words that
the HWX target gives, which struct ane_h16_hwx now records for the DMA
check.

A word of the checked blocks written twice in one task must repeat its
value, and a base its slot too. An H17 program writes source 2's base
twice, unchanged. The check kept only the last write, so a first write
could name any address or stride unchecked. No program in the corpus
writes any other word twice.

A configuration word relocated on the slot 4 custom BAR takes the custom
BAR value, which the check does not see, so it must already enable its
DMA. Zero, or an idle lane, could become a DMA the check saw as off.
Every such word in the corpus enables its DMA.

Refuse a zero width on an enabled input or output stream instead of
reading it as one. A task without widths stalled the J775D's H17, and an
H16 matmul without them computed its full 256-wide result, so the kernel
cannot bound what a zero width moves. For the same reason a zero depth,
group or output channel count is read as one only when its stride is
zero, and a coefficient lane of size 0 is refused: at the end of its
buffer, its offset passed with nothing to read. No program in the corpus
has any of these.

Over 224 programs built with mil-hwx-compiler, 222 pass. Two are refused:
- The H16G chain example s_mm_256 reads its second output channel group
  0x40000 bytes past its coefficient base, beyond the 0x20000-byte buffer
  the first task fills. The other matmul form of the same size strides
  0x10000, where those coefficients are. Bit 2 of common word 0x3c, set
  only in this form, does not change the unit: the attention fixture's
  two coefficient DMAs with that bit set read exactly what an earlier
  task wrote.
- The H16G fixture matmul_gelu_256 leaves its widths out. The other
  fixtures in the corpus include them.
The corpus has no H15 program; the H15 framing is covered by KUnit.

Signed-off-by: Jeff Queisser <[email protected]>
@funkzy
funkzy requested review from a team as code owners November 26, 2026 03:07
@funkzy
funkzy requested review from LiamRay11 and malik-na November 26, 2026 03:08
@funkzy

funkzy commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@DjDeveloperr Pushed cd4666bbd23e (accel/ane: bound each H15/H16/H17 task's DMAs on its own words on top of a merge of main) addressing the review findings, and re-verified on J775D:

  1. Zero-width refusal (Blocker 1): ane_hx_dma_tile() now refuses zero width on enabled input/output DMAs instead of reading it as 1, and ane_hx_dma_count() refuses zero depth/group/output-channel counts when their stride is non-zero (plus zero coefficient lane sizes), with KUnit coverage (ane-h16-tasks 17/17).
  2. Corpus refusals (Blocker 2): Replaced the cross-task running register image with per-task validation over reset values (matching the J775D 2-task probes), while requiring enabled coefficient DMAs and slot-4 relocated config words to bind their base in the same task and refusing differing duplicate writes. Over the 224 mil-hwx-compiler programs, 222/224 now pass (all 8 previously refused H16G programs pass) and 3,786/3,786 mutations are refused. The two remaining refusals are:
    • s_mm_256: genuine out-of-bounds read (0x40000 past its coefficient base on a 0x20000 buffer; bit 2 of common word 0x3c does not change the stride unit, confirmed by the attention fixture's two coefficient DMAs).
    • matmul_gelu_256: leaves its widths out, so it is refused under the zero-width rule above.
  3. Additional hardening (M3/H15): Unified the structural gate, HWX relocation walk, and DMA check onto one ane_hx_task_frame() / ane_hx_record_count() walker using hwx->task_header_words (8 on H15, 9 on H16/H17), fixing an out-of-step DMA walk on live M3 (H15) streams, with H15 KUnit tests.
  4. Exact-head J775D A/B row (cd4666bbd23e): kit pr2876-m7 (window pr2876m7@20261125-1729) vs baseline kit pr2876-m7b (window pr2876m7@20261125-1729), on main 8f99a858b456 plus local need df27feb3e7ab (the J775D die 0 Neural Engine opt-in, local, not yet a PR), 27.2 stub, published Aura aura-main-7bf44a63: on-hardware ANE KUnit 304 pass / 0 fail / 1 skip (16 modules), A.hwx 1000/1000 & B.hwx 200/200 bit-exact, h17-mobilenet 16/16 top-1, dma-buf heap 50/50 + 20/20, 5/5 hostile DMA bases and 7/7 malformed LOAD sections refused (ENOEXEC), 5 s FUSE stall unblocked (25.0 ms vs 4726.0 ms baseline), 0 new kernel errors (8 vs 8), 2/2 baseline failed units (ALARM, no SELinux). host_tests_vm.sh 686/686 pass.

Still open for peer hardware coverage (Blocker 3): an H16 (M4 / M4 Pro, e.g. J616s or J713) row at cd4666bbd23e (MobileNet, #1882/#2748 programs, s_mm_256 baseline check, 2-task reset probe) and an M3 (H15) LOAD row.

@github-actions github-actions Bot added blast:m3 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) and removed needs-hw-row No hardware row at the PR head (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 26, 2026

@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.

Code approved at cd4666bbd23e. The validator now rejects enabled transfers with a missing width and checks each task against its own buffer bounds. All eight H16G programs from my earlier review pass the author's corpus check. The two remaining refusals are accounted for. The J775D run also passed MobileNet and the LOAD checks.

Hold merge for the H16 hardware result. Per-task reset was measured on H17, and the H15 task header changed too. I’ve asked for the H16 MobileNet and reset checks and a known-good H15 LOAD on this head. The J775D result used the author's local device-tree opt-in. Hardware and corpus results

@DjDeveloperr
DjDeveloperr dismissed their stale review November 26, 2026 03:31

Superseded by the review at cd4666b

@github-actions github-actions Bot removed changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 26, 2026
@erikwb

erikwb commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Note

🤖 Claude Opus 5.5 responding on behalf of erikwb

J713 (M4 Air, H16) at cd4666bbd23e: MobileNet and the new refusals PASS; per-task reset not measured; #2748 int8 not run. Kernel: the PR head merged onto our daily J713 27.2 stack (99fc34a5c4bd; the stack doesn't touch drivers/accel). One-shot boot, default cmdline, daily restored afterwards. A/B against the daily (same stack, no PR).

Evidence
  • MobileNetV1 224 (H16G, open compiler, dequantized Apache-2.0 weights), 16 images: DRAM-linked 28-task program b1d27309201e 16/16 top-1 on both kernels. L2-resident schedule f705b8bf5505 16/16 on both. 0 ANE/DART faults.
  • Open-compiler corpus (mm128/512, add/mul/gelu/exp at 128 and 512): all within tolerance on both kernels.
  • s_mm_256 and matmul_gelu_256: LOAD on the daily, refused with ENOEXEC on the PR head. mm768/1536/3072, add/mul/gelu/exp 2048 and attn4h load on both.
  • 2-task reset probe: the DRAM control passes on both. The L2 variant (6b9ed508f0a7, task 1 leaves out task 0's source DMA) is accepted by the PR validator, but on both kernels the firmware never completes its LOAD (ETIMEDOUT). So H16 per-task reset values are still unmeasured, and the failure is in the probe, not the PR. The driver quarantined the session, restarted the engine from the preload in 110–116 ms, and every later program passed on both kernels.
  • accel/ane: accept H17 programs from Apple's zin_ane_compiler 10.205 (on #1790) #1882 changes H17 rules only: nothing H16-runnable. accel/ane: h16, h17: load programs with int8 and uint8 surfaces #2748's H16 int8/uint8 cases are macOS-compiled programs from the author's local kit, not in any aurora-silicon repo, so they weren't run here.
  • 0 failed units on both kernels. 0 new kernel error classes on the PR head vs the daily.

@github-actions github-actions Bot added the ready-to-merge Meets the merge policy: merge it (bot) label Nov 26, 2026
@RyanTheTide
RyanTheTide merged commit 6cb2228 into aurora-silicon:main Nov 26, 2026
39 of 40 checks passed
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) blast:m3 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants