Repository navigation
drm/asahi: legacy: bound attachment payloads and firmware-supplied queue and slot indices - #2886
Conversation
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]>
|
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:
|
There was a problem hiding this comment.
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:
- Blocker — Corrupt out-of-range
doneptr >= inner.sizeis accepted silently (workqueue.rs:563-576,1209-1224):- In
ring_reaches_done(),wptr = (wptr + 1) % sizeis always< size, so any firmware-corrupteddoneptr >= 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 refusedoneptr >= inner.sizewithEIOright alongside the in-range collision check.
- In
- Unratelimited
pr_err!on repeated submits (workqueue.rs:568-575):- Once
doneptrdisagrees, every subsequent submit ioctl hitspr_err!without ratelimiting or marking the queue lost. Please ratelimit the log (or log once per workqueue).
- Once
- Scope vs.
channel.rs:101-107RXwptr:- The PR title covers firmware-supplied queue and slot indices, but
RxChannel::get_or_peek()still acceptswptr >= self.countwithout bounds checking, causing an infinite replay livelock on a corrupt RX write pointer. Please either bound RXwptrhere or narrow the PR title/description.
- The PR title covers firmware-supplied queue and slot indices, but
- 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_*_ATTACHMENTSon 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.
- 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
Minor wording note: commit 3 states every caller reports an empty slot as an error, whereas EventManager::signal() logs via mod_pr_debug!.
|
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
left a comment
There was a problem hiding this comment.
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.
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at 70a4f3be8166
Blockers:
drivers/gpu/drm/asahi/workqueue.rs:563-576:ring_reaches_done()wrapswptrwith% size, so a firmwaredoneptr >= inner.sizenever matches and the submit goes ahead. The new KUnit cases even expect!ring_reaches_done(…, 8)and(…, u32::MAX). Fix: refusedoneptr >= inner.sizewith EIO next to the in-range check.- 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.
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]>
|
Fixed at 79b6317 (one normal push: fix commit 1b36787 plus a merge of Blocker 1 (a done pointer ≥ ring size was never refused): |
|
Row at 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). DetailBoth 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 |
There was a problem hiding this comment.
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: priordoneptr >= inner.sizeblocker fixed cleanly (refuses out-of-range done pointer with-EIOand rate-limitedpr_err_once!, plusRxChannelwptr bounds and attachment payload bounds).- Hardware rows & CI: 26/26 CI checks green (
SUCCESS),MERGEABLEonmain, and exact-head rows PASS on J316s (M1 Pro / G13S) and J413 (M2 Air / G14G,dEQP-VKsmoke +glmark2FBO). - Checked for Apple material, tool attribution, private serials, and gating: clean; human
Signed-off-bypresent.
Evidence
- Head:
79b63175df0e(base: main,mergeable: MERGEABLE,+137/-10across 5 files).
|
code-owner ping <@422957901716652033> / @DjDeveloperr: merge train at |
|
Merging under the 6-point rule (Ryan 09:29, permanent), at |
Problem
Three places on the G13/G14 path trust a length or an index more than they should:
SET_*_ATTACHMENTSpayload by its declared size; the second parsessize / 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.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 withEIO; the existing rollback handles a failedsubmit().event: treat out-of-range firmware slot numbers as empty: owner lookups useget(); 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
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.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.compute-preempt-tests2/2,asahi-m41/1.checkpatch.pl: no warnings.Still to run