Repository navigation
accel/ane: check H16/H17 DMA bases and LOAD sections against the program, and pin EXECUTE buffers before locking - #2876
Conversation
|
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:
The pin/unpin error paths look right to me: every exit after a pin goes through |
|
Review notes on the DMA base check (commit 1). I read it; no build.
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]>
There was a problem hiding this comment.
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:
- 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()resetsimg[]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.
- 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 whenoffsetis not 64-byte aligned (e.g.offset = 1, extent = 64computeslast = 65, while 64-byte DMA lines covering[offset, offset + extent)span[0, 128)). Either reject unaligned offsets (offset & 63) or boundALIGN(offset + extent, 64)with overflow checking.
- Checking
- Blocker — Commit 1 compatibility corpus & unmodelled blocks:
- The strict allowlist rejects registers it does not model, yet existing supported
#2748int8/uint8 programs and#1882zin-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.
- The strict allowlist rejects registers it does not model, yet existing supported
- Blocker — Commit 3 (
ane_h16_accel.c:193,ane_h16_user_pinwrap edge case,ane_h16_program.c:968-971):pin_user_pages_fast()returns-EFAULTonVM_PFNMAP/VM_IOmappings (such asdrm_gem_shmemGPU mmaps or CMA dma-buf mmaps) wherecopy_from_user()/copy_to_user()previously worked. Either explicitly document this UAPI change in the commit message or provide an unlocked bounce-copy fallback forVM_PFNMAPranges.- In
ane_h16_user_pin()(ane_h16_accel.c:42-45):DIV_ROUND_UP(u->offset + size, PAGE_SIZE) > INT_MAXcan wrap to0whenu->offset + size > SIZE_MAX - (PAGE_SIZE - 1)(e.g.ptr = PAGE_SIZE - 1,size = SIZE_MAX - (PAGE_SIZE - 1)passesptr + size >= ptr, overflowsDIV_ROUND_UPto0, and returns0withu->count = 0). Bounded by surface size in the ioctl path today, but the helper itself should checksize > (size_t)INT_MAX * PAGE_SIZE - u->offset(orcheck_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 contradictsane_h16_mmap()(ane_h16_accel.c:300-316) takingf->lockanda->lockunder the mmap lock. The actual ordering after commit 3 ismmap_lock -> f->lock -> a->lock(nothing may fault/takemmap_lockundera->lock, andane_h16_export_put()defers becauseh16_give_back()calls it undera->lockandvma_closeundermmap_lock).
- 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.
- Only J775D die 0 (with
b29dac1 to
1c027e7
Compare
|
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. Two limits:
To check per-task register reset directly on the J775D's H17, I ran two-task variants of the
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. R2-2: unmodelled blocks. Zero isn't possible for most of them, since every program writes them. Instead:
The commit message gives the per-block reason. R2-3: decode hardening.
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.
The refused H16G matmul ( 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:
dj's wrap case in 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 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 Assisted-by: LLM (Claude:Opus 5.5), LLM (Gemini:Neon) |
There was a problem hiding this comment.
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 (0x44d0zeroed, cache DMA allowlist, non-relocatable L2/PE/NE blocks), decode hardening (ane_hx_dma_strict_test),ane_h16_user_pin()INT_MAX * PAGE_SIZEwrap fix,VM_PFNMAP/VM_IObounce path, correctedane_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 disclosesAssisted-by:; naming clean.
Remaining blockers before approval
- 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)returnstrueas soon as it sees anyVM_PFNMAP | VM_IOVMA in[ptr, ptr + size)without checkingVM_WRITEor verifying that the entire[ptr, ptr + size)range is mapped with no holes.- For a read-only
VM_PFNMAP/VM_IOoutput (or aVM_PFNMAP/VM_IOVMA followed by an unmapped hole or read-only VMA),ane_h16_user_pin(..., write=true)returns-EFAULT,ane_h16_user_unpinnable()returnstrue, andane_h16_user_bounce(..., write=true)skipscopy_from_user()and returns0. The ANE request then executes on hardware beforeane_h16_user_put()fails oncopy_to_user(), contradicting the commit message andane_h16_user_get()doc comment ("Unmapped memory and read-only outputs still fail before the request"). (ane_h16_accel_user_bounce_testmissed this becauserodid not haveVM_IOset.) - Fix: pass
writetoane_h16_user_unpinnable(), walk the full[ptr, ptr + size)range with no gaps, requireVM_WRITEon every VMA whenwriteis true (andVM_READwhen!write), returntrueonly if the entire range is validly mapped and at least one VMA hasVM_PFNMAP | VM_IO, and add KUnit coverage for a read-onlyVM_IOoutput and aVM_IO+ unmapped-hole range.
- 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-compilerH16G 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 matmuls_mm_256remains undiagnosed (real compiler OOB vs missing stride-unit rule for word0x3cbit 2).
- §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), whileane_hx_dma_tile()still accepts width0as1; confirm whether width0on H17 can reach past its buffer before stalling (or tighten accordingly once H16mm256vs H17 behavior is settled). - §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/#2748programs bit-exact, refused OOB LOAD,s_mm_256baseline 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]>
1c027e7 to
35b9d3b
Compare
|
Updated in
Arm64 KUnit on
Items 2–4 (the Assisted-by: LLM (Gemini:Neon) |
There was a problem hiding this comment.
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-100now walks the entire[ptr, ptr + size)range with no gaps (!vma || vma->vm_start > addr), requiresVM_WRITEwhenwriteis set (VM_READotherwise) on every VMA in the range, and returnstrueonly when the entire range is validly mapped and at least one VMA carriesVM_PFNMAP | VM_IO.ane_h16_accel_user_bounce_testcovers both a read-onlyVM_IOoutput and aVM_IO+ unmapped-hole range, and arm64 KUnit at35b9d3b40af5passes 302/303 ANE cases (0 fail, 1 skip) includingane-h16-accel4/4,ane-h16-tasks11/11,ane-h16-program61/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 humanSigned-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)
- §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-compilerH16G 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 matmuls_mm_256remains undiagnosed (real compiler OOB vs missing stride-unit rule for word0x3cbit 2).
- §3 — H17 zero-width behavior: Omitting common widths (
0x04/0x14) on J775D H17 stalled and quarantined the program (firmware_stage program wedged), whileane_hx_dma_tile()accepts width0as1. Confirm whether width0on H17 can touch past its buffer before stalling (or tighten once H16mm256vs H17 behavior is settled). - §5 — Multi-Mac & exact-head hardware coverage: No hardware run at
35b9d3b40af5yet; 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/#2748programs bit-exact, refused OOB LOAD,s_mm_256baseline check, and the two-task per-task reset probe with full regression counts.
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at 35b9d3b40af5
Blockers:
- Shown on the J775D: a program that leaves out the common widths (
0x04/0x14) stalled the H17 and quarantined it (firmware_stage program wedged), yetane_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. - The new running-image check refuses 8
mil-hwx-compilerH16G programs (space-to-depth, depth-to-space, the attention fixture and 5 L2-resident MobileNet schedules), pluss_mm_256. If those run onmain, 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 word0x3cbit 2). - 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.
Superseded by the review at 35b9d3b
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
Signed-off-by: Jeff Queisser <[email protected]>
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]>
|
@DjDeveloperr Pushed
Still open for peer hardware coverage (Blocker 3): an H16 (M4 / M4 Pro, e.g. J616s or J713) row at |
DjDeveloperr
left a comment
There was a problem hiding this comment.
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
Superseded by the review at cd4666b
|
Note 🤖 Claude Opus 5.5 responding on behalf of erikwb J713 (M4 Air, H16) at Evidence
|
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 onmain8f99a858b456plus local die-0 ANE DT opt-indf27feb3e7ab(27.2 stub, published Auraaura-main-7bf44a63): on-hardware ANE KUnit 304 pass / 0 fail / 1 skip (16 modules,ane-h16-tasks17/17),A.hwx1000/1000 &B.hwx200/200 bit-exact,h17-mobilenet16/16 top-1, dma-bufheap50/50 + 20/20, 5/5 hostile DMA bases and 7/7 malformed LOAD sections refused (ENOEXEC), 5 s FUSE fault unblocked (25.0 msvs4726.0 msbaseline), 0 new kernel errors (8vs8),2/2baseline failed units (ALARM, no SELinux).host_tests_vm.sh686/686 pass;mil-hwx-compilercorpus 222/224 pass (s_mm_256real OOB andmatmul_gelu_256omitted widths refused), 3,786/3,786 mutations refused.Risk: two-way door · M3 (H15), M4 (H16), and M5 (H17) Macs using the
accel/aneH16 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/#2748programs,s_mm_256baseline check, and 2-task reset probe); M3 (H15) hardware LOAD row; tree-supported J775D die-0 ANE DT opt-in (local commitdf27feb3e7abis not a PR yet).Details
Problem
Three gaps in the H15/H16/H17 LOAD and EXECUTE paths:
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 nestsmmap_lockinside the driver locks (invertingane_h16_mmap()).Why this shape
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 walkerane_hx_task_frame()and one record counterane_hx_record_count(), parameterized byhwx->task_header_wordsfrom 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.kmap_local_page()under the node lock; unpinnableVM_PFNMAP/VM_IOranges are validated across every VMA and bounced outside both locks.Change
d80bb1356d30accel/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 (ENOEXECbefore mapping).68bc9a8c583caccel/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.35b9d3b40af5accel/ane: h16: copy EXECUTE buffers without user faults under the node lock: pin user pages (or bounce validatedVM_PFNMAP/VM_IOranges) outside the file and node locks.cd4666bbd23eaccel/ane: bound each H15/H16/H17 task's DMAs on its own words(after merge7b774dee929bofmain):mil-hwx-compilerH16G 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 lanes0x20allowed; active lanes require a relocated base).ane_hx_task_frame()usinghwx->task_header_words(8 on H15, 9 on H16/H17), with H15 KUnit coverage.mil-hwx-compilerprograms): 222/224 pass;s_mm_256is a real OOB read (0x40000past its coefficient base on a0x20000buffer; bit 2 of word0x3cdoes not change stride units, confirmed by the attention fixture's two coefficient DMAs);matmul_gelu_256omits its widths and is refused per the zero-width rule.Evidence
Testing
cd4666bbd23e— kitpr2876-m7(windowpr2876m7@20261125-1729) vs baseline kitpr2876-m7b(windowpr2876m7@20261125-1729), built onmain8f99a858b456with 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) plusCONFIG_KUNIT=mand the ANE KUnit test modules as=m. Booted on the 27.2 stub with published Auraaura-main-7bf44a63(ro), default command line:pr2876-m7(PR)pr2876-m7b(base)BOOT-OK,firmware_stage=program,accel0BOOT-OK,firmware_stage=program,accel0304pass,0fail,1skip (ane-h16-tasks17/17,ane-h16-program65/65,ane-h16-hwx20/20,ane-h16-accel4/4)289pass,0fail,1skippart1.py(A.hwx× 1000 /B.hwx× 200)1000/1000(p50 125.7 us),200/200(p50 163.5 us) bit-exact1000/1000,200/200(p50 158.1 us) bit-exacth17-mobilenet(16 images, 50 timing runs)16/16top-1 (p50 2.618 ms)16/16top-1 (p50 2.494 ms)heap(plain/all/inputs/output)50/50(A),20/20(B),0errors /0inexact50/50(A),20/20(B),0errors /0inexacts26)5/5OOB refused (ENOEXEC),A7in-range+0x2000ok (0quarantine)sections)7/7mutated sections refused (ENOEXEC), controls ok (0quarantine)4/4baseline accepted, controls okfuse)a_still_stalled_when_b_done=true,b_wall_ms=25.0,load_ms=4.3,20/20oka_still_stalled_when_b_done=false,b_wall_ms=4726.0,load_ms=4702.72/2baseline (iwd,systemd-networkd-persistent-storage),8errors (0new); ALARM (no SELinux)2failed units,8errorscd4666bbd23e:host_tests_vm.sh(ht-2876m2):686/686passed (rc 0).ane_h16_tasks_test):17/17pass (0fail).mil-hwx-compilercorpus:222/224pass (s_mm_256real OOB andmatmul_gelu_256omitted widths refused);3,786/3,786mutations refused.checkpatch.pl --strict:0errors,0warnings,0checks;W=1ANE build:0warnings.