Re: [PATCH v2 1/2] PM: hibernate: add pm_hibernation_snapshot_done() helper

From: Haowen Tu

Date: Mon Jun 01 2026 - 23:30:33 EST


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