mirror of https://lore.kernel.org/linux-amlogic/
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Zhentao Guo" <zhentao.guo@amlogic.com>
Cc: robh@kernel.org, media-ci@linuxtv.org, conor+dt@kernel.org,
	devicetree@vger.kernel.org, linux-amlogic@lists.infradead.org,
	neil.armstrong@linaro.org
Subject: Re: [PATCH v11 5/6] arm64: dts: amlogic: Add video decoder driver support for S4 SOCs
Date: Mon, 12 Oct 2026 07:24:45 +0000	[thread overview]
Message-ID: <sashiko-outbox-167786@kernel.org> (raw)
In-Reply-To: <20261012-b4-s4-vdec-upstream-v11-5-25939f85ada5@amlogic.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] media: amlogic: vdec: Missing locking in the timeout/error path of aml_h264_dec_run()
- [High] media: amlogic: vdec: Infinite loop in threaded IRQ handler due to 0 timeout in read_poll_timeout()
--

commit caf90beec035f24ac592fd4c243200813bb1fcc4
Author: Zhentao Guo <zhentao.guo@amlogic.com>

arm64: dts: amlogic: Add video decoder driver support for S4 SOCs

This commit adds the vdec node to enable the Amlogic V4L2 stateless video 
decoder for S4 SOCs. It also enables the optee node to support loading the
video firmware via TEE helpers.

> diff --git a/arch/arm64/boot/dts/amlogic/meson-s4.dtsi b/arch/arm64/boot/dts/amlogic/meson-s4.dtsi
> index 2a6fbd5308362..7a1dcb3951c82 100644
> --- a/arch/arm64/boot/dts/amlogic/meson-s4.dtsi
> +++ b/arch/arm64/boot/dts/amlogic/meson-s4.dtsi

[ ... ]

> @@ -907,5 +912,33 @@ emmc: mmc@fe08c000 {

[ ... ]

> +		video-codec@fe320000 {
> +			compatible = "amlogic,s4-vdec";
> +			reg = <0x0 0xfe320000 0x0 0x10000>,
> +			      <0x0 0xfe036000 0x0 0x20>;
> +			reg-names = "dos",
> +				    "dmc";
> +			interrupts = <GIC_SPI 91 IRQ_TYPE_EDGE_RISING>,
> +				     <GIC_SPI 92 IRQ_TYPE_EDGE_RISING>;
> +			clocks = <&clkc_periphs CLKID_DOS>,
> +				 <&clkc_periphs CLKID_VDEC_SEL>,
> +				 <&clkc_periphs CLKID_HEVCF_SEL>;
> +			clock-names = "dos",
> +				      "vdec",
> +				      "hvdec";
> +			power-domains = <&pwrc PWRC_S4_DOS_VDEC_ID>,
> +					<&pwrc PWRC_S4_DOS_HEVC_ID>;
> +			power-domain-names = "vdec",
> +					     "hvdec";
> +			resets = <&reset RESET_DOS>;
> +			amlogic,canvas = <&canvas>;
> +			amlogic,secure-monitor = <&sm>;
> +		};

[Severity: High]
Enabling this device exposes a locking regression in the driver. In the
timeout/error path of aml_h264_dec_run(), aml_stop_vdec_hw() is called without
holding dec_hw->ctx_mutex:

drivers/media/platform/amlogic/vdec/h264.c:aml_h264_dec_run() {
...
		/*
		 * Halt the hardware and wait out any in-flight threaded IRQ
		 * handler before cleaning up, otherwise both contexts may run
		 * h264_release_decode_spec() concurrently.
		 */
		aml_stop_vdec_hw(dec_hw);
		synchronize_irq(dec_hw->dec_irq);
		h264_release_decode_spec(dec_hw, ctx);
	} else if (-ERESTARTSYS == ret) {
		ret = -1;
		aml_stop_vdec_hw(dec_hw);
		synchronize_irq(dec_hw->dec_irq);
		h264_release_decode_spec(dec_hw, ctx);
...
}

If wait_event_interruptible_timeout() times out or is interrupted, the
threaded IRQ handler vdec_threaded_isr_handler() may execute concurrently on
another CPU while holding ctx_mutex.

Because aml_stop_vdec_hw() is unprotected, can it reset the hardware
concurrently while the ISR is still interacting with it? 

If the ISR writes to DPB_STATUS_REG after the reset, it could inadvertently
restart the hardware decoding process. This means a restarted hardware block
could fire a new interrupt after synchronize_irq() returns, allowing a new
ISR to run concurrently with h264_release_decode_spec().

Will this lead to concurrent double-freeing of canvas indices?

[Severity: High]
Enabling this device also exposes an infinite loop risk in the threaded IRQ
handler. In h264_config_decode_buf(), read_poll_timeout() is called with a
timeout of 0:

drivers/media/platform/amlogic/vdec/h264.c:h264_config_decode_buf() {
...
	read_poll_timeout(read_dos_reg, reg_val,
			  !(reg_val & 0x800),
			  10, 0, true, hw, H264_CO_MB_RW_CTL);
...
}

The read_poll_timeout() macro treats a timeout of 0 as an infinite wait.

Since this executes inside the threaded interrupt handler on every H264 frame
decode, if the hardware hangs or the register condition is never met,
would the thread spin indefinitely and hang the system or consume 100% CPU on
the IRQ thread?

>  	};
>  };

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261012-b4-s4-vdec-upstream-v11-0-25939f85ada5@amlogic.com?part=5

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

  reply	other threads:[~2026-10-12  7:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12  7:06 [PATCH v11 0/6] Add Amlogic stateless H.264 video decoder for S4 Zhentao Guo via B4 Relay
2026-10-12  7:06 ` [PATCH v11 1/6] firmware: meson: sm: video firmware loading via secure monitor Zhentao Guo via B4 Relay
2026-10-12  7:06 ` [PATCH v11 2/6] firmware: meson: sm: Add video firmware loading SMC call Zhentao Guo via B4 Relay
2026-10-12  7:06 ` [PATCH v11 3/6] media: dt-bindings: Add Amlogic V4L2 video decoder Zhentao Guo via B4 Relay
2026-10-12  7:13   ` sashiko-bot
2026-10-12  7:06 ` [PATCH v11 4/6] decoder: Add V4L2 stateless H.264 decoder driver Zhentao Guo via B4 Relay
2026-10-12  7:20   ` sashiko-bot
2026-10-12  7:06 ` [PATCH v11 5/6] arm64: dts: amlogic: Add video decoder driver support for S4 SOCs Zhentao Guo via B4 Relay
2026-10-12  7:24   ` sashiko-bot [this message]
2026-10-12  7:06 ` [PATCH v11 6/6] arm64: defconfig: Enable CONFIG_VIDEO_AMLOGIC_VDEC Zhentao Guo via B4 Relay

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-167786@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=media-ci@linuxtv.org \
    --cc=neil.armstrong@linaro.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=zhentao.guo@amlogic.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

all inboxes | Powered by JetHome®