From: "Mario Limonciello (AMD)" <superm1@kernel.org>
To: "Rafael J . Wysocki" <rafael@kernel.org>,
Alex Deucher <alexander.deucher@amd.com>
Cc: linux-pm@vger.kernel.org (open list:HIBERNATION (aka Software
Suspend, aka swsusp)),
amd-gfx@lists.freedesktop.org (open list:RADEON and AMDGPU DRM
DRIVERS), "Mario Limonciello (AMD)" <superm1@kernel.org>,
Muhammad Usama Anjum <usama.anjum@collabora.com>
Subject: [PATCH v2 1/2] PM: Allow device drivers to manage the frozen state of a device
Date: Fri, 24 Oct 2025 20:00:57 -0500 [thread overview]
Message-ID: <20251025010058.2417352-2-superm1@kernel.org> (raw)
In-Reply-To: <20251025010058.2417352-1-superm1@kernel.org>
During a normal successful hibernate sequence devices will go through
the freeze() callbacks create an image, go through the thaw() callbacks,
and poweroff() callbacks.
During a successful hibernate sequence some device drivers may want to
skip the thaw() callbacks. This confuses the PM core though because it
thinks the device is no longer suspended.
To accommodate drivers that want to do this, introduce a new is_frozen
bit that the driver can set and manage. From the driver perspective
any thaw() or restore() callbacks that are being skipped should set
is_frozen and return an error code. The PM core will then put the
device back into the list of devices to resume for any aborted hibernate.
Tested-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>
---
v2:
* add tag
* fix lkp robot issue
* rebase on linux-pm/bleeding-edge
---
Documentation/driver-api/pm/devices.rst | 8 ++++++++
drivers/base/power/main.c | 7 +++++++
include/linux/pm.h | 3 +++
3 files changed, 18 insertions(+)
diff --git a/Documentation/driver-api/pm/devices.rst b/Documentation/driver-api/pm/devices.rst
index 36d5c9c9fd113..55c6337271086 100644
--- a/Documentation/driver-api/pm/devices.rst
+++ b/Documentation/driver-api/pm/devices.rst
@@ -578,6 +578,14 @@ should already have been stored during the ``freeze``, ``freeze_late`` or
the entire system, so it is not necessary for the callback to put the device in
a low-power state.
+Skipping thaw phase
+-------------------
+In some rare situations, it may be desirable to skip the thaw phases
+(``thaw_noirq``, ``thaw_early``, ``thaw``) of a device entirely. This can be
+achieved by a device driver returning an error code from any of it's thaw
+callbacks but also setting dev->power.is_frozen to true. This indicates to the
+PM core that the device is still in the frozen state. The PM core will consider
+this when resuming the device in later phases such as `restore` or `poweroff`.
Leaving Hibernation
-------------------
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 7a8807ec9a5d0..c5a192fc04344 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -1110,6 +1110,13 @@ static void device_resume(struct device *dev, pm_message_t state, bool async)
End:
error = dpm_run_callback(callback, dev, state, info);
+#ifdef CONFIG_HIBERNATE_CALLBACKS
+ /* device manages frozen state */
+ if (error && dev->power.is_frozen) {
+ dev->power.is_suspended = true;
+ error = 0;
+ }
+#endif
device_unlock(dev);
dpm_watchdog_clear(&wd);
diff --git a/include/linux/pm.h b/include/linux/pm.h
index a72e42eec1303..852902fc72158 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -689,6 +689,9 @@ struct dev_pm_info {
#else
bool should_wakeup:1;
#endif
+#ifdef CONFIG_HIBERNATE_CALLBACKS
+ bool is_frozen:1; /* Owned by the driver */
+#endif
#ifdef CONFIG_PM
struct hrtimer suspend_timer;
u64 timer_expires;
--
2.43.0
next prev parent reply other threads:[~2025-10-25 1:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-25 1:00 [PATCH v2 0/2] Fixups for cancelled hibernate Mario Limonciello (AMD)
2025-10-25 1:00 ` Mario Limonciello (AMD) [this message]
2025-11-03 19:50 ` [PATCH v2 1/2] PM: Allow device drivers to manage the frozen state of a device Rafael J. Wysocki
2025-11-04 12:14 ` Muhammad Usama Anjum
2025-10-25 1:00 ` [PATCH v2 2/2] drm/amd: Manage frozen state internally Mario Limonciello (AMD)
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=20251025010058.2417352-2-superm1@kernel.org \
--to=superm1@kernel.org \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=usama.anjum@collabora.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