Skip to content

Commit 8873710

Browse files
committed
PM: runtime: Fix supplier device management during consumer probe
Because pm_runtime_get_suppliers() bumps up the rpm_active counter of each device link to a supplier of the given device in addition to bumping up the supplier's PM-runtime usage counter, a runtime suspend of the consumer device may case the latter to go down to 0 when pm_runtime_put_suppliers() is running on a remote CPU. If that happens after pm_runtime_put_suppliers() has released power.lock for the consumer device, and a runtime resume of that device takes place immediately after it, before pm_runtime_put() is called for the supplier, that pm_runtime_put() call may cause the supplier to be suspended even though the consumer is active. To prevent that from happening, modify pm_runtime_get_suppliers() to call pm_runtime_get_sync() for the given device's suppliers without touching the rpm_active counters of the involved device links Accordingly, modify pm_runtime_put_suppliers() to call pm_runtime_put() for the given device's suppliers without looking at the rpm_active counters of the device links at hand. [This is analogous to what happened before commit 4c06c4e ("driver core: Fix possible supplier PM-usage counter imbalance").] Since pm_runtime_get_suppliers() sets supplier_preactivated for each device link where the supplier's PM-runtime usage counter has been incremented and pm_runtime_put_suppliers() calls pm_runtime_put() for the suppliers whose device links have supplier_preactivated set, the PM-runtime usage counter is balanced for each supplier and this is independent of the runtime suspend and resume of the consumer device. However, in case a device link with DL_FLAG_PM_RUNTIME set is dropped during the consumer device probe, so pm_runtime_get_suppliers() bumps up the supplier's PM-runtime usage counter, but it cannot be dropped by pm_runtime_put_suppliers(), make device_link_release_fn() take care of that. Fixes: 4c06c4e ("driver core: Fix possible supplier PM-usage counter imbalance") Reported-by: Peter Wang <peter.wang@mediatek.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: Peter Wang <peter.wang@mediatek.com> Cc: 5.1+ <stable@vger.kernel.org> # 5.1+
1 parent 0735819 commit 8873710

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

drivers/base/core.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,16 @@ static void device_link_release_fn(struct work_struct *work)
487487
device_link_synchronize_removal();
488488

489489
pm_runtime_release_supplier(link);
490+
/*
491+
* If supplier_preactivated is set, the link has been dropped between
492+
* the pm_runtime_get_suppliers() and pm_runtime_put_suppliers() calls
493+
* in __driver_probe_device(). In that case, drop the supplier's
494+
* PM-runtime usage counter to remove the reference taken by
495+
* pm_runtime_get_suppliers().
496+
*/
497+
if (link->supplier_preactivated)
498+
pm_runtime_put_noidle(link->supplier);
499+
490500
pm_request_idle(link->supplier);
491501

492502
put_device(link->consumer);

drivers/base/power/runtime.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,7 +1768,6 @@ void pm_runtime_get_suppliers(struct device *dev)
17681768
if (link->flags & DL_FLAG_PM_RUNTIME) {
17691769
link->supplier_preactivated = true;
17701770
pm_runtime_get_sync(link->supplier);
1771-
refcount_inc(&link->rpm_active);
17721771
}
17731772

17741773
device_links_read_unlock(idx);
@@ -1788,19 +1787,8 @@ void pm_runtime_put_suppliers(struct device *dev)
17881787
list_for_each_entry_rcu(link, &dev->links.suppliers, c_node,
17891788
device_links_read_lock_held())
17901789
if (link->supplier_preactivated) {
1791-
bool put;
1792-
17931790
link->supplier_preactivated = false;
1794-
1795-
spin_lock_irq(&dev->power.lock);
1796-
1797-
put = pm_runtime_status_suspended(dev) &&
1798-
refcount_dec_not_one(&link->rpm_active);
1799-
1800-
spin_unlock_irq(&dev->power.lock);
1801-
1802-
if (put)
1803-
pm_runtime_put(link->supplier);
1791+
pm_runtime_put(link->supplier);
18041792
}
18051793

18061794
device_links_read_unlock(idx);

0 commit comments

Comments
 (0)