Skip to contentSkip to conversation

media: qcom: iris: fix runtime PM reference handling

PATCH Superseded Hungyu Lin 3 participants 6 messages Jun 4 – Jun 7

Subsystems (4)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Hungyu Lin

author
#0 lore raw

v3 cover media: qcom: iris: fix runtime PM reference handling

This series fixes runtime PM handling in the iris driver.

Patch 1 fixes runtime PM reference leaks and balances runtime PM usage counts in the power domain enable/disable paths.

Patch 2 complements the first patch by rolling back the OPP vote when pm_runtime_resume_and_get() fails in iris_enable_power_domains().

Changes since v2:
- Convert the runtime PM fixes into a 2-patch series.
- Add a follow-up fix to roll back the OPP vote on pm_runtime_resume_and_get() failure.

Hungyu Lin (2):
media: qcom: iris: fix runtime PM reference leaks
media: qcom: iris: rollback OPP vote on PM resume failure

 drivers/media/platform/qcom/iris/iris_resources.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v3 1/2 media: qcom: iris: fix runtime PM reference leaks

Use pm_runtime_resume_and_get() in iris_enable_power_domains() to avoid leaking a runtime PM usage count on failure.

Also ensure pm_runtime_put_sync() is always called in iris_disable_power_domains(), even when iris_opp_set_rate() fails, so runtime PM references remain balanced.

Fixes bb8a95aa038e ("media: iris: implement power management")
---
 drivers/media/platform/qcom/iris/iris_resources.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/media/platform/qcom/iris/iris_resources.c +4 -6
index 773f6548370a..f5e3341e1430 100644
@@ -78,11 +78,11 @@ int iris_enable_power_domains(struct iris_core *core, struct device *pd_dev)
 	if (ret)
 		return ret;
 
-	ret = pm_runtime_get_sync(pd_dev);
-	if (ret < 0)
+	ret = pm_runtime_resume_and_get(pd_dev);
+	if (ret)
 		return ret;
 
-	return ret;
+	return 0;
 }
 
 int iris_disable_power_domains(struct iris_core *core, struct device *pd_dev)
@@ -90,12 +90,10 @@ int iris_disable_power_domains(struct iris_core *core, struct device *pd_dev)
 	int ret;
 
 	ret = iris_opp_set_rate(core->dev, 0);
-	if (ret)
-		return ret;
 
 	pm_runtime_put_sync(pd_dev);
 
-	return 0;
+	return ret;
 }
 
 static struct clk *iris_get_clk_by_type(struct iris_core *core, enum platform_clk_type clk_type)
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v3 1/2] media: qcom: iris: fix runtime PM reference leaks

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Asymmetric and incorrect teardown order in iris_vpu_power_off_hw().
- [High] Runtime PM reference count underflow due to unconditional pm_runtime_put_sync() calls. --

commit a22a4f4f739fd2c34235f6490e49b9bb97a0667e
Author: Hungyu Lin <[email protected]>

media: qcom: iris: fix runtime PM reference leaks

Use pm_runtime_resume_and_get() in iris_enable_power_domains() to avoid leaking a runtime PM usage count on failure.

Also ensure pm_runtime_put_sync() is always called in iris_disable_power_domains(), even when iris_opp_set_rate() fails, so runtime PM references remain balanced.

Quoted 21 lines
drivers/media/platform/qcom/iris/iris_resources.c +3 -3
index 773f6548370a2..f5e3341e14309 100644
@@ -78,11 +78,11 @@ int iris_enable_power_domains(struct iris_core *core, struct device *pd_dev)
 	if (ret)
 		return ret;
 
-	ret = pm_runtime_get_sync(pd_dev);
-	if (ret < 0)
+	ret = pm_runtime_resume_and_get(pd_dev);
+	if (ret)
 		return ret;
 
-	return ret;
+	return 0;
 }
 
 int iris_disable_power_domains(struct iris_core *core, struct device *pd_dev)
@@ -90,12 +90,10 @@ int iris_disable_power_domains(struct iris_core *core, struct device *pd_dev)
 	int ret;

drivers/media/platform/qcom/iris/iris_resources.c int iris_disable_power_domains(struct iris_core *core, struct device *pd_dev) · line 97

Quoted 10 lines
drivers/media/platform/qcom/iris/iris_resources.c +1 -3
 
 	ret = iris_opp_set_rate(core->dev, 0);
-	if (ret)
-		return ret;
 
 	pm_runtime_put_sync(pd_dev);
 
-	return 0;
+	return ret;
 }

[Severity: High]
This isn't a bug introduced by this patch, but while reviewing the runtime PM fixes, I noticed potential regressions due to unconditional pm_runtime_put_sync() calls when pm_runtime_resume_and_get() fails.

Looking at iris_hfi_queue_cmd_write() in drivers/media/platform/qcom/iris/iris_hfi_queue.c:

	ret = pm_runtime_resume_and_get(core->dev);
	if (ret < 0)
		goto exit;
	...
exit:
	pm_runtime_put_sync(core->dev);

	return ret;

Since pm_runtime_resume_and_get() automatically drops its usage counter increment and returns a negative error code upon failure, doesn't the unconditional pm_runtime_put_sync() call at the exit label cause an underflow of the PM usage counter?

A similar issue appears in iris_core_deinit() from drivers/media/platform/qcom/iris/iris_core.c:

	pm_runtime_resume_and_get(core->dev);

	mutex_lock(&core->lock);
	if (core->state != IRIS_CORE_DEINIT) {
		iris_fw_unload(core);
		...
		core->state = IRIS_CORE_DEINIT;
	}
	mutex_unlock(&core->lock);

	pm_runtime_put_sync(core->dev);

The return value of pm_runtime_resume_and_get() is ignored here, and pm_runtime_put_sync() is executed unconditionally at the end of the function.

Could this also underflow the counter on failure, breaking device power management balance and potentially causing the device to be powered off while actively in use?

[Severity: High]
This is a pre-existing issue, but I also noticed an asymmetric teardown order in iris_vpu_power_off_hw() from drivers/media/platform/qcom/iris/iris_vpu_common.c:

	dev_pm_genpd_set_hwmode(core->pmdomain_tbl->pd_devs[IRIS_HW_POWER_DOMAIN],
				false);
	iris_disable_power_domains(core,
				   core->pmdomain_tbl->pd_devs[IRIS_HW_POWER_DOMAIN]);
	iris_disable_unprepare_clock(core, IRIS_HW_AHB_CLK);
	iris_disable_unprepare_clock(core, IRIS_HW_CLK);

Does this code disable the power domain before disabling the corresponding hardware clocks?

This appears to contradict standard Qualcomm hardware power sequencing where clocks must remain enabled during the GDSC disable handshake. It also violates the symmetrical reverse order used in the error path of iris_vpu_power_on_hw().

Could disabling a power domain before its clocks result in hardware lockups, GDSC disable failures, or register access violations?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Reviewed-by on v3 1/2
#3 lore raw

Re: [PATCH v3 1/2] media: qcom: iris: fix runtime PM reference leaks

In reply to Hungyu Lin
Quoted 7 lines · Hungyu Lin

Use pm_runtime_resume_and_get() in iris_enable_power_domains() to avoid leaking a runtime PM usage count on failure.

Also ensure pm_runtime_put_sync() is always called in iris_disable_power_domains(), even when iris_opp_set_rate() fails, so runtime PM references remain balanced.

Quoted 6 lines
Fixes bb8a95aa038e ("media: iris: implement power management")
---
 drivers/media/platform/qcom/iris/iris_resources.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

Please take a look at Sashiko comments and fix those issues.

For the patch itself:

Signature · 2 lines
With best wishes
Dmitry
author
#4 lore raw

PATCH v3 2/2 media: qcom: iris: rollback OPP vote on PM resume failure

In reply to Hungyu Lin

Rollback the maximum OPP vote when
pm_runtime_resume_and_get() fails in
iris_enable_power_domains().

This ensures the performance state vote is released when power domain enablement does not complete successfully.

Fixes bb8a95aa038e ("media: iris: implement power management")
---
 drivers/media/platform/qcom/iris/iris_resources.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/media/platform/qcom/iris/iris_resources.c +3 -1
index f5e3341e1430..a7d25f7a201a 100644
@@ -79,8 +79,10 @@ int iris_enable_power_domains(struct iris_core *core, struct device *pd_dev)
 		return ret;
 
 	ret = pm_runtime_resume_and_get(pd_dev);
-	if (ret)
+	if (ret) {
+		iris_opp_set_rate(core->dev, 0);
 		return ret;
+	}
 
 	return 0;
 }
Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH v3 2/2] media: qcom: iris: rollback OPP vote on PM resume failure

Quoted 4 lines · Hungyu Lin

Rollback the maximum OPP vote when
pm_runtime_resume_and_get() fails in
iris_enable_power_domains().

Quoted 8 lines

This ensures the performance state vote is released when power domain enablement does not complete successfully.

Fixes bb8a95aa038e ("media: iris: implement power management")
---
 drivers/media/platform/qcom/iris/iris_resources.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Please implement standard rollback code, using goto's.

Quoted 20 lines
drivers/media/platform/qcom/iris/iris_resources.c +3 -1
index f5e3341e1430..a7d25f7a201a 100644
@@ -79,8 +79,10 @@ int iris_enable_power_domains(struct iris_core *core, struct device *pd_dev)
 		return ret;
 
 	ret = pm_runtime_resume_and_get(pd_dev);
-	if (ret)
+	if (ret) {
+		iris_opp_set_rate(core->dev, 0);
 		return ret;
+	}
 
 	return 0;
 }
Signature · 1 line
2.34.1
Signature · 2 lines
With best wishes
Dmitry