* [PATCH 0/2] PM: hibernate: add helper to detect image-write phase @ 2026-04-28 8:05 Haowen Tu 2026-04-28 8:05 ` [PATCH 1/2] PM: hibernate: add pm_hibernation_storing_image() helper Haowen Tu 2026-04-28 8:05 ` [PATCH 2/2] media: uvcvideo: skip resume when writing hibernation image Haowen Tu 0 siblings, 2 replies; 8+ messages in thread From: Haowen Tu @ 2026-04-28 8:05 UTC (permalink / raw) To: rafael Cc: lenb, pavel, linux-pm, laurent.pinchart, hansg, mchehab, linux-media, linux-kernel, Haowen Tu During S4 hibernation, after create_image() saves the memory snapshot, the kernel resumes devices with PMSG_THAW solely to write the hibernation image to storage before final powerdown. Drivers unrelated to storage I/O have no reason to reinitialize during this transient phase. Drivers using dev_pm_ops already have separate .thaw and .restore callbacks and can handle this natively. However, usb_driver.resume takes no pm_message_t argument, so a USB driver cannot distinguish PMSG_THAW from PMSG_RESTORE without an out-of-band query. This series adds pm_hibernation_storing_image(), a small helper that returns true during the image-write window. As a first user, the UVC driver uses it to skip resume in uvc_video_resume() until the real PMSG_RESTORE wake-up. Tested with hibernation image written to local storage and resumed from disk on a system with a USB UVC camera attached. Haowen Tu (2): pm/hibernate: add pm_hibernation_storing_image() helper media: uvcvideo: skip resume when writing hibernation image drivers/media/usb/uvc/uvc_video.c | 10 ++++++++++ include/linux/suspend.h | 2 ++ kernel/power/hibernate.c | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+) -- 2.20.1 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/2] PM: hibernate: add pm_hibernation_storing_image() helper 2026-04-28 8:05 [PATCH 0/2] PM: hibernate: add helper to detect image-write phase Haowen Tu @ 2026-04-28 8:05 ` Haowen Tu 2026-04-28 8:05 ` [PATCH 2/2] media: uvcvideo: skip resume when writing hibernation image Haowen Tu 1 sibling, 0 replies; 8+ messages in thread From: Haowen Tu @ 2026-04-28 8:05 UTC (permalink / raw) To: rafael Cc: lenb, pavel, linux-pm, laurent.pinchart, hansg, mchehab, linux-media, linux-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_storing_image() for this purpose. The implementation returns !!in_suspend, which is set to 1 in create_image() just before swsusp_arch_suspend() and reset to 0 in hibernate() after swsusp_write() completes. Because in_suspend is marked __nosavedata, it is not saved into the hibernation image; on the restore path the variable remains 0 throughout, so the helper correctly returns false during PMSG_RESTORE device resume. Signed-off-by: Haowen Tu <tuhaowen@uniontech.com> --- include/linux/suspend.h | 2 ++ kernel/power/hibernate.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/linux/suspend.h b/include/linux/suspend.h index b02876f1ae38..28b454def83d 100644 --- a/include/linux/suspend.h +++ b/include/linux/suspend.h @@ -393,6 +393,7 @@ extern void hibernation_set_ops(const struct platform_hibernation_ops *ops); extern int hibernate(void); extern bool system_entering_hibernation(void); extern bool hibernation_available(void); +extern bool pm_hibernation_storing_image(void); asmlinkage int swsusp_save(void); extern struct pbe *restore_pblist; int pfn_is_nosave(unsigned long pfn); @@ -412,6 +413,7 @@ static inline void hibernation_set_ops(const struct platform_hibernation_ops *op static inline int hibernate(void) { return -ENOSYS; } static inline bool system_entering_hibernation(void) { return false; } static inline bool hibernation_available(void) { return false; } +static inline bool pm_hibernation_storing_image(void) { return false; } static inline int hibernate_quiet_exec(int (*func)(void *data), void *data) { return -ENOTSUPP; diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index af8d07bafe02..bc632cce40ff 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -113,6 +113,25 @@ bool hibernation_available(void) !secretmem_active() && !cxl_mem_active(); } +/** + * pm_hibernation_storing_image - check if system is writing the hibernation image + * + * After create_image() saves a memory snapshot, the kernel briefly resumes + * devices with PMSG_THAW to write the image to storage before final powerdown. + * Drivers for hardware not involved in storage I/O may call this helper from + * their resume callbacks to skip unnecessary hardware initialization during + * that transient phase. + * + * Context: May be called from device PM callbacks. + * Return: %true if a hibernation snapshot has been taken and the system is + * in the process of writing the image to persistent storage. + */ +bool pm_hibernation_storing_image(void) +{ + return !!in_suspend; +} +EXPORT_SYMBOL_GPL(pm_hibernation_storing_image); + /** * hibernation_set_ops - Set the global hibernate operations. * @ops: Hibernation operations to use in subsequent hibernation transitions. -- 2.20.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/2] media: uvcvideo: skip resume when writing hibernation image 2026-04-28 8:05 [PATCH 0/2] PM: hibernate: add helper to detect image-write phase Haowen Tu 2026-04-28 8:05 ` [PATCH 1/2] PM: hibernate: add pm_hibernation_storing_image() helper Haowen Tu @ 2026-04-28 8:05 ` Haowen Tu 2026-04-28 8:36 ` Oliver Neukum 2026-04-28 9:13 ` Laurent Pinchart 1 sibling, 2 replies; 8+ messages in thread From: Haowen Tu @ 2026-04-28 8:05 UTC (permalink / raw) To: rafael Cc: lenb, pavel, linux-pm, laurent.pinchart, hansg, mchehab, linux-media, linux-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 and return early from uvc_video_resume(), preventing the unnecessary hardware reinitialization and the spurious LED activation. Skipping the THAW resume is safe: stream->frozen remains 1 (set during the earlier FREEZE suspend), the device is powered off immediately after swsusp_write() with no intervening suspend, and the subsequent PMSG_RESTORE resume on the restored kernel calls uvc_video_resume() with pm_hibernation_storing_image() returning false, performing the full reinitialization as normal. Signed-off-by: Haowen Tu <tuhaowen@uniontech.com> --- drivers/media/usb/uvc/uvc_video.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index f6c8e3223796..16a911b684d5 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> @@ -2135,6 +2136,15 @@ int uvc_video_resume(struct uvc_streaming *stream, int reset) { int ret; + /* + * After taking the hibernation memory snapshot, the kernel briefly resumes + * devices with PMSG_THAW to write the image to storage before powerdown. + * The UVC device is not involved in storage I/O, so skip reinitializing + * it to avoid unnecessary USB traffic during this transient phase. + */ + if (pm_hibernation_storing_image()) + return 0; + /* * If the bus has been reset on resume, set the alternate setting to 0. * This should be the default value, but some devices crash or otherwise -- 2.20.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] media: uvcvideo: skip resume when writing hibernation image 2026-04-28 8:05 ` [PATCH 2/2] media: uvcvideo: skip resume when writing hibernation image Haowen Tu @ 2026-04-28 8:36 ` Oliver Neukum 2026-04-28 8:58 ` Haowen Tu 2026-04-28 9:13 ` Laurent Pinchart 1 sibling, 1 reply; 8+ messages in thread From: Oliver Neukum @ 2026-04-28 8:36 UTC (permalink / raw) To: Haowen Tu, rafael Cc: lenb, pavel, linux-pm, laurent.pinchart, hansg, mchehab, linux-media, linux-kernel Hi, On 28.04.26 10:05, Haowen Tu wrote: > Skipping the THAW resume is safe: stream->frozen remains 1 (set during > the earlier FREEZE suspend), the device is powered off immediately after > swsusp_write() with no intervening suspend, and the subsequent > PMSG_RESTORE resume on the restored kernel calls uvc_video_resume() > with pm_hibernation_storing_image() returning false, performing the full > reinitialization as normal. > What happens if writing out the image fails? Regards Oliver ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] media: uvcvideo: skip resume when writing hibernation image 2026-04-28 8:36 ` Oliver Neukum @ 2026-04-28 8:58 ` Haowen Tu 0 siblings, 0 replies; 8+ messages in thread From: Haowen Tu @ 2026-04-28 8:58 UTC (permalink / raw) To: oneukum Cc: hansg, laurent.pinchart, lenb, linux-kernel, linux-media, linux-pm, mchehab, pavel, rafael, tuhaowen Hi Oliver, On Tue, 28 Apr 2026, Oliver Neukum wrote: > What happens if writing out the image fails? Thanks for pointing this out. If swsusp_write() fails, the system resumes in the original kernel instead of powering off, so the failure path needs to be considered as well. I was reasoning about the successful hibernation path here, but you are right that skipping resume work during THAW may not be safe if the image write does not complete. I will trace the failure path more carefully and update the series accordingly. Thanks, Haowen Tu ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] media: uvcvideo: skip resume when writing hibernation image 2026-04-28 8:05 ` [PATCH 2/2] media: uvcvideo: skip resume when writing hibernation image Haowen Tu 2026-04-28 8:36 ` Oliver Neukum @ 2026-04-28 9:13 ` Laurent Pinchart 2026-04-29 1:15 ` Haowen Tu 2026-04-29 1:16 ` Haowen Tu 1 sibling, 2 replies; 8+ messages in thread From: Laurent Pinchart @ 2026-04-28 9:13 UTC (permalink / raw) To: Haowen Tu Cc: rafael, lenb, pavel, linux-pm, hansg, mchehab, linux-media, linux-kernel On Tue, Apr 28, 2026 at 04:05:13PM +0800, Haowen Tu wrote: > 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 and return early from > uvc_video_resume(), preventing the unnecessary hardware reinitialization > and the spurious LED activation. > > Skipping the THAW resume is safe: stream->frozen remains 1 (set during > the earlier FREEZE suspend), the device is powered off immediately after > swsusp_write() with no intervening suspend, and the subsequent > PMSG_RESTORE resume on the restored kernel calls uvc_video_resume() > with pm_hibernation_storing_image() returning false, performing the full > reinitialization as normal. > > Signed-off-by: Haowen Tu <tuhaowen@uniontech.com> > --- > drivers/media/usb/uvc/uvc_video.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c > index f6c8e3223796..16a911b684d5 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> > @@ -2135,6 +2136,15 @@ int uvc_video_resume(struct uvc_streaming *stream, int reset) > { > int ret; > > + /* > + * After taking the hibernation memory snapshot, the kernel briefly resumes > + * devices with PMSG_THAW to write the image to storage before powerdown. > + * The UVC device is not involved in storage I/O, so skip reinitializing > + * it to avoid unnecessary USB traffic during this transient phase. > + */ Will all leaf drivers need to implement something similar ? How does that scale ? > + if (pm_hibernation_storing_image()) > + return 0; > + > /* > * If the bus has been reset on resume, set the alternate setting to 0. > * This should be the default value, but some devices crash or otherwise -- Regards, Laurent Pinchart ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] media: uvcvideo: skip resume when writing hibernation image 2026-04-28 9:13 ` Laurent Pinchart @ 2026-04-29 1:15 ` Haowen Tu 2026-04-29 1:16 ` Haowen Tu 1 sibling, 0 replies; 8+ messages in thread From: Haowen Tu @ 2026-04-29 1:15 UTC (permalink / raw) To: laurent.pinchart Cc: gregkh, linux-usb, hansg, mchehab, rafael, lenb, pavel, linux-pm, linux-media, linux-kernel, Haowen Tu Hi Laurent, On Tue, Apr 28, 2026 at 12:13:56PM +0300, Laurent Pinchart wrote: > Will all leaf drivers need to implement something similar ? How does > that scale ? Thanks, that's a very valid concern. If this pattern ends up being needed in multiple USB interface drivers, then handling it in each leaf driver would clearly not scale well. My initial motivation was that the UVC streaming resume path is reached from usb_driver.resume(), which doesn't expose the hibernation PM message. As a result, the driver has no way to distinguish PMSG_THAW from PMSG_RESTORE locally. That said, I agree this points to a USB-level design question rather than just a UVC-specific one. I'll revisit the approach with that in mind, and will include the USB maintainers and list in the next round. Thanks, Haowen ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] media: uvcvideo: skip resume when writing hibernation image 2026-04-28 9:13 ` Laurent Pinchart 2026-04-29 1:15 ` Haowen Tu @ 2026-04-29 1:16 ` Haowen Tu 1 sibling, 0 replies; 8+ messages in thread From: Haowen Tu @ 2026-04-29 1:16 UTC (permalink / raw) To: laurent.pinchart Cc: gregkh, linux-usb, hansg, mchehab, rafael, lenb, pavel, linux-pm, linux-media, linux-kernel, Haowen Tu Hi Laurent, On Tue, Apr 28, 2026 at 12:13:56PM +0300, Laurent Pinchart wrote: > Will all leaf drivers need to implement something similar ? How does > that scale ? Thanks, that's a very valid concern. If this pattern ends up being needed in multiple USB interface drivers, then handling it in each leaf driver would clearly not scale well. My initial motivation was that the UVC streaming resume path is reached from usb_driver.resume(), which doesn't expose the hibernation PM message. As a result, the driver has no way to distinguish PMSG_THAW from PMSG_RESTORE locally. That said, I agree this points to a USB-level design question rather than just a UVC-specific one. I'll revisit the approach with that in mind, and will include the USB maintainers and list in the next round. Thanks, Haowen ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-04-29 1:16 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-04-28 8:05 [PATCH 0/2] PM: hibernate: add helper to detect image-write phase Haowen Tu 2026-04-28 8:05 ` [PATCH 1/2] PM: hibernate: add pm_hibernation_storing_image() helper Haowen Tu 2026-04-28 8:05 ` [PATCH 2/2] media: uvcvideo: skip resume when writing hibernation image Haowen Tu 2026-04-28 8:36 ` Oliver Neukum 2026-04-28 8:58 ` Haowen Tu 2026-04-28 9:13 ` Laurent Pinchart 2026-04-29 1:15 ` Haowen Tu 2026-04-29 1:16 ` Haowen Tu
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox