Repository navigation
Conversation
|
The accounting looks correct to me.
The only hardware row is the J775D. Rows from the other G17 Macs (A18 Pro, M4 Pro) would be good: Assisted-by: LLM (Claude:Opus 5.5) |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Pre-PR checklist review on 464023d790812a1522cdf7b3d8eb8aa1c790c309 (CI: host-tests green; note SEP source checks / rust-build / kunit workflows did not trigger for drivers/gpu/drm/asahi/ paths).
Blockers (REQUEST_CHANGES)
-
Build failure with
CONFIG_KUNIT=m(-Dwarnings/dead_code):#[kernel::macros::kunit_tests(asahi_gem_user_memory)]expands to#[cfg(CONFIG_KUNIT = "y")](rust/macros/kunit.rs:44), somod user_memory_testsis compiled out whenCONFIG_KUNIT=m(standard on distro kernels).- However,
drivers/gpu/drm/asahi/gem.rs:1075gates the four privateextern "C"KUnit helpers with#[cfg(CONFIG_KUNIT)], which Kbuild defines for both=yand=m(scripts/kconfig/confdata.c:799). UnderCONFIG_KUNIT=m, all fourextern "C"declarations have no callers and fail the build witherror: function ... is never usedunder-Dwarnings(dead_code). - Every other KUnit helper in
drivers/gpu/drm/asahi/(g17/kick.rs,pairs.rs,preparation.rs,queue/admission.rs,runtime.rs) uses#[cfg(CONFIG_KUNIT = "y")]. - Matching that on the C side,
drivers/gpu/drm/asahi/user_pages.c:67anduser_pages.h:21should use#ifdef CONFIG_KUNIT(i.e.IS_BUILTIN(CONFIG_KUNIT)) instead of#if IS_ENABLED(CONFIG_KUNIT), so the test-onlyasahi_test_drop_ipc_lock()/asahi_test_user_locked_vm_add()/asahi_test_set_memlock()helpers are not compiled into productionaurora.kowhenCONFIG_KUNIT=m.
-
KUnit test cleanup underflows global
root_user->locked_vmon early error return (drivers/gpu/drm/asahi/gem.rs:887-914):- Inside the cleanup closure in
pins_count_against_the_user(),UserPages::pin(addr, 2 * PAGE_SIZE, true)?(line 889) runs beforeasahi_test_user_locked_vm_add(held)(line 897). - If that
?returnsErr(beforeheldis added), line 911 still unconditionally executesasahi_test_user_locked_vm_add(-held), subtracting1024from the globalroot_user->locked_vmthat was never added and leaving it negative for the rest of the kernel run. - Track whether
heldwas added (e.g.,let mut held_added = false;) and only subtract-heldif it was actually added.
- Inside the cleanup closure in
Code Review of Core Accounting Path (Looks Good)
asahi_user_account()/asahi_user_unaccount()inuser_pages.c: Matchesio_uring(ns_capable_noaudit(&init_user_ns, CAP_IPC_LOCK)+ atomic cmpxchg loop onuser->locked_vm, pluscheck_add_overflowwhich is strictly safer) andiommufd's underflowWARN_ONwhile still callingfree_uid(user).UserPages::pin()/Drop:userandmmaccounting unwind cleanly ifpages.reserve(),asahi_pin_user_fragments(), orpin_user_pages_fast()fail afterthisis constructed.include/linux/sched/user.h: AddingIS_ENABLED(CONFIG_DRM_ASAHI)touser_struct::locked_vmmatchesIS_ENABLED(CONFIG_IOMMUFD).asahi_test_drop_ipc_lock()/asahi_test_restore_creds():prepare_creds()+override_creds()+put_cred(revert_creds())refcounting is correct for this kernel'srcu_replace_pointer-basedoverride_creds/revert_creds.
Pre-PR Checklist (§1–§6)
- §1 No model gating: Pass — applies to all GPUs supporting user-memory objects (
File::supports_user_memory()). - §2 Production-ready: Pass — default command line, no hacks.
- §3 Safety: Pass — uses standard
RLIMIT_MEMLOCK+user_struct::locked_vm. - §4 Clean-room & attribution: Pass — clean human commit identity and
Signed-off-by;Assisted-by:in PR body. - §5 Evidence: Strong J775D A/B row (including Borealis
dEQP-VK.memory.external_memory_host.*and cross-process fork/exitENOMEMverification), though as noted in## Still to runtheCONFIG_MM_SUBPAGEfragment-pin path (user4k/gem-userptr) and other G17 Macs remain to be run; also please re-verify a build withCONFIG_KUNIT=mafter fixing the cfg gate above. - §6 Naming: Pass (correctly uses Borealis).
Assisted-by: LLM (Gemini 4 Neon)
…oss fork and exit GEM_USERPTR counts the pages it pins in the calling mm's pinned_vm and compares that count with RLIMIT_MEMLOCK. The object belongs to the DRM file, not to the mm. A forked child starts with nothing counted, its pins land in the file it shares with its parent, and they stay pinned after it exits, counted against an mm that no longer runs anything. The limit therefore does not bound what one user can pin. Charge the pins to the user instead, in user_struct::locked_vm, as io_uring does for its registered buffers (__io_account_mem()) and iommufd for its pinned pages: every process of the user shares the count, and a pin stays charged until its object is freed. As in both, a CAP_IPC_LOCK caller is not charged. The mm's pinned_vm still counts the pages, as it did. The UAPI comment says so, and the driver joins the users of user_struct::locked_vm in <linux/sched/user.h>, as iommufd did. Only the G17 backend takes user-memory objects (File::supports_user_memory()), so other GPUs do not run this code. A process with a smaller page size is charged the same native pages. A KUnit case checks that a CAP_IPC_LOCK caller is not charged; that, without it, pages charged to the test's user as another process of that user would charge them make the next pin fail although the test's own mm has none; and that dropped pins are given back. The case and its helpers in user_pages.c are built only with built-in KUnit and a built-in driver, where the suite runs before userspace and nothing else charges the test's user, and it undoes its changes before its final assertion. This is a narrow fix. The charge loop in user_pages.c is the sixth copy of one that io_uring (__io_account_mem()), iommufd (incr_user_locked_vm()), secretmem, the network zerocopy path (mm_account_pinned_pages()) and XDP umem each carry, and every user of user_struct::locked_vm adds its option to the condition in <linux/sched/user.h>. The structural fix is one charge and uncharge helper for user_struct::locked_vm, with a Kconfig symbol that its users select in place of that condition. It changes code owned by mm, io_uring, iommufd and networking, so it is left as a follow-up for those owners. This copy keeps their arithmetic, adding only an overflow check, so that such a helper can replace it. Fixes: ecc94a2 ("drm/asahi: GEM_USERPTR, buffer objects over the caller's memory") Reported-by: Erik Bourget <erik@ebourget.net> Suggested-by: Erik Bourget <erik@ebourget.net> Signed-off-by: Jeff Queisser <funkzy@users.noreply.github.com>
464023d to
1121847
Compare
|
Thanks, dj and Ryan. Both blockers were real; the commit is amended (now 1121847).
Assisted-by: LLM (Claude:Opus 5.5) |
|
Thanks. Re-checked at 1121847 against 464023d.
The J775D fork-and-exit row is at this head, and the earlier dEQP row at 464023d still applies, because the runtime code is identical. Still missing: the same Assisted-by: LLM (Claude:Opus 5.5) |
|
Not on integration/aurora yet: on daa9e2d GEM_USERPTR pins are still counted only in the calling mm's pinned_vm. The commit applies cleanly on daa9e2d. Both blockers from the review of 464023d (the CONFIG_KUNIT=m build and the test cleanup) are addressed at 1121847, but the requested-changes review has not been refreshed since; @DjDeveloperr, could you re-check that head? The hardware rows still missing are dEQP-VK.memory.external_memory_host.* at the default memory-lock limit plus a normal desktop session with Borealis on the A18 Pro and the M4 Pro. |
|
Rows at the default memory-lock limit (8 MiB soft and hard, desktop user, no prlimit) on a MacBook Neo, fleet85:
Charging |
|
Thanks for the rows, Ryan. Closing this in favour of #2961, which fixes the underlying cause cleanly by removing the Assisted-by: LLM (Gemini:Neon) |
Change of approach
The earlier version charged the pins with the driver's own copy of the
user_struct::locked_vmcharge loop and addedthe driver to the condition in
<linux/sched/user.h>, described as following io_uring and iommufd. That loop is asixth copy: io_uring, iommufd, secretmem, the network zerocopy path and XDP umem each carry one, and each user adds
its option to that condition, because the kernel has no shared helper for this count. This version keeps the code
and labels it a narrow fix, here and in the commit message, and names the shared helper as a follow-up for the
owners of that code (under Still to run).
Problem
GEM_USERPTR counts the pages it pins in the calling mm's
pinned_vmand compares that count with RLIMIT_MEMLOCK.The object belongs to the DRM file, not to the mm. A forked child starts with nothing counted, its pins land in the
file it shares with its parent, and they stay pinned after it exits, counted against an mm that no longer runs
anything. So the limit doesn't bound what one user can pin.
Why this shape
The limit was checked in one place,
UserPages::pin(), against a count that belongs to an mm, while the pinnedobject belongs to the DRM file and can outlive the process that made it. The per-mm count (
mm->pinned_vm, as RDMAumem and amdxdna use it) has that property wherever the pinned object outlives the process; counting per DRM file
instead would still give each file of the user its own full limit. The change uses the count the kernel already keeps
for pins owned by a file rather than a process:
user_struct::locked_vm, which io_uring (__io_account_mem()) andiommufd charge the same way. Every process of the user then draws on one limit, a pin is charged until its object is
freed, and a CAP_IPC_LOCK caller is not charged at all, as in both. The mm's
pinned_vmstill counts the pages for/proc. Only the G17 backend creates user-memory objects, so this is the only place they are charged.The charge itself is narrow. The structural fix is one charge and uncharge helper for
user_struct::locked_vm, usedby all six, with a Kconfig symbol its users select in place of the growing condition in
<linux/sched/user.h>. Itchanges code owned by mm, io_uring, iommufd and networking, so it is a follow-up for those owners rather than part of
this PR. The copy here keeps their arithmetic, adding only an overflow check, so such a helper can replace it.
Change
asahi_user_account()andasahi_user_unaccount()inuser_pages.c, beside the driver's other pin helpers: thesame arithmetic as
__io_account_mem()plus an overflow check, with iommufd's underflow warning on release (anarrow copy, above).
UserPagesholds the charged user with a reference until it is dropped.<linux/sched/user.h>: the driver is added to the condition foruser_struct::locked_vm, as iommufd andsecretmem were (the Kconfig symbol above would replace that condition).
DRM_IOCTL_ASAHI_GEM_USERPTRsays what is counted.CONFIG_MM_SUBPAGE, drm/asahi: GEM_USERPTR in processes with a smaller page size #2226) is charged the same nativepages.
VK_EXT_external_memory_hostimports are the userspace that creates these objects.They now share one RLIMIT_MEMLOCK across all of the user's processes, where each process had its own before. Under
systemd's default (8 MiB for a user session) the sum of a user's host imports is what is limited; an import past
it fails with
VK_ERROR_OUT_OF_DEVICE_MEMORY, as one that took a single process past its own limit did before.The Gallium driver doesn't create these objects, and under virtio (
agx_has_userptr()) they aren't used.Testing
pins_count_against_the_userinasahi_gem_user_memory. A caller with CAP_IPC_LOCK is notcharged, while its mm still counts the pages. With CAP_IPC_LOCK dropped and RLIMIT_MEMLOCK set just above what the
test's user holds, pins within the limit are charged and given back. Once pages are charged to the user as another
of its processes would charge them, the next pin is refused, although the test's own mm has none. The case and its
helpers are built only with built-in KUnit and a built-in driver, where the suite runs before userspace and nothing
else charges the test's user; it is reported as skipped otherwise. Its checks are error returns, so it undoes its
changes before its one assertion. On integration/aurora cacf355 plus this change only, 375 of 377 cases pass
in 76 suites and 2 skip, as on integration alone, where the removed
memlock_limit_policycase runs instead.asahi-userptr-user-limit-1(integration/aurora000ab96 plus arm64: dts: apple: t6050-j775d: Give the Mac Studio (M5 Ultra) a working GPU, and its M and P core capacities (754/1024) to the scheduler #1973, the J775D GPU node, without which the J775D has no GPU and so no GEM_USERPTR, plus this
change at 1121847) against kit
asahi-userptr-user-limit-1b(the same base and arm64: dts: apple: t6050-j775d: Give the Mac Studio (M5 Ultra) a working GPU, and its M and P core capacities (754/1024) to the scheduler #1973 alone), windowryan2775d@20261122-1247. One boot each through the 27.0 firmware and Aura main dff1235d, default kernel command
line, read-only root. Both come up with the GPU's render node.
GEM_USERPTR into the DRM file they share, and exit. With this change 2 pin and 6 are refused with ENOMEM, so the
user holds 16 MiB; without it all 8 pin, 64 MiB. Once the file is closed a new pin succeeds on both, so the
charge is given back.
options it needs, and systemd-networkd-persistent-storage because the test boots mount the root read-only.
receiver, four refusals of a cpufreq boost request). The boot with this change also has a USB descriptor-read
timeout from the KVM, which a boot of integration alone in the same session also has. No WARNING, BUG or Oops.
ALARM has no SELinux, so there is no AVC count.
trackh-g10(the posted version of this change, 464023d, whose amendmentchanges only its KUnit case) against kit
trackh-gb(without it), on integration/aurora cacf355 plus whatthe J775D's GPU needs under the 27.2 firmware: drm/asahi: t6050: identify the K114/K116 27.2 (26B8125) G17S firmware (on #1173) #1650 (its M5 InitData), arm64: dts: apple: t6050-j775d: Give the Mac Studio (M5 Ultra) a working GPU, and its M and P core capacities (754/1024) to the scheduler #1973, and two commits of ours not yet
posted, "drm/asahi: t6050: Run the Mac Studio's (M5 Ultra) GPU under the 27.2 boot stub: admit its 26B123 G17D
firmware" and "drm/asahi: t6050: Give the M5 Ultra's 27.2 firmware the power-controller status config of its own
26B123 layout". One boot each through the 27.2 firmware with our daily Aura build, read-only root.
DefaultLimitMEMLOCK, which every process of the desktopsession has), with a Borealis build that advertises
VK_EXT_external_memory_host:dEQP-VK.memory.external_memory_host.*passes 4 and reports 8 not supported (image formats) of 12, 0 failed,with and without this change. Among the installed applications, FFmpeg's Vulkan upload doesn't import host
memory (no pinned pages while it runs), and the desktop session holds no pinned pages on either kernel. No
installed workload was found that imports host memory, so none is affected.
kernel error at err level and above.
CONFIG_MM_SUBPAGE, which the J775D kits have; offat run time without
user4k=on), also extra evidence, not this PR's own: on the extra row's 27.2 base(integration/aurora cacf355 plus the same four), kit
ryan2777row(with this change at 4540607a7b4d, the same patch as this head) against kittrackh-gb, booted withuser4k=on, runningtools/testing/selftests/arm64/user4k/gem-userptr. The selftest's results don't depend onwhether the pins are charged to the mm or to the user, so both arms are expected to match. On both it passes 3 of
3, as root and as an unprivileged user at the default 8 MiB limit. Native pages mapped whole and in order pin
32 KiB and give it back on close, and the two mixed-page layouts get EFAULT with nothing pinned. With
RLIMIT_MEMLOCK at 16 KiB all three are refused with ENOMEM before any page is pinned. The same 2 failed units and
the same err-level lines on both, no WARNING, BUG or Oops.
warning in the files this change touches. Also with
CONFIG_KUNIT=m, and withCONFIG_KUNIT=yand aurora as amodule: both complete, aurora.ko links without the test helpers, and there is no warning in these files.
run-host-tests.pyin the build VM: 451 of 451 pass with this change, as on the base.--strict: no errors.Still to run
user_struct::locked_vmin place of the six copies (__io_account_mem(),incr_user_locked_vm(), secretmem,mm_account_pinned_pages(), XDP umem and this driver's), and a Kconfig symbol in place of the condition in<linux/sched/user.h>.Assisted-by: LLM (Claude:Opus 5.5)