Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kyrie Wu" <kyrie.wu@mediatek.com>
Cc: devicetree@vger.kernel.org, conor+dt@kernel.org,
	media-ci@linuxtv.org, robh@kernel.org
Subject: Re: [PATCH v7 02/14] media: mediatek: vcodec: add driver to support vcp
Date: Wed, 23 Sep 2026 02:57:41 +0000	[thread overview]
Message-ID: <20260923025742.1D9A11F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260923024258.257846-3-kyrie.wu@mediatek.com>

Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
- [High] media: mediatek: vcodec: CPU lockup due to unhandled signal in wait_event_interruptible
- [High] media: mediatek: vcodec: modprobe fork bomb DoS in vcp device polling
- [High] media: mediatek: vcodec: Use-After-Free and state desynchronization on IPI timeout
- [High] media: mediatek: vcodec: rproc reference leak on vcp deregister failure
- [Medium] media: mediatek: vcodec: build failure due to missing MTK_VCP_RPROC module dependency
- [Medium] media: mediatek: vcodec: compilation error due to undeclared VCP_SYNC_TIMEOUT_MS
--

commit d524a6ee370f9efe82015b1c8256b28c7fb3bc55
Author: Kyrie Wu <kyrie.wu@mediatek.com>

media: mediatek: vcodec: add driver to support vcp
    
The processor is changed from scp to vcp in mt8196 platform.
Adding new firmware interface to communicate kernel with vcp
for the communication method is changed.

> diff --git a/drivers/media/platform/mediatek/vcodec/Kconfig b/drivers/media/platform/mediatek/vcodec/Kconfig
> index bc8292232530b..d23dad5c78ce3 100644
> --- a/drivers/media/platform/mediatek/vcodec/Kconfig
> +++ b/drivers/media/platform/mediatek/vcodec/Kconfig
[ ... ]
> @@ -21,6 +24,7 @@ config VIDEO_MEDIATEK_VCODEC
>  	select V4L2_MEM2MEM_DEV
>  	select VIDEO_MEDIATEK_VCODEC_VPU if VIDEO_MEDIATEK_VPU
>  	select VIDEO_MEDIATEK_VCODEC_SCP if MTK_SCP
> +	select VIDEO_MEDIATEK_VCODEC_VCP if MTK_VCP_RPROC

[Severity: Medium]
Will this cause a link failure if VIDEO_MEDIATEK_VCODEC is built-in (=y) and
MTK_VCP_RPROC is a module (=m)? Because this select statement doesn't
enforce a modular state dependency, mtk_vcodec_fw_vcp.c could be built-in
while attempting to call exported symbols from the MTK_VCP_RPROC module.

> diff --git a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vcp.c b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vcp.c
> new file mode 100644
> index 0000000000000..150d842c7d226
> --- /dev/null
> +++ b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vcp.c
[ ... ]
> @@ -0,0 +1,571 @@
[ ... ]
> +static int mtk_vcodec_vcp_msg_process_thread(void *arg)
> +{
[ ... ]
> +	do {
> +		ret = wait_event_interruptible(fw->vcp->msg_queue.wq,
> +					       atomic_read(&fw->vcp->msg_queue.cnt) > 0 ||
> +					       kthread_should_stop());
> +		if (ret < 0) {
> +			dev_err(&fw->pdev->dev, "wait msg queue ack timeout %d %d\n",
> +				ret, atomic_read(&fw->vcp->msg_queue.cnt));
> +			continue;

[Severity: High]
Could this lead to an infinite busy loop if a signal is delivered to the
kthread? When wait_event_interruptible() returns -ERESTARTSYS due to a
pending signal, the continue statement immediately restarts the loop. Since
the signal is never cleared, it seems this will continuously spin and lock up
the CPU.

> +		}
[ ... ]
> +		handler(msg, obj->len, fw->vcp->ipi_desc[obj->id].priv);
> +		mtk_vcodec_vcp_ipi_unlock(fw->vcp, obj->id);
> +
> +		fw->vcp->msg_signaled[obj->id] = true;
> +		wake_up(&fw->vcp->msg_wq[obj->id]);

[Severity: High]
Is it possible that this accesses freed memory if the original request timed
out? In mtk_vcodec_vcp_msg_ipi_send(), if the wait for msg_wq times out,
it returns an error to the caller, which might free the associated context.
When the delayed ACK finally arrives, this handler could dereference the
freed context or wake up a completely new request reusing the same ID.

> +
> +		mtk_vcodec_vcp_free_msg_node(fw, msg_node);
> +	} while (!kthread_should_stop());
> +
> +	return ret;
> +}
[ ... ]
> +static int mtk_vcodec_vcp_msg_ipi_send(struct mtk_vcodec_fw *fw, int id, void *buf,
> +				       unsigned int len, unsigned int wait)
> +{
[ ... ]
> +	mutex_lock(&vcp->ipi_mutex);
> +	feature_id = VDEC_FEATURE_ID;
> +	mailbox_id = IPI_OUT_VDEC_1;
> +
> +	timeout_jiffies = jiffies + msecs_to_jiffies(VCP_SYNC_TIMEOUT_MS);

[Severity: Medium]
Will this cause a compilation error? VCP_SYNC_TIMEOUT_MS doesn't seem to be
defined anywhere in this patch or the kernel tree.

> +	while (!vcp_device->ops->vcp_is_ready(vcp_device, feature_id)) {
[ ... ]
> +wait_ack:
> +	/* wait for VCP's ACK */
> +	ret = wait_event_interruptible_timeout(*msg_wq, *msg_signaled,
> +					       msecs_to_jiffies(IPI_TIMEOUT_MS));
> +	if (!ret) {
> +		vcp->ipi_id_ack[id] = VCODEC_IPI_MSG_STATUS_FAIL;
> +		dev_err(&fw->pdev->dev, "wait ipi ack timeout! %d %d\n", ret, vcp->ipi_id_ack[id]);

[Severity: High]
As mentioned above regarding mtk_vcodec_vcp_msg_process_thread(), when this
timeout is reached, the hardware transaction appears to remain pending. Does
this leave the firmware state desynchronized and risk memory corruption when
the delayed ACK eventually arrives?

> +	} else if (ret == -ERESTARTSYS) {
[ ... ]
> +static int mtk_vcodec_vcp_get_vcp_device(struct mtk_vcodec_fw *fw)
> +{
> +	struct device *dev = &fw->pdev->dev;
> +	int retry = 0, retry_cnt = 10000;
> +	phandle vcp_phandle;
> +
> +	while (!try_then_request_module(mtk_vcodec_vcp_driver_loaded(fw), "mtk-vcp")) {
> +		if (++retry > retry_cnt) {
> +			dev_err(dev, "failed to load mtk-vcp module");
> +			return -EPROBE_DEFER;
> +		}
> +		usleep_range(1000, 2000);
> +	}

[Severity: High]
Could this loop result in a modprobe fork bomb? try_then_request_module()
invokes the userspace modprobe helper. If the module is genuinely missing or
fails to load, this loops 10,000 times, potentially spawning 10,000 modprobe
processes over 15 seconds, exhausting system resources.

> +
> +	if (of_property_read_u32(dev->of_node, "mediatek,vcp", &vcp_phandle)) {
[ ... ]
> +static void mtk_vcodec_vcp_release(struct mtk_vcodec_fw *fw)
> +{
[ ... ]
> +	if (!fw->vcp->is_register_done) {
> +		fw->vcp->is_init_done = false;
> +		goto put_device;
> +	}
> +
> +	ret = vcp_device->ops->deregister_feature(vcp_device, fw->vcp->feature_id);
> +	if (ret < 0) {
> +		dev_err(dev, "deregister feature_id(%d) fail(%d)\n", fw->vcp->feature_id, ret);
> +		return;

[Severity: High]
Does this early return cause a leak of the rproc reference count? Returning
here bypasses the put_device label and skips mtk_vcodec_vcp_put_device(),
which would prevent the module from ever being unloaded if deregistration
fails.

> +	}
> +
> +	fw->vcp->is_register_done = false;
> +	fw->vcp->is_init_done = false;
> +
> +put_device:
> +	mtk_vcodec_vcp_put_device(fw);
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260923024258.257846-1-kyrie.wu@mediatek.com?part=2

  reply	other threads:[~2026-09-23  2:57 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-23  2:42 [PATCH v7 00/14] media: mediatek: vcodec: support video decoder in mt8196 Kyrie Wu
2026-09-23  2:42 ` [PATCH v7 01/14] media: mediatek: vcodec: support vcp architecture Kyrie Wu
2026-09-23  2:42 ` [PATCH v7 02/14] media: mediatek: vcodec: add driver to support vcp Kyrie Wu
2026-09-23  2:57   ` sashiko-bot [this message]
2026-09-23  2:42 ` [PATCH v7 03/14] media: mediatek: vcodec: add driver to support vcp encoder Kyrie Wu
2026-09-23  3:06   ` sashiko-bot
2026-09-23  2:42 ` [PATCH v7 04/14] media: mediatek: vcodec: get different firmware ipi id Kyrie Wu
2026-09-23  3:03   ` sashiko-bot
2026-09-23  2:42 ` [PATCH v7 05/14] media: mediatek: vcodec: get share memory address Kyrie Wu
2026-09-23  2:58   ` sashiko-bot
2026-09-23  2:42 ` [PATCH v7 06/14] media: mediatek: vcodec: add debug information Kyrie Wu
2026-09-23  2:42 ` [PATCH v7 07/14] media: mediatek: vcodec: send share memory address to vcp Kyrie Wu
2026-09-23  2:42 ` [PATCH v7 08/14] Add the MT8196 compatible string to the MediaTek vcodec subdev decoder binding Kyrie Wu
2026-10-06 14:35   ` Rob Herring
2026-09-23  2:42 ` [PATCH v7 09/14] media: mediatek: vcodec: add decoder compatible to support mt8196 Kyrie Wu
2026-09-23  2:42 ` [PATCH v7 10/14] media: mediatek: vcodec: define MT8196 vcodec levels Kyrie Wu
2026-09-23  2:42 ` [PATCH v7 11/14] media: mediatek: vcodec: support 36bit iova address Kyrie Wu
2026-09-23  2:42 ` [PATCH v7 12/14] media: mediatek: vcodec: clean xpc status Kyrie Wu
2026-09-23  3:02   ` sashiko-bot
2026-09-23  2:42 ` [PATCH v7 13/14] media: mediatek: decoder: fill av1 buffer size with picinfo Kyrie Wu
2026-09-23  2:42 ` [PATCH v7 14/14] media: mediatek: decoder: support av1 extend vsi Kyrie Wu
2026-09-23  3:00   ` 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=20260923025742.1D9A11F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=kyrie.wu@mediatek.com \
    --cc=media-ci@linuxtv.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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