mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v4] media: qcom: iris: guard IRQ handler with runtime PM check
@ 2026-06-08  0:11 Hungyu Lin
  2026-06-08  7:54 ` Konrad Dybcio
  0 siblings, 1 reply; 4+ messages in thread
From: Hungyu Lin @ 2026-06-08  0:11 UTC (permalink / raw)
  To: linux-media
  Cc: vikash.garodia, dikshita.agarwal, abhinav.kumar, bod, mchehab,
	linux-arm-msm, linux-kernel, Hungyu Lin

Guard hardware register access in the threaded IRQ handler with
pm_runtime_get_if_active().

A possible ordering exists where the top-half IRQ handler returns
IRQ_WAKE_THREAD, runtime PM suspend powers down the VPU, and the
threaded IRQ handler subsequently runs and accesses hardware
registers through iris_vpu_clear_interrupt().

Avoid touching registers when the device is no longer active by
skipping interrupt processing when runtime PM indicates that the
device is suspended.

Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
---
v4:
- Clarify the possible ordering between IRQ_WAKE_THREAD,
  runtime PM suspend, and the threaded IRQ handler.
- Describe the race condition motivating the runtime PM check.

v3:
- Remove the early enable_irq() from the PM-inactive early-return path.
- IRQ re-enablement is already handled by iris_vpu_power_on() after power-on.

v2:
- Use pm_runtime_get_if_active() instead of pm_runtime_get_if_in_use().
- Handle negative runtime PM return values correctly.
- Return IRQ_NONE when interrupt processing is skipped.

 drivers/media/platform/qcom/iris/iris_hfi_common.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/media/platform/qcom/iris/iris_hfi_common.c b/drivers/media/platform/qcom/iris/iris_hfi_common.c
index 621c66593d88..ab2ec1e75309 100644
--- a/drivers/media/platform/qcom/iris/iris_hfi_common.c
+++ b/drivers/media/platform/qcom/iris/iris_hfi_common.c
@@ -100,10 +100,17 @@ irqreturn_t iris_hfi_isr(int irq, void *data)
 irqreturn_t iris_hfi_isr_handler(int irq, void *data)
 {
 	struct iris_core *core = data;
+	int ret;
 
 	if (!core)
 		return IRQ_NONE;
 
+	if (IS_ENABLED(CONFIG_PM)) {
+		ret = pm_runtime_get_if_active(core->dev);
+		if (ret <= 0)
+			return IRQ_NONE;
+	}
+
 	mutex_lock(&core->lock);
 	pm_runtime_mark_last_busy(core->dev);
 	iris_vpu_clear_interrupt(core);
@@ -111,6 +118,8 @@ irqreturn_t iris_hfi_isr_handler(int irq, void *data)
 
 	core->hfi_response_ops->hfi_response_handler(core);
 
+	pm_runtime_put_autosuspend(core->dev);
+
 	if (!iris_vpu_watchdog(core, core->intr_status))
 		enable_irq(irq);
 
-- 
2.34.1


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

* Re: [PATCH v4] media: qcom: iris: guard IRQ handler with runtime PM check
  2026-06-08  0:11 [PATCH v4] media: qcom: iris: guard IRQ handler with runtime PM check Hungyu Lin
@ 2026-06-08  7:54 ` Konrad Dybcio
  2026-06-08  8:28   ` Hungyu Lin
  0 siblings, 1 reply; 4+ messages in thread
From: Konrad Dybcio @ 2026-06-08  7:54 UTC (permalink / raw)
  To: Hungyu Lin, linux-media
  Cc: vikash.garodia, dikshita.agarwal, abhinav.kumar, bod, mchehab,
	linux-arm-msm, linux-kernel

On 6/8/26 2:11 AM, Hungyu Lin wrote:
> Guard hardware register access in the threaded IRQ handler with
> pm_runtime_get_if_active().
> 
> A possible ordering exists where the top-half IRQ handler returns
> IRQ_WAKE_THREAD, runtime PM suspend powers down the VPU, and the
> threaded IRQ handler subsequently runs and accesses hardware
> registers through iris_vpu_clear_interrupt().
> 
> Avoid touching registers when the device is no longer active by
> skipping interrupt processing when runtime PM indicates that the
> device is suspended.
> 
> Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
> ---

[...]

> --- a/drivers/media/platform/qcom/iris/iris_hfi_common.c
> +++ b/drivers/media/platform/qcom/iris/iris_hfi_common.c
> @@ -100,10 +100,17 @@ irqreturn_t iris_hfi_isr(int irq, void *data)
>  irqreturn_t iris_hfi_isr_handler(int irq, void *data)
>  {
>  	struct iris_core *core = data;
> +	int ret;
>  
>  	if (!core)
>  		return IRQ_NONE;
>  
> +	if (IS_ENABLED(CONFIG_PM)) {

I'm not sure this driver is much useful without CONFIG_PM

> +		ret = pm_runtime_get_if_active(core->dev);
> +		if (ret <= 0)
> +			return IRQ_NONE;
> +	}

Have you actually hit this issue, or is it purely theoretical? We
shouldn't be receiving interrupts at the tail end of suspend callbacks
(and there's a disable_irq_nosync() right after the HW is disabled)

Konrad

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

* Re: [PATCH v4] media: qcom: iris: guard IRQ handler with runtime PM check
  2026-06-08  7:54 ` Konrad Dybcio
@ 2026-06-08  8:28   ` Hungyu Lin
  2026-06-10 12:54     ` Konrad Dybcio
  0 siblings, 1 reply; 4+ messages in thread
From: Hungyu Lin @ 2026-06-08  8:28 UTC (permalink / raw)
  To: Konrad Dybcio
  Cc: linux-media, vikash.garodia, dikshita.agarwal, abhinav.kumar,
	bod, mchehab, linux-arm-msm, linux-kernel

> Have you actually hit this issue, or is it purely theoretical? We
> shouldn't be receiving interrupts at the tail end of suspend callbacks
> (and there's a disable_irq_nosync() right after the HW is disabled)

I have not observed this on hardware.

My concern comes from disable_irq_nosync().

Its documentation states that it does not ensure
existing instances of the IRQ handler have completed
before returning.

Given that, could a queued threaded handler still
execute after the VPU has been powered down?

Thanks,
Hungyu

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

* Re: [PATCH v4] media: qcom: iris: guard IRQ handler with runtime PM check
  2026-06-08  8:28   ` Hungyu Lin
@ 2026-06-10 12:54     ` Konrad Dybcio
  0 siblings, 0 replies; 4+ messages in thread
From: Konrad Dybcio @ 2026-06-10 12:54 UTC (permalink / raw)
  To: Hungyu Lin
  Cc: linux-media, vikash.garodia, dikshita.agarwal, abhinav.kumar,
	bod, mchehab, linux-arm-msm, linux-kernel

On 6/8/26 10:28 AM, Hungyu Lin wrote:
>> Have you actually hit this issue, or is it purely theoretical? We
>> shouldn't be receiving interrupts at the tail end of suspend callbacks
>> (and there's a disable_irq_nosync() right after the HW is disabled)
> 
> I have not observed this on hardware.
> 
> My concern comes from disable_irq_nosync().
> 
> Its documentation states that it does not ensure
> existing instances of the IRQ handler have completed
> before returning.

Then let's just replace disable_irq_nosync with disable_irq,
I think this will solve this issue

Konrad

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

end of thread, other threads:[~2026-06-10 12:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-08  0:11 [PATCH v4] media: qcom: iris: guard IRQ handler with runtime PM check Hungyu Lin
2026-06-08  7:54 ` Konrad Dybcio
2026-06-08  8:28   ` Hungyu Lin
2026-06-10 12:54     ` Konrad Dybcio

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®