Skip to content

drm/asahi: G14 compute on GPU firmware 27.2 - #2544

Open
satchlj wants to merge 4 commits into
satchlj/g14-v27-2-sharedfrom
satchlj/g14-v27-2-compute
Open

satchlj wants to merge 4 commits into
satchlj/g14-v27-2-sharedfrom
satchlj/g14-v27-2-compute

Conversation

@satchlj

@satchlj satchlj commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Claude Opus 5.5 on @satchlj's behalf.

Second of three PRs that replace #2473: the compute backend as the G14 firmware-27.2 path. It builds on #2543. #2545 removes its build dependency on CONFIG_DRM_ASAHI_M3_T8122.

Selection. A G14G GPU (apple,agx-t8112, the existing T8112 configuration) whose DT apple,firmware-version is 27.2.0 takes this path in probe, before anything starts the coprocessor. There is no board name and no extra compatible. Other firmware versions keep the existing code.

What changes

  • fw/initdata.rs, rust/macros/versions.rs: raw InitData and HwDataB gain a V27_2 layout. A new AGX_V27_2 version group instantiates only those two types for G14/V27_2. Compile-time checks pin the 27.2 offsets against 13.5. GpuManager and the other versioned types are unchanged.
  • gpu/v27_2.rs: the 27.2 root. It is built on the records of a 13.5 G14 manager (GpuManager::build_graph with GraphProfile::G14V27_2: no register mappings, and the private range stays below the 27.2 timestamp aperture). It holds the hardware data from the 13.5 values, the chip's 27.2 register table (hw/t8112.rs), the power and thermal controller, the two idle-policy records, and one queue with a kernel-owned boot compute job. The firmware never sees the 13.5 root.
  • g14_v27_2.rs: start sequence, runtime and DRM backend. It mirrors the kernel window into the loader's shared second-level table and names it in TTBAT context 0 (mmu::FirmwareWindow). It then starts the ASC, sends the root, holds the GPU powered and retires the boot job. Clients submit through the 26.x front end (m3_submit). Each compute command is encoded in the 27.2 layout from a 48-slot pool and published in order on the root's queue. The runtime runs from the firmware's endpoint-0x20 messages, which it sends after publishing event, statistics or log records: each one queues a run of the service, which consumes the event, statistics, log and trace rings (the firmware waits when one is full) and retires completed commands. Completion follows the queue's retired position, which the firmware advances in order. There is no poll or timer; the DRM scheduler's job timeout runs the service as the backstop for a hung command. Each command goes into the next of 48 pool slots that is neither in flight nor still held by the firmware (tracking +0x94). The scheduler has one run queue per priority. Render commands get EINVAL. Unbind lets published work retire, detaches the message route, drains the service's workqueue, then stops the firmware (allow-off, RTKit power-off if it is still running, ASC halt) and keeps its memory for the rest of the boot.
  • Smaller pieces: CrashLog::from_firmware, GpuArray::shared_index, EventManager::try_get_polled, the Fender operating-point read, rtkit_dump.c (crash log to devcoredump), and the G14 skip of the 26.x CDM launch check, which decodes the G15 launch format.

Against #2473

Tested, this head (f890a9c9, slot-cursor fix) on phellos (J413, firmware 27.2), the up3 default kernel (7.3.0-1-up3-ARCH), this branch's module built against it (through #2545), loaded with no parameters under the same watchdog arrangement, trials h1–h8: 8/8 PASS. Each ran 3 × 1024 and 300 × 4096 words, every word checked, 303 of 303 dispatches; "GPU stopped: allow-off=Ok(()) running=Ok(0) forced-off=None submitted=303 completed=303 notifications=307 late=0 skipped-slots=0 deferred-cursors=45…48"; clean rmmod; unattended return. Cause and bisect are in the PR comment of 2026-11-20.

Tested, previous head (9454ef44, review rework) on phellos, J413 with firmware 27.2, the up2 default kernel (integration/aurora 458f759 + open PRs; this module built from the #2545 head over it), loaded with no parameters under the same watchdog arrangement, trial d8: PASS (later, on the up3 kernel, this head passed only 2 of 7 boots: the pool-slot cursor race fixed by f890a9c), 3 × 1024 and 300 × 4096 words, every word checked, 303 of 303 dispatches; "GPU stopped: allow-off=Ok(()) running=Ok(0) forced-off=None submitted=303 completed=303 notifications=307 late=0 skipped-slots=11945"; clean rmmod; unattended return to the default. The 300 dispatches took 77 ms (6.3 s with the old 20 ms idle poll). Start takes about 5 ms instead of 1.5 s.

Tested, earlier heads on phellos, a J413 (M2 MacBook Air) with firmware 27.2. The packaged default kernel (integration/aurora 61295c2 + open PRs) loaded this PR's module with no parameters, under a watchdog with unattended return:

  • trial c3, this head (module built in the distribution's default config, which has DRM_ASAHI_G15 and DRM_ASAHI_M3_T8122): PASS, 303 of 303 dispatches, 0 bad words; normal stop; clean rmmod; return to the default;
  • trial c1, this PR before a cfg-only change (gating unused helpers): the same.
    Each trial ran Vulkan compute through Mesa's Borealis driver: 3 × 1024 and 300 × 4096 words, data[i] = data[i]*mul + add + i, every word checked on the CPU after each dispatch. That is 303 dispatches, past the 256-entry submission ring. Then a normal stop (allow-off acknowledged, firmware reported off, no forced power-off) and a clean rmmod.

The boot loader on those trials was a trial Stage 2 that publishes the GPU on 27.2. Its DTB names the GPU apple,agx-t8112-identify, apple,agx-t8112; the first compatible is the loader's own trigger. The Aura in phellos's default (main + aura#381) leaves the GPU disabled on 27.2, so this path needs an Aura change before it runs on a default install. That change is not part of this series.

Waits that remain. Each is a bounded check of a word the firmware writes and sends no message for: the loader's handoff answer, the ready status (+0x14), the command-handler installation (+0x4c24 cleared), the idle-policy acknowledgement and the running flag at stop (the existing G14 path waits for its device-control channel the same way), and, after a notification, at most 2 ms for the retired position when the completion stamp is already there (never needed in the trials: late=0). The stop line reports the notifications received, those waits, and how many held slots were passed over.

Untested

  • Render (refused), and performance above the first operating point: globals +0x98 caps the state at 100, as in every trial.
  • Other G14G machines, other 27.2 builds, and firmware other than 27.2.
  • More than one client at a time, and runs much longer than 303 dispatches.
  • All 48 pool slots held at once (then the next notification, submission or scheduler timeout publishes; nothing else wakes it). Why the firmware keeps retired slots linked, and links some again after releasing them, is not known.
  • Rebind after unbind (the window stays installed, so a second probe gets EBUSY), suspend, and GPU fault recovery.
  • An Aura that publishes the GPU without the -identify compatible.

Assisted-by: LLM (Anthropic:Claude Opus 5.5)

@satchlj

satchlj commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Claude Opus 5.5 on @satchlj's behalf: hardware run.

PR head Checked Result
650176f1 Stacked series in the default kernel (CONFIG_DRM_ASAHI_G14_V27_2=y). Default loader leaves the GPU disabled; one-shot with a trial loader that publishes it: insmod with no parameters, Vulkan compute 3 × 1024 + 300 × 4096 words, every word checked on the CPU, "GPU stopped: … submitted=303 completed=303", rmmod clean. Render not tested Pass, 303/303

Build: phellos (MacBook Air M2, J413, macOS 27.2 / 26B123 stub), default rebuilt 2026-11-20 = linux integration/aurora 458f759 + #2519 #1832 #1831 #2264 #2525 #2526 #2543 #2544 #2545; Aura main 0beafec9 + aurora-silicon/aura#377 aurora-silicon/aura#227 (isp.c only) aurora-silicon/aura#381 aurora-silicon/aura#382; U-Boot aurora-wip 37baf8f7 + aurora-silicon/u-boot#67; Stage 2 DTB t8112-j413-fw27.dtb. One-shot boot under the SoC watchdog, then made the default (two default boots healthy).

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for the split. This step drops all the module parameters and the timed re-kick, and selects the path by G14G plus apple,firmware-version 27.2, which is what we hoped for.

One point is left. We avoid sleep/poll loops where the firmware gives a signal:

  • g14_v27_2.rs:48-49 and :285-291: completion and ring draining run from delayed work every 1 ms while busy and every 20 ms forever when idle, while recv_message (:111) drops every message on endpoints 0x20/0x21.
  • :214 waits a fixed 1 s for initialization to "settle", and :217 ignores the timeout of the command-service wait.
  • :482-495 stops the poll work with fsleep loops and a fixed 20 ms sleep instead of cancelling and flushing it.

Could completion and ring service run from the firmware's endpoint messages (as the existing G14 path does), with the idle poll gone, and cancel_delayed_work_sync in stop? If 27.2 really sends nothing, a code comment saying so would cover it. We will run rows on our M2 (G14G) as each step lands.

@satchlj

satchlj commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Claude Opus 5.5 on @satchlj's behalf.

@RyanTheTide: done in 9454ef44 (new commit, plus a merge of #2543's new head). The firmware does give a signal: on 27.2 it sends endpoint 0x20 a message after it publishes event, statistics or log records.

  • :48-49, :285-291 and :111. recv_message on 0x20 now queues one run of the service on its own ordered workqueue. Each run drains every ring, reads the retired position and publishes pending work. The delayed work, the 1 ms busy re-run and the 20 ms idle poll are gone, and there is no timer. As a backstop for a command the firmware never completes, the DRM scheduler's job timeout queues a service run, which reaches the existing 5 s command timeout. A firmware crash queues one too.
  • :214. The fixed 1 s "settle" is replaced by the firmware's ready word (status +0x14), bounded at 2 s, failing on timeout.
  • :217. The timeout is now an error. Making it one showed that the old condition (+0x4c00, +0x4c24) == (2, 0) never held once the handlers were installed: the old start always ran out the 500 ms. Installation is acknowledged by the firmware clearing +0x4c24, so that is the only condition now. Start takes about 5 ms instead of 1.5 s. A failed start names the step.
  • :482-495. stop now does three things in order. It waits on a condition variable that the service signals when nothing is pending or published, up to 2 s. It detaches the message route, so nothing can queue more work. Then it drains the workqueue. The fsleep loops, the queued counter and the 20 ms sleep are gone. The Rust workqueue binding has no cancel_delayed_work_sync, and since there is no delayed work any more, the owned queue's drain is the equivalent.
  • Waits that remain. Each is bounded and checks a word the firmware writes without sending a message: the loader handoff answer, the ready status, the +0x4c24 clear, the idle-policy acknowledgement and the running flag at stop. The existing G14 path waits for its device-control channel the same way (TxChannel::wait_for). There is also one wait after a notification, at most 2 ms, for the retired position when the completion stamp is already written. It never ran in the trials.

One finding the old poll had hidden. With completion now sub-millisecond, the fixed round-robin over the 48 pool slots stopped at the first reuse: the firmware kept the retired command's tracking slot (+0x94) linked indefinitely, and a diagnostic run showed it linking slot 0 again after releasing it. Pump now takes the next slot that is neither in flight nor held. If all 48 were held, it kicks the retirement scan once and the next notification, submission or scheduler timeout retries. I don't know why the firmware holds slots this way; the PR body says so.

Head Check Result
7fcd6e20 (#2545 head, contains this one), module built against phellos's up2 default kernel phellos (J413, firmware 27.2), loaded with no parameters, watchdog-protected one-shot boot (trial d8): Vulkan compute 3 × 1024 + 300 × 4096 words, every word checked on the CPU PASS, 303/303. GPU stopped: allow-off=Ok(()) running=Ok(0) forced-off=None submitted=303 completed=303 notifications=307 late=0 skipped-slots=11945, clean rmmod, unattended return. 300 dispatches in 77 ms (6.3 s before)
same arm64 module build: up2 config (G15, M3_T8122, G14_V27_2 on), and G14_V27_2 without M3_T8122 OK, no warnings on lines this stack touches
same asahi-m4 run-host-tests.py (Linux), m3-runtime-tests.rs 23/23, 83/83

Trials d1–d7 were the failures that led here: the never-satisfied command-service condition (d1), then the held-slot stall at command 48 (d2–d7, including the diagnostic run). Each one stopped the firmware cleanly and returned unattended.

Untested: everything in the body's Untested list, and in particular all 48 slots held at once, concurrent clients, and runs much longer than 303 dispatches.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for 9454ef4, it covers what we asked:

  • service now runs on endpoint 0x20's messages, with the scheduler timeout as the backstop;
  • the ready word and the +0x4c24 clear replace the fixed settle, and their timeouts are real errors;
  • stop drains the queue.

The waits that remain are bounded, poll words the firmware writes without sending a message, and say so in a comment. That's fine. The held tracking-slot finding is worth keeping in the description, as you did.

We'll run rows on our M2 (J413, 27.2) on this head: compute workloads, rmmod and reload, and one s2idle cycle.

@satchlj

satchlj commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Claude Opus 5.5 on @satchlj's behalf.

New commit f890a9c on this branch fixes a pool-slot stall in the notification rework (9454ef4). #2545 has it merged as 6c5d3db.

Symptom. On phellos (J413, firmware 27.2) the 300 × 4096 compute check stalled at the first pool wrap on most boots. Every slot was still linked (+0x94), so the 49th command was never published: submitted=48 completed=48 skipped-slots=480, then a clean stop. 3 × 1024 always passed.

Bisect. The asahi tree of the up2 trial that passed (d8) is byte-identical to this branch, so the base kernel was not the cause.

  • This branch's asahi tree on the older base (458f759), built against the up3 kernel: 0/2. One of the two was a timeout variant, a command that never completed.
  • The pre-rework heads (650176f / 7375638) against the up3 kernel: 3/4.
  • This head (9454ef4) against the up3 kernel, with a 1.5 s settle added before the boot job: 1/4. So start timing is not the cause.
  • Earlier: 2/7 on the up3 default (e1–e4, c6–c8). Every rework build before d8 (d2–d7, up2 kernel) stalled at the first reuse.

Cause. Dumps of the 48 tracking slots and the queue's timestamp queue at the wrap (diagnostic module, 7 runs):

  • The firmware links the slots LIFO into the queue's list: +0x98 next, +0xa0 the previous entry's next field. Each slot's +0xc reads 1.
  • Every slot's retirement cursor reads 0.
  • In the 5 failing runs, no slot was unlinked. In the 2 passing runs, exactly one slot had cursor 1, and it was the one slot the firmware had unlinked. The pool then reused that slot for the whole run, which is why the passing runs show skipped-slots near 47 per command.

The firmware writes +0xc in its post-processing, which can run after the queue's retired position advances. retire() ran on the first notification after the position moved, read +0xc as 0, and wrote 0 to the cursor, so the slot was never unlinked. The old 1 ms / 20 ms poll retired later and usually missed this window (3/4 here, 5/5 in c1–c5).

Fix. CommandPool::retire advances the cursor only once +0xc is recorded, and returns whether it did. A slot retired too early goes into a pending set. acknowledge() advances its cursor the next time the service runs: on the firmware's next notification, a submission or the scheduler timeout. There is no fixed wait or poll. Slot selection still skips slots that are still linked. The stop line now reports deferred-cursors.

Tested on hardware. phellos (J413, macOS 27.2 stub 26B123), up3 default kernel 7.3.0-1-up3-ARCH, this branch's module built against it, loaded with no parameters, trial loader gpu-up1-loader.bin, watchdog-protected one-shots with unattended return. Trials h1–h8: 8/8 PASS. Each ran 3 × 1024 and then 300 × 4096, every word checked on the CPU, 303/303 dispatches. Every run ended GPU stopped: allow-off=Ok(()) running=Ok(0) forced-off=None submitted=303 completed=303 notifications=307 late=0 skipped-slots=0 deferred-cursors=45…48, with a clean rmmod and the return to the default. With the slots now reused in order, skipped-slots is 0.

Host tests. tools/testing/selftests/drivers/gpu/asahi-m4 run-host-tests.py on the #2545 head: 23/23 ok.

Untested. Workloads other than this serial Vulkan compute check (many commands in flight at once, several clients). Render is still out of scope. The boot job's own tracking slot is never retired; it stays linked at the tail of the list, which these runs show is harmless.

🤖 Generated with Claude Code

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for f890a9c and the clear bisect. Advancing a slot's cursor only once the firmware has recorded +0xc, with early slots deferred to the next service run (notification, submission or scheduler timeout), keeps the runtime event-driven with no fixed wait. The h1-h8 8/8 runs with skipped-slots=0 are convincing.

We will run our M2 (J413, 27.2) rows on f890a9c rather than on 9454ef4: compute workloads, rmmod and reload, and one s2idle cycle. We'll post them here.

@satchlj

satchlj commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Claude Opus 5.5 on @satchlj's behalf.

Open finding at f890a9c (not fixed): s2idle with the GPU bound, then a hang around unload.

On phellos (J413, 27.2, up4 kernel with this series, GPU published by aura#402 at 10373aae, aurora autoloaded), one boot, 2026-11-20:

  • The rtc1 s2idle with the 27.2 firmware running logged apple-pmgr-pwrstate … PS gfx: Failed to reach power state 0xf (requested 0xf00200f, now: 0xf002b0f). The system resumed.
  • About 50 s later, fuser /dev/dri/renderD128; rmmod aurora; systemctl restart sddm hard-hung the machine. The journal holds nothing after 107.8 s, so I can't tell which of the three hung. A power cycle was needed.
  • Without a prior s2idle, rmmod is clean: every trial (c1–c8, d8, e2, h1–h8, u1–u3) stopped normally with running=Ok(0) and unloaded cleanly.

So the 27.2 runtime has no suspend handling. The gfx domain can't reach its target while the firmware is up, and an unload after that may not be safe. Until this is handled, the series should keep the GPU unpublished by default. Next steps:

  • stop or block s2idle while the firmware runs (a PM callback that halts it, or refuses suspend);
  • reproduce the unload-after-s2idle under the trial watchdog, to tell whether rmmod's stop path is what hangs.

Untested: s2idle with the GPU idle but bound, without any later unload.

🤖 Generated with Claude Code

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for flagging the s2idle finding at f890a9c rather than leaving it for a reviewer to hit. Agreed that the GPU should stay unpublished by default until suspend is handled.

For the fix, we would prefer a suspend callback that stops the firmware through its own shutdown handshake and starts it again on resume, over refusing suspend, so a bound GPU does not block sleep. If the stop path turns out to be what hangs after the s2idle, that would be good to know first.

Our M2 rows on f890a9c will cover compute, rmmod and reload now; we will keep the s2idle row for the head that adds suspend handling.

@satchlj

satchlj commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Claude Opus 5.5 on @satchlj's behalf.

Suspend handling is in as 0aac788 ("let the G14 firmware-27.2 GPU through suspend-to-idle"), merged into #2545 as a8d3cd3. That merge only moves the callbacks' cfg gate to CONFIG_DRM_ASAHI_G14_V27_2. The DT half is #2614.

What hung, first. It was not the stop path. The driver had no callback for suspend-to-idle (its prepare acts only on firmware suspend), so genpd gated the GFX domain under the running firmware in the noirq phase. At the wake pmgr logged PS gfx: Failed to reach power state 0xf (requested 0xf00200f, now: 0xf002b0f): target active, actual gated, BUSY. The next GPU access then hung a CPU: an RCU stall with CPU 2 not answering the NMI, about 35 s after a post-resume compute dispatch, and the earlier unbind hang. This is the J713 case that apple,sleep-retained was added for.

Your preferred design, tried first. Stop through the firmware's handshake (idle policy allow-off, then wait until it reports not running) and start it again on resume (keep-powered).

  • The stop works: "stopped for sleep: submitted=303 completed=303".
  • The restart does not. The first try was refused, because the idle ring only took its two build-time records. With the record encoded into the next slot, the firmware took the keep-powered record and crashed in that wake: RTKit crash, an EL1 exception with FAR in its own text region (0x800b306f8).

I did not go further into that. A cold restart (ASC halt, then start again) is not possible with this runtime, because its stop keeps the firmware's memory for the rest of the boot.

What the commit does instead.

  • Before suspend-to-idle: hold new publications and let published work retire (EBUSY if it doesn't within the stop drain time). The firmware keeps its keep-powered policy.
  • After the wake: publish what was held.
  • Domain: apple,sleep-retained on the J413 fw27 GFX domain keeps it on through the sleep.
  • Firmware-mediated sleep: still refused.

Rows (phellos, up4 default kernel df62a8c + our PRs, this commit as the module, aura#402 Stage 2 with the property). Each boot ran 3 × 1024 + 300 × 4096 Vulkan compute dispatches with every word checked, then one rtc1 s2idle, then the same again. No unload anywhere: rmmod after s2idle was never run.

boot before sleep after sleep PS gfx reboot after
s3 (same code as an experiment build) PASS, 50.3 ms PASS, 53.3 ms none (test script fault, WD1 reset)
s4 PASS, 51.1 ms PASS, 49.0 ms none (same fault)
s5 PASS, 58.2 ms PASS, 49.3 ms none (same fault)
s7 PASS, 51.2 ms PASS, 53.9 ms none clean

For s3–s5, the test's watchdog pinger kept the test's SSH session open, so the reboot step never ran; WD1 reset the machine instead. A control boot without s2idle (s6) did the same, and s7 with the fix rebooted cleanly. Every boot logged "GPU held for sleep: submitted=303 completed=303 pending=0" and "released after sleep: running=Ok(1)".

Untested: sleep with commands queued in pending, i.e. a client submitting while the system freezes; long sleeps and many cycles per boot; lid-close sleep; idle power, since the GPU stays powered through the sleep.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks for trying the handshake route first and for the clear account of why it can't work here. Knowing that the hang was genpd gating the domain under a running firmware, not the stop path, is very useful, and given the restart crash, holding publications, draining, and keeping the domain through apple,sleep-retained (#2614) is a reasonable design.

We'll run our s2idle row on 0aac788 with the #2614 property: compute before and after, a few cycles in one boot, and the power drawn during the sleep, since the GPU now stays powered through it.

@satchlj

satchlj commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Claude Opus 5.5 on @satchlj's behalf: trailer-only rewrite, removed Co-Authored-By from 4 commit(s); same trees, Signed-off-by kept (0aac788 -> 81446c7, --force-with-lease).

@satchlj
satchlj force-pushed the satchlj/g14-v27-2-shared branch from 259dd1a to a111d34 Compare November 21, 2026 21:53
@satchlj
satchlj force-pushed the satchlj/g14-v27-2-compute branch from 81446c7 to f5dfd26 Compare November 21, 2026 21:53
@satchlj

satchlj commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Claude Opus 5.5 on @satchlj's behalf: added the missing Signed-off-by: Satya Benson to 2 commit(s); same trees, nothing else changed (81446c7 -> f5dfd26, --force-with-lease).

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

Pre-PR checklist review at head f5dfd2617395 (stacked on #2543).

Blockers

  1. §3 Safety — hardcoded SRAM voltage fallback and duplicated thermal/alarm literals (drivers/gpu/drm/asahi/gpu/v27_2.rs).
    • In RootV27_2::build() (around sram_mv), if adt-perf-states-sram is absent under /chosen/aurora-gpu-resources/sgx, the code silently falls back to None => (*mv).max(850). Per §3, safety/voltage limits must come from the machine (ADT/DT) and never fall back to a guessed constant; if the loader does not supply adt-perf-states-sram, sram_table() must return an error (EINVAL/ENODEV) and refuse to start the GPU rather than inventing an 850 mV floor.
    • In RootV27_2::controller(), thermal/alarm thresholds (11000, 900, 125) and sensor correction coefficients (5.3) are written as bare literals instead of being read from cfg.da (unk_8cc, unk_87c, unk_e24) and cfg.unk_coef_a (which hw/t8112.rs already holds) or DT/ADT.
  2. Concurrency bug — Runtime::submit() vs Runtime::stop() race (drivers/gpu/drm/asahi/g14_v27_2.rs).
    AsahiPlatformDriver::unbind calls backend.stop() before _reg (the DRM registration) is torn down, so DRM scheduler kthreads can still invoke JobImpl::run() -> Runtime::submit(). submit() checks if !self.healthy() outside self.state.lock(), whereas stop() sets healthy = false, detaches notify, drains self.queue, and only then acquires self.state.lock() to guard.take(). A submit() that passes the unlocked healthy() check before stop() flips it can acquire self.state.lock() after queue.drain() and before guard.take(), push to pending, and call pump() — publishing a new command and ringing EP_DOORBELL while stop() is shutting down / halting the ASC.
    • Fix: re-check self.healthy() after acquiring self.state.lock() in submit() (and guard pump() on self.healthy()), returning Err(EIO) / Err(ENODEV) without mutating pending or publishing.
  3. Partial multi-command publication & OOM-after-publish bugs (drivers/gpu/drm/asahi/g14_v27_2.rs, pump() & service_locked()).
    • Drop of VmBind after firmware publication on ENOMEM: pump() publishes the command to the queue ring and sends EP_DOORBELL before calling state.inflight.push(...). If push fails with ENOMEM, bind (mmu::VmBind) is dropped immediately while the firmware is executing the command on that ASID slot. Reserve capacity in state.inflight before publishing to the firmware so push cannot fail post-publication.
    • Leaked VmJobGuard / premature quarantine on partial multi-command packet failure: if a Packet has multiple compute commands, command 0 is pushed onto state.inflight with last = false and packet.mark_published() is set. If command 1 then fails in pump(), pending.remove(0) drops the packet, packet.release_guard() is skipped (because index != 0), and packet.finish(Err(e)) immediately quarantines vm_job and signals the error fence while command 0 is still executing. When command 0 subsequently retires in service_locked(), if done.last { done.packet.retired(); } is false, so release_guard() is never invoked on retirement. Track the last published command (or remaining published count) per packet so retirement of the last published command cleans up the guard properly rather than leaking/quarantining it across a clean retirement.
  4. §1 Redundant chip-ID gate & firmware-version gate rationale (drivers/gpu/drm/asahi/driver.rs, drivers/gpu/drm/asahi/g14_v27_2.rs).
    • g14_v27_2::start() has a redundant match cfg.chip_id { 0x8112 => ... } check; attach the 27.2 register table / writable mask to HwConfig (or pass it cleanly from cfg) rather than matching a literal chip ID in code.
    • driver.rs gates on exact apple,firmware-version == [27, 2, 0]. Per §1, if an exact firmware-version gate is unavoidable (e.g., 27.3+ ABI may diverge), document why in the commit message and ensure it uses the narrowest firmware/layout property.

Non-blocking Notes

  • Runtime::sleep_prepare() currently wakes every 50 ms via idle.wait_timeout because service() signals idle only when both inflight.is_empty() && pending.is_empty(). Signalling idle whenever state.inflight.is_empty() && (state.pending.is_empty() || self.asleep.load(Ordering::Acquire)) removes the 50 ms polling wait during suspend drain.
  • STATE_CAP = 100 in gpu/v27_2.rs caps performance at P1 as a bring-up limit; make sure a follow-up tracks lifting it once higher operating points are verified.
  • Consider rebasing onto #2543 rather than carrying merge commit 66c50471 once #2543 is updated.

Pre-PR Checklist (§1–§6)

  • §1 No model gating: Blocked (see Blocker #4).
  • §2 Production-ready, no hacks: Blocked by concurrency/error-handling bugs (#2, #3); no module parameters remain (good).
  • §3 Safety: Blocked (see Blocker #1).
  • §4 Clean-room & attribution: Pass. All 4 non-merge commits carry human author/committer and human Signed-off-by: only, with no AI trailers; PR body discloses agent assistance.
  • §5 Evidence: Partial. CI checks on this base (source, rust-build, kunit, DWC3/ATC matrix) are green (host-tests does not trigger against a non-integration base branch). Still needed on the final head: J413 regression counts (0 SELinux denials, 0 failed units, 0 new kernel errors), rmmod after s2idle, and a G13/G14 13.5-stub no-regression boot row covering the touched shared files (driver.rs, gpu.rs, mmu.rs, fw/initdata.rs, event.rs, object.rs, regs.rs).
  • §6 Naming: Pass.

Assisted-by: LLM (Gemini 4 Neon)

GPU firmware 27.2 on G14 (the M2's G14G) takes a new root: four opaque
records (status, control, power, an extra block) after the UAT level
descriptors, and a runtime directory of 26.x-style channels in place of
the 13.5 RuntimePointers. Add that root as G14 V27_2 and a compute-only
runtime on it.

- fw/initdata.rs: the raw InitData and HwDataB layouts gain V27_2 (a new
  AGX_V27_2 version group instantiates only these two), with layout
  checks against 13.5.
- gpu/v27_2.rs: builds the root on the records of a 13.5 G14 manager
  (GpuManager::build_graph with GraphProfile::G14V27_2, which maps no
  registers and keeps the private range below the 27.2 timestamp
  aperture): hardware data from the 13.5 values, the chip's 27.2
  register table (hw/t8112.rs), the power and thermal controller, the
  idle-policy records, and one queue with a kernel-owned boot compute job.
- g14_v27_2.rs: start sequence and runtime. The driver's kernel window is
  mirrored into the loader's shared second-level table and named in
  TTBAT context 0 (mmu::FirmwareWindow); the ASC is started, the GPU held
  powered and the boot job retired; clients then submit through the 26.x
  front end (m3_submit), each compute command re-encoded in the 27.2
  layout from a 48-slot pool and published in order. Completion follows
  the queue's retired position. The firmware's event, statistics, log and
  trace rings are consumed as they fill. Render commands get EINVAL.
- driver.rs: a G14G whose DT apple,firmware-version is 27.2.0 takes this
  path, before anything starts the coprocessor.

There are no module parameters. Inputs come from the DT (operating
points, power and thermal properties, apple,coredump-copy-buffer, the
SRAM voltages the loader publishes, the UAT regions), the GPU's ID
registers and the T8112 chip configuration. Unbind stops the firmware
(allow-off, RTKit power-off if it does not stop, ASC halt) and keeps its
memory for the rest of the boot.

Signed-off-by: Satya Benson <satya@benson.earth>
Review asked for no sleep or poll loops where the firmware gives a
signal. The runtime polled from delayed work every 1 ms while busy and
every 20 ms when idle, and dropped every endpoint message.

The firmware sends endpoint 0x20 a message after it publishes event,
statistics or log records. Each message now queues one run of the
service, which consumes the rings and retires completed commands; there
is no idle poll and no timer. The DRM scheduler's job timeout runs the
service once more, so a command the firmware never completes still hits
the command timeout. A firmware crash also runs it.

The service runs on its own ordered workqueue. Stop waits for published
work on a condition variable the service signals, detaches the message
route so nothing queues more work, and drains the workqueue, replacing
the fsleep loops and the fixed 20 ms sleep.

Start waits for the firmware's ready status (+0x14) instead of a fixed
1 s, and fails if the command handlers are not installed in time instead
of ignoring the timeout. Installation is acknowledged by the firmware
clearing the request word (+0x4c24); the old wait also required the
powered-stage word (+0x4c00) to read 2, which it never did after the
handlers were installed, so it always ran out its 500 ms. A failed start
names the step. These and the idle-policy and running-flag waits stay
bounded checks of a shared word: the firmware writes it and sends no
message, as with the existing G14 device-control channel.

The completion stamp is written before the firmware's post-processing
advances the queue's retired position, which sends no message. When the
stamp is there and the position is not, the service waits for the
position for at most 2 ms.

Faster retirement showed that the firmware keeps a retired command's
tracking slot (+0x94) linked for a while, and can link one again after
releasing it; with a fixed round-robin the pool stopped at the first
reuse. Pump now takes the next slot that is neither in flight nor held.
If all are held it kicks the firmware's retirement scan once and the
next notification, submission or scheduler timeout retries; there is no
message for a slot's release.

The stop line reports the notifications received, how often the
position wait ran and how many held slots were passed over.

Signed-off-by: Satya Benson <satya@benson.earth>
…are records it

On phellos (J413, firmware 27.2) the 300-dispatch compute check stalled
at the first pool wrap on most boots: every slot was still linked in the
queue's tracking list (+0x94), so no slot could be reused and the 49th
command timed out (submitted=48 completed=48 skipped-slots=480).

Dumps of the tracking slots at the wrap show why. The firmware records
the value a slot's retirement cursor must reach (+0xc, 1 for every use)
in its post-processing, which can run after the queue's retired
position advances. The service retires a command as soon as the
position moves, so it usually read +0xc as 0 and wrote 0 to the cursor.
The firmware then never unlinked the slot. In the boots that passed,
the read happened to land after the record for one slot; only that slot
was ever unlinked, and the pool reused it for the rest of the run
(skipped-slots near 47 per command). The polled runtime before the
notification rework retired 1 to 20 ms later and usually missed the
window, which is why it mostly passed.

Retirement now advances the cursor only once +0xc is recorded. A slot
retired before that is kept in a pending set, and its cursor is advanced
when the service next runs: on the firmware's next notification,
submission or scheduler timeout. That is no fixed wait. The stop line
counts the deferred cursors.

Signed-off-by: Satya Benson <satya@benson.earth>
With the G14 firmware-27.2 runtime bound, a suspend-to-idle on phellos
(J413) left the GPU unusable. At the wake the GFX power domain did not
come back ("PS gfx: Failed to reach power state 0xf"), and the next GPU
access, a compute dispatch or an unbind, hung a CPU. The driver had no
callback for that sleep. Linux gated the domain under the running
firmware, as on J713 before apple,sleep-retained.

The domain is now kept through the sleep by the device tree
(apple,sleep-retained on the J413 firmware-27 GFX domain). Before
suspend-to-idle, the runtime holds new publications and lets published
commands retire, so the sleep starts with nothing in flight; after the
wake it publishes what was held. The firmware keeps running with its
keep-powered policy. The ASC, the root and every mapping stay as they
are.

Its own power-off handshake (idle policy allow-off before the sleep,
keep-powered after it) was tried and not kept: the firmware crashed in
the wake that followed it.

The sleep is refused (EBUSY) if published work does not retire within
the stop drain time. A sleep that powers the SoC down is still refused:
the firmware would be lost, and this runtime has no cold restart.

Signed-off-by: Satya Benson <satya@benson.earth>
@satchlj
satchlj force-pushed the satchlj/g14-v27-2-compute branch from f5dfd26 to 4c4f313 Compare November 22, 2026 10:43
@satchlj
satchlj force-pushed the satchlj/g14-v27-2-shared branch from a111d34 to 119cce5 Compare November 22, 2026 10:43
@RyanTheTide

Copy link
Copy Markdown
Contributor

Re-checked at 4c4f313. This is a rebase onto the updated satchlj/g14-v27-2-shared that drops the merge commit. Range-diff shows commits 2-4 unchanged, and the first changes only in conflict context (the Makefile line and the rxc.stats.set_manager() call the base added). The code is the same as f5dfd26, so the points raised at that head are all still open. The M2 s2idle row I mentioned is still to come and will be run at this head.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Test rows from a second G14G machine: Mac mini M2 (J473, T8112) on the macOS 27.2 stub, GPU published by the Stage 2 from aurora-silicon/aura#402. Kernel: integration/aurora a463112 with #2543 → #2544 → #2545 → #2610 merged on top (local merge, no other changes), distribution command line, one-boot trials with a watchdog and unattended return. Userspace: Fedora mesa-aurora 26.3.0-30 (Borealis), dEQP-VK 1.4.7.1, clpeak 2.1.1 (Vulkan backend).

This stack, unchanged (state cap 100):

  • Binds in about 5 s ("G14 firmware 27.2 running; compute-only DRM device registered"), renderD128, Apple M2 (G14G B0).
  • dEQP-VK compute.pipeline.* without cooperative-matrix and explicit-layout groups and without the 6 max_workgroup_memory cases: 738/776 Pass, 0 Fail, 38 NotSupported.
  • clpeak: fp32 905 / 957 / 1035 GFLOPS (float / float2 / float4), fp16 up to 1122, int32 282 GOPS, global memory 58.5–60.7 GB/s, kernel launch round trip 2.66 µs.
  • 600 s clpeak soak: 244 iterations, 0 failures, fp32 steady at 980.7 GFLOPS, SoC die 33 → 36 °C, no fault, crash, timeout or AVC.

Two dispatches that hang the firmware at the first state, both deterministic:

  • dEQP-VK.compute.pipeline.zero_initialize_workgroup_memory.max_workgroup_memory.1, alone, as the first submission of a boot: compute command timed out: stamp=0x100 expected=0x200 submitted=1 completed=0. In a full run it fails at the same submission every time. The same case passes with 13.5 firmware on an M2.
  • clpeak's int8 dot-product test.

After the timeout the runtime is marked failed and every later client gets ENODEV until reboot. A lab build that prints the MMU fault status on a timeout reads FAULT_INFO = 0 for both, so these are not page faults.

Performance states (lab builds, only the globals +0x98 cap changed):

cap state (DT OPP) fp32 float4 result
100 1 (444 MHz) 1035 GFLOPS stable
200 2 (612 MHz) 1424 GFLOPS stable: CTS subset 738/776, 120 s soak clean
500 5 (1110 MHz) 2788 GFLOPS stable: CTS subset 738/776, 600 s soak 252 iterations 0 failures, die max 39 °C
600, 700, ceiling 6 (1236 MHz) and up — first heavy dispatch never retires, FAULT_INFO = 0

So the cap tracks the state index in hundredths, states 1–5 run here, and the hang starts at state 6 (1236 MHz / 875 mV in the DT). A fixed 500 would be another magic number, so we are not proposing it as a change; it narrows where the 27.2 state-change inputs go wrong.

Not tested here: render (refused, as expected), suspend, more than one client at a time.

Row details
  • Trial Stage 2: aura#402 G14G handoff build, sha256 1cbfed26…; production boot object untouched; each trial is one boot (aura-try + GRUB next_entry) with a watchdog dead-man.
  • Kernel 7.3.0-aurora-m2gpu1+, merge of drm/asahi: report the G14 firmware-27.2 device as compute-only #2610's head on integration a463112 (no conflicts).
  • dEQP list: compute.pipeline.* minus cooperative_matrix and workgroup_memory_explicit_layout (782 cases), minus the 6 zero_initialize_workgroup_memory.max_workgroup_memory.* cases.
  • Before the hanging case, the full list gave 122 Pass / 25 NotSupported / 0 Fail over 148 cases; the timeout line was stamp=0xcc00 expected=0xcd00 submitted=204 completed=203.
  • Lab-only builds (not proposed): (a) print the MMU FAULT_INFO register (SGX + 0x17030, as the 13.5 path reads it) when a command times out; (b) the +0x98 cap taken from a test-only module parameter so one build covers the bisection.
  • cap 500: fp16 2792 GFLOPS, int32 708 GOPS, global memory 63.9–66.4 GB/s, local 922–1388 GB/s, launch 2.39 µs.

Assisted-by: LLM (Claude:Opus 5.5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants