Skip to content

drm/asahi: keep a submission's syncs and command copy off contiguous pages - #3021

Open
jgoyvaerts wants to merge 2 commits into
aurora-silicon:mainfrom
jgoyvaerts:m4pro/asahi-submit-kvvec
Open

jgoyvaerts wants to merge 2 commits into
aurora-silicon:mainfrom
jgoyvaerts:m4pro/asahi-submit-kvvec

Conversation

@jgoyvaerts

Copy link
Copy Markdown

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:

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 to KVVec<SyncItem> in every generation's submit() (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 under JobQueue's Mutex, and M5's local publication. The command copy dies in the ioctl. So vfree() 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), but check_stream() checks that only after the copy, because G15's max_cmdbuf_size() was the default usize::MAX. With commit 1, that default would let a G15 submit allocate up to 2 GiB through vmalloc before being refused. Returning MAX_CMDBUF, as G16 does, refuses it with E2BIG before anything is allocated. A longer stream now gets E2BIG instead of EINVAL.

Testing

  • KUnit (arm64 qemu, asahi + SEP + ISP config): 751 tests, 750 pass, 1 skip.
  • An all-generations compile (G15, M3_T8122, G18, M5 enabled) builds the asahi driver.
  • 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 matching KVVec alias.
  • checkpatch: 0 errors. The one warning is m3_submit.rs's existing 127-column line, where only the type changed.
  • On hardware: commit 1 (as it was before rebasing) ran in our M4 Pro (J616s) test kernel. There, vkd3d-proton's 544-test d3d12 list and dEQP-VK query_pool/timestamp (1999 cases) showed no regressions against the previous kernel, with 0 page allocation failures, 0 OOM kills and 0 GPU recoveries.
  • Commit 2 and the G18/M5/M3 paths are not tested on hardware. An M3 Pro/Max, M5 or M6 row from someone with one would be welcome.

Not changed

  • G18, M5 and M3 still have no command-buffer bound. Each needs one from its own format; with commit 1, their submits can allocate up to 2 GiB before their parser refuses them, charged to the caller.
  • The sync count has no uAPI limit. Past 2 GiB of records kvmalloc warns, as krealloc did past 32 MiB before this change.

Assisted-by: LLM (Claude:Opus 5.5)

…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 DjDeveloperr left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formal §1–§6 review at 4ac613b62450 (live CI: host-tests SUCCESS, MERGEABLE/CLEAN):

Technical / §1–§4 / §6: Clean.

  • Switching SyncItem::parse and copy_commands in drivers/gpu/drm/asahi/file.rs from KVec (GFP_KERNEL) to KVVec (GFP_KERNEL_ACCOUNT) eliminates order-3 kmalloc OOM kills on large userspace-sized submissions without pinning physically contiguous pages. Verified UserSliceReader::read_all<A: Allocator> accepts &mut KVVec<u8>, every generation consumes/drops KVVec<SyncItem> in sleepable submit-ioctl context (no vfree() in atomic/IRQ context), and tools/testing/selftests/drivers/gpu/asahi-m4/test-submit-restart.py is updated to match.
  • Returning command::MAX_CMDBUF (4 MiB) from g15::Gpu::max_cmdbuf_size() prevents pre-parse oversized vmalloc allocations 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 + G15 max_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)

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