Repository navigation
drm/asahi: g17: copy and prepare VM_BIND batches in kvmalloc memory - #3920
Conversation
vm_bind_g17() copies the user's array of bind operations into a KVec and prepares every operation into a PreparedUserBindBatch whose KVec has room for all of them, 160 bytes an operation on arm64. Both are kmalloc'ed, so physically contiguous. A batch of about 210,000 operations or more asks kmalloc for more than 32 MiB: the page allocator warns (mm/page_alloc.c, __alloc_frozen_pages_noprof), VM_BIND fails with ENOMEM and Borealis reports a lost device. One vkQueueBindSparse of 100,000 blocks of a sparse image is enough, since Borealis binds each 64 KiB block as two 32 KiB halves, each with its read-only shadow. Neither buffer needs to be physically contiguous. Use KVVec, which falls back to vmalloc, for both. Signed-off-by: Jos Dehaes <jos.dehaes@gmail.com>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
satchlj
left a comment
There was a problem hiding this comment.
Reviewed 90f7cf541193: bytes in vm_bind_g17() and PreparedUserBindBatch::ops are host-only buffers never passed to DMA or required to be physically contiguous, and UserSliceReader::read_all() is generic over Allocator, so switching both to KVVec cleanly avoids kmalloc order-limit warnings and ENOMEM on large sparse VM_BIND batches.
Non-blocking follow-up note: VmLifetime's state.unmaps (drivers/gpu/drm/asahi/mmu/lifetime.rs) is still a KVec<PreparedUserUnmap> and calls state.unmaps.reserve(batch.ops.len() - start, GFP_KERNEL) in defer_bind_batch(), so a large (>~210k op) all-unmap batch against a quarantined VM would hit the same kmalloc ceiling.
|
Exact-head M5 Max ( Reproducer (
|
|
Exact-head J413 (MacBook Air 13" M2, Tested with
System booted with 0 failed units and clean |
|
Local CI for head Hosted Actions on this fork PR still wait for approval, so I ran the affected workflow steps on pc on a merge tree.
|
What:
vm_bind_g17()holds a batch's user copy (32 bytes an operation) and its prepared operations (160 bytes each) inKVec, which iskmallocmemory and so physically contiguous. A batch of about 210,000 operations needs more than 32 MiB. The page allocator then warns,VM_BINDfails withENOMEM, and Borealis reports a lost device. OnevkQueueBindSparseof 100,000 sparse-image blocks is enough to cause this, since Borealis binds each 64 KiB block as four operations. Both buffers are nowKVVec, which falls back to vmalloc.Tested: J614c (M4 Max) at
90f7cf5411: onevkQueueBindSparseof 100,000 and of 200,000 blocks (400,000 and 800,000 operations) binds with no warning and completes; before this change both warned and failed withENOMEM.Risk: two-way door · all Macs:
vm_bind()hands every GPU with tracked submission tovm_bind_g17()(G14 on firmware 27.2, G15, G16, G17, G18, M3, M5)Not yet: other Macs.
Details
vm_bind_g17()reads the user's array withread_all()into aKVec<u8>(stride x count bytes). It then buildsPreparedUserBindBatch::new(&vm, count), which isKVec::with_capacity(count)ofPreparedUserBindOp, 160 bytes an operation on arm64. The second buffer is the one that fails. In the warning below, x22 =0x3d09000= 64,000,000 bytes = 400,000 operations x 160. A Mario Kart World run hit the same warning with 59,211,200 bytes (370,070 operations).Neither buffer is handed to hardware or needs to be physically contiguous, so
KVVec(kvmalloc: kmalloc first, vmalloc above what kmalloc can give) changes nothing else. Indexing,iter(),iter_mut(),drain(start..)andchunks_exact()work the same on it.The count is still bounded only by what userspace asks for: the batch costs 192 bytes an operation in kernel memory. A
bind_batch_limit()for G17 could cap it withEINVAL, but Borealis would then have to split its batches. I left that out of this change.Warning on
main+ Borealis, onevkQueueBindSparseof 100,000 blocks:Borealis then logs
DRM_IOCTL_ASAHI_VM_BIND failed: Cannot allocate memory (vm=1, ops=400000), andvkQueueWaitIdlereturnsVK_ERROR_DEVICE_LOST.Evidence
Repro
bigbind: onevkQueueBindSparsethat binds N 64 KiB blocks of a sparse 16384x16384 RGBA8 array image (aliased) to one 64 KiB allocation. Source below.b98bf00b32+ #2170 + #3200)ENOMEM,vkQueueWaitIdle-4With 43.6, binds of 100,000 blocks and more succeeded, but the queue still hung afterwards on older Mesa. That came from a separate Borealis bug: sparse images of 4 GiB or more got a 32-bit address range (mesa fix: https://github.com/joske/mesa/tree/fix/borealis-sparse-image-4gib, PR to aurora-silicon/mesa follows). With that fixed as well, 100,000 and 200,000 blocks bind and complete with no kernel message.
At the head of this PR (
90f7cf5411on main5a870d0f0b), booted on J614c, with Borealis at aurora-wip689b2fe3dbfplus the mesa fix:With Borealis without the mesa fix on the same kernel, 100,000 and 200,000 blocks also bind with no warning, and then hang on the 4 GiB address bug, as described above.
RADV (RX 6800) binds 200,000 blocks in one call without issue.