Skip to content

drm/asahi: mmu: cache dcache line size and stream scatterlist page-table maps - #3032

Merged
DjDeveloperr merged 1 commit into
aurora-silicon:mainfrom
AxxzyWasTaken:pr/asahi-mmu-stream-map
Nov 24, 2026
Merged

DjDeveloperr merged 1 commit into
aurora-silicon:mainfrom
AxxzyWasTaken:pr/asahi-mmu-stream-map

Conversation

@AxxzyWasTaken

@AxxzyWasTaken AxxzyWasTaken commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What: Cache dcache line size and stream scatterlist page-table maps in the Asahi MMU.
Tested: J616C M4 Max (T6041, G17P B1) at 5bf9b71: 16 MiB fresh-BO VM_BIND 678.5 -> 416.6 us (1.63x), gpubench mem.buffer alloc_us 3.71 -> 1.04 us (3.56x), 0 MMU/GPU faults, 0 failed units, host-tests green.
Risk: two-way · all Apple Silicon Macs using drm/asahi MMU.
Not yet: None (approved and CI green).

Original details and measurements

Cache the arm64 sanitized CTR_EL0.DminLine data-cache line stride and stream multi-segment scatterlist page-table mappings through a single UAT page-table walk instead of calling UatPageTable::map_pages() once per scatterlist segment.

Cause

Mapping a multi-segment shmem GEM BO through VmInner::sm_step_map() or VmInner::map_node_prepared() previously called UatPageTable::map_pages() once per scatterlist segment. On SoCs with UatQuirks::clean_tables (such as T6041/G17P), every individual 16 KiB segment performed:

  • a separate full L0 -> L1 -> L2 page-table walk,
  • an FFI call to read_sanitised_ftr_reg(SYS_CTR_EL0) inside clean_poc(),
  • redundant dc cvac maintenance across the same 64-byte leaf-table cache lines, and
  • a system-wide dsb sy (poc_barrier()).

Fix

  • Cache the sanitized CTR_EL0.DminLine stride lazily in DCACHE_LINE_SIZE: AtomicUsize (drivers/gpu/drm/asahi/pgtable.rs). On arm64 CTR_EL0.DminLine is FTR_STRICT + FTR_LOWER_SAFE, so it is invariant once SMP boot completes.
  • Add UatPageTable::map_segments() backed by SegmentCursor (drivers/gpu/drm/asahi/pgtable.rs) to stream (PhysicalAddr, usize) scatterlist segments (with initial offset and one_page repeat support) through a single self.walk(), emitting at most one point-of-coherency clean per leaf-table slice and a single final dsb sy barrier.
  • Switch VmInner::sm_step_map() and VmInner::map_node_prepared() (drivers/gpu/drm/asahi/mmu.rs) to call map_segments(), preserving full alignment checks, collision refusal (EBUSY), and failure rollback semantics (and explicitly rejecting truncated scatterlists with EINVAL).
  • Add KUnit suite asahi_pgtable_segments covering multi-segment streaming with offset and zero-length entries, one_page repeat, and unaligned / truncated input rejection.
  • Applies uniformly across all Asahi UAT users without chip-specific gates.

Hardware Results (Exact-Head Live M4 Max A/B)

  • Machine / firmware: Apple MacBook Pro 16-inch M4 Max (J616C, T6041 / G17P B1, 32-core GPU, FW 25G83), AC power, Mesa a4f0da8300 (Borealis).
  • Kernels compared: Exact integration/aurora 70a00e583b03 (7.3.0-j616c-ia35+, baseline aurora.ko SHA-256 934255e5...) vs exact PR head 5bf9b71aee899207c72c1fa274fbef91cbf1bfe4 (aurora.ko SHA-256 c90c5327..., unmodified 70a00e583b03 DTB, default cmdline + panic=10 trial guard).
  • A/B workload (fresh non-cached Vulkan host-visible coherent shmem BO batches — 8 simultaneous BOs per fresh process across 3 processes to prevent userspace BO-cache reuse, plus gpubench-vk --test mem.buffer median over 5 runs):
Workload Before (70a00e583b03) After (5bf9b71aee89) Speedup
Fresh shmem BO alloc + VM_BIND (16 MiB, med of 3×8) 678.5 us (24.7 GB/s) 416.6 us (40.3 GB/s) 1.63x
Fresh shmem BO alloc + VM_BIND (64 MiB, med of 3×8) 1477.6 us (45.4 GB/s) 1485.6 us (45.2 GB/s) (mean 1511 -> 1460 us) 1.03x mean
Fresh shmem BO alloc + VM_BIND (128 MiB, med of 3×8) 3377.6 us (39.7 GB/s) 2679.0 us (50.1 GB/s) 1.26x
gpubench-vk mem.buffer alloc_us (d=1) 3.709 us 1.042 us 3.56x
gpubench-vk mem.buffer map_us (d=1) 0.667 us 0.559 us 1.19x
gpubench-vk mem.buffer free_us (d=1) 0.083 us 0.042 us 1.98x
  • GPU compute CRC sanity on newly mapped BOs: gpubench-vk compute.blur_fp32(taps=9, 1080p, d=4) valid: true, status: ok.
  • §5 Regression triad: 0 GPU/MMU/UAT faults or recoveries, 0 SELinux denials (N/A — Arch Linux ARM), 0 failed systemd units, 0 new kernel errors (only pre-existing brcmf_pcie_setup boot retry, nvme udev kyber rule, bluetoothd BAP, and dbus-broker duplicate FileManager1).

Build & Host Testing

  • Base: integration/aurora 70a00e583b03
  • python3 -I tools/asahi/run-host-tests.py --only g17 --jobs 4: 90/90 passed
  • python3 -I tools/asahi/run-host-tests.py --only asahi --jobs 4: 3/3 passed (includes asahi-m4, asahi-g15, asahi-stats-raw-tests)
  • make ARCH=arm64 LLVM=1 drivers/gpu/drm/asahi/aurora.o (regular and CONFIG_KUNIT=y on ia33.config, compiling asahi_pgtable_segments KUnit tests): compiles cleanly with 0 new warnings
  • C changes: none (pure Rust; scripts/checkpatch.pl --strict N/A).

…ble maps

Mapping a multi-segment shmem GEM BO through VmInner::sm_step_map() or
VmInner::map_node_prepared() previously invoked UatPageTable::map_pages()
once per scatterlist segment. On SoCs with UatQuirks::clean_tables (such
as T6041/G17P), every individual 16 KiB segment performed a full L0->L1->L2
walk, an FFI call to read_sanitised_ftr_reg(SYS_CTR_EL0), redundant
dc cvac maintenance on the same 64-byte leaf-table cache lines, and a
system-wide dsb sy barrier.

Cache the sanitized DminLine cache-line stride in an AtomicUsize, add
UatPageTable::map_segments() (backed by a streaming SegmentCursor with
KUnit coverage) to fill all scatterlist segments in a single walk with
one PoC clean per leaf-table slice and a single final dsb sy barrier,
and switch sm_step_map() and map_node_prepared() to use it.

Signed-off-by: AxxzyWasTaken <[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 pre-PR review at verified head 5bf9b71aee899207c72c1fa274fbef91cbf1bfe4.

  • Code & correctness:
    • DCACHE_LINE_SIZE: AtomicUsize lazily caches arm64 sanitized CTR_EL0.DminLine (FTR_STRICT | FTR_LOWER_SAFE, always >= 4, idempotent Relaxed load/store).
    • UatPageTable::map_segments() + SegmentCursor stream (PhysicalAddr, usize) scatterlist segments through a single self.walk() (one PoC clean per leaf slice + one final dsb sy), preserving alignment checks, EBUSY collision refusal, one_page repeat, and rollback_failed_map() in sm_step_map(). Bonus safety improvement: explicitly returns EINVAL on truncated scatterlists instead of silently returning Ok(()) with left > 0.
    • KUnit suite asahi_pgtable_segments covers multi-segment offset/zero-len streaming, one_page repeat, and unaligned/short rejection.
  • §1–§4 / §6: Uniform across all Asahi UAT users (no chip gates, no hacks), human author/committer + human Signed-off-by: only (0 AI trailers), host-tests SUCCESS (MERGEABLE/CLEAN).
  • §5: Exact-head J616C A/B (1.63x 16 MiB VM_BIND, 3.56x mem.buffer alloc_us), CRC valid, 0 faults/errors/failed units. (Note for merge train: touches shared mmu.rs/pgtable.rs, so pair with a second-Mac regression row per merge policy if needed.)

Approved.

Assisted-by: LLM (Gemini 4 Neon)

@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:all 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) labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merge readiness at 5bf9b71a: ready to merge

Check Detail
CI at head ok 4 checks passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok in the PR body at 5bf9b71a
Conflicts ok none
PR text ok Risk: two-way · all Apple Silicon Macs using drm/asahi MMU.

Areas: area:gpu
Merge: gh pr merge 3032 --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.

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-hw-row No hardware row at the PR head (bot) ready-to-merge Meets the merge policy: merge it (bot) labels Nov 24, 2026
@DjDeveloperr
DjDeveloperr merged commit 99fe4b7 into aurora-silicon:main Nov 24, 2026
7 checks passed
@DjDeveloperr

Copy link
Copy Markdown
Contributor

Thank you for the contribution, @AxxzyWasTaken!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpu Area from CODEOWNERS (bot) blast:all 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.

2 participants