Skip to contentSkip to conversation

media: qcom: iris: guard IRQ handler with runtime PM check

PATCH Superseded Hungyu Lin 2 participants 2 messages Jun 4

Subsystems (4)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Hungyu Lin

author
#0 lore raw

PATCH 1/1 media: qcom: iris: guard IRQ handler with runtime PM check

Use pm_runtime_get_if_in_use() before accessing hardware registers in the threaded IRQ handler. Skip interrupt processing when the device is not in use.

---
 drivers/media/platform/qcom/iris/iris_hfi_common.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/media/platform/qcom/iris/iris_hfi_common.c +7 -0
index 621c66593d88..ffb2e65f90f8 100644
@@ -104,6 +104,11 @@ irqreturn_t iris_hfi_isr_handler(int irq, void *data)
 	if (!core)
 		return IRQ_NONE;
 
+	if (!pm_runtime_get_if_in_use(core->dev)) {
+		enable_irq(irq);
+		return IRQ_HANDLED;
+	}
+
 	mutex_lock(&core->lock);
 	pm_runtime_mark_last_busy(core->dev);
 	iris_vpu_clear_interrupt(core);
@@ -111,6 +116,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
#1 lore raw
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] Using `pm_runtime_get_if_in_use()` instead of `pm_runtime_get_if_active()` in the IRQ handler…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Using pm_runtime_get_if_in_use() instead of pm_runtime_get_if_active() in the IRQ handler causes missed interrupts and IRQ storms during the autosuspend window.
- [High] The boolean NOT operator (!) mishandles negative error returns from the PM runtime API, leading to hardware access when suspended and usage counter underflows.
- [High] Returning IRQ_HANDLED when skipping interrupt processing on the early exit path defeats the kernel's spurious interrupt detection mechanism. --

commit 576f1f875241104f6f3a35d723ea4b7f5bb6ff29
Author: Hungyu Lin <[email protected]>

media: qcom: iris: guard IRQ handler with runtime PM check

This commit adds a runtime PM check before accessing hardware registers in the threaded IRQ handler, skipping processing when the device is not in use.

drivers/media/platform/qcom/iris/iris_hfi_common.c irqreturn_t iris_hfi_isr_handler(int irq, void *data) · line 107

Quoted 9 lines
drivers/media/platform/qcom/iris/iris_hfi_common.c +1 -0
index 621c66593d88d..ffb2e65f90f86 100644
@@ -104,6 +104,11 @@ irqreturn_t iris_hfi_isr_handler(int irq, void *data)
 	if (!core)
 		return IRQ_NONE;
 
+	if (!pm_runtime_get_if_in_use(core->dev)) {

[Severity: High]
Does the logical NOT operator correctly handle negative error codes here?

If runtime PM is disabled (such as during system suspend or driver unbind), the API returns -EINVAL. Since !(-EINVAL) evaluates to false, wouldn't the handler bypass this early return entirely?

This would cause the handler to proceed and access potentially unpowered hardware, and later cause a usage counter underflow when unconditionally calling pm_runtime_put_autosuspend() at the end of the function since the counter was never incremented.

Could the return value be assigned to an integer and checked with <= 0 instead?

[Severity: High]
Is pm_runtime_get_if_in_use() the right API here rather than pm_runtime_get_if_active()?

The driver uses pm_runtime_put_autosuspend(), which drops the usage count to 0 but keeps the device in an active power state until the delay timer expires.

If a valid hardware interrupt fires during this autosuspend window, pm_runtime_get_if_in_use() will return 0 because the usage count is 0.

Would this cause the handler to incorrectly assume the device is inactive, skip clearing the interrupt, and exit? Because the interrupt is never cleared, wouldn't it immediately re-fire and cause an IRQ storm?

drivers/media/platform/qcom/iris/iris_hfi_common.c irqreturn_t iris_hfi_isr_handler(int irq, void *data) · line 109

Quoted 2 lines
drivers/media/platform/qcom/iris/iris_hfi_common.c +2 -0
+		enable_irq(irq);
+		return IRQ_HANDLED;

[Severity: High]
Should this return IRQ_NONE instead of IRQ_HANDLED?

If the PM check correctly determines that the device is inactive, the device could not have generated the interrupt.

By returning IRQ_HANDLED, does this falsely claim ownership of a spurious interrupt, preventing the kernel's "nobody cared" mechanism from automatically disabling the faulty IRQ line?

Quoted 4 lines
drivers/media/platform/qcom/iris/iris_hfi_common.c +2 -0
+	}
+
 	mutex_lock(&core->lock);
 	pm_runtime_mark_last_busy(core->dev);

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1