Skip to content

drm/asahi: g17: install a submission's outputs only once it is queued - #3701

Open
jgoyvaerts wants to merge 9 commits into
aurora-silicon:mainfrom
jgoyvaerts:m4pro/g17-submit-errno-enqueue
Open

jgoyvaerts wants to merge 9 commits into
aurora-silicon:mainfrom
jgoyvaerts:m4pro/g17-submit-errno-enqueue

Conversation

@jgoyvaerts

@jgoyvaerts jgoyvaerts commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

What: Stacked on #3700; review only the top commit "drm/asahi: g17: install a submission's outputs only once it is queued". A G17 SUBMIT now stores its fence in the output sync objects after it has queued its commands, not before. A refusal (ENOMEM/ENOSPC) while preparing the first command then leaves the outputs untouched (#3700's contract, bit 48), so Borealis reports out of memory instead of losing the device. Every refusal of a one-command submission is covered.
Tested: no Mac at this head yet. At 4bdf454 (#3700 at 133672c merged, which carries main 9b8e29f): KUnit (arm64 qemu) 1059 passed, 1 skipped, 0 failed. Full host run at 2d39b84bace9 (the same code but for one KUnit test line): every g17 test and mutation passes. The other failures of the full host run are local toolchain gaps in tests this PR does not touch (rustup 1.93.1 missing for g15-*, a __stack_chk_guard link error in sep-suspend-errors and asahi-m4's test-stream-gate); they fail the same way in all three merged trees. Earlier, KUnit at 1b3f06b: 949 passed, 1 skipped, 0 failed; without CONFIG_DRM_ASAHI_G16 (the m4 kernel config): 946 passed, 4 skipped, no dead-code warning. Host tests at 95bb3cf (the same code but for one cfg attribute): g17-submit-refusal-untouched-tests and its 8 mutations (3 new) pass; the 29 remaining failures of the full run also fail on main.
Risk: two-way door · M4 and M5 (G17), plus G16's cumulative signals (same allocation, now in two calls). On every failure other than a refusal, the outputs end as before.
Not yet:

  • Hardware: Borealis keyed on bit 48 (mesa wifi: apple: centauri: serialize sibling acquisition with probing #1421) with an injected ENOMEM on a command's completion allocation, on a kernel carrying this.
  • Later commands: a refusal of a later command of the same ioctl still returns EIO, because earlier commands are queued.
  • Publication: per-queue firmware objects built at publication come in the next step.
Details

Before: Outputs::publish* created the aggregate fence and stored it in every output at once, before the enqueue loop. Every failure in the loop came after the outputs changed, so under #3700's contract it was EIO. The loop allocates each command's Completion (the compute timestamp page among it), dependency vectors, Packet and drm_sched job.

After:

  • publish* creates the aggregate fence and prepares the cumulative signal (asahi_g17_signals_prepare(): allocates the scope, stores nothing).
  • Outputs::install() (asahi_g17_signals_commit(), or drm_syncobj_* for plain outputs) stores it. It cannot fail.
  • G17's submit installs after the loop, unless untouched_refusal(any command queued, result). Outputs' drop still installs on every other path, so the end state of every non-refusal is unchanged.
  • "Queued" means the command's scheduler job is armed. The two push_within_capacity calls after arming fill room reserved before the first command, and now return EIO if they ever fail, so a refusal never follows a queued command.

Ordering: early publication can complete a command before the outputs carry the fence; they then get an already-signalled fence. The cumulative scope is still taken over the anchor's current fence before the loop, and the queue's lock is held throughout. WAIT_FOR_SUBMIT waiters on an output point wake after the loop instead of before it.

G16: SignalBundle::publish() stays, as prepare plus commit, built only with CONFIG_DRM_ASAHI_G16: G17 no longer calls it.

Evidence

tools/asahi/g17-submit-refusal-untouched-tests.py adds three checks:

  • creating the submission stores nothing;
  • the outputs are installed after the loop, gated on queued commands;
  • post-queue failures are EIO.

The new mutations install-early, ignore-queued and queued-enomem are each caught. The three checks fail on #3700's head, which installs at creation.

A G17 SUBMIT that fails installs a failed fence on every output sync
object: the queue's allocation_failure fence if the ioctl fails before it
publishes its aggregate fence, the aggregate fence carrying the error
after that. So when userspace gets ENOMEM, the outputs have already
signalled, and the timeline points it asked for exist, failed.
- **Vulkan:** a failed vkQueueSubmit must leave every semaphore and
  resource unaffected. Borealis can therefore only treat any SUBMIT
  failure as a lost device, even a plain lack of memory.
- **The DRM convention:** an ioctl that fails changes nothing (msm,
  panthor, xe).

Make a refusal change nothing:
- **The contract:** ENOMEM (no memory) and ENOSPC (no GPU capacity) from
  SUBMIT mean the ioctl queued no command and changed no output: no
  allocation_failure, no fallback fence, no cumulative-signal chain.
  Userspace may report the error (VK_ERROR_OUT_OF_HOST_MEMORY,
  VK_ERROR_OUT_OF_DEVICE_MEMORY) and submit again.
- **Late failures:** after the aggregate fence is published to the
  outputs, the same failures are returned as EIO, and the outputs carry
  them, so ENOMEM and ENOSPC never mean "something changed".
- **Other errnos:** they leave a failed fence on the outputs as before,
  except a malformed input/output split, which still installs none.
- **Discovery:** `DRM_ASAHI_FEATURE_SUBMIT_REFUSAL_UNTOUCHED` (bit 48)
  reports the contract. drm_asahi_submit::flags stays MBZ.

What old userspace sees: it loses its device on any SUBMIT errno either
way, and its own waits already handle an output without a fence. The one
difference is a waiter blocked on a refused submission's output point,
in another thread or process. It is no longer woken with an error fence;
it waits until its own timeout, as on msm, panthor and xe.

What is a refusal today is everything before the aggregate fence is
published: the fallback fence, command parsing and validation, VM pins,
the frontier reservation, work-state leases and chunks. The per-command
allocations of the enqueue loop still follow publication, so they fail
as EIO. Moving them before it, and building per-queue firmware objects
at QUEUE_CREATE or SUBMIT instead of at publication, comes next.

Tests:
- **KUnit:** the refusal decision and the errno mapping.
- **Host test** (g17-submit-refusal-untouched-tests.py) checks the wiring:
  - Outputs::new, Outputs' drop and submit consult the decision;
  - flags stays MBZ;
  - only G17 reports the feature.

  Five injected faults are caught.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
A G17 SUBMIT stores its aggregate fence in the output sync objects when it
creates it, before the loop that queues its commands. Every failure of
that loop therefore comes after the outputs changed. Under
DRM_ASAHI_FEATURE_SUBMIT_REFUSAL_UNTOUCHED, those failures cannot be
refusals (ENOMEM, ENOSPC), and they become EIO. The loop allocates each
command's completion state, including the compute timestamp page, its
dependency vectors, its packet and its scheduler job. A lack of memory
there cost the client its device.

Install the outputs after the loop instead:
- **Creating the submission** builds the aggregate fence and allocates
  the cumulative signal's scope (now `asahi_g17_signals_prepare()`), but
  stores nothing.
- **Outputs::install()** stores it in every output
  (`asahi_g17_signals_commit()`). It cannot fail.
- **When it runs:**
  - after the loop, unless the ioctl was refused before its first command
    was queued;
  - otherwise when the outputs are dropped, as before.
- **Queued means armed:** a command counts as queued once its scheduler
  job is armed. The two pushes after that, into room reserved before the
  first command, now return EIO if they ever fail, so ENOMEM never
  follows a queued command.

A refusal while preparing the first command now leaves the outputs
untouched too. This covers every refusal of a one-command submission. A
refusal of a later command still returns EIO, because earlier commands of
the same ioctl are already queued.

Early publication can now complete a command before its outputs carry
the fence. They then get a fence that is already signalled. The cumulative
scope is still taken over the anchor's fence before the loop, under the
queue's lock.

G16 keeps `SignalBundle::publish()`, now prepare plus commit, built only
with CONFIG_DRM_ASAHI_G16 (G17 no longer calls it).

The host test g17-submit-refusal-untouched-tests.py also checks three
things: creating the submission stores nothing, the outputs are installed
after the loop and gated on queued commands, and post-queue failures are
EIO. Three more injected faults are caught.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
@jgoyvaerts
jgoyvaerts force-pushed the m4pro/g17-submit-errno-enqueue branch from 95bb3cf to 1b3f06b Compare November 30, 2026 21:13
Signed-off-by: DjDeveloperr <hey@djdev.me>
Signed-off-by: DjDeveloperr <hey@djdev.me>
Signed-off-by: DjDeveloperr <hey@djdev.me>
A first-command refusal leaves the prepared aggregate private. Emit the install event when the output syncobjs have actually been updated so a refused ioctl cannot report a transient installation.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr

Copy link
Copy Markdown
Contributor

J700 (Neo, G17P) boot row at head 6d560c76

Kernel: one trial boot (boot 042d7a16). Stock Fedora -41 was restored and verified afterwards.

Results

  • GET_PARAMS: bit 48 is set; features 0x0001397a6001fc07.
  • Normal submits all completed with correct output:
    • q4 render triangle, checked by per-queue CRC
    • compute.light d1/d16, checked by per-slot CRC
    • 4-queue render; 4-queue and 4-process compute
    • concurrent render + compute
    • cross-queue timeline and binary semaphores; host signal
    • queue create/use/close/reuse (CRC ok); mem.buffer
  • Multi-queue CTS:
  • Health: 0 WARN, 0 GPU faults, 0 AVC, 0 failed units. The only flagged boot line is the out-of-tree taint from the M= module build.

Not run: the same refusal rows as on #3700: first-command refusal without a phase-1 install, same-queue retry, and the installed fence plus terminal error after partial acceptance. There is no genuine refusal path on this kernel, so they need an injection test kernel and Mesa #1421.

DjDeveloperr
DjDeveloperr previously approved these changes Dec 1, 2026

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

Reviewed 6d560c7. The corrected #3700 is in the branch. Abandoning a prepared scope releases both child references while its prior anchor is pending. The follow-up moves the install trace past enqueue, so a first-command refusal emits no installation event. The regression check caught the old ordering, and all 300 driver checks passed. G17 refusal/retry and G16 cumulative signals still need hardware rows.

Main's b01dc0e replaces Outputs::finish() with
Outputs::set_result() and leaves the outputs untouched for an
-ERESTARTSYS before publication. Conflict in g17/queue/mod.rs, resolved
as the union: the submission's result is first mapped by
submit_result() (a refusal after publication becomes EIO), then stored
with main's set_result(), so Outputs::drop() sees the result the ioctl
returns; the traced output fence stays None for an untouched refusal,
and main's output_fence() keeps it None for -ERESTARTSYS.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
…ueue

Brings in aurora-silicon#3700's merge of main (133672c) and with it main's
b01dc0e: Outputs::set_result() replaces Outputs::finish(), and an
-ERESTARTSYS before publication leaves the outputs untouched. No
conflicts. On this branch that -ERESTARTSYS comes before
Outputs::publish(), so no submission exists, Outputs::install() does
nothing and Outputs::drop() returns before the fallback is installed:
the outputs stay untouched as main requires.

Main's KUnit test full_window_signal_leaves_timeline_untouched_for_restart
publishes the restarted submission and expects its timeline point
installed. On this branch Outputs::publish_with() only prepares the
outputs and Queue::submit() installs them once a command is queued, so
the test now calls Outputs::install() after publishing, as submit does.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
@jgoyvaerts
jgoyvaerts marked this pull request as ready for review December 4, 2026 05:20
@jgoyvaerts
jgoyvaerts requested review from a team as code owners December 4, 2026 05:20
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:m4 Macs affected, from Merge risk (bot) blast:m5 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) labels Dec 4, 2026
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

Merge readiness at 4bdf4544: not ready yet

Check Detail
CI at head running running: 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 4bdf4544
Conflicts ok none
PR text ok Risk: two-way · M4 and M5 (G17), plus G16's cumulative signals (same allocation, now in two calls). On every failure other than a refusal, the outputs end as before.

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 commented Dec 4, 2026 •

Copy link
Copy Markdown

Merge readiness at 70614ee0: not ready yet

Check Detail
CI at head ok 9 checks passed
Review no needs one approving review from Core, Omarchy Mac or Aurora Maintainers (not the author)
Requested changes ok none
Hardware row at head no no line with the head SHA 70614ee0, a Mac and a result in the PR body or a comment
Conflicts no merge conflicts with main: merge it in (no force push)
PR text ok Risk: two-way · M4 and M5 (G17), plus G16's cumulative signals (same allocation, now in two calls). On every failure other than a refusal, the outputs end as before.

Areas: area:gpu

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

Keep main's shared input allocation before enqueue. The submit trace
still runs after the output sync objects have been installed.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@github-actions github-actions Bot added the needs-hw-row No hardware row at the PR head (bot) label Dec 4, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor

Forward-merged main be72f78e54d6 at 70614ee042ac. The merge keeps the shared-input allocation before enqueue and the submit trace after output sync-object installation.

The warm ARM64 make ARCH=arm64 LLVM=1 W=1 drivers/gpu/drm/asahi/ build linked aurora.o. The submit-refusal, command-input, and inline cross-engine host suites passed 20/20, including their mutation checks. The stack still depends on #3700. The hardware and userspace bit-48 checks are still due.

@github-actions github-actions Bot added the merge-conflict Conflicts with the base branch (bot) label Dec 4, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

@jgoyvaerts This branch now conflicts with main (1da341136110) in:

  • drivers/gpu/drm/asahi/g17/mod.rs
  • include/uapi/drm/asahi_drm.h
  • tools/asahi/run-host-tests.py

Could you forward-merge main into this branch (normal git merge, no rebase/force-push)? If you haven't had a chance within 24 hours, a maintainer can forward-merge main on top for you.

This branch has not been deployed

No deployments
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:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) merge-conflict Conflicts with the base branch (bot) needs-hw-row No hardware row at the PR head (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.

3 participants