public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: Haowen Tu <tuhaowen@uniontech.com>
To: rafael@kernel.org
Cc: lenb@kernel.org, pavel@kernel.org, linux-pm@vger.kernel.org,
	laurent.pinchart@ideasonboard.com, hansg@kernel.org,
	mchehab@kernel.org, linux-media@vger.kernel.org,
	linux-kernel@vger.kernel.org, Haowen Tu <tuhaowen@uniontech.com>
Subject: [PATCH 1/2] PM: hibernate: add pm_hibernation_storing_image() helper
Date: Tue, 28 Apr 2026 16:05:12 +0800	[thread overview]
Message-ID: <20260428080513.1833515-2-tuhaowen@uniontech.com> (raw)
In-Reply-To: <20260428080513.1833515-1-tuhaowen@uniontech.com>

During hibernation, after create_image() saves the memory snapshot,
the kernel resumes devices with PMSG_THAW solely to write the hibernation
image to storage, then powers off.  Drivers for hardware not involved in
storage I/O have no reason to reinitialize during this transient phase.

Some subsystems, such as USB, do not expose the hibernation PM message
to driver resume callbacks, so drivers there need an explicit query to
distinguish the image-write phase from the final restore path.  Export
pm_hibernation_storing_image() for this purpose.

The implementation returns !!in_suspend, which is set to 1 in
create_image() just before swsusp_arch_suspend() and reset to 0 in
hibernate() after swsusp_write() completes.  Because in_suspend is
marked __nosavedata, it is not saved into the hibernation image; on the
restore path the variable remains 0 throughout, so the helper correctly
returns false during PMSG_RESTORE device resume.

Signed-off-by: Haowen Tu <tuhaowen@uniontech.com>
---
 include/linux/suspend.h  |  2 ++
 kernel/power/hibernate.c | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/include/linux/suspend.h b/include/linux/suspend.h
index b02876f1ae38..28b454def83d 100644
--- a/include/linux/suspend.h
+++ b/include/linux/suspend.h
@@ -393,6 +393,7 @@ extern void hibernation_set_ops(const struct platform_hibernation_ops *ops);
 extern int hibernate(void);
 extern bool system_entering_hibernation(void);
 extern bool hibernation_available(void);
+extern bool pm_hibernation_storing_image(void);
 asmlinkage int swsusp_save(void);
 extern struct pbe *restore_pblist;
 int pfn_is_nosave(unsigned long pfn);
@@ -412,6 +413,7 @@ static inline void hibernation_set_ops(const struct platform_hibernation_ops *op
 static inline int hibernate(void) { return -ENOSYS; }
 static inline bool system_entering_hibernation(void) { return false; }
 static inline bool hibernation_available(void) { return false; }
+static inline bool pm_hibernation_storing_image(void) { return false; }
 
 static inline int hibernate_quiet_exec(int (*func)(void *data), void *data) {
 	return -ENOTSUPP;
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index af8d07bafe02..bc632cce40ff 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -113,6 +113,25 @@ bool hibernation_available(void)
 		!secretmem_active() && !cxl_mem_active();
 }
 
+/**
+ * pm_hibernation_storing_image - check if system is writing the hibernation image
+ *
+ * After create_image() saves a memory snapshot, the kernel briefly resumes
+ * devices with PMSG_THAW to write the image to storage before final powerdown.
+ * Drivers for hardware not involved in storage I/O may call this helper from
+ * their resume callbacks to skip unnecessary hardware initialization during
+ * that transient phase.
+ *
+ * Context: May be called from device PM callbacks.
+ * Return: %true if a hibernation snapshot has been taken and the system is
+ *         in the process of writing the image to persistent storage.
+ */
+bool pm_hibernation_storing_image(void)
+{
+	return !!in_suspend;
+}
+EXPORT_SYMBOL_GPL(pm_hibernation_storing_image);
+
 /**
  * hibernation_set_ops - Set the global hibernate operations.
  * @ops: Hibernation operations to use in subsequent hibernation transitions.
-- 
2.20.1


  reply	other threads:[~2026-04-28  8:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-28  8:05 [PATCH 0/2] PM: hibernate: add helper to detect image-write phase Haowen Tu
2026-04-28  8:05 ` Haowen Tu [this message]
2026-04-28  8:05 ` [PATCH 2/2] media: uvcvideo: skip resume when writing hibernation image Haowen Tu
2026-04-28  8:36   ` Oliver Neukum
2026-04-28  8:58     ` Haowen Tu
2026-04-28  9:13   ` Laurent Pinchart
2026-04-29  1:15     ` Haowen Tu
2026-04-29  1:16     ` Haowen Tu

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=20260428080513.1833515-2-tuhaowen@uniontech.com \
    --to=tuhaowen@uniontech.com \
    --cc=hansg@kernel.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=lenb@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=pavel@kernel.org \
    --cc=rafael@kernel.org \
    /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