Repository navigation
drm/asahi: keep a submission's syncs and command copy off contiguous pages - #3021
Conversation
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 <[email protected]>, 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)
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
J616s row, as asked. Our m4.185 kernel carries every line this PR adds (checked line by line against head
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. |
…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]>
4ac613b to
58c1307
Compare
satchlj
left a comment
There was a problem hiding this comment.
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-generationsubmit()): SwitchingSyncItem::parse()andcopy_commands()fromKVec(GFP_KERNEL) toKVVec(GFP_KERNEL_ACCOUNT) eliminates order-3kmallocOOM kills on large userspace-sized submissions without pinning physically contiguous pages. Verified every generation (including G18'sOutputPublication::accept()underJobQueue's mutex and M5's local publication) consumes/dropsKVVec<SyncItem>in sleepable submit-ioctl context sovfree()never runs in atomic/IRQ context. - G15 pre-copy command-buffer cap (
drivers/gpu/drm/asahi/g15/mod.rs): Overridingmax_cmdbuf_size()tocommand::MAX_CMDBUF(4 MiB) rejects oversized streams withE2BIGbefore allocating/copying from userspace, matching G16. - Tests & trailers: Both
test-fence-signalling.pyandtest-submit-restart.pyare updated cleanly (host-testsgreen), and both commits carry validSigned-off-bytrailers.
Merge-Gate Notes
- The J616s M4 Pro verification row (
vkd3d-proton65,536-command test, 1,999dEQP-VK query_pool/timestampcases with 0 diffs, 0 OOM kills, 0 failed units, 0 kernel errors, 0 GPU recoveries) is documented; notepr-readinessstill expects a line citing the rebased head58c13077, plus a G15 (M3 Pro/Max) smoke row and clearance of the prior review from@DjDeveloperr.
|
J773g (M4 Mac mini, G16G): PASS on the merge result with main. The exact head Why not the exact head: this branch's base A rebase onto current main fixes that. What ran: a guarded one-shot on the default cmdline of main On that kernel:
|
|
J516s (MacBook Pro 16" M3 Pro, 27.2 stub, G15S) row for |
DjDeveloperr
left a comment
There was a problem hiding this comment.
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.
Superseded by the review at 58c1307
|
|
|
|
RyanTheTide
left a comment
There was a problem hiding this comment.
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.
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]>
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 EINVALNot 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: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.Evidence
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