Skip to content

drm/asahi: g17: set an output fence's error and signal it under its lock - #3311

Merged
RyanTheTide merged 4 commits into
mainfrom
fix/g17-cancel-signalled-fence-3278
Nov 29, 2026
Merged

RyanTheTide merged 4 commits into
mainfrom
fix/g17-cancel-signalled-fence-3278

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What: Set a submit's output fence error and signal the fence in one step, under the fence lock. If the fence has already signalled, keep that result. This fixes the dma_fence_set_error() WARN at include/linux/dma-fence.h:695 that fires when a queue with cancelled jobs is destroyed. Fixes #3278

Tested: Neo J700 at 27a5185, two one-shot boots of 7.3.0-neo-fix3278, both returned to stock -41. Results: 2,580 deqp-vk processes killed mid-run with live queues (51 outputs cancelled through member_done()), then a CTS smoke over the #3278 groups: 3,777 Pass, 1,060 NotSupported, 0 fail. 0 WARN/BUG, 0 GPU faults, 0 AVC. Host: the g17 host tests pass 224/224, the new test passes, and its three mutations all fail as they should.

Risk: two-way · G17P / M5 (shared g17 fence/completion path): Neo J700 and M5 J714s. The output-fence path is shared by every G17 submit. On main the result is the same as before, because member_done() is still the only thing that signals the fence. A revert restores the two-call version.

Not yet: the J714s row. It is the second-generation row for shared g17 code, and it is the only Mac that hits #3278. It needs a cdirect kernel rebased onto this change (see Evidence), then the #3278 CTS mix with 16 jobs, checking for no WARN.

Details

Who signals the fence first. Submission::member_done() used to call dma_fence_set_error() and then signal in a separate call. That only works if the last member is the only thing that ever signals the output fence. On main it is. The kernels that hit the WARN are 7.3.0-m5-cdirect14, cdirect15 and cdirect16, built from the local perf/m5-cdirect* branches. They carry g17/fast_signal.rs (947f9742a168, "bottom-half early completion signalling for M5 compute"). When the stamp of a submit's only remaining command lands, that bottom half signals the output fence. It checks remaining == 1, error == 0 and not signalled, and it neither completes the member nor claims the Completion. The command then waits for the event worker to retire it. If userspace destroys the queue in that window (deqp-vk does after each wait), drm_sched_fini() cancels the unretired job. Backend::cancel() then runs fail_while_owned(ECANCELED), which completes the last member, and member_done() sets an error on the signalled fence. That is the trace in #3278. The bottom half also checks the submission state under its own table lock but signals after dropping it. So a member failing at the same moment could also set the error after the signal.

Every copy of this WARN in the lab logs (43 log files, J714s rows from 11-24 to 11-26) is on cdirect14, cdirect15 or cdirect16. None is on a Neo, M4, M3 or pre-cdirect M5 kernel.

The ComputeReserve refusals before the WARN are capacity pressure from 16 parallel deqp-vk jobs. A refused compute command waits in admission unpublished, and a cancel completes it through fail_unpublished(). The WARN in #3278 comes through fail_while_owned(), which means a published command.

The change. The new helper asahi_g17_finish_fence(fence, error, scoped) in g17/sync_scope.c takes the fence lock and checks the signalled bit. If the fence is still unsignalled, it sets the error and calls dma_fence_signal_locked(). dma_fence_signal() takes that same lock to set the bit, so no signal can come between the check and the error. A fence that already signalled keeps the result its waiters saw. Here that is the success the bottom half witnessed, so the late ECANCELED of a completed command is dropped. Scoped outputs still drain their ready queue scopes. asahi_g17_signal_fence(), also used by g16, is now the same helper with no error. member_done() keeps its trace point, and it still releases the submission state on success and through the last owner on failure.

With this change the cdirect bottom half needs no extra claim. Its signal and member_done() now both decide under the fence lock.

Evidence
  • J700 rows (7.3.0-neo-fix3278, kit built from 27a5185 with the Neo -41 config, one-shot grub2-reboot, saved_entry left at -41). Each boot returned to -41 with the kit removed; /boot, ESP, /lib/modules, BLS, rpm list and grubenv are identical to before; stock.sh is the same at start and end; PMU boot-error count 00 throughout. Holds: 18:18–18:24 and 18:39–18:46 EST.
  • Host: python3 -I tools/asahi/run-host-tests.py --jobs 6 --only g17: 224/224 passed (CI host-tests, which runs every host test, passes too), including g17-output-fence-tests (1.4 s) and its --mutation unlocked-member-done, set-error-when-signalled and check-outside-lock runs. Each of those three panics (exit 101) on a counted dma_fence_set_error() WARN. The old member_done() and set-error-when-signalled fail on the drm/asahi: g17: dma_fence_set_error() on an already-signalled fence when a queue with cancelled jobs is destroyed (WARN dma-fence.h:695, J714s) #3278 sequence. check-outside-lock fails when the early signal lands just before the member takes the lock. In the two-thread race (9,409 rounds), the early signal wins about 7,400 times and the cancel about 2,000 times, with 0 WARNs. In every round the error waiters read equals the error at signal time.
  • Style: scripts/checkpatch.pl -g HEAD: 0 errors. The one warning is the usual MAINTAINERS note for a new tools/asahi file. rustfmt --check on g17/fence.rs shows the same four older diffs as main, none on changed lines.
  • Where the WARN shows up: rg "WARNING: include/linux/dma-fence.h:695" over the lab logs (work/) finds 43 files. Every one that names its kernel is 7.3.0-m5-cdirect14, cdirect15 or cdirect16, all J714s.
  • Carrying it to the cdirect kernels: the commit applies to b130c950a65c (perf/m5-cdirect15) with a 3-way merge. That branch's fence::signal_exported_raw() also calls asahi_g17_signal_fence, so keep that function's extern declaration there, or switch the call to asahi_g17_finish_fence(fence, 0, true).

Submission::member_done() sets the submit's output fence error with
dma_fence_set_error() and then signals the fence in a separate call.
That assumes the last member is the only thing that ever signals the
fence. When something else signals it first, the error lands on a fence
whose waiters already saw a result, and dma_fence_set_error() WARNs at
include/linux/dma-fence.h:695.

That is the WARN in linux#3278. The M5 perf kernels that hit it
(7.3.0-m5-cdirect14 to cdirect16) add an early completion path in a
bottom half. Once the stamp of a submit's only remaining command lands,
it signals the output fence before that command retires. If the queue
is destroyed in that window, drm_sched_fini() cancels the unretired job
and fail_while_owned(ECANCELED) completes the last member, so
member_done() sets an error on the signalled fence. The early signal
also checks the submission state and then signals without a lock, so
it can race a member that fails at the same time. On main, member_done()
is the only signaller. Every copy of this WARN in the lab logs comes
from those three kernels.

Do both steps in one pass under the fence lock, in a new
asahi_g17_finish_fence() helper. If the fence is still unsignalled, it
sets the error and signals. If it already signalled, it leaves the
result alone. The fence lock is the lock dma_fence_signal() itself
takes, so the error can no longer follow or race any signal. A scoped
output still drains its ready queue scopes. asahi_g17_signal_fence()
now calls the same helper with no error, so it behaves as before.

Add tools/asahi/g17-output-fence-tests.py. It compiles the real
Submission, Aggregate and Member code and the new helper against a
host dma_fence model that keeps the WARN. It replays the linux#3278
sequence: one command left, an early signal, then a cancel. It also
lands the early signal just before the member takes the lock, and runs
the two on separate threads. Three mutations must fail it: the old
member_done(), setting the error on a signalled fence, and testing the
signalled bit outside the lock.

Closes: #3278
Signed-off-by: DjDeveloperr <[email protected]>
@DjDeveloperr
DjDeveloperr marked this pull request as ready for review November 26, 2026 23:48
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 26, 2026 23:48
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Non-author review at 27a5185ee87d: READY. I found no code blockers. Before it merges it needs the J714s row the PR lists under Not yet, and green CI.

Checked

  • asahi_g17_finish_fence() / signal_with_error() in g17/sync_scope.c:
    • It takes dma_fence_lock_irqsave(), tests the signalled bit, sets the error only when the fence is still unsignalled, and calls dma_fence_signal_locked() under that same lock. It is wrapped in dma_fence_begin_signalling()/end_signalling().
    • Every signaller sets the signalled bit only under the fence lock, so no signal can land between the check and dma_fence_set_error().
    • An already-signalled fence keeps the result its waiters saw.
    • It is IRQ-safe (irqsave).
  • Lock order: no new nesting. member_done() already took the fence lock through the old signal call. Only set_error, which takes no lock, moved inside it. The scoped path still signals inside the per-CPU active_scopes section and drains ready scopes after the lock is released, as before.
  • Callers:
    • Submission::member_done() now goes through finish_exported(fence, error, fence.scoped) for both scoped and unscoped outputs. It no longer calls set_error or signal separately.
    • error comes from to_errno(), so it is negative, which is what dma_fence_set_error() requires. Success still releases the state there; a failure releases it through the last owner.
    • asahi_g17_signal_fence(), which g16 also uses, becomes the same helper with no error, so it behaves as before.
    • The early-signal path (g17/fast_signal.rs) exists only on the local perf/m5-cdirect* branches, not on main. With this change, its signal and member_done() both decide under the fence lock, which closes the window between its lock drop and the signal. The PR body's porting note for signal_exported_raw() covers the carry-over.
  • tools/asahi/g17-output-fence-tests.py: I ran it here against the head's fence.rs and sync_scope.c.
    • The base run passes: in the two-thread race the early signal won 7,513 rounds and the cancel 1,896, with 0 WARNs.
    • --mutation unlocked-member-done, set-error-when-signalled and check-outside-lock each exit 101, on the counted dma_fence_set_error() WARN.
    • All four runs are registered in run-host-tests.py.
  • checkpatch --strict: 0 errors and 0 checks. The one warning is the usual MAINTAINERS note for a new tools/asahi file.
  • PR body:

Not blocking: g17/completion.rs Output::publish() (around line 233) and the second site around line 575 still call set_error() and then signal() separately. That's safe while publish() is the only signaller of those completion fences. If an early path is ever added there, it should go through asahi_g17_finish_fence() too.

Before merge:

Merging is left to the PR Merge Lane.

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J714s (MacBook Pro 14" M5 Pro, G17S B1) second-generation row at exact head 27a5185ee87d: PASS. 0 WARN, 0 GPU faults.

  • Kernel: 7.3.0-m5-rows-k3311h, a warm native build on the M5 of this PR's head alone.
  • Boot: the default command line, headless. The default kernel (7.3.0-m5-cdirect16) was restored afterwards with a clean systemctl reboot, and all 253 ESP file hashes were verified.
  • Mesa: the system Mesa (aurora-m5 ICD).

1. Kill stress: 180 s with 12 workers.

  • Method: each worker ran deqp-vk on 400 random cases from the drm/asahi: g17: dma_fence_set_error() on an already-signalled fence when a queue with cancelled jobs is destroyed (WARN dma-fence.h:695, J714s) #3278 groups (without cooperative_matrix) and sent it SIGKILL 0.25–2 s in, so its queues were destroyed while they still held queued, waiting or running jobs.
  • Result: 1,911 deqp-vk processes were killed mid-run. A dEQP-VK.api.smoke.triangle health check passes before and after.
  • Kernel log for the stress window: 0 WARNING:/BUG:/Oops/Call trace, 0 dma-fence.h WARNs, 0 GPU MMU faults, 0 G17 recoveries, 0 firmware crashes and 0 capacity refusals. The only lines were the four apple-pmgr sync_state() pending lines every boot has, and no rescuer-kthread or ENOMEM lines.
  • Not measured: failed outputs were not counted. tracefs wasn't mounted on that boot, so the asahi_g17_output filter could not be armed. The number of -ECANCELED outputs is therefore unknown here; on the J700 it was 51 per 981 kills.

2. CTS mix at 16 jobs (deqp-runner, deqp-vk 1.4.7.1), straight after the stress:

3. Whole boot: 0 WARN/BUG/Oops, 0 GPU MMU faults and 0 G17 recoveries. There is one distinct error-level line (apple-dcp … DCP requested undeclared provider clock index), which the default boot also logs. Failed units: tailscaled.service only, the same as on the default boot.

Not run here: a cdirect kernel with this change merged in. That is the configuration that reproduces #3278 (the bottom-half early signal). It applies to b130c950a65c with a 3-way merge plus the signal_exported_raw() call change described above, but that branch differs from main's tree in about 1,000 files, which means a near-full rebuild. It can be run as a separate row if needed to close #3278.

@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:m5 Macs affected, from Merge risk (bot) blast:neo 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) labels Nov 27, 2026
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Merge readiness at cc26f9ee: not ready yet

Check Detail
CI at head running running: KUnit isp, KUnit jpeg, KUnit prores, KUnit scaler, KUnit macsmc, KUnit clpc
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 cc26f9ee
Conflicts ok none
PR text ok Risk: two-way · G17P / M5 (shared g17 fence/completion path): Neo J700 and M5 J714s. The output-fence path is shared by every G17 submit. On main the result is the same as before, because memberdone() is still the only thing that signals the fence. A revert restores the two-call version.

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 the merge-conflict Conflicts with the base branch (bot) label Nov 27, 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.

Code approved at the reviewed head. The shared helper checks signal state, sets the error and signals under the same DMA-fence lock. Scoped completion callbacks still drain after that lock is released. The reported J700 cancellation stress supports the change. Keep current-head CI and the J714s cdirect cancellation row as merge gates.

@RyanTheTide

Copy link
Copy Markdown
Contributor

code-owner ping @DjDeveloperr: closeout merge of your PR at e34ff145. App approved at this head, CI 21/21 green. The J714s row at 27a5185e still holds: the head only adds a main merge (git cherry: one own commit, unchanged). The J700 stress row is on the PR. Merging under the 6-point rule 1 h from now unless you say hold.

@github-actions github-actions Bot added merge-conflict Conflicts with the base branch (bot) and removed needs-hw-row No hardware row at the PR head (bot) labels Nov 29, 2026
Forward-merge main. Only the run-host-tests.py registry conflicted:
main extended the g17-object-fence-tests mutation list, this branch
registers g17-output-fence-tests after it. Keep main's list and add
the new entry.

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

Copy link
Copy Markdown
Contributor

Forward-merged main into this branch (merge commit 07b335c, no force push). Only the tools/asahi/run-host-tests.py registry conflicted: main extended the g17-object-fence-tests mutation list, and this branch adds the g17-output-fence-tests entry after it. The merge keeps main's list and adds your entry. Driver files (fence.rs, sync_scope.c/.h) merged cleanly and are unchanged.
Tests: run-host-tests.py --only g17 passed 262 jobs, including g17-output-fence-tests and its unlocked-member-done/set-error-when-signalled/check-outside-lock mutations, and all object-fence mutations. Only g17-compute-owed-stamp-tests failed, and it fails on main too (a stale note_retired() stub).
Still needed: CI and App re-review at the merge head. Rows carry over because no driver code changed. Thanks @DjDeveloperr.

@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 07b335c

Checked: The registry resolution keeps the object-fence mutation cases and adds the separate output-fence entry. Fence error and signaling still share the lock, with callbacks drained outside it. Keep exact CI and J714s cdirect cancellation.

@RyanTheTide

Copy link
Copy Markdown
Contributor

code-owner ping @DjDeveloperr: closeout merge at 07b335c2. The App approved at this head after the closeout forward-merge/fix. Rows: J714s at 27a5185 + J700 stress; registry-only conflict. Merging under the 6-point rule 1 h from now, once hosted CI at this head and main CI are green, unless you object.

@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) and removed merge-conflict Conflicts with the base branch (bot) labels Nov 29, 2026
@erikwb

erikwb commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

J716c (16-inch M5 Max, G17C) at cc26f9ee: boots; Vulkan synchronization and compute CTS at 4 jobs pass with no WARN and no GPU faults. The 16-job mix could not be run: it hangs this Mac with or without this PR (#3621).

Evidence

Batched kernel 7.3.0-ewb368+ = main 219311530ef0 + #3605 222e0e6b + #3311 cc26f9ee + #3310 5fb10c0a + #3458 625fd0f1 + #3459 af388dc6 + #3460 f8442a49, each head merged unchanged. The J716c DTB is built without #include "t6050-media.dtsi" (main hangs the J716c at boot otherwise, #3618). One-shot trial boot on the default command line plus watchdog.open_timeout=120 (recovery watchdog for test boots only); compared with the default 7.3.0-ewb342+ on the same Mac, dock and network.

Vulkan CTS with Borealis aurora-wip 437b0b52151, 4 jobs: synchronization list (5354 cases) 4496 pass, 93 flaky, 0 fail; compute sample 490 pass, 760 skip; 0 kernel log lines during the runs, 0 WARN/BUG/Oops. At 16 jobs the machine hangs, and plain main without these PRs hangs the same way (#3621), so that is not from this change.

0 DART faults. Kernel errors are the same set as the default boot; failed units: aurora-peripherals.service only, same as the default boot.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging under the 6-point rule (Ryan 09:29, permanent), at cc26f9ee. (1) The review App approved at this head. (2) Full CI is green. (3/4) Rows: J714s-at-27a5185e-+-J700-stress;-registry-only-conflict. (5) There's no blocking review. (6) Dj was pinged here 653 min ago with no objection. Revert: git revert -m 1 <merge>.

@RyanTheTide
RyanTheTide merged commit de965eb into main Nov 29, 2026
23 checks passed
@RyanTheTide
RyanTheTide deleted the fix/g17-cancel-signalled-fence-3278 branch November 29, 2026 17:01
@satchlj

satchlj commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

tools/asahi/g17-output-fence-tests.py from this PR fails at main de965eb5b26b before it runs anything. drivers/gpu/drm/asahi/g17/fence.rs now has two fn member_done( (lines 397 and 450: member_done(&self, fence: &UserFence<ExportFence>, result: Result) and member_done(&self, result: Result)), and the test's item() extractor asserts exactly one match:

AssertionError: '    fn member_done(': 2 matches

I reproduced this locally on a merge of main; main's own host-tests run (46287227020) is still queued. A longer signature in the extractor call would pick the intended one. linux#3389 carries the same fence.rs, so its host-tests will show this failure until main is fixed.

RyanTheTide added a commit that referenced this pull request Nov 30, 2026
Main (#3330, granular work-state retire) added a multi-command path
that splits an ioctl into chunked work-state leases and publishes them
with Outputs::publish_with_status(), next to the single-command
Outputs::publish(). This branch makes publish() take a lease created
by the caller, so the interruptible order-window wait happens before
any output is published.

Kept both: the multi-command path is main's unchanged (its first
WorkStateLease::deferred() now waits interruptibly too, before
publication); the single-command path creates its lease before
publish() as this branch does. note_render() runs just before either
publication, after any wait. Outputs keeps main's publish_source()
split with this branch's publish_with(Option<lease>) on top.

tools/asahi/g17-output-fence-tests.py (main, #3311/#3648) extracts
impl Submission and expected one Arc::new() there, the one in
Submission::new(), which this branch removes; it now expects none.

Signed-off-by: Ryan Murray <[email protected]>
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:m5 Macs affected, from Merge risk (bot) blast:neo 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.

drm/asahi: g17: dma_fence_set_error() on an already-signalled fence when a queue with cancelled jobs is destroyed (WARN dma-fence.h:695, J714s)

4 participants