Repository navigation
drm/asahi: report that GEM_USERPTR pins are not bounded by RLIMIT_MEMLOCK - #3088
Conversation
…LOCK Since commit 8a92c87 ("drm/asahi: bound GEM_USERPTR pins by the GPU memory limits, not RLIMIT_MEMLOCK") GEM_USERPTR takes a range of any size the GPU memory limits admit. Earlier kernels with GEM_USERPTR charge the pins to the caller's RLIMIT_MEMLOCK and refuse a larger range with ENOMEM; the systemd default is 8 MiB. Userspace cannot tell the two apart before it imports, so an API without a size bound of its own on imports (VK_EXT_external_memory_host) either has to offer them on every kernel and fail large imports on the older ones, or check the memlock limit on every kernel and stop offering them where the limit no longer applies. Report DRM_ASAHI_FEATURE_USERPTR_NO_MEMLOCK with DRM_ASAHI_FEATURE_USERPTR. Bit 42 is taken by DRM_ASAHI_FEATURE_COMPUTE_MULTI_CHANNEL, which is in review. The userptr selftest checks the bit in memlock_does_not_bound. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
Independent source and hardware evidence review at I checked the module-build commit ROW e21d48c | MacBook Neo (J700) | PASS | Fleet88 with the candidate module, 5/5 USERPTR selftests and 96 MiB imported with 0 mismatches at stock 8 MiB memlock. Saved boot restored. ROW e21d48c | J616s (M4 Pro regression) | PASS | Fleet88 with the candidate module, 5/5 USERPTR selftests and 96 MiB imported with 0 mismatches at stock 8 MiB memlock. Saved boot restored. |
RyanTheTide
left a comment
There was a problem hiding this comment.
Verdict: post-merge review at e21d48c624bd (merged as 9e9749c4). I found no defect and there is nothing to revert or fix.
Blockers: none
Checked:
- No uapi collision. On
main, bits 40 (VDM_USC_INVALIDATE), 41 (COMPUTE_ONLY) and 43 (USERPTR_NO_MEMLOCK) are defined. Bit 42 is used only by the open #3035 (COMPUTE_MULTI_CHANNEL). No other open linux PR touchingasahi_drm.h(3044, 3035, 2887) and no open mesa PR touching the header copy (585 adds bit 41, 390) defines bit 43. The mesa copy from aurora-silicon/mesa#963 uses the same value. - The bit tells the truth. On
main,UserPages::pin()(gem.rs~L500-560) adds the range tomm->pinned_vmand pins withFOLL_LONGTERMwithout anyRLIMIT_MEMLOCKcomparison. The GPU memory ledger is what bounds it.file.rsreports the bit under the samesupports_user_memory()condition asDRM_ASAHI_FEATURE_USERPTR, so the bit is never reported without USERPTR. - Selftest:
memlock_does_not_boundnow also expects the bit. It is anEXPECT_*, so on an older kernel the test still runs the memlock body and reports both results.
Notes (not blocking):
- Backports: the bit is only true together with the
UserPages::pin()change from #2961. Any lab or fleet branch that cherry-picks this commit must carry #2961 too. Otherwise Borealis offers unbounded host imports on a kernel that still charges memlock, and large imports fail withVK_ERROR_OUT_OF_DEVICE_MEMORY. ADepends-on/Fixes-style note in the fleet cut list would cover it. - Pre-existing from #2961, not this PR: these pins still raise
pinned_vm, which io_uring fixed buffers, RDMA and VFIO compare withRLIMIT_MEMLOCK. A process that imports, say, 96 MiB of host memory into the GPU at the default 8 MiB limit will then have its io_uring buffer registration refused. That is the documented trade-off ingem.rs. It may be worth one line in the uapi comment ("still shown in VmPin and counted by other pinners") so userspace isn't surprised; the mesa header text already says the pages show in VmPin. - The PR merged without a non-author review. This pass is that review after the fact.
Evidence
git grep '<< *4[0-9])' 9e9749c4 -- include/uapi/drm/asahi_drm.hgh pr difffor linux 3044/3035/2887 and mesa 585/390, grepped for bit 4x definesgit grep -n 'pinned_vm\|FOLL_LONGTERM\|MEMLOCK' 9e9749c4 -- drivers/gpu/drm/asahi:gem.rsL454-598; no rlimit check on the pin path
What: Report a new feature bit,
DRM_ASAHI_FEATURE_USERPTR_NO_MEMLOCK(bit 43), alongsideDRM_ASAHI_FEATURE_USERPTR. Since #2961, GEM_USERPTR takes any range the GPU memory limits admit. Older kernels charge the pins to RLIMIT_MEMLOCK (8 MiB by default). Userspace can't tell the two apart before it imports, so Borealis has to choose between failing large host imports on older kernels and hiding VK_EXT_external_memory_host on fixed ones. Borealis reads this bit in aurora-silicon/mesa#963.Tested: MacBook Neo and J616s M4 Pro, with fleet88 and this commit's aurora.ko: userptr selftest 5/5 (it now also checks the bit), Borealis offers VK_EXT_external_memory_host at the default 8 MiB, a 96 MiB host import works, Geekbench 6 Vulkan completes, dEQP-VK.memory.external_memory_host.* 4 pass / 8 not supported / 0 fail. No kernel errors.
Risk: two-way · Macs whose GPU offers GEM_USERPTR (M4 Pro/Max, M5 family, A18 Pro). It only adds a bit; no behaviour changes.
Not yet: nothing on hardware.
Details
file.rs: the bit is reported whereversupports_user_memory()reports GEM_USERPTR, sinceUserPages::pin()no longer checks RLIMIT_MEMLOCK.DRM_ASAHI_FEATURE_COMPUTE_MULTI_CHANNEL(drm/asahi: g17: fan M5 Pro compute out to sibling channels for sustained heavy kicks #3035).memlock_does_not_boundalso expects the bit. On a kernel without this commit only that assertion fails (4/5).checkpatch --strict is clean. rustfmt shows the same differences in file.rs before and after this commit; none are from these lines.
Evidence
Module-only aurora.ko: fleet88 (
d420ae2b) + this commit's diff, built in a copy of the tree fleet88 was built in. Its Rust undefined symbols match the stock fleet88 aurora.ko (181/181), vermagic 7.3.0-aurora-fleet88. It was loaded on a one-shot boot that blacklists the stock module, and each Mac rebooted to its saved fleet88 afterwards. The rows were run with the code of this commit; amending the message to fix a checkpatch commit reference didn't change the code.