Skip to content

drm/asahi: legacy: bound attachment payloads and firmware-supplied queue and slot indices - #2886

Merged
RyanTheTide merged 5 commits into
mainfrom
pr/asahi-legacy-fw-index
Nov 28, 2026
Merged

RyanTheTide merged 5 commits into
mainfrom
pr/asahi-legacy-fw-index

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Three places on the G13/G14 path trust a length or an index more than they should:

  • The submit ioctl walks the command buffer twice. The first pass skips a SET_*_ATTACHMENTS payload by its declared size; the second parses size / sizeof(drm_asahi_attachment) records and leaves any remainder unread, so the two passes can disagree about where the next command header starts, and the command counts from the first pass no longer describe what the second submits.
  • workqueue::Job::submit() asserts that the done pointer the firmware writes into the queue info is not the next slot it fills. A value that disagrees with the driver's own count of pending commands panics the kernel.
  • The event channel indexes the event and buffer owner tables with slot numbers taken from firmware messages. An out-of-range value panics the event thread on the Rust bounds check.

Change

  • queue: require whole records in attachment payloads: an attachment payload must be a multiple of the record size, checked in both passes, so both advance by the declared size.
  • workqueue: refuse a job when the firmware done pointer is in its slots: check the slots the job will use before taking any and fail the submission with EIO; the existing rollback handles a failed submit().
  • event: treat out-of-range firmware slot numbers as empty: owner lookups use get(); an out-of-range slot is reported like an empty one by the existing callers.

No change for well-formed userspace (Mesa sends whole records) or a firmware whose pointers agree with the driver.

Testing

  • KUnit (arm64, 16K pages, QEMU, drivers/gpu/drm/asahi/.kunitconfig), integration/aurora 110861f plus this branch and the G17 watchdog change submitted alongside it: Ran 374 tests: passed: 372, skipped: 2, no new warnings in the touched files.
  • New KUnit cases: attachment_payload_must_hold_whole_records, attachment_parse_consumes_the_declared_size, done_pointer_inside_the_new_entries_is_refused, firmware_slot_outside_the_table_has_no_owner.
  • Host tests: compute-preempt-tests 2/2, asahi-m4 1/1.
  • checkpatch.pl: no warnings.
  • Hardware: not yet: one-shot boot on a G13 and a G14 Mac (M1 Pro, M2) with a GPU smoke (dEQP-VK smoke list, GL) on the default command line.

Still to run

  • Hardware rows on M1 Pro and M2 (one-shot test kernel = fleet kernel plus these commits, default command line): GPU smoke, s2idle, kernel log clean.
  • KUnit of the new cases against the old code (each new case fails there: a remainder accepted, a panic on the done pointer and on an out-of-range slot).

The legacy submit path walks the command buffer twice. The first pass
counts commands and skips every non-command payload by its declared
size; the second pass parses SET_*_ATTACHMENTS payloads as size / STRIDE
records and leaves any remainder unread. A payload that is not a
multiple of the record size therefore makes the second pass read the
remainder as the next command header, so the command counts taken in
the first pass (submission limit, notification count, last-command
stamps) no longer describe what is submitted.

Refuse an attachment payload that does not hold whole records, in both
passes, so both advance by the declared size.

Signed-off-by: Ryan Murray <[email protected]>
…in its slots

Job::submit() asserts that the done pointer read from the firmware's
queue info is not the next slot it is about to fill. The value is
written by the firmware, so a pointer that disagrees with the driver's
own count of pending commands panics the kernel in the submit path.

Check the slots the job will use before taking any of them and fail the
submission with EIO instead. The existing rollback handles a failed
submit().

Signed-off-by: Ryan Murray <[email protected]>
The event channel hands slot numbers from firmware messages (timeout,
channel error, TVB grow) straight to the event and buffer managers,
which index their owner tables with them. An out-of-range value hits
the Rust bounds check and panics the event thread.

Look owners up with get() and handle an out-of-range slot like an empty
one, which every caller already reports as an error.

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

Copy link
Copy Markdown
Contributor Author

Review at 70a4f3b.

The three fixes are correct as far as they go: the attachment check matches what Mesa sends, the done-pointer check is the old assert's condition turned into EIO, and the event slot lookups no longer panic. Points to address:

  1. workqueue.rs:563-576: when the done pointer really disagrees, every later submit on that workqueue hits the same check, so each ioctl logs an unratelimited pr_err! and gets EIO. Nothing marks the queue or GPU as failed or starts recovery. Please ratelimit it (or log once per workqueue) and say whether the queue should be killed. A doneptr >= inner.size value never matches in ring_reaches_done() (workqueue.rs:1209) and passes silently, though it is just as inconsistent. Refusing it here costs one compare.
  2. The title says "firmware-supplied queue and slot indices", but channel.rs:101-107 still trusts the firmware RX wptr. A value >= count is never equal to the driver's rptr, so get() keeps returning stale ring entries and the event thread replays old messages forever (no OOB access, but a livelock). Please bound it here or narrow the title and commit text.
  3. event.rs:212-218: the commit says an out-of-range slot is "reported like an empty one ... as an error", but signal() reports an empty slot only through mod_pr_debug!. Flag bits can't go out of range ([u32; 4] = 128 = NUM_EVENTS), so this is a wording fix only.
  4. Rows: this path is G13, G14G and G14X, built as separate managers at fw 12.3 and 13.5 (driver.rs:393-406). The planned rows cover M1 Pro and M2 only. An M2 Pro/Max (G14X) boot plus GPU smoke is missing. On G13/G14 only GL (gallium agx_batch.c) sends SET_*_ATTACHMENTS (Borealis skips them there), so the smoke has to include GL FBO rendering, not just dEQP-VK. The "new KUnit cases fail on the old code" run is also still open.

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

Formal §1–§6 review at 70a4f3be8166.

Commit 1 (queue/mod.rs: attachment_count() enforcing whole records in both passes) and commit 3 (event.rs/buffer.rs: bounds-checked slot_owner() lookups via .get()) are clean and close real bounds/desync issues. §1 (no model gating), §4 (human commits + Signed-off-by, clean-room, PR Assisted-by), and §6 (naming) pass, and host-tests is green.

Items to address before merge:

  1. Blocker — Corrupt out-of-range doneptr >= inner.size is accepted silently (workqueue.rs:563-576, 1209-1224):
    • In ring_reaches_done(), wptr = (wptr + 1) % size is always < size, so any firmware-corrupted doneptr >= inner.size (even explicitly asserted as !ring_reaches_done(..., 8) and !ring_reaches_done(..., u32::MAX) in the new KUnit test) passes the check and proceeds to submit. Please refuse doneptr >= inner.size with EIO right alongside the in-range collision check.
  2. Unratelimited pr_err! on repeated submits (workqueue.rs:568-575):
    • Once doneptr disagrees, every subsequent submit ioctl hits pr_err! without ratelimiting or marking the queue lost. Please ratelimit the log (or log once per workqueue).
  3. Scope vs. channel.rs:101-107 RX wptr:
    • The PR title covers firmware-supplied queue and slot indices, but RxChannel::get_or_peek() still accepts wptr >= self.count without bounds checking, causing an infinite replay livelock on a corrupt RX write pointer. Please either bound RX wptr here or narrow the PR title/description.
  4. Blocker — §5 hardware evidence & negative-control KUnit missing:
    • No hardware runs yet on the affected G13 / G14G / G14X generations (M1 Pro, M2, M2 Pro/Max) on the default command line with regression counts (0 AVC, 0 failed units, 0 new kernel errors). Because SET_*_ATTACHMENTS on G13/G14 is exercised by GL rather than Borealis, the smoke needs to cover GL FBO rendering in addition to dEQP-VK.
    • Please also complete the listed base-commit negative-control KUnit verification.

Minor wording note: commit 3 states every caller reports an empty slot as an error, whereas EventManager::signal() logs via mod_pr_debug!.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Test evidence at 70a4f3b (adds to the review above, doesn't change its points).

The four new KUnit case bodies, extracted verbatim together with the helpers they exercise and built with host rustc: 4/4 pass at this head, 4/4 fail with the new checks reverted. A host model of the two submit passes shows that with the change both passes agree on the command walk for every accepted stream (before, they could disagree). Whole-record attachment sizes are accepted exactly as before. The ring check refuses no consistent queue state, so it matches the old assert's condition. An arm64 KUnit run under QEMU is still open.

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Independent source review at 70a4f3be8166. The legacy parser makes attachment lengths and firmware queue indices explicit. Please exercise an affected G14 render workload that submits attachments on the default J413 kernel and verify rendering after s2idle. The compute-only J473 branch does not exercise the legacy render path.

@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) changes-requested A reviewer requested changes (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merge readiness at 79b63175: not ready yet

Check Detail
CI at head ok 19 checks passed
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes no requested by DjDeveloperr
Hardware row at head ok comment at 79b63175
Conflicts ok none
PR text adopt when you next edit add a 'Tested:' line; a 'Risk:' line (door and Macs) (guide)

Areas: area:gpu

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

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

Verdict: FINISH, then merge at 70a4f3be8166

Blockers:

  1. drivers/gpu/drm/asahi/workqueue.rs:563-576: ring_reaches_done() wraps wptr with % size, so a firmware doneptr >= inner.size never matches and the submit goes ahead. The new KUnit cases even expect !ring_reaches_done(…, 8) and (…, u32::MAX). Fix: refuse doneptr >= inner.size with EIO next to the in-range check.
  2. Missing rows: this queue code runs on both G13 and G14, so at this head it needs one M1-family Mac and one M2-family Mac, each with GL FBO rendering (G13/G14 attachments are used by GL) and a dEQP-VK smoke run.

Checked: no Apple material, no gates. Attachment payloads and queue and slot indices are bounded, and the KUnit cases fail with the checks reverted. Nits: rate-limit the pr_err! at :568-575; RxChannel::get_or_peek() (channel.rs:101-107) still trusts the RX wptr, so bound it here or narrow the title.

@DjDeveloperr
DjDeveloperr dismissed their stale review November 24, 2026 23:29

Superseded by the review at 70a4f3b

…ite pointer

Review follow-up.

WorkQueue::submit() checked the firmware done pointer only against the
slots the job is about to fill. ring_reaches_done() wraps the write
pointer with % size, so a done pointer at or past the ring size never
matches and the job went ahead. Refuse doneptr >= size with EIO next to
the in-range check. Log the refusal once: every refused job would
otherwise log again.

RxChannel::get_or_peek() trusted the firmware write pointer. One at or
past the ring size never equals the read pointer, so the
while let Some(msg) = ch.get(0) receive loops would walk stale entries
forever. Treat the channel as empty and log once instead.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide
RyanTheTide requested review from a team as code owners November 27, 2026 06:54
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Fixed at 79b6317 (one normal push: fix commit 1b36787 plus a merge of main, no force).

Blocker 1 (a done pointer ≥ ring size was never refused): WorkQueue::submit() now refuses doneptr >= inner.size with EIO, next to the in-range check. The KUnit case comments say ring_reaches_done() is only asked for in-range pointers.
Nits: the refusal logs with pr_err_once! (each refused job would log again). RxChannel::get_or_peek() now bounds the firmware write pointer. One at or past count never equals the read pointer, so the while let Some(msg) = ch.get(0) receive loops would have walked stale entries forever. It now reads as an empty channel and logs once. So the title holds as it is.
Testing: builds in the full fleet-config kernel 7.3.0-aurora-fixa2 (LLVM=1, Rust, DRM_ASAHI=m): main plus this PR plus six other heads, with this PR's files byte-identical to its head.
Still to run (blocker 2): M1-family and M2-family rows at this head with GL FBO rendering and a dEQP-VK smoke. Queued on our M1 Pro and J413 with the fixa2 kernel. I'll post them here.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Row at 79b63175df0e (this PR's files byte-identical in the combined test kernel 7.3.0-aurora-fixa2): M1 Pro (J316s, T6000/G13S): PASS, M2 Air (J413, T8112/G14G): PASS.

This is your G13 + G14 ask. dEQP-VK smoke on both. GL FBO rendering is shown on the G14 only; for the G13 it still needs a Mac with a live output (the M1 Pro panel is dead).

Detail

Both rows ran on the default cmdline with the kernel booted once as a non-default entry, then back to fleet89, which was verified afterwards (saved entry, empty next_entry, kernel removed, 0 failed, Enforcing). Per Mac: SELinux Enforcing, 0 failed units, 0 AVC, 0 err-level kernel lines, 0 oops; Wi-Fi ping OK; s2idle (rtc1, 15 s) rc=0 with ping and a 64 MiB direct NVMe read after the wake; Apple SoC watchdog armed with time left counting (44 s and 58 s of systemd's 60 s); dEQP-VK api.smoke 8/8 pass. J413 also: glmark2 off-screen (FBO) score 7672, 2 audio sinks. On the M1 Pro, glmark2-wayland never starts rendering: its internal panel is dead and there is no Wayland output, the same on fleet89 (traced), so no GL FBO number there. Silent, no playback. Logs: traces/kernel/20261127-fixa2-rows/ (store).
Kernel kit: kits/test/20261127-fixa2 = main 0a4f97d + forward-merged heads of #2919 #2886 #2302 #2475 #2393 #2384 #2895.

@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) and removed needs-hw-row No hardware row at the PR head (bot) ci-failing A check failed at the PR head (bot) labels 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.

Verdict: MERGE at 79b63175

Blockers: none (26/26 CI green and exact-head G13/G14 hardware rows PASS; ready to merge).

Checked:

  • drivers/gpu/drm/asahi/workqueue.rs, channel.rs, event.rs, queue/mod.rs, buffer.rs: prior doneptr >= inner.size blocker fixed cleanly (refuses out-of-range done pointer with -EIO and rate-limited pr_err_once!, plus RxChannel wptr bounds and attachment payload bounds).
  • Hardware rows & CI: 26/26 CI checks green (SUCCESS), MERGEABLE on main, and exact-head rows PASS on J316s (M1 Pro / G13S) and J413 (M2 Air / G14G, dEQP-VK smoke + glmark2 FBO).
  • Checked for Apple material, tool attribution, private serials, and gating: clean; human Signed-off-by present.
Evidence
  • Head: 79b63175df0e (base: main, mergeable: MERGEABLE, +137/-10 across 5 files).

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

code-owner ping <@422957901716652033> / @DjDeveloperr: merge train at 79b63175. The review App approved this head (NEON-PR-REVIEW2's adversarial pass). Rows: J316s+J413. This merges under the 6-point rule 1 h from now, once hosted CI is green, unless you object.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Merging under the 6-point rule (Ryan 09:29, permanent), at 79b63175. (1) The review App approved at this head. (2) Full CI is green. (3/4) Rows: J316s+J413. (5) There's no blocking review. (6) Dj was pinged here 118 min ago with no objection. Revert: git revert -m 1 <merge>.

@RyanTheTide
RyanTheTide merged commit 4b7ec32 into main Nov 28, 2026
37 of 38 checks passed
@RyanTheTide
RyanTheTide deleted the pr/asahi-legacy-fw-index branch November 28, 2026 14:00
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) changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants