Skip to content

drm/asahi: g16: keep renders of a multisampling VM apart from other VMs - #3180

Merged
RyanTheTide merged 1 commit into
mainfrom
fix/g16-msaa-crossvm-isolation
Nov 27, 2026
Merged

RyanTheTide merged 1 commit into
mainfrom
fix/g16-msaa-crossvm-isolation

Conversation

@DjDeveloperr

Copy link
Copy Markdown
Contributor

What: On the g16 backend, every VM's render passes share one firmware TA/FS queue pair. When two VMs' renders are in that queue at the same time and one of the VMs renders multisampled, that VM's passes lose coverage. Pixels and samples that should be covered come out uncovered or zero: CTS pipeline.monolithic.multisample min_sample_shading, alpha_to_coverage, z_export *_atc, mixed_count and standardsampleposition, and resolve_image.whole_copy_before_resolving. Its fragment shaders can also read VA 0 (an event=0x71 fault across all 8 banks at VA 0x0..0x380) or stall the fragment stage.

One process alone never shows this, and neither do processes that only render single-sampled. It is not about TA and FS running at the same time: making the later pass's TA wait for the earlier pass's FS with ring barriers does not help. The two passes only have to be in the queue together.

This change marks a VM once a multisampled pass of it becomes visible to the firmware. A render then waits for another VM's render flight to retire if either VM is marked or the render itself is multisampled. Admission, the same-submit fold and the cross-job fold apply this to every member, so a multisampled member never joins a prefix that is already beside another VM's render. Renders of one VM, and of VMs that never render multisampled, overlap as before.

Tested:

  • J773g (M4 Mac mini, T8132, 26B123) at a39164050e257, kernel origin/main 6d6e5366aab95 + this change, built on the J773g. This head differs from a39164050e257 only in two moved doc-comment lines and the selftest (diff below), so that run is the row for this head.
    • X7 ×4 (pipeline.monolithic.multisample, 4 deqp-vk processes): 32 process runs, 340,352 results, 0 non-pass.
    • 24-case MSAA list ×4: 8,160 results, 0 non-pass.
    • resolve_image family ×4: 60,976 results, 0 non-pass.
    • One RTC s2idle cycle, then the 24-case list again: 1,152 results, 0 non-pass.
    • 0 GPU faults, 0 recoveries, 0 quarantined owners.
  • Same runs on stock (7.3.0-ARCH-m4mainefed1ae3) fail within seconds:
    • 24-case list ×4: about 72 non-pass per 45 s, plus a reproduced FS recovery and the VA-0 FS fault.
    • X7 ×4: about 100 non-pass per 32 runs.
  • Earlier version on J773g: c091c85500ad3 had the same per-VM rule without the fold checks. It ran 100 X7 process runs (1,063,600 results), E2, the resolve family and the 24-case list with a single-sampled neighbour, all with 0 non-pass.
  • Selftests:
    • Full run-host-tests.py on the J773g at this head: 26/26.
    • test-publication.py: 89 passed. The new tests compile production code verbatim: the same-submit fold loop, the cross-job fold block and the publication prologue through the VM mark.
    • Mutation check: inverting the same-submit, cross-job or mark guard fails exactly its matching test. Removing a fold guard, or moving the mark before visibility, fails too.
  • Perf (gpubench-vk on J773g): render.light queue d1, queue d8, procs d4 and render.deferred are unchanged within noise. procs d4 measured 82.7–84.8 µs per submit, against 83.2–85.4 with origin/main behaviour. These were measured on c091c85500ad3, not on this head. Single-sampled work takes the same path here, because no VM is ever marked.
  • checkpatch --strict clean.

Risk: two-way door. It changes render admission on the g16 backend only, so it reaches every GPU that backend runs (M4, and the M3 parts on the 26B123 protocol). Cost: a process that renders multisampled no longer overlaps its renders with other processes' renders. An all-MSAA 4-process stress runs about 25% slower per iteration. Multi-process single-sampled rows are unchanged.

Not yet:

  • A row on a second M4 chip (T6040 or T6041), because the g16 path runs there too.
  • A frame-time row for an MSAA game under a compositor.
Details

How the mechanism was isolated: a diagnostic-only kernel (never for merge) switched admission at runtime, and the 24-case list ×4 ran for 45 s per mode, about 8,250 results each.

Mode Non-pass
origin/main behaviour 72
TA waits on the other VM's FS (ring barrier), behind an MSAA flight / any flight 70 / 72
USC cache invalidate set in every VDM root barrier 110
Full pass-slot scrub and work-image rewrite on every claim 73
No render published beside another VM's flight 0
No render pipelining at all 0

So the cause is the two VMs' renders being published together, not execution overlap, stale USC caches or partial work-image rewrites.

A rule keyed only on the pass's sample count was not enough. On the resolve family it still left 13 failures in 97,976 results, all whole_copy_before_resolving.2_bit. Its check pass is attachmentless and reads the MSAA images as input attachments, and Borealis gives such a pass sample count 1 until a draw sets it. That is why the VM is marked.

Excluding every cross-VM render overlap would also fix it, but render.light procs d4 went from 83.3 to 130.0 µs per submit, so it was rejected.

Runtime code compared with the tested a39164050e257 (git diff a39164050e257 HEAD -- . ':(exclude)tools/testing'):

-    /// Whether `job` requires `self.engine.flights` to drain to empty before it can
-    /// publish (so `alt`-class bypass must not keep refilling the engine ahead of it).
     /// Whether render `r` of `vm` may be published beside the flights in flight
     /// ([`msaa_render_conflict`]). Every member of a prefix is checked, not only its first.
     fn msaa_member_allowed(&self, vm: &Arc<super::vm::VmState>, r: &RenderCommand) -> bool {
@@
+    /// Whether `job` requires `self.engine.flights` to drain to empty before it can
+    /// publish (so `alt`-class bypass must not keep refilling the engine ahead of it).
     fn needs_engine_drain(&self, job: &Arc<Job>) -> bool {

The firmware or hardware state behind this is not identified. Giving each VM its own render queue, as macOS gives each command queue its own, would be the architectural follow-up and would let this rule go.

Every VM's render passes go through the one firmware TA/FS queue pair.
While passes of two VMs are both published there and one of the VMs
renders multisampled, that VM's passes lose coverage: pixels or samples
that should be covered come out uncovered or zero (CTS multisample
min_sample_shading, alpha_to_coverage, z_export *_atc, mixed_count,
standardsampleposition, and resolve_image whole_copy_before_resolving),
and its fragment shaders can fault at VA 0 or stall the fragment stage.
One VM alone never shows it, nor do VMs that render only single-sampled.

Making the later pass's TA wait for the earlier pass's FS with ring
barriers does not help: the two passes need not run at the same time,
only be published together. Single-sampled passes of a multisampling
VM are affected too, such as an attachmentless pass that reads its
multisampled images as input attachments.

Mark a VM once a multisampled pass of it becomes visible to the
firmware, and hold a render while another VM's render flight has not
retired if either VM is marked or the render itself is multisampled.
Apply the same rule to every member the same-submit and cross-job render
folds append, so a multisampled member never joins a prefix beside
another VM's render. Renders of one VM, and of VMs that never render
multisampled, still queue behind each other.

Signed-off-by: Diljit Singh <[email protected]>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 26, 2026 01:53
@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 Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Merge readiness at 9c3c459d: not ready yet

Check Detail
CI at head ok 18 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 9c3c459d
Conflicts ok none
PR text ok Risk: two-way · . It changes render admission on the g16 backend only, so it reaches every GPU that backend runs (M4, and the M3 parts on the 26B123 protocol). Cost: a process that renders multisampled no longer overlaps its renders with other processes' renders. An all-MSAA 4-process stress runs about 25% slower per iteration. Multi-process single-sampled rows are unchanged.

Areas: area:gpu

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

@RyanTheTide

Copy link
Copy Markdown
Contributor

9c3c459 J616s (T6040, M4 Pro, G16S B1) PASS: guarded one-shot (batch bc86f31c475b over main 5a4b951, 0 merge-tree diffs on 4 changed files, default cmdline, stock Stage 2 1.0.0b17, boot 54953f36-9276-4713-b89d-4d2b31756795): 6 concurrent deqp-vk processes (--jobs 6) over dEQP-VK.renderpass*.multisample* + dEQP-VK.pipeline..multisample. (50,260 cases in 14 s): 15,350 Pass / 0 Fail / 34,910 NS / 0 Warnings / 0 Waived; Borealis VK api.smoke 8/8 pre, post-MSAA, and post-1/1 rtc1 s2idle; Asahi GL gl-smoke 32/32 pre & post; 0 GPU faults/recoveries, 0 failed units, Enforcing, 0 new AVC, 0 new kernel errors; stock 7.3.0-aurora-fleet89 restored.

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

Copy link
Copy Markdown
Contributor Author

Verdict at 9c3c459d84f0: ready

Blockers: none.

Checked:

  • Keyed by what is submitted. A pass counts as multisampled when its samples is 2 or 4; the parser accepts only 1, 2 or 4. The mark is per VM. There is no SoC or board check, so the rule runs on every chip this backend drives.
  • Ordering. The VM is marked right after *visible = true and before the flight joins engine.flights, all under the device lock. The next admission check in the same publish pass already sees both. A publication that fails before visibility never marks the VM. One that fails after visibility leaves it marked, which is the safe side.
  • Every way in is checked. That covers the lead pass (can_queue_behind, and the behind check at the top of publish_prefix_body), the same-submit fold and the cross-job fold. The cross-job fold only takes jobs of the same VM and queue, so checking against engine.flights is enough. All three member paths go through prefix_render, so f.msaa also sees folded passes.
  • Lifetime. The mark is an AtomicBool in VmStateInner, and in-flight jobs hold the VM through their Arc. Nothing is allocated or freed, so there is no use-after-free and no leak. Recovery and VM close don't need to clear it.
  • No wedge. A held render takes the existing cross-VM drain path (needs_engine_drain, counted as drain_cross), as renders behind another VM's compute already do. In-flight flights only wait on work that was already published, so they retire and the held render gets in. Queue turns keep one VM from starving the other.
  • Single-sampled work is unchanged. While no VM has published a multisampled pass, the new check is false everywhere. The only added cost is a scan of at most 32 flights per member.
  • No runtime switch, no module parameter, no new constant.
  • Known cost, not a blocker. A VM stays marked for its lifetime, so a long-lived process that renders multisampled once (a browser, say) takes turns with the compositor's renders from then on. That is the compositor frame-time row under "Not yet". Also, a VM whose first multisampled access isn't a multisampled pass (an attachmentless pass reading images that compute wrote) is not marked. That fits what the PR says the rule covers.
  • Before merge. The two rows (J773g, J616s) are both M4. The M3 parts that also run this backend (T6030, T8122) have no row yet; a J516s row would cover them. This PR and drm/asahi: g16: drop the M4 TA wave window #3185 conflict in g16/command.rs, g16/engine.rs and test-publication.py, so whichever lands second needs a rebase and a fresh row.
Evidence
  • Head 9c3c459d84f0 over main 6d6e5366aab9. It merges cleanly into current main 40e5e29cc915; merged with drm/asahi: g16: drop the M4 TA wave window #3185 it conflicts in the three files above.
  • Read: g16/engine.rs (msaa_render_conflict, msaa_member_allowed, needs_engine_drain, the render arm of can_queue_behind_with_ta, the same-submit fold check at engine.rs:3173, the cross-job fold check at engine.rs:3330 (same-VM condition at about line 3288), the mark after *visible = true at engine.rs:3479-3482, the flight push at engine.rs:3643-3645, and prefix_render at engine.rs:4008), g16/vm.rs, and g16/command.rs (the samples check at lines 649 and 1282).
  • Build at this head, asahi profile, Image modules, LLVM=1, native arm64: OK, aurora.ko linked. No new warning: the g16 ones (fetch_update deprecated in vm.rs, unused check_render in command.rs, unused retired* in poll.rs) are already on the base and on lines this PR does not change.
  • KUnit, drivers/gpu/drm/asahi/.kunitconfig on arm64 QEMU: 431 tests, 427 passed, 4 skipped (config or board-image cases), 0 failed.
  • Host selftests, run-host-tests.py --only asahi-m4 at this head: 26/26 files pass; test-publication.py 89 passed.
  • CI at this head: all 18 checks pass (apple-build, host-tests, KUnit asahi and the other KUnit suites).

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J516s (MacBook Pro 16" M3 Pro, 27.2 stub) row for 9c3c459d84f0, from one boot of main 9a9862253576 + #3180, #3195, #3196, #3021, #3210 (no file overlap). Main 9a9862253576 alone was booted as the control. Both were one-shot boots on the default cmdline with Mesa 0539df01eab6. dEQP-VK.pipeline.monolithic.multisample.* (10,636 cases) ran in 4 deqp-vk processes for 10 rounds (5, then an s2idle attempt, then 5 more). Non-pass per round with the PR: 5/8/8/8/6 and 8/9/5/10/5, 72 in all and every one a Fail. On main: 5/9/4/7/9 and 6/10/6/7/12, 75 in all. So the PR adds 0 beyond main's count. resolve_image (516 cases, 4 processes): 0 non-pass on both. gpubench-vk render.light: 127/44 µs per submit at queue d1/d8 and 68 at procs d4, against 127/43 and 67 on main. 0 GPU faults or recoveries and 0 failed units. The only new kernel error lines are dwc3-apple's s2idle refusal at prepare (genpd_prepare -11, also on main, so no sleep happened) and the MTP HID "no listeners" line that the baseline also logs.

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

Verdict at 9c3c459d: MERGE.

Blockers: none.

Checked (adversarial)

  • Every way a render gets published goes through the new VM-separation check: the lead pass (can_queue_behind_with_ta and the behind check in publish_prefix_body), needs_engine_drain, the same-submit fold, and the cross-job fold, which only folds same-VM/queue jobs.
  • The check is symmetric: either VM is marked, or the render itself is multisampled. It reads the VM's mark each time, so older flights of a VM marked later are caught.
  • The mark is set under the device lock before the flight is pushed, and stays set if publication fails, which is the safe side.
  • A held render goes through the existing drain-to-empty path (DrainCross), so there's no deadlock, and starvation is no worse than the existing cross-VM rule.
  • The flag is an AtomicBool, and flights hold the VM through an Arc, so there is no address reuse.
  • There are no gates, params, delays or debug leftovers. It merges cleanly into main, and the asahi-m4 host test passes.
  • Rows: J516s and J616s at this head. J773g at a3916405; this head differs only in two moved doc-comment lines and the selftest.

Non-blocking

  • On J516s it's 72 fails with the PR against 75 on main, so on M3 it fixes nothing and only adds the cost. Please say in the body that the M3 cause is different.
  • The J616s row has no stock control.
  • A process that once renders multisampled stays marked for life, for example a browser beside the compositor. The compositor frame-time row is still under Not yet.
  • It conflicts with #3185, so whichever lands second needs a rebase and a row.

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

2 participants