Skip to content

accel/ane: h16: stop poisoning output surfaces on every execute - #4027

Open
satchlj wants to merge 2 commits into
mainfrom
satchlj/ane-h16-drop-exec-output-poison
Open

satchlj wants to merge 2 commits into
mainfrom
satchlj/ane-h16-drop-exec-output-poison

Conversation

@satchlj

@satchlj satchlj commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Remove the per-execute memset(cpu, 0xff, buffers[i].size) output-surface poison from ane_h16_exec_ioctl().

Each loaded program owns private kernel surfaces for the lifetime of its drm_file. Newly allocated program surfaces are zeroed via __GFP_ZERO in both ane_h16_backend.c and ane_fw_cold.c, and recycled spare surfaces are zeroed in h16_take_spare() at H16_LOAD. Filling the entire output surface with 0xff before every copy-mode execution dirties the full output buffer (614 KB on unet-320, and megabytes on larger models) on every inference without security or correctness benefit.

Tested:

  • Apple M5 Max (T6050, J775c, default kernel command line) at d309550e34af (Documentation/accel/apple-ane.rst docs-only commit on top of unchanged code commit 055bdde67804; batched candidate b74bea916b44 = main 2b2681932a5c + IOMMU_CACHE commits + 055bdde67804): PASS (307200/307200 exact, max 0 ulp across 5 interleaved 3-input cases + 100/100 copy runs + 3/3 15 s RTC s2idle cycles, suspend_stats 3/0, 0 failed units, 0 new kernel errors).
    • unet-320 copy-mode copy_in drops from 23.7 us mean (22.9 us min) to 19.4 us mean (18.4 us min) on cpu12 (19.1 us mean unpinned).
  • Host/KUnit checks at d309550e34af (CI 9/9 PASS; scripts/checkpatch.pl --strict 0/0/0; KUnit boot.kunitconfig + transport.kunitconfig 334/334 PASS, pm.kunitconfig 20/20 PASS).
  • Untested on hardware: H16 (T6040/T6041) hardware execution (requested repeated-execute + untouched-range + fresh-load zeroed-range check on H16 peer before landing; code path verified by KUnit and inspection of ane_h16_alloc_prot __GFP_ZERO + h16_take_spare zeroing).

Risk: two-way; affects copy-mode H16_EXEC on H16 and H17 ANE devices only.

H16_EXEC was filling every output surface with 0xff via memset() before
every copy-mode execution, dirtying the full output buffer (614 KB on
unet-320 and megabytes on larger models) on every inference.

Each program owns its private surfaces for the life of its drm_file;
freshly allocated surfaces are zeroed via __GFP_ZERO in both
ane_h16_backend.c and ane_fw_cold.c, and recycled spare surfaces are
zeroed in h16_take_spare() at H16_LOAD. Remove the redundant per-execute
0xff poison from the hot path.

Signed-off-by: Satya Benson <satya@benson.earth>
@satchlj
satchlj requested review from a team as code owners December 3, 2026 00:50
@github-actions github-actions Bot added area:media Area from CODEOWNERS (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 3, 2026
@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Merge readiness at d309550e: not ready yet

Check Detail
CI at head ok 11 checks passed
Review no needs one approving review from Core, Omarchy Mac or Aurora Maintainers (not the author)
Requested changes ok none
Hardware row at head ok comment at d309550e
Conflicts ok none
PR text ok Risk: two-way · affects copy-mode H16EXEC on H16 and H17 ANE devices only.

Areas: area:media

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

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: MERGE at 055bdde

Checked: Removing the pre-execute fill leaves input upload, device and CPU synchronization, and successful output copy-out intact. Failed executions return before copy-out. Both allocating backends zero new pages, and recycled surfaces are cleared when loaded into a program before any file can read them. Checked the reported 354 KUnit passes and J775c bit-exact copy and interleaved input checks.

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

The copy-mode behavior documented in Documentation/accel/apple-ane-cold.rst changes here. It says each H16_EXEC initializes the output mapping before execution. The output copy still includes the whole buffer, so bytes the engine leaves untouched now come from the previous execute rather than the per-call fill. LOAD-time zeroing cannot preserve that behavior on the second execute. Please preserve the existing behavior for outputs without a full-write guarantee, or document the change and verify that supported programs overwrite every returned byte.

@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label Dec 3, 2026
DjDeveloperr
DjDeveloperr previously approved these changes Dec 3, 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.

Read at 055bdde67804. The copy-out only runs after a successful execute, the surfaces belong to one open file, and new and recycled surfaces are zeroed (__GFP_ZERO, h16_take_spare()), so the 0xff fill protects nothing. The J775c row covers H17. The same path runs on H16, so it gets one J773g (T8132) run on our side before it lands; we carry that with the J714s run for #4026, whose t6050-peripherals.dtsi change also reaches J714s.

@github-actions github-actions Bot removed the needs-review No approving review from Core or Omarchy Mac yet (bot) label Dec 3, 2026
@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) and removed ci-failing A check failed at the PR head (bot) labels Dec 3, 2026
H16_EXEC no longer fills the output mapping before each execute, so the
sentence that says so is wrong. Describe what happens now: the surfaces
are zeroed at H16_LOAD and belong to one open file, and output bytes that
the engine does not write keep the value of the previous execute.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr

Copy link
Copy Markdown
Contributor

Answer to the 00:55 review: documented at the new head d309550e34af (one commit on top of 055bdde67804, documentation only). The sentence was in Documentation/accel/apple-ane.rst (apple-ane-cold.rst has no such line). It now says that H16_EXEC does not touch the output mapping, that surfaces are zeroed at H16_LOAD and belong to one open file, and that output bytes the engine does not write keep the value of that file's previous execute.

On the full-write question: the J775c row compares every output byte with the golden output for one model (unet-320) over interleaved inputs. It does not prove that every program writes its whole output, so the text promises no more than the above. The H16 run on J773g (T8132) is still owed before this lands.

@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 3, 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.

The latest commit documents that a successful copy-mode call returns the full output surface and that bytes the engine skips retain their value from that file's previous execute. It leaves the J775c-tested code unchanged. Before landing, please run the repeated-execute case on H16 (J773g or a T6040/T6041 peer), including an output with an untouched range, and check that a newly loaded program starts with a cleared range.

@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label Dec 4, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

Hardware verification on exact head d309550e34af (exact blob match on 2/2 files):

Tested in matched-DTB one-shot combined batch kernel 7.3.0-trb-b1 (ffa2cdc5d7b1 atop 1da341136110; exact 3-way blob identity verified against git merge-tree(main, PR_HEAD) with zero file overlap across disjoint PRs) paired with aura 1.0.0b19 + U-Boot 2026.07-g5c0d5fe1a222 and each Mac's freshly built 7.3.0-trb-b1 DTB (no Stage 1, 1TR, LocalPolicy, or default-boot changes):

  • MacBook Pro (14-inch, M5 Pro — K114s, T6050, G17S B1, sysfw 27.2, boot_id=75766774, paired t6050-k114s.dtb 8bfed4b2 replacing live 2debbcb4): 40/40 feats PASS, SELinux=Enforcing, failed_units=[], cpus_online=0-17, dcp_bound=5/5, eDP-1 connected/enabled/3024x1986 (apple-panel-bl:187/1000), live external Acer DP-2 connected/enabled/1920x1080, simpledrm_active=0, handoff_errors=0, 3 apple_dcp HDMI/USBC DP audio cards (8/9/10), wifi_ping=ok, typec_ports=4, ane_accel=accel0, oops=0, dart_faults=0, gpu_kernel_errors=0, avc=0; cleanly restored to saved EDGE 1675a62307d2 (boot_id=da7477fc, failed=0).
  • MacBook Air (13-inch, M4 — J713, T8132, G16G B0, sysfw 27.2, boot_id=ef37e788, paired t8132-j713.dtb a86b5e6d replacing live 80e4ee65): 39/39 feats PASS, SELinux=Enforcing, failed_units=[], cpus_online=0-9, dcp_bound=3/3, handoff_errors=0, vkcube 300 frames PASS, rtcwake s2idle (wall=20s, success_delta=1, fail_delta=0) SLEEP PASS with clean post-wake display/Wi-Fi/ping, wifi_ping=ok, typec_ports=3, ane_accel=accel0, oops=0, dart_faults=0, avc=0; cleanly restored to saved EDGE 1675a62307d2 (boot_id=ff4b6a36, failed=0).
  • MacBook Pro (16-inch, M4 Pro — J616s, T6040, G16S B1, sysfw 27.2.1, boot_id=26f04386, paired t6040-j616s.dtb e2ac54bb replacing live 028c6026): SELinux=Enforcing, failed_units=[], cpus_online=0-13, eDP-1 connected/enabled/3456x2234, dcp_bound=3/3, handoff_errors=0, glmark2=23059 (Apple M4 Pro G16S B1), rtcwake s2idle (wall=21s, success_delta=1, fail_delta=0) SLEEP PASS with clean post-wake display/Wi-Fi/ping, wifi_ping=ok, typec_ports=4, usb_hosts=4, ane_accel=accel0, kerr_count=0, oops=0, dart_faults=0, avc=0; cleanly restored to saved EDGE 1675a62307d2.
  • H16/H17 ANE accel nodes (/dev/accel/accel0, ane_kernel_errors=0) verified cleanly across J616s, J713, and K114s.

Result: PASS on K114s (M5 Pro), J713 (M4 Air), and J616s (M4 Pro) at exact head d309550e34af.

@RyanTheTide

Copy link
Copy Markdown
Contributor

J616s H16G copy-mode hardware row for d309550e34af

Saved kernel 1675a62307d2 and guarded 7.3.0-trb-b1 (ffa2cdc5d7b119c206e810b16249e80a925f0571), Aura 1.0.0b19, default cmdline and paired kernel DTBs. The tested drivers/accel/ane/ane_h16_accel.c and Documentation/accel/apple-ane.rst match d309550e34af byte for byte. Other disjoint changes were in the batch.

Both arms classified 16/16 changing synthetic inputs correctly. The newly loaded output surface was all zero (458,752 bytes), all 16 mapped output regions matched their copy-mode outputs, and all full output digests matched between stock and candidate. The measured 360,654 padding bytes stayed zero in both arms, so this fixture confirms correctness and fresh zeroing; it did not distinguish whether any of those offsets were left untouched by firmware.

Signed stock restored after the guarded one-shot. Board evidence.

This branch has not been deployed

No deployments
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) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants