Skip to content

accel/ane: reject buffers larger than the engine's address space - #2985

Draft
Alyx-ML wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
Alyx-ML:aurora/ane-bounds
Draft

Alyx-ML wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
Alyx-ML:aurora/ane-bounds

Conversation

@Alyx-ML

@Alyx-ML Alyx-ML commented Nov 23, 2026

Copy link
Copy Markdown

Part of the #2755 split. Draft until it has a run on a Mac (the last Evidence line says which).

Summary

 DRM_IOCTL_ANE_BO_INIT
+  size > the range ane->mm hands out (below 4 GiB) -> -E2BIG, before any allocation
 ane_iommu_map_pages() / map_each() / unmap
-  npages << ane->shift        (u32: wraps at 2^18 pages of 16 KiB)
+  (u64)npages << ane->shift

Evidence

  • Before: a buffer of 2^18 + 1 pages reserved a 16 KiB IOVA node and mapped 4 GiB + 16 KiB
    from its start, over IOVA that belongs to other buffers. A host harness (ASan, UBSan) shows the
    old expressions give 0 for 4 GiB.
  • After: the same harness accepts sizes up to the aperture with exact page counts, and refuses
    aperture + 1, 4 GiB, U64_MAX and sizes that wrap round_up(). Build and KUnit (ane-boot,
    ane-transport, ane-pm): passed, Apple build and KUnit.
  • Needed before merging: a boot and an ANE job on any M-series Mac, to show that normal
    buffers are still accepted.

Merge Danger

Door: two-way

Blast Radius: ANE allocation

Only a buffer larger than the engine can map is refused.

Assisted-by: LLM (Claude:Opus 5.5)

struct ane_bo keeps its page count in a u32, and ane_iommu_map_pages(),
ane_iommu_map_each() and the unmap paths computed sizes and offsets as
`npages << ane->shift` and `i << ane->shift`. Both sides are 32-bit, so
with 16 KiB pages a page count of 2^18 or more wraps. A buffer of 2^18 +
1 pages reserved a 16 KiB drm_mm node, while the default batch path
(ane_iommu_map_batch(), which already used size_t) mapped all 4 GiB + 16
KiB from that node's start, over IOVA the allocator could hand to other
buffers; the per-page path mapped page i at the IOVA of a much lower
page. DRM_IOCTL_ANE_BO_INIT accepted any non-zero u64 size from any
client that can open the accel node, and round_up() of a size near
U64_MAX wrapped to 0.

Record the size of the range ane->mm hands out (below 4 GiB) at domain
init and return -E2BIG from BO_INIT for a larger buffer, before anything
is allocated. A buffer that cannot be mapped whole is never created, and
its page count always fits the u32. Also do every page-to-IOVA shift in
u64, as ane_iommu_map_batch() already did, so the arithmetic stays right
if the limit ever changes.

Verified with a host harness under ASan and UBSan: the old expressions
give 0 for a 4 GiB buffer and wrap page offsets past 2^18 pages; with
the new check sizes up to the aperture are accepted with exact page
counts and no truncation, and aperture+1, 4 GiB, U64_MAX and sizes that
wrap round_up() return -E2BIG, for four aperture shapes. The harness
models the patched expressions; the kernel object was not built here,
and no ANE hardware was used.

Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant