Skip to contentSkip to conversation

accel/amdxdna: fix usage_count leak when autosuspend_delay is negative

PATCH In review Guangshuo Li 3 participants 3 messages Aug 7 – Aug 18

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

PATCH 1/1 accel/amdxdna: fix usage_count leak when autosuspend_delay is negative

amdxdna_pm_init() calls pm_runtime_use_autosuspend(), but amdxdna_pm_fini() does not call the matching pm_runtime_dont_use_autosuspend() when tearing down runtime PM.

If autosuspend_delay is set to a negative value while autosuspend is enabled, the runtime PM core increments usage_count to prevent runtime suspend. Without calling pm_runtime_dont_use_autosuspend() during driver teardown, this reference is not dropped and usage_count remains unbalanced.

Add the missing pm_runtime_dont_use_autosuspend() call in amdxdna_pm_fini() before restoring the runtime PM usage reference and forbidding runtime PM.

This issue was found by manual code inspection.

Fixes 063db451832b ("accel/amdxdna: Enhance runtime power management")
---
 drivers/accel/amdxdna/amdxdna_pm.c | 1 +
 1 file changed, 1 insertion(+)
drivers/accel/amdxdna/amdxdna_pm.c +1 -0
index b1fafddd7ad5..7dcedb7c105f 100644
@@ -73,6 +73,7 @@ void amdxdna_pm_fini(struct amdxdna_dev *xdna)
 {
 	struct device *dev = xdna->ddev.dev;
 
+	pm_runtime_dont_use_autosuspend(dev);
 	pm_runtime_get_noresume(dev);
 	pm_runtime_forbid(dev);
 }
Signature · 1 line
2.43.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

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

Pre-existing issues:
- [High] Deadlock during device teardown due to synchronous runtime PM resume while holding dev_lock --

--- Patch [1]: [PATCH] accel/amdxdna: fix usage_count leak when autosuspend_delay is negative --- commit 31ff9d16b70b74f4b276ff67df887f4acb154424
Author: Guangshuo Li <[email protected]>

accel/amdxdna: fix usage_count leak when autosuspend_delay is negative

This commit fixes a usage_count leak when autosuspend_delay is negative by adding a missing pm_runtime_dont_use_autosuspend() call during driver teardown in amdxdna_pm_fini().

drivers/accel/amdxdna/amdxdna_pm.c void amdxdna_pm_fini(struct amdxdna_dev *xdna) · line 78

Quoted 11 lines
drivers/accel/amdxdna/amdxdna_pm.c +1 -0
index b1fafddd7ad59..7dcedb7c105f2 100644
@@ -73,6 +73,7 @@ void amdxdna_pm_fini(struct amdxdna_dev *xdna)
 {
 	struct device *dev = xdna->ddev.dev;
 
+	pm_runtime_dont_use_autosuspend(dev);
 	pm_runtime_get_noresume(dev);
 	pm_runtime_forbid(dev);

[Severity: High]
This is a pre-existing issue, but does calling pm_runtime_forbid() here cause a self-deadlock during device teardown?

If the device is in the RPM_SUSPENDED state when driver unbind occurs, amdxdna_remove() acquires dev_lock before starting the teardown chain:

drivers/accel/amdxdna/amdxdna_pci_drv.c:amdxdna_remove() {
    mutex_lock(&xdna->dev_lock);
    ...
    xdna->dev_info->ops->fini(xdna);
    ...
}

The teardown chain eventually reaches amdxdna_pm_fini(). Calling pm_runtime_forbid() triggers a synchronous resume, which in turn invokes the driver's resume callback. The resume callback then attempts to acquire the exact same lock:

drivers/accel/amdxdna/amdxdna_pm.c:amdxdna_pm_resume() {
    guard(mutex)(&xdna->dev_lock);
    ...
}

Could this sequence cause the unbind thread to hang indefinitely waiting for xdna->dev_lock?

Quoted 1 line
drivers/accel/amdxdna/amdxdna_pm.c +0 -0
 }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Guangshuo Li
Quoted 9 lines · Guangshuo Li

amdxdna_pm_init() calls pm_runtime_use_autosuspend(), but amdxdna_pm_fini() does not call the matching pm_runtime_dont_use_autosuspend() when tearing down runtime PM.

If autosuspend_delay is set to a negative value while autosuspend is enabled, the runtime PM core increments usage_count to prevent runtime suspend. Without calling pm_runtime_dont_use_autosuspend() during driver teardown, this reference is not dropped and usage_count remains unbalanced.

As I've explained elsewhere, this is just misleading. There is no usage count leak here as the count is balanced whenever the user re-enables autosuspend through sysfs (by writing a non-negative timeout).

Drivers should clean up after themselves and disable autosuspend, but this is more of a clean up than a fix and should not be backported.

You've sent upwards of 60 of these in the matter of just a few days, some of which have even been picked up. Please send follow-ups (replies or v2s) as soon as possible to prevent further of these from getting merged.

Quoted 8 lines

Add the missing pm_runtime_dont_use_autosuspend() call in amdxdna_pm_fini() before restoring the runtime PM usage reference and forbidding runtime PM.

This issue was found by manual code inspection.

Fixes 063db451832b ("accel/amdxdna: Enhance runtime power management")

Johan