media: renesas: rzv2h-ivc: stop interrupt before disabling clocks on suspend
PATCH 1/1 media: renesas: rzv2h-ivc: stop interrupt before disabling clocks on suspend
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.
---
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(-)
drivers/media/platform/renesas/rzv2h-ivc/rzv2h-ivc-dev.c +2 -1
@@ -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 ; }
Signature · 1 line
2.34.1
Jacopo Mondi
maintainerQuoted 6 lines · Yaohan Li
rzv2h_ivc_runtime_resume()enables the clocks, deasserts resets, unmasksRZV2H_IVC_REG_FM_INT_EN, and finally requestsivc->irqnum.
rzv2h_ivc_runtime_suspend()tears these down in the wrong order: it asserts resets and disables all three clocks whileRZV2H_IVC_REG_FM_INT_ENis still enabled and before callingfree_irq(). If an interrupt arrives
How can an interrupt arrive ater the reset signal has been asserted ?
Quoted 50 lines
or is still running during that window,
rzv2h_ivc_isr()can callrzv2h_ivc_transfer_buffer()and write MMIO registers while the block is held in reset with its clocks gated.Mask
RZV2H_IVC_REG_FM_INT_ENand freeivc->irqnumbefore asserting resets and disabling the clocks, matching the resume path in reverse.Fixes f0b3984d821b ("media: platform: Add Renesas Input Video Control block driver")Signed-off-by Yaohan Li <[email protected]>---
Based on v7.4-rc5 (fe6ff8d5d675); applies cleanly on media-committers fixes and next. Scoped strictly to therzv2h_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 CCFclk_hwclocks, and a virtual IRQ across 5 runtime suspend/resume and system force-suspend/resume cycles (unmodified driver disables all three clocks whileFM_INT_ENis still set andivc->irqnumis still bound; patched clearsFM_INT_ENand frees the IRQ first with 0 KASAN or lockdep warnings). Also build-tested onx86_64and 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(-)drivers/media/platform/renesas/rzv2h-ivc/rzv2h-ivc-dev.c +2
-2@@ -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
Hi Jacopo,
Quoted 6 lines · Jacopo Mondi
Quoted 3 lines · Yaohan Li
rzv2h_ivc_runtime_suspend()tears these down in the wrong order: it asserts resets and disables all three clocks whileRZV2H_IVC_REG_FM_INT_ENis still enabled and before callingfree_irq(). If an interrupt arrivesHow can an interrupt arrive ater the reset signal has been asserted ?
You're right -- saying a new interrupt could arrive after reset was imprecise.
My concern is an interrupt handler that is already running on another CPU when runtime_suspend() asserts the resets and disables the clocks. Since free_irq() currently runs after both, nothing waits for an in-flight handler before the clocks are gated.
Also, the driver gets shared resets via devm_reset_control_bulk_get_optional_shared(), so asserting them does not necessarily assert the physical reset line if another consumer still holds it deasserted.
My QEMU test only checks the teardown order, not real RZ/V2H interrupt behavior. Does the streaming stop path already guarantee that no handler can still be running when runtime_suspend() is entered?
Thanks,
Yaohan