media: qcom: iris: guard IRQ handler with runtime PM check
Subsystems (4)
PATCH v2 1/1 media: qcom: iris: guard IRQ handler with runtime PM check
Use pm_runtime_get_if_active() before accessing hardware registers in the threaded IRQ handler. Skip interrupt processing when the device is not active.
---
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(+)
drivers/media/platform/qcom/iris/iris_hfi_common.c +9 -0
@@ -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 ; + ret =pm_runtime_get_if_active (core->dev); +if (ret <=0 ) { +enable_irq (irq); +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);
Signature · 1 line
2.34.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [Critical] Unmasking a level-triggered IRQ without clearing the interrupt source when pm_runtime_get_if_active() returns <= 0 causes an infinite interrupt storm and potential system deadlock.
- [High] core->intr_status is read locklessly after dropping the Runtime PM reference, causing a race that leads to unbalanced enable_irq() and potentially missing watchdog errors.
Pre-existing issues:
- [High] Missing cancel_delayed_work_sync() for sys_error_handler in driver removal path leads to Use-After-Free. --
commit 0c8846847b29684af89fca24c8cacbe7c8cb8ceb
Author: Hungyu Lin <[email protected]>
media: qcom: iris: guard IRQ handler with runtime PM check
This commit adds a runtime PM check to the threaded IRQ handler using pm_runtime_get_if_active(). It skips interrupt processing if the device is not active, preventing hardware access on suspended devices.
Quoted 9 lines
drivers/media/platform/qcom/iris/iris_hfi_common.c +1
-0@@ -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;
drivers/media/platform/qcom/iris/iris_hfi_common.c irqreturn_t iris_hfi_isr(int irq, void *data) · line 113
Quoted 10 lines
drivers/media/platform/qcom/iris/iris_hfi_common.c +6
-0if (!core)return IRQ_NONE ; + ret =pm_runtime_get_if_active (core->dev); +if (ret <=0 ) { +enable_irq (irq); +return IRQ_NONE ; + } +
[Severity: Critical]
Is it safe to unmask the IRQ without clearing the hardware source first?
Because the interrupt is level-triggered, if pm_runtime_get_if_active() bails out (for instance, during RPM_RESUMING transitions or if CONFIG_PM is disabled), calling enable_irq() without clearing the interrupt via iris_vpu_clear_interrupt() might trigger an immediate interrupt storm.
Would this cause the CPU to lock up in an infinite loop?
Quoted 3 lines
drivers/media/platform/qcom/iris/iris_hfi_common.c +0
-0mutex_lock (&core->lock);pm_runtime_mark_last_busy (core->dev);iris_vpu_clear_interrupt (core);
[ ... ]
drivers/media/platform/qcom/iris/iris_hfi_common.c irqreturn_t iris_hfi_isr_handler(int irq, void *data) · line 125
Quoted 9 lines
drivers/media/platform/qcom/iris/iris_hfi_common.c +2
-0@@ -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);
[Severity: High]
Does dropping the runtime PM reference before checking core->intr_status introduce a race condition?
If the device autosuspends immediately after pm_runtime_put_autosuspend() and is concurrently resumed, the resume path could clear core->intr_status and call enable_irq() before iris_vpu_watchdog() runs here.
If the threaded handler then reads the newly cleared core->intr_status (0), would it execute an unbalanced enable_irq() and potentially miss watchdog errors?
Quoted 2 lines
drivers/media/platform/qcom/iris/iris_probe.c +0
-0
[ ... ]
Quoted 17 lines
static void
iris_remove(struct platform_device *pdev){ struct iris_core *core; core = platform_get_drvdata(pdev); if (!core) return; iris_core_deinit(core); video_unregister_device(core->vdev_dec); video_unregister_device(core->vdev_enc); v4l2_device_unregister(&core->v4l2_dev); mutex_destroy(&core->lock); }
[Severity: High]
This isn't a bug introduced by this patch, but does iris_remove() need to call cancel_delayed_work_sync() for sys_error_handler before destroying the lock and returning?
Because the core structure is allocated with devm_kzalloc, devres will free it after iris_remove() completes. If there is pending sys_error_handler work, could it execute after the memory is freed or the mutex is destroyed, leading to a use-after-free?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1