Skip to content

drm/asahi: size SUBMIT's user copies for kvmalloc, with a bound per GPU - #2998

Draft
Alyx-ML wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
Alyx-ML:aurora/asahi-submit-alloc
Draft

Alyx-ML wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
Alyx-ML:aurora/asahi-submit-alloc

Conversation

@Alyx-ML

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

Copy link
Copy Markdown

Part of the #2755 split. Draft: it needs deqp-vk or CTS runs. This follows jgoyvaerts'
three points and complements #2858.

Summary

 submit(): command copy       KVec, GFP_KERNEL      -> KVVec, GFP_KERNEL_ACCOUNT
 parse_array(): sync array    KVec, GFP_KERNEL      -> KVVec, GFP_KERNEL_ACCOUNT   (> INT_MAX bytes: E2BIG)
 every submit()               KVec<SyncItem>        -> KVVec<SyncItem>
 Gpu::max_cmdbuf_size()       usize::MAX            -> INT_MAX (the most kvmalloc accepts)
 G17                                                -> MAX_CMDBUF = 64 * (1 + 5) * (8 + 65535) = 25,168,512
 G15                          usize::MAX            -> its own 4 MiB MAX_CMDBUF, before the copy
 G16                          4 MiB                    (unchanged)
 VM_BIND copies               + __GFP_NOWARN

Evidence

  • Before: on J616s, deqp-vk hit an order-3 OOM kill from these copies (jgoyvaerts' report).
    A request past the largest page order hits WARN_ON_ONCE_GFP().
  • After: build, Rust included, and KUnit asahi: passed, Apple build and KUnit. rustfmt is clean on
    the changed code.
  • Needed before merging: deqp-vk or CTS on G13, G14 and G17 (J616s among them).
  • G18, M5 and M3 stay on the shared default until their own largest stream is known.

Merge Danger

Door: two-way

Blast Radius: every GPU's SUBMIT

Large copies may come from vmalloc and are charged to the caller's memcg. On G17, a stream over
25,168,512 bytes now fails before the copy. On G15, a stream over 4 MiB, which its parser refused
after the copy with EINVAL, now fails before it with E2BIG. On G13, G14, G18, M3 and M5, only
streams over 2 GiB fail early.

Assisted-by: LLM (Claude:Opus 5.5)

Several ioctls size a kernel allocation straight from userspace:

- SUBMIT copies cmdbuf_size bytes (a u32, so up to 4 GiB) into a KVec.
  Only G16 bounds it before the copy (4 MiB); every other GPU kept the
  trait default of usize::MAX.
- SUBMIT allocates in_sync_count + out_sync_count sync items before any
  per-GPU check.
- VM_BIND copies stride * num_binds bytes and then reserves num_binds
  prepared operations. Without a GPU batch limit (bind_batch_limit()
  returns None), both are up to u32::MAX.

A request past the page allocator's largest order hits
WARN_ON_ONCE_GFP() in __alloc_pages(). Any user with the render node can
trigger it, and with panic_on_warn it takes the machine down. Short of
that limit, a valid but large request still needs high-order contiguous
pages: an order-3 allocation of the sync array failed on J616s under
deqp-vk.

For SUBMIT:

- Copy the command stream and build the sync array in KVVec with
  GFP_KERNEL_ACCOUNT. kvmalloc() falls back to vmalloc() instead of
  failing on fragmented memory, and the memory is charged to the
  caller's memcg. The sync array keeps this type through every
  generation's submit() (G13/G14, G15, G16, G17, G18, M3, M5); the G17
  job vectors are converted in aurora-silicon#2858.
- kvmalloc() refuses, and warns about, more than INT_MAX bytes. The
  trait default for max_cmdbuf_size() is now INT_MAX, so a larger
  command stream fails with E2BIG. This rejects no stream any GPU could
  accept before. A sync array larger than INT_MAX bytes fails with
  E2BIG too.
- G17 returns its own bound: the largest valid G17 stream,
  MAX_COMMANDS_PER_SUBMISSION * (1 + 5) *
  (size_of::<drm_asahi_cmd_header>() + u16::MAX) = 25,168,512 bytes,
  checked at build time to be at most INT_MAX.
- G15 returns its 4 MiB MAX_CMDBUF, as G16 already does. Its parser
  refused a longer stream before, but only after the copy, with EINVAL.
  Such a stream now fails before the copy, with E2BIG.
- G18, M3 and M5 use the shared default until their own largest stream
  is known.

For VM_BIND, pass __GFP_NOWARN on the user-sized allocations, so a
request that is too large fails with ENOMEM and no warning. Its sizes
are not changed. The timestamp mapping limit is left to
aurora-silicon#2531.

Checked by reading the call paths (file.rs submit, parse_array, vm_bind,
vm_bind_g17, mmu/bind.rs, and each generation's submit()). rustfmt is
clean on the changed code. The kernel Rust code was not compiled here.
What userspace can see: on G17, a stream over 25,168,512 bytes, which
its parser cannot accept, now fails before the copy; on G15, a stream
over 4 MiB fails with E2BIG before the copy instead of EINVAL after it;
on G13, G14, G18, M3 and M5, only streams over 2 GiB fail early. The
allocation path changes on every GPU, so deqp-vk or CTS runs on G13, G14
and G17 (J616s among them) are needed before this is merged.

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