Re: [RFC] USB/PM: should USB interface drivers distinguish hibernation THAW from RESTORE?

From: Alan Stern

Date: Wed Apr 29 2026 - 10:25:25 EST


On Wed, Apr 29, 2026 at 11:36:17AM +0800, Haowen Tu wrote:
> Hi,
>
> I'm looking for feedback on a USB/PM design question that came up while
> investigating a UVC hibernation issue.
>
> In the hibernation flow, after the memory snapshot has been created, the
> kernel briefly resumes devices in order to write the image to storage.
> On the successful hibernation path, the system is then powered off. For
> a USB camera that was actively streaming before hibernation, this means
> the USB resume path runs during that intermediate THAW phase, even
> though the final RESTORE path has not happened yet.
>
> From the driver's point of view, that THAW phase is not semantically the
> same as the later RESTORE path after booting from the image.
>
> The difficulty is that USB interface drivers currently get
>
> int (*suspend)(struct usb_interface *intf, pm_message_t message);
>
> but resume-side callbacks are only
>
> int (*resume)(struct usb_interface *intf);
> int (*reset_resume)(struct usb_interface *intf);
>
> so by the time a USB interface driver's resume path runs, it has no
> direct way to distinguish a hibernation image-write THAW from the later
> RESTORE path.
>
> The immediate trigger here is UVC, where resuming the streaming path
> during that THAW phase can turn the camera LED back on and cause other
> visible device activity even though the system is about to power off.

You don't know that. As Oliver pointed out, if writing out the system's
hibernation image fails, the system will not power off.

And anyway, what's wrong with turning the camera LED back on and
performing other visible device activity during the THAW phase of
hibernation? If it helps, don't think of this as momentarily resuming
activity during a shutdown -- instead think of the preceding FREEZE
phase as momentarily pausing all activity while the system is still
running.

Note that during the FREEZE phase, devices are not required to go to
low power, just to stop transferring data. It would be okay to leave
the LED on during the FREEZE.

> More generally, review feedback on that patch was that solving this in
> individual leaf drivers would not scale well if other USB interface
> drivers ever need similar behavior.

It's not clear to me that anything needs to be solved.

> So the question is whether USB interface drivers should be able to
> distinguish these two phases, and if so, what the right interface would
> be.
>
> Possible directions could include:
>
> 1. Exposing the phase distinction to USB interface drivers
> 2. Handling it inside usbcore
> 3. Adding a USB-specific callback or other mechanism for this
> transition
>
> I'm intentionally not proposing a concrete API in this RFC yet. I'd
> first like to understand whether this should be considered a real USB PM
> interface issue, and if so, which direction would be the least
> intrusive and most maintainable.

Before anything gets changed, you should provide a good justification
for changing it.

Alan Stern