Repository navigation
drm/asahi: g17: keep userspace-sized submit vectors off contiguous pages - #2858
Draft
jgoyvaerts wants to merge 1 commit into
Draft
jgoyvaerts wants to merge 1 commit into
jgoyvaerts wants to merge 1 commit into
Conversation
The submit ioctl collects its validated commands and their VM pins in KVecs, and builds each command's dependency, checked-input and firmware fence lists in KVecs too. All of them are sized by userspace: up to 64 commands per submission, each over a kilobyte once validated, and as many dependencies as the command waits for, which for the other engine's unfinished commands can be thousands. kmalloc() needs them physically contiguous, so a large submission asks for an order-3 block for its commands alone, on every ioctl. On a machine without compaction that is never allowed to fail and ends in the OOM killer instead, five times in one dEQP-VK run on an M4 Pro, with 26 GB available: deqp-vk invoked oom-killer: gfp_mask=0x40cc0(GFP_KERNEL|__GFP_COMP), order=3 krealloc_node_align_noprof+0x154/0x238 rust_helper_krealloc_node_align+0x10/0x20 ..._asahi_core3g175queue...18prepare_submission... Nothing needs these contiguous: only the ioctl and the job read them. Make them KVVecs, and the cursor array the merge of a long dependency list allocates a kvmalloc_array(). Small ones keep their kmalloc memory. Userspace decides how large they get, so charge all of them to the caller's memory cgroup (GFP_KERNEL_ACCOUNT). A vmalloc()ed vector must be freed where vfree() may sleep. The command, dependency and merge vectors are freed in the ioctl. A job's packet keeps its checked inputs and firmware fences, and its owners release it under the runtime's mutexes or from drm_sched's free_job() work, never under a spinlock or in a fence callback. The fence array of the merged dependency itself is allocated by __dma_fence_unwrap_merge() and freed with kfree() by dma_fence_array, so it stays contiguous. It holds only unsignalled fences, 8 bytes each. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
jgoyvaerts
force-pushed
the
m4pro/g17-submit-kvvec
branch
from
November 22, 2026 20:30
5ba7b33 to
b99cc53
Compare
|
Review at b99cc53 (non-author, draft). No blocker.
Small points, not blocking:
Assisted-by: LLM (Claude:Opus 5.5) |
Author
|
Partial hardware evidence from the J616s (M4 Pro). The same change, in our tree as one commit on top of #2228's per-queue scratch, is in our m4.179 kernel, which also turns compaction back on. On this boot:
This stays a draft. I haven't rerun the large dEQP-VK run that hit the OOM killer, and with compaction now on in that kernel, 0 OOM kills on this boot doesn't show this change on its own. The next check is that dEQP-VK run, with a Assisted-by: LLM (Claude:Opus 5.5) |
Alyx-ML
added a commit
to Alyx-ML/linux
that referenced
this pull request
Nov 23, 2026
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.
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.
What: Keep the G17 submit path's userspace-sized vectors (the per-ioctl commands and VM pins, the per-command dependency lists, the merge arrays) off contiguous pages and charge them to the caller, after an order-3 GFP_KERNEL OOM kill under deqp-vk.
Tested: J616s M4 Pro at b99cc53 (the same change, on #2228's per-queue scratch, carried in our m4.179 to m4.185 kernels): 0 OOM kills and 0 page allocation failures; d3d12 list (544) and dEQP-VK query_pool/timestamp without regressions; 0 failed units, 0 GPU recoveries. Our kernels load no SELinux/AppArmor.
Risk: two-way door · M4, M4 Pro, M4 Max and M5 (shared G17 code)
Not yet: the large dEQP-VK run that hit the OOM kill, with a kmalloc probe; M4, M4 Max and M5 rows
Details
Trigger: an order-3 GFP_KERNEL OOM kill under deqp-vk. On a J616s (M4 Pro, 16K pages) the OOM killer fired five times in one dEQP-VK run, from the submit ioctl, while 26 GB was available. It killed unrelated processes:
That kernel had
CONFIG_COMPACTIONoff, which is our own config and is being fixed there. With nothing to compact, an order <= 3 allocation is never allowed to fail, so it ends in the OOM killer. Compaction makes order 3 recoverable, but the driver still shouldn't need physically contiguous memory per submit for data userspace sizes.What userspace sizes, and what changes
prepare_submission'spendingMAX_COMMANDS_PER_SUBMISSION), each(Validated, Order, Destinations)over 1 KB, which needs order 3prepare_submission'sguardsdependencies,checked_inputs,firmwarePacket::{inputs, firmware}sync_input::merge()'s pointer arrayasahi_g17_merge_fences()'s cursor arraykvmalloc_array()/kvfree()All of them also use
GFP_KERNEL_ACCOUNT, so a client that submits huge batches or waits on huge prefixes is charged in its own memory cgroup. kvmalloc still tries kmalloc first, so small sizes keep their current memory.vfree() context. A vmalloc'ed vector must be freed where
vfree()may sleep.Packet's two vectors go with the packet. Its holders are runtime state behind mutexes, the drm_sched job (free_jobruns from the scheduler's workqueue or at teardown), and the ioctl.Packettakes a spinlock or RCU read lock, or disables IRQs. The only fence callback (sync_scope.c) holds no packet.Left contiguous, by design. The merged
dma_fence_array's own fence array is allocated by core__dma_fence_unwrap_merge()and freed withkfree()indma_fence_array_release(), so it can't move to vmalloc from the driver. It holds only unsignalled fences, 8 bytes each.Overlap with #2228. #2228 moves
pending/guardsinto a per-queueScratch; it is amended to make thatScratchKVVec +GFP_KERNEL_ACCOUNTtoo. This PR fixes the code as it is on main, so it can land on its own. Whichever of the two lands second resolves a few lines inprepare_submission.Evidence
Testing
tools/asahi/run-host-tests.py --only g17: 90/90.Not done
file.rs's sync array and command copy are the same kind of userspace-sized allocation, shared by every generation: drm/asahi: keep a submission's syncs and command copy off contiguous pages #3021.