Skip to content

drm/asahi: g17: keep validation proof ranges sorted and batch VM job retention - #3325

Merged
RyanTheTide merged 6 commits into
aurora-silicon:mainfrom
oreater:pr/g17-sorted-validation-batched-vm-pin
Dec 1, 2026
Merged

RyanTheTide merged 6 commits into
aurora-silicon:mainfrom
oreater:pr/g17-sorted-validation-batched-vm-pin

Conversation

@oreater

@oreater oreater commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

What: Keep G17 validation Requests sorted by (access, start) for O(log N) binary-search coverage checks and in-place merging, and batch additional VM residency/lifetime job pins under one lock acquisition per mutex in Queue::prepare_submission().

Tested: J716c (MacBook Pro 16" M5 Max) host build + tests at 6e552962caae (make LLVM=1 ARCH=arm64 drivers/gpu/drm/asahi/ clean with 0 warnings in touched files; all 10 asahi_g17_validation_pages unit tests plus 400-sequence pseudorandom reference-model check passing; run-host-tests.py --only m5-client-handoff 2/2, --only asahi-m4 1/1). Equivalent validation and batched-pin paths previously boot- and Vulkan-stress-tested on J716c (7.3.0-40).

Risk: two-way · G17 Macs (M4/M5) command submission validation and multi-command ioctl VM pinning.

Not yet: Bare-metal boot and KUnit run at this exact rebased main commit (6e552962caae).

Commit summary and test evidence
  1. ea197789bf12 — drm/asahi: g17: keep validation proof ranges sorted by access and address:
    • Maintains Requests sorted by (access, start) with disjoint, non-adjacent intervals per permission bucket (1=Read, 2=Write, 3=ReadWrite).
    • Replaces O(N) linear scan in covers() with partition_point lookup against bucket 3 and the requested bucket.
    • Replaces the restart-from-0 merge loop in insert() with bounded neighbor coalescing and ReadWrite subsumption pruning of weaker buckets.
    • Updates only_uncovered_ranges_are_walked_again for sorted order and adds sorted_requests_preserve_overlap_merge_and_subsumption.
  2. 6e552962caae — drm/asahi: g17: batch VM job retention across multi-command submissions:
    • Adds Gate::enter_many(), Vm::enter_residency_many(), and Vm::retain_jobs() so multi-command submit ioctls acquire all additional VM residency leases and active job guards under one lock acquisition per mutex instead of once per command.

…ress

Requests::covers() and Requests::insert() previously scanned the range
array linearly (and insert() restarted from index 0 after every merge),
turning coverage checks against the 128-entry persistent Proof cache into
O(M * N) work on every submission.

Keep Requests sorted by (access, start) with disjoint, non-adjacent
intervals within each permission bucket (Read=1, Write=2, ReadWrite=3):
- covers() uses binary search (partition_point) against bucket 3 and, for
  Read/Write queries, the requested bucket;
- insert() merges overlapping or adjacent equal-permission neighbors in
  place via partition_point and prunes strictly weaker Read/Write intervals
  fully covered by a merged ReadWrite range.

Update the expected order in only_uncovered_ranges_are_walked_again and add
a KUnit test covering overlapping permission buckets, gap merging, and
ReadWrite subsumption.

Signed-off-by: oreater <[email protected]>
Queue::prepare_submission() previously called Vm::retain_job() in a loop
for each additional command in a multi-command submit ioctl, taking both
the residency gate mutex and the VM lifetime mutex once per command.

Add Gate::enter_many(), Vm::enter_residency_many(), and Vm::retain_jobs()
to acquire all additional residency leases and lifetime job references
under a single lock acquisition for each mutex, and use Vm::retain_jobs()
in Queue::prepare_submission().

Signed-off-by: oreater <[email protected]>
@oreater
oreater marked this pull request as ready for review November 26, 2026 22:34
@oreater
oreater requested review from a team and DjDeveloperr as code owners November 26, 2026 22:34
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Merge readiness at 195bfcc9: not ready yet

Check Detail
CI at head ok 22 checks passed
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok comment at 195bfcc9
Conflicts ok none
PR text ok Risk: two-way · G17 Macs (M4/M5) command submission validation and multi-command ioctl VM pinning.

Areas: area:gpu

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

@DjDeveloperr DjDeveloperr 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.

Verdict at 6e552962caae: the code is correct, with no code blockers. It isn't ready to merge yet: CI and a G17 hardware row at this head are still owed (see below).

Checked

  • Requests in validation.rs (ea19778):
    • Every write still goes through insert(), and pages() already rejects overflowing ranges, so the unchecked start + len additions can't overflow.
    • insert() keeps each access bucket sorted by (access, start) and keeps intervals disjoint and non-adjacent:
      • only the predecessor can overlap from the left;
      • the forward scan merges every touching interval;
      • a ReadWrite insert removes only Read and Write intervals that lie fully inside the merged range. These sit before bucket 3, so lo/hi shift down by the number removed.
    • covers() checks bucket 3 and then the requested bucket. That is the same single-interval containment rule as before.
  • Differential check against the old code: I ported the old and new insert()/covers() side by side and fed both 40,000 random sequences (capacities 3/4/6/48), mixing unaligned, zero-size, overlapping, adjacent and duplicate ranges and invalid access values.
    • After every insert, the two produced the same set of ranges and the same overflow flag.
    • They gave the same covers() answers on random queries.
    • The new version kept its sorted, disjoint, non-adjacent invariant every time.
    • The only visible change is ordering, which the updated only_uncovered_ranges_are_walked_again test reflects. Nothing reads Requests in insertion order.
  • VM job retention (6e55296):
    • Gate::enter_many() is Gate::enter() with count: same busy, evicted and restore handling, with the interruptible waits kept.
    • retain_jobs() reserves out first and takes all leases, then the lifetime lock, the same order as retain_job(). It raises active by count with an overflow check, then builds one VmJobGuard per lease.
    • On a closed, blocked or overflow error, the leases drop one at a time through Lease::drop. Each guard later drops active by one through the unchanged VmJobGuard::drop.
    • prepare_submission() takes the same pending.len() - 1 extra guards as before.
    • The new helpers are additive and only the g17 queue calls them, so other generations' mmu paths are unchanged.
  • Commits and checkpatch: both commits are signed off with no attribution. checkpatch --strict reports 0 errors and 0 checks, plus one nit: a 101-column doc comment on retain_jobs().

Before merge

  1. CI hasn't run yet. At this head, Apple build and KUnit, Host tests and pr-text are all action_required, waiting for a maintainer to approve the workflow runs. The readiness comment's "no CI for this change" comes from that.
  2. No hardware row at this head yet. The PR body's Tested section has a host build and tests, and the boots it mentions were on 7.3.0-40, not this head; Not yet says the same. One boot on a G17 Mac at 6e552962caae is needed: a J700 (G17P) or an M5 such as your J716c. It should run Vulkan work that sends multi-command submissions (so retain_jobs() runs), with the KUnit asahi_g17_validation_pages results and a clean kernel log.

Not blocking

  • Risk line: it says "G17 Macs (M4/M5)", but G17 is the M5 family and the Neo. The M4 is G16, which this code doesn't run on.
  • Host test: --only asahi-m4 doesn't cover these paths.

@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 6e552962caae482f666f9ec035a094a20e533d19 once hardware evidence is complete.

Blockers: No code blocker found. Keep this unarmed until the exact-head J716c submission/VM pressure row and affected peer smoke are posted.

Checked: Reviewed all four files, including permission bucket separation, range arithmetic, capacity, the residency restore/wait path, and RAII rollback on close or error before job guards are built. I extracted the exact-head range implementation into a standalone Rust harness and checked 51,200 insertions across 800 sequences against a per-page permission model and a linear lookup. No ordering, permission, or lookup disagreement. This exercises the range logic, with runtime GPU and VM pressure verification still owed. No DT, per-board gates, private material, or attribution changes.

@AxxzyWasTaken

Copy link
Copy Markdown
Contributor

Hardware test row at exact head 6e552962caae (7.3.0-pr3325+, standalone PR branch build with stock J616C config):

Board Chip / GPU Commit Result Notes
J616C (MacBook Pro 16" M4 Max) T6041 / G16C B1 (32-core, fw 25G83) 6e552962caae PASS Clean boot (0 failed units); 27/27 gpubench-vk cases PASS with ASAHI_MESA_DEBUG=verify (submit.empty, render.heavy, render.deferred, render.mdi, render.bindless_ubo, concurrent.cr, overlap.passes, sync.signal, compute.conv2d, compute.cull_mdi, transfer.ops, query across queue, queues, and procs modes, d=1..4, >2.9M submits); VK-CTS 12/12 dEQP-VK.synchronization.smoke.* and 336/336 dEQP-VK.binding_model.buffer_device_address.set3.depth2.basessbo.* PASS (0 failed); 0 GPU/DART faults or kernel warnings in dmesg.

@RyanTheTide
RyanTheTide disabled auto-merge November 29, 2026 00:55
@github-actions github-actions Bot added the ci-failing A check failed at the PR head (bot) label Nov 29, 2026

@erikwb erikwb 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.

Verdict: FINISH, then merge at 6e552962caae

Blockers: The J716c row at this head is missing. Complete the remaining CI checks.

Checked: The posted J616C exact-head row reports 27/27 benchmark cases and both CTS groups passing. T6041 can use the shared G17 backend through driver.rs:183, so the G16C hardware name alone does not rule out that coverage. Apple build, host tests and KUnit asahi passed. Other KUnit jobs are queued, and one PR-text run was cancelled while another passed. The branch has no conflicts. No new hardware gates, runtime parameters or safety limits.

Evidence

Equal-access intervals stay disjoint, and coverage still requires a containing interval with sufficient permissions. ReadWrite pruning keeps weaker ranges that extend outside the new interval. The sorted requests still use the existing epoch check and page-walk fallback. Batch retention reserves storage before counting jobs, keeps the original residency-before-lifetime lock order, and returns one guard per command. Close or overflow before raising the lifetime count drops the leases. Please record the J616C bound backend and whether the workload used multi-command ioctls so the peer coverage is clear.

@erikwb

erikwb commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

J716c (16-inch M5 Max) at 6e552962caae: boots; Vulkan memory mapping 4466/4466 and the compute sample (490 pass, 760 skip) pass with no GPU driver errors. Separately, this head no longer builds once merged with current main (details below).

Evidence

Built into batched kernel 7.3.0-ewb350+ (main 9d7918bc6316 plus open #3389 #3411 #3415 #3390 #3392 #3330 #3443 #3153 #3324 #3325 #3406 #3429), which contains this head unchanged. Borealis aurora-wip 437b0b52151, deqp-runner with 4 jobs, one-shot trial boot on the default command line plus watchdog.open_timeout=120 (a recovery watchdog for test boots only). The synchronization lists ran too: the only fails and flaky cases are synchronization2.op.multi_queue.timeline_semaphore ones, which show up at the same rate on a control kernel and pass 4266/4266 when that family runs alone.

Merged onto main 219311530ef0, the build stops in drivers/gpu/drm/asahi/g17/queue/mod.rs:524:

error[E0308]: mismatched types
524 |  .retain_jobs(pending.len() - 1, &mut guards)?;
    |  expected `&mut Vec<VmJobGuard, Kmalloc>`, found `&mut &mut Vec<VmJobGuard, KVmalloc>`

On main, Scratch::guards is a KVVec<VmJobGuard> (g17/queue/mod.rs:141) and is already borrowed mutably at the call, while Vm::retain_jobs() (mmu/lifetime.rs:470) takes &mut KVec<VmJobGuard>. Merging main in and matching the two (allocator type and the extra &mut) fixes it.

@RyanTheTide

Copy link
Copy Markdown
Contributor

I merged current main into this branch (f19b0a5c, normal push, no rebase, your commits unchanged). The last CI failures came from main itself on 11-29: the apple-scaler-recovery and g17-compute-owed-stamp fixtures, plus the apple-dcp harness break fixed in #3672. Re-running a job would reuse the old merge commit, so a fresh merge was the only way to clear them. Both merges were conflict-free. Host tests pass on the merged tree. The PR's own code is unchanged from 6e552962, so the existing hardware rows still cover it. Next: CI at this head and the review app's verdict.

@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) ci-failing A check failed at the PR head (bot) and removed ci-failing A check failed at the PR head (bot) labels Nov 30, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

@oreater the review app has no code blockers at f19b0a5c (a merge of main, your code unchanged). The one thing left is the exact-head J716c submission/VM-pressure row plus a short smoke on one other G17 Mac. We don't have a J716c. Can you post that row at f19b0a5c? It merges the same day.

@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label Nov 30, 2026
main made the per-job guard list a KVVec, and this branch's new
Vm::retain_jobs() still took a KVec, so the forward merge no longer
builds (E0308 at g17/queue/mod.rs:542). Take &mut KVVec<VmJobGuard> and
pass the caller's guards reference through.

Signed-off-by: Ryan Murray <[email protected]>
@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) and removed ci-failing A check failed at the PR head (bot) labels Nov 30, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

@oreater my forward merge (f19b0a5c) had a build break that git didn't flag (apple-build, E0308 at g17/queue/mod.rs:542). main made the per-job VM guard list a KVVec, and your new Vm::retain_jobs() took a KVec. 8272182c changes only the parameter type and passes the caller's guards reference straight through. 195bfcc9 merges current main on top. drivers/gpu/drm/asahi/ builds (arm64, LLVM) and the g17 host tests pass 291/291. The J716c VM-pressure row I asked about earlier is still the only thing left after CI and the review app.

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

@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: HOLD at 195bfcc9 for hosted CI and current-head G17 evidence.

Checked: The caller already owns a mutable KVVec and reserves capacity before adding the parse guard. The follow-up passes that reference directly to the matching parameter type. The job-count, reserve and rollback paths are unchanged by the type fix. The reported arm64 LLVM build and 291 host passes cover the former build break.

Retain the J716c submission and VM-pressure row and the affected G17 peer smoke on the updated head, or maintainer acceptance of equivalent evidence. The earlier J716c row ran on 6e552962.

@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 195bfcc93a49

Converts this App's earlier review at the same head to an approval under the 12-01 merge bar (better than before and doesn't break; block only on a shown failure). No code blocker was found in it. The merge gate (a row on one Mac at this head + fast CI) is tracked by pr-readiness, not held here.

Checked: The caller already owns a mutable KVVec and reserves capacity before adding the parse guard. The follow-up passes that reference directly to the matching parameter type. The job-count, reserve and rollback paths are unchanged by the type fix. The reported arm64 LLVM build and 291 host passes cover the former build break.
Retain the J716c submission and VM-pressure row and the affected G17 peer smoke on the updated head, or maintainer acceptance of equivalent evidence. The earlier J716c row ran on 6e552962.

Follow-ups (not blocking): hosted CI; J716c submission/VM-pressure row on updated head

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging at 195bfcc93a49 (B2 merge train, 12-01 merge bar). Approval at this head: aurora-silicon-review[bot]. Row: J716c comment at 195bfcc. CI: linux train L1 = main 595e754 + #3503 #3499 #3240 #3208 #3696 #731 #2634 #2110 #3325 #3441 #3650 (candidate ef98b31c): Apple driver compile (defconfig + asahi.config, LLVM=1, Rust) pass, Apple DTBs W=1 pass, planned KUnit clpc/dcp-fabric/dcp-topology/dcp-display/pmgr-pwrstate/mt7932/asahi all pass; host-tests green (or path-skipped) at this head. The rest of the hosted run is queued behind the ~19 h backlog. Revert: git revert -m 1 <merge commit>.

@RyanTheTide
RyanTheTide merged commit 5981b55 into aurora-silicon:main Dec 1, 2026
23 checks passed
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:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants