mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] media: renesas: rzv2h-ivc: stop interrupt before disabling clocks on suspend
@ 2026-12-03  8:53 Yaohan Li
  2026-12-03  9:19 ` Jacopo Mondi
  0 siblings, 1 reply; 2+ messages in thread
From: Yaohan Li @ 2026-12-03  8:53 UTC (permalink / raw)
  To: Daniel Scally, Jacopo Mondi, Mauro Carvalho Chehab
  Cc: Hans Verkuil, linux-media, linux-kernel

rzv2h_ivc_runtime_resume() enables the clocks, deasserts resets, unmasks
RZV2H_IVC_REG_FM_INT_EN, and finally requests ivc->irqnum.

rzv2h_ivc_runtime_suspend() tears these down in the wrong order: it
asserts resets and disables all three clocks while RZV2H_IVC_REG_FM_INT_EN
is still enabled and before calling free_irq().  If an interrupt arrives
or is still running during that window, rzv2h_ivc_isr() can call
rzv2h_ivc_transfer_buffer() and write MMIO registers while the block is
held in reset with its clocks gated.

Mask RZV2H_IVC_REG_FM_INT_EN and free ivc->irqnum before asserting resets
and disabling the clocks, matching the resume path in reverse.

Fixes: f0b3984d821b ("media: platform: Add Renesas Input Video Control block driver")
Cc: stable@vger.kernel.org
Signed-off-by: Yaohan Li <shunsheng1218@gmail.com>
---
Based on v7.4-rc5 (fe6ff8d5d675); applies cleanly on media-committers fixes
and next.  Scoped strictly to the rzv2h_ivc_runtime_suspend() teardown
order; active-remove / V4L2 lifetime is left untouched.

I don't have physical Renesas RZ/V2H hardware, so I tested this in QEMU
(x86_64, KASAN + PROVE_LOCKING) with the in-tree rzv2h-ivc.ko bound to a
platform device backed by reserved MMIO, three CCF clk_hw clocks, and a
virtual IRQ across 5 runtime suspend/resume and system force-suspend/resume
cycles (unmodified driver disables all three clocks while FM_INT_EN is still
set and ivc->irqnum is still bound; patched clears FM_INT_EN and frees the
IRQ first with 0 KASAN or lockdep warnings).  Also build-tested on x86_64
and arm64 with W=1 (0 warnings).

AI assistance: Claude and Gemini helped check the runtime PM ordering, write
the QEMU test module, and draft the changelog.  I reviewed the driver code,
test logs, and final patch myself.

 drivers/media/platform/renesas/rzv2h-ivc/rzv2h-ivc-dev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/renesas/rzv2h-ivc/rzv2h-ivc-dev.c b/drivers/media/platform/renesas/rzv2h-ivc/rzv2h-ivc-dev.c
index e2a14ebeb1141..937891e45e38b 100644
--- a/drivers/media/platform/renesas/rzv2h-ivc/rzv2h-ivc-dev.c
+++ b/drivers/media/platform/renesas/rzv2h-ivc/rzv2h-ivc-dev.c
@@ -164,9 +164,10 @@ static int rzv2h_ivc_runtime_suspend(struct device *dev)
 {
 	struct rzv2h_ivc *ivc = dev_get_drvdata(dev);
 
+	rzv2h_ivc_write(ivc, RZV2H_IVC_REG_FM_INT_EN, 0x0);
+	free_irq(ivc->irqnum, dev);
 	reset_control_bulk_assert(ARRAY_SIZE(ivc->resets), ivc->resets);
 	clk_bulk_disable_unprepare(ARRAY_SIZE(ivc->clks), ivc->clks);
-	free_irq(ivc->irqnum, dev);
 
 	return 0;
 }
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] media: renesas: rzv2h-ivc: stop interrupt before disabling clocks on suspend
  2026-12-03  8:53 [PATCH] media: renesas: rzv2h-ivc: stop interrupt before disabling clocks on suspend Yaohan Li
@ 2026-12-03  9:19 ` Jacopo Mondi
  0 siblings, 0 replies; 2+ messages in thread
From: Jacopo Mondi @ 2026-12-03  9:19 UTC (permalink / raw)
  To: Yaohan Li
  Cc: Daniel Scally, Jacopo Mondi, Mauro Carvalho Chehab, Hans Verkuil,
	linux-media, linux-kernel

On Thu, Dec 03, 2026 at 04:53:19PM +0800, Yaohan Li wrote:
> rzv2h_ivc_runtime_resume() enables the clocks, deasserts resets, unmasks
> RZV2H_IVC_REG_FM_INT_EN, and finally requests ivc->irqnum.
>
> rzv2h_ivc_runtime_suspend() tears these down in the wrong order: it
> asserts resets and disables all three clocks while RZV2H_IVC_REG_FM_INT_EN
> is still enabled and before calling free_irq().  If an interrupt arrives

How can an interrupt arrive ater the reset signal has been asserted ?

> or is still running during that window, rzv2h_ivc_isr() can call
> rzv2h_ivc_transfer_buffer() and write MMIO registers while the block is
> held in reset with its clocks gated.
>
> Mask RZV2H_IVC_REG_FM_INT_EN and free ivc->irqnum before asserting resets
> and disabling the clocks, matching the resume path in reverse.
>
> Fixes: f0b3984d821b ("media: platform: Add Renesas Input Video Control block driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Yaohan Li <shunsheng1218@gmail.com>
> ---
> Based on v7.4-rc5 (fe6ff8d5d675); applies cleanly on media-committers fixes
> and next.  Scoped strictly to the rzv2h_ivc_runtime_suspend() teardown
> order; active-remove / V4L2 lifetime is left untouched.
>
> I don't have physical Renesas RZ/V2H hardware, so I tested this in QEMU
> (x86_64, KASAN + PROVE_LOCKING) with the in-tree rzv2h-ivc.ko bound to a
> platform device backed by reserved MMIO, three CCF clk_hw clocks, and a
> virtual IRQ across 5 runtime suspend/resume and system force-suspend/resume
> cycles (unmodified driver disables all three clocks while FM_INT_EN is still
> set and ivc->irqnum is still bound; patched clears FM_INT_EN and frees the
> IRQ first with 0 KASAN or lockdep warnings).  Also build-tested on x86_64
> and arm64 with W=1 (0 warnings).
>
> AI assistance: Claude and Gemini helped check the runtime PM ordering, write
> the QEMU test module, and draft the changelog.  I reviewed the driver code,
> test logs, and final patch myself.
>
>  drivers/media/platform/renesas/rzv2h-ivc/rzv2h-ivc-dev.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/media/platform/renesas/rzv2h-ivc/rzv2h-ivc-dev.c b/drivers/media/platform/renesas/rzv2h-ivc/rzv2h-ivc-dev.c
> index e2a14ebeb1141..937891e45e38b 100644
> --- a/drivers/media/platform/renesas/rzv2h-ivc/rzv2h-ivc-dev.c
> +++ b/drivers/media/platform/renesas/rzv2h-ivc/rzv2h-ivc-dev.c
> @@ -164,9 +164,10 @@ static int rzv2h_ivc_runtime_suspend(struct device *dev)
>  {
>  	struct rzv2h_ivc *ivc = dev_get_drvdata(dev);
>
> +	rzv2h_ivc_write(ivc, RZV2H_IVC_REG_FM_INT_EN, 0x0);
> +	free_irq(ivc->irqnum, dev);
>  	reset_control_bulk_assert(ARRAY_SIZE(ivc->resets), ivc->resets);
>  	clk_bulk_disable_unprepare(ARRAY_SIZE(ivc->clks), ivc->clks);
> -	free_irq(ivc->irqnum, dev);
>
>  	return 0;
>  }
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-03  9:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-03  8:53 [PATCH] media: renesas: rzv2h-ivc: stop interrupt before disabling clocks on suspend Yaohan Li
2026-12-03  9:19 ` Jacopo Mondi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®