Skip to content

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

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

jgoyvaerts wants to merge 6 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. KUnit (arm64 qemu) 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 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.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants