Repository navigation
drm/asahi: g17: bound a submission's command stream before copying it - #3015
jgoyvaerts wants to merge 1 commit into
Conversation
DjDeveloperr
left a comment
There was a problem hiding this comment.
Formal §1–§6 pre-PR review at deff2b333b569dcfd86d414e1ebfeb5855b1f872 (base integration/aurora; live CI host-tests: FAIL).
Strengths
- Bound derivation (
drivers/gpu/drm/asahi/g17/command.rs:10-25): Verified against everycmd_typeaccepted byParser::next_parsed()(g17/command.rs:239-308): at mostMAX_COMMANDS_PER_SUBMISSION(64) work commands (RENDER/COMPUTE), each affected by at most 5 distinct state-setting kinds (3 attachment lists + render resources v1/v2 + compute resources), each up tosize_of::<drm_asahi_cmd_header>() + u16::MAXbytes (25,168,512B). Cleanly prevents the 4 GiBcmdbuf_sizeWARN_ON_ONCE(order > MAX_PAGE_ORDER)trigger beforefile.rsallocates. - §1 Code shape / §2 / §3 / §4 / §6: No chip/board/firmware gates; default-cmdline safe; commit
deff2b333b56carries human author/committerJonathan Goyvaerts <jonathan.goyvaerts@gmail.com>and humanSigned-off-by:only with zero AI commit trailers; PR body ends withAssisted-by:.
Blockers
-
CI failure in
host-tests(asahi-m4/test-command-stream.py) — HARD BLOCKER:- Live check run
host-testsfailed (462/463 passed,FAIL asahi-m4,not ok 1 - test-command-stream.py) with:
error[E0425]: cannot find value ATTACHMENT_KINDS in this scopeatParser.attachments: [Attachments; ATTACHMENT_KINDS]andAttachments::EMPTY; ATTACHMENT_KINDS. - Root cause:
tools/testing/selftests/drivers/gpu/asahi-m4/test-command-stream.py:63-64slicesdrivers/gpu/drm/asahi/g17/command.rsstarting at/// Where a render command's stage-prefix fields start(after line 10'sconst ATTACHMENT_KINDS: usize = 3;), and itsg17_constantsregex does not extractATTACHMENT_KINDS. - Fix: Update
tools/testing/selftests/drivers/gpu/asahi-m4/test-command-stream.pyto extractATTACHMENT_KINDS(or keepATTACHMENT_KINDSinside the sliced region) sohost-testspasses cleanly.
- Live check run
-
§1 / §5 Hardware Evidence:
- The J616s (
M4 Pro) hardware run was on a different commit ("with a weaker<= INT_MAXassert"), omits the §5 regression health tuple (SELinux denials, failed units) and an explicit oversized-submitE2BIGboundary check (cmdbuf_size > MAX_STREAMreturning-E2BIGwith 0 kernel warnings), and does not include an M5 (G17G/G17S/G17C) row even thoughg17/command.rsandg17/mod.rsserve both G17P and M5. Please add an exact-head hardware row with full §5 regression counts after fixing CI (and request an M5 run if no M5 machine is available).
- The J616s (
Non-Blocking Notes
const _: () = assert!(MAX_STREAM <= kernel::bindings::KMALLOC_MAX_SIZE as usize);(g17/command.rs:25): holds on ARM64 16K (ARCH_FORCE_MAX_ORDER = 11→32 MiB), butDRM_ASAHIalso allows(COMPILE_TEST && !GENERIC_ATOMIC64)withPAGE_SIZE_16KB. On non-ARM64 16K targets whereMAX_PAGE_ORDER = 10,KMALLOC_MAX_SIZEis16 MiB < 24 MiB, which would breakCOMPILE_TESTbuilds.- Note that
#2755is closed (unmerged), so the follow-up to switchfile.rs's command-buffer copy fromKVectoKVVec+GFP_KERNEL_ACCOUNTdoes not need to wait on#2755.
§1–§6 Checklist
- §1 No model gating: Pass in code; M5 coverage owed/requested under §1/§5.
- §2 Production-ready, no hacks: Pass.
- §3 Safety: Pass.
- §4 Clean-room & attribution: Pass.
- §5 Evidence: Request changes (CI
host-testsfailure + exact-head hardware row with full §5 health tuple). - §6 Naming: Pass.
Assisted-by: LLM (Gemini 4 Neon)
The submit ioctl copies the whole command stream from userspace before any parser sees it, and refuses only one longer than the GPU's max_cmdbuf_size(). G17 never set one, so it kept the default of usize::MAX: any cmdbuf_size up to 4 GiB was handed to the allocator. The copy is one kmalloc(), and past KMALLOC_MAX_SIZE (32 MiB with 16K pages) the page allocator refuses it with a WARN_ON_ONCE(), so userspace could trigger a kernel warning. Anything below that became a physically contiguous allocation as large as userspace asked for. The format has a real maximum, so take it from there. Each entry is a command header and a payload of at most u16::MAX bytes. A submission holds at most MAX_COMMANDS_PER_SUBMISSION work commands, and the rest of the stream sets what the work commands after it use: three attachment lists, the render resources and the compute resources. A set that a later one replaces before any work, or one after the last work command, changes nothing. The largest stream in which every entry has an effect is therefore 64 work commands, each after at most one set of each of the five kinds, every entry at its largest: 64 * 6 * (8 + 65535) bytes, about 24 MiB. A build-time assert keeps it within INT_MAX, the kvmalloc() limit, and on arm64 also within KMALLOC_MAX_SIZE, which depends on the architecture's page orders. Longer streams only repeat sets, so refuse them with E2BIG before copying, as G16 does with its own 4 MiB bound. The asahi-m4 command-stream selftest builds the G17 parser on the host; it now also takes ATTACHMENT_KINDS from the source. A KUnit test parses a submission of 64 largest work commands, checks that it fits the bound, and checks that a 65th is refused. Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
deff2b3 to
ec6ae20
Compare
|
Thanks @DjDeveloperr. New head
Assisted-by: LLM (Claude:Opus 5.5) |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Formal §1–§6 pre-PR re-review at live head ec6ae209d790eb48ced87505ee54bffb2163d945 (base integration/aurora 70a00e583b03; not superseded; live CI host-tests: PASS, MERGEABLE/CLEAN).
Verification of Fixes Since Prior Review
- CI
host-testsfixed:tools/testing/selftests/drivers/gpu/asahi-m4/test-command-stream.pynow extractsATTACHMENT_KINDSing17_constants, and livehost-testspasses cleanly. COMPILE_TESTbuild assert fixed:drivers/gpu/drm/asahi/g17/command.rs:25-27now pairs the unconditionalMAX_STREAM <= i32::MAX as usizeassert with#[cfg(CONFIG_ARM64)] const _: () = assert!(MAX_STREAM <= kernel::bindings::KMALLOC_MAX_SIZE as usize);. Verified againstdrivers/gpu/drm/asahi/KconfigthatDRM_ASAHIdepends onPAGE_SIZE_16KB, soKMALLOC_MAX_SIZEis always32 MiB >= 24 MiB(25,168,512B) onCONFIG_ARM64.- §5 Hardware evidence updated: J616s (
M4 Pro/G17P) testing now reports exactMAX_STREAMboundary checks (MAX_STREAMpasses size check toENOENT;MAX_STREAM + 1,64 MiB, andUINT32_MAXreturnE2BIGwith 0 kernel warnings / 0 new log lines),vkd3d-proton(544 d3d12 tests) +dEQP-VKquery_pool/timestamp (1999 cases) with 0 regressions / 0 refused submissions, and the §5 boot health tuple (0failed system/user units,0error-level kernel messages,0GPU recoveries, SELinux N/A / disabled). KUnit arm64 qemu passes745/746(1 skip) including the newasahi_g17_streamtest. Per §1, the author proved the change on the G17 Mac they own and requested an M5 run.
Non-Blocking Notes
- The J616s hardware test kernel differed from
ec6ae209d790only in compile-time asserts and host/KUnit tests (identical runtimemax_cmdbuf_size() -> 25,168,512); an exactuname/ M5 confirmation row remains welcome if available.
§1–§6 Checklist
- §1 No model gating: PASS — bound derived from the G17 command-stream format (
64 * 6 * (8 + 65535)), no chip/board/firmware gates; tested on owned G17 Mac with M5 run requested. - §2 Production-ready, no hacks: PASS — default cmdline, no hacks.
- §3 Safety: PASS — rejects oversized
cmdbuf_sizewithE2BIGbeforefile.rsallocates, preventing theWARN_ON_ONCE(order > MAX_PAGE_ORDER)trigger. - §4 Clean-room & attribution: PASS — commit
ec6ae209d790carries human author/committer (Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>) and humanSigned-off-by:only, zero AI commit trailers; PR body carriesAssisted-by:. - §5 Evidence: PASS — KUnit + CI
host-testsgreen + J616s boundary, workload, and §5 health tuple verified. - §6 Naming: PASS.
Ready for MERGETRAIN-LINUX4.
Assisted-by: LLM (Gemini 4 Neon)
|
J616s row on a kernel carrying this PR's exact bound code. Our m4.183 test kernel has the
An M5 row is still open. Assisted-by: LLM (Claude:Opus 5.5) |
G17 never set
max_cmdbuf_size(), so it kept the default ofusize::MAX. The submit ioctl copies the whole command stream into one kmalloc'd buffer before any parser sees it, andcmdbuf_sizeis au32. So any process with the render node can make the kernel:KMALLOC_MAX_SIZE(32 MiB with the 16K pages asahi requires), where the page allocator'sWARN_ON_ONCE(order > MAX_PAGE_ORDER)fires;This sets G17's bound from the format's real maximum, not a constant:
drm_asahi_cmd_headerplus a payload of at mostu16::MAXbytes (the header'ssizefield).MAX_COMMANDS_PER_SUBMISSION(64). The parser refuses at>=before counting the new one, so 64 are accepted.MAX_STREAM= 64 × 6 × (8 + 65535) = 25,168,512 bytes (24 MiB). Build-time asserts keep it withinINT_MAX(the kvmalloc limit) and, on arm64, withinKMALLOC_MAX_SIZE(32 MiB with 16K pages). The second is arm64-only becauseKMALLOC_MAX_SIZEdepends on the architecture's page orders, and a COMPILE_TEST build elsewhere can have a smaller one. A longer stream only repeats sets and gets E2BIG before the copy, as G16 does with its 4 MiB bound.Real streams are far smaller: Mesa's Vulkan driver sends at most 2 sets per work command, GL 1. Command payloads can be longer than their struct only with zero tails (
payload<T>()), which is the usual DRM extension rule, so the header'su16size really is the per-entry maximum.Relation to #2755: #2755 makes the default 16 MiB for every GPU. That is below this maximum, so G17 overrides it either way, and the two don't conflict.
Testing
asahi_g17_streamcase parses 64 zeroed 65535-byte renders, checks they fitMAX_STREAM, and checks that a 65th is refused.tools/asahi/run-host-tests.py(what CI runs): the asahi-m4 suite passes.test-command-stream.pybuilds the G17 parser on the host, and now also takesATTACHMENT_KINDSfrom the source. checkpatch: 0 errors.INT_MAXassert; the arm64 assert is build-time only, so it behaves the same.DRM_IOCTL_ASAHI_SUBMITwith onlycmdbuf_sizeset. ExactlyMAX_STREAMpasses the size check and fails at the queue lookup (ENOENT).MAX_STREAM + 1, 64 MiB andUINT32_MAXgetE2BIG. 0 kernel warnings and 0 new kernel log lines.The trigger was an order-3 GFP_KERNEL OOM kill under deqp-vk on that machine, from these copies. Making the copy itself not need contiguous pages is a separate change, waiting on #2755.
Assisted-by: LLM (Claude:Opus 5.5)