From: sashiko-bot@kernel.org
To: "Kyrie Wu" <kyrie.wu@mediatek.com>, devicetree@vger.kernel.org
Cc: robh@kernel.org, conor+dt@kernel.org, media-ci@linuxtv.org
Subject: Re: [PATCH v9 02/14] media: mediatek: vcodec: add driver to support vcp
Date: Tue, 17 Nov 2026 03:55:59 +0000 [thread overview]
Message-ID: <sashiko-outbox-218172@kernel.org> (raw)
In-Reply-To: <20261117032950.1425556-3-kyrie.wu@mediatek.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] media: mediatek: vcodec: missing VCP headers and MTK_VCP_RPROC
Kconfig deps
- [High] media: mediatek: vcodec: 10000-iteration modprobe loop in
mtk_vcodec_vcp_get_vcp_device()
- [High] media: vcodec: vcp: IPC desync and UAF on late ACK after
ipi_send timeout
- [Medium] media: mediatek: vcodec: unlocked ipi_id_ack read and signal
spin in mtk_vcodec_vcp_msg_ipi_send()
- [Medium] media: vcodec: vcp: broken -ERESTARTSYS retry and unlocked
ipi_id_ack read
--
commit c713bc7fb9740ba11c4b6d799c501d0a787e9d1f
Author: Kyrie Wu <kyrie.wu@mediatek.com>
media: mediatek: vcodec: add driver to support vcp
This commit adds a VCP firmware interface for the MediaTek vcodec driver
and updates the firmware selection callbacks to support VCP alongside VPU
and SCP.
> 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
> @@ -1,4 +1,7 @@
> # SPDX-License-Identifier: GPL-2.0-only
> +config VIDEO_MEDIATEK_VCODEC_VCP
> + bool
> +
> config VIDEO_MEDIATEK_VCODEC_SCP
> bool
>
> @@ -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
> select V4L2_H264
> select V4L2_VP9
> select MEDIA_CONTROLLER
[ ... ]
> 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..3b85ae0e632a8
> --- /dev/null
> +++ b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vcp.c
> @@ -0,0 +1,571 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (c) 2025 MediaTek Inc.
> + * Author: Kyrie Wu <kyrie.wu@mediatek.com>
> + */
> +
> +#include <linux/delay.h>
> +#include <linux/dma-direction.h>
> +#include <linux/dma-mapping.h>
> +#include <linux/iommu.h>
> +#include <linux/remoteproc/mtk_vcp_public.h>
> +#include <linux/firmware/mediatek/mtk-vcp-ipc.h>
[Severity: High]
Does this build when CONFIG_VIDEO_MEDIATEK_VCODEC_VCP is enabled?
Neither linux/remoteproc/mtk_vcp_public.h nor
linux/firmware/mediatek/mtk-vcp-ipc.h exists in the tree, leaving struct
mtk_vcp_device incomplete and symbols such as VDEC_FEATURE_ID,
vcp_get_ipidev(), mtk_vcp_ipc_send(), and mtk_vcp_get_by_phandle()
undeclared throughout mtk_vcodec_fw_vcp.c.
In addition, VIDEO_MEDIATEK_VCODEC still has:
depends on VIDEO_MEDIATEK_VPU || MTK_SCP
depends on VIDEO_MEDIATEK_VPU || !VIDEO_MEDIATEK_VPU
depends on MTK_SCP || !MTK_SCP
without MTK_VCP_RPROC. On VCP-only platforms VIDEO_MEDIATEK_VCODEC cannot
be enabled, and a configuration with VIDEO_MEDIATEK_VCODEC=y and
MTK_VCP_RPROC=m builds mtk_vcodec_fw_vcp.o into the kernel image and fails
to link against modular MTK_VCP_RPROC symbols.
[ ... ]
> +static int mtk_vcodec_vcp_msg_process_thread(void *arg)
> +{
> + struct mtk_vcodec_fw *fw = arg;
> + struct vdec_vpu_ipi_ack *msg = NULL;
> + struct mtk_vcp_share_obj *obj;
> + struct mtk_vcp_msg_node *msg_node;
> + vcp_ipi_handler_t handler;
> + unsigned long flags;
> + int ret = 0;
> +
> + do {
[ ... ]
> + 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]);
> +
> + mtk_vcodec_vcp_free_msg_node(fw, msg_node);
> + } while (!kthread_should_stop());
> +
> + return ret;
> +}
[Severity: High]
Can a delayed firmware ACK after a timeout or signal in
mtk_vcodec_vcp_msg_ipi_send() cause a use-after-free and desynchronize
subsequent IPI waits?
CPU0 CPU1 (vcp_vdec_msq_thread)
vdec_h264_slice_init()
vpu_dec_init()
mtk_vcodec_vcp_msg_ipi_send()
wait_event_interruptible_timeout()
--> times out or -ERESTARTSYS
mutex_unlock(&vcp->ipi_mutex)
kfree(inst)
mtk_vcodec_vcp_msg_process_thread()
vpu_dec_ipi_handler()
vpu = (void *)msg->ap_inst_addr
vpu->failure = -EINVAL <-- use-after-free
fw->vcp->msg_signaled[id] = true
wake_up(&fw->vcp->msg_wq[id])
When mtk_vcodec_vcp_msg_ipi_send() times out or aborts on a signal, the
caller tears down and frees the codec instance while VCP is still
processing the request. When the late ACK arrives, vpu_dec_ipi_handler()
still dereferences vpu->ctx and writes to vpu->failure and vpu->signaled
even when vpu_dec_check_ap_inst() fails. mtk_vcodec_vcp_msg_process_thread()
then sets msg_signaled[obj->id] = true and wakes msg_wq[obj->id],
prematurely completing the next caller waiting on the same IPI ID.
[ ... ]
> +static int mtk_vcodec_vcp_msg_ipi_send(struct mtk_vcodec_fw *fw, int id, void *buf,
> + unsigned int len, unsigned int wait)
> +{
[ ... ]
> +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]);
> + } else if (ret == -ERESTARTSYS) {
> + if (retry_cnt++ < 5)
> + goto wait_ack;
> +
> + dev_err(&fw->pdev->dev, "wait ipi ack err (%d)\n", vcp->ipi_id_ack[id]);
> + vcp->ipi_id_ack[id] = VCODEC_IPI_MSG_STATUS_FAIL;
> + } else if (ret < 0) {
> + dev_err(&fw->pdev->dev, "wait ipi ack fail ret %d %d\n", ret, vcp->ipi_id_ack[id]);
> + vcp->ipi_id_ack[id] = VCODEC_IPI_MSG_STATUS_FAIL;
> + }
[Severity: Medium]
Does jumping back to wait_ack on -ERESTARTSYS spin through all 5 retries
without sleeping?
Because the pending signal on current is not cleared before returning to
userspace, each retry of wait_event_interruptible_timeout() immediately
returns -ERESTARTSYS, aborting the wait with VCODEC_IPI_MSG_STATUS_FAIL
while the firmware command is still in flight. Also, vcp->ipi_id_ack[id]
is read after mutex_unlock(&vcp->ipi_mutex) below, where a concurrent
caller can overwrite it before this function returns.
> +
> + dev_dbg(&fw->pdev->dev, "receive message: id %d len %d data 0x%x\n",
> + obj.id, obj.len, data[0]);
> +
> + mutex_unlock(&vcp->ipi_mutex);
> +
> + return vcp->ipi_id_ack[id];
[Severity: Medium]
Can a concurrent caller overwrite vcp->ipi_id_ack[id] after
mutex_unlock(&vcp->ipi_mutex) before it is read for the return value?
A second thread waiting on vcp->ipi_mutex can immediately acquire the lock
and reset vcp->ipi_id_ack[id] (for example to VCODEC_IPI_MSG_STATUS_OK or
-EINVAL) before the first thread returns, and the -ERESTARTSYS retry loop
above returns immediately on all 5 attempts while a signal remains pending
on current.
[ ... ]
> +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]
Does this loop invoke request_module("mtk-vcp") up to 10,001 times during
V4L2 device open() if the mtk-vcp driver is not available?
try_then_request_module() synchronously spawns /sbin/modprobe whenever
mtk_vcodec_vcp_driver_loaded() returns false. Because
mtk_vcodec_vcp_get_vcp_device() is called from
mtk_vcodec_vcp_load_firmware() during fops_vcodec_open() while holding
dev->dev_mutex (rather than during probe like SCP and VPU), opening
/dev/videoX when mtk-vcp is absent spawns 10,001 modprobe processes and
blocks all V4L2 open and release calls for 10 to 20+ seconds before
returning -EPROBE_DEFER (which mtk_vcodec_vcp_load_firmware() then turns
into -EINVAL). Furthermore, if the driver is unbound before open() is ever
called, fw->vcp->vcp_device is still NULL and mtk_vcodec_vcp_release() logs
a spurious error.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117032950.1425556-1-kyrie.wu@mediatek.com?part=2
next prev parent reply other threads:[~2026-11-17 3:56 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 3:29 [PATCH v9 00/14] media: mediatek: vcodec: support video decoder in mt8196 Kyrie Wu
2026-11-17 3:29 ` [PATCH v9 01/14] media: mediatek: vcodec: support vcp architecture Kyrie Wu
2026-11-17 3:29 ` [PATCH v9 02/14] media: mediatek: vcodec: add driver to support vcp Kyrie Wu
2026-11-17 3:55 ` sashiko-bot [this message]
2026-11-17 3:29 ` [PATCH v9 03/14] media: mediatek: vcodec: add driver to support vcp encoder Kyrie Wu
2026-11-17 3:53 ` sashiko-bot
2026-11-17 3:29 ` [PATCH v9 04/14] media: mediatek: vcodec: get different firmware ipi id Kyrie Wu
2026-11-17 3:53 ` sashiko-bot
2026-11-17 3:29 ` [PATCH v9 05/14] media: mediatek: vcodec: get share memory address Kyrie Wu
2026-11-17 3:58 ` sashiko-bot
2026-11-17 3:29 ` [PATCH v9 06/14] media: mediatek: vcodec: add debug information Kyrie Wu
2026-11-17 3:29 ` [PATCH v9 07/14] media: mediatek: vcodec: send share memory address to vcp Kyrie Wu
2026-11-17 3:29 ` [PATCH v9 08/14] media: dt-bindings: mediatek,vcodec-subdev-decoder: Add MT8196 Kyrie Wu
2026-11-17 3:39 ` sashiko-bot
2026-11-17 3:29 ` [PATCH v9 09/14] media: mediatek: vcodec: add decoder compatible to support mt8196 Kyrie Wu
2026-11-17 3:29 ` [PATCH v9 10/14] media: mediatek: vcodec: define MT8196 vcodec levels Kyrie Wu
2026-11-17 3:29 ` [PATCH v9 11/14] media: mediatek: vcodec: support 36bit iova address Kyrie Wu
2026-11-17 3:29 ` [PATCH v9 12/14] media: mediatek: vcodec: clean xpc status Kyrie Wu
2026-11-17 3:29 ` [PATCH v9 13/14] media: mediatek: decoder: fill av1 buffer size with picinfo Kyrie Wu
2026-11-17 3:29 ` [PATCH v9 14/14] media: mediatek: decoder: support av1 extend vsi Kyrie Wu
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-218172@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