mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Haowen Tu <tuhaowen@uniontech.com>
To: rafael@kernel.org
Cc: tuhaowen@uniontech.com, gregkh@linuxfoundation.org,
	hansg@kernel.org, kernel@uniontech.com,
	laurent.pinchart@ideasonboard.com, lenb@kernel.org,
	linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
	linux-pm@vger.kernel.org, linux-usb@vger.kernel.org,
	mchehab@kernel.org, oneukum@suse.com, pavel@kernel.org,
	stern@rowland.harvard.edu
Subject: [PATCH v3 2/3] PM: hibernate: add pm_hibernation_snapshot_done() helper
Date: Thu, 18 Jun 2026 09:31:32 +0800	[thread overview]
Message-ID: <20260618013133.1047270-3-tuhaowen@uniontech.com> (raw)
In-Reply-To: <20260618013133.1047270-1-tuhaowen@uniontech.com>

Some subsystem resume callbacks do not receive the PM event and
therefore cannot distinguish the PMSG_THAW phase after snapshot creation
from the PMSG_RESTORE phase.

Export pm_hibernation_snapshot_done() so a driver can query whether the
hibernation snapshot has been created and is still available.  The
helper only exposes the PM state; callers remain responsible for
ensuring that any device-specific behavior is safe, including subsequent
poweroff or shutdown handling.

The helper returns !!in_suspend.  This variable is set before
swsusp_arch_suspend(), cleared before the snapshot memory is released,
and marked __nosavedata, so it remains clear on the restore path.

Signed-off-by: Haowen Tu <tuhaowen@uniontech.com>
---
Changes in v3:
- Split the in_suspend cleanup into a preceding patch.
- Clarify that callers must account for poweroff/shutdown handling.
- Drop extern from the new prototype.

Changes in v2:
- Rename pm_hibernation_storing_image() to
  pm_hibernation_snapshot_done().

 include/linux/suspend.h  |  2 ++
 kernel/power/hibernate.c | 12 ++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/include/linux/suspend.h b/include/linux/suspend.h
index b02876f1ae38..2cebbec3e2f7 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);
+bool pm_hibernation_snapshot_done(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_snapshot_done(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 6d3e637c5a02..045d29f55011 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -113,6 +113,18 @@ bool hibernation_available(void)
 		!secretmem_active() && !cxl_mem_active();
 }
 
+/**
+ * pm_hibernation_snapshot_done - check if a hibernation snapshot is available
+ *
+ * Return: %true if a hibernation snapshot has been taken and has not been
+ *         released yet.
+ */
+bool pm_hibernation_snapshot_done(void)
+{
+	return !!in_suspend;
+}
+EXPORT_SYMBOL_GPL(pm_hibernation_snapshot_done);
+
 /**
  * hibernation_set_ops - Set the global hibernate operations.
  * @ops: Hibernation operations to use in subsequent hibernation transitions.
-- 
2.20.1

  parent reply	other threads:[~2026-06-18  1:32 UTC|newest]

Thread overview: 42+ 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 ` [PATCH 1/2] PM: hibernate: add pm_hibernation_storing_image() helper Haowen Tu
2026-05-26 13:43   ` Rafael J. Wysocki
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
2026-05-28  8:18 ` [PATCH v2 0/2] PM: hibernate: skip UVC resume after snapshot Haowen Tu
2026-05-28  8:18   ` [PATCH v2 1/2] PM: hibernate: add pm_hibernation_snapshot_done() helper Haowen Tu
2026-06-01 18:22     ` Rafael J. Wysocki
2026-06-02  3:24       ` Haowen Tu
2026-06-18  1:31         ` [PATCH v3 0/3] PM: hibernate: skip UVC streaming restart after snapshot Haowen Tu
2026-06-18  1:31           ` [PATCH v3 1/3] PM: hibernate: clear in_suspend before freeing the snapshot Haowen Tu
2026-07-22 15:37             ` Rafael J. Wysocki (Intel)
2026-06-18  1:31           ` Haowen Tu [this message]
2026-07-22 15:40             ` [PATCH v3 2/3] PM: hibernate: add pm_hibernation_snapshot_done() helper Rafael J. Wysocki (Intel)
2026-06-18  1:31           ` [PATCH v3 3/3] media: uvcvideo: skip streaming restart after hibernation snapshot Haowen Tu
2026-07-22 20:06             ` Laurent Pinchart
2026-07-23  1:39               ` Haowen Tu
2026-07-23  8:46                 ` Laurent Pinchart
2026-07-29  7:11                   ` [PATCH v4 0/4] PM: hibernate: defer UVC streaming restart after snapshot Haowen Tu
2026-07-29  7:11                     ` [PATCH v4 1/4] PM: hibernate: clear in_suspend before freeing the snapshot Haowen Tu
2026-07-29  7:11                     ` [PATCH v4 2/4] PM: hibernate: add pm_hibernation_snapshot_done() helper Haowen Tu
2026-07-29  7:11                     ` [PATCH v4 3/4] PM: hibernate: notify on image write failure Haowen Tu
2026-07-29  7:11                     ` [PATCH v4 4/4] media: uvcvideo: defer streaming restart after hibernation snapshot Haowen Tu
2026-07-29  7:29                       ` Hans de Goede
2026-07-29  7:56                         ` Haowen Tu
2026-07-29 14:08                           ` Alan Stern
2026-07-29 14:43                             ` Oliver Neukum
2026-07-29 14:54                               ` Alan Stern
2026-07-30 13:16                             ` Laurent Pinchart
2026-07-30 14:29                               ` Alan Stern
2026-07-30 15:38                                 ` Laurent Pinchart
2026-07-31  1:30                                   ` Haowen Tu
2026-09-03  2:14                                   ` [PATCH v5 0/4] PM: hibernate: skip unnecessary THAW resume Haowen Tu
2026-09-03  2:14                                     ` [PATCH v5 1/4] PM: hibernate: clear in_suspend before freeing the snapshot Haowen Tu
2026-09-03  2:14                                     ` [PATCH v5 2/4] PM: hibernate: add pm_hibernation_snapshot_done() helper Haowen Tu
2026-09-03  2:14                                     ` [PATCH v5 3/4] PM: hibernate: allow devices to skip post-snapshot THAW Haowen Tu
2026-09-03  2:14                                     ` [PATCH v5 4/4] media: uvcvideo: skip post-snapshot hibernation THAW Haowen Tu
2026-05-28  8:18   ` [PATCH v2 2/2] media: uvcvideo: skip resume after hibernation snapshot 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=20260618013133.1047270-3-tuhaowen@uniontech.com \
    --to=tuhaowen@uniontech.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hansg@kernel.org \
    --cc=kernel@uniontech.com \
    --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=linux-usb@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=oneukum@suse.com \
    --cc=pavel@kernel.org \
    --cc=rafael@kernel.org \
    --cc=stern@rowland.harvard.edu \
    /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

all inboxes | Powered by JetHome®