Skip to contentSkip to conversation

media: iris: fix deadlock in iris_pm_suspend() with threaded IRQ handler

PATCH In review Wangao Wang 2 participants 2 messages Nov 24 – Nov 25

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: iris: fix deadlock in iris_pm_suspend() with threaded IRQ handler

Commit b9c2215bdedc ("media: qcom: iris: use disable_irq() during power-off") replaced disable_irq_nosync() with disable_irq() in iris_vpu_power_off() to ensure the threaded IRQ handler completes before the VPU is powered down.

However, this introduced a deadlock. iris_pm_suspend() holds core->lock across the entire suspend sequence, and iris_hfi_isr_handler() must acquire the same lock before it can complete. Since disable_irq() blocks until the threaded handler finishes, the two contexts wait on each other indefinitely:

kworker (pm_runtime_work) iris_hfi_isr_handler (kthread)
------------------------- ------------------------------
mutex_lock(&core->lock)
iris_hfi_pm_suspend()
iris_vpu_power_off()
disable_irq() mutex_lock(&core->lock)
__synchronize_irq() [blocked: core->lock held
schedule() by kworker]
[blocked: waiting
for handler to finish]

This manifests as a hung task with kworker stuck in D state:

  INFO: task kworker/u33:8:178 blocked for more than 122 seconds.
  Call trace:
    __synchronize_irq+0xb8/0xf8
    disable_irq+0x60/0x88
    iris_vpu_power_off+0x6c/0xb0 [qcom_iris]
    iris_hfi_pm_suspend+0x44/0xa0 [qcom_iris]
    iris_pm_suspend+0x6c/0xa0 [qcom_iris]
    pm_generic_runtime_suspend+0x38/0x80
    rpm_suspend+0xec/0x6b8
    pm_runtime_work+0x118/0x128

Fix this by reverting iris_vpu_power_off() to disable_irq_nosync(), which prevents new IRQ deliveries without blocking, and adding synchronize_irq() in iris_pm_suspend() after core->lock is released. At that point, any in-flight threaded handler can acquire the lock, complete its work, and return, so synchronize_irq() is guaranteed to make forward progress.

Fixes b9c2215bdedc ("media: qcom: iris: use disable_irq() during power-off")
---
 drivers/media/platform/qcom/iris/iris_probe.c      | 10 ++++++++++
 drivers/media/platform/qcom/iris/iris_vpu_common.c |  2 +-
 2 files changed, 11 insertions(+), 1 deletion(-)
drivers/media/platform/qcom/iris/iris_probe.c +10 -0
index 343e44c6b9c46190a4fb3a0055ba012b16011235..5580094d427429d610d7d0aeb85582676312707a 100644
@@ -388,6 +388,16 @@ static int __maybe_unused iris_pm_suspend(struct device *dev)
 exit:
 	mutex_unlock(&core->lock);
 
+	/*
+	 * iris_vpu_power_off() uses disable_irq_nosync() to avoid a deadlock
+	 * where disable_irq() would wait for the threaded IRQ handler to finish,
+	 * while the threaded handler is itself blocked waiting for core->lock.
+	 * Synchronize here, after releasing the lock, to ensure any in-flight
+	 * threaded IRQ handler has completed before returning from suspend.
+	 */
+	if (!ret)
+		synchronize_irq(core->irq);
+
 	return ret;
 }
 
drivers/media/platform/qcom/iris/iris_vpu_common.c +1 -1
index 243bd845349fe7359d9616e12c83eef44ff8d55e..1e183fc4e58ceeca4e9b3cd103344f45a3d841c8 100644
@@ -240,7 +240,7 @@ void iris_vpu_power_off(struct iris_core *core)
 	iris_unset_icc_bw(core);
 
 	if (!iris_vpu_watchdog(core, core->intr_status))
-		disable_irq(core->irq);
+		disable_irq_nosync(core->irq);
 }
 
 int iris_vpu_power_on_controller(struct iris_core *core)

---
base-commit: 3191063649dbf7c0d0b768e1f3655e4c5fc6edb5
change-id: 20261124-disable_irq_fix-a042ac20facd

Best regards,

Signature · 1 line
Wangao Wang <[email protected]>
maintainer
#1 lore raw
Quoted 24 lines · Wangao Wang

Commit b9c2215bdedc ("media: qcom: iris: use disable_irq() during power-off") replaced disable_irq_nosync() with disable_irq() in iris_vpu_power_off() to ensure the threaded IRQ handler completes before the VPU is powered down.

However, this introduced a deadlock. iris_pm_suspend() holds core->lock across the entire suspend sequence, and iris_hfi_isr_handler() must acquire the same lock before it can complete. Since disable_irq() blocks until the threaded handler finishes, the two contexts wait on each other indefinitely:

   kworker (pm_runtime_work)         iris_hfi_isr_handler (kthread)
   -------------------------         ------------------------------
   mutex_lock(&core->lock)
     iris_hfi_pm_suspend()
       iris_vpu_power_off()
         disable_irq()                 mutex_lock(&core->lock)
           __synchronize_irq()         [blocked: core->lock held
             schedule()                 by kworker]
             [blocked: waiting
               for handler to finish]

This manifests as a hung task with kworker stuck in D state:

Quoted 10 lines
   INFO: task kworker/u33:8:178 blocked for more than 122 seconds.
   Call trace:
     __synchronize_irq+0xb8/0xf8
     disable_irq+0x60/0x88
     iris_vpu_power_off+0x6c/0xb0 [qcom_iris]
     iris_hfi_pm_suspend+0x44/0xa0 [qcom_iris]
     iris_pm_suspend+0x6c/0xa0 [qcom_iris]
     pm_generic_runtime_suspend+0x38/0x80
     rpm_suspend+0xec/0x6b8
     pm_runtime_work+0x118/0x128

This is fixed with, pls apply the same for your issue.

https://lore.kernel.org/all/[email protected]/