Repository navigation
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of the #2755 split. Draft: it needs deqp-vk or CTS runs. This follows jgoyvaerts'
three points and complements #2858.
Summary
Evidence
A request past the largest page order hits
WARN_ON_ONCE_GFP().asahi: passed, Apple build and KUnit. rustfmt is clean onthe changed code.
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)