Linux USB
 help / color / mirror / Atom feed
* [PATCH v2 0/2] PM: hibernate: skip UVC resume after snapshot
       [not found] <20260428080513.1833515-1-tuhaowen@uniontech.com>
@ 2026-05-28  8:18 ` Haowen Tu
  2026-05-28  8:18   ` [PATCH v2 1/2] PM: hibernate: add pm_hibernation_snapshot_done() helper Haowen Tu
  2026-05-28  8:18   ` [PATCH v2 2/2] media: uvcvideo: skip resume " Haowen Tu
  0 siblings, 2 replies; 24+ messages in thread
From: Haowen Tu @ 2026-05-28  8:18 UTC (permalink / raw)
  To: rafael
  Cc: lenb, pavel, linux-pm, laurent.pinchart, hansg, mchehab,
	linux-media, gregkh, stern, oneukum, linux-usb, linux-kernel,
	kernel, Haowen Tu

During hibernation, after the memory snapshot has been created, the
kernel briefly resumes devices with PMSG_THAW to write the snapshot to
storage before powering off.  USB driver resume callbacks do not receive
the hibernation PM message, so uvcvideo cannot distinguish this transient
image-write phase from the final restore path.

This series adds pm_hibernation_snapshot_done() and uses it in uvcvideo
to avoid reinitializing the camera during the image-write phase.

This is not intended to make every leaf driver special-case hibernation
THAW.  A generic USB-core skip would not be safe because some USB
interfaces may be part of the storage path, or otherwise be required by
dependencies during image writeout.  The helper is an opt-in mechanism
for drivers with a concrete reason to avoid reinitializing hardware in
this transient phase.  In this case, uvcvideo has a user-visible side
effect, the camera indicator LED, while the camera is not part of the
image writeout path.

Changes in v2:
- Rename pm_hibernation_storing_image() to
  pm_hibernation_snapshot_done().
- Clear in_suspend before releasing snapshot memory on the hibernation
  failure paths and after swsusp_write() returns.
- Update the uvcvideo call site for the new helper name.

Haowen Tu (2):
  PM: hibernate: add pm_hibernation_snapshot_done() helper
  media: uvcvideo: skip resume after hibernation snapshot

 drivers/media/usb/uvc/uvc_video.c | 12 ++++++++++++
 include/linux/suspend.h           |  2 ++
 kernel/power/hibernate.c          | 31 +++++++++++++++++++++++++++----
 3 files changed, 41 insertions(+), 4 deletions(-)

-- 
2.20.1

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v2 1/2] PM: hibernate: add pm_hibernation_snapshot_done() helper
  2026-05-28  8:18 ` [PATCH v2 0/2] PM: hibernate: skip UVC resume after snapshot Haowen Tu
@ 2026-05-28  8:18   ` Haowen Tu
  2026-06-01 18:22     ` Rafael J. Wysocki
  2026-05-28  8:18   ` [PATCH v2 2/2] media: uvcvideo: skip resume " Haowen Tu
  1 sibling, 1 reply; 24+ messages in thread
From: Haowen Tu @ 2026-05-28  8:18 UTC (permalink / raw)
  To: rafael
  Cc: lenb, pavel, linux-pm, laurent.pinchart, hansg, mchehab,
	linux-media, gregkh, stern, oneukum, linux-usb, linux-kernel,
	kernel, Haowen Tu

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_snapshot_done() for this purpose.

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

Clear in_suspend before releasing snapshot memory on hibernation failure
paths and after swsusp_write() returns, so the helper does not report a
stale snapshot after the snapshot pages have been released.

Signed-off-by: Haowen Tu <tuhaowen@uniontech.com>
---
Changes in v2:
- Rename pm_hibernation_storing_image() to
  pm_hibernation_snapshot_done().
- Clear in_suspend before releasing snapshot memory on failure paths and
  after swsusp_write() returns.

 include/linux/suspend.h  |  2 ++
 kernel/power/hibernate.c | 31 +++++++++++++++++++++++++++----
 2 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/include/linux/suspend.h b/include/linux/suspend.h
index b02876f1ae38..78e7e33c3d19 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_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 af8d07bafe02..47047937e262 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_snapshot_done - check if a hibernation snapshot is available
+ *
+ * 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 that do not need to participate in image writing 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 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.
@@ -418,6 +437,7 @@ static void shrink_shmem_memory(void)
 int hibernation_snapshot(int platform_mode)
 {
 	pm_message_t msg;
+	bool snapshot_done;
 	int error;
 
 	pm_suspend_clear_flags();
@@ -474,15 +494,18 @@ int hibernation_snapshot(int platform_mode)
 	 * returns here (1) after the image has been created or the
 	 * image creation has failed and (2) after a successful restore.
 	 */
+	snapshot_done = in_suspend;
 
 	/* We may need to release the preallocated image pages here. */
-	if (error || !in_suspend)
+	if (error || !snapshot_done) {
+		in_suspend = 0;
 		swsusp_free();
+	}
 
-	msg = in_suspend ? (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE;
+	msg = snapshot_done ? (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE;
 	dpm_resume(msg);
 
-	if (error || !in_suspend)
+	if (error || !snapshot_done)
 		pm_restore_gfp_mask();
 
 	console_resume_all();
@@ -865,6 +888,7 @@ int hibernate(void)
 
 		pm_pr_dbg("Writing hibernation image.\n");
 		error = swsusp_write(flags);
+		in_suspend = 0;
 		swsusp_free();
 		if (!error) {
 			if (hibernation_mode == HIBERNATION_TEST_RESUME)
@@ -872,7 +896,6 @@ int hibernate(void)
 			else
 				power_down();
 		}
-		in_suspend = 0;
 		pm_restore_gfp_mask();
 	} else {
 		pm_pr_dbg("Hibernation image restored successfully.\n");
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v2 2/2] media: uvcvideo: skip resume after hibernation snapshot
  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-05-28  8:18   ` Haowen Tu
  1 sibling, 0 replies; 24+ messages in thread
From: Haowen Tu @ 2026-05-28  8:18 UTC (permalink / raw)
  To: rafael
  Cc: lenb, pavel, linux-pm, laurent.pinchart, hansg, mchehab,
	linux-media, gregkh, stern, oneukum, linux-usb, linux-kernel,
	kernel, Haowen Tu

When a UVC camera is in active use and the system enters S4 hibernation,
the camera is suspended as part of the normal device freeze sequence.
However, after create_image() saves the memory snapshot, the kernel
briefly resumes all devices with PMSG_THAW to write the hibernation
image to storage.  This causes uvc_video_resume() to run and
reinitialize the camera hardware, which visibly turns on the camera
indicator LED during this intermediate phase even though the system is
about to power off.

The UVC device is not needed during the image-write window, where the
system only needs devices required for writing the hibernation image.
USB .resume callbacks do not receive pm_message_t, unlike .suspend, so
use the PM-layer helper to detect this phase.

This is intentionally handled in uvcvideo rather than in USB core.  USB
core cannot skip all interface resume callbacks during hibernation THAW,
because some USB interfaces may be part of the image writeout path or
otherwise be required by dependencies.  uvcvideo has a concrete
user-visible side effect from reinitializing hardware in this transient
phase, and it is not involved in image writeout.

The check is placed after stream->frozen is cleared and the clock is
reset, so that driver state remains consistent if the image write fails
and the system resumes normally instead of powering off.  In that case
userspace will need to restart the stream, but the driver will not be
left with stale frozen state.

Tested with hibernation image written to local storage and resumed from
disk on a system with a USB UVC camera attached; the camera LED remains
off during image writing and the video stream resumes correctly after
restore.

Signed-off-by: Haowen Tu <tuhaowen@uniontech.com>
---
Changes in v2:
- Use pm_hibernation_snapshot_done() after the PM helper was renamed.

 drivers/media/usb/uvc/uvc_video.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
index f6c8e3223796..9fa649fd47e0 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -12,6 +12,7 @@
 #include <linux/list.h>
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <linux/suspend.h>
 #include <linux/usb.h>
 #include <linux/usb/hcd.h>
 #include <linux/videodev2.h>
@@ -2151,6 +2152,17 @@ int uvc_video_resume(struct uvc_streaming *stream, int reset)
 	if (!uvc_queue_streaming(&stream->queue))
 		return 0;
 
+	/*
+	 * During hibernation image writing (PMSG_THAW), the kernel briefly
+	 * resumes devices after the snapshot has been created.  Skip hardware
+	 * reinitialization to avoid USB traffic and the spurious camera LED
+	 * activation.  stream->frozen has already been cleared, so if the
+	 * image write fails and the system resumes normally, driver state
+	 * remains consistent; userspace will need to restart the stream.
+	 */
+	if (pm_hibernation_snapshot_done())
+		return 0;
+
 	ret = uvc_commit_video(stream, &stream->ctrl);
 	if (ret < 0)
 		return ret;
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 1/2] PM: hibernate: add pm_hibernation_snapshot_done() helper
  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
  0 siblings, 1 reply; 24+ messages in thread
From: Rafael J. Wysocki @ 2026-06-01 18:22 UTC (permalink / raw)
  To: Haowen Tu
  Cc: rafael, lenb, pavel, linux-pm, laurent.pinchart, hansg, mchehab,
	linux-media, gregkh, stern, oneukum, linux-usb, linux-kernel,
	kernel

On Thu, May 28, 2026 at 10:19 AM Haowen Tu <tuhaowen@uniontech.com> wrote:
>
> 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.

They do have a reason for doing it.

Their poweroff (or shutdown) callbacks will be called while preparing
to power off the system subsequently and they need to be ready for
that.  The most straightforward way to achieve this is to resume so
they can "suspend" again.

> 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_snapshot_done() for this purpose.
>
> The implementation returns !!in_suspend, which is set to 1 in
> create_image() just before swsusp_arch_suspend().  Because in_suspend is
> marked __nosavedata, it is not saved into the hibernation image; on the
> restore path the variable remains 0, so the helper correctly returns
> false during PMSG_RESTORE device resume.
>
> Clear in_suspend before releasing snapshot memory on hibernation failure
> paths and after swsusp_write() returns, so the helper does not report a
> stale snapshot after the snapshot pages have been released.

This last piece needs to be split off into a separate patch.

> Signed-off-by: Haowen Tu <tuhaowen@uniontech.com>
> ---
> Changes in v2:
> - Rename pm_hibernation_storing_image() to
>   pm_hibernation_snapshot_done().
> - Clear in_suspend before releasing snapshot memory on failure paths and
>   after swsusp_write() returns.
>
>  include/linux/suspend.h  |  2 ++
>  kernel/power/hibernate.c | 31 +++++++++++++++++++++++++++----
>  2 files changed, 29 insertions(+), 4 deletions(-)
>
> diff --git a/include/linux/suspend.h b/include/linux/suspend.h
> index b02876f1ae38..78e7e33c3d19 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_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 af8d07bafe02..47047937e262 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_snapshot_done - check if a hibernation snapshot is available
> + *
> + * 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 that do not need to participate in image writing 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 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.
> @@ -418,6 +437,7 @@ static void shrink_shmem_memory(void)
>  int hibernation_snapshot(int platform_mode)
>  {
>         pm_message_t msg;
> +       bool snapshot_done;
>         int error;
>
>         pm_suspend_clear_flags();
> @@ -474,15 +494,18 @@ int hibernation_snapshot(int platform_mode)
>          * returns here (1) after the image has been created or the
>          * image creation has failed and (2) after a successful restore.
>          */
> +       snapshot_done = in_suspend;
>
>         /* We may need to release the preallocated image pages here. */
> -       if (error || !in_suspend)
> +       if (error || !snapshot_done) {
> +               in_suspend = 0;
>                 swsusp_free();
> +       }
>
> -       msg = in_suspend ? (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE;
> +       msg = snapshot_done ? (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE;
>         dpm_resume(msg);
>
> -       if (error || !in_suspend)
> +       if (error || !snapshot_done)
>                 pm_restore_gfp_mask();
>
>         console_resume_all();
> @@ -865,6 +888,7 @@ int hibernate(void)
>
>                 pm_pr_dbg("Writing hibernation image.\n");
>                 error = swsusp_write(flags);
> +               in_suspend = 0;
>                 swsusp_free();
>                 if (!error) {
>                         if (hibernation_mode == HIBERNATION_TEST_RESUME)
> @@ -872,7 +896,6 @@ int hibernate(void)
>                         else
>                                 power_down();
>                 }
> -               in_suspend = 0;
>                 pm_restore_gfp_mask();
>         } else {
>                 pm_pr_dbg("Hibernation image restored successfully.\n");
> --
> 2.20.1

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2 1/2] PM: hibernate: add pm_hibernation_snapshot_done() helper
  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
  0 siblings, 1 reply; 24+ messages in thread
From: Haowen Tu @ 2026-06-02  3:24 UTC (permalink / raw)
  To: rafael
  Cc: gregkh, hansg, kernel, laurent.pinchart, lenb, linux-kernel,
	linux-media, linux-pm, linux-usb, mchehab, oneukum, pavel, stern,
	tuhaowen

Hi Rafael,

On Mon, Jun 01, 2026 at 08:22:00PM +0200, Rafael J. Wysocki wrote:
> On Thu, May 28, 2026 at 10:19 AM Haowen Tu <tuhaowen@uniontech.com> wrote:
> >
> > 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.
>
> They do have a reason for doing it.
>
> Their poweroff (or shutdown) callbacks will be called while preparing
> to power off the system subsequently and they need to be ready for
> that.  The most straightforward way to achieve this is to resume so
> they can "suspend" again.

Thanks for pointing this out.

My understanding is that the hibernation image contains the state from
the snapshot point, that is before the subsequent THAW and image-write
phase.  Therefore, on the later restore path, the kernel resumes from the
state captured at the snapshot point and still goes through the normal
PMSG_RESTORE resume path.  The THAW activity after the snapshot is not
part of the restored image state.

That said, I agree that some devices may need to be resumed before the
final poweroff/shutdown callbacks run, so the wording in the changelog is
too broad.  I did not mean to suggest that all non-storage devices can or
should skip THAW resume.

The helper is meant to expose this PM state, not to prescribe that
drivers should skip THAW resume.  Whether a driver uses it would remain a
driver-specific decision, based on whether skipping the hardware
reinitialization is safe for that device, including its subsequent
poweroff/shutdown handling.  Drivers that need the normal THAW resume
before poweroff/shutdown would simply not use it.

In this series the user is uvcvideo.  For USB devices, and specifically
for UVC cameras, the device is hotpluggable and the driver already needs
to tolerate device removal and disconnect-like conditions.  The UVC
driver also does not need the camera streaming engine to be restarted in
order to write the hibernation image, while restarting it has a visible
side effect by turning the camera LED back on.  The check is placed after
the driver's frozen state is cleared, so if image writeout fails, the
driver is not left in the frozen state.

I will reword the changelog in the next version to avoid implying that
non-storage devices generally have no reason to resume during THAW.

> > Clear in_suspend before releasing snapshot memory on hibernation failure
> > paths and after swsusp_write() returns, so the helper does not report a
> > stale snapshot after the snapshot pages have been released.
>
> This last piece needs to be split off into a separate patch.

Sure, I will split the in_suspend cleanup into a separate patch in the
next version.

I will wait for your feedback before sending the next version.

Thanks,
Haowen

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v3 0/3] PM: hibernate: skip UVC streaming restart after snapshot
  2026-06-02  3:24       ` Haowen Tu
@ 2026-06-18  1:31         ` Haowen Tu
  2026-06-18  1:31           ` [PATCH v3 1/3] PM: hibernate: clear in_suspend before freeing the snapshot Haowen Tu
                             ` (2 more replies)
  0 siblings, 3 replies; 24+ messages in thread
From: Haowen Tu @ 2026-06-18  1:31 UTC (permalink / raw)
  To: rafael
  Cc: tuhaowen, gregkh, hansg, kernel, laurent.pinchart, lenb,
	linux-kernel, linux-media, linux-pm, linux-usb, mchehab, oneukum,
	pavel, stern

After a hibernation snapshot is created, devices are resumed with
PMSG_THAW before the image is written and the system is powered off.
USB interface driver resume callbacks do not receive the PM event, so
they cannot distinguish this phase from PMSG_RESTORE.

This series first makes the lifetime represented by in_suspend match the
snapshot memory lifetime, then exposes that state through
pm_hibernation_snapshot_done().  The helper only exposes the PM state;
drivers remain responsible for deciding whether device-specific behavior
is safe, including subsequent poweroff or shutdown handling.

As the first user, uvcvideo skips only restarting active streaming
hardware during the transient THAW phase.  Its frozen state and clock are
still updated, a subsequent UVC suspend can stop the stream as usual,
and uvcvideo does not provide a shutdown callback that requires the
streaming hardware to be restarted first.

Changes in v3:
- Split the in_suspend cleanup into a separate patch, as requested by
  Rafael.
- Reword the helper description to clarify that it only exposes PM
  state and that callers must account for poweroff/shutdown handling.
- Restrict the UVC description to skipping the streaming hardware
  restart and explain why it does not prevent UVC shutdown handling.
- Drop extern from the new prototype to satisfy Media CI checkpatch.

Changes in v2:
- Rename pm_hibernation_storing_image() to
  pm_hibernation_snapshot_done().
- Clear in_suspend before releasing snapshot memory on failure paths and
  after swsusp_write() returns.
- Move the UVC check after clearing the frozen state and resetting its
  clock.

Haowen Tu (3):
  PM: hibernate: clear in_suspend before freeing the snapshot
  PM: hibernate: add pm_hibernation_snapshot_done() helper
  media: uvcvideo: skip streaming restart after hibernation snapshot

 drivers/media/usb/uvc/uvc_video.c |  8 ++++++++
 include/linux/suspend.h           |  2 ++
 kernel/power/hibernate.c          | 24 ++++++++++++++++++++----
 3 files changed, 30 insertions(+), 4 deletions(-)

-- 
2.20.1

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v3 1/3] PM: hibernate: clear in_suspend before freeing the snapshot
  2026-06-18  1:31         ` [PATCH v3 0/3] PM: hibernate: skip UVC streaming restart after snapshot Haowen Tu
@ 2026-06-18  1:31           ` Haowen Tu
  2026-07-22 15:37             ` Rafael J. Wysocki (Intel)
  2026-06-18  1:31           ` [PATCH v3 2/3] PM: hibernate: add pm_hibernation_snapshot_done() helper Haowen Tu
  2026-06-18  1:31           ` [PATCH v3 3/3] media: uvcvideo: skip streaming restart after hibernation snapshot Haowen Tu
  2 siblings, 1 reply; 24+ messages in thread
From: Haowen Tu @ 2026-06-18  1:31 UTC (permalink / raw)
  To: rafael
  Cc: tuhaowen, gregkh, hansg, kernel, laurent.pinchart, lenb,
	linux-kernel, linux-media, linux-pm, linux-usb, mchehab, oneukum,
	pavel, stern

in_suspend indicates that a hibernation snapshot has been created and is
still available.  Keep that state consistent with the lifetime of the
snapshot memory by clearing in_suspend before swsusp_free() releases it.

If image creation fails after in_suspend has been set,
hibernation_snapshot() releases the snapshot memory but currently leaves
in_suspend set.  Preserve its value locally long enough to select the
appropriate device resume message, then clear it before releasing the
snapshot.

Also clear in_suspend before releasing the snapshot after swsusp_write()
returns.

Signed-off-by: Haowen Tu <tuhaowen@uniontech.com>
---
Changes in v3:
- Split this cleanup from the helper patch.

 kernel/power/hibernate.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index af8d07bafe02..6d3e637c5a02 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -418,6 +418,7 @@ static void shrink_shmem_memory(void)
 int hibernation_snapshot(int platform_mode)
 {
 	pm_message_t msg;
+	bool snapshot_done;
 	int error;
 
 	pm_suspend_clear_flags();
@@ -474,15 +475,18 @@ int hibernation_snapshot(int platform_mode)
 	 * returns here (1) after the image has been created or the
 	 * image creation has failed and (2) after a successful restore.
 	 */
+	snapshot_done = in_suspend;
 
 	/* We may need to release the preallocated image pages here. */
-	if (error || !in_suspend)
+	if (error || !snapshot_done) {
+		in_suspend = 0;
 		swsusp_free();
+	}
 
-	msg = in_suspend ? (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE;
+	msg = snapshot_done ? (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE;
 	dpm_resume(msg);
 
-	if (error || !in_suspend)
+	if (error || !snapshot_done)
 		pm_restore_gfp_mask();
 
 	console_resume_all();
@@ -865,6 +869,7 @@ int hibernate(void)
 
 		pm_pr_dbg("Writing hibernation image.\n");
 		error = swsusp_write(flags);
+		in_suspend = 0;
 		swsusp_free();
 		if (!error) {
 			if (hibernation_mode == HIBERNATION_TEST_RESUME)
@@ -872,7 +877,6 @@ int hibernate(void)
 			else
 				power_down();
 		}
-		in_suspend = 0;
 		pm_restore_gfp_mask();
 	} else {
 		pm_pr_dbg("Hibernation image restored successfully.\n");
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v3 2/3] PM: hibernate: add pm_hibernation_snapshot_done() helper
  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-06-18  1:31           ` Haowen Tu
  2026-07-22 15:40             ` Rafael J. Wysocki (Intel)
  2026-06-18  1:31           ` [PATCH v3 3/3] media: uvcvideo: skip streaming restart after hibernation snapshot Haowen Tu
  2 siblings, 1 reply; 24+ messages in thread
From: Haowen Tu @ 2026-06-18  1:31 UTC (permalink / raw)
  To: rafael
  Cc: tuhaowen, gregkh, hansg, kernel, laurent.pinchart, lenb,
	linux-kernel, linux-media, linux-pm, linux-usb, mchehab, oneukum,
	pavel, stern

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

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v3 3/3] media: uvcvideo: skip streaming restart after hibernation snapshot
  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-06-18  1:31           ` [PATCH v3 2/3] PM: hibernate: add pm_hibernation_snapshot_done() helper Haowen Tu
@ 2026-06-18  1:31           ` Haowen Tu
  2026-07-22 20:06             ` Laurent Pinchart
  2 siblings, 1 reply; 24+ messages in thread
From: Haowen Tu @ 2026-06-18  1:31 UTC (permalink / raw)
  To: rafael
  Cc: tuhaowen, gregkh, hansg, kernel, laurent.pinchart, lenb,
	linux-kernel, linux-media, linux-pm, linux-usb, mchehab, oneukum,
	pavel, stern

After the hibernation snapshot is created, devices are resumed with
PMSG_THAW before the image is written and the system is powered off.
Restarting an active UVC stream during this phase reinitializes the
camera and visibly turns its indicator LED back on.

Skip only the UVC streaming hardware restart while the snapshot is
available.  The driver's frozen state and clock are still updated before
the check, and a subsequent UVC suspend can stop the stream and select
alternate setting 0 as usual.  uvcvideo does not provide a shutdown
callback that requires the streaming hardware to be restarted first.

This is a device-specific use of pm_hibernation_snapshot_done().  The
helper does not cause other drivers or USB core to skip THAW resume.

Tested with hibernation image written to local storage and resumed from
disk on a system with a USB UVC camera attached; the camera LED remains
off during image writing and the video stream resumes correctly after
restore.

Signed-off-by: Haowen Tu <tuhaowen@uniontech.com>
---
Changes in v3:
- Clarify that only the UVC streaming hardware restart is skipped.
- Explain the subsequent UVC suspend and shutdown handling.

Changes in v2:
- Use pm_hibernation_snapshot_done() after the PM helper was renamed.
- Move the check after clearing the frozen state and resetting the clock.

 drivers/media/usb/uvc/uvc_video.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
index f6c8e3223796..1744298f4b1f 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -12,6 +12,7 @@
 #include <linux/list.h>
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <linux/suspend.h>
 #include <linux/usb.h>
 #include <linux/usb/hcd.h>
 #include <linux/videodev2.h>
@@ -2151,6 +2152,13 @@ int uvc_video_resume(struct uvc_streaming *stream, int reset)
 	if (!uvc_queue_streaming(&stream->queue))
 		return 0;
 
+	/*
+	 * Avoid restarting the streaming hardware during the transient THAW
+	 * phase after a hibernation snapshot has been created.
+	 */
+	if (pm_hibernation_snapshot_done())
+		return 0;
+
 	ret = uvc_commit_video(stream, &stream->ctrl);
 	if (ret < 0)
 		return ret;
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [PATCH v3 1/3] PM: hibernate: clear in_suspend before freeing the snapshot
  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)
  0 siblings, 0 replies; 24+ messages in thread
From: Rafael J. Wysocki (Intel) @ 2026-07-22 15:37 UTC (permalink / raw)
  To: Haowen Tu
  Cc: rafael, gregkh, hansg, kernel, laurent.pinchart, lenb,
	linux-kernel, linux-media, linux-pm, linux-usb, mchehab, oneukum,
	pavel, stern

On Thu, Jun 18, 2026 at 3:32 AM Haowen Tu <tuhaowen@uniontech.com> wrote:
>
> in_suspend indicates that a hibernation snapshot has been created and is
> still available.  Keep that state consistent with the lifetime of the
> snapshot memory by clearing in_suspend before swsusp_free() releases it.
>
> If image creation fails after in_suspend has been set,
> hibernation_snapshot() releases the snapshot memory but currently leaves
> in_suspend set.  Preserve its value locally long enough to select the
> appropriate device resume message, then clear it before releasing the
> snapshot.
>
> Also clear in_suspend before releasing the snapshot after swsusp_write()
> returns.
>
> Signed-off-by: Haowen Tu <tuhaowen@uniontech.com>

This is fine with me, so

Acked-by: Rafael J. Wysocki (Intel) <rafael@kernel.org>

and please feel free to route it along with the media patch.

Alternatively, I can pick up the whole series if I get an ACK on the
media patch.

> ---
> Changes in v3:
> - Split this cleanup from the helper patch.
>
>  kernel/power/hibernate.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
> index af8d07bafe02..6d3e637c5a02 100644
> --- a/kernel/power/hibernate.c
> +++ b/kernel/power/hibernate.c
> @@ -418,6 +418,7 @@ static void shrink_shmem_memory(void)
>  int hibernation_snapshot(int platform_mode)
>  {
>         pm_message_t msg;
> +       bool snapshot_done;
>         int error;
>
>         pm_suspend_clear_flags();
> @@ -474,15 +475,18 @@ int hibernation_snapshot(int platform_mode)
>          * returns here (1) after the image has been created or the
>          * image creation has failed and (2) after a successful restore.
>          */
> +       snapshot_done = in_suspend;
>
>         /* We may need to release the preallocated image pages here. */
> -       if (error || !in_suspend)
> +       if (error || !snapshot_done) {
> +               in_suspend = 0;
>                 swsusp_free();
> +       }
>
> -       msg = in_suspend ? (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE;
> +       msg = snapshot_done ? (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE;
>         dpm_resume(msg);
>
> -       if (error || !in_suspend)
> +       if (error || !snapshot_done)
>                 pm_restore_gfp_mask();
>
>         console_resume_all();
> @@ -865,6 +869,7 @@ int hibernate(void)
>
>                 pm_pr_dbg("Writing hibernation image.\n");
>                 error = swsusp_write(flags);
> +               in_suspend = 0;
>                 swsusp_free();
>                 if (!error) {
>                         if (hibernation_mode == HIBERNATION_TEST_RESUME)
> @@ -872,7 +877,6 @@ int hibernate(void)
>                         else
>                                 power_down();
>                 }
> -               in_suspend = 0;
>                 pm_restore_gfp_mask();
>         } else {
>                 pm_pr_dbg("Hibernation image restored successfully.\n");
> --
> 2.20.1

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v3 2/3] PM: hibernate: add pm_hibernation_snapshot_done() helper
  2026-06-18  1:31           ` [PATCH v3 2/3] PM: hibernate: add pm_hibernation_snapshot_done() helper Haowen Tu
@ 2026-07-22 15:40             ` Rafael J. Wysocki (Intel)
  0 siblings, 0 replies; 24+ messages in thread
From: Rafael J. Wysocki (Intel) @ 2026-07-22 15:40 UTC (permalink / raw)
  To: Haowen Tu
  Cc: rafael, gregkh, hansg, kernel, laurent.pinchart, lenb,
	linux-kernel, linux-media, linux-pm, linux-usb, mchehab, oneukum,
	pavel, stern

On Thu, Jun 18, 2026 at 3:32 AM Haowen Tu <tuhaowen@uniontech.com> wrote:
>
> 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.

Fine with me now, so

Acked-by: Rafael J. Wysocki (Intel) <rafael@kernel.org>

and please feel free to route it along with the media patch.

> 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
>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v3 3/3] media: uvcvideo: skip streaming restart after hibernation snapshot
  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
  0 siblings, 1 reply; 24+ messages in thread
From: Laurent Pinchart @ 2026-07-22 20:06 UTC (permalink / raw)
  To: Haowen Tu
  Cc: rafael, gregkh, hansg, kernel, lenb, linux-kernel, linux-media,
	linux-pm, linux-usb, mchehab, oneukum, pavel, stern

On Thu, Jun 18, 2026 at 09:31:33AM +0800, Haowen Tu wrote:
> After the hibernation snapshot is created, devices are resumed with
> PMSG_THAW before the image is written and the system is powered off.
> Restarting an active UVC stream during this phase reinitializes the
> camera and visibly turns its indicator LED back on.
> 
> Skip only the UVC streaming hardware restart while the snapshot is
> available.  The driver's frozen state and clock are still updated before
> the check, and a subsequent UVC suspend can stop the stream and select
> alternate setting 0 as usual.

Why is that desired (both the decision to only block the resume of the
video interface, and the decision to not block the next suspend) ?

> uvcvideo does not provide a shutdown
> callback that requires the streaming hardware to be restarted first.
> 
> This is a device-specific use of pm_hibernation_snapshot_done().  The
> helper does not cause other drivers or USB core to skip THAW resume.

I don't think this sentence belongs to the commit message.

> Tested with hibernation image written to local storage and resumed from
> disk on a system with a USB UVC camera attached; the camera LED remains
> off during image writing and the video stream resumes correctly after
> restore.
> 
> Signed-off-by: Haowen Tu <tuhaowen@uniontech.com>
> ---
> Changes in v3:
> - Clarify that only the UVC streaming hardware restart is skipped.
> - Explain the subsequent UVC suspend and shutdown handling.
> 
> Changes in v2:
> - Use pm_hibernation_snapshot_done() after the PM helper was renamed.
> - Move the check after clearing the frozen state and resetting the clock.
> 
>  drivers/media/usb/uvc/uvc_video.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> index f6c8e3223796..1744298f4b1f 100644
> --- a/drivers/media/usb/uvc/uvc_video.c
> +++ b/drivers/media/usb/uvc/uvc_video.c
> @@ -12,6 +12,7 @@
>  #include <linux/list.h>
>  #include <linux/module.h>
>  #include <linux/slab.h>
> +#include <linux/suspend.h>
>  #include <linux/usb.h>
>  #include <linux/usb/hcd.h>
>  #include <linux/videodev2.h>
> @@ -2151,6 +2152,13 @@ int uvc_video_resume(struct uvc_streaming *stream, int reset)
>  	if (!uvc_queue_streaming(&stream->queue))
>  		return 0;
>  
> +	/*
> +	 * Avoid restarting the streaming hardware during the transient THAW
> +	 * phase after a hibernation snapshot has been created.
> +	 */
> +	if (pm_hibernation_snapshot_done())
> +		return 0;
> +
>  	ret = uvc_commit_video(stream, &stream->ctrl);
>  	if (ret < 0)
>  		return ret;

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v3 3/3] media: uvcvideo: skip streaming restart after hibernation snapshot
  2026-07-22 20:06             ` Laurent Pinchart
@ 2026-07-23  1:39               ` Haowen Tu
  2026-07-23  8:46                 ` Laurent Pinchart
  0 siblings, 1 reply; 24+ messages in thread
From: Haowen Tu @ 2026-07-23  1:39 UTC (permalink / raw)
  To: laurent.pinchart
  Cc: gregkh, hansg, kernel, lenb, linux-kernel, linux-media, linux-pm,
	linux-usb, mchehab, oneukum, pavel, rafael, stern, tuhaowen

Hi Laurent,

On Wed, Jul 22, 2026 at 11:06:20PM +0300, Laurent Pinchart wrote:
> On Thu, Jun 18, 2026 at 09:31:33AM +0800, Haowen Tu wrote:
> > After the hibernation snapshot is created, devices are resumed with
> > PMSG_THAW before the image is written and the system is powered off.
> > Restarting an active UVC stream during this phase reinitializes the
> > camera and visibly turns its indicator LED back on.
> > 
> > Skip only the UVC streaming hardware restart while the snapshot is
> > available.  The driver's frozen state and clock are still updated before
> > the check, and a subsequent UVC suspend can stop the stream and select
> > alternate setting 0 as usual.
>
> Why is that desired (both the decision to only block the resume of the
> video interface, and the decision to not block the next suspend) ?

The intention is not to block the whole video interface resume callback.
The callback still clears stream->frozen and resets the stream clock
before the new check.  The patch only skips the final streaming hardware
restart, namely uvc_commit_video() and uvc_video_start_transfer().

In the earlier version the check was placed before those state updates.
After Oliver pointed out the image write failure path, I moved it later
in uvc_video_resume().  If swsusp_write() fails, the system continues
running in the original kernel, and the driver should not be left with
stream->frozen still set from the preceding FREEZE suspend.

That is the part that reconfigures the camera and restarts USB video
transfers, which is what turns the camera indicator LED back on during
the hibernation image-write phase.  The control interface resume path is
left unchanged because it is not the source of that visible side effect,
and because I do not want to change more of the UVC PM flow than needed
for this case.

The later suspend is also intentionally left unchanged.  The patch should
not alter the PM core sequencing.  If the platform hibernation path or an
error recovery path later asks the UVC streaming interface to suspend
again, uvc_video_suspend() can still run the existing cleanup path and
select alternate setting 0 as usual.  This keeps the interface in the
same state that the existing suspend path expects, instead of introducing
a special case where the later suspend is skipped too.

> > uvcvideo does not provide a shutdown
> > callback that requires the streaming hardware to be restarted first.
> > 
> > This is a device-specific use of pm_hibernation_snapshot_done().  The
> > helper does not cause other drivers or USB core to skip THAW resume.
>
> I don't think this sentence belongs to the commit message.

Agreed, I can drop that sentence from the commit message in the next
version.  It belongs more in the cover letter, if anywhere.

Thanks,
Haowen

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v3 3/3] media: uvcvideo: skip streaming restart after hibernation snapshot
  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
  0 siblings, 1 reply; 24+ messages in thread
From: Laurent Pinchart @ 2026-07-23  8:46 UTC (permalink / raw)
  To: Haowen Tu
  Cc: gregkh, hansg, kernel, lenb, linux-kernel, linux-media, linux-pm,
	linux-usb, mchehab, oneukum, pavel, rafael, stern

On Thu, Jul 23, 2026 at 09:39:55AM +0800, Haowen Tu wrote:
> On Wed, Jul 22, 2026 at 11:06:20PM +0300, Laurent Pinchart wrote:
> > On Thu, Jun 18, 2026 at 09:31:33AM +0800, Haowen Tu wrote:
> > > After the hibernation snapshot is created, devices are resumed with
> > > PMSG_THAW before the image is written and the system is powered off.
> > > Restarting an active UVC stream during this phase reinitializes the
> > > camera and visibly turns its indicator LED back on.
> > > 
> > > Skip only the UVC streaming hardware restart while the snapshot is
> > > available.  The driver's frozen state and clock are still updated before
> > > the check, and a subsequent UVC suspend can stop the stream and select
> > > alternate setting 0 as usual.
> >
> > Why is that desired (both the decision to only block the resume of the
> > video interface, and the decision to not block the next suspend) ?
> 
> The intention is not to block the whole video interface resume callback.
> The callback still clears stream->frozen and resets the stream clock
> before the new check.  The patch only skips the final streaming hardware
> restart, namely uvc_commit_video() and uvc_video_start_transfer().

Yes, I understand what the patch does.

> In the earlier version the check was placed before those state updates.
> After Oliver pointed out the image write failure path, I moved it later
> in uvc_video_resume().  If swsusp_write() fails, the system continues
> running in the original kernel, and the driver should not be left with
> stream->frozen still set from the preceding FREEZE suspend.

Does that mean that, if swsusp_write() fails, the camera will be left in
a hybrid state where the control interface has been resumed but the
streaming interface will not have been restarted ?

> That is the part that reconfigures the camera and restarts USB video
> transfers, which is what turns the camera indicator LED back on during
> the hibernation image-write phase.  The control interface resume path is
> left unchanged because it is not the source of that visible side effect,
> and because I do not want to change more of the UVC PM flow than needed
> for this case.
> 
> The later suspend is also intentionally left unchanged.  The patch should
> not alter the PM core sequencing.  If the platform hibernation path or an
> error recovery path later asks the UVC streaming interface to suspend
> again, uvc_video_suspend() can still run the existing cleanup path and
> select alternate setting 0 as usual.  This keeps the interface in the
> same state that the existing suspend path expects, instead of introducing
> a special case where the later suspend is skipped too.
> 
> > > uvcvideo does not provide a shutdown
> > > callback that requires the streaming hardware to be restarted first.
> > > 
> > > This is a device-specific use of pm_hibernation_snapshot_done().  The
> > > helper does not cause other drivers or USB core to skip THAW resume.
> >
> > I don't think this sentence belongs to the commit message.
> 
> Agreed, I can drop that sentence from the commit message in the next
> version.  It belongs more in the cover letter, if anywhere.

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v4 0/4] PM: hibernate: defer UVC streaming restart after snapshot
  2026-07-23  8:46                 ` Laurent Pinchart
@ 2026-07-29  7:11                   ` Haowen Tu
  2026-07-29  7:11                     ` [PATCH v4 1/4] PM: hibernate: clear in_suspend before freeing the snapshot Haowen Tu
                                       ` (3 more replies)
  0 siblings, 4 replies; 24+ messages in thread
From: Haowen Tu @ 2026-07-29  7:11 UTC (permalink / raw)
  To: laurent.pinchart, rafael
  Cc: gregkh, hansg, kernel, lenb, linux-kernel, linux-media, linux-pm,
	linux-usb, mchehab, oneukum, pavel, stern, tuhaowen

During hibernation, after the memory snapshot has been created, the
kernel resumes devices with PMSG_THAW to write the hibernation image.
USB interface resume callbacks do not receive the PM message, so UVC
cannot distinguish that intermediate THAW resume from the later RESTORE
resume by using its local callback arguments.

This series keeps in_suspend consistent with the lifetime of snapshot
memory, exports pm_hibernation_snapshot_done(), adds a hibernation image
write failure notification, and uses both in uvcvideo to defer restarting
streaming during the THAW phase after snapshot creation.

Unlike v3, the UVC patch now handles the image write failure path.  The
driver records streams whose streaming restart was deferred.  If image
writeout fails, PM sends PM_HIBERNATION_IMAGE_WRITE_FAILED after
swsusp_write() returns and before userspace is thawed, and uvcvideo
restarts those deferred streams.  If the recovery restart fails, the
driver falls back to its existing streamoff error path so userspace is
not left waiting indefinitely.

Changes in v4:
- Add PM_HIBERNATION_IMAGE_WRITE_FAILED before userspace thaw on image
  write failure.
- Update uvcvideo to defer streaming restart instead of just skipping it.
- Recover deferred UVC streams on image write failure.
- Carry Rafael's Acked-by tags on the two PM patches from v3.

Haowen Tu (4):
  PM: hibernate: clear in_suspend before freeing the snapshot
  PM: hibernate: add pm_hibernation_snapshot_done() helper
  PM: hibernate: notify on image write failure
  media: uvcvideo: defer streaming restart after hibernation snapshot

 drivers/media/usb/uvc/uvc_driver.c | 56 +++++++++++++++++++++++++++++-
 drivers/media/usb/uvc/uvc_video.c  | 19 +++++++++-
 drivers/media/usb/uvc/uvcvideo.h   |  2 ++
 include/linux/suspend.h            |  3 ++
 kernel/power/hibernate.c           | 27 +++++++++++---
 5 files changed, 101 insertions(+), 6 deletions(-)

-- 
2.20.1

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v4 1/4] PM: hibernate: clear in_suspend before freeing the snapshot
  2026-07-29  7:11                   ` [PATCH v4 0/4] PM: hibernate: defer UVC streaming restart after snapshot Haowen Tu
@ 2026-07-29  7:11                     ` Haowen Tu
  2026-07-29  7:11                     ` [PATCH v4 2/4] PM: hibernate: add pm_hibernation_snapshot_done() helper Haowen Tu
                                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 24+ messages in thread
From: Haowen Tu @ 2026-07-29  7:11 UTC (permalink / raw)
  To: laurent.pinchart, rafael
  Cc: gregkh, hansg, kernel, lenb, linux-kernel, linux-media, linux-pm,
	linux-usb, mchehab, oneukum, pavel, stern, tuhaowen

in_suspend indicates that a hibernation snapshot has been created and is
still available.  Keep that state consistent with the lifetime of the
snapshot memory by clearing in_suspend before swsusp_free() releases it.

If image creation fails after in_suspend has been set,
hibernation_snapshot() releases the snapshot memory but currently leaves
in_suspend set.  Preserve its value locally long enough to select the
appropriate device resume message, then clear it before releasing the
snapshot.

Also clear in_suspend before releasing the snapshot after swsusp_write()
returns.

Acked-by: Rafael J. Wysocki (Intel) <rafael@kernel.org>
Signed-off-by: Haowen Tu <tuhaowen@uniontech.com>
---
 kernel/power/hibernate.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index af8d07bafe02..6d3e637c5a02 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -418,6 +418,7 @@ static void shrink_shmem_memory(void)
 int hibernation_snapshot(int platform_mode)
 {
 	pm_message_t msg;
+	bool snapshot_done;
 	int error;
 
 	pm_suspend_clear_flags();
@@ -474,15 +475,18 @@ int hibernation_snapshot(int platform_mode)
 	 * returns here (1) after the image has been created or the
 	 * image creation has failed and (2) after a successful restore.
 	 */
+	snapshot_done = in_suspend;
 
 	/* We may need to release the preallocated image pages here. */
-	if (error || !in_suspend)
+	if (error || !snapshot_done) {
+		in_suspend = 0;
 		swsusp_free();
+	}
 
-	msg = in_suspend ? (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE;
+	msg = snapshot_done ? (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE;
 	dpm_resume(msg);
 
-	if (error || !in_suspend)
+	if (error || !snapshot_done)
 		pm_restore_gfp_mask();
 
 	console_resume_all();
@@ -865,6 +869,7 @@ int hibernate(void)
 
 		pm_pr_dbg("Writing hibernation image.\n");
 		error = swsusp_write(flags);
+		in_suspend = 0;
 		swsusp_free();
 		if (!error) {
 			if (hibernation_mode == HIBERNATION_TEST_RESUME)
@@ -872,7 +877,6 @@ int hibernate(void)
 			else
 				power_down();
 		}
-		in_suspend = 0;
 		pm_restore_gfp_mask();
 	} else {
 		pm_pr_dbg("Hibernation image restored successfully.\n");
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 2/4] PM: hibernate: add pm_hibernation_snapshot_done() helper
  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                     ` 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
  3 siblings, 0 replies; 24+ messages in thread
From: Haowen Tu @ 2026-07-29  7:11 UTC (permalink / raw)
  To: laurent.pinchart, rafael
  Cc: gregkh, hansg, kernel, lenb, linux-kernel, linux-media, linux-pm,
	linux-usb, mchehab, oneukum, pavel, stern, tuhaowen

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.

Acked-by: Rafael J. Wysocki (Intel) <rafael@kernel.org>
Signed-off-by: Haowen Tu <tuhaowen@uniontech.com>
---
 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

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 3/4] PM: hibernate: notify on image write failure
  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                     ` Haowen Tu
  2026-07-29  7:11                     ` [PATCH v4 4/4] media: uvcvideo: defer streaming restart after hibernation snapshot Haowen Tu
  3 siblings, 0 replies; 24+ messages in thread
From: Haowen Tu @ 2026-07-29  7:11 UTC (permalink / raw)
  To: laurent.pinchart, rafael
  Cc: gregkh, hansg, kernel, lenb, linux-kernel, linux-media, linux-pm,
	linux-usb, mchehab, oneukum, pavel, stern, tuhaowen

Some drivers may defer device-specific resume work after the hibernation
snapshot has been created, because the system is expected to either write
the image and power off, or enter the test-resume path.

If writing the image fails, however, the original kernel continues
running. Add a PM_HIBERNATION_IMAGE_WRITE_FAILED notification after
swsusp_write() fails and before userspace is thawed, so drivers that
deferred resume work can recover their device state before userspace
observes it.

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

diff --git a/include/linux/suspend.h b/include/linux/suspend.h
index 2cebbec3e2f7..36a5b3a8cb38 100644
--- a/include/linux/suspend.h
+++ b/include/linux/suspend.h
@@ -441,6 +441,7 @@ static inline int is_hibernate_resume_dev(dev_t dev) { return 0; }
 #define PM_POST_SUSPEND		0x0004 /* Suspend finished */
 #define PM_RESTORE_PREPARE	0x0005 /* Going to restore a saved image */
 #define PM_POST_RESTORE		0x0006 /* Restore failed */
+#define PM_HIBERNATION_IMAGE_WRITE_FAILED	0x0007 /* Image write failed */
 
 extern struct mutex system_transition_mutex;
 
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 045d29f55011..592862fd45d4 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -890,6 +890,9 @@ int hibernate(void)
 				power_down();
 		}
 		pm_restore_gfp_mask();
+
+		if (error)
+			pm_notifier_call_chain(PM_HIBERNATION_IMAGE_WRITE_FAILED);
 	} else {
 		pm_pr_dbg("Hibernation image restored successfully.\n");
 	}
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 4/4] media: uvcvideo: defer streaming restart after hibernation snapshot
  2026-07-29  7:11                   ` [PATCH v4 0/4] PM: hibernate: defer UVC streaming restart after snapshot Haowen Tu
                                       ` (2 preceding siblings ...)
  2026-07-29  7:11                     ` [PATCH v4 3/4] PM: hibernate: notify on image write failure Haowen Tu
@ 2026-07-29  7:11                     ` Haowen Tu
  2026-07-29  7:29                       ` Hans de Goede
  3 siblings, 1 reply; 24+ messages in thread
From: Haowen Tu @ 2026-07-29  7:11 UTC (permalink / raw)
  To: laurent.pinchart, rafael
  Cc: gregkh, hansg, kernel, lenb, linux-kernel, linux-media, linux-pm,
	linux-usb, mchehab, oneukum, pavel, stern, tuhaowen

When a UVC camera is streaming and the system enters hibernation, the
streaming interface is frozen before the snapshot is created. The
original kernel then resumes devices with PMSG_THAW so it can write the
hibernation image.

Restarting UVC streaming during this transient phase can turn the camera
LED back on and generate USB traffic even though the normal successful
path writes the image and powers off. USB interface resume callbacks do
not receive the PM message, so use pm_hibernation_snapshot_done() to
detect this phase and defer the streaming restart.

The deferred state is kept in the UVC stream. If image writeout succeeds,
the system powers off and no restart is needed. If image writeout fails,
the PM core sends PM_HIBERNATION_IMAGE_WRITE_FAILED before userspace is
thawed; the UVC PM notifier then restarts streams whose resume was
deferred. If that recovery restart fails, fall back to the existing
streamoff error path so userspace is notified instead of waiting on
buffers indefinitely.

Signed-off-by: Haowen Tu <tuhaowen@uniontech.com>
---
 drivers/media/usb/uvc/uvc_driver.c | 56 +++++++++++++++++++++++++++++-
 drivers/media/usb/uvc/uvc_video.c  | 19 +++++++++-
 drivers/media/usb/uvc/uvcvideo.h   |  2 ++
 3 files changed, 75 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c
index 31b4ac3b48c1..3cf861e0fa95 100644
--- a/drivers/media/usb/uvc/uvc_driver.c
+++ b/drivers/media/usb/uvc/uvc_driver.c
@@ -13,6 +13,7 @@
 #include <linux/list.h>
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <linux/suspend.h>
 #include <linux/usb.h>
 #include <linux/usb/quirks.h>
 #include <linux/usb/uvc.h>
@@ -38,6 +39,8 @@ unsigned int uvc_dbg_param;
 unsigned int uvc_timeout_param = UVC_CTRL_STREAMING_TIMEOUT;
 
 static struct usb_driver uvc_driver;
+static LIST_HEAD(uvc_pm_devices);
+static DEFINE_MUTEX(uvc_pm_mutex);
 
 /* ------------------------------------------------------------------------
  * Utility functions
@@ -2200,6 +2203,7 @@ static int uvc_probe(struct usb_interface *intf,
 	INIT_LIST_HEAD(&dev->entities);
 	INIT_LIST_HEAD(&dev->chains);
 	INIT_LIST_HEAD(&dev->streams);
+	INIT_LIST_HEAD(&dev->pm_list);
 	kref_init(&dev->ref);
 	atomic_set(&dev->nmappings, 0);
 
@@ -2346,6 +2350,10 @@ static int uvc_probe(struct usb_interface *intf,
 	if (!(dev->quirks & UVC_QUIRK_DISABLE_AUTOSUSPEND))
 		usb_enable_autosuspend(udev);
 
+	mutex_lock(&uvc_pm_mutex);
+	list_add_tail(&dev->pm_list, &uvc_pm_devices);
+	mutex_unlock(&uvc_pm_mutex);
+
 	uvc_dbg(dev, PROBE, "UVC device initialized\n");
 
 	return 0;
@@ -2370,6 +2378,10 @@ static void uvc_disconnect(struct usb_interface *intf)
 	    UVC_SC_VIDEOSTREAMING)
 		return;
 
+	mutex_lock(&uvc_pm_mutex);
+	list_del_init(&dev->pm_list);
+	mutex_unlock(&uvc_pm_mutex);
+
 	uvc_unregister_video(dev);
 	kref_put(&dev->ref, uvc_delete);
 }
@@ -2447,6 +2459,41 @@ static int uvc_reset_resume(struct usb_interface *intf)
 	return __uvc_resume(intf, 1);
 }
 
+static int uvc_pm_notify(struct notifier_block *nb, unsigned long action,
+			 void *data)
+{
+	struct uvc_device *dev;
+	struct uvc_streaming *stream;
+	int ret;
+
+	if (action != PM_HIBERNATION_IMAGE_WRITE_FAILED)
+		return NOTIFY_DONE;
+
+	mutex_lock(&uvc_pm_mutex);
+	list_for_each_entry(dev, &uvc_pm_devices, pm_list) {
+		list_for_each_entry(stream, &dev->streams, list) {
+			if (!stream->hibernate_resume_deferred)
+				continue;
+
+			stream->hibernate_resume_deferred = 0;
+			ret = uvc_video_resume(stream, 0);
+			if (ret < 0) {
+				mutex_lock(&stream->queue.mutex);
+				vb2_streamoff(&stream->queue.queue,
+					      stream->queue.queue.type);
+				mutex_unlock(&stream->queue.mutex);
+			}
+		}
+	}
+	mutex_unlock(&uvc_pm_mutex);
+
+	return NOTIFY_OK;
+}
+
+static struct notifier_block uvc_pm_nb = {
+	.notifier_call = uvc_pm_notify,
+};
+
 /* ------------------------------------------------------------------------
  * Module parameters
  */
@@ -3291,8 +3338,15 @@ static int __init uvc_init(void)
 
 	uvc_debugfs_init();
 
+	ret = register_pm_notifier(&uvc_pm_nb);
+	if (ret < 0) {
+		uvc_debugfs_cleanup();
+		return ret;
+	}
+
 	ret = usb_register(&uvc_driver);
 	if (ret < 0) {
+		unregister_pm_notifier(&uvc_pm_nb);
 		uvc_debugfs_cleanup();
 		return ret;
 	}
@@ -3303,6 +3357,7 @@ static int __init uvc_init(void)
 static void __exit uvc_cleanup(void)
 {
 	usb_deregister(&uvc_driver);
+	unregister_pm_notifier(&uvc_pm_nb);
 	uvc_debugfs_cleanup();
 }
 
@@ -3313,4 +3368,3 @@ MODULE_AUTHOR(DRIVER_AUTHOR);
 MODULE_DESCRIPTION(DRIVER_DESC);
 MODULE_LICENSE("GPL");
 MODULE_VERSION(DRIVER_VERSION);
-
diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
index f6c8e3223796..2c57b7042856 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -12,6 +12,7 @@
 #include <linux/list.h>
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <linux/suspend.h>
 #include <linux/usb.h>
 #include <linux/usb/hcd.h>
 #include <linux/videodev2.h>
@@ -2151,11 +2152,27 @@ int uvc_video_resume(struct uvc_streaming *stream, int reset)
 	if (!uvc_queue_streaming(&stream->queue))
 		return 0;
 
+	/*
+	 * Defer restarting the streaming hardware during the transient THAW
+	 * phase after a hibernation snapshot has been created. If writing the
+	 * image succeeds, the system powers off and the restart is not needed.
+	 * If writing fails, the PM core notifies the driver before userspace is
+	 * thawed so deferred streams can be restarted.
+	 */
+	if (pm_hibernation_snapshot_done()) {
+		stream->hibernate_resume_deferred = 1;
+		return 0;
+	}
+
 	ret = uvc_commit_video(stream, &stream->ctrl);
 	if (ret < 0)
 		return ret;
 
-	return uvc_video_start_transfer(stream, GFP_NOIO);
+	ret = uvc_video_start_transfer(stream, GFP_NOIO);
+	if (!ret)
+		stream->hibernate_resume_deferred = 0;
+
+	return ret;
 }
 
 /* ------------------------------------------------------------------------
diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
index 0a0c01b2420f..c87eaaaf2749 100644
--- a/drivers/media/usb/uvc/uvcvideo.h
+++ b/drivers/media/usb/uvc/uvcvideo.h
@@ -475,6 +475,7 @@ struct uvc_streaming {
 
 	/* Buffers queue. */
 	unsigned int frozen : 1;
+	unsigned int hibernate_resume_deferred : 1;
 	struct uvc_video_queue queue;
 	struct workqueue_struct *async_wq;
 	void (*decode)(struct uvc_urb *uvc_urb, struct uvc_buffer *buf,
@@ -604,6 +605,7 @@ struct uvc_device {
 
 	/* Video Streaming interfaces */
 	struct list_head streams;
+	struct list_head pm_list;
 	struct kref ref;
 
 	/* Status Interrupt Endpoint */
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [PATCH v4 4/4] media: uvcvideo: defer streaming restart after hibernation snapshot
  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
  0 siblings, 1 reply; 24+ messages in thread
From: Hans de Goede @ 2026-07-29  7:29 UTC (permalink / raw)
  To: Haowen Tu, laurent.pinchart, rafael
  Cc: gregkh, kernel, lenb, linux-kernel, linux-media, linux-pm,
	linux-usb, mchehab, oneukum, pavel, stern

Hi Haowen,

Thank you for your work on this.

On 29-Jul-26 09:11, Haowen Tu wrote:
> When a UVC camera is streaming and the system enters hibernation, the
> streaming interface is frozen before the snapshot is created. The
> original kernel then resumes devices with PMSG_THAW so it can write the
> hibernation image.
> 
> Restarting UVC streaming during this transient phase can turn the camera
> LED back on and generate USB traffic even though the normal successful
> path writes the image and powers off.

Right, so the purpose here is to avoid the LED turning back on and
to speedup the hibernate?

IOW except for the LED turning back on and things taking slightly
longer everything works correctly with the current code, right ?

I'm wondering if it would not be better to solve this in userspace
and have userspace stop the streaming before hibernation ?

Things like network connections will also get disrupted so some sort
of system-is-going-to-suspend notification to userspace processes
sounds useful ?   This could e.g. also be used for program to save
any unsaved work (e.g. save unsaved changes in an editor to
a recovery file).

> USB interface resume callbacks do
> not receive the PM message,

Hmm, the way you word this sound like this is a problem at the USB
layer. But I think this is more of a short-coming in the generic
device model.

To clarify AFAIK the actual USB device to which the interfaces belong
also does not get a specific PM message here, right ?

The reason I'm asking is because the way this is worded in the commit
message makes it sounds like this might be something which could
be solved in the USB subsystem which I do not think is the case ?

Regards,

Hans




> so use pm_hibernation_snapshot_done() to
> detect this phase and defer the streaming restart.
> 
> The deferred state is kept in the UVC stream. If image writeout succeeds,
> the system powers off and no restart is needed. If image writeout fails,
> the PM core sends PM_HIBERNATION_IMAGE_WRITE_FAILED before userspace is
> thawed; the UVC PM notifier then restarts streams whose resume was
> deferred. If that recovery restart fails, fall back to the existing
> streamoff error path so userspace is notified instead of waiting on
> buffers indefinitely.
> 
> Signed-off-by: Haowen Tu <tuhaowen@uniontech.com>
> ---
>  drivers/media/usb/uvc/uvc_driver.c | 56 +++++++++++++++++++++++++++++-
>  drivers/media/usb/uvc/uvc_video.c  | 19 +++++++++-
>  drivers/media/usb/uvc/uvcvideo.h   |  2 ++
>  3 files changed, 75 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c
> index 31b4ac3b48c1..3cf861e0fa95 100644
> --- a/drivers/media/usb/uvc/uvc_driver.c
> +++ b/drivers/media/usb/uvc/uvc_driver.c
> @@ -13,6 +13,7 @@
>  #include <linux/list.h>
>  #include <linux/module.h>
>  #include <linux/slab.h>
> +#include <linux/suspend.h>
>  #include <linux/usb.h>
>  #include <linux/usb/quirks.h>
>  #include <linux/usb/uvc.h>
> @@ -38,6 +39,8 @@ unsigned int uvc_dbg_param;
>  unsigned int uvc_timeout_param = UVC_CTRL_STREAMING_TIMEOUT;
>  
>  static struct usb_driver uvc_driver;
> +static LIST_HEAD(uvc_pm_devices);
> +static DEFINE_MUTEX(uvc_pm_mutex);
>  
>  /* ------------------------------------------------------------------------
>   * Utility functions
> @@ -2200,6 +2203,7 @@ static int uvc_probe(struct usb_interface *intf,
>  	INIT_LIST_HEAD(&dev->entities);
>  	INIT_LIST_HEAD(&dev->chains);
>  	INIT_LIST_HEAD(&dev->streams);
> +	INIT_LIST_HEAD(&dev->pm_list);
>  	kref_init(&dev->ref);
>  	atomic_set(&dev->nmappings, 0);
>  
> @@ -2346,6 +2350,10 @@ static int uvc_probe(struct usb_interface *intf,
>  	if (!(dev->quirks & UVC_QUIRK_DISABLE_AUTOSUSPEND))
>  		usb_enable_autosuspend(udev);
>  
> +	mutex_lock(&uvc_pm_mutex);
> +	list_add_tail(&dev->pm_list, &uvc_pm_devices);
> +	mutex_unlock(&uvc_pm_mutex);
> +
>  	uvc_dbg(dev, PROBE, "UVC device initialized\n");
>  
>  	return 0;
> @@ -2370,6 +2378,10 @@ static void uvc_disconnect(struct usb_interface *intf)
>  	    UVC_SC_VIDEOSTREAMING)
>  		return;
>  
> +	mutex_lock(&uvc_pm_mutex);
> +	list_del_init(&dev->pm_list);
> +	mutex_unlock(&uvc_pm_mutex);
> +
>  	uvc_unregister_video(dev);
>  	kref_put(&dev->ref, uvc_delete);
>  }
> @@ -2447,6 +2459,41 @@ static int uvc_reset_resume(struct usb_interface *intf)
>  	return __uvc_resume(intf, 1);
>  }
>  
> +static int uvc_pm_notify(struct notifier_block *nb, unsigned long action,
> +			 void *data)
> +{
> +	struct uvc_device *dev;
> +	struct uvc_streaming *stream;
> +	int ret;
> +
> +	if (action != PM_HIBERNATION_IMAGE_WRITE_FAILED)
> +		return NOTIFY_DONE;
> +
> +	mutex_lock(&uvc_pm_mutex);
> +	list_for_each_entry(dev, &uvc_pm_devices, pm_list) {
> +		list_for_each_entry(stream, &dev->streams, list) {
> +			if (!stream->hibernate_resume_deferred)
> +				continue;
> +
> +			stream->hibernate_resume_deferred = 0;
> +			ret = uvc_video_resume(stream, 0);
> +			if (ret < 0) {
> +				mutex_lock(&stream->queue.mutex);
> +				vb2_streamoff(&stream->queue.queue,
> +					      stream->queue.queue.type);
> +				mutex_unlock(&stream->queue.mutex);
> +			}
> +		}
> +	}
> +	mutex_unlock(&uvc_pm_mutex);
> +
> +	return NOTIFY_OK;
> +}
> +
> +static struct notifier_block uvc_pm_nb = {
> +	.notifier_call = uvc_pm_notify,
> +};
> +
>  /* ------------------------------------------------------------------------
>   * Module parameters
>   */
> @@ -3291,8 +3338,15 @@ static int __init uvc_init(void)
>  
>  	uvc_debugfs_init();
>  
> +	ret = register_pm_notifier(&uvc_pm_nb);
> +	if (ret < 0) {
> +		uvc_debugfs_cleanup();
> +		return ret;
> +	}
> +
>  	ret = usb_register(&uvc_driver);
>  	if (ret < 0) {
> +		unregister_pm_notifier(&uvc_pm_nb);
>  		uvc_debugfs_cleanup();
>  		return ret;
>  	}
> @@ -3303,6 +3357,7 @@ static int __init uvc_init(void)
>  static void __exit uvc_cleanup(void)
>  {
>  	usb_deregister(&uvc_driver);
> +	unregister_pm_notifier(&uvc_pm_nb);
>  	uvc_debugfs_cleanup();
>  }
>  
> @@ -3313,4 +3368,3 @@ MODULE_AUTHOR(DRIVER_AUTHOR);
>  MODULE_DESCRIPTION(DRIVER_DESC);
>  MODULE_LICENSE("GPL");
>  MODULE_VERSION(DRIVER_VERSION);
> -
> diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> index f6c8e3223796..2c57b7042856 100644
> --- a/drivers/media/usb/uvc/uvc_video.c
> +++ b/drivers/media/usb/uvc/uvc_video.c
> @@ -12,6 +12,7 @@
>  #include <linux/list.h>
>  #include <linux/module.h>
>  #include <linux/slab.h>
> +#include <linux/suspend.h>
>  #include <linux/usb.h>
>  #include <linux/usb/hcd.h>
>  #include <linux/videodev2.h>
> @@ -2151,11 +2152,27 @@ int uvc_video_resume(struct uvc_streaming *stream, int reset)
>  	if (!uvc_queue_streaming(&stream->queue))
>  		return 0;
>  
> +	/*
> +	 * Defer restarting the streaming hardware during the transient THAW
> +	 * phase after a hibernation snapshot has been created. If writing the
> +	 * image succeeds, the system powers off and the restart is not needed.
> +	 * If writing fails, the PM core notifies the driver before userspace is
> +	 * thawed so deferred streams can be restarted.
> +	 */
> +	if (pm_hibernation_snapshot_done()) {
> +		stream->hibernate_resume_deferred = 1;
> +		return 0;
> +	}
> +
>  	ret = uvc_commit_video(stream, &stream->ctrl);
>  	if (ret < 0)
>  		return ret;
>  
> -	return uvc_video_start_transfer(stream, GFP_NOIO);
> +	ret = uvc_video_start_transfer(stream, GFP_NOIO);
> +	if (!ret)
> +		stream->hibernate_resume_deferred = 0;
> +
> +	return ret;
>  }
>  
>  /* ------------------------------------------------------------------------
> diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
> index 0a0c01b2420f..c87eaaaf2749 100644
> --- a/drivers/media/usb/uvc/uvcvideo.h
> +++ b/drivers/media/usb/uvc/uvcvideo.h
> @@ -475,6 +475,7 @@ struct uvc_streaming {
>  
>  	/* Buffers queue. */
>  	unsigned int frozen : 1;
> +	unsigned int hibernate_resume_deferred : 1;
>  	struct uvc_video_queue queue;
>  	struct workqueue_struct *async_wq;
>  	void (*decode)(struct uvc_urb *uvc_urb, struct uvc_buffer *buf,
> @@ -604,6 +605,7 @@ struct uvc_device {
>  
>  	/* Video Streaming interfaces */
>  	struct list_head streams;
> +	struct list_head pm_list;
>  	struct kref ref;
>  
>  	/* Status Interrupt Endpoint */


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v4 4/4] media: uvcvideo: defer streaming restart after hibernation snapshot
  2026-07-29  7:29                       ` Hans de Goede
@ 2026-07-29  7:56                         ` Haowen Tu
  2026-07-29 14:08                           ` Alan Stern
  0 siblings, 1 reply; 24+ messages in thread
From: Haowen Tu @ 2026-07-29  7:56 UTC (permalink / raw)
  To: hansg
  Cc: gregkh, kernel, laurent.pinchart, lenb, linux-kernel, linux-media,
	linux-pm, linux-usb, mchehab, oneukum, pavel, rafael, stern,
	tuhaowen

Hi Hans,

On Wed, Jul 29, 2026 at 09:29:03AM +0200, Hans de Goede wrote:
> Right, so the purpose here is to avoid the LED turning back on and
> to speedup the hibernate?
>
> IOW except for the LED turning back on and things taking slightly
> longer everything works correctly with the current code, right ?

Yes, the current code is functionally correct in the sense that the
hibernation flow can complete and the camera can be restored afterwards.

The issue was reported as a user-visible privacy concern.  When an active
UVC camera enters hibernation, the camera LED turns off during the freeze
phase but turns back on after the snapshot has been created, while the
system is writing the hibernation image.  From the user's point of view,
this looks like the camera has been activated again during the
hibernation transition.

I am not claiming that this causes image data to be exposed.  The problem
is the unnecessary hardware reactivation and the resulting unexpected
privacy-indicator behavior during a system power transition.

Avoiding the restart also avoids unnecessary device work in this window,
but I do not intend to make performance the main argument here.  The
primary goal is to avoid the unexpected camera reactivation.

> I'm wondering if it would not be better to solve this in userspace
> and have userspace stop the streaming before hibernation ?

That would help when all userspace camera users cooperate, but I don't
think it is equivalent to handling this in the driver.

UVC is a generic driver and the kernel PM transition can happen while an
application is actively streaming.  Relying on every userspace camera
consumer to stop streaming before hibernation would make the behavior
depend on userspace policy and application support.  The driver already
knows whether streaming was active at freeze time, and it is also the
component that restarts the hardware during resume, so it can avoid this
specific unnecessary hardware restart more reliably.

> Hmm, the way you word this sound like this is a problem at the USB
> layer. But I think this is more of a short-coming in the generic
> device model.
>
> To clarify AFAIK the actual USB device to which the interfaces belong
> also does not get a specific PM message here, right ?
>
> The reason I'm asking is because the way this is worded in the commit
> message makes it sounds like this might be something which could
> be solved in the USB subsystem which I do not think is the case ?

Yes, that is my understanding as well.  The USB device resume path does
not expose the specific PM transition type to the UVC interface driver's
resume callback.

The problem was observed in UVC, and the immediate reason there is that
the UVC resume path is reached through usb_driver.resume(), which does
not receive the PM event.  But I agree that this should not be worded as
a USB subsystem bug.

My earlier thought was to expose the THAW/RESTORE distinction through
USB, but that would still need coordination with the PM core, and it
would only cover USB drivers.  If other non-USB drivers have similar
device-specific reasons to avoid work during the post-snapshot THAW
phase, they would need their own handling too.

So I can reword the commit message to avoid implying that this is a USB
core issue.  Something like:

  Some resume callback paths, including the UVC path through
  usb_driver.resume(), do not receive the PM event and therefore cannot
  distinguish the transient post-snapshot THAW phase from the later
  RESTORE phase using their local callback arguments.

The helper is intended to expose only the hibernation snapshot state.
Whether it is safe or useful to defer any work remains a driver-specific
decision.

Thanks,
Haowen

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v4 4/4] media: uvcvideo: defer streaming restart after hibernation snapshot
  2026-07-29  7:56                         ` Haowen Tu
@ 2026-07-29 14:08                           ` Alan Stern
  2026-07-29 14:43                             ` Oliver Neukum
  0 siblings, 1 reply; 24+ messages in thread
From: Alan Stern @ 2026-07-29 14:08 UTC (permalink / raw)
  To: Haowen Tu
  Cc: hansg, gregkh, kernel, laurent.pinchart, lenb, linux-kernel,
	linux-media, linux-pm, linux-usb, mchehab, oneukum, pavel, rafael

On Wed, Jul 29, 2026 at 03:56:55PM +0800, Haowen Tu wrote:
> Hi Hans,
> 
> On Wed, Jul 29, 2026 at 09:29:03AM +0200, Hans de Goede wrote:
> > Right, so the purpose here is to avoid the LED turning back on and
> > to speedup the hibernate?
> >
> > IOW except for the LED turning back on and things taking slightly
> > longer everything works correctly with the current code, right ?
> 
> Yes, the current code is functionally correct in the sense that the
> hibernation flow can complete and the camera can be restored afterwards.
> 
> The issue was reported as a user-visible privacy concern.  When an active
> UVC camera enters hibernation, the camera LED turns off during the freeze
> phase but turns back on after the snapshot has been created, while the
> system is writing the hibernation image.  From the user's point of view,
> this looks like the camera has been activated again during the
> hibernation transition.
> 
> I am not claiming that this causes image data to be exposed.  The problem
> is the unnecessary hardware reactivation and the resulting unexpected
> privacy-indicator behavior during a system power transition.
> 
> Avoiding the restart also avoids unnecessary device work in this window,
> but I do not intend to make performance the main argument here.  The
> primary goal is to avoid the unexpected camera reactivation.
> 
> > I'm wondering if it would not be better to solve this in userspace
> > and have userspace stop the streaming before hibernation ?
> 
> That would help when all userspace camera users cooperate, but I don't
> think it is equivalent to handling this in the driver.
> 
> UVC is a generic driver and the kernel PM transition can happen while an
> application is actively streaming.  Relying on every userspace camera
> consumer to stop streaming before hibernation would make the behavior
> depend on userspace policy and application support.  The driver already
> knows whether streaming was active at freeze time, and it is also the
> component that restarts the hardware during resume, so it can avoid this
> specific unnecessary hardware restart more reliably.
> 
> > Hmm, the way you word this sound like this is a problem at the USB
> > layer. But I think this is more of a short-coming in the generic
> > device model.
> >
> > To clarify AFAIK the actual USB device to which the interfaces belong
> > also does not get a specific PM message here, right ?
> >
> > The reason I'm asking is because the way this is worded in the commit
> > message makes it sounds like this might be something which could
> > be solved in the USB subsystem which I do not think is the case ?
> 
> Yes, that is my understanding as well.  The USB device resume path does
> not expose the specific PM transition type to the UVC interface driver's
> resume callback.
> 
> The problem was observed in UVC, and the immediate reason there is that
> the UVC resume path is reached through usb_driver.resume(), which does
> not receive the PM event.  But I agree that this should not be worded as
> a USB subsystem bug.
> 
> My earlier thought was to expose the THAW/RESTORE distinction through
> USB, but that would still need coordination with the PM core, and it
> would only cover USB drivers.  If other non-USB drivers have similar
> device-specific reasons to avoid work during the post-snapshot THAW
> phase, they would need their own handling too.
> 
> So I can reword the commit message to avoid implying that this is a USB
> core issue.  Something like:
> 
>   Some resume callback paths, including the UVC path through
>   usb_driver.resume(), do not receive the PM event and therefore cannot
>   distinguish the transient post-snapshot THAW phase from the later
>   RESTORE phase using their local callback arguments.
> 
> The helper is intended to expose only the hibernation snapshot state.
> Whether it is safe or useful to defer any work remains a driver-specific
> decision.

You're missing an important fact: If something goes wrong during the 
hibernation transition (for example, if the kernel's memory image can't 
be stored to disk) then there will be no RESTORE phase.  Following the 
THAW phase, the system will return to normal operation.

For this reason, during THAW drivers must not assume that the system is 
about to power down.

Alan Stern

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v4 4/4] media: uvcvideo: defer streaming restart after hibernation snapshot
  2026-07-29 14:08                           ` Alan Stern
@ 2026-07-29 14:43                             ` Oliver Neukum
  2026-07-29 14:54                               ` Alan Stern
  0 siblings, 1 reply; 24+ messages in thread
From: Oliver Neukum @ 2026-07-29 14:43 UTC (permalink / raw)
  To: Alan Stern, Haowen Tu
  Cc: hansg, gregkh, kernel, laurent.pinchart, lenb, linux-kernel,
	linux-media, linux-pm, linux-usb, mchehab, pavel, rafael

On 29.07.26 16:08, Alan Stern wrote:

> You're missing an important fact: If something goes wrong during the
> hibernation transition (for example, if the kernel's memory image can't
> be stored to disk) then there will be no RESTORE phase.  Following the
> THAW phase, the system will return to normal operation.

Right, but that does not need to mean that the driver has to be operational
at the THAW phase. It has to be operational before userland is unfrozen
again at the latest. The difficulty how the driver learns that the system
will not power down remains to be solved.
  
> For this reason, during THAW drivers must not assume that the system is
> about to power down.

True. For this reason the patch introduces a notifier queue.

Now, that you make me think about that it seems to be inelegant, as this throws
away the proper order of the device tree. It seems to me that we should
bite the bullet and go for the big solution:

Split the THAW phase in two, like a THAW_WRITEOUT and an optional
THAW_BAILOUT that is called only when the system does not power down.

	Regards
		Oliver


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v4 4/4] media: uvcvideo: defer streaming restart after hibernation snapshot
  2026-07-29 14:43                             ` Oliver Neukum
@ 2026-07-29 14:54                               ` Alan Stern
  0 siblings, 0 replies; 24+ messages in thread
From: Alan Stern @ 2026-07-29 14:54 UTC (permalink / raw)
  To: Oliver Neukum
  Cc: Haowen Tu, hansg, gregkh, kernel, laurent.pinchart, lenb,
	linux-kernel, linux-media, linux-pm, linux-usb, mchehab, pavel,
	rafael

On Wed, Jul 29, 2026 at 04:43:44PM +0200, Oliver Neukum wrote:
> On 29.07.26 16:08, Alan Stern wrote:
> 
> > You're missing an important fact: If something goes wrong during the
> > hibernation transition (for example, if the kernel's memory image can't
> > be stored to disk) then there will be no RESTORE phase.  Following the
> > THAW phase, the system will return to normal operation.
> 
> Right, but that does not need to mean that the driver has to be operational
> at the THAW phase. It has to be operational before userland is unfrozen
> again at the latest. The difficulty how the driver learns that the system
> will not power down remains to be solved.
> > For this reason, during THAW drivers must not assume that the system is
> > about to power down.
> 
> True. For this reason the patch introduces a notifier queue.
> 
> Now, that you make me think about that it seems to be inelegant, as this throws
> away the proper order of the device tree. It seems to me that we should
> bite the bullet and go for the big solution:
> 
> Split the THAW phase in two, like a THAW_WRITEOUT and an optional
> THAW_BAILOUT that is called only when the system does not power down.

I could think up some better names for it.  Also, it doesn't fit into 
the existing scheme of callbacks, whereby each "suspend"-type callback 
has a corresponding "resume"-type callback.  The new one you're 
proposing would be something different -- a "stay-alive" callback, 
neither suspend nor resume.

Alan Stern

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2026-07-29 14:54 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20260428080513.1833515-1-tuhaowen@uniontech.com>
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           ` [PATCH v3 2/3] PM: hibernate: add pm_hibernation_snapshot_done() helper Haowen Tu
2026-07-22 15:40             ` 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-05-28  8:18   ` [PATCH v2 2/2] media: uvcvideo: skip resume " Haowen Tu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox