Skip to content

drm/asahi: g14_v27_2: mirror FirmwareWindow L2 growth and avoid runtime alloc.private leaks - #3250

Merged
RyanTheTide merged 1 commit into
aurora-silicon:mainfrom
AxxzyWasTaken:pr/g14-v27-2-fw-window-gc
Nov 28, 2026
Merged

RyanTheTide merged 1 commit into
aurora-silicon:mainfrom
AxxzyWasTaken:pr/g14-v27-2-fw-window-gc

Conversation

@AxxzyWasTaken

@AxxzyWasTaken AxxzyWasTaken commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What: Fix both long-running workload failures in the G14 firmware 27.2 backend:

  1. Dynamic FirmwareWindow L2 mirroring past 32 MiB (drivers/gpu/drm/asahi/mmu.rs, g14_v27_2.rs, gpu/v27_2.rs): Retain FirmwareWindow inside kernel_vm's VmInner via Uat::attach_firmware_window() after boot instead of discarding it with core::mem::forget(). Mirror newly allocated kernel-window L2 entries into shared_l2 on VmInner::map_node(), Vm::map_io(), and Uat::prepare_tables() under kernel_vm's existing exclusive GPUVM lock (zero new locks). FirmwareWindow::sync_range() validates bounds, window intactness, and every covered L2 slot in a read-only pass (including confirming previously mirrored slots still match shared_l2 so cleared or replaced firmware descriptors fail closed), PoC-cleans each new L3 page (clean_page + dsb sy) before atomic Release publication to shared_l2, then PoC-cleans the updated shared_l2 span and issues tlbi_range(0, span_start, span_len).
  2. Stop unbounded alloc.private garbage leak (drivers/gpu/drm/asahi/buffer.rs): On G14 27.2, alloc.private is mapped PROT_FW_PRIV_RW with keep_garbage = true / GarbageAction::Hold. Auditing all G14 27.2 alloc.private callers shows every allocation is boot-only except Buffer::new(), which allocated the unused legacy 13.5 buffer::Info wrapper on every render-queue create/destroy cycle (27.2 firmware receives its own Binding::info in alloc.shared, never buffer::Info's GPU VA). Add ParameterListPlacement::info_in_private() returning false for KernelGpu so buffer::Info is placed in uncached alloc.shared (keep_garbage = false), eliminating runtime alloc.private growth while keeping keep_garbage = true intact and legacy VmPrivate unchanged.
  3. Host tests (tools/asahi/g14-v27-2-fw-window-gc-tests.py): Registered in tools/asahi/run-host-tests.py, covering multi-L2 growth across 32/64/96 MiB boundaries, PoC/TLBI ordering, atomic rollback (including missing/replaced shared_l2 descriptors on previously mirrored slots), and render-flight reclamation with 10 negative-control mutations.

Tested: python3 tools/asahi/run-host-tests.py --only g14-v27-2-fw-window-gc: 11/11 PASS (10/10 negative-control mutations killed, including skip-existing-shared-check).

  • python3 tools/asahi/run-host-tests.py --only asahi-m4: 1/1 PASS.
  • ARM64 cross-compile (ARCH=arm64 LLVM=1 drivers/gpu/drm/asahi/aurora.o) with CONFIG_DRM_ASAHI_G14_V27_2=y: PASS, 0 warnings in touched files.
  • git diff --check clean; scripts/checkpatch.pl --strict: 0 errors, 0 style warnings.

Not yet: On-hardware G13G (T8103) / G14G (T8112) firmware 27.2 soak test crossing >32 MiB kernel-window growth, repeated render-queue create/destroy cycles, and post-S2R allocations.

Risk: two-way · G13G (T8103) and G14G (T8112) GPUs running the g14_v27_2 firmware 27.2 backend; legacy 12.x/13.5 and G15/G16/G17/G18 paths are untouched.

Closes: #3067

@AxxzyWasTaken
AxxzyWasTaken requested review from a team and DjDeveloperr as code owners November 26, 2026 12:52
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:m1 Macs affected, from Merge risk (bot) blast:m2 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 c12e5891: not ready yet

Check Detail
CI at head no failing: pr-text / pr-text
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 c12e5891
Conflicts ok none
PR text ok Risk: two-way · G13G (T8103) and G14G (T8112) GPUs running the g14v272 firmware 27.2 backend; legacy 12.x/13.5 and G15/G16/G17/G18 paths are untouched. Closes: #3067

Areas: area:gpu

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

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

The two-phase mirror checks a new slot before publishing and cleans the new L3 page first. For a previously mirrored slot it returns early on shadow descriptor == entries[idx] without checking that the corresponding shared_l2 entry still matches. intact() checks the roots and context, so it does not establish the shared slot contents. Please verify existing shared descriptors too, or document the invariant that firmware and resume cannot clear or replace a slot while those roots remain unchanged. Include a host case for an existing shadow slot with a missing shared descriptor. Keep the landing gate on a firmware-27.2 G13G/G14G soak that crosses more than 32 MiB, churns queues, and repeats growth after resume.

Fix two long-running workload bugs in the G14 firmware 27.2 backend:

1. Dynamic FirmwareWindow L2 mirroring past 32 MiB

FirmwareWindow previously mirrored the shadow kernel L2 page table into
the firmware's shared_l2 table once during start() and then discarded
ownership with core::mem::forget(window). Each L2 entry spans 32 MiB
(2048 * 16 KiB pages), so any post-boot mapping in alloc.gpu,
alloc.shared, or the kernel window that allocated a fresh L2 table past
the boot-time 32 MiB span updated only the driver's shadow L2 and never
populated shared_l2, causing immediate UAT translation faults.

Attach FirmwareWindow to kernel_vm's VmInner via
Uat::attach_firmware_window() after boot succeeds and invoke
VmInner::sync_firmware_window() from VmInner::map_node(), Vm::map_io(),
and Uat::prepare_tables() under the existing exclusive kernel GPUVM
lock (introducing no new locks or lock-order edges).

FirmwareWindow::sync_range() validates window bounds, intactness, and
every covered shadow L2 entry in a read-only pass (including verifying
previously mirrored slots still match shared_l2 so cleared or replaced
descriptors fail closed), cleans each new L3 page to PoC (clean_page +
dsb sy) before atomically publishing its descriptor into shared_l2,
then cleans the updated shared_l2 span to PoC and issues mem::sync() +
mem::tlbi_range(0, span_start, span_len) + mem::sync(). Any failure
returns before mutating shared_l2 so discard_partial_map() rolls back
cleanly.

2. Eliminate unbounded alloc.private garbage accumulation

G14 27.2 maps alloc.private with PROT_FW_PRIV_RW (non-coherent ASC
cached) and has no device-control cache flush path, so alloc.private
keeps keep_garbage = true and GarbageAction::Hold to prevent stale ASC
cache lines from being exposed by reuse. Every other G14 27.2
alloc.private object is boot-only and retained for the life of the boot,
except Buffer::new(), which allocated the legacy 13.5 buffer::Info
wrapper from alloc.private on every render-queue create/destroy cycle.
G14 27.2 firmware never receives buffer::Info's GPU VA (QueueRender
builds its own 27.2 Binding::info record in alloc.shared).

Add ParameterListPlacement::info_in_private() returning false for
ParameterListPlacement::KernelGpu so Buffer::new() allocates the unused
wrapper from uncached alloc.shared (keep_garbage = false). Runtime
render-queue churn now performs zero alloc.private allocations and
immediately reclaims Buffer allocations on Buffer::drop once all
RenderFlights holding the Scene/Buffer have retired (while fail_all()
retains in-flight flights on timeout/fault).

Add a host test harness in tools/asahi/g14-v27-2-fw-window-gc-tests.py
(registered in tools/asahi/run-host-tests.py) exercising real extracted
code from mmu.rs, buffer.rs, and gpu.rs across multi-L2 growth
(32/64/96 MiB), PoC/TLBI ordering, fail-closed rollback (including
missing or replaced shared_l2 entries on previously mirrored slots),
and render-flight reclamation with 10 negative-control mutations.

Closes: aurora-silicon#3067
Signed-off-by: AxxzyWasTaken <[email protected]>
@AxxzyWasTaken
AxxzyWasTaken force-pushed the pr/g14-v27-2-fw-window-gc branch from 80412b4 to c12e589 Compare November 27, 2026 17:10
@AxxzyWasTaken

Copy link
Copy Markdown
Contributor Author

Updated at c12e58916d3b (rebased onto main ad25d59a9d6d for clean CI):

  • Verify existing mirrored slots against shared_l2: In FirmwareWindow::sync_range() Phase 1 (drivers/gpu/drm/asahi/mmu.rs), when e == prev, load shared[idx] with Acquire and return Err(EIO) if cur_shared != e rather than returning early on the cached shadow descriptor alone. Any cleared (0) or replaced shared_l2 descriptor now fails closed before Phase 2 publishes any new slots, and rolls back via discard_partial_map().
  • Host test coverage (tools/asahi/g14-v27-2-fw-window-gc-tests.py + run-host-tests.py): Added t4b_existing_shadow_slot_missing_or_replaced_shared_descriptor_fails_closed covering (a) single-slot existing shadow slot with shared_l2[slot] == 0 while intact() stays true, (b) replaced non-zero shared_l2[slot], and (c) multi-slot straddling [new_slot, existing_slot_with_missing_shared] verifying zero partial publication on new_slot, plus negative-control mutation skip-existing-shared-check.
  • Verification at c12e58916d3b:
    • python3 tools/asahi/run-host-tests.py --only g14-v27-2-fw-window-gc: 11/11 PASS (10/10 mutations killed).
    • python3 tools/asahi/run-host-tests.py --only asahi-m4: 1/1 PASS.
    • ARM64 cross-compile (ARCH=arm64 LLVM=1 drivers/gpu/drm/asahi/aurora.o, CONFIG_DRM_ASAHI_G14_V27_2=y): PASS, 0 warnings in touched files.
    • scripts/checkpatch.pl --strict: 0 errors, 0 warnings, 0 checks.

Keeping the landing gate on a firmware-27.2 G13G/G14G soak crossing >32 MiB, churning queues, and repeating growth after resume (no M1/M2 hardware locally).

@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 c12e58916d3b. The source fix resolves my earlier shared L2 finding.

Blockers: Complete the hosted checks and attach the firmware 27.2 G13G/G14G qualification for growth across an L2 boundary, queue churn and new allocations after resume.

Checked: The first pass now compares each previously mirrored descriptor against the live shared entry, rejects cleared or replaced entries, and validates the full range before publishing any new descriptors.

Evidence

The source fixture covers missing and replaced descriptors and a range spanning a new slot followed by a mismatched live slot, with the first slot still unpublished after the error. The PR records an author arm64 compile and keeps the hardware soak open.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Tested c12e589 on J473 (M2 mini, G14G B0, fw 27.2): PASS, as part of a batch boot.

Kernel: 7.3.0-aurora-ibg14b = main d8c60437 + no-ff merges of #3250 c12e5891, #3238 d1c27c87, #3230 f6a5d7a1 and #3214 f1e87917 (each head is an ancestor; the only conflict was the tools/asahi/run-host-tests.py registry). Signed combo27 config, combo27 J473 Stage 2, saved production options. Host tests on the composed tree: fw-window-gc 11/11, try-bind 10/10, legacy-wq-prepub-abort 10/10, dcp-hdmi-sleep-unplug 13/13.

Row (one guarded one-shot, restored to fleet89 after):

  • Desktop row: GNOME session, vkcube, glxgears, WebGL; all sinks muted.
  • 3 short s2idle cycles (rtc, 15 s) with HDMI + USB-C displays attached, plus 1 after load: 4/4 rc=0, triangle/vkcube pass after each, HDMI DCP powered back with HPD connected each time.
  • Heavy compute 3 rounds (gpubench-vk light, heavy, alu and bw at depths 1..64): 12/12 ok, klog_bad 0.
  • GL render.postfx 8/8 loops, then 10 fresh Vulkan clients 10/10. GNOME shell PID unchanged for the whole boot.
  • 0 GPU faults, timeouts, recoveries or firmware crashes. Enforcing, 0 failed units.
  • The one red check is AVC=2, both from restorecon writing the harness's own Firefox log file (setfiles_t on var_lib_t). That is fixture noise, not this kernel.

Evidence: traces/gpu/20261129-ib-g14batch/20261129-005245-j473-ibg14b-a.

For this PR: the 10 fresh Vulkan clients and the GL loops create and destroy render queues on every client. No firmware-window or allocation errors were logged, and nothing failed. I didn't measure alloc.private growth directly.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Tested c12e589 on J316s. G13 row: tested on J316s (M1 Pro, G13S C0) at this head, PASS. Kernel 7.3.0-aurora-ibg13b = main d95848ae + no-ff merges of #3250 c12e5891, #3238 d1c27c87 and #3230 ac06a535 (each head an ancestor).

  • One GRUB one-shot on the fleet89 saved default.
  • Hardware GL ES smoke (surfaceless, Apple M1 Pro (G13S C0)) and Vulkan device enumeration pass.
  • gpubench-vk compute.heavy and compute.light, 3 rounds each: all ok.
  • 2 s2idle cycles (rtc1, 15 s): rc=0, with GL, Vulkan and compute passing after each.
  • 0 GPU timeouts, faults, recoveries or firmware crashes. Enforcing, AVC 0, 0 failed units.
  • The production kernel gives the identical result in the same check (baseline-fleet89-j316s.txt).
  • Restored: custom.cfg byte-identical, kernel removed.

The J473 G14 27.2 row on the same kernel also passes (heavy 12/12, GL 8/8, Vulkan 10/10, s2idle 4/4). Evidence: traces/gpu/20261129-ib-g13batch/ (README).

@RyanTheTide

Copy link
Copy Markdown
Contributor

code-owner ping <@422957901716652033> / @DjDeveloperr: merge train at c12e5891. App approved. Rows at this head: J473 (G14, fw 27.2) + J316s (G13) PASS. Merges in 1 h under the 6-point rule, in order #3214 -> #3250 -> #3238 -> #3230, unless you object.

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

Copy link
Copy Markdown
Contributor

Merging under the 6-point rule (Ryan 09:29, permanent), at c12e5891. (1) The review App approved at this head. (2) Full CI is green. (3/4) Rows: J473+J316s. (5) There's no blocking review. (6) Dj was pinged here 65 min ago with no objection. Revert: git revert -m 1 <merge>.

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:m1 Macs affected, from Merge risk (bot) blast:m2 Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (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.

drm/asahi: g14_v27_2: static boot-time FirmwareWindow L2 mirror faults past 32 MiB and alloc.private garbage leaks

2 participants