Skip to content

drm/asahi: g16: bind a VM to its TTBAT slot with its first queue - #4077

Merged
DjDeveloperr merged 2 commits into
mainfrom
fix/g16-vm-slot-at-first-queue
Dec 3, 2026
Merged

DjDeveloperr merged 2 commits into
mainfrom
fix/g16-vm-slot-at-first-queue

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

What: bind a G16 VM to its TTBAT slot when its first queue is created, not when the VM is.

There are 63 slots and a VM used to keep one from VM_CREATE until its last firmware lease went. A Vulkan client creates two VMs: the physical device's (hk_physical_device.c, never gets a queue) and the logical device's. Only a queue's jobs run in a VM's context, so the first one needs no slot.

Slots are also short because the newest retired compute owner of every pipe, the newest render owner and the owner epoch of every PB slot keep their VM bound after its client exits: up to 8 + 1 + 20 = 29 on main. On J773g in the #3340 row, vm_bindings showed 30 bound VMs for 9 open handles on main and 38 for 9 with #3340's 16 pipes, where VM_CREATE failed with ENOSPC. Those leases stay. Releasing a closed VM's PB epoch early faulted before (047b934ce47a), and nothing here shortens a lease.

  • Registry keeps VMs without a queue unbound (IdleVm); vm::lookup() binds one for its first queue, once, under a mutex. A failed binding leaves the VM unbound for another try, and a VM closed meanwhile keeps nothing.
  • The slot is still reserved before it is bound, so the slot allocator never waits and a leased slot is never handed out.
  • The limit of eight VMs per file counts every VM. The device limit and the per-process share count bound VMs.

Tested:

  • New host test asahi-m4/test-vm-slots.py runs the production VM and queue creation with hw.rs's pipe and PB slot counts: every lease held by an exited client, 9 desktop VMs, then 16 Vulkan processes. It fails on main (13th process, errno 28, 63 slots in use) and on drm/asahi: g16: widen compute concurrency to 64/16 and cache shared UMA and fw_stamp #3340 at eb8c98e615c0 (9th process), and passes here. It also checks that a leased slot isn't reused until its last owner goes, one binding for all queues of a VM, a failed binding, a close during the binding, the file quota and fail-stop.
  • tools/asahi/run-host-tests.py --only asahi-m4 passes (all scripts, test-resources.py 84/84), --only g16 2/2 with 3/3 mutants killed.
  • arm64 W=1 build of drivers/gpu/drm/asahi/: no errors; the only warning in vm.rs is main's fetch_update deprecation (rustc 1.100.1). checkpatch --strict clean except the MAINTAINERS reminder for the new file, which the directory's entry covers.
  • No hardware.

Risk: two-way · Macs on the g16 backend (T8132; T6030 and T8122). A plain revert undoes it.

  • Running out of slots is now ENOSPC from QUEUE_CREATE, not VM_CREATE. Mesa reports both as a failed vkCreateDevice.
  • VMs without a queue are no longer bounded by 63 device-wide: by eight per file and the GPU memory limits, as on the other backends by 64 per file.
  • The TTBAT names a VM's root later than before; everything mapped by then is already written back, as at VM_CREATE before.

Not yet: J773g and J516s rows. KUnit. T8122 has no row.

A user VM takes one of the 63 TTBAT slots when it is created and keeps it
until its last firmware lease goes. A Vulkan client creates two VMs: its
physical device's, which never gets a queue, and its logical device's. So
the slots run out at half as many clients as the contexts could serve.

Slots are short to begin with. The newest retired compute owner of every
pipe, the newest render owner, and the owner epoch of every PB slot keep
their VM bound after its client exits, until a later publication displaces
them. With eight compute pipes and twenty PB slots that is up to 29 slots
of clients that are gone. On a J773g desktop with gpubench
compute.light procs running, 21 of the 63 slots were held like that and 9
by the desktop, which left room for 16 Vulkan processes and nothing more.
With the sixteen pipes of linux#3340, 29 were, and VM_CREATE failed with
ENOSPC.

Those leases have to stay: releasing a closed VM's PB epoch early let the
parameter manager write through a reused context (047b934). But only
the jobs of a queue run in a VM's context, so a VM without one needs no
slot. Keep it unbound in the registry and bind it when its first queue is
created. Its root is named by the TTBAT only then, with every mapping made
before it already visible to the walker. Slots stay exclusive and are
reserved before they are bound, as before, so a leased slot is still
never handed out again and the slot allocator never waits. A failed
binding leaves the VM unbound for another try.

The per-file limit of eight VMs still counts every VM, bound or not. The
device limit and the per-process share count bound VMs, so running out of
slots is now ENOSPC from QUEUE_CREATE rather than from VM_CREATE. The
fail-stop path also latches its error on unbound VMs.

test-vm-slots.py runs the production VM and queue creation against a
model of the slots, with the pipe and PB slot counts of hw.rs: every
lease held by an exited client, the desktop, then sixteen Vulkan
processes. Without this change the thirteenth process fails there, and
the ninth with sixteen pipes.

Signed-off-by: DjDeveloperr <hey@djdev.me>
Registry::reserve() takes a TTBAT slot for a VM's first queue and no
longer counts the VM against its file. Reserve without a file; the file
limit is covered by the asahi-m4 selftest test-vm-registry.py.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners December 3, 2026 07:14
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:m3 Macs affected, from Merge risk (bot) blast:m4 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 e1a82653: ready to merge

Check Detail
CI at head ok 10 checks passed
Review ok approved by RyanTheTide
Requested changes ok none
Hardware row at head ok comment at e1a82653
Conflicts ok none
PR text ok Risk: two-way · Macs on the g16 backend (T8132; T6030 and T8122). A plain revert undoes it. - Running out of slots is now ENOSPC from QUEUE_CREATE, not VM_CREATE. Mesa reports both as a failed vkCreateDevice. - VMs without a queue are no longer bounded by 63 device-wide: by eight per file and the GPU memory limits, as on the other backends by 64 per file. - The TTBAT names a VM's root later than before; everything mapped by then is already written back, as at VM_CREATE before.

Areas: area:gpu
Merge: gh pr merge 4077 --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.

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The idle and bound paths preserve the file quota and existing firmware lease lifetime. Binding is serialized, a failed bind leaves the idle entry available for retry, and close during publication is handled. The host case exercises the slot pressure reported on J773g. The hardware row is still pending.

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J773g row at e1a826530d63, merged onto main 536a613c0abe: PASS.

What

Tested

  • gpubench-vk ran the 06:09Z set twice, with the same binary and system ICD (mesa-aurora 26.3.0 d4ad4a4dce6) as the 06:09Z row.
    • All 31 results in each pass were ok and checked.
    • compute.light procs was ok at d=2, 4, 8 and 16 in both passes (pass 2, d=16: 33.1 µs/submit).
    • The churn (5 × procs d=8) and three more procs d=16 runs were all ok.
    • No ENOSPC, VM_CREATE or QUEUE_CREATE failure. vm_bindings ended at live 27 handles 6.
  • Stats after the bench: health: failed 0, recoveries 0, compute owners retired 24 reusable 16 quarantined 0.
  • Kernel log: no GPU, MMU, RTKit, WARNING, BUG or Oops line that the stock boot lacks.
  • Judge:
    • The sealed kit's judge printed FAIL. Its only reasons were systemd's two watchdog-arming lines ("Using hardware watchdog …", "Watchdog running with a hardware timeout of 1min"). The kit's own arming step writes them, and its fault pattern matched watchdog. That is a kit bug.
    • The fixed kit (work/j773g-3340-armB-20261203, seal 47f5c716) leaves out exactly those two lines and keeps every other rule. It reads this run as arm A and gives linux#4077 (arm A): PASS.

Risk

Not yet

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-hw-row No hardware row at the PR head (bot) labels Dec 3, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Rechecked on main ebfc4f60bdd1. The standalone merge tree 1c2eb779f6d4 still fails test-resources.py with E0560 (LiveToken.file_id). The #3340 merge tree c71356f0e4c5 contains this head and passes the same test 98/98. The J516s row is already with #3340; that is the landing path.

@DjDeveloperr
DjDeveloperr merged commit b3dadb2 into main Dec 3, 2026
13 checks passed
@DjDeveloperr
DjDeveloperr deleted the fix/g16-vm-slot-at-first-queue branch December 3, 2026 20:03
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:m3 Macs affected, from Merge risk (bot) blast:m4 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.

2 participants