Repository navigation
media: apple: scaler: T8142 (M5) MSR23 - #2221
Conversation
d4dc7f1 to
7249b78
Compare
|
Thanks, this is a big step: a job builder that computes each job instead of replaying captures, with 43 jobs checked on J815 hardware. A few things:
Rows: J815 is covered. Once the node is SoC-level, a J704 or J813 owner can run 1920x1080 BGRA to 1280x720 NV12 (BT.709, video range), 100 jobs. Pass: output byte-identical to the J815 output for the same input, no job error, no DART fault. We can run no-regression rows on our A18 Pro (Neo) and M4 Pro (MSR20 paths). |
7249b78 to
3d722ce
Compare
|
@RyanTheTide thanks for the review. All four points are addressed in the new head 3d722ce:
Also new since your review: crop, compose, 90/180/270 rotation and flips, as a separate commit. On the J815, 26 geometry jobs are byte-identical to macOS 27.2 for the same input: crops, compose into a larger frame (the outside stays untouched), every rotation and flip of BGRA, NV12, NV24, GREY and P010, at up to 4K, combined with scaling and with colour conversion. The other 50 jobs still match, and there were no DART faults. KUnit passes 22/22. The J704/J813 row you described (1920x1080 BGRA -> 1280x720 NV12, BT.709 video range, 100 jobs) should now run with no board changes. |
|
Thanks for the quick turnaround. The SoC-level enable, the variant data and the comment fix all look good, and J704, J813 and J815 build here with the scaler enabled on each. One point is still open, the filter taps ( Nit: |
|
Two review points are still open on this head, so a short ping:
Everything else from the earlier rounds looks resolved. Thanks again. |
3d722ce to
7f8e392
Compare
|
@RyanTheTide both points are addressed in the new head 7f8e392 (squashed, so the series is still three commits on top of the binding):
J815 results (MacBook Air 15" M5, against macOS 27.2's output for the same input, 76 jobs: colour conversions at BT.601/709/2020 video and full range, scaling from 1/4 to 4x, NV12/P010/GREY/NV16/NV24, 4K, crops, rotations and flips):
The captured set reproduces macOS exactly, so the job builder itself is right. The generated taps stay within one code value of Apple's filter. Two further jobs were skipped as intended, because the driver rejects their odd sizes. KUnit and checkpatch are clean. |
|
Thanks for 7f8e392. Generating the taps from a stated design (Kaiser-windowed sinc per ratio bin, the 1:1 pass-through, Q12 rounding) with the script in |
…abled The binding keeps every firmware-fronted scaler disabled until its firmware handoff, clocks, power and reset ownership are qualified. On the M5 (T8142) they are: the driver starts the firmware core from the image iBoot pre-loads, with the two power domains, and runs jobs on the MacBook Air 15" M5. Keep the T6050 and T8152 instances disabled. Signed-off-by: Nick <[email protected]>
7f8e392 to
e6a33be
Compare
|
Housekeeping only: the four commits had an |
|
Re-review of e6a33be: no code blockers; one body fix and one small code point. Earlier points, at this head:
New:
Rows: the J815 76-job set on this head, with the generated taps. The J704 or J813 row (1920x1080 BGRA -> 1280x720 NV12, BT.709 video range, 100 jobs, byte-identical to the J815 output) is still open for an M5 owner. Our Neo and M4 Pro MSR20 no-regression rows will run on e6a33be. Assisted-by: LLM (Claude:Opus 5.5) |
e6a33be to
4a69f01
Compare
|
@RyanTheTide thanks, both done in
The only code change is in Rows: the J815 76-job set on this head with the generated taps is owed by me. The J704/J813 row is still open for an M5 owner. |
There was a problem hiding this comment.
Formal §1–§6 pre-PR review at 4a69f01a301253e1ebd76f0540f944210908f142 (against live integration/aurora 70a00e583b03): REQUEST_CHANGES.
Audit Summary (§1–§4, §6)
- DT / Attribution / Policy / CI (§1–§4, §6): PASS — not superseded on
integration/aurora,mergeable: clean, all live CI checks green (host-tests,kunit,rust-build,source,dt-checks, DWC3/ATC matrix). T8142 scaler, DART, and both power domains are enabled at SoC level (t8142-peripherals.dtsi), firmware name and power-up writes +settle_uslive in variant data, filter taps are generated from a stated Kaiser-windowed sinc design (tools/media/apple-scaler/msr23_filters.py), all 4 commits carry human author/committer + humanSigned-off-by:only, and PR body disclosure + naming are clean.
Code & Lifetime Blockers
- LIFO
devmteardown UAF and MMIO-after-powerdown on unbind (drivers/media/platform/apple/scaler/apple-scaler-drv.c:1793, 1879, 1894, 1925):asc_v23_probe()registersmsr23_cancel_workat:1793beforemsr23_put(:1879) andasc_register_video()->asc_cleanup(:1925).- Because devres actions unwind LIFO on remove/unbind,
asc_cleanupcallsv4l2_m2m_release(asc->m2m_dev)andmsr23_putcallspm_runtime_put_sync_suspend(dev)whilemsr23_work()can still be queued or executing, beforemsr23_cancel_workever runscancel_work_sync(&m->work). - An in-flight job will touch powered-down MMIO registers and hit a use-after-free on
asc->m2m_devinasc_finish() -> v4l2_m2m_job_finish(). Cancelm->workinsideasc_cleanup(right besidecancel_delayed_work_sync(&asc->watchdog), beforev4l2_m2m_release), or register the cancel action strictly afterasc_cleanup/video_register_device.
- Unchecked
fw->sizeinmsr23_s0()andmsr23_s1()-> slab/MMIO out-of-bounds read (drivers/media/platform/apple/scaler/apple-scaler-drv.c:1216-1231, 1255):- In
msr23_s0(),size_t len = fw ? fw->size : MSR23_TEXT_SIZE;is passed directly tokvmalloc(len)andmemcpy_fromio(buf, w5, len)followed bymemcpy(vec, buf, sizeof(vec)). A truncated on-disk firmware file (fw->size < sizeof(vec)) causes a heap OOB read inmemcpy(vec, buf, 8); an oversized file (fw->size > MSR23_SRAM_TEXT_MAX) reads past SRAM into core DRAM/MMIO or pastw[5]'s ioremap. - In
msr23_s1(),if (fw->size > MSR23_SRAM_TEXT_MAX || !msr23_text_valid((const u32 *)fw->data))is missing afw->size < 2 * sizeof(u32)bounds check before dereferencingfw->dataas twou32words.
- In
- Incomplete DART window validation for multi-planar & spanning buffers (
drivers/media/platform/apple/scaler/apple-scaler-drv.c:1603-1609):msr23_run()only checksmsr23_in_window(vb2_dma_contig_plane_dma_addr(src, 0), 1)anddst, 0with length1.- For multi-planar
V4L2_PIX_FMT_NV12M, plane 1 is a separate DMA allocation and is never checked against[MSR23_WIN, MSR23_WIN + MSR23_WIN_SPAN). Passing length1instead of the plane's mapped size (vb2_plane_size(vb, k)/sizeimage) also allows buffers starting inside the window to overrun its upper bound. Validate every plane across its full byte length (and includingout.dst_off[k]).
- Unsynchronized
hflip/vflipcontrol race + mid-stream invalidation (drivers/media/platform/apple/scaler/apple-scaler-drv.c:816, 831, 874-878, 1535, 1721-1736):asc_start_streaming()grabs onlyctx->rotate_ctrl, leavingV4L2_CID_HFLIPandV4L2_CID_VFLIPmutable while streaming.asc_s_ctrl()writesctx->hflip/ctx->vflipunderasc->lockwhilemsr23_work()runs onsystem_dfl_wqwithoutasc->lockand reads them inmsr23_job_of()(unsynchronized data race / torn H+V update).- Toggling
hflip/vflipmid-stream on a 1:1 CSC job that passedSTREAMONalso hitsmsr23_check()'s rejection (s->rgb != d->rgb && sw == dw && sh == dh && (msr23_orient(job) & 0x70)) and starts failing queued buffers with-EINVAL. Grabhflip/vflipwhile streaming alongsiderotate_ctrl(or snapshot under lock and enforce validity).
- Minor cleanup nits (fix while touching
apple-scaler-drv.c):apple-scaler-drv.c:995: stale comment (/* MSR23 has no m2m device yet; its core is lost and not restarted (logged on resume). */) — MSR23 now registersm2m_devandasc_resume()callsmsr23_restart().apple-scaler-drv.c:1957: stray double-tab indentation onstruct resource *res;.
§5 Evidence Blockers
- Exact-head hardware & regression evidence still owed on
4a69f01a3012:- J815 (M5 Air 15") rerun of the 76-job suite with the generated taps on head
4a69f01a3012, plus a boot regression row (0 SELinux denials, 0 failed units, 0 new kernel errors) and a suspend/resume check exercisingmsr23_restart(). - J704 / J813 (other T8142 M5 board) verification (since MSR23 is enabled SoC-wide in
t8142-peripherals.dtsi).
- J815 (M5 Air 15") rerun of the 76-job suite with the generated taps on head
The M5's scaler (MSR23) is fronted by a Cortex-M core: the driver no longer programs the engine's registers but hands the core block lists in a DMA ring. Bring it up: - start the image iBoot pre-loads into the core's SRAM (or upload the variant's firmware file when the SRAM holds none and the core has never run: writing the SRAM under a core that has run hangs the machine); - write the engine's power-up registers, start the core, take its hello, and send the init message and the four shared pages; - submit jobs through the block-list ring and collect their status from the status ring. A job whose status is an error, or whose status entry belongs to another job, fails and takes the core out of service, as a timeout does. The firmware file name and the power-up writes, each with the time to wait after it (1 ms after the reset release on T8142), are variant data, so a later MSR23 SoC can reuse the code. Each job is a register image the firmware streams into the engine. The driver builds it from the job's parameters (apple-scaler-msr23.c): sizes, strides and plane codes per side, the scaler's steps, initial phases and polyphase filter bins per axis, the colour matrix (asc_csc_compute()), chroma up/downsampling, the dither of a 10-bit source written at 8 bits, and the spill buffer size. Words that are the same in every job are a defaults table. The polyphase filter taps (8 bins of 9 taps, 32 phases) are generated from a stated design, a Kaiser-windowed sinc per scaling ratio, by tools/media/apple-scaler/msr23_filters.py, which also documents how the engine stores them. The firmware tiles the job itself (job word 0x72000000), so no tile array is built. The engine takes B,G,R,A (V4L2 ABGR32, added for MSR23 only), NV12, NV16, NV24, P010 and GREY, even sizes from 64 to 4096 wide and up to 4K UHD in area, and scales up to 4x down or up per axis. Y'CbCr to Y'CbCr keeps the matrix and range. Formats are limited to that range, and STREAMON refuses a pair outside it. Tested on the MacBook Air 15" M5 (J815) against macOS 27.2's output for the same input, over 76 jobs: BGRA <-> NV12 at BT.601/709/2020, video and full range; BGRA -> P010, NV16 and NV24 and P010 -> BGRA; BGRA scaling from 1/4 to 4x, on both axes or one; NV12, P010 and GREY scaling; 4K BGRA -> 1080p NV12 and back; the conversions at seven sizes from VGA to 4K; and crops, rotations and flips. With the coefficient set captured from macOS's own jobs loaded in place of the generated one, all 76 are byte-identical, which checks everything but the taps. With the generated taps, 52 are byte-identical and 24 differ by at most one code value per sample (PSNR 57.8 dB or better). Add KUnit tests for the builder: a BGRA -> NV12 conversion, scaling steps and phases, the rejected jobs and the block list. Signed-off-by: Nick <[email protected]>
The M5 (MSR23) engine reads a rectangle of the source, writes into a rectangle of the destination, rotates in quarter turns and mirrors. Expose these as the OUTPUT crop and CAPTURE compose selections and the V4L2_CID_ROTATE, V4L2_CID_HFLIP and V4L2_CID_VFLIP controls. - Crop: the source region's size, and its origin per plane in samples of that plane; plane sizes and pointers stay those of the whole picture. - Compose: a picture of the rectangle's size at an offset into the destination planes. The rest of the CAPTURE buffer is left as it is. - Rotation and flips: block 0 +0x64 bits 3-6, a quarter-turn count, then mirrors of the rotated picture. The reader rotates, so the scaler and the output window work in the destination's orientation. - A conversion at 1:1 with a quarter turn runs its matrix where a scaled job does (block 11); in block 3 the rotated output is wrong. With a mirror or a half turn, a 1:1 conversion has not been checked and is refused, as are quarter turns of 4:2:2. - Rectangles are even and at least 64 pixels, like the formats. They survive a format change they still fit (v4l2-ctl sets the CAPTURE format again when it starts streaming). - Rotation and both mirrors are fixed while either queue streams: the job worker reads them without the device lock, and a mirror can make a checked 1:1 pair invalid. Same-format jobs at 1:1 now take the source's component sizes in the channel map, as scaled jobs do: before, luma above half scale came out 1 lower. Tested on the MacBook Air 15" M5 (J815): with the coefficient set captured from macOS's jobs loaded in place of the generated taps, 26 geometry jobs give output byte-identical to macOS 27.2 for the same input: quarter and half turns and flips of BGRA, NV12, NV24, P010 and GREY up to 4K, with and without scaling and conversion; crops of BGRA, NV12 and P010 with and without scaling and conversion; and compose. The 50 jobs without geometry still match. With the generated taps, these 26 are part of the previous commit's 76-job result (52 byte-identical, 24 within one code value). v4l2-compliance: cropping and composing pass. Add KUnit tests for the crop and compose words, the orientation codes, the rejected rectangles and rotations, and the channel map. Signed-off-by: Nick <[email protected]>
The MSR23 scaler, its DART and its two power domains are part of the T8142 SoC: enable them in the SoC's peripherals, not per board. A board whose SRAM holds no pre-loaded core image and that has no firmware file fails the probe cleanly (-ENOENT). Tested on the MacBook Air 15" M5 (J815). Signed-off-by: Nick <[email protected]>
4a69f01 to
5f370f8
Compare
|
Thanks for the review. Head is now
Build: the new head builds as an external module against the J815 kernel with W=1 and no warnings. Hardware so far: on the J815 (7.3.0-aurora-j815-dev), a module carrying the same four fixes and two local-only extra controls loads, runs its jobs, unloads, and lets the boot module rebind with a clean dmesg. This is not the exact-head evidence you asked for. The next J815 boot runs the exact
I'll post the numbers here. I have no J704 or J813, so that row needs someone with one of those boards. |
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
The exact-head rows for J815 (MacBook Air 15" M5), this head merged with the other J815 PRs into one test kernel on
The head merges cleanly with Not measured at this head: the at-most-one-code-value bound of the 21 differing jobs, because it needs the test module that loads other taps. Also still open are the J704 and J813 rows, since I have neither board. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at 5f370f8cde82: the code is ready; it needs only a row at this head.
Blockers: none in the code. Missing row: one J813 or J815 at this head with the scaler doing a crop, a rotation and a flip, then an unbind and rebind with a job in flight.
Checked: no Apple material, no gates. The unbind order is fixed: cancel_work_sync() runs before v4l2_m2m_release(), and the fixes are squashed into the commits that introduced each line. CI green. Thanks.
Superseded by the review at 5f370f8
|
Merge it please |
What: a driver for the M5's scaler/CSC engine (MSR23, which sits behind a Cortex-M core) in
apple-scaler. It covers conversion between BGRA, NV12/16/24, P010 and GREY, scaling up to 4x either way, crop, compose, quarter turns and flips. The T8142 DTS enables it. There are four commits: the binding, the driver, the geometry, and the DTS.Tested: J815 (MacBook Air 15" M5) at
5f370f8cde82: the job suite compared byte for byte with macOS 27.2's output for the same input gives 51 identical and 21 differing by the generated filter taps (thescl-*/gd2-*/scaledgeo*jobs), with 2 refused as designed (odd sizes). 22 generated jobs from the same table are 8 self-consistent and 14 identical plus consistent. The driver's suspend/resume path ran three times (resume 102 ms throughmsr23_restart()) and the suite gave the same 51/21/2 afterwards. 0 job errors, 0 DART faults. Regression at boot: 0 SELinux denials (SELinux off), 0 failed units, 0 new kernel errors.Risk: two-way door. Only T8142 (M5) machines: the scaler node is enabled there and nowhere else, and the older MMIO generations (up to v22) take the same path as before.
Not yet: J704 / J813 rows (I have neither); the at-most-one-code-value bound of the differing jobs at this head (it needs the test module that loads other taps); 10-bit RGB (
ARGB2101010), odd sizes and border fill around a compose rectangle.Details
The AP doesn't program MSR23's registers. It hands the core block lists in a DMA ring, and the driver builds each job's register image from the job's parameters.
Firmware
__TEXTinto its SRAM (ADTpre-loaded = 1), and the driver starts it. The variant's firmware file is uploaded only when the SRAM holds none and the core has never run: writing the SRAM under a core that has run hangs the machine. A file shorter than the reset vector or larger than the SRAM text is ignored with a warning.Jobs
-EIOand takes the core out of service, as a timeout does.apple-scaler-msr23.c): sizes, strides and plane codes per side; scaler steps, initial phases and polyphase filter bins per axis; the colour matrix (asc_csc_compute()), chroma up/downsampling, and the dither of a 10-bit source written at 8 bits; the spill buffer size. The firmware tiles each job itself.tools/media/apple-scaler/msr23_filters.py, which also documents how the engine stores them.msr23_filters.py --checkreports 0 differing words against the driver's table.vb2_plane_size()before a job is queued.ABGR32, MSR23 only), NV12, NV16, NV24, P010 and GREY. Sizes: even, 64 to 4096 wide, up to 4K UHD in area. Scaling: up to 4x down or up per axis.V4L2_CID_ROTATEin quarter turns, andHFLIP/VFLIPmirroring the rotated picture; rectangles are even and at least 64 pixels. Rotate and both flips are grabbed while either queue streams.asc_cleanup()cancels the job work beforev4l2_m2m_release(), so no job reaches the m2m device or the registers after either is gone.Changed on this head (review of
4a69f01a3012): the unbind order, the firmware size checks, the per-plane DART window check and the control grab above, plus the suspend comment and an indent. Rebased ontomain; it merges cleanly withmain8c6bd8d.Build:
checkpatch --strictclean (only the MAINTAINERS note for the new file;scaler/is listed); each commit builds withW=1as a module; theapple-scalerKUnit suite passes on arm64 QEMU (22/22); the T8142 J704/J813/J815 DTBs build.v4l2-compliance1.32: 47/48, Cropping and Composing OK. The one failure is testM2MFormats's rule that the CAPTURE colorimetry equals the OUTPUT's, which a colour-space converter doesn't follow (an RGB capture of a Y'CbCr output).Evidence
J815, macOS 27.2 stub, this head merged with the other J815 PRs into one test kernel on
main2943fff; moduleapple-scaler.kofrom that kernel, bound to305000000.scaler,/dev/video14.scl-down2/up2/down1p5/up1p5/mixed/near1/small,scl-down2-nv12, thegd2-*sizes, 4K BGRA <-> 1080p NV12, and the scaledgeo3/geo4jobs, including the compose job, whose area outside the rectangle stays zero).scl-odd-bgra(1002x564) andgeo-letterbox(odd picture height): odd sizes are refused by design.Results are the same across boots.
msr23_filters.py --check: 0 differing words.