Repository navigation
drm/asahi: don't refuse the page tables of the driver's own client mappings - #4246
Conversation
…ppings A client VM's page tables are charged to its client since commit 31e8f6f ("drm/asahi: charge a VM's page tables to its client's memory limit"), and a table past the client's or the device's limit fails the mapping that needed it with ENOMEM. That is right for VM_BIND, which returns the error. But the driver maps its own objects into client VMs too (Vm::map_at() and Vm::map_in_range()), and G17 does so to publish a command: the views of a queue's kick and descriptor rings, of its pool pages and, on the A18 Pro, of the shared compute aperture, which is 26 mappings at a VM's first compute command. SUBMIT has accepted the command by then, so the refusal can only fail its fence. The VM and its later commands stay usable, but the failure is also what VM_STATUS and its mirror report, and Borealis takes that for a lost device. So a client whose large buffers take the memory up to the limit, which Vulkan reports as VK_ERROR_OUT_OF_DEVICE_MEMORY and applications handle, loses its device over a 16 KiB page table. Returning the refusal from SUBMIT instead would not help: Borealis also takes a failed SUBMIT for a lost device, because it has already moved the submission's semaphore payloads. Keep charging these tables, so they are visible and count against the client's next buffer and bind, but do not refuse them. They stay bounded without the limits: userspace does not place these mappings, and each is of an object that the driver made for a VM or a queue, or whose backing is itself charged. VM_BIND keeps refusing, and a failed page allocation still fails both. Every mapping of a driver's GEM object goes through VmInner::map_node(), so this covers all GPU families. The tables of kernel VMs are not charged. The host test compiles the production walk, ledger and map_node(). At either limit, main's map_node() fails with ENOMEM. The models of three other fixtures follow the new names. Fixes: 31e8f6f ("drm/asahi: charge a VM's page tables to its client's memory limit") Signed-off-by: DjDeveloperr <hey@djdev.me>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
J700 (MacBook Neo, A18 Pro, G17P B1) row at the exact head Full kernels built from main
Both arms: identity and 8-client queue churn PASS, watchdog PASS; the J700 was verified back on stock after each boot. So at the same limit this PR refuses six times as many allocations and none of them loses the device, which is the fix. A J773g row at this head (second generation) is queued on the M4 mini. |
|
Hardware row at exact head Kit: Restored to stock |
There was a problem hiding this comment.
Verdict: MERGE at 8bc2fcf
Checked: The exception is selected by the driver’s internal KernelMapping allocation path. VM_BIND and prepared user binds retain admission and the existing VA and GEM restrictions. Driver mappings still use the same backing, PTE permission and reservation checks. The second empty-leaf check stays under PPL before any store. Mapping and unmapping permissions are unchanged.
Checked: The exact accounting suite passed and caught all five negative controls. Both client and device accounting still charge driver-created tables, binds remain subject to the limits, real allocation failures propagate, and the charges are reclaimed. The exact M4 retention and VM-word suites also passed, including live-range rejection, rollback ordering and 441 golden cases.
satchlj
left a comment
There was a problem hiding this comment.
Approved at 8bc2fcf14647.
Reviewed drivers/gpu/drm/asahi/mmu.rs, drivers/gpu/drm/asahi/pgtable.rs, the KUnit case, and the host-test updates:
- Replacing
alloc: boolwithenum Missing { Skip, Admit, Commit }cleanly separates driver-internal client-VM mappings (VmInner::map_node()->prepare_driver_map()->Missing::Commit) from userVM_BINDpaths (prepare_map()/alloc_pages()/map_*()->Missing::Admit). - Driver-made page tables are still charged via
charge.add(UAT_PGSZ as u64)(counting against subsequent user binds and released on drop) while avoiding post-SUBMITfence failures / spuriousDeviceLostwhen a client sits at its memory limit; real allocation failures still return-ENOMEM. - Hosted CI is green (
apple-build,host-tests,KUnit asahi,readiness,pr-text), with exact-head J700 PASS and J773g no-regression rows posted.
What: The page tables of a client VM are charged to its client since #2530, and a table past the client's or the device's memory limit fails the mapping that needed it. VM_BIND can return that error. The driver's own mappings in a client VM can't: G17 makes some of them to publish a command that SUBMIT has already accepted, so the refusal fails the command's fence, and userspace takes that for a lost device. These tables are still charged and still count against the client's next buffer and bind, but they are no longer refused. VM_BIND keeps refusing, and a real allocation failure still fails both.
Fixes #4195.
Tested: no Mac at this head yet. Host test
asahi-driver-map-charge-tests: the production page-table walk, ledger andVmInner::map_node(); on mainmap_node()fails with ENOMEM at either limit, here it succeeds, binds are still refused, and every charge is given back; 5 of 5 mutations are caught.run-host-tests.pyin the host-test container, without a git history: main de55bfa 1127 runs, this head 1133 (the 6 more are this test), the same 55 runs fail on both (they read older revisions withgit show).drivers/gpu/drm/asahimodule build arm64 LLVM=1 W=1: the same 38 warnings as main, in the same places, none new. CI's KUnit asahi job (arm64 QEMU) runs the newasahi_pgtable_chargecasethe_tables_of_a_driver_map_are_charged_but_never_refused: passed.Risk: two-way door · every Mac running the driver (the code is shared by all GPU families); the change is an accounting rule, with no uAPI change. A client's driver-made page tables can pass its limit, by an amount bounded by the driver objects of its VMs and queues.
Not yet:
Details
Why the fence is not the place to report it.
Job::publish()runs aftermark_accepted(), so SUBMIT has returned or will return success.finish_publication()already spares the VM for ENOMEM (fail_vm()is for EIO, ETIMEDOUT and ENODEV;record_if_device_loss()ignores ENOMEM), and the VM's later commands run. Butfail_unpublished()reports the failure in VM_STATUS and its mirror, and Borealis turns any nonzero value into VK_ERROR_DEVICE_LOST (hk_check_status()). It must: a dropped command means wrong contents, and syncobj waits don't return fence errors.Why not from SUBMIT. Borealis ends the device on any failed SUBMIT (
queue_submit_single()): by then it has moved the semaphore payloads, so it can't return a retryable error. #3704 moves the compute allocations to SUBMIT, which is right for a real ENOMEM, but its compute publication still maps the pool pages, the descriptor ring and the shared aperture into the client VM (map_client(),cache_compute_vm()), and that is where page tables are allocated.Why the tables stay bounded. Userspace does not place driver mappings. Each is of a driver object of a VM or queue, or of an object whose own backing is charged. A table maps 32 MiB; a driver object maps at least one 16 KiB page.
Scope.
VmInner::map_node()makes every mapping of a GEM object by the driver (map_at(),map_in_range()and the guard-tail variant).bind_object(),sm_step_map()and the prepared-bind path keepprepare_map()/alloc_pages().Evidence
J700 (MacBook Neo, A18 Pro, G17P B1), four trial boots on the same
7.3.0-pr3681-c1fae1dbImage, each with a differentaurora.ko; the GPU memory limit at 50 % (3.91 GB) for the multi-queue CTS step (synchronization/2 multi_queue, first 12,000 cases), memory sampled every 0.5 s (#4195 comment).6985e45aENOMEMatg17/runtime/backend.rs:7537a63062+ #3681 (older driver)6985e45a+ #3985The Mac never ran low on RAM: at least 1.4 GB stayed available in every arm. On main, the client's committed memory (2.57 GB) plus the driver's kernel-resident memory (1.34 GB) reached the 3.91 GB limit when the device was lost. With the page-table charges reverted the same cases are refused more than 1,000 times and the device survives, so the charge path is what loses it; the older driver loses it too.