Linux Media Controller development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sven Püschel" <s.pueschel@pengutronix.de>
Cc: linux-media@vger.kernel.org
Subject: Re: [PATCH 09/17] media: rockchip: rga: use components to manage multiple cores
Date: Fri, 05 Jun 2026 22:24:18 +0000	[thread overview]
Message-ID: <20260605222418.C97DF1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260606-spu-rga3multicore-v1-9-3ec2b15675f7@pengutronix.de>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [Critical] v4l2 `m2m_dev` is freed while the shared interrupt handler remains active, causing a use-after-free.

Pre-existing issues:
- [High] Missing `synchronize_irq()` in runtime suspend and unsafe hardware access in shared IRQ handler.
- [High] Out-of-order `pm_runtime_enable` and `platform_set_drvdata` causes a NULL pointer dereference in `rga_runtime_resume`.
--

commit 56522d85947daeaf3327877b7e9e7555910847ab
Author: Sven Püschel <s.pueschel@pengutronix.de>

media: rockchip: rga: use components to manage multiple cores

Use component helpers to manage multiple cores and aggregate them into a
central master device. This gives us a dedicated master device and
ensures that all cores (components) are properly set up before creating
the video device.

> diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/platform/rockchip/rga/rga.c
> index 15d095a1d1973..178f45b8da940 100644
> --- a/drivers/media/platform/rockchip/rga/rga.c
> +++ b/drivers/media/platform/rockchip/rga/rga.c
[ ... ]
> +static int rga_core_probe(struct platform_device *pdev)
> +{
> +	int ret = 0;
> +
> +	ret = component_add(&pdev->dev, &rga_core_ops);
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "failed to register component: %d", ret);
> +		return ret;
> +	}
> +
> +	return 0;
> +}

[Severity: High]
This is a pre-existing issue, but can the initialization order leave the
driver vulnerable to sysfs-triggered PM transitions?

During probe, pm_runtime_enable() is called before the driver data is set:

drivers/media/platform/rockchip/rga/rga.c:
	pm_runtime_set_autosuspend_delay(core->dev, 50);
	pm_runtime_enable(core->dev);
	...
	platform_set_drvdata(pdev, core);

If a concurrent PM state transition to 'on' occurs (e.g., via a sysfs write)
before platform_set_drvdata() runs, the PM core will trigger
rga_runtime_resume().

Will this result in a NULL pointer dereference when dev_get_drvdata() is
called?

drivers/media/platform/rockchip/rga/rga.c:rga_runtime_resume() {
	struct rga_core *core = dev_get_drvdata(dev);

	return clk_bulk_prepare_enable(core->num_clks, core->clks);
}

[ ... ]
>  static int __maybe_unused rga_runtime_suspend(struct device *dev)
>  {
>  	struct rga_core *core = dev_get_drvdata(dev);
> @@ -933,7 +912,7 @@ static int __maybe_unused rga_runtime_resume(struct device *dev)
>  	return clk_bulk_prepare_enable(core->num_clks, core->clks);
>  }
>  
> -static const struct dev_pm_ops rga_pm = {
> +static const struct dev_pm_ops rga_core_pm = {
>  	SET_RUNTIME_PM_OPS(rga_runtime_suspend,
>  			   rga_runtime_resume, NULL)
>  };

[Severity: High]
This is a pre-existing issue, but does this runtime suspend callback lack
a synchronize_irq() call?

When the hardware lacks an internal IOMMU, the driver requests a shared
interrupt line (IRQF_SHARED). If a shared interrupt fires while the device
is runtime-suspended, the interrupt handler rga_isr() unconditionally
reads hardware registers via rga_handle_irq() without verifying if the
device is powered on using pm_runtime_get_if_active().

Does disabling clocks here in rga_runtime_suspend():

drivers/media/platform/rockchip/rga/rga.c:rga_runtime_suspend() {
    ...
	clk_bulk_disable_unprepare(core->num_clks, core->clks);
    ...
}

allow the interrupt handler to execute mid-flight while the hardware is
powered down, potentially leading to a synchronous external abort?

[ ... ]
> +static void rga_unbind(struct device *dev)
> +{
> +	component_unbind_all(dev, NULL);
> +}

[Severity: Critical]
Does unbinding the master device cause a use-after-free in the active
interrupt handler?

Because the componentization moved the v4l2 m2m_dev allocation to the master
device, but the devres-managed IRQ request is on the core component device,
the shared interrupt handler rga_isr() remains active indefinitely.

When the master device is unbound, rga->m2m_dev is freed:

drivers/media/platform/rockchip/rga/rga.c:rga_unbind() {
    ...
	v4l2_m2m_release(rga->m2m_dev);
    ...
}

If a shared interrupt fires after the master is unbound, will rga_isr()
access the freed m2m_dev and rga structures when calling
v4l2_m2m_job_finish()?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260606-spu-rga3multicore-v1-0-3ec2b15675f7@pengutronix.de?part=9

  reply	other threads:[~2026-06-05 22:24 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-05 22:06 [PATCH 00/17] media: rockchip: rga: Add multi-core support Sven Püschel
2026-06-05 22:06 ` [PATCH 01/17] media: rockchip: rga: zero cmdbuf in shared code Sven Püschel
2026-06-05 22:20   ` sashiko-bot
2026-06-05 22:06 ` [PATCH 02/17] media: rockchip: rga: add comment about pixel alignment for YUV formats Sven Püschel
2026-06-05 22:06 ` [PATCH 03/17] media: rockchip: rga: move early return into if condition in vidioc_enum_fmt Sven Püschel
2026-06-05 22:06 ` [PATCH 04/17] media: rockchip: rga: removed unused regmap member Sven Püschel
2026-06-05 22:06 ` [PATCH 05/17] media: v4l2-mem2mem: support running multiple jobs in parallel Sven Püschel
2026-06-05 22:18   ` sashiko-bot
2026-06-05 22:06 ` [PATCH 06/17] media: rockchip: rga: move power handling to device_run Sven Püschel
2026-06-05 22:22   ` sashiko-bot
2026-06-05 22:06 ` [PATCH 07/17] media: rockchip: rga: adjust get_version to return the version Sven Püschel
2026-06-05 22:06 ` [PATCH 08/17] media: rockchip: rga: add rga_core structure Sven Püschel
2026-06-05 22:22   ` sashiko-bot
2026-06-05 22:06 ` [PATCH 09/17] media: rockchip: rga: use components to manage multiple cores Sven Püschel
2026-06-05 22:24   ` sashiko-bot [this message]
2026-06-05 22:06 ` [PATCH 10/17] media: rockchip: rga: move rockchip_rga allocation to master probe Sven Püschel
2026-06-05 22:23   ` sashiko-bot
2026-06-05 22:06 ` [PATCH 11/17] media: rockchip: rga: move video device to the master Sven Püschel
2026-06-05 22:21   ` sashiko-bot
2026-06-05 22:06 ` [PATCH 12/17] media: rockchip: rga: move core initialization from bind to probe Sven Püschel
2026-06-05 22:20   ` sashiko-bot
2026-06-05 22:06 ` [PATCH 13/17] media: rockchip: rga: bind all cores to the master Sven Püschel
2026-06-05 22:23   ` sashiko-bot
2026-06-05 22:07 ` [PATCH 14/17] media: rockchip: rga: put all cores into first core iommu domain Sven Püschel
2026-06-05 22:23   ` sashiko-bot
2026-06-05 22:07 ` [PATCH 15/17] media: rockchip: rga: schedule jobs to multiple cores Sven Püschel
2026-06-05 22:25   ` sashiko-bot
2026-06-05 22:07 ` [PATCH 16/17] arm64: dts: rockchip: add rga3 dt nodes to rk3588 Sven Püschel
2026-06-05 22:07 ` [PATCH 17/17] iommu/rockchip: disable fetch dte time limit Sven Püschel
2026-06-05 22:26   ` 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=20260605222418.C97DF1F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=s.pueschel@pengutronix.de \
    --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