Repository navigation
drm/asahi: keep a submission's syncs and command copy off contiguous pages - #3021
Open
jgoyvaerts wants to merge 2 commits into
Open
jgoyvaerts wants to merge 2 commits into
jgoyvaerts wants to merge 2 commits into
Conversation
…pages The submit ioctl copies the command buffer from userspace into a KVec, and parses the in and out syncs into another one. Userspace sets both sizes: in_sync_count and out_sync_count are u32s with no limit of their own, and only some GPUs bound the command buffer before it is copied (G17's max_cmdbuf_size() is the default, usize::MAX). kmalloc() needs both physically contiguous, so a large submission asks for a high-order block on every ioctl, which without compaction may end in the OOM killer instead of failing. Nothing needs them contiguous: only the ioctl reads them, and every generation's submit consumes the syncs before it returns. Make both KVVecs, so a large one falls back to vmalloc() while small ones keep their kmalloc memory, and charge them to the caller's memory cgroup (GFP_KERNEL_ACCOUNT). The sync list's type changes to KVVec in every generation's submit; nothing else about it does. The asahi-m4 submit-restart selftest, which builds that code on the host, gets the matching KVVec alias. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
G15 accepts a command stream of at most MAX_CMDBUF (4 MiB), but checks it only in check_stream(), after the submit ioctl has copied the whole cmdbuf_size from userspace. Its max_cmdbuf_size() was the default, usize::MAX, so a submit of up to 4 GiB was first copied into the kernel and only then refused. Return MAX_CMDBUF from max_cmdbuf_size(), as G16 does, so the ioctl refuses a longer stream with E2BIG before it allocates anything. A stream that check_stream() accepts is unaffected; a longer one now fails with E2BIG instead of EINVAL. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
DjDeveloperr
requested changes
Nov 23, 2026
DjDeveloperr
left a comment
There was a problem hiding this comment.
Formal §1–§6 review at 4ac613b62450 (live CI: host-tests SUCCESS, MERGEABLE/CLEAN):
Technical / §1–§4 / §6: Clean.
- Switching
SyncItem::parseandcopy_commandsindrivers/gpu/drm/asahi/file.rsfromKVec(GFP_KERNEL) toKVVec(GFP_KERNEL_ACCOUNT) eliminates order-3kmallocOOM kills on large userspace-sized submissions without pinning physically contiguous pages. VerifiedUserSliceReader::read_all<A: Allocator>accepts&mut KVVec<u8>, every generation consumes/dropsKVVec<SyncItem>in sleepable submit-ioctl context (novfree()in atomic/IRQ context), andtools/testing/selftests/drivers/gpu/asahi-m4/test-submit-restart.pyis updated to match. - Returning
command::MAX_CMDBUF(4 MiB) fromg15::Gpu::max_cmdbuf_size()prevents pre-parse oversizedvmallocallocations cleanly (matching G16). - Commit attribution (
Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>, zero AI commit trailers) is clean.
Blocker before approval (§5):
- Shared
file.rs+ G15max_cmdbuf_size()changes need exact-head (4ac613b62450) hardware/regression verification rows: (1) an exact-head J616s (M4 Pro) run with the §5 regression triad (0 SELinux denials [or N/A], 0 failed units, 0 new kernel errors), and (2) at least one G15 (M3 Pro/Max) hardware boot/smoke verifying commit 2 (plus one additional generation if available).
Once exact-head §5 rows are posted, this is ready to approve.
Assisted-by: LLM (Gemini 4 Neon)
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.
Two commits for the submit ioctl's userspace-sized buffers. They're in shared
file.rs, so they affect every generation.1. Keep a submission's syncs and command copy off contiguous pages
The ioctl copies the whole command stream from userspace before any parser sees it, and parses the in and out syncs into a second array. Both were
KVecs, physically contiguous through kmalloc, sized by userspace:cmdbuf_sizeis au32. Only G16 bounds it before the copy, and G15 with commit 2 below; drm/asahi: g17: bound a submission's command stream before copying it #3015 does G17.in_sync_countandout_sync_countareu32s with no limit of their own.Up to order 3, such a GFP_KERNEL allocation isn't allowed to fail. The trigger for this series was an order-3 OOM kill under deqp-vk on a J616s (M4 Pro), five times in one run with 26 GB available.
Both become
KVVecs, so a large one falls back to vmalloc while small ones keep their kmalloc memory. They're charged to the caller's memory cgroup (GFP_KERNEL_ACCOUNT). The sync list's type changes toKVVec<SyncItem>in every generation'ssubmit()(G15, G16, G17, G18, M3, M5 and the shared queue trait); nothing else about it changes.vfree() context: every generation consumes the sync list inside its submit ioctl. That includes G18's asynchronous queue, whose
OutputPublication::accept()drops it underJobQueue'sMutex, and M5's local publication. The command copy dies in the ioctl. Sovfree()always runs where it may sleep.2. g15: refuse an oversized command buffer before copying it
G15's format accepts at most
MAX_CMDBUF(4 MiB), butcheck_stream()checks that only after the copy, because G15'smax_cmdbuf_size()was the defaultusize::MAX. With commit 1, that default would let a G15 submit allocate up to 2 GiB through vmalloc before being refused. ReturningMAX_CMDBUF, as G16 does, refuses it with E2BIG before anything is allocated. A longer stream now gets E2BIG instead of EINVAL.Testing
tools/asahi/run-host-tests.py(what CI runs): no failures beyond the base's on my machine. The asahi-m4 submit-restart selftest, which builds the submit code on the host, gets the matchingKVVecalias.m3_submit.rs's existing 127-column line, where only the type changed.Not changed
Assisted-by: LLM (Claude:Opus 5.5)