From: "Rafael J. Wysocki" <rafael@kernel.org>
To: Ulf Hansson <ulf.hansson@linaro.org>,
Rose Wu <ya-jou.wu@mediatek.com>,
linux-pm@vger.kernel.org
Cc: rafael.j.wysocki@intel.com, regressions@lists.linux.dev,
linux-kernel@vger.kernel.org,
wsd_upstream <wsd_upstream@mediatek.com>,
linux-mediatek@lists.infradead.org,
"artis. chiu" <artis.chiu@mediatek.com>,
"Johnny-cc. Kao" <Johnny-cc.Kao@mediatek.com>
Subject: [PATCH v4] PM: sleep: core: Fix runtime PM enabling in device_resume_early()
Date: Tue, 18 Nov 2025 15:16:04 +0100 [thread overview]
Message-ID: <12784270.O9o76ZdvQC@rafael.j.wysocki> (raw)
In-Reply-To: <5941318.DvuYhMxLoT@rafael.j.wysocki>
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Runtime PM should only be enabled in device_resume_early() if it has
been disabled for the given device by device_suspend_late(). Otherwise,
it may cause runtime PM callbacks to run prematurely in some cases
which leads to further functional issues.
Make two changes to address this problem.
First, reorder device_suspend_late() to only disable runtime PM for a
device when it is going to look for the device's callback or if the
device is a "syscore" one. In all of the other cases, disabling runtime
PM for the device is not in fact necessary. However, if the device's
callback returns an error and the power.is_late_suspended flag is not
going to be set, enable runtime PM so it only remains disabled when
power.is_late_suspended is set.
Second, make device_resume_early() only enable runtime PM for the
devices with the power.is_late_suspended flag set.
Fixes: 443046d1ad66 ("PM: sleep: Make suspend of devices more asynchronous")
Reported-by: Rose Wu <ya-jou.wu@mediatek.com>
Closes: https://lore.kernel.org/linux-pm/70b25dca6f8c2756d78f076f4a7dee7edaaffc33.camel@mediatek.com/
Cc: 6.16+ <stable@vger.kernel.org> # 6.16+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
v3 -> v4:
* Reorder the syscore check in device_resume_early() after the
is_late_suspended check (Ulf)
* Update the changelog to reflect the above.
v2 -> v3:
* Also set is_late_suspended for syscore devices to avoid skipping runtime PM
disabling for them (Ulf).
* Update the changelog to reflect the above.
v1 -> v2:
* Add pm_runtime_enable() to device_suspend_late() error path (Rose).
* Update the changelog to reflect the above.
---
drivers/base/power/main.c | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -903,12 +903,15 @@ static void device_resume_early(struct d
TRACE_DEVICE(dev);
TRACE_RESUME(0);
- if (dev->power.syscore || dev->power.direct_complete)
+ if (dev->power.direct_complete)
goto Out;
if (!dev->power.is_late_suspended)
goto Out;
+ if (dev->power.syscore)
+ goto Skip;
+
if (!dpm_wait_for_superior(dev, async))
goto Out;
@@ -941,11 +944,11 @@ Run:
Skip:
dev->power.is_late_suspended = false;
+ pm_runtime_enable(dev);
Out:
TRACE_RESUME(error);
- pm_runtime_enable(dev);
complete_all(&dev->power.completion);
if (error) {
@@ -1630,12 +1633,6 @@ static void device_suspend_late(struct d
TRACE_DEVICE(dev);
TRACE_SUSPEND(0);
- /*
- * Disable runtime PM for the device without checking if there is a
- * pending resume request for it.
- */
- __pm_runtime_disable(dev, false);
-
dpm_wait_for_subordinate(dev, async);
if (READ_ONCE(async_error))
@@ -1646,9 +1643,18 @@ static void device_suspend_late(struct d
goto Complete;
}
- if (dev->power.syscore || dev->power.direct_complete)
+ if (dev->power.direct_complete)
goto Complete;
+ /*
+ * Disable runtime PM for the device without checking if there is a
+ * pending resume request for it.
+ */
+ __pm_runtime_disable(dev, false);
+
+ if (dev->power.syscore)
+ goto Skip;
+
if (dev->pm_domain) {
info = "late power domain ";
callback = pm_late_early_op(&dev->pm_domain->ops, state);
@@ -1679,6 +1685,7 @@ Run:
WRITE_ONCE(async_error, error);
dpm_save_failed_dev(dev_name(dev));
pm_dev_err(dev, state, async ? " async late" : " late", error);
+ pm_runtime_enable(dev);
goto Complete;
}
dpm_propagate_wakeup_to_parent(dev);
next prev parent reply other threads:[~2025-11-18 14:16 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-17 9:31 [REGRESSION] PM / sleep: Unbalanced suspend/resume on late abort causes data abort Rose Wu
2025-11-17 16:59 ` Rafael J. Wysocki
2025-11-17 18:57 ` [PATCH v1] PM: sleep: core: Fix runtime PM enabling in device_resume_early() Rafael J. Wysocki
2025-11-18 8:31 ` Rose Wu
2025-11-18 11:48 ` [PATCH v2] " Rafael J. Wysocki
2025-11-18 12:17 ` Ulf Hansson
2025-11-18 12:26 ` Rafael J. Wysocki
2025-11-18 12:45 ` [PATCH v3] " Rafael J. Wysocki
2025-11-18 12:57 ` Ulf Hansson
2025-11-18 13:01 ` Rafael J. Wysocki
2025-11-18 14:16 ` Rafael J. Wysocki [this message]
2025-11-18 14:44 ` [PATCH v4] " Ulf Hansson
2025-11-18 12:49 ` [PATCH v2] " Ulf Hansson
2025-11-18 12:52 ` Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=12784270.O9o76ZdvQC@rafael.j.wysocki \
--to=rafael@kernel.org \
--cc=Johnny-cc.Kao@mediatek.com \
--cc=artis.chiu@mediatek.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael.j.wysocki@intel.com \
--cc=regressions@lists.linux.dev \
--cc=ulf.hansson@linaro.org \
--cc=wsd_upstream@mediatek.com \
--cc=ya-jou.wu@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox