Skip to content

drm/asahi: g17: let a refused submission leave its outputs untouched - #3700

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

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

Conversation

@jgoyvaerts

@jgoyvaerts jgoyvaerts commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

What: A refused G17 SUBMIT now changes nothing. ENOMEM (no memory) or ENOSPC (no GPU capacity) means no command was queued and no output sync object changed, so Borealis can return VK_ERROR_OUT_OF_HOST_MEMORY / OUT_OF_DEVICE_MEMORY instead of losing the device. Today every G17 SUBMIT failure installs a failed fence on the outputs, which Vulkan's rule for a failed vkQueueSubmit forbids. DRM_ASAHI_FEATURE_SUBMIT_REFUSAL_UNTOUCHED (bit 48) reports the contract. drm_asahi_submit::flags stays MBZ.
Tested: no Mac at this head yet. KUnit (arm64 qemu) at e382bd2: 949 passed, 1 skipped, 0 failed. Host tests at e382bd2: g17-submit-refusal-untouched-tests and its 5 mutations pass, as do g17-chunk-work-guard and g17-compute-multi-channel-feature with their mutations. The 29 remaining failures also fail on main (sep-suspend-errors, g15-*, apple-dcp, test-m3-uapi).
Risk: one-way door (uAPI: a new feature bit and changed refusal semantics) · M4 and M5 (G17).

  • Old userspace loses its device on any SUBMIT error either way. Borealis and Gallium already handle an output that never gets a fence (agx_batch.c agx_wait_failed_submit, hk_cmd_pool.c hk_cmd_pending_poll, bounded query waits, device destroy waiting only up to LAST_SUBMITTED).
  • The one change: a waiter already blocked on a refused submission's output point, in another thread or process, is no longer woken with an error fence. It waits until its own timeout, as on msm, panthor and xe.
    Not yet:
  • Hardware: a boot of a kernel carrying this (m4.215 has the earlier opt-in form) with Borealis keyed on bit 48 (mesa wifi: apple: centauri: serialize sibling acquisition with probing #1421), and a kernel-side injected refusal.
  • Coverage: only failures before the aggregate fence is published are refusals here. drm/asahi: g17: install a submission's outputs only once it is queued #3701 extends that to the first command's preparation. The per-queue firmware objects built at publication move to QUEUE_CREATE/SUBMIT in follow-ups.
Details

The contract (bit 48 present):

SUBMIT returns Queued Outputs
0 the submission its fence
ENOMEM, ENOSPC nothing unchanged: no allocation_failure, no fallback, no cumulative-signal chain
EIO possibly part of it a failed fence; this includes an ENOMEM/ENOSPC raised after the aggregate fence was published
any other errno (EINVAL, E2BIG, ENOENT, EFAULT, ...) nothing as today: a failed fence, except a malformed input/output split, which installs none

EAGAIN is not a capacity answer here, because libdrm's drmIoctl retries it in a loop. ERESTARTSYS restarts as before.

Earlier draft: this PR was first an opt-in submit flag plus bit 48. The flag only preserved the error wake-up of blocked waiters for old Mesa, so it was dropped in favour of the standard always-on shape.

What is a refusal at this head: everything before Outputs::publish*:

  • the fallback fence (Outputs::new);
  • command parsing, validation and VM pins (prepare_submission);
  • the frontier and publisher reservation;
  • work-state leases and chunks.

The enqueue loop runs after the aggregate fence is published, so its failures return EIO: Completion (including the compute timestamp page), the dependency vectors, Packet and the drm_sched job. #3701 moves the publish point after that loop.

Plumbing: fence::untouched_refusal(published, result) decides; fence::submit_result(published, result) maps a late ENOMEM/ENOSPC to EIO. They are used in Outputs::new, Outputs' drop and G17's submit.

Evidence
  • KUnit asahi_g17_aggregate_promise: a_refusal_before_publication_leaves_the_outputs_untouched, enomem_and_enospc_after_publication_become_eio.
  • tools/asahi/g17-submit-refusal-untouched-tests.py fails on main (the code is absent) and passes at head. Its mutations new-installs, drop-installs, no-errno-map, flags-accepted and not-reported are each caught.
  • The userspace review behind the bit-only shape (Mesa m4/next b54448cf7, aurora-wip 89ddabbf7, virglrenderer ca50e00) found no path that depends on a failed SUBMIT fencing its outputs. virglrenderer's asahi native context destroys its out syncobj on a SUBMIT error without waiting on it (asahi_renderer.c:758-800). Upstream Mesa knows only G13/G14.

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>
@jgoyvaerts
jgoyvaerts force-pushed the m4pro/g17-submit-errno branch from 6bcc79e to e382bd2 Compare November 30, 2026 18:59
Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr

Copy link
Copy Markdown
Contributor

J700 (Neo, G17P) boot row at head b6ead1c5

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

Results

  • GET_PARAMS: bit 48 (SUBMIT_REFUSAL_UNTOUCHED) 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, compared case for case with the same Image running the drm/asahi: g17: keep G17P render queue records firmware-cached #3705 module:
    • sync2 op.multi_queue: 16,680 Pass / 7,080 NotSupported / 0 Fail
    • sync op.multi_queue: 12,798 Pass / 9 NotSupported / 0 Fail
    • identical results, 0 recoveries
  • Health: 0 WARN, 0 GPU faults, 0 AVC, 0 failed units. The only flagged boot line is "aurora: loading out-of-tree module taints kernel". It comes from building the module with M=, not from the driver.

Not run: the refusal contract itself. This kernel has no way to make SUBMIT genuinely refuse with ENOMEM or ENOSPC before publication. The J700 config has no fault injection (no FAILSLAB, FAIL_FUNCTION or BPF override), and before #3704, G17P submit allocations are not charged to the memory cgroup. The sentinel-output, same-recording retry and refusal-after-accepted-batch rows still need a test kernel with an injection point, plus Mesa #1421 on it.

@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 b6ead1c. A cumulative-scope allocation refusal preserves ENOMEM and the output syncobjs. The ioctl return trace carries no private fence. The 297 driver checks passed. The always-on bit-48 refusal and same-queue retry still need a hardware row.

@DjDeveloperr

Copy link
Copy Markdown
Contributor

Fixed the errno and trace for an unpublished cumulative-scope allocation refusal in b6ead1c.

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