From: sashiko-bot@kernel.org
To: "Kyrie Wu" <kyrie.wu@mediatek.com>
Cc: conor+dt@kernel.org, media-ci@linuxtv.org, robh@kernel.org,
devicetree@vger.kernel.org
Subject: Re: [PATCH v17 08/12] media: mediatek: jpeg: fix remove buffer removal timing for multi-core
Date: Tue, 22 Sep 2026 09:32:56 +0000 [thread overview]
Message-ID: <20260922093256.8B8931F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260922091530.241762-9-kyrie.wu@mediatek.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] media: mtk-jpeg: list corruption due to racy buffer removal
--
commit d081c3bb256d4600d543f05fb28f936f6f62ecbc
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-protected scope in the
JPEG encoding and decoding workers. The intent is to ensure proper
synchronization before buffers are removed from their queues.
> 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
[ ... ]
> @@ -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: High]
Can this cause list corruption if the hardware completes very quickly?
By calling mtk_jpeg_enc_start before removing the buffers from the ready
queues, is there a window where the interrupt handler completes the operation,
marks the buffers as done, and wakes up userspace?
If the IRQ handler runs concurrently without acquiring the hardware lock and
userspace rapidly requeues the same buffer, could it invoke list operations on
a buffer that is still in the ready queue? When the worker thread subsequently
calls v4l2_m2m_src_buf_remove, would this removal operation completely corrupt
the list pointers?
> v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
> spin_unlock_irqrestore(&comp_jpeg[hw_id]->hw_lock, flags);
>
[ ... ]
> @@ -1782,6 +1778,8 @@ static void mtk_jpegdec_worker(struct work_struct *work)
> jpeg_src_buf->bs_size,
> &bs,
> &fb);
> + v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
> + v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
> mtk_jpeg_dec_start(comp_jpeg[hw_id]->reg_base);
> v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
> spin_unlock_irqrestore(&comp_jpeg[hw_id]->hw_lock, flags);
For the decoding worker, it looks like mtk_jpeg_dec_start is called after
the buffers are removed, which avoids the race condition described above.
Would it be safer to reorder the encoder side to match this sequence and
remove the buffers before starting the hardware?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260922091530.241762-1-kyrie.wu@mediatek.com?part=8
next prev parent reply other threads:[~2026-09-22 9:32 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-22 9:15 [PATCH v17 00/12] Enable jpeg enc & dec multi-hardwares for MT8196 Kyrie Wu
2026-09-22 9:15 ` [PATCH v17 01/12] media: mediatek: jpeg: fix jpeg cores' amounts setting Kyrie Wu
2026-09-22 9:28 ` sashiko-bot
2026-09-22 9:15 ` [PATCH v17 02/12] media: mediatek: jpeg: fix jpeg buffer payload size setting Kyrie Wu
2026-09-22 9:27 ` sashiko-bot
2026-09-22 11:40 ` AngeloGioacchino Del Regno
2026-09-22 9:15 ` [PATCH v17 03/12] media: mediatek: jpeg: fix buffer structure size and layout Kyrie Wu
2026-09-22 11:40 ` AngeloGioacchino Del Regno
2026-09-22 9:15 ` [PATCH v17 04/12] media: mediatek: jpeg: Fix buffer completion on multi-core streaming stop Kyrie Wu
2026-09-22 9:27 ` sashiko-bot
2026-09-22 11:40 ` AngeloGioacchino Del Regno
2026-09-22 9:15 ` [PATCH v17 05/12] media: mediatek: jpeg: Fix multi-core clk suspend and resume setting Kyrie Wu
2026-09-22 9:26 ` sashiko-bot
2026-09-22 11:39 ` AngeloGioacchino Del Regno
2026-09-22 9:15 ` [PATCH v17 06/12] media: mediatek: jpeg: fix buffer state update timing Kyrie Wu
2026-09-22 9:31 ` sashiko-bot
2026-09-22 11:40 ` AngeloGioacchino Del Regno
2026-09-22 9:15 ` [PATCH v17 07/12] media: mediatek: jpeg: fix resolution change event handling in decoder Kyrie Wu
2026-09-22 9:29 ` sashiko-bot
2026-09-22 11:40 ` AngeloGioacchino Del Regno
2026-09-22 9:15 ` [PATCH v17 08/12] media: mediatek: jpeg: fix remove buffer removal timing for multi-core Kyrie Wu
2026-09-22 9:32 ` sashiko-bot [this message]
2026-09-22 11:39 ` AngeloGioacchino Del Regno
2026-09-22 9:15 ` [PATCH v17 09/12] media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgdec compatible Kyrie Wu
2026-09-22 11:39 ` AngeloGioacchino Del Regno
2026-09-22 9:15 ` [PATCH v17 10/12] media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgenc compatible Kyrie Wu
2026-09-22 11:39 ` AngeloGioacchino Del Regno
2026-09-22 9:15 ` [PATCH v17 11/12] media: mediatek: jpeg: add jpeg compatible Kyrie Wu
2026-09-22 11:39 ` AngeloGioacchino Del Regno
2026-09-22 9:15 ` [PATCH v17 12/12] media: mediatek: jpeg: add jpeg smmu sid setting Kyrie Wu
2026-09-22 9:34 ` sashiko-bot
2026-09-22 11:39 ` AngeloGioacchino Del Regno
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=20260922093256.8B8931F000FF@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