Skip to content

media: apple: scaler: stop the engine before handing back a failed job's buffers - #3204

Merged
RyanTheTide merged 2 commits into
mainfrom
fix/scaler-stop-engine-before-buffers
Nov 29, 2026
Merged

RyanTheTide merged 2 commits into
mainfrom
fix/scaler-stop-engine-before-buffers

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What: A failed scaler job (for example, lossless input the engine can't decode) left the engine's interrupt line asserted until the interrupt core disabled it, so no later job could complete until the driver was reloaded. A timed-out job handed its buffers back while the engine might still be using them. Both now stop the engine first: mask the interrupt, reset the engine, and hand the buffers back only once it is idle with no status left.

Tested: the module builds W=1-clean (clang, arm64). The new host test apple-scaler-recovery-tests.py passes its 8 cases; at the previous revision 5 of them fail, and that run is the registered negative control. J773g (M4 mini) at 145ffb7639b5: conversion CRCs match base, three all-zero lossless inputs each come back as an error with the next valid conversion completing, and a timed-out job no longer wedges the engine. 0 DART faults, no interrupt disabled (row). J700 (Neo) at 145ffb7639b5, with #3217, in the combined candidate 7.3.0-neo-combined1126, which carries it unchanged: conversions match base. Three all-zero lossless inputs each come back as an error, and the next valid conversion completes. 0 DART faults, no interrupt disabled, nothing times out.

Risk: two-way · M1 and M4 families and the Neo, which have the direct-MMIO scaler. The interrupt is now threaded.

Not yet: nothing. The P010 to XRGB32 timeout seen on the M4 mini is fixed separately in #3217.

Details
  • The interrupt is requested threaded and one-shot (NULL primary handler, IRQF_ONESHOT), so the line stays masked while a failed job is handled.
  • asc_abort() runs for an error interrupt and for a watchdog timeout:
    • It masks ASC_IRQ_ENABLE and resets the engine: the engine reset first, then the PMGR reset of its power domain, as asc_device_run() already did at power-up. Both now share asc_reset_engine().
    • Only then does it hand the buffers back.
    • If neither reset stops the engine, it powers the engine off (pm_runtime_put_sync_suspend()) before the buffers go back.
  • asc_hw_init() now fails if a completion or error source is still set after the reset and clear, since that source would hold the line.
  • The watchdog disables the interrupt line around the reset, so a handler already running finishes before any register is touched.
  • A clean completion is unchanged. The next job finds the engine reset, with interrupts enabled.
  • Malformed lossless input is not checked up front. The decompressor alone decides which block payloads are valid, so a CPU-side walk of the metadata could not prove a picture decodes. Geometry and buffer size are already checked in buf_prepare(). What changes is that a decompress error can no longer wedge the engine.
Evidence
  • python3 tools/asahi/apple-scaler-recovery-tests.py: all 8 cases ok (done, decompress-error, decompress-error-running, timeout-idle, timeout, timeout-stuck, late-error, spurious).
  • python3 tools/asahi/apple-scaler-recovery-tests.py --ref 40e5e29cc915a421fb2676f895ff7dcc3f47a224: decompress-error, decompress-error-running, timeout-idle, timeout and timeout-stuck fail. At that revision the buffers go back with the line still asserted or the engine still running.
  • tools/asahi/run-host-tests.py --only scaler: 2/2.
  • Module: make M=drivers/media/platform/apple/scaler LLVM=1 W=1 modules against a configured 7.3 tree, no warnings.

…b's buffers

A job that fails with an error, for example a decompress error from
lossless input the engine cannot decode, left the engine's interrupt
line asserted. Writing ASC_IRQ_STATUS does not deassert it; only an
engine reset does, and that reset waited for the next job. The handler
then saw interrupts with no status and returned IRQ_NONE until the
interrupt core disabled the line, so no later job could complete
without reloading the driver and resetting the engine first.

A job that timed out had its buffers handed back at once, while the
engine might still be reading or writing them, and again the reset
waited for the next job.

Handle both before any buffer goes back:

- The interrupt is threaded and one-shot, so the line stays masked while
  a failed job is handled.
- A failed or timed-out job masks the engine interrupt and resets the
  engine, falling back to the PMGR reset as at power-up. The buffers go
  back once the engine is idle and no completion or error source is
  left set. asc_hw_init() now fails if a source stays set after the
  reset.
- If no reset stops the engine, it is powered off before the buffers go
  back.
- The watchdog disables the interrupt line while it resets the engine,
  so an interrupt handler already running finishes first.

Add a host test that runs the production interrupt handler and watchdog
against a modelled engine whose error holds the line until a reset: a
decompress error with the engine idle and running, timeouts with the
engine idle, running and stuck, a late error and a spurious interrupt.
At the previous revision five of the eight cases fail.

Signed-off-by: Dj <[email protected]>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 26, 2026 07:32
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) area:media Area from CODEOWNERS (bot) blast:m1 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) blast:neo Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Merge readiness at 01086502: not ready yet

Check Detail
CI at head no failing: KUnit ane-boot, KUnit ane-pm, KUnit dcp-fabric, KUnit asahi, KUnit spi-hid-apple, KUnit avd
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head no no line with the head SHA 01086502, a Mac and a result in the PR body or a comment
Conflicts ok none
PR text ok Risk: two-way · M1 and M4 families and the Neo, which have the direct-MMIO scaler. The interrupt is now threaded.

Areas: area:gpu, area:media

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

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J773g (M4 Mac mini, T8132 scaler, MSR hardware-version 20) at 145ffb7639b5: the recovery fix works on this Mac. One conversion, P010 → XRGB32 1280×720, fails here with both modules, so convert doesn't end with "0 failed" on either.

How it was run: both modules were loaded in the same boot of one kernel, main 9a9862253576 plus this PR. The PR's 3 files are identical to its head; the same kernel also carried #3200, #3208 and #3210, with no files overlapping. Base is main's drivers/media/platform/apple/scaler built against that same tree, so the vermagic matches; this kernel's own module is the candidate. scaler-row sha256 ae50a441…253.

base module (main) candidate module (this PR)
NV12 → ARGB32 1920×1080 ok, CRC 87c952e0 ok, CRC 87c952e0
ARGB32 → NV12 1920×1080 ok, CRC 0047e4e3 ok, CRC 0047e4e3
P010 → XRGB32 1280×720 FAIL (job timed out, "engine does not go idle: -110") FAIL (job timed out; "engine does not stop after a failed job, powering it off")
NV12 → L8V0 → NV12 1920×1088 FAIL: the engine stays wedged after the P010 timeout ok, CRC 92ea3acb
convert result 3 failed 1 failed

So after a timed-out job, main's module leaves the engine stuck for every later job until the module is reloaded. The candidate resets or powers off the engine, and the next jobs complete.

scaler-row malformed (candidate only): 3/3 all-zero L8V0 inputs come back as errors. After each one, a valid NV12 → ARGB32 completes with the same CRC. Result: "malformed: 0 failed", not inconclusive.

Kernel log over the module A/B:

  • DART/IOMMU faults: 0.
  • "nobody cared" / "Disabling IRQ": 0.
  • "job failed": 3, from the three malformed inputs.
  • The P010 timeouts are the only other new lines: 2 "job timed out", plus the -110 and power-off lines above.

Not yet: the P010 → XRGB32 timeout on the J773g with both modules. It looks like a separate issue, either the format on this scaler or the test's P010 case.

Both modules were unloaded afterwards and the kernel's own module reloaded. Then the Mac went back to the stock kernel, and the binary and modules were removed from the Mac.

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Verdict at 145ffb7639b5: ready

Blockers: none

Checked:

  • The threaded handler. The IRQ is now requested threaded and one-shot (NULL primary, IRQF_ONESHOT, not shared), so the line stays masked until asc_irq() returns. The handler now runs with IRQs on, so it takes hw_lock with irqsave, matching asc_device_run() and the watchdog. Sleeping in asc_hw_init()'s poll, reset_control_reset() and pm_runtime_put_sync_suspend() is fine in the thread.
  • Exactly one path finishes a job. Both the handler and the watchdog take active under hw_lock and set it to NULL, so only one of them ever reaches asc_abort() or asc_finish() for a job. A watchdog that finds no job returns before disable_irq(). One that claims a job calls disable_irq(), which waits for a running handler thread, before it resets the engine.
  • Runtime PM is balanced. The handler drops its get_if_active() reference before the abort, and the job's own reference keeps the engine powered through the reset. Exactly one put follows: put_sync_suspend() if no reset stops the engine, otherwise put_autosuspend() in asc_complete(). Runtime suspend only returns 0, and resume sets need_init, so the next job resets the engine after a power-off.
  • The next job. m2m_job_finish() only queues the next device_run(). A successful abort leaves interrupts enabled and need_init clear, and a power-off leaves need_init set. The shared asc_reset_engine() keeps the power-up fallback to the PMGR reset as it was.
  • Merged-code rules: no runtime switch, no new constant, no SoC or board gate.
  • For the rows: asc_hw_init() now fails if a completion or error bit is still set after the reset and the clear. If some engine keeps a bit set across a reset, every job would fail there. The malformed-input and CRC rows listed under "Not yet" will show whether that happens.
Evidence
  • Build at 145ffb7639b5 with the asahi profile (LLVM): drivers/media/platform/apple/scaler/, exit 0, no warnings.
  • tools/asahi/apple-scaler-recovery-tests.py: 8/8 ok. With --ref 40e5e29cc915, timeout-stuck and the other negative cases fail (!done[i].running, hw.power_offs == 1, autosuspend_puts == 0), as the PR says.
  • run-host-tests.py --only scaler: 2/2.
  • KUnit drivers/media/platform/apple/scaler/.kunitconfig at this head (arm64 QEMU, run locally because CI's KUnit scaler was still pending): 17/17 pass, including apple-scaler 9/9.
  • The Neo and M4 mini rows are still listed under "Not yet".

@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) and removed ci-failing A check failed at the PR head (bot) labels Nov 26, 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 01086502 (once cancelled CI checks are rerun green)

Blockers: none (code, host tests, and J773g hardware row are ready; rerun the 15 cancelled CI checks before merge).

Checked:

  • drivers/media/platform/apple/scaler/apple-scaler-drv.c: verified devm_request_threaded_irq(..., NULL, asc_irq, IRQF_ONESHOT, ...) keeps the line masked until asc_irq() finishes, spin_lock_irqsave(&asc->hw_lock, flags) matches asc_device_run()/asc_watchdog(), asc_hw_init() rejects residual ASC_IRQ_DONE | ASC_IRQ_ERRORS after reset, and asc_abort() masks interrupts, tries engine + PMGR reset, and falls back to pm_runtime_put_sync_suspend() (passing powered_off = true to avoid double runtime PM put) before handing buffers back.
  • Verified asc_watchdog() wraps asc_abort() with disable_irq(asc->irq) / enable_irq(asc->irq) so no concurrent threaded IRQ races the reset.
  • tools/asahi/apple-scaler-recovery-tests.py: verified 8/8 cases and negative control against prior revision.
  • Verified J773g (M4 mini) hardware row (CRCs match base, all-zero lossless errors recover cleanly, timed-out job no longer wedges engine, 0 DART faults).
Evidence
  • Diff reviewed at 01086502 (all 3 files, 581 lines).
  • CI at review time: 4 passed, 0 failed, 15 cancelled.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merge-train status at 01086502 (App approval noted; rows: 15 cancelled; J773g PASS). @DjDeveloperr code-owner ping (6-point rule, point 6): merge earliest 17:15 AEDT once full CI is green (I re-ran cancelled jobs) and the second-family row point holds. Revert: git revert -m 1 <merge>.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merge-train, point 4: the scaler driver runs on every family that has the block, and the J773g row covers one. Please add a row at this head on a second family (J616s or M1 Pro: scale jobs, plus the failed-job recovery path if it can be triggered, 0 IOMMU faults), then it merges.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Row (J616s, M4 Pro) at exact head 0108650 in combined candidate cedaeff9ee2fe5396733351bb571d0a6049bd7fc on main aa76613: 8 apple-scaler v4l2 m2m conversions (NV12/NM12/P010/BA24/BX24, 160x120..3840x2160, 16 frames each) -> PASS (7/8 complete with output sha identical to production; NV12->BX24 640x480 job-times-out on production too and the engine takes the next job normally after it; 0 IOMMU/DART faults). Evidence: traces/kernel/20261129-closeout-j616s-combo/. Saved boot restored.

@RyanTheTide

Copy link
Copy Markdown
Contributor

code-owner ping @DjDeveloperr: closeout merge at 01086502. The App approved at this head. Rows: J773g + J616s exact head (cedaeff9): 7/8 conversions identical to prod, 0 IOMMU faults (the 8th times out on prod too, filed separately). Merging under the 6-point rule 1 h from now, once hosted CI at this head is green, unless you object.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging under the 6-point rule (Ryan 09:29, permanent), at 01086502. (1) The review App approved at this head. (2) Full CI is green. (3/4) Rows: J773g-+-J616s-exact-head-(cedaeff9):-7/8-conversions-identical-to-prod. (5) There's no blocking review. (6) Dj was pinged here 63 min ago with no objection. Revert: git revert -m 1 <merge>.

@RyanTheTide
RyanTheTide merged commit 6c869fd into main Nov 29, 2026
31 of 105 checks passed
@RyanTheTide
RyanTheTide deleted the fix/scaler-stop-engine-before-buffers branch November 29, 2026 11:40
RyanTheTide added a commit to axboe/linux that referenced this pull request Nov 30, 2026
The merge of aurora-silicon#3204 combined the recovery harness with preexisting
rotation and V4L2 control fields in the scaler driver. Declare both
types in the host harness so the extracted structures compile.

The registered pre-fix control still fails its recovery assertions
after compiling.

Signed-off-by: Ryan Murray <[email protected]>
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) area:media Area from CODEOWNERS (bot) blast:m1 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) blast:neo Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (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.

2 participants