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:mainfrom
Alyx-ML:aurora/asahi-submit-alloc
Draft

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

Conversation

@Alyx-ML

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

Copy link
Copy Markdown
Contributor

Part of the #2755 split. Draft: it needs deqp-vk or CTS runs.

Summary

 Gpu::max_cmdbuf_size() default   usize::MAX        -> KMALLOC_MAX_SIZE (the copy is kmalloc)
 G15                              usize::MAX        -> its own 4 MiB MAX_CMDBUF, before the copy
 G16, G17                         4 MiB, MAX_STREAM    (unchanged)
 parse_array(): sync array        no bound          -> E2BIG past KMALLOC_MAX_SIZE
 command and sync copies          GFP_KERNEL        -> GFP_KERNEL_ACCOUNT
 VM_BIND copies                   GFP_KERNEL        -> GFP_KERNEL | __GFP_NOWARN

Evidence

  • Before: userspace picks the size of each copy. Past KMALLOC_MAX_SIZE, kmalloc() warns
    (WARN_ON_ONCE_GFP()), which stops the machine under panic_on_warn. G15, G18, M3, M5 and
    g14_v27_2 had no bound before the copy.
  • After: rebased on main and checked with rustfmt. My fork's Actions could not run, so the
    PR's own CI is the build and KUnit asahi check at this head.
  • Needed before merging: deqp-vk or CTS on G13, G14 and G17 (J616s among them).

Merge Danger

Door: two-way

Blast Radius: every GPU's SUBMIT

On G15, a stream over 4 MiB, which its parser refused after the copy with EINVAL, now fails
before it with E2BIG. On the GPUs without their own bound, a stream over KMALLOC_MAX_SIZE fails
with E2BIG instead of a warning and ENOMEM.

@RyanTheTide

Copy link
Copy Markdown
Contributor

@Alyx-ML checking open drafts today. To come out of draft, this still needs:

  • It conflicts with main. Merge main in or rebase (no force push needed: a merge commit is fine).
  • Then a test run at the final head on a Mac with the hardware it touches, and mark it ready for review.

If it's no longer needed, say so here and we'll close it. Otherwise it stays open as a draft until these are done.

SUBMIT copies the command stream and the sync array into kmalloc()
buffers (KVec), with sizes that userspace picks. kmalloc() warns when
asked for more than KMALLOC_MAX_SIZE, and with panic_on_warn that
warning stops the machine. G16 and G17 refuse a longer stream before the
copy, but:

- The default max_cmdbuf_size() is usize::MAX. The GPUs that do not
  override it (g14_v27_2, G15, G18, M3 and M5) copy a stream of any
  size the ioctl allows.
- G15's parser refuses a stream over its 4 MiB MAX_CMDBUF, but only
  after the copy.
- parse_array() sizes the sync array from in_sync_count plus
  out_sync_count with no bound.
- VM_BIND copies stride * num_binds bytes. A GPU without a bind batch
  limit does not bound either one.

Make KMALLOC_MAX_SIZE the default bound, as g17::command::MAX_STREAM
already asserts for G17. Have G15 return its MAX_CMDBUF, as G16 does,
so a longer stream fails with E2BIG before the copy instead of EINVAL
after it. Refuse a sync array larger than KMALLOC_MAX_SIZE with E2BIG.
Charge both copies to the caller's memcg (GFP_KERNEL_ACCOUNT), since
userspace picks their size.
Copy the VM_BIND array with __GFP_NOWARN, so an oversized one fails
with ENOMEM and no warning.

No stream that could be copied before is refused: a larger copy already
failed in kmalloc(), with the warning. G15 and G16 accept at most 4 MiB,
and G17's MAX_STREAM is checked at build time to be at most
KMALLOC_MAX_SIZE on arm64.

The earlier version of this change also moved both copies to kvmalloc()
and gave G17 its own bound. main has since given G17 MAX_STREAM and
keeps the copies in kmalloc() buffers, so this version follows that.

Signed-off-by: Alyx-ML <[email protected]>
@Alyx-ML

Alyx-ML commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main (6305df3) and cut down, because main has moved:

  • G17 now has command::MAX_STREAM, and the copies stay in kmalloc() buffers on purpose
    (MAX_STREAM is asserted to fit KMALLOC_MAX_SIZE). So this no longer moves the copies to
    kvmalloc() or adds a G17 bound.
  • What is left: the default max_cmdbuf_size() becomes KMALLOC_MAX_SIZE instead of usize::MAX,
    G15 returns its 4 MiB MAX_CMDBUF, the sync array gets the same bound, both copies are charged
    to the caller's memcg, and the VM_BIND copies use __GFP_NOWARN.

I have updated the description. No stream that could be copied before is refused. It still
needs the deqp-vk or CTS runs.

Assisted-by: LLM (Claude:Opus 5.5)

@Alyx-ML
Alyx-ML force-pushed the aurora/asahi-submit-alloc branch from fef478c to 6305df3 Compare November 27, 2026 01:14

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants