Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sofus Forstreuter" <sofus.c@icloud.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org,
	media-ci@linuxtv.org
Subject: Re: [PATCH v4 13/17] arm64: dts: apple: t8122: add avd nodes
Date: Sat, 28 Nov 2026 22:37:24 +0000	[thread overview]
Message-ID: <sashiko-outbox-239108@kernel.org> (raw)
In-Reply-To: <20261128-avd-v4-13-35ad7d52c842@icloud.com>

Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [Critical] media: apple: avd: tile dimension underflow in
  compute_tiles_non_uniform()
- [Critical] media: apple: avd: out-of-bounds access and div-by-zero in
  AV1 and H264
- [High] media: apple: avd: unsynchronized reset in avd_watchdog_func()
  vs IRQ
- [Medium] media: apple: avd: wrong plane length field in
  stream_slice_mv()
- [Low] arm64: dts: apple: t8122: undocumented apple,t8122-dart
  compatible string
- [Low] arm64: dts: apple: t8122: undocumented dma-coherent property on
  video-codec
--

commit 573c860e172e49f12afc5a250236593df08daaa0
Author: Sofus Forstreuter <sofus.c@icloud.com>

arm64: dts: apple: t8122: add avd nodes

This commit adds the avd_dart IOMMU and video-codec Devicetree nodes to enable
the Apple Video Decoder on the Apple T8122 SoC.

> diff --git a/arch/arm64/boot/dts/apple/t8122.dtsi b/arch/arm64/boot/dts/apple/t8122.dtsi
> index 52257fa226317..5f73ad9b247ef 100644
> --- a/arch/arm64/boot/dts/apple/t8122.dtsi
> +++ b/arch/arm64/boot/dts/apple/t8122.dtsi
> @@ -190,6 +190,39 @@ soc {
>  		nonposted-mmio;
>  		#size-cells = <2>;
>  
> +		avd_dart: iommu@289010000 {
> +			compatible = "apple,t8122-dart", "apple,t8110-dart";

[Severity: Low]
Should "apple,t8122-dart" be documented in
Documentation/devicetree/bindings/iommu/apple,dart.yaml?  Without a binding
update, make dtbs_check fails schema validation on t8122 targets.

> +			reg = <0x2 0x89010000 0x0 0x4000>;
> +			interrupt-parent = <&aic>;
> +			interrupts = <AIC_IRQ 686 IRQ_TYPE_LEVEL_HIGH>;
> +			#iommu-cells = <1>;
> +			power-domains = <&ps_avd_sys>;
> +		};
> +
> +		video-codec@289070000 {
> +			compatible = "apple,t8122-avd";

[Severity: Critical]
Enabling "apple,t8122-avd" exposes HEVC decoding to userspace, but can
compute_tiles_non_uniform() underflow column_width[] and row_height[] and walk
off the end of the tile arrays on the kernel heap?

drivers/media/platform/apple/avd/avd-hevc.c:compute_tiles_non_uniform() {
	for (i = 0; i < num_cols - 1; i++) {
		column_width[i] = pps->column_width_minus1[i] + 1;
		sum += column_width[i];
	}
	column_width[i] = pic_in_cts_width - sum;
}

When userspace submits a V4L2_CID_STATELESS_HEVC_PPS control with
V4L2_HEVC_PPS_FLAG_TILES_ENABLED set and V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING
clear, nothing checks that sum stays below pic_in_cts_width or
pic_in_cts_height.  If sum exceeds the picture dimension in CTBs, the trailing
u16 width or height wraps up to 65535, and compute_tile_ids() reads
ctb_addr_rs_to_ts[] and writes tile_ids[] out of bounds on the kernel heap.

In addition, avd_hevc_validate_sps() does not reject zero
pic_width_in_luma_samples or pic_height_in_luma_samples (which causes
avd_hevc_compute_tiles() to allocate zero-sized buffers and dereference
ZERO_SIZE_PTR in compute_tile_ids()) and does not bound
log2_min_luma_coding_block_size_minus3 or
log2_diff_max_min_luma_coding_block_size before avd_hevc_compute_tiles()
shifts 1 by their sum and divides by max_cu_width.

[Severity: Critical]
This node also enables AV1 (for the first time in the series) and H264 on
T8122, but can an unvalidated V4L2_CID_STATELESS_AV1_FRAME control underflow
the capture buffer offsets in avd_av1_set_prob() and avd_av1_run_preamble()?

drivers/media/platform/apple/avd/avd-av1.c:avd_av1_set_prob() {
	memcpy(vaddr + AVD_AV1_CDFS_OFFSET(length, dst->av1.color_size),
	       av1_ctx->bufs.probs.cpu, sizeof(struct avd_av1_cdfs));
}

frame_width_minus_1 and frame_height_minus_1 are not checked against
ctx->decoded_fmt or planes[0].length, so a frame whose computed color_size
exceeds length underflows AVD_AV1_CDFS_OFFSET() and AVD_AV1_COLOR_OFFSET(),
writing sizeof(struct avd_av1_cdfs) bytes before vaddr in kernel memory.
Similarly, avd_h264_validate_sps() does not check SPS macroblock dimensions
against ctx->coded_fmt used to size the scratch and auxiliary buffers.

Two other input checks are missing in drivers/media/platform/apple/avd/avd-av1.c:
set_tiles() stores u32 tile_group->tile_row and tile_col in signed ints before
checking >= V4L2_AV1_MAX_TILE_ROWS / COLS (allowing values >= 0x80000000 to
index tile_info arrays negatively), and calc_upscale() and set_refs() divide
by upscaled_plane_w, width, and height without rejecting upscaled_width == 0
or frame_width_minus_1 / frame_height_minus_1 == U32_MAX.

[Severity: Medium]
In the HEVC backend enabled here, does stream_slice_mv() read the wrong plane
length field when computing mv_color_addr?

drivers/media/platform/apple/avd/avd-hevc.c:stream_slice_mv() {
	if (ref_valid) {
		dma_addr_t mv_color_addr = ref->dma.y +
			(ref->base.vb.planes[0].length -
			 mv_color_size(fmt_width(ctx), fmt_height(ctx)));
		pusha(mv_color_addr, "mv_colo", 0);
	}
}

When userspace queues VB2_MEMORY_DMABUF capture buffers with v4l2_plane.length
set to 0, __prepare_dmabuf() populates ref->base.vb.vb2_buf.planes[0].length
while leaving ref->base.vb.planes[0].length at 0.  Subtracting mv_color_size()
then underflows in 32-bit unsigned arithmetic and programs an IOVA roughly
4 GB past ref->dma.y ( triggering a DART IOMMU fault) instead of using
ref->dma.aux_start as stream_refs() does.

> +			reg = <0x2 0x89070000 0x0 0x4000>,
> +			      <0x2 0x89080000 0x0 0x10000>,
> +			      <0x2 0x89090000 0x0 0x14000>,
> +			      <0x2 0x890a4000 0x0 0x4000>,
> +			      <0x2 0x89100000 0x0 0x10000>;
> +			reg-names = "piodma", "code", "sram", "mbox", "ctrl";
> +			interrupt-parent = <&aic>;
> +			interrupts = <AIC_IRQ 679 IRQ_TYPE_LEVEL_HIGH>,
> +				     <AIC_IRQ 680 IRQ_TYPE_LEVEL_HIGH>,
> +				     <AIC_IRQ 681 IRQ_TYPE_LEVEL_HIGH>,
> +				     <AIC_IRQ 682 IRQ_TYPE_LEVEL_HIGH>,
> +				     <AIC_IRQ 683 IRQ_TYPE_LEVEL_HIGH>,
> +				     <AIC_IRQ 684 IRQ_TYPE_LEVEL_HIGH>,
> +				     <AIC_IRQ 685 IRQ_TYPE_LEVEL_HIGH>;
> +			interrupt-names = "mbox0", "mbox1", "mbox2", "mbox3",
> +					  "flag0", "flag1", "piodma";
> +			iommus = <&avd_dart 0>, <&avd_dart 1>;
> +			power-domains = <&ps_avd_sys>;
> +			resets = <&ps_avd_sys>;

[Severity: High]
With mbox0 and resets = <&ps_avd_sys> wired up here, can avd_watchdog_func()
reset the ps_avd_sys domain while avd_irq_handler() is concurrently accessing
avd->mbox?

CPU0 (kworker)                    CPU1 (irq/mbox0-avd)
avd_watchdog_func()               avd_irq_handler()
  writel(0, ...IRQ_ENABLE)
  avd_reset(avd)
    reset_control_reset()
      apple_pmgr_reset_assert()
                                    readl(...MBOX0_RETRIEVE)  <-- MMIO in reset
  avd_job_finish(ctx, ERROR)
    ...starts next job,
    schedules watchdog_work
                                    cancel_delayed_work(&ctx->watchdog_work)
                                      avd_job_finish(ctx, state)  <-- wrong job

avd_watchdog_func() clears AVD_REG_MBOX_IRQ_ENABLE in MMIO but does not call
disable_irq() or synchronize with the threaded mbox0 handler before resetting
ps_avd_sys and finishing the job.  On Apple SoCs, reading avd->mbox while
APPLE_PMGR_DEV_DISABLE and APPLE_PMGR_RESET are asserted can trigger an
SError, and the racing IRQ thread can cancel the newly scheduled watchdog and
finish the next decode job early.

> +			dma-coherent;

[Severity: Low]
Does Documentation/devicetree/bindings/media/apple,avd.yaml need to allow
dma-coherent?  The schema specifies additionalProperties: false without
listing dma-coherent, causing make dtbs_check to fail on this node.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261128-avd-v4-0-35ad7d52c842@icloud.com?part=13

  reply	other threads:[~2026-11-28 22:37 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28 22:02 [PATCH v4 00/17] media: apple: add avd driver Sofus Forstreuter
2026-11-28 22:02 ` [PATCH v4 01/17] dt-bindings: media: add apple,avd Sofus Forstreuter
2026-11-28 22:08   ` sashiko-bot
2026-11-28 22:02 ` [PATCH v4 02/17] media: v4l2: Add P210 pixel format Sofus Forstreuter
2026-11-28 22:02 ` [PATCH v4 03/17] media: v4l2: Add Apple interchange pixel formats Sofus Forstreuter
2026-11-28 22:02 ` [PATCH v4 04/17] media: v4l2-ctrls: validate AV1 context_update_tile_id Sofus Forstreuter
2026-11-28 22:39   ` sashiko-bot
2026-11-28 22:02 ` [PATCH v4 05/17] media: v4l2-ctrls: validate vp9 tile_rows_log2 Sofus Forstreuter
2026-11-28 22:08   ` sashiko-bot
2026-11-28 22:02 ` [PATCH v4 06/17] media: apple: add avd driver Sofus Forstreuter
2026-11-28 22:42   ` sashiko-bot
2026-11-28 22:02 ` [PATCH v4 07/17] media: apple: avd: add h264 support Sofus Forstreuter
2026-11-28 22:43   ` sashiko-bot
2026-11-28 22:02 ` [PATCH v4 08/17] media: apple: avd: add vp9 support Sofus Forstreuter
2026-11-28 22:49   ` sashiko-bot
2026-11-28 22:02 ` [PATCH v4 09/17] media: apple: avd: add hevc support Sofus Forstreuter
2026-11-28 22:46   ` sashiko-bot
2026-11-28 22:02 ` [PATCH v4 10/17] media: apple: avd: add av1 support Sofus Forstreuter
2026-11-28 22:39   ` sashiko-bot
2026-11-28 22:02 ` [PATCH v4 11/17] arm64: dts: apple: t8103: add avd nodes Sofus Forstreuter
2026-11-28 22:36   ` sashiko-bot
2026-11-28 22:02 ` [PATCH v4 12/17] arm64: dts: apple: t8112: " Sofus Forstreuter
2026-11-28 22:21   ` sashiko-bot
2026-11-28 22:02 ` [PATCH v4 13/17] arm64: dts: apple: t8122: " Sofus Forstreuter
2026-11-28 22:37   ` sashiko-bot [this message]
2026-11-28 22:02 ` [PATCH v4 14/17] arm64: dts: apple: t600x: " Sofus Forstreuter
2026-11-28 22:35   ` sashiko-bot
2026-11-28 22:02 ` [PATCH v4 15/17] arm64: dts: apple: t602x: " Sofus Forstreuter
2026-11-28 22:20   ` sashiko-bot
2026-11-28 22:02 ` [PATCH v4 16/17] arm64: dts: apple: t6030: " Sofus Forstreuter
2026-11-28 22:42   ` sashiko-bot
2026-11-28 22:02 ` [PATCH v4 17/17] arm64: dts: apple: t6031: " Sofus Forstreuter
2026-11-28 22:42   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-239108@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=media-ci@linuxtv.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sofus.c@icloud.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox