Skip to content

drm/asahi: m5, g18: clear retained storage between VMs, fail a refused job alone - #2949

Merged
DjDeveloperr merged 3 commits into
mainfrom
asahi/handover-clear
Nov 26, 2026
Merged

DjDeveloperr merged 3 commits into
mainfrom
asahi/handover-clear

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The M5 and G18 backends hand one render job (and one compute job) from one client VM to the next by mapping the same retained objects into the new VM. Two things were wrong with that hand-over:

  • The data storage behind those objects (USC and parameter-buffer blocks, scene scratch, discard page, compute operand/preemption/robustness storage) still held what the previous VM's work wrote when the next VM mapped it. Only the G18 render targets were cleared.
  • On G18, every error a submission met after admission (an address unmapped after admission, a closed VM, a render-target allocation that failed) was treated as fatal and ended the firmware session, so no client could submit again until reboot.

Change

  • m5: zero the retained data storage in rebind_vm() before another VM maps it. Allocator and parameter-manager state the firmware records refer to (USC directory, free list, page list, metrics) is kept. The same VM resubmitting clears nothing.
  • g18: after the job has retired and the previous VM's views are dropped, clear the same kinds of storage for the render and compute jobs before another VM maps them, and map the command graph read-only into the client view.
  • g18: ApplicationJob::prepare() commits the frame only after its last fallible step. A preparation error that leaves the job unpublished is a new JobFailure::Refused: the submitter gets its errno, and the session and the other clients keep working. Errors after publication, or on a crashed firmware, stay fatal. The documented defaults of the g18_admit_* parameters are corrected to 1.

No new parameters, gates or tables. The same-VM path is unchanged.

Testing

  • New host tests m5-client-handoff-tests.py, g18-client-handoff-tests.py and g18-job-error-tests.py drive the production hand-over and outcome paths against models of the mappings. Each runs with the previous code and each clear removed as mutants, and every mutant is caught. At this head: 2/2, 2/2 and 2/2 (run-host-tests.py --only).
  • drivers/gpu/drm/asahi/ builds at this head (fleet81 release config, all backends) with no new warnings.

Still to run

  • Hardware rows on a T8142 (m5 backend) and a T8152 (g18 backend): two clients alternating render and compute, and one client whose submission is refused after admission while another keeps rendering. Neither SoC is in our lab, so these need the owners of those machines.
  • A compute plan whose scratch is larger than the dynamic window is still refused after admission. The refusal now fails only that job, but admission should bound it too. That is left for a follow-up.
Commits
  1. drm/asahi: m5: clear pool storage before handing the job to another VM
  2. drm/asahi: g18: clear client storage when the render or compute job changes VM
  3. drm/asahi: g18: fail a job refused before publication alone

The M5 backend has one render pair and one compute queue for all
clients. When a submission comes from a VM other than the current
owner, rebind_vm() maps the retained USC pool, parameter buffer and
compute storage into the new VM at the same addresses. Their contents
were left as the previous VM's work wrote them.

Zero the data storage before another VM maps it: the USC blocks, the
parameter-buffer blocks, scene scratch and discard page, and the
compute operand, preemption and robustness storage. rebind_vm() only
runs once the pair has fully retired, and submissions are synchronous,
so no work still uses the memory. Construction leaves the same storage
zeroed.

The USC directory and free list, the page list and the metrics are
allocator and parameter-manager state that the retained firmware
records and cursors refer to. They are kept unchanged. A same-VM
resubmission does not clear anything.

Add a host test that runs the production hand-over against mocks and
checks every data object is zero when the next VM maps it, with the
previous code and each clear removed as mutants.

Signed-off-by: Ryan Murray <[email protected]>
…hanges VM

The single application render job and the application compute job are
handed from one client VM to the next by re-aliasing their objects at
the same addresses. Only the render targets were cleared, so PB blocks
(including grown ones), the scene scratch, the discard page and the USC
scratch blocks of the render and compute pools still held what the
previous VM's work left there.

Once the job has retired and the previous VM's views are dropped, clear
that storage before another VM maps it. Allocator structures, the PB
block table, page list and ring cursors, and the pool directory, block
list and descriptor are kept as they are: they hold only the owners'
addresses and their cursors are owned by the PM/USC. A replacement
compute pool that retains the old scratch objects inherits the last VM.
The same VM again clears nothing.

The job context only reads the command graph (the RCE register lists),
so map the client view read-only, as g17 maps M5 command storage.

Add a host test that runs the production paths against a model of the
mappings, with mutants including the previous code.

Signed-off-by: Ryan Murray <[email protected]>
Every error a submission met after admission ended the firmware session:
an address the client unmapped after admission, its VM closed, or a
render target allocation it sized made submit_application() return
Failure::Fatal, and no client could submit again until reboot.

ApplicationJob::prepare() now commits the frame (guard, generation,
retired) only after its last fallible step, so an error leaves the job
retired and the next prepare() rebuilds what this one changed; the first
frame's kernel alias is made once. Nothing of a render reaches the
firmware before prepare() returns. A prepare error that leaves the job
unpublished is a new JobFailure::Refused: the submitter gets its errno,
the session and the path keep serving and the client's VM is not
poisoned. The compute path does the same when the failed preparation
left its owner retired with no process, command or context published.
Anything else, and any error on a crashed firmware, stays fatal.

Also correct the documented defaults of the g18_admit_* parameters,
which are 1.

Add a host test that drives the production prepare and outcome paths
against the hand-over model, with the previous code as a mutant.

Signed-off-by: Ryan Murray <[email protected]>

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

Formal §1–§6 pre-PR checklist review at 0a4f6d6576a39c4879259de5efc295d064793555.

Checklist Summary

  • §1 No model gating: Pass — zero chip, SoC, board, or firmware-version gates; applies cleanly across the M5 and G18 VM hand-over paths.
  • §2 Production-ready: Pass — no new parameters, hacks, sleeps, or lab-only paths; fixes stale doc comments on g18_admit_* defaults (which are already 1).
  • §3 Safety & security: Pass — thorough, clean isolation and error-handling fixes:
    • M5 (rebind_vm, M5GraphicsUsc::alias_into, M5ParameterBuffer::alias_into): verifies full retirement (scheduler_status == [2, 0] and stamps match generation * 0x100), drops prior vm_aliases and retracts old context roots before clearing all 25 retained data objects (19 USC blocks, 3 PB blocks, scene_scratch, discard, compute_storage), orders with fence(Ordering::SeqCst), and keeps allocator/PM state (directory, freelist, page_list, metrics). Same-VM resubmission clears nothing; handing back to the original owner VM still clears before reusing its own mappings.
    • G18 hand-over clear: verifies self.retired, retracts program to self.storage, drops user_aliases and pool_aliases, clears all PB blocks (grown blocks included), scene_scratch, and discard on VM change, and maps the client command-graph view (va::GRAPHICS_JOB_LOW) read-only (PROT_GPU_SHARED_RO) so client GPU shaders cannot modify audited command buffers. Render and compute UMA pools track client_vm: Option<u64>, zero scratch blocks on VM change (propagating client_vm across replacement_shared_compute), and build aliases into a local KVec inside alias_into_process() so mid-aliasing failures do not poison self.process_aliases.
    • G18 JobFailure::Refused: ApplicationJob::prepare() defers committing guard, generation, retired, and client_frames until after encode_application(), guards the first-frame kernel-lower graph alias with self.job.aliases.is_empty(), encodes JobOutcome::Refused as 0x1000 - error.to_errno() (0x1001..0x1fff, cleanly disjoint from 0, TICKET_RUNNING = 1, Recovered = 2, Stranded = 3, and negative fatal errnos), returns the submitter's errno without poisoning the client's VM, and keeps crashed firmware / post-publication / armed-compute errors fatal (application_compute_unpublished() also checks self.scheduler.binding(0).is_err() when application_compute is None).
  • §4 Clean-room & attribution: Pass — all 3 commits carry human author/committer (Ryan Murray <[email protected]>) and human Signed-off-by: only, zero AI trailers in commits; PR body includes Assisted-by:; clean-room.
  • §5 Evidence & CI: Code + CI sound; hardware owner rows owed before merge.
    • host-tests CI is green, including all 3 new production-extracting host harnesses (m5-client-handoff-tests.py, g18-client-handoff-tests.py, g18-job-error-tests.py) with mutation suites killing every mutant including pre-fix base c5e25e0925351. Kernel build (drivers/gpu/drm/asahi/, fleet81 config) clean.
    • Because the author's lab lacks T8142 and T8152, hardware rows must come from T8142 and T8152 owners (M1–M4 stand-ins do not exercise the m5/g18 backends) and are genuinely needed before merge — in particular on T8152 to confirm hardware RCE executes cleanly with va::GRAPHICS_JOB_LOW mapped PROT_GPU_SHARED_RO and recovers cleanly from post-admission refusals, and on T8142 to confirm multi-MiB WC clears on VM hand-over retire without faults:
      1. T8142 (M5) owner row: two clients alternating render and compute + regression tuple (0 SELinux denials, 0 failed units, 0 new kernel errors).
      2. T8152 (G18) owner row: two clients alternating render and compute (exercising PROT_GPU_SHARED_RO + hand-over clears) and one client triggering a post-admission refusal while another client keeps rendering without session death + regression tuple.
  • §6 Naming: Pass.

Non-blocking Audit Notes

  • In ApplicationJob::prepare() (drivers/gpu/drm/asahi/g18/runtime/graphics_job_application.rs:88-154), if a new client fails at vm.translate_iova() (line 153) after remap and self.job.program.rebind_retired(vm)? (line 133), program and user_aliases stay bound to the refused VM with pool_aliases empty and retired == true / guard == None. That matches the existing idle-retired state and the next submission either fills pool_aliases (same VM) or remaps cleanly (another VM), so it is safe; validating vm.translate_iova() before remap would just avoid unnecessary PB clear + remap work on a bad-address refusal.
  • In G18UmaPoolMemory::clear_scratch_for(), updating self.client_vm = Some(vm.id()) before alias_into_process() is safe on aliasing failure because scratch has already been zeroed (cannot leak data; at worst triggers one extra harmless clear on a later VM).

Verdict

COMMENT — 0 code/CI/policy blockers; code and mutation-tested host harnesses are solid. Holding APPROVE and merge until the T8142 (M5) and T8152 (G18) owner §5 hardware rows are posted.

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

Formal §1–§6 pre-PR review on live head 0a4f6d6576a39c4879259de5efc295d064793555 (against live integration/aurora 70a00e583b03, not superseded; live CI host-tests green).

Checklist Summary

  • §1 No model gating: Pass — no chip, SoC, board, or firmware-version gates.
  • §2 Production-ready: Pass — no new parameters, hacks, sleeps, or lab-only code paths; corrects stale g18_admit_* doc defaults to 1.
  • §3 Safety & correctness: Pass — M5 (rebind_vm) verifies full retirement and drops prior vm_aliases before zeroing all 25 retained data objects with fence(Ordering::SeqCst) while preserving allocator/PM metadata; G18 drops prior aliases and clears PB blocks (including grown ones), scene_scratch, discard, and render/compute UMA pool scratch on VM change (carrying client_vm across replacement_shared_compute), maps client va::GRAPHICS_JOB_LOW read-only (PROT_GPU_SHARED_RO), and defers ApplicationJob::prepare() frame commit past all fallible steps so unpublished refusals fail only that job (JobFailure::Refused) without poisoning the client VM or ending the session.
  • §4 Clean-room & attribution: Pass — all 3 commits carry human author/committer (Ryan Murray <[email protected]>) and human Signed-off-by: only, zero AI commit trailers.
  • §5 Evidence (BLOCKER): Code and mutation-tested host harnesses (m5-client-handoff-tests.py, g18-client-handoff-tests.py, g18-job-error-tests.py) are solid and live CI host-tests is green, but hardware verification on the affected SoCs is still owed before merge:
    1. T8142 (m5 backend) owner row at this head (default cmdline): two clients alternating render and compute across VM hand-overs without faults, plus regression tuple (0 SELinux denials, 0 failed units, 0 new kernel errors) and kernel build ID.
    2. T8152 (g18 backend) owner row at this head (default cmdline): two clients alternating render and compute (confirming real RCE execution with va::GRAPHICS_JOB_LOW mapped PROT_GPU_SHARED_RO and hand-over clears) plus one client triggering a post-admission refusal while another keeps rendering without session death, plus regression tuple (0 SELinux denials, 0 failed units, 0 new kernel errors) and kernel build ID.
  • §6 Naming & CI: Pass — live host-tests green on 0a4f6d6576a39c4879259de5efc295d064793555.

Verdict

REQUEST_CHANGES — 0 code/CI/attribution blockers; holding approval solely for the T8142 (M5) and T8152 (G18) owner §5 hardware and regression rows.

@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) changes-requested A reviewer requested changes (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merge readiness at 0a4f6d65: ready to merge

Check Detail
CI at head ok 1 check passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok comment at 0a4f6d65
Conflicts ok none
PR text adopt when you next edit add a 'Tested:' line; a 'Risk:' line (door and Macs) (guide)

Areas: area:gpu
Merge: gh pr merge 2949 --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 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: FINISH, then merge at 0a4f6d6576a3: the code is ready; it needs only a row at this head.

Blockers: none in the code. Missing row: the paths only run on T8142 (M5, rebind_vm) and T8152 (G18). Needed: one M5 run at this head with two clients switching VMs and the retained objects cleared, and a refused job failing alone. We'll run it on our J714s. These paths are shared by M5 and M6, so one T8152 run at this head is also needed before it merges.

Checked: no Apple material, no gates. All 25 retained objects are cleared after full retirement on a VM change, and the host harnesses are mutation-tested. CI green.

@DjDeveloperr
DjDeveloperr dismissed their stale review November 25, 2026 04:45

Superseded by the review at 0a4f6d6

@github-actions github-actions Bot removed changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 25, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

0a4f6d6 J616s (T6040, M4 Pro) PASS: guarded one-shot combined batch (0aa9d658ff34 over main bc9b4c0, 0 merge-tree diffs on 17 changed files, default cmdline, stock Stage 2 1.0.0b17, boot 2546a528-6d7f-434e-b679-90a87d626c2e): 0 failed units, Enforcing, 0 new AVC, 0 GPU faults, 0 new kernel/subsystem errors, eDP connected pre/post, sep+mtp RTKit v12 clean, Borealis VK api.smoke 8/8 pre/post + glsl.loops 624/624, Wi-Fi 3/3 ping pre/post, 2/2 rtc1 s2idle; stock 7.3.0-aurora-fleet89 restored.

Copy link
Copy Markdown
Contributor

PASS on a 14-inch MacBook Pro (J714s, M5 Pro/T6050, G17S B1), kernel 7.3.0-m5-rows-prs, at 0a4f6d6576a39c4879259de5efc295d064793555.

Candidate 053c0549b09b7a48582d5dfbfeb1ddbb25af442d merged these unchanged heads onto main 15695c3ba53291e78bf62140598dbdffc7fb2b72 plus Clang fix 0050f580cc54892302f38e458e609d1b793010e0, which has since merged. The baseline was that same main plus the fix (f2b85419afafcfd6e6bc5ceeaa79e9ee557563a4).

The merged heads were #2906 f3ad1a8f362c, #3123 822a1dd7369c, #3116 064c3c65cd3e, #2949 0a4f6d6576a3, #2913 48b6d70dde9e, #2218 b3e6c51a4b5f and #2007 4738426f6c24.

Vulkan CTS returned identical per-case results on the baseline and candidate. api.smoke passed 8/8, glsl.loops passed 624/624, and compute.pipeline.basic returned 80 passes and 1 skip. Both arms had 0 GPU faults and 0 kernel WARNs in the CTS window, including 0 dma-fence.h:695 WARNs.

The command line matched the default. SELinux was disabled. tailscaled.service was the one failed unit on both boots and on the default. Each boot had 6 error-priority lines, all the known DCP clock-index message. After one deep cycle, there were 83 warning/error-priority lines on the baseline and 79 on the candidate, with zero added lines and zero kernel WARNING: reports. The known DCP clock-index message occurred 10 times on each arm through the wake.

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) needs-template PR body lacks Tested or 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