Skip to content

Commit 85bc48d

Browse files
committed
PM: Block enabling of runtime PM during system suspend
JIRA: https://issues.redhat.com/browse/RHEL-80696 commit 3e5eee1 Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Date: Tue Feb 18 21:11:42 2025 +0100 If device_prepare() runs on a device that has never had runtime PM enabled so far, it may reasonably assume that runtime PM will not be enabled for that device during the system suspend-resume cycle currently in progress, but this has never been guaranteed. To verify this assumption, make device_prepare() arrange for triggering a device warning accompanied by a call trace dump if runtime PM is enabled for such a device after it has returned. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org> Link: https://patch.msgid.link/6131109.lOV4Wx5bFT@rjwysocki.net Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
1 parent d93f607 commit 85bc48d

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

drivers/base/power/main.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,8 @@ static void device_complete(struct device *dev, pm_message_t state)
11071107
device_unlock(dev);
11081108

11091109
out:
1110+
/* If enabling runtime PM for the device is blocked, unblock it. */
1111+
pm_runtime_unblock(dev);
11101112
pm_runtime_put(dev);
11111113
}
11121114

@@ -1850,6 +1852,13 @@ static int device_prepare(struct device *dev, pm_message_t state)
18501852
* it again during the complete phase.
18511853
*/
18521854
pm_runtime_get_noresume(dev);
1855+
/*
1856+
* If runtime PM is disabled for the device at this point and it has
1857+
* never been enabled so far, it should not be enabled until this system
1858+
* suspend-resume cycle is complete, so prepare to trigger a warning on
1859+
* subsequent attempts to enable it.
1860+
*/
1861+
pm_runtime_block_if_disabled(dev);
18531862

18541863
if (dev->power.syscore)
18551864
return 0;

drivers/base/power/runtime.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,6 +1460,26 @@ int pm_runtime_barrier(struct device *dev)
14601460
}
14611461
EXPORT_SYMBOL_GPL(pm_runtime_barrier);
14621462

1463+
void pm_runtime_block_if_disabled(struct device *dev)
1464+
{
1465+
spin_lock_irq(&dev->power.lock);
1466+
1467+
if (dev->power.disable_depth && dev->power.last_status == RPM_INVALID)
1468+
dev->power.last_status = RPM_BLOCKED;
1469+
1470+
spin_unlock_irq(&dev->power.lock);
1471+
}
1472+
1473+
void pm_runtime_unblock(struct device *dev)
1474+
{
1475+
spin_lock_irq(&dev->power.lock);
1476+
1477+
if (dev->power.last_status == RPM_BLOCKED)
1478+
dev->power.last_status = RPM_INVALID;
1479+
1480+
spin_unlock_irq(&dev->power.lock);
1481+
}
1482+
14631483
void __pm_runtime_disable(struct device *dev, bool check_resume)
14641484
{
14651485
spin_lock_irq(&dev->power.lock);
@@ -1518,6 +1538,10 @@ void pm_runtime_enable(struct device *dev)
15181538
if (--dev->power.disable_depth > 0)
15191539
goto out;
15201540

1541+
if (dev->power.last_status == RPM_BLOCKED) {
1542+
dev_warn(dev, "Attempt to enable runtime PM when it is blocked\n");
1543+
dump_stack();
1544+
}
15211545
dev->power.last_status = RPM_INVALID;
15221546
dev->power.accounting_timestamp = ktime_get_mono_fast_ns();
15231547

include/linux/pm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ enum rpm_status {
600600
RPM_RESUMING,
601601
RPM_SUSPENDED,
602602
RPM_SUSPENDING,
603+
RPM_BLOCKED,
603604
};
604605

605606
/*

include/linux/pm_runtime.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ extern int pm_runtime_get_if_in_use(struct device *dev);
7777
extern int pm_schedule_suspend(struct device *dev, unsigned int delay);
7878
extern int __pm_runtime_set_status(struct device *dev, unsigned int status);
7979
extern int pm_runtime_barrier(struct device *dev);
80+
extern void pm_runtime_block_if_disabled(struct device *dev);
81+
extern void pm_runtime_unblock(struct device *dev);
8082
extern void pm_runtime_enable(struct device *dev);
8183
extern void __pm_runtime_disable(struct device *dev, bool check_resume);
8284
extern void pm_runtime_allow(struct device *dev);
@@ -271,6 +273,8 @@ static inline int pm_runtime_get_if_active(struct device *dev)
271273
static inline int __pm_runtime_set_status(struct device *dev,
272274
unsigned int status) { return 0; }
273275
static inline int pm_runtime_barrier(struct device *dev) { return 0; }
276+
static inline void pm_runtime_block_if_disabled(struct device *dev) {}
277+
static inline void pm_runtime_unblock(struct device *dev) {}
274278
static inline void pm_runtime_enable(struct device *dev) {}
275279
static inline void __pm_runtime_disable(struct device *dev, bool c) {}
276280
static inline void pm_runtime_allow(struct device *dev) {}

0 commit comments

Comments
 (0)