From: sashiko-bot@kernel.org
To: "Kyrie Wu" <kyrie.wu@mediatek.com>
Cc: devicetree@vger.kernel.org, media-ci@linuxtv.org,
robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v18 08/13] media: mediatek: jpeg: fix remove buffer removal timing for multi-core
Date: Sat, 10 Oct 2026 08:18:59 +0000 [thread overview]
Message-ID: <sashiko-outbox-166334@kernel.org> (raw)
In-Reply-To: <e5ca1ec64d2d99feb38484ec480debc2ac7b84a8.1791614327.git.kyrie.wu@mediatek.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] media: mtk-jpeg: M2M buffer list corruption due to late removal
--
commit efc50151e6e8cc8e10e2f2bc55033a7e5675f87a
Author: Kyrie Wu <kyrie.wu@mediatek.com>
media: mediatek: jpeg: fix remove buffer removal timing for multi-core
This commit moves the calls to v4l2_m2m_src_buf_remove() and
v4l2_m2m_dst_buf_remove() inside the spinlock to synchronize buffer handling.
> diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> index edd9e2d0ab05f..0907960db1436 100644
> --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> @@ -1654,9 +1654,6 @@ static void mtk_jpegenc_worker(struct work_struct *work)
> goto enc_end;
> }
>
> - v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
> - v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
> -
> schedule_delayed_work(&comp_jpeg[hw_id]->job_timeout_work,
> msecs_to_jiffies(MTK_JPEG_HW_TIMEOUT_MSEC));
[Severity: Critical]
Does scheduling the timeout work before removing the buffers create a race
condition?
If this worker thread stalls for the timeout duration,
mtk_jpegenc_timeout_work() can execute concurrently and return the buffers to
userspace. If userspace then immediately requeues the buffer with VIDIOC_QBUF,
it will be added to the queue via list_add_tail().
Since this worker thread hasn't yet reached v4l2_m2m_src_buf_remove(), the
buffer's node would still be linked in the M2M rdy_queue, which could result
in list corruption from double linking.
>
> @@ -1674,6 +1671,8 @@ static void mtk_jpegenc_worker(struct work_struct *work)
> &src_buf->vb2_buf);
> mtk_jpeg_set_enc_params(ctx, comp_jpeg[hw_id]->reg_base);
> mtk_jpeg_enc_start(comp_jpeg[hw_id]->reg_base);
> + v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
> + v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
[Severity: Critical]
Are we exposed to a similar list corruption race here by starting the hardware
before removing the buffers from the M2M queue?
mtk_jpeg_enc_start() asynchronously kicks off the hardware. If the hardware
finishes immediately, it can trigger mtk_jpegenc_hw_irq_handler() on another
CPU.
The lockless IRQ handler retrieves the buffers and calls v4l2_m2m_buf_done(),
returning them to userspace. If userspace immediately requeues the buffer,
VIDIOC_QBUF will add it to the list while it's still linked in the rdy_queue,
which can cause list corruption and kernel panics.
It looks like this ordering was handled correctly in mtk_jpegdec_worker(),
where mtk_jpeg_dec_start() is called after the buffers are removed. Should
mtk_jpeg_enc_start() follow the same pattern here?
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1791614327.git.kyrie.wu@mediatek.com?part=8
next prev parent reply other threads:[~2026-10-10 8:19 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-10 8:07 [PATCH v18 00/13] media: mediatek: jpeg: add MT8196 JPEG support Kyrie Wu
2026-10-10 8:07 ` [PATCH v18 01/13] media: mediatek: jpeg: fix jpeg cores' amounts setting Kyrie Wu
2026-10-10 8:16 ` sashiko-bot
2026-10-10 8:07 ` [PATCH v18 02/13] media: mediatek: jpeg: fix jpeg buffer payload size setting Kyrie Wu
2026-10-10 8:07 ` [PATCH v18 03/13] media: mediatek: jpeg: fix buffer structure size and layout Kyrie Wu
2026-10-10 8:07 ` [PATCH v18 04/13] media: mediatek: jpeg: Fix buffer completion on multi-core streaming stop Kyrie Wu
2026-10-10 8:17 ` sashiko-bot
2026-10-10 8:07 ` [PATCH v18 05/13] media: mediatek: jpeg: Fix multi-core clk suspend and resume setting Kyrie Wu
2026-10-10 8:24 ` sashiko-bot
2026-10-10 8:07 ` [PATCH v18 06/13] media: mediatek: jpeg: fix buffer state update timing Kyrie Wu
2026-10-10 8:19 ` sashiko-bot
2026-10-10 8:07 ` [PATCH v18 07/13] media: mediatek: jpeg: fix resolution change event handling in decoder Kyrie Wu
2026-10-10 8:24 ` sashiko-bot
2026-10-10 8:07 ` [PATCH v18 08/13] media: mediatek: jpeg: fix remove buffer removal timing for multi-core Kyrie Wu
2026-10-10 8:18 ` sashiko-bot [this message]
2026-10-10 8:07 ` [PATCH v18 09/13] media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgdec compatible Kyrie Wu
2026-10-10 8:07 ` [PATCH v18 10/13] media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgenc compatible Kyrie Wu
2026-10-10 8:18 ` sashiko-bot
2026-10-10 8:07 ` [PATCH v18 11/13] media: mediatek: jpeg: add jpeg compatible Kyrie Wu
2026-10-10 8:21 ` sashiko-bot
2026-10-10 8:07 ` [PATCH v18 12/13] dt-bindings: mediatek: Add MT8196 JPEG SMMU bindings Kyrie Wu
2026-10-10 8:07 ` [PATCH v18 13/13] media: mediatek: jpeg: add jpeg smmu sid setting Kyrie Wu
2026-10-10 8:23 ` 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-166334@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