Skip to content

drm/asahi: bound GEM_USERPTR pins by the GPU memory limits, not RLIMIT_MEMLOCK - #2961

Merged
RyanTheTide merged 1 commit into
integration/aurorafrom
vk-memlock/userptr-gpu-ledger
Nov 24, 2026
Merged

RyanTheTide merged 1 commit into
integration/aurorafrom
vk-memlock/userptr-gpu-ledger

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

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 case memlock_limit becomes memlock_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:

Mac Geekbench 6.7.1 Vulkan before after userptr selftest after dEQP-VK.memory.external_memory_host.* before / after
M4 Pro 16" (J616s) aborts: allocate_buffer_host(...) returned -2 8/8 workloads, https://browser.geekbench.com/v6/compute/6987994 5/5 4 pass, 8 not supported, 0 fail / same
MacBook Neo (A18 Pro) aborts: same error 8/8 workloads, https://browser.geekbench.com/v6/compute/6987830 5/5 4 pass, 8 not supported, 0 fail / same

No kernel errors on either Mac after the change.

  • The ledger limits are on by default. On the Neo (7.29 GB RAM) they are 5.24 GB for the device and 3.91 GB per client (gpu_memory in sysfs).
  • checkpatch is clean, rustfmt is clean, and the module builds with no new warnings.

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
  • Kit: module-only aurora.ko built 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.
  • Selftest with the old source on the patched module: memlock_limit fails as expected, because the behaviour it tested is gone. The other 4 pass.
  • Selftest with the new source on the stock module: memlock_does_not_bound fails 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 fdinfo drm-total-system rise by the object's size and return after GEM_CLOSE.

Assisted-by: LLM (Claude:Opus 5.5)

…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>
@funkzy

funkzy commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Source review at 8a92c87c looks clean — removing the RLIMIT_MEMLOCK check on pinned_vm leaves memacct::LEDGER as the single bound for GEM_USERPTR (including across fork() and all error/drop paths), and we'll close #2777 in favour of this.

One small non-blocking note on the PR body and commit message: they describe GEM_USERPTR and GEM_CREATE as the same kind of unevictable memory held until freed. On G17, idle GEM_CREATE objects can be reclaimed under memory pressure and count in the creator's MM_SHMEMPAGES, whereas GEM_USERPTR pages are not reclaimable and drop out of process RSS once unmapped (so the OOM killer no longer sees them, though they stay charged to the memory cgroup, matching i915). It may be worth rewording that sentence to note the OOM-visibility trade-off.

Assisted-by: LLM (Gemini:Neon)

@RyanTheTide
RyanTheTide marked this pull request as ready for review November 24, 2026 09:04
@RyanTheTide
RyanTheTide merged commit 7092b1d into integration/aurora Nov 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants