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 v19 05/13] media: mediatek: jpeg: Fix multi-core clk suspend and resume setting
Date: Mon, 16 Nov 2026 02:03:55 +0000 [thread overview]
Message-ID: <sashiko-outbox-216060@kernel.org> (raw)
In-Reply-To: <20261116013402.1273016-6-kyrie.wu@mediatek.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] media: mediatek: jpeg: deadlock and missed hw wait in
v4l2_m2m_suspend()
- [Medium] media: mediatek: jpeg: uncoordinated v4l2_m2m_resume() on
shared m2m_dev
--
commit 3fc9b3db7f2ed0b9fd6715e9fd9cf8dac338e53f
Author: Kyrie Wu <kyrie.wu@mediatek.com>
media: mediatek: jpeg: Fix multi-core clk suspend and resume setting
This commit moves multi-core clock management to the hardware component
devices' runtime PM callbacks and adds system sleep callbacks to suspend
and resume the M2M queue and component clocks.
> diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
> index 3c22417f4e7c4..b9ba37a880b2d 100644
> --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
> +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
[ ... ]
> @@ -673,11 +669,67 @@ static int mtk_jpegdec_hw_probe(struct platform_device *pdev)
> return 0;
> }
>
> +static int mtk_jpegdec_pm_suspend(struct device *dev)
> +{
> + struct mtk_jpegdec_comp_dev *jpeg = dev_get_drvdata(dev);
> +
> + clk_bulk_disable_unprepare(jpeg->jdec_clk.clk_num,
> + jpeg->jdec_clk.clks);
> +
> + return 0;
> +}
> +
> +static int mtk_jpegdec_pm_resume(struct device *dev)
> +{
> + struct mtk_jpegdec_comp_dev *jpeg = dev_get_drvdata(dev);
> +
> + return clk_bulk_prepare_enable(jpeg->jdec_clk.clk_num,
> + jpeg->jdec_clk.clks);
> +}
> +
> +static int mtk_jpegdec_suspend(struct device *dev)
> +{
> + struct mtk_jpegdec_comp_dev *jpeg = dev_get_drvdata(dev);
> + int ret;
> +
> + /* Stop new submissions before checking hardware activity. */
> + v4l2_m2m_suspend(jpeg->master_dev->m2m_dev);
> +
> + if (READ_ONCE(jpeg->hw_state) != MTK_JPEG_HW_IDLE)
> + ret = -EBUSY;
[Severity: High]
Can v4l2_m2m_suspend() deadlock during system suspend, and does it wait
for active multi-core hardware jobs?
v4l2_m2m_suspend() waits until TRANS_RUNNING is cleared by
v4l2_m2m_job_finish(). However, mtk_jpegdec_worker() and
mtk_jpegenc_worker() call v4l2_m2m_job_finish() immediately after starting
the hardware, while jpeg->hw_state is still MTK_JPEG_HW_BUSY:
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c:mtk_jpegdec_worker() {
...
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);
}
As a result, v4l2_m2m_suspend() does not wait for an in-flight frame to
finish on the hardware, and the subsequent jpeg->hw_state check
immediately fails system suspend with -EBUSY whenever a frame is active.
Furthermore, mtk_jpeg_probe() allocates jpeg->workqueue with WQ_FREEZABLE,
which is frozen during suspend_freeze_processes() before device suspend
callbacks run, whereas v4l2_m2m_job_finish() schedules the next job via
m2m_dev->job_work on the non-freezable system_percpu_wq:
kworker (jpeg->workqueue) PM task / system_percpu_wq
suspend_freeze_processes()
freeze_workqueues_begin()
mtk_jpegdec_worker()
mtk_jpeg_dec_start()
v4l2_m2m_job_finish()
v4l2_m2m_try_run()
curr_ctx->job_flags |= TRANS_RUNNING
mtk_jpeg_multicore_dec_device_run()
queue_work(jpeg->workqueue, ...)
(queued on frozen workqueue)
mtk_jpegdec_suspend()
v4l2_m2m_suspend()
wait_event(..., !TRANS_RUNNING)
<-- hangs forever
The same issue applies to mtk_jpegenc_suspend() in mtk_jpeg_enc_hw.c.
> + else
> + ret = pm_runtime_force_suspend(dev);
> + if (ret)
> + v4l2_m2m_resume(jpeg->master_dev->m2m_dev);
> +
> + return ret;
> +}
> +
> +static int mtk_jpegdec_resume(struct device *dev)
> +{
> + struct mtk_jpegdec_comp_dev *jpeg = dev_get_drvdata(dev);
> + int ret;
> +
> + ret = pm_runtime_force_resume(dev);
> + if (ret < 0)
> + return ret;
> +
> + v4l2_m2m_resume(jpeg->master_dev->m2m_dev);
> +
> + return 0;
> +}
[Severity: Medium]
Does calling v4l2_m2m_resume() on the shared master_dev->m2m_dev from
each component device unpause the M2M queue while sibling components are
still force-suspended?
In multi-core mode, the parent device and all component devices share a
single m2m_dev whose QUEUE_PAUSED flag is a single non-refcounted bit.
During system resume, the parent device resumes before its children in
mtk_jpeg_resume() and calls v4l2_m2m_resume(jpeg->m2m_dev), and the first
child to resume calls v4l2_m2m_resume(jpeg->master_dev->m2m_dev) again
while the remaining child devices are still force-suspended (and even if a
sibling fails pm_runtime_force_resume()). Similarly, if one child device
suspends and a second child fails mtk_jpegdec_suspend() with -EBUSY, the
error path calls v4l2_m2m_resume() before dpm_resume() has force-resumed
the first child.
If v4l2_m2m_resume() dispatches a queued job while any idle sibling is
still force-suspended, mtk_jpegdec_worker() or mtk_jpegenc_worker() can
select that sibling, fail pm_runtime_resume_and_get() with -EACCES, and
complete the buffers with VB2_BUF_STATE_ERROR. The same issue exists in
mtk_jpegenc_suspend() and mtk_jpegenc_resume() in mtk_jpeg_enc_hw.c.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116013402.1273016-1-kyrie.wu@mediatek.com?part=5
next prev parent reply other threads:[~2026-11-16 2:03 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 1:33 [PATCH v19 00/13] media: mediatek: jpeg: add MT8196 JPEG support Kyrie Wu
2026-11-16 1:33 ` [PATCH v19 01/13] media: mediatek: jpeg: fix jpeg cores' amounts setting Kyrie Wu
2026-11-16 1:48 ` sashiko-bot
2026-11-16 1:33 ` [PATCH v19 02/13] media: mediatek: jpeg: fix jpeg buffer payload size setting Kyrie Wu
2026-11-16 1:33 ` [PATCH v19 03/13] media: mediatek: jpeg: fix buffer structure size and layout Kyrie Wu
2026-11-16 1:33 ` [PATCH v19 04/13] media: mediatek: jpeg: Fix buffer completion on multi-core streaming stop Kyrie Wu
2026-11-16 1:33 ` [PATCH v19 05/13] media: mediatek: jpeg: Fix multi-core clk suspend and resume setting Kyrie Wu
2026-11-16 2:03 ` sashiko-bot [this message]
2026-11-16 1:33 ` [PATCH v19 06/13] media: mediatek: jpeg: fix buffer state update timing Kyrie Wu
2026-11-16 1:52 ` sashiko-bot
2026-11-16 1:33 ` [PATCH v19 07/13] media: mediatek: jpeg: fix resolution change event handling in decoder Kyrie Wu
2026-11-16 1:55 ` sashiko-bot
2026-11-16 1:33 ` [PATCH v19 08/13] media: mediatek: jpeg: fix remove buffer removal timing for multi-core Kyrie Wu
2026-11-16 1:33 ` [PATCH v19 09/13] dt-bindings: soc: mediatek: Add MT8196 JPEG SMMU Kyrie Wu
2026-11-16 1:52 ` sashiko-bot
2026-11-16 1:33 ` [PATCH v19 10/13] media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgdec compatible Kyrie Wu
2026-11-16 1:33 ` [PATCH v19 11/13] media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgenc compatible Kyrie Wu
2026-11-16 1:33 ` [PATCH v19 12/13] media: mediatek: jpeg: add jpeg compatible Kyrie Wu
2026-11-16 2:04 ` sashiko-bot
2026-11-16 1:33 ` [PATCH v19 13/13] media: mediatek: jpeg: add jpeg smmu sid setting Kyrie Wu
2026-11-16 2:04 ` 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-216060@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