* [PATCH v2] media: mali-c55: Keep IRQ requested during suspend
@ 2026-10-27 14:08 Linus Walleij
2026-11-05 8:07 ` Linus Walleij
2026-11-10 12:51 ` Jacopo Mondi
0 siblings, 2 replies; 7+ messages in thread
From: Linus Walleij @ 2026-10-27 14:08 UTC (permalink / raw)
To: Li Youhong, Daniel Scally, Jacopo Mondi, Mauro Carvalho Chehab,
Hans Verkuil, Nayden Kanchev
Cc: linux-media, stable, Linus Walleij
The interrupt is currently freed on every runtime suspend and requested
again on runtime resume. Apart from tying interrupt ownership to the
power state rather than to the driver lifetime, this leaves remove to
guess whether an action is installed for the IRQ.
Request the interrupt once during probe and free it during remove.
Disable and synchronize the IRQ before powering the ISP off, and enable
it only after a successful power-on.
Hold a runtime PM reference during probe until the IRQ is installed,
and stop runtime PM and drain the IRQ before unregistering the media
entities during remove.
Fixes: d5f281f3dd29 ("media: mali-c55: Add Mali-C55 ISP driver")
Cc: stable@vger.kernel.org
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
This is essentially my reply with the "proper fix" for:
https://lore.kernel.org/linux-media/20260903025526.2657105-1-dayou5941@163.com/
Keep the Mali-C55 interrupt requested for the driver's lifetime instead
of changing interrupt ownership along with the runtime power state.
Synchronize and disable the IRQ before power-off, and enable it after
power-on. Hold a PM reference until probe installs the IRQ, and stop
runtime PM and drain the IRQ before removing the media entities.
Tested on the Renesas RZ/V2H board with the other in-flight patches
(DTS changes and the TPG enablement) doing full suspend/resume cycles
with wakeup from RTC and NMI and capturing images before and after
the test.
This patch was authored with the assistance of an LLM.
---
Changes in v2:
- Drop the wakeup-source binding patch and all ISP wakeup handling.
- Drop the patch retaining ISP power for wakeup; keep the IRQ lifetime fix.
- Link to v1: https://patch.msgid.link/20260929-mali-c55-irq-supend-resume-v1-0-e3af34afff12@kernel.org
---
.../media/platform/arm/mali-c55/mali-c55-core.c | 44 ++++++++++++----------
1 file changed, 24 insertions(+), 20 deletions(-)
diff --git a/drivers/media/platform/arm/mali-c55/mali-c55-core.c b/drivers/media/platform/arm/mali-c55/mali-c55-core.c
index f28e9f4354ac..3c2816b6a96b 100644
--- a/drivers/media/platform/arm/mali-c55/mali-c55-core.c
+++ b/drivers/media/platform/arm/mali-c55/mali-c55-core.c
@@ -675,8 +675,7 @@ static int __maybe_unused mali_c55_runtime_suspend(struct device *dev)
{
struct mali_c55 *mali_c55 = dev_get_drvdata(dev);
- if (irq_has_action(mali_c55->irqnum))
- free_irq(mali_c55->irqnum, dev);
+ disable_irq(mali_c55->irqnum);
__mali_c55_power_off(mali_c55);
return 0;
@@ -745,20 +744,9 @@ static int __maybe_unused mali_c55_runtime_resume(struct device *dev)
if (ret)
return ret;
- /*
- * The driver needs to transfer large amounts of register settings to
- * the ISP each frame, using either a DMA transfer or memcpy. We use a
- * threaded IRQ to avoid disabling interrupts the entire time that's
- * happening.
- */
- ret = request_threaded_irq(mali_c55->irqnum, NULL, mali_c55_isr,
- IRQF_ONESHOT, dev_driver_string(dev), dev);
- if (ret) {
- __mali_c55_power_off(mali_c55);
- dev_err(dev, "failed to request irq\n");
- }
+ enable_irq(mali_c55->irqnum);
- return ret;
+ return 0;
}
static const struct dev_pm_ops mali_c55_pm_ops = {
@@ -825,27 +813,42 @@ static int mali_c55_probe(struct platform_device *pdev)
pm_runtime_set_autosuspend_delay(&pdev->dev, 2000);
pm_runtime_use_autosuspend(&pdev->dev);
pm_runtime_set_active(&pdev->dev);
+ pm_runtime_get_noresume(dev);
pm_runtime_enable(&pdev->dev);
ret = mali_c55_media_frameworks_init(mali_c55);
if (ret)
goto err_pm_runtime_disable;
- pm_runtime_idle(&pdev->dev);
-
mali_c55->irqnum = platform_get_irq(pdev, 0);
if (mali_c55->irqnum < 0) {
ret = mali_c55->irqnum;
goto err_deinit_media_frameworks;
}
+ /*
+ * The driver needs to transfer large amounts of register settings to
+ * the ISP each frame, using either a DMA transfer or memcpy. We use a
+ * threaded IRQ to avoid disabling interrupts the entire time that's
+ * happening.
+ */
+ ret = request_threaded_irq(mali_c55->irqnum, NULL, mali_c55_isr,
+ IRQF_ONESHOT, dev_driver_string(dev), dev);
+ if (ret) {
+ dev_err(dev, "failed to request irq\n");
+ goto err_deinit_media_frameworks;
+ }
+
+ pm_runtime_put_autosuspend(dev);
+
return 0;
err_deinit_media_frameworks:
mali_c55_media_frameworks_deinit(mali_c55);
err_pm_runtime_disable:
- pm_runtime_set_suspended(&pdev->dev);
pm_runtime_disable(&pdev->dev);
+ pm_runtime_put_noidle(dev);
+ pm_runtime_set_suspended(&pdev->dev);
kfree(mali_c55->context.registers);
err_power_off:
__mali_c55_power_off(mali_c55);
@@ -859,12 +862,13 @@ static void mali_c55_remove(struct platform_device *pdev)
{
struct mali_c55 *mali_c55 = platform_get_drvdata(pdev);
+ pm_runtime_disable(&pdev->dev);
+ free_irq(mali_c55->irqnum, &pdev->dev);
mali_c55_media_frameworks_deinit(mali_c55);
- if (!pm_runtime_suspended(&pdev->dev)) {
+ if (!pm_runtime_status_suspended(&pdev->dev)) {
__mali_c55_power_off(mali_c55);
pm_runtime_set_suspended(&pdev->dev);
}
- pm_runtime_disable(&pdev->dev);
kfree(mali_c55->context.registers);
of_reserved_mem_device_release(&pdev->dev);
}
---
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
change-id: 20260918-mali-c55-irq-supend-resume-30b507a20011
Best regards,
--
Linus Walleij <linusw@kernel.org>
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2] media: mali-c55: Keep IRQ requested during suspend
2026-10-27 14:08 [PATCH v2] media: mali-c55: Keep IRQ requested during suspend Linus Walleij
@ 2026-11-05 8:07 ` Linus Walleij
2026-11-10 12:51 ` Jacopo Mondi
1 sibling, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2026-11-05 8:07 UTC (permalink / raw)
To: Li Youhong, Daniel Scally, Jacopo Mondi, Mauro Carvalho Chehab,
Hans Verkuil, Nayden Kanchev
Cc: linux-media, stable
On Tue, Oct 27, 2026 at 3:08 PM Linus Walleij <linusw@kernel.org> wrote:
> The interrupt is currently freed on every runtime suspend and requested
> again on runtime resume. Apart from tying interrupt ownership to the
> power state rather than to the driver lifetime, this leaves remove to
> guess whether an action is installed for the IRQ.
>
> Request the interrupt once during probe and free it during remove.
>
> Disable and synchronize the IRQ before powering the ISP off, and enable
> it only after a successful power-on.
>
> Hold a runtime PM reference during probe until the IRQ is installed,
> and stop runtime PM and drain the IRQ before unregistering the media
> entities during remove.
>
> Fixes: d5f281f3dd29 ("media: mali-c55: Add Mali-C55 ISP driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Linus Walleij <linusw@kernel.org>
The PW bot replies:
Thanks for your patches! Unfortunately the Media CI robot detected some
issues:
# Test virtme64:test-virtme
Error running test. Final Summary not found
I take it that the PW bot has issues with itself (don't we all).
So not my problem?
Jacopo, do you think we can apply this?
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] media: mali-c55: Keep IRQ requested during suspend
2026-10-27 14:08 [PATCH v2] media: mali-c55: Keep IRQ requested during suspend Linus Walleij
2026-11-05 8:07 ` Linus Walleij
@ 2026-11-10 12:51 ` Jacopo Mondi
2026-11-23 0:29 ` Linus Walleij
1 sibling, 1 reply; 7+ messages in thread
From: Jacopo Mondi @ 2026-11-10 12:51 UTC (permalink / raw)
To: Linus Walleij
Cc: Li Youhong, Daniel Scally, Jacopo Mondi, Mauro Carvalho Chehab,
Hans Verkuil, Nayden Kanchev, linux-media, stable
Hi Linus
On Tue, Oct 27, 2026 at 03:08:05PM +0100, Linus Walleij wrote:
> The interrupt is currently freed on every runtime suspend and requested
> again on runtime resume. Apart from tying interrupt ownership to the
> power state rather than to the driver lifetime, this leaves remove to
> guess whether an action is installed for the IRQ.
>
> Request the interrupt once during probe and free it during remove.
>
> Disable and synchronize the IRQ before powering the ISP off, and enable
> it only after a successful power-on.
>
> Hold a runtime PM reference during probe until the IRQ is installed,
> and stop runtime PM and drain the IRQ before unregistering the media
> entities during remove.
>
> Fixes: d5f281f3dd29 ("media: mali-c55: Add Mali-C55 ISP driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Linus Walleij <linusw@kernel.org>
> ---
> This is essentially my reply with the "proper fix" for:
> https://lore.kernel.org/linux-media/20260903025526.2657105-1-dayou5941@163.com/
>
> Keep the Mali-C55 interrupt requested for the driver's lifetime instead
> of changing interrupt ownership along with the runtime power state.
> Synchronize and disable the IRQ before power-off, and enable it after
> power-on. Hold a PM reference until probe installs the IRQ, and stop
> runtime PM and drain the IRQ before removing the media entities.
>
> Tested on the Renesas RZ/V2H board with the other in-flight patches
> (DTS changes and the TPG enablement) doing full suspend/resume cycles
> with wakeup from RTC and NMI and capturing images before and after
> the test.
>
> This patch was authored with the assistance of an LLM.
> ---
> Changes in v2:
> - Drop the wakeup-source binding patch and all ISP wakeup handling.
> - Drop the patch retaining ISP power for wakeup; keep the IRQ lifetime fix.
> - Link to v1: https://patch.msgid.link/20260929-mali-c55-irq-supend-resume-v1-0-e3af34afff12@kernel.org
> ---
> .../media/platform/arm/mali-c55/mali-c55-core.c | 44 ++++++++++++----------
> 1 file changed, 24 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/media/platform/arm/mali-c55/mali-c55-core.c b/drivers/media/platform/arm/mali-c55/mali-c55-core.c
> index f28e9f4354ac..3c2816b6a96b 100644
> --- a/drivers/media/platform/arm/mali-c55/mali-c55-core.c
> +++ b/drivers/media/platform/arm/mali-c55/mali-c55-core.c
> @@ -675,8 +675,7 @@ static int __maybe_unused mali_c55_runtime_suspend(struct device *dev)
> {
> struct mali_c55 *mali_c55 = dev_get_drvdata(dev);
>
> - if (irq_has_action(mali_c55->irqnum))
> - free_irq(mali_c55->irqnum, dev);
> + disable_irq(mali_c55->irqnum);
> __mali_c55_power_off(mali_c55);
>
> return 0;
> @@ -745,20 +744,9 @@ static int __maybe_unused mali_c55_runtime_resume(struct device *dev)
> if (ret)
> return ret;
>
> - /*
> - * The driver needs to transfer large amounts of register settings to
> - * the ISP each frame, using either a DMA transfer or memcpy. We use a
> - * threaded IRQ to avoid disabling interrupts the entire time that's
> - * happening.
> - */
> - ret = request_threaded_irq(mali_c55->irqnum, NULL, mali_c55_isr,
> - IRQF_ONESHOT, dev_driver_string(dev), dev);
> - if (ret) {
> - __mali_c55_power_off(mali_c55);
> - dev_err(dev, "failed to request irq\n");
> - }
> + enable_irq(mali_c55->irqnum);
>
> - return ret;
> + return 0;
> }
>
> static const struct dev_pm_ops mali_c55_pm_ops = {
> @@ -825,27 +813,42 @@ static int mali_c55_probe(struct platform_device *pdev)
> pm_runtime_set_autosuspend_delay(&pdev->dev, 2000);
> pm_runtime_use_autosuspend(&pdev->dev);
> pm_runtime_set_active(&pdev->dev);
> + pm_runtime_get_noresume(dev);
Why is it relevant to hold a PM reference during the installation of
the IRQ handler ?
> pm_runtime_enable(&pdev->dev);
>
> ret = mali_c55_media_frameworks_init(mali_c55);
> if (ret)
> goto err_pm_runtime_disable;
>
> - pm_runtime_idle(&pdev->dev);
> -
> mali_c55->irqnum = platform_get_irq(pdev, 0);
> if (mali_c55->irqnum < 0) {
> ret = mali_c55->irqnum;
> goto err_deinit_media_frameworks;
> }
>
> + /*
> + * The driver needs to transfer large amounts of register settings to
> + * the ISP each frame, using either a DMA transfer or memcpy. We use a
> + * threaded IRQ to avoid disabling interrupts the entire time that's
> + * happening.
Does this comment still apply in your opinion ? I mean, thread_irq are
pretty regular stuff, do we need to justify its usage ?
> + */
> + ret = request_threaded_irq(mali_c55->irqnum, NULL, mali_c55_isr,
> + IRQF_ONESHOT, dev_driver_string(dev), dev);
> + if (ret) {
> + dev_err(dev, "failed to request irq\n");
> + goto err_deinit_media_frameworks;
> + }
> +
> + pm_runtime_put_autosuspend(dev);
> +
> return 0;
>
> err_deinit_media_frameworks:
> mali_c55_media_frameworks_deinit(mali_c55);
> err_pm_runtime_disable:
> - pm_runtime_set_suspended(&pdev->dev);
> pm_runtime_disable(&pdev->dev);
> + pm_runtime_put_noidle(dev);
> + pm_runtime_set_suspended(&pdev->dev);
> kfree(mali_c55->context.registers);
> err_power_off:
> __mali_c55_power_off(mali_c55);
> @@ -859,12 +862,13 @@ static void mali_c55_remove(struct platform_device *pdev)
> {
> struct mali_c55 *mali_c55 = platform_get_drvdata(pdev);
>
> + pm_runtime_disable(&pdev->dev);
It amazes me how, after so many years, I still can't find a clear, firm
indication of what is the intended call order for pm_runtime_disable()
and the other pm_runtime calls is during a driver's remove.
Media drivers seem to do different things with some disabling pm
before setting the state to suspended, other doing the other way
around.
In the end, I think this doesn't make any difference, but in this
specific occurance:
1) Is this re-ordering required to support the new interrupt handling?
or
2) Is it a change that is worth doing anyway ? (and I should say "should
go in a different patch on its own")
> + free_irq(mali_c55->irqnum, &pdev->dev);
> mali_c55_media_frameworks_deinit(mali_c55);
> - if (!pm_runtime_suspended(&pdev->dev)) {
> + if (!pm_runtime_status_suspended(&pdev->dev)) {
I guess this is required because you moved pm_runtime_disable() up
Thanks
j
> __mali_c55_power_off(mali_c55);
> pm_runtime_set_suspended(&pdev->dev);
> }
> - pm_runtime_disable(&pdev->dev);
> kfree(mali_c55->context.registers);
> of_reserved_mem_device_release(&pdev->dev);
> }
>
> ---
> base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
> change-id: 20260918-mali-c55-irq-supend-resume-30b507a20011
>
> Best regards,
> --
> Linus Walleij <linusw@kernel.org>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] media: mali-c55: Keep IRQ requested during suspend
2026-11-10 12:51 ` Jacopo Mondi
@ 2026-11-23 0:29 ` Linus Walleij
2026-11-23 8:28 ` Jacopo Mondi
0 siblings, 1 reply; 7+ messages in thread
From: Linus Walleij @ 2026-11-23 0:29 UTC (permalink / raw)
To: Jacopo Mondi
Cc: Li Youhong, Daniel Scally, Mauro Carvalho Chehab, Hans Verkuil,
Nayden Kanchev, linux-media, stable
Hi Jacopo,
On Tue, Nov 10, 2026 at 1:51 PM Jacopo Mondi
<jacopo.mondi@ideasonboard.com> wrote:
> > static const struct dev_pm_ops mali_c55_pm_ops = {
> > @@ -825,27 +813,42 @@ static int mali_c55_probe(struct platform_device *pdev)
> > pm_runtime_set_autosuspend_delay(&pdev->dev, 2000);
> > pm_runtime_use_autosuspend(&pdev->dev);
> > pm_runtime_set_active(&pdev->dev);
> > + pm_runtime_get_noresume(dev);
>
> Why is it relevant to hold a PM reference during the installation of
> the IRQ handler ?
Probe enables runtime PM before registering the media devices.
Once those devices are visible, a streaming path can take and drop a
PM reference. The probe reference keeps the ISP active until the IRQ is
installed, so runtime suspend cannot call disable_irq() on an IRQ we
haven’t requested yet. I’ll add a comment.
> > + /*
> > + * The driver needs to transfer large amounts of register settings to
> > + * the ISP each frame, using either a DMA transfer or memcpy. We use a
> > + * threaded IRQ to avoid disabling interrupts the entire time that's
> > + * happening.
>
> Does this comment still apply in your opinion ? I mean, thread_irq are
> pretty regular stuff, do we need to justify its usage ?
Nah I'll drop it.
> > + pm_runtime_disable(&pdev->dev);
>
> It amazes me how, after so many years, I still can't find a clear, firm
> indication of what is the intended call order for pm_runtime_disable()
> and the other pm_runtime calls is during a driver's remove.
>
> Media drivers seem to do different things with some disabling pm
> before setting the state to suspended, other doing the other way
> around.
>
> In the end, I think this doesn't make any difference, but in this
> specific occurance:
>
> 1) Is this re-ordering required to support the new interrupt handling?
> or
> 2) Is it a change that is worth doing anyway ? (and I should say "should
> go in a different patch on its own")
>
> > + free_irq(mali_c55->irqnum, &pdev->dev);
> > mali_c55_media_frameworks_deinit(mali_c55);
> > - if (!pm_runtime_suspended(&pdev->dev)) {
> > + if (!pm_runtime_status_suspended(&pdev->dev)) {
>
> I guess this is required because you moved pm_runtime_disable() up
The remove ordering is part of the IRQ lifetime change. Both runtime
PM callbacks now assume the IRQ is installed, so we need to drain
them befor free_irq(). Then free_irq() waits for the threaded handler
before we unregister the media entities it uses.
That’s also why I switched to pm_runtime_status_suspended().
It reports the actual status after pm_runtime_disable(), so we only
power off the ISP if it’s still active.
I'll resend a touched-up version.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] media: mali-c55: Keep IRQ requested during suspend
2026-11-23 0:29 ` Linus Walleij
@ 2026-11-23 8:28 ` Jacopo Mondi
2026-11-23 10:38 ` Linus Walleij
0 siblings, 1 reply; 7+ messages in thread
From: Jacopo Mondi @ 2026-11-23 8:28 UTC (permalink / raw)
To: Linus Walleij
Cc: Jacopo Mondi, Li Youhong, Daniel Scally, Mauro Carvalho Chehab,
Hans Verkuil, Nayden Kanchev, linux-media, stable
Hi Linus
On Mon, Nov 23, 2026 at 01:29:05AM +0100, Linus Walleij wrote:
> Hi Jacopo,
>
> On Tue, Nov 10, 2026 at 1:51 PM Jacopo Mondi
> <jacopo.mondi@ideasonboard.com> wrote:
>
> > > static const struct dev_pm_ops mali_c55_pm_ops = {
> > > @@ -825,27 +813,42 @@ static int mali_c55_probe(struct platform_device *pdev)
> > > pm_runtime_set_autosuspend_delay(&pdev->dev, 2000);
> > > pm_runtime_use_autosuspend(&pdev->dev);
> > > pm_runtime_set_active(&pdev->dev);
> > > + pm_runtime_get_noresume(dev);
> >
> > Why is it relevant to hold a PM reference during the installation of
> > the IRQ handler ?
>
> Probe enables runtime PM before registering the media devices.
> Once those devices are visible, a streaming path can take and drop a
This seems veeery theoretical. To have the v4l2 device and subdevice
nodes appear to userspace we have to wait the ivc to probe (see the
.complete() notifier callback handler) and to operate the pipeline we
need the CSI-2 receiver and the sensor to have probed as well. This in
m2m mode. With an inline path to have the devnodes registered you have
to have the whole chain to probe up to the sensor.
So yeah, maybe Sashiko would tell you this is possible but I hardly
believe it is.
Anyway, there is a remote possibility for a window here, so let's
increase the pm runtime counter.
> PM reference. The probe reference keeps the ISP active until the IRQ is
> installed, so runtime suspend cannot call disable_irq() on an IRQ we
> haven’t requested yet. I’ll add a comment.
A suspend will always follow a resume, and if a resume tries to enable
an irq before it is installed we'll have problems as well.
If that's a real concern to you, shouldn't we install the irq handler
before enabling pm runtime and powering the device up ?
>
> > > + /*
> > > + * The driver needs to transfer large amounts of register settings to
> > > + * the ISP each frame, using either a DMA transfer or memcpy. We use a
> > > + * threaded IRQ to avoid disabling interrupts the entire time that's
> > > + * happening.
> >
> > Does this comment still apply in your opinion ? I mean, thread_irq are
> > pretty regular stuff, do we need to justify its usage ?
>
> Nah I'll drop it.
>
> > > + pm_runtime_disable(&pdev->dev);
> >
> > It amazes me how, after so many years, I still can't find a clear, firm
> > indication of what is the intended call order for pm_runtime_disable()
> > and the other pm_runtime calls is during a driver's remove.
> >
> > Media drivers seem to do different things with some disabling pm
> > before setting the state to suspended, other doing the other way
> > around.
> >
> > In the end, I think this doesn't make any difference, but in this
> > specific occurance:
> >
> > 1) Is this re-ordering required to support the new interrupt handling?
> > or
> > 2) Is it a change that is worth doing anyway ? (and I should say "should
> > go in a different patch on its own")
> >
> > > + free_irq(mali_c55->irqnum, &pdev->dev);
> > > mali_c55_media_frameworks_deinit(mali_c55);
> > > - if (!pm_runtime_suspended(&pdev->dev)) {
> > > + if (!pm_runtime_status_suspended(&pdev->dev)) {
> >
> > I guess this is required because you moved pm_runtime_disable() up
>
> The remove ordering is part of the IRQ lifetime change. Both runtime
> PM callbacks now assume the IRQ is installed, so we need to drain
> them befor free_irq(). Then free_irq() waits for the threaded handler
> before we unregister the media entities it uses.
I'm sorry, this is certainly me missing some pm_runtime internals,
but where is this happening ?
>
> That’s also why I switched to pm_runtime_status_suspended().
> It reports the actual status after pm_runtime_disable(), so we only
> power off the ISP if it’s still active.
It seems to me pm_runtime_status_suspended() ignores the runtime
counter and is only there because you pm_runtime_disable() earlier ?
>
> I'll resend a touched-up version.
>
> Yours,
> Linus Walleij
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] media: mali-c55: Keep IRQ requested during suspend
2026-11-23 8:28 ` Jacopo Mondi
@ 2026-11-23 10:38 ` Linus Walleij
2026-11-23 11:12 ` Jacopo Mondi
0 siblings, 1 reply; 7+ messages in thread
From: Linus Walleij @ 2026-11-23 10:38 UTC (permalink / raw)
To: Jacopo Mondi
Cc: Li Youhong, Daniel Scally, Mauro Carvalho Chehab, Hans Verkuil,
Nayden Kanchev, linux-media, stable
Hi Jacopo,
On Mon, Nov 23, 2026 at 9:28 AM Jacopo Mondi
<jacopo.mondi@ideasonboard.com> wrote:
> So yeah, maybe Sashiko would tell you this is possible but I hardly
> believe it is.
> Anyway, there is a remote possibility for a window here, so let's
> increase the pm runtime counter.
I'm honestly not sure. The framework should ideally stop this
from ever happening but I'm not good enough with the media
framework to have even a vaguest idea of how to fix this.
What happened is that I asked an LLM to review the code
using the Sashiko scripts and it complains about this risk.
> > PM reference. The probe reference keeps the ISP active until the IRQ is
> > installed, so runtime suspend cannot call disable_irq() on an IRQ we
> > haven’t requested yet. I’ll add a comment.
>
> A suspend will always follow a resume, and if a resume tries to enable
> an irq before it is installed we'll have problems as well.
>
> If that's a real concern to you, shouldn't we install the irq handler
> before enabling pm runtime and powering the device up ?
Often that is not a good idea, because the IRQ line can
be in an undefined state and give rise to interrupt storms
if you do that. As soon as the irq handler is installed it gets
unmasked by enable_irq().
Also right now the device is powered up
by directly calling __mali_c55_power_on() in probe() maybe
we should just let the PM runtime resume power it up
for clarity?
It's quite common to power up a device (enable clocks
and de-assert resets) before enabling
runtime PM though, that's what I usually do.
Remove problems:
> > > > + pm_runtime_disable(&pdev->dev);
> > > > + free_irq(mali_c55->irqnum, &pdev->dev);
Note: here we disable runtime PM and free the IRQ and this will
make sure no further IRQs appear from this point.
But clocks can still be running and resets can still be
de-asserted because there is no guarantee that runtime
suspend has executed just because we disable pm_runtime.
> > > > mali_c55_media_frameworks_deinit(mali_c55);
> > > > - if (!pm_runtime_suspended(&pdev->dev)) {
> > > > + if (!pm_runtime_status_suspended(&pdev->dev)) {
> > >
> > > I guess this is required because you moved pm_runtime_disable() up
> >
> > The remove ordering is part of the IRQ lifetime change. Both runtime
> > PM callbacks now assume the IRQ is installed, so we need to drain
> > them befor free_irq(). Then free_irq() waits for the threaded handler
> > before we unregister the media entities it uses.
>
> I'm sorry, this is certainly me missing some pm_runtime internals,
> but where is this happening ?
It's not a pm runtime thing more of a free_irq() thing,
it will wait for outstanding threaded handlers to complete.
When we get here we know no further IRQs can happen, but we
have no guarantee that runtime suspend has been called,
so we check just like the old code did to make sure it
gets de-clocked and resets are asserted.
Compare with the old code:
static void mali_c55_remove(struct platform_device *pdev)
{
struct mali_c55 *mali_c55 = platform_get_drvdata(pdev);
mali_c55_media_frameworks_deinit(mali_c55);
if (!pm_runtime_suspended(&pdev->dev)) {
__mali_c55_power_off(mali_c55);
pm_runtime_set_suspended(&pdev->dev);
}
pm_runtime_disable(&pdev->dev);
kfree(mali_c55->context.registers);
}
Since IRQs are unregistered in the runtime suspend callback,
this is not a problem here.
> > That’s also why I switched to pm_runtime_status_suspended().
> > It reports the actual status after pm_runtime_disable(), so we only
> > power off the ISP if it’s still active.
>
> It seems to me pm_runtime_status_suspended() ignores the runtime
> counter and is only there because you pm_runtime_disable() earlier ?
Kind of, I guess it's a bad idea to free_irq() before disabling
runtime PM?
An alternative is to call pm_runtime_force_suspend() before
free_irq() so you know for sure the device is powered off,
I can try this if you like it better.
Hm actually that would probably be better... shall I try that?
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] media: mali-c55: Keep IRQ requested during suspend
2026-11-23 10:38 ` Linus Walleij
@ 2026-11-23 11:12 ` Jacopo Mondi
0 siblings, 0 replies; 7+ messages in thread
From: Jacopo Mondi @ 2026-11-23 11:12 UTC (permalink / raw)
To: Linus Walleij
Cc: Jacopo Mondi, Li Youhong, Daniel Scally, Mauro Carvalho Chehab,
Hans Verkuil, Nayden Kanchev, linux-media, stable
Hi Linus
On Mon, Nov 23, 2026 at 11:38:26AM +0100, Linus Walleij wrote:
> Hi Jacopo,
>
> On Mon, Nov 23, 2026 at 9:28 AM Jacopo Mondi
> <jacopo.mondi@ideasonboard.com> wrote:
>
> > So yeah, maybe Sashiko would tell you this is possible but I hardly
> > believe it is.
> > Anyway, there is a remote possibility for a window here, so let's
> > increase the pm runtime counter.
>
> I'm honestly not sure. The framework should ideally stop this
> from ever happening but I'm not good enough with the media
> framework to have even a vaguest idea of how to fix this.
The only way for this to happen is that all devices in the capture
pipeline probe before the ISP and when we register a notifier in
mali_c55_media_frameworks_init() the v4l2-async framework notices all
dependencies are there and calls mali_c55_notifier_complete() which
registers all device nodes. At this point we should have userspace
operating the pipeline before we get to installing the irq handlers
(which happens just after calling mali_c55_media_frameworks_init()).
Yes, there is a window there, but its so tiny I wonder if it we can
really ever hit it. But as we know the most unlikely things can
happen, let's take it into account even if unlikely ? What do you
think ?
>
> What happened is that I asked an LLM to review the code
> using the Sashiko scripts and it complains about this risk.
>
Exactly, this is one of the very far fetched issues bots tend to
report and for which we're receiving an increasing number of
not-really-required fixes for.
This is not your case of course, I'm just complaining about the
current state of affairs and the overload it imposes on reviewers and
maintainers :)
> > > PM reference. The probe reference keeps the ISP active until the IRQ is
> > > installed, so runtime suspend cannot call disable_irq() on an IRQ we
> > > haven’t requested yet. I’ll add a comment.
> >
> > A suspend will always follow a resume, and if a resume tries to enable
> > an irq before it is installed we'll have problems as well.
> >
> > If that's a real concern to you, shouldn't we install the irq handler
> > before enabling pm runtime and powering the device up ?
>
> Often that is not a good idea, because the IRQ line can
> be in an undefined state and give rise to interrupt storms
> if you do that. As soon as the irq handler is installed it gets
> unmasked by enable_irq().
Right, and those are probably the spurious IRQs I had seen when I first
tried to install irq handlers in probe(). I still question the idea of
having the irq vector being fully unmasked in POR state, but it's
probably a bit late to complain to hardware designers.
>
> Also right now the device is powered up
> by directly calling __mali_c55_power_on() in probe() maybe
> we should just let the PM runtime resume power it up
> for clarity?
The thing is that the driver doesn't depend on PM.
Honestly, I would just depend on PM everywhere these days.
>
> It's quite common to power up a device (enable clocks
> and de-assert resets) before enabling
> runtime PM though, that's what I usually do.
Isn't it happening here as well ? I see a call to
__mali_c55_power_on() before pm_runtime_enable().
>
> Remove problems:
>
> > > > > + pm_runtime_disable(&pdev->dev);
> > > > > + free_irq(mali_c55->irqnum, &pdev->dev);
>
> Note: here we disable runtime PM and free the IRQ and this will
> make sure no further IRQs appear from this point.
>
> But clocks can still be running and resets can still be
> de-asserted because there is no guarantee that runtime
> suspend has executed just because we disable pm_runtime.
>
> > > > > mali_c55_media_frameworks_deinit(mali_c55);
> > > > > - if (!pm_runtime_suspended(&pdev->dev)) {
> > > > > + if (!pm_runtime_status_suspended(&pdev->dev)) {
> > > >
> > > > I guess this is required because you moved pm_runtime_disable() up
> > >
> > > The remove ordering is part of the IRQ lifetime change. Both runtime
> > > PM callbacks now assume the IRQ is installed, so we need to drain
> > > them befor free_irq(). Then free_irq() waits for the threaded handler
> > > before we unregister the media entities it uses.
> >
> > I'm sorry, this is certainly me missing some pm_runtime internals,
> > but where is this happening ?
>
> It's not a pm runtime thing more of a free_irq() thing,
> it will wait for outstanding threaded handlers to complete.
I see
>
> When we get here we know no further IRQs can happen, but we
> have no guarantee that runtime suspend has been called,
> so we check just like the old code did to make sure it
> gets de-clocked and resets are asserted.
>
> Compare with the old code:
>
> static void mali_c55_remove(struct platform_device *pdev)
> {
> struct mali_c55 *mali_c55 = platform_get_drvdata(pdev);
>
> mali_c55_media_frameworks_deinit(mali_c55);
> if (!pm_runtime_suspended(&pdev->dev)) {
> __mali_c55_power_off(mali_c55);
> pm_runtime_set_suspended(&pdev->dev);
> }
> pm_runtime_disable(&pdev->dev);
> kfree(mali_c55->context.registers);
> }
>
> Since IRQs are unregistered in the runtime suspend callback,
> this is not a problem here.
>
> > > That’s also why I switched to pm_runtime_status_suspended().
> > > It reports the actual status after pm_runtime_disable(), so we only
> > > power off the ISP if it’s still active.
> >
> > It seems to me pm_runtime_status_suspended() ignores the runtime
> > counter and is only there because you pm_runtime_disable() earlier ?
>
> Kind of, I guess it's a bad idea to free_irq() before disabling
> runtime PM?
>
> An alternative is to call pm_runtime_force_suspend() before
> free_irq() so you know for sure the device is powered off,
> I can try this if you like it better.
Reading the pm_runtime_force_suspend() documentation
* Typically this function may be invoked from a system suspend callback to make
* sure the device is put into low power state and it should only be used during
* system-wide PM transitions to sleep states. It assumes that the analogous
* pm_runtime_force_resume() will be used to resume the device.
Do you think it is appropriate at remove() ?
>
> Hm actually that would probably be better... shall I try that?
Is pm_runtime_force_suspend() different than open coding
pm_runtime_disable(&pdev->dev);
if (pm_runtime_status_suspended(&pdev->dev) {
__mali_c55_power_off(mali_c55);
pm_runtime_set_suspended(&pdev->dev);
}
free_irq(mali_c55->irqnum, &pdev->dev);
Is it different because of the dev_pm_enable_wake_irq_check() (which I
don't the purpose of) ?
Anyway the implementation of pm_runtime_force_suspend() calls
pm_runtime_disable() first as your patch does, and we're really
looking at details here. Also, I'm a bit out of my experties area
here, so whatever seems appropriate to you should be fine with me as
well.
Thanks
j
>
> Yours,
> Linus Walleij
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-23 11:12 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-27 14:08 [PATCH v2] media: mali-c55: Keep IRQ requested during suspend Linus Walleij
2026-11-05 8:07 ` Linus Walleij
2026-11-10 12:51 ` Jacopo Mondi
2026-11-23 0:29 ` Linus Walleij
2026-11-23 8:28 ` Jacopo Mondi
2026-11-23 10:38 ` Linus Walleij
2026-11-23 11:12 ` Jacopo Mondi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox