Repository navigation
drm/asahi: bound GEM_USERPTR pins by the GPU memory limits, not RLIMIT_MEMLOCK - #2961
Conversation
…T_MEMLOCK GEM_USERPTR refused a range that would take the caller's pinned_vm past RLIMIT_MEMLOCK unless it had CAP_IPC_LOCK. The default limit is 8 MiB (systemd's DefaultLimitMEMLOCK), so VK_EXT_external_memory_host could import only small buffers. Geekbench 6 Vulkan imports a 90.7 MiB host buffer; the import failed with ENOMEM, Vulkan returned VK_ERROR_OUT_OF_DEVICE_MEMORY and the benchmark aborted on every default install. The pages of a user-memory object and the backing of a GEM_CREATE object are the same kind of memory: unevictable, held for the GPU until the object is freed. GEM_CREATE is bounded only by the client and device limits of the GPU memory ledger, and gem_userptr() already admits the user-memory object's size into that ledger. The memlock check bounded the same memory a second time, at a far lower level, and only for one of the two ways to get it. A process that may not import a buffer may still allocate one of the same size and copy into it. Other DRM drivers that pin user memory for buffer objects (i915, etnaviv) do not charge RLIMIT_MEMLOCK either; amdgpu and xe do not pin. Drop the check. The pages are still added to the mm's pinned_vm, so VmPin in /proc/<pid>/status shows them and other long-term pinners keep counting them against their own limits. The UAPI comment says so, and the selftest's memlock_limit case becomes memlock_does_not_bound: it pins 64 pages with a soft limit of 0 and without CAP_IPC_LOCK. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
Source review at One small non-blocking note on the PR body and commit message: they describe Assisted-by: LLM (Gemini:Neon) |
Problem
Geekbench 6 Vulkan aborts on every default install of an M4 Pro or A18 Pro Mac. It imports a 90.7 MiB host buffer with VK_EXT_external_memory_host. GEM_USERPTR checks the pinned pages against RLIMIT_MEMLOCK, which defaults to 8 MiB (systemd's DefaultLimitMEMLOCK). The ioctl fails with ENOMEM, Borealis returns VK_ERROR_OUT_OF_DEVICE_MEMORY (-2) and the benchmark stops. Any application that imports a host buffer larger than 8 MiB fails the same way.
Change
GEM_USERPTR no longer checks RLIMIT_MEMLOCK. The GPU memory ledger bounds the pins instead:
gem_userptr()already admits each user-memory object into its per-client and device limits, the same limits that bound GEM_CREATE. The two kinds of backing are the same kind of memory: unevictable pages held for the GPU until the object is freed. The memlock check bounded that memory a second time, at a much lower level, and only for the import path. A process refused an import could still allocate a buffer of the same size and copy into it.Other DRM drivers that pin user memory for buffer objects (i915, etnaviv) do not charge RLIMIT_MEMLOCK. amdgpu and xe do not pin at all.
The pages are still counted in the mm's
pinned_vm, so VmPin shows them. The UAPI comment says this. The selftest casememlock_limitbecomesmemlock_does_not_bound.No Mesa change is needed. Raising the distro memlock default was considered and rejected: it would raise the mlock limit of every program, and with this change no distro needs it.
Testing
All rows ran as the desktop user with the default limits (memlock 8192 KiB soft and hard, no prlimit), on fleet85 with this commit as a module-only build:
allocate_buffer_host(...) returned -2No kernel errors on either Mac after the change.
gpu_memoryin sysfs).Still to run
Nothing on hardware. Only G17 GPUs offer GEM_USERPTR, so M1 to M3 Macs and the base M4 never take this path. On those Macs Borealis does not expose VK_EXT_external_memory_host.
This supersedes the premise of #2777, which moves the same RLIMIT_MEMLOCK check to
user_struct::locked_vm: that still fails Geekbench at the default 8 MiB.Row details
aurora.kobuilt against the fleet85 tree, loaded from a one-shot boot entry that blacklists the stock module. The entry was removed afterwards and the Mac rebooted to its default.memlock_limitfails as expected, because the behaviour it tested is gone. The other 4 pass.memlock_does_not_boundfails with -ENOMEM, which reproduces the bug.memlock_does_not_bound: drops CAP_IPC_LOCK, sets the RLIMIT_MEMLOCK soft limit to 0, pins 64 pages (1 MiB), checks that VmPin and fdinfodrm-total-systemrise by the object's size and return after GEM_CLOSE.Assisted-by: LLM (Claude:Opus 5.5)