Skip to content

drm/asahi: don't refuse the page tables of the driver's own client mappings - #4246

Merged
DjDeveloperr merged 1 commit into
mainfrom
neo/pt-kernel-map-charge
Dec 4, 2026
Merged

DjDeveloperr merged 1 commit into
mainfrom
neo/pt-kernel-map-charge

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

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 and VmInner::map_node(); on main map_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.py in 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 with git show). drivers/gpu/drm/asahi module 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 new asahi_pgtable_charge case the_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:

  • J700 row at this PR head. A sealed J700 kit runs this commit on the same 12,000 multi-queue cases at the 50 % limit: main 6985e45's driver plus only this commit, as a module on the drm/asahi: g17: cut the references a pending command holds #3681 Image of the four arms below. It is not this head's exact driver, because main's later rust/kernel changes are in the Image.
  • Other publication-time limit refusals stay on M5: pool pages, targets and tiler blocks charged to the client (drm/asahi: g17: allocate compute objects in SUBMIT, not at publication #3704 moves the compute ones to SUBMIT).
  • A refusal returned from SUBMIT would still be a lost device with today's Borealis, which treats every failed SUBMIT as one; only QUEUE_CREATE refusals become a Vulkan error.
Details

Why the fence is not the place to report it. Job::publish() runs after mark_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. But fail_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 keep prepare_map()/alloc_pages().

Evidence

J700 (MacBook Neo, A18 Pro, G17P B1), four trial boots on the same 7.3.0-pr3681-c1fae1db Image, each with a different aurora.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).

driver multi-queue CTS refusals lowest MemAvailable lost device
main 6985e45a stopped at 6,008 / 12,000 703 1.48 GB yes, ENOMEM at g17/runtime/backend.rs:75
main with #2530's page-table charges reverted 12,000 / 12,000, 0 GPU fault lines 1,053 1.40 GB no
main 37a63062 + #3681 (older driver) stopped at 913 22 1.97 GB yes, same line
6985e45a + #3985 stopped at 920 32 1.96 GB yes, same line

The 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.

…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>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners December 3, 2026 23:14
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 3, 2026
@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Merge readiness at 8bc2fcf1: ready to merge

Check Detail
CI at head ok 10 checks passed
Review ok approved by satchlj
Requested changes ok none
Hardware row at head ok comment at 8bc2fcf1
Conflicts ok none
PR text ok Risk: two-way · 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.

Areas: area:gpu
Merge: gh pr merge 4246 --merge (Owners and Core through the bypass: add --admin).

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J700 (MacBook Neo, A18 Pro, G17P B1) row at the exact head 8bc2fcf14647: PASS. Main loses the device (#4195 reproduced); this PR keeps it.

Full kernels built from main de55bfa1 and from this head (release 7.3.0-r4246-de55bfa1, same Image for both, the arms differ only in aurora.ko; the head's source tree equals this PR's tree 447f2c05). One trial boot per arm. The GPU memory limit is set to 50 % (3.91 GB) for the multi-queue CTS step (synchronization/synchronization2 multi_queue, 12,000 cases per pass), memory sampled every 0.5 s.

arm boot multi-queue CTS refusals lowest MemAvailable lost device
main de55bfa1 ea00c4f6 stopped at 1,565 / 12,000 163 1.48 GB yes: GPU work of a client failed (ENOMEM, reported at g17/runtime/backend.rs:75)
this PR edfe1ac7 ran on until its time budget (1 of 2 passes) 1,009 1.45 GB no, 0 GPU fault/lost lines

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.

@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label Dec 4, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Hardware row at exact head 8bc2fcf14647f326265f55e9f6a933588127ba4d on J773g (Apple Mac mini M4, G16G B0, 24 GB RAM, 27.2): PASS NOT EXERCISED (clean no-regression second-gen row; B kept the device identically to A, with 0 faults and 0 refusals across 12,000 multi-queue CTS cases at 25% GPU memory limit).

Kit: work/j773g-4246-exact-20261203 (KIT.sha256 409a17b3…, --check PASS).
Kernel: 7.3.0-j773g-r4246-de55bfa1 (stock main3685 config, LOCALVERSION only; A and B differ only in aurora.ko).
Receipt: work/j773g-4246-exact-20261203/results/run1/.

linux#4246 J773g row, run run1: 2026-12-04T01:58:03Z .. 2026-12-04T02:05:05Z
arm A: KEPT       7.3.0-j773g-r4246-de55bfa1 aurora f9abf74e08e0 (boot 873483f7-e022-4fb0-9aef-ce30a852406e); limit 25 % (device 5909 MiB, client 5909 MiB); 12000/12000 cases in 82.3 s, stop None, lowest MemAvailable 19819 MiB, 0 fault lines, refusals 0; {'NotSupported': 9156, 'Pass': 2844}
arm B: KEPT       7.3.0-j773g-r4246-de55bfa1 aurora e76629d85d28 (boot 63a14108-c5ef-4a2f-99f9-480a5a3a98d0); limit 25 % (device 5909 MiB, client 5909 MiB); 12000/12000 cases in 81.9 s, stop None, lowest MemAvailable 19803 MiB, 0 fault lines, refusals 0; {'NotSupported': 9156, 'Pass': 2844}
lists: synchronization2 23760 cases (= the J700's: True), synchronization 12807 (= the J700's: True); from mustpass /root/m4cts/cts-vk/mustpass/main/vk-default
VERDICT PASS NOT EXERCISED: B kept the device and A did not lose it (kept)

Restored to stock 7.3.0-j773g-main3685+ (boot_id=3093facc-b3ac-4535-98ee-6abfb676b729), staging cleaned on minihw and m5-linux.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: bool with enum Missing { Skip, Admit, Commit } cleanly separates driver-internal client-VM mappings (VmInner::map_node() -> prepare_driver_map() -> Missing::Commit) from user VM_BIND paths (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-SUBMIT fence failures / spurious DeviceLost when 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.

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 4, 2026
@DjDeveloperr
DjDeveloperr merged commit c042c5f into main Dec 4, 2026
14 checks passed
@DjDeveloperr
DjDeveloperr deleted the neo/pt-kernel-map-charge branch December 4, 2026 02:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpu Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

G17P: main loses the device (ENOMEM) and fails queue churn with several queues; 7.3.0-41 passes

2 participants