Skip to content

accel/ane: h17: use IOMMU_CACHE for dma-coherent program surfaces - #4026

Merged
DjDeveloperr merged 2 commits into
mainfrom
satchlj/ane-h17-coherent-program-surfaces
Dec 3, 2026
Merged

DjDeveloperr merged 2 commits into
mainfrom
satchlj/ane-h17-coherent-program-surfaces

Conversation

@satchlj

@satchlj satchlj commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

When an H17 ANE device is marked dma-coherent in the device tree, map its PAGE_KERNEL program surfaces with IOMMU_CACHE so the DART2 PTEs clear APPLE_DART2_PTE_PROT_NO_CACHE and the engine snoops CPU caches directly (matching ane_h16_backend.c and ane_t6021_fwload.c), and skip dma_map_sgtable() and per-execute dma_sync_sgtable_*() cache maintenance. Mark the T6050 ANE node dma-coherent (already allowed by Documentation/devicetree/bindings/npu/apple,ane.yaml).

Non-coherent devices (without dma-coherent in DT, including T8140 and T8142 until verified on their hardware) keep the existing software cache-sync path unchanged.

Tested:

  • Apple M5 Max (T6050, J775c, default kernel command line) at exact head 9673fd472911 (batched candidate b74bea916b44 = main 2b2681932a5c + unchanged PR commits 4e9b344d907b, 9673fd472911 + output-poison removal commit): PASS (307200/307200 exact, max 0 ulp across 5 interleaved 3-input cases + 100 copy runs + 3/3 15 s RTC s2idle cycles, suspend_stats 3/0, 0 failed units, 0 DART faults, 0 new kernel errors).
  • Host/KUnit/DT checks at exact head 9673fd472911: scripts/checkpatch.pl --strict 0/0/0; all 7 T6050 DTBs (j714s, j716c, j775c, j775d, j873s, k114c, k116c) compile cleanly with dma-coherent verified via dtc; KUnit boot.kunitconfig + transport.kunitconfig 334/334 PASS, pm.kunitconfig 20/20 PASS.
  • Untested on hardware: T8140 and T8142 (both stay on the existing non-coherent path because their DTs do not set dma-coherent).

Risk: two-way; affects H17 ANE program surface mappings on T6050 (dma-coherent enabled) and leaves non-coherent H17 devices on the existing software sync path.

When the ANE device is marked dma-coherent in the device tree, map H17
program surfaces (PAGE_KERNEL cached pages) with IOMMU_CACHE so the DART2
PTEs clear NO_CACHE and the engine snoops CPU caches directly, matching
ane_h16_backend.c and ane_t6021_fwload.c.

Skip the software dma_map_sgtable() and per-execute dma_sync_sgtable_*()
cache maintenance on coherent devices; non-coherent devices keep the
existing software cache-sync path unchanged.

Signed-off-by: Satya Benson <satya@benson.earth>
The T6050 ANE DART2 mappings support hardware cache coherency when
IOMMU_CACHE clears the DART2 NO_CACHE PTE bit. Mark the T6050 ANE node
dma-coherent (already allowed by Documentation/devicetree/bindings/npu/
apple,ane.yaml) so H17 program surfaces use hardware snooping without
per-execute software cache flushes.

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:bringup Area from CODEOWNERS (bot) area:media Area from CODEOWNERS (bot) blast:m5 Macs affected, from Merge risk (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 9673fd47: not ready yet

Check Detail
CI at head running running: apple-build, host-tests, KUnit plan
Review ok approved by RyanTheTide
Requested changes ok none
Hardware row at head ok in the PR body at 9673fd47
Conflicts ok none
PR text ok Risk: two-way · affects H17 ANE program surface mappings on T6050 (dma-coherent enabled) and leaves non-coherent H17 devices on the existing software sync path.

Areas: area:bringup, area:media

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

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

Reviewed 9673fd4. For coherent program surfaces the mapping, DMA allocation bookkeeping and sync paths agree. Non-coherent program surfaces keep the software sync and matched unmap, and other firmware allocations retain their existing path. The reported J775c row verifies the live DT and bit-exact outputs across interleaved inputs.

@github-actions github-actions Bot removed the needs-review No approving review from Core or Omarchy Mac yet (bot) label Dec 3, 2026

@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 9673fd4

Checked: The existing ANE binding validates and allows dma-coherent. The shared T6050 node and the standalone J775c node both carry it. Only coherent H17 program surfaces get IOMMU_CACHE and skip DMA sync. The IOMMU consumes physical scatterlist entries, teardown only unmaps DMA-mapped tables, and the transport keeps its publication and completion DMA barriers. Checked the seven DTB results, 354 KUnit cases and the J775c bit-exact interleaved input results.

@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (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
@DjDeveloperr

Copy link
Copy Markdown
Contributor

Local checks for 9673fd472911 merged onto main 0b5e5581a5fb (main has since moved to 386cc0259126; those 5 commits are the M3 display change only and touch none of these files):

  • git merge-tree on the three changed files: clean, +22/-4.
  • Read the change and the release path. ane_fw_pages_release() calls dma_unmap_sgtable() only when m->dma_mapped is set, and the coherent early return leaves it clear, so every free path (failed allocation, failed DVA insert, ane_fw_program_unmap()) frees the table without unmapping it. iommu_map_sgtable() walks orig_nents, so the skipped map is fine. IOMMU_CACHE goes through ane_fw_alloc_mem() to iommu_map_sgtable(); the DART code clears NO_CACHE for it. Firmware-owned memory keeps its uncached path.
  • make W=1 drivers/accel/ane/ for arm64 (clang 23, with the ANE KUnit objects): 36 objects, no warnings.
  • All 11 T6050 DTBs build, and the enabled ANE node of each carries dma-coherent.
  • ANE host tests (ane-tm-transient-fault with its old-revision control, clpc-ane-cpu-opp with its five mutations): the same results on main and on the merge, and every control fails as required. t6050-dp-tunnel-dt-tests passes on the merge.

Not run here: hosted apple-build/host-tests/KUnit plan (still queued), KUnit on UML. Hardware is the J775c row in the body. The J714s run follows after the merge: the coherent path runs only where the DT says dma-coherent, which is T6050 only.

Two comments for a later cleanup, no change needed now: the ane_fw_alloc_pages() comment now sits above ane_fw_program_coherent(), and the ane_fw_alloc_mem() comment still says the engine does not snoop.

@DjDeveloperr
DjDeveloperr merged commit 664b5db into main Dec 3, 2026
12 of 16 checks passed
@DjDeveloperr
DjDeveloperr deleted the satchlj/ane-h17-coherent-program-surfaces branch December 3, 2026 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:bringup Area from CODEOWNERS (bot) area:media Area from CODEOWNERS (bot) blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants