Linux USB
 help / color / mirror / Atom feed
From: Haowen Tu <tuhaowen@uniontech.com>
To: rafael@kernel.org
Cc: lenb@kernel.org, pavel@kernel.org, linux-pm@vger.kernel.org,
	laurent.pinchart@ideasonboard.com, hansg@kernel.org,
	mchehab@kernel.org, linux-media@vger.kernel.org,
	gregkh@linuxfoundation.org, stern@rowland.harvard.edu,
	oneukum@suse.com, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel@uniontech.com,
	Haowen Tu <tuhaowen@uniontech.com>
Subject: [PATCH v2 2/2] media: uvcvideo: skip resume after hibernation snapshot
Date: Thu, 28 May 2026 16:18:40 +0800	[thread overview]
Message-ID: <20260528081840.3528089-3-tuhaowen@uniontech.com> (raw)
In-Reply-To: <20260528081840.3528089-1-tuhaowen@uniontech.com>

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

      parent reply	other threads:[~2026-05-28  8:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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-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
2026-05-28  8:18   ` Haowen Tu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260528081840.3528089-3-tuhaowen@uniontech.com \
    --to=tuhaowen@uniontech.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hansg@kernel.org \
    --cc=kernel@uniontech.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=lenb@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=oneukum@suse.com \
    --cc=pavel@kernel.org \
    --cc=rafael@kernel.org \
    --cc=stern@rowland.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox