Skip to content

drm/asahi: preserve workqueue event order across pre-publication run() aborts - #3230

Merged
RyanTheTide merged 1 commit into
aurora-silicon:mainfrom
AxxzyWasTaken:pr/asahi-wq-prepub-abort
Nov 29, 2026
Merged

RyanTheTide merged 1 commit into
aurora-silicon:mainfrom
AxxzyWasTaken:pr/asahi-wq-prepub-abort

Conversation

@AxxzyWasTaken

@AxxzyWasTaken AxxzyWasTaken commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What: Fixes legacy G13/G14/G14X workqueue event ordering corruption when a committed job fails in QueueJob::run() before publishing its commands to firmware:

  • Monotonic WorkQueueOrder: Encapsulate queue sequence and stamp ordering in WorkQueueOrder, remove EventValue::sub(), and update last_submitted and published_event_seq only in JobSubmission::run() on actual publication.
  • Pre-publication abort vs partial commit rollback: On pre-publication abort in Job::drop() and JobSubmission::drop(), advance submit_seq past aborted commands without rolling back tail counters or overwriting last_submitted; keep tail-only uncommit() for partial QueueJob::commit() failures under the queue lock.
  • Barrier and TVB safety across aborts: Have WorkQueue::event_info() return the live wait target so new barriers skip already-aborted jobs; track cross-submission explicit barrier waits (wait_frag_seq / wait_comp_seq) in QueueJob and cancel with -ECANCELED in run() if the waited-on event_seq was never published; take all subqueue jobs upfront in QueueJob::run() and call abort_subqueues() synchronously on every pre-publication error path; latch tvb_init_pending immediately after buffer.new_scene() when scene.rebind() is true and propagate scene.rebind() || init_slot out of submit_render() so neither mid-submit_render() errors nor pre-publication aborts lose an InitBuffer requirement.
  • Tests: Add KUnit tests in drivers/gpu/drm/asahi/workqueue.rs (including FIFO abort -> dependent consumer cancel -> later independent publish ordering) and a host test harness with 9 negative-control mutations in tools/asahi/legacy-wq-prepub-abort-tests.py (registered in tools/asahi/run-host-tests.py).

Closes: #2546

Tested: Rebased onto main (a81a12c7de36) at ac06a53503ca: tools/asahi/run-host-tests.py --only legacy-wq-prepub-abort passed 10/10 (baseline + all 9 negative-control mutations killed); ARM64 cross-compile (ARCH=arm64 LLVM=1 drivers/gpu/drm/asahi/asahi_core.o with CONFIG_KUNIT=y) passed with 0 warnings in touched files; git diff --check clean; scripts/checkpatch.pl --strict reports 0 errors / 0 code warnings. Prior head f6a5d7a1183d also passed the J473 (M2 mini, G14G B0, fw 27.2) batch no-regression row (#3230 (comment)); functional diff from f6a5d7a1183d is empty (only merged the 1-line mod tests import with #2886's ring_reaches_done).

Not yet: Live G13 (M1) row and live G13/G14/G14X hardware abort row exercising a failed producer, committed dependent consumer with explicit barrier, and later independent submission on the producer queue (no legacy M1/M2 hardware locally — peer row requested).

Risk: two-way · G13/G14/G14X Macs (M1, M2 family)

@AxxzyWasTaken
AxxzyWasTaken requested review from a team and DjDeveloperr as code owners November 26, 2026 10:08
@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) ci-failing A check failed at the PR head (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 ac06a535: 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 in the PR body at ac06a535
Conflicts ok none
PR text ok Risk: two-way · G13/G14/G14X Macs (M1, M2 family)

Areas: area:gpu

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

@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) and removed ci-failing A check failed at the PR head (bot) labels Nov 26, 2026

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Hold at 604e5be0065b for CI and cross-queue abort evidence.

Blockers: Apple build, arm64 KUnit, PR text and readiness are red at this head. Please refresh the branch on the current base and get the required checks green. The review also needs the requested live legacy-GPU abort row. Include a failed producer, a committed consumer with an explicit barrier to that producer, and a later independent submission on the producer queue. Record whether the dependent job cancels and independent work continues.

Checked: The exact-head standalone host harness passed here. Its order model treats publication as a high-water sequence. A later publish can make has_published() return true for an aborted sequence below that watermark. Please show what ordering invariant prevents a dependent job from reaching that state, or cover it explicitly if a later stamp is meant to satisfy the earlier wait.

@AxxzyWasTaken
AxxzyWasTaken force-pushed the pr/asahi-wq-prepub-abort branch from 604e5be to f6a5d7a Compare November 27, 2026 15:17
@AxxzyWasTaken

Copy link
Copy Markdown
Contributor Author

Refreshed onto main (a561e89792d5) at f6a5d7a1183d so the full CI suite runs cleanly (the earlier run on 604e5be0065b was hit by the upstream cancel sweep), and documented/tested the has_published() ordering invariant:

  • Why the high-water published_event_seq cannot be falsely satisfied by a later publish:
    1. Every Queue submits all its QueueJobs into a single drm_sched::Entity, so QueueJob::run() executes strictly in FIFO submission order. The inline fast path (can_submit_inline()) enforces the same order: it requires previous_status != 0 (the previous QueueJob's finished fence is already signaled) and inner.order.submit_seq == self.event_info.cmd_seq.
    2. Cross-submission explicit barriers (index == 0) always capture events[q][0] from WorkQueue::event_info() = WorkQueueOrder::wait_target() under the queue lock — i.e., the latest committed event_seq at Queue::submit() time.
    3. Therefore, any dependent consumer J_dep waiting on producer J_prod (event_seq = k) was submitted and armed to self.entity after J_prod and before any later producer J_later (event_seq = m > k; if J_later had committed before J_dep::submit(), J_dep would have captured m, not k). When J_dep::run() executes, J_prod has already either published or aborted, and J_later cannot have run yet, so published_event_seq <= k, with published_event_seq >= k iff J_prod itself published.
  • Added this invariant comment on WorkQueueOrder::has_published() and KUnit test fifo_abort_cancels_dependent_consumer_before_later_independent_publish in drivers/gpu/drm/asahi/workqueue.rs.
  • Local verification at f6a5d7a1183d: tools/asahi/run-host-tests.py --only legacy-wq-prepub-abort 10/10 PASS (9/9 mutations killed), ARM64 drivers/gpu/drm/asahi/asahi_core.o (CONFIG_KUNIT=y) clean (0 warnings in touched files).
  • Hardware row: I only have an M4 Max (J616C) locally, so this still needs a legacy G13/G14/G14X (M1/M2) peer row exercising the failed-producer -> dependent-consumer-cancel -> later-independent-submission sequence.

@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 new FIFO case exercises a committed producer abort followed by the dependent consumer and then the independent producer. I confirmed that the cross-submission barrier captures the current render or compute tail and that the submissions share the same scheduler entity. This addresses my high-water concern for that execution order. The exact-head standalone harness passed here. Code approved. The live G13/G14/G14X row still needs to exercise all three steps, and the hosted checks are queued.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Tested f6a5d7a on J473 (M2 mini, G14G B0 = G14 legacy-wq family, 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: this is a no-regression row on the shared workqueue path. The failed-producer abort itself wasn't triggered, since nothing in the row aborts a run() before publication. An M1 (G13) row is still open.

…) aborts

On the legacy G13/G14/G14X workqueue backend, failing a committed job in
QueueJob::run() before publishing its commands corrupts queue ordering in
three ways:

1. Drop for Job subtracted event_count and pending.len() from the tail
   event value, commit_seq, and event_seq without moving submit_seq. If a
   second job J2 is building concurrently against J1's tail, J2::commit()
   fails with "Job::commit() out of order" (EINVAL); if J2 is already
   committed, J2::submit() fails with submit_seq != cmd_seq.
2. Drop for JobSubmission rolled back the same tail counters and set
   inner.last_submitted = Some(val) to the rolled-back tail value, which
   corrupts free_slots() when earlier work is in flight or later jobs are
   already committed.
3. QueueJob::run() took each subqueue job one by one before calling
   submit()?, so an early error dropped only the taken subqueues while
   leaving later subqueues to drop asynchronously in QueueJob::drop()
   (which drm_sched cannot invoke until earlier pending jobs complete).

Legacy firmware stamps only require strictly monotonic 0x100-aligned
values per event slot, not contiguous increments. Keep tail_value,
commit_seq, and event_seq monotonic once a job commits:

- Encapsulate queue sequence and stamp ordering in WorkQueueOrder, remove
  EventValue::sub(), and update last_submitted and published_event_seq
  only in JobSubmission::run() when commands are actually published.
- On committed pre-publication abort in Job::drop() and
  JobSubmission::drop(), advance submit_seq past the aborted commands
  without rolling back tail counters or overwriting last_submitted. Keep
  tail-only uncommit() for partial QueueJob::commit() failure under the
  queue lock.
- Have WorkQueue::event_info() return the live wait target (the latest
  committed tail when submit_seq < commit_seq, otherwise the last
  published work while pending is non-empty, else None) so new barriers
  skip already-aborted jobs instead of livelocking.
- Track cross-submission explicit barrier waits (wait_frag_seq and
  wait_comp_seq) in QueueJob and cancel with ECANCELED in run() if the
  waited-on event_seq was never published, preventing firmware barrier
  hangs on stamps that will never be written.
- Take all subqueue jobs upfront in QueueJob::run() and call
  abort_subqueues() synchronously on every pre-publication error path.
- Latch tvb_init_pending immediately after buffer.new_scene() when
  scene.rebind() is true and propagate scene.rebind() || init_slot out
  of submit_render() so neither a mid-submit_render() error nor a
  pre-publication abort can lose a rebind InitBuffer requirement.

Add KUnit tests in workqueue.rs and a host test harness with negative-
control mutations in tools/asahi/legacy-wq-prepub-abort-tests.py.

Closes: aurora-silicon#2546
Signed-off-by: AxxzyWasTaken <[email protected]>
@AxxzyWasTaken
AxxzyWasTaken force-pushed the pr/asahi-wq-prepub-abort branch from f6a5d7a to ac06a53 Compare November 28, 2026 15:10
@AxxzyWasTaken

Copy link
Copy Markdown
Contributor Author

Rebased onto main (a81a12c7de36) at ac06a53503ca to resolve the 1-line mod tests import conflict in drivers/gpu/drm/asahi/workqueue.rs after #2886 (ring_reaches_done).

  • Functional logic is unchanged from f6a5d7a1183d (which passed the J473 batch row above); drm/asahi: legacy: bound attachment payloads and firmware-supplied queue and slot indices #2886's doneptr Err(EIO) refusal check in Job::submit() is preserved verbatim and unwinds through Job::drop() -> abort_committed().
  • Verified at ac06a53503ca: tools/asahi/run-host-tests.py --only legacy-wq-prepub-abort passes 10/10 (baseline + all 9 negative-control mutations killed), ARM64 cross-compile of drivers/gpu/drm/asahi/asahi_core.o (CONFIG_KUNIT=y) passes with 0 warnings in touched files, git diff --check clean, checkpatch.pl --strict 0 errors / 0 code warnings.

Thanks for the J473 batch row! Ready for CI and re-check at ac06a53503ca.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MERGE at ac06a535 (wait for queued CI to finish green before merging)

Blockers: none in code (peer G13 / live abort hardware row noted in Not yet:).

Checked:

  • Verified rebase ac06a53503ca onto main (a81a12c7de36): resolves only the 1-line mod tests import conflict in drivers/gpu/drm/asahi/workqueue.rs after #2886 (ring_reaches_done), preserving #2886's doneptr Err(EIO) check verbatim and introducing zero functional changes relative to the previously approved f6a5d7a1183d head.
  • Verified exact-head offline checks at ac06a53503ca: tools/asahi/run-host-tests.py --only legacy-wq-prepub-abort 10/10 (baseline + all 9 negative-control mutations killed), arm64 LLVM=1 CONFIG_KUNIT=y build 0 warnings in touched files, checkpatch.pl --strict 0 errors.
  • Prior f6a5d7a1183d head (functionally identical) passed the J473 (M2 mini, G14G B0, fw 27.2) batch no-regression boot row.
Evidence
  • Risk: two-way · G13/G14/G14X Macs (M1, M2 family) present.
  • All 19 queued CI jobs (apple-build, host-tests, pr-text, KUnit suites) pending at ac06a535.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Tested ac06a53 on J473 (M2 mini, G14G B0, fw 27.2): PASS. This refreshes the row at your new head.

The G13 (J316s) row for this PR, #3250 and #3238 comes next with the same kernel.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Tested ac06a53 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 ac06a535. 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 ac06a535. (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 465 min ago with no objection. Revert: git revert -m 1 <merge>.

@RyanTheTide
RyanTheTide merged commit 573c1eb into aurora-silicon:main Nov 29, 2026
20 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpu Area from CODEOWNERS (bot) blast: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: a job that fails in run() before publishing breaks its queue's event order

2 participants