Skip to content

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

Merged
RyanTheTide merged 3 commits into
aurora-silicon:mainfrom
jgoyvaerts:m4pro/asahi-submit-kvvec
Nov 27, 2026
Merged

RyanTheTide merged 3 commits into
aurora-silicon:mainfrom
jgoyvaerts:m4pro/asahi-submit-kvvec

Conversation

@jgoyvaerts

@jgoyvaerts jgoyvaerts commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What: The submit ioctl's command copy and sync array, both sized by userspace, become KVVecs charged to the caller for every generation, and G15 refuses a stream over its 4 MiB limit before the copy.
Tested: J616s M4 Pro at 4ac613b (every line this PR adds is in our m4.185 kernel): vkd3d-proton's 65,536-command test passes; dEQP-VK query_pool/timestamp 0 differences; 0 page allocation failures, 0 OOM kills, 0 failed units, 0 new kernel errors, 0 GPU recoveries. Our kernels load no SELinux/AppArmor. Other generations: an all-generations compile and the host tests only.
Risk: two-way door · all Macs (shared file.rs); on G15 (M3 Pro/Max) a stream over 4 MiB gets E2BIG instead of EINVAL
Not yet: a G15 (M3) boot or smoke row; G18, M5 and M3 rows

Details

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.

Evidence

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.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

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 <[email protected]>, 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)

@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) changes-requested A reviewer requested changes (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 24, 2026
@github-actions github-actions Bot added blast:all Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) and removed needs-hw-row No hardware row at the PR head (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merge readiness at 438cb839: not ready yet

Check Detail
CI at head no failing: apple-build, pr-text / pr-text, KUnit ane-boot, KUnit ane-pm, KUnit dcp-fabric, KUnit dcp-topology
Review ok approved by DjDeveloperr, satchlj
Requested changes ok none
Hardware row at head ok comment at 438cb839
Conflicts ok none
PR text ok Risk: two-way · all Macs (shared file.rs); on G15 (M3 Pro/Max) a stream over 4 MiB gets E2BIG instead of EINVAL

Areas: area:gpu

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@jgoyvaerts

Copy link
Copy Markdown
Contributor Author

J616s row, as asked. Our m4.185 kernel carries every line this PR adds (checked line by line against head 4ac613b62450). The patch IDs differ only because that kernel's G18 code predates the asynchronous submit the PR's G18 hunk sits in.

  • vkd3d-proton's 65,536-command test passes.
  • dEQP-VK query_pool/timestamp (1999 cases): 0 differences against the same Mesa build on the previous kernel.
  • 0 page allocation failures, 0 OOM kills.
  • Regression triad: 0 failed units (system and user), 0 error-level kernel messages, 0 GPU recoveries. Our kernels load no SELinux/AppArmor (LSMs: capability, landlock, yama).

A G15 (M3 Pro/Max) boot or smoke row needs someone with an M3; I have none. The description now follows the new PR structure.

@github-actions github-actions Bot added the merge-conflict Conflicts with the base branch (bot) label Nov 25, 2026
…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 <[email protected]>
Signed-off-by: Dj <[email protected]>
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 <[email protected]>
Signed-off-by: Dj <[email protected]>
@DjDeveloperr
DjDeveloperr force-pushed the m4pro/asahi-submit-kvvec branch from 4ac613b to 58c1307 Compare November 25, 2026 02:17
@DjDeveloperr
DjDeveloperr requested a review from a team as a code owner November 25, 2026 02:17
@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) and removed merge-conflict Conflicts with the base branch (bot) labels Nov 25, 2026

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Gemini 4 Neon on @satchlj's behalf — reviewed 58c130777d7b (MERGEABLE, CI host-tests / readiness / pr-text all SUCCESS).

Verdict

APPROVE at 58c130777d7b — code, lifetime/sleep-context safety, host tests, and commit trailers are all clean.

Audit Highlights

  • Non-contiguous, cgroup-charged submission allocations (drivers/gpu/drm/asahi/file.rs + per-generation submit()): Switching SyncItem::parse() and copy_commands() 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 every generation (including G18's OutputPublication::accept() under JobQueue's mutex and M5's local publication) consumes/drops KVVec<SyncItem> in sleepable submit-ioctl context so vfree() never runs in atomic/IRQ context.
  • G15 pre-copy command-buffer cap (drivers/gpu/drm/asahi/g15/mod.rs): Overriding max_cmdbuf_size() to command::MAX_CMDBUF (4 MiB) rejects oversized streams with E2BIG before allocating/copying from userspace, matching G16.
  • Tests & trailers: Both test-fence-signalling.py and test-submit-restart.py are updated cleanly (host-tests green), and both commits carry valid Signed-off-by trailers.

Merge-Gate Notes

  • The J616s M4 Pro verification row (vkd3d-proton 65,536-command test, 1,999 dEQP-VK query_pool/timestamp cases with 0 diffs, 0 OOM kills, 0 failed units, 0 kernel errors, 0 GPU recoveries) is documented; note pr-readiness still expects a line citing the rebased head 58c13077, plus a G15 (M3 Pro/Max) smoke row and clearance of the prior review from @DjDeveloperr.

@DjDeveloperr

Copy link
Copy Markdown
Contributor

J773g (M4 Mac mini, G16G): PASS on the merge result with main. The exact head 58c130777d7b does not build for G16.

Why not the exact head: this branch's base a97744009d4d predates main's 53fc42ef2 ("drm/asahi: g16: pass compute_only=false to SignalBundle::publish"). At the head, drivers/gpu/drm/asahi/g16/fence.rs:591 still calls bundle.publish(fence)?, but SignalBundle::publish takes (current, compute_only):

error[E0061]: this method takes 2 arguments but 1 argument was supplied
   --> drivers/gpu/drm/asahi/g16/fence.rs:591:20

A rebase onto current main fixes that.

What ran: a guarded one-shot on the default cmdline of main 7f00dc6bc52c + this PR. The merge is clean, but main has changed 11 of this PR's 14 files since its base, so the row is on the merge result, not identical files.

On that kernel:

  • asahi-m4 selftests from the merged tree: test-submit-restart.py 1/1 and test-fence-signalling.py 7/7. They also pass when run against the exact head's tree, since they're CPU-only.
  • VK smoke (api.smoke, single-queue synchronization*.basic and compute.pipeline.basic): 123 pass, 15 not supported, 0 fail.
  • GPU mailbox receive IRQs grow normally across the smoke (+17).
  • Health: 0 GPU faults or recoveries, 0 WARNING: lines, 0 failed units. The error-level kernel lines are the same set as on a main 7f00dc6bc52c kernel, so there are 0 new kernel errors.

@DjDeveloperr

Copy link
Copy Markdown
Contributor

J516s (MacBook Pro 16" M3 Pro, 27.2 stub, G15S) row for 58c130777d7b: PASS, from one-shot boots of main 9a9862253576 + #3180, #3195, #3196, #3021, #3210 (no file overlap) on the default cmdline, with Mesa 0539df01eab6. test-submit-restart.py and test-fence-signalling.py pass against that tree. A dEQP-VK smoke (api.smoke, synchronization.basic, memory.allocation.basic and the command_buffers execute/submit cases) passes 149/149. The refusal check sends one submission of 4 MiB + 8 bytes: it returns E2BIG before any copy, and one of exactly 4 MiB gets past the size check and stops at the queue lookup (ENOENT). No GPU work is sent, and no kernel line is logged. 0 GPU faults or recoveries, 0 failed units, and no new kernel error lines beyond the MTP HID "no listeners" line the baseline also logs. On the 27.2 stub the J516s GPU runs the aurora-g16 backend, so this row covers the shared file.rs path and G16's bound. The new G15 max_cmdbuf_size() is only reachable on the 14.x g15 backend.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verdict: FINISH, then merge at 58c130777d7b: the code is ready; it needs rows at this head.

Blockers: none in the code. Syncs and command copies now use KVVec charged to the caller on every generation, including the M3 path in m3_submit.rs, so a large submission no longer needs contiguous pages, and G15 refuses an oversized command buffer before copying it.

Rows before merging: the re-push changed the code since the J616s run (the m3_submit.rs hunk is new), and file.rs is used by every GPU. So at this head it needs one M4 run and one G15 (M3) run, each with large submissions (the asahi-m4 submit-restart and fence-signalling tests are enough), a dEQP-VK smoke run and 0 new kernel errors. We'll arrange them if you can't.

Checked: thank you. No Apple material, no gates. CI green.

@DjDeveloperr
DjDeveloperr dismissed their stale review November 26, 2026 11:08

Superseded by the review at 58c1307

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 26, 2026
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 26, 2026 12:44
@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) needs-hw-row No hardware row at the PR head (bot) and removed ready-to-merge Meets the merge policy: merge it (bot) labels Nov 26, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

438cb839f1ad J615 (M3 Air, apple,t8122 / Apple M3 G15G C0, default cmdline) PASS: guarded one-shot exact-head boot (7.3.0-aurora-pr2905-aurora-pr3021-438cb839); host tests at head (test-fence-signalling.py 7/7 + sync_input C coalescing, test-submit-restart.py 1/1) PASS; aurora-g16 292400000.gpu RTKit v12 READY (10 cores, UAT self-check ok); vulkaninfo Borealis Apple M3 (G15G C0); glmark2-gbm --off-screen Score 5724 (build 5889 FPS, shading:phong 5561 FPS); deqp-vk 288/288 PASS / 0 FAIL (dEQP-VK.api.smoke.* 8/8, dEQP-VK.pipeline.monolithic.timestamp.* 278/278, dEQP-VK.query_pool.concurrent_queries.* 2/2); 0 GPU faults/recoveries, 0 page-allocation failures, 0 failed units, SELinux Enforcing, 0 AVC denials since boot; restored saved 7.3.0-aurora-fleet90-airs2 (next_entry empty, verified).

@RyanTheTide

Copy link
Copy Markdown
Contributor

438cb839f1ad J616s (Apple M4 Pro / T6040 / G16S B1) PASS: guarded one-shot exact-head boot (7.3.0-aurora-pr2905-aurora-pr3021-438cb839, default cmdline, aurora 28a600000.gpu RTKit v12 fw 25G83); glmark2-gbm --off-screen Score 21076, deqp-vk api.smoke.* 8/8 PASS + query_pool.concurrent_queries.* 2/2 PASS (pipeline.monolithic.timestamp.advanced_graphics_tests.draw_indirect_stage_in_render_pass hit VK_ERROR_DEVICE_LOST with 0 kernel GPU faults, reproduced identically in A/B control on stock 7.3.0-aurora-fleet89 / Borealis d4ad4a4dce); 0 GPU faults/recoveries, 0 page-allocation failures, 0 failed units, Enforcing, 0 AVC; restored to 7.3.0-aurora-fleet89 (next_entry= empty, verified).

@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label Nov 27, 2026

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verdict at 438cb839: merge.

Blockers: none.

Checked

  • Rows at this head:
    • J615 (M3 / G15, the generation "Not yet" listed) PASS: deqp-vk 288/288, glmark2, 0 GPU faults.
    • J616s (M4 Pro) PASS. The one DEVICE_LOST test fails the same way on the stock fleet kernel (A/B control), so it isn't caused by this PR.
  • APPROVED at this head by Dj and satchlj.
  • CI 18/18 after re-running the cancelled runs.
  • The G18/M5 rows stay as follow-ups.

@RyanTheTide
RyanTheTide merged commit 6077e2c into aurora-silicon:main Nov 27, 2026
22 of 110 checks passed
RyanTheTide added a commit that referenced this pull request Nov 30, 2026
main (#3021) made the parsed sync list a KVVec, and this branch's
coalesce_outputs() still took a KVec, so the forward merge no longer
builds (E0308 at file.rs:332). Take &mut KVVec<SyncItem>; the body only
uses Vec methods.

Signed-off-by: Ryan Murray <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpu Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants