From nobody Mon Jun 8 16:29:10 2026 Received: from smtpbgbr1.qq.com (smtpbgbr1.qq.com [54.207.19.206]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74B96378D82 for ; Thu, 28 May 2026 08:19:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.207.19.206 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956399; cv=none; b=n/7ommjcCdIV00i/gHEzZ/cvhkvdc0VOVAyY6doy6YDjvVq8hUOwA9YpbzRa9utjFzgoZ665SwuSqlROwYqZDdRsCLCPc8jp43vE6pDQEZEkvS6Vd1ZZ18aeubZxGOC/g2Z7DdHF8vlXG5XjqPr2T4YGYwM+6s9bo9U7fEK+CY4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956399; c=relaxed/simple; bh=nAVAHsXso3C/0PsJj5P60FI82/FmYb+nqnvDIYEgvvo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hoyWUX6O6YGadcgEAugsAbycs8GCf0CGuEZrkDEEBxLK8vsBLFcOhGPDtHCvvp2LR/ZcTRl8EcUMwsZl8adH3UKRRqQStFNkj6hAPS1UYOkHibKBq/RPFcl5vY+WwMP7tloja6QVhiuklhSAlAfSgh2Xs1FJKozXKJnB9ma26g0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uniontech.com; spf=pass smtp.mailfrom=uniontech.com; dkim=pass (1024-bit key) header.d=uniontech.com header.i=@uniontech.com header.b=RQO1kUr4; arc=none smtp.client-ip=54.207.19.206 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uniontech.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=uniontech.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=uniontech.com header.i=@uniontech.com header.b="RQO1kUr4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uniontech.com; s=onoh2408; t=1779956358; bh=hTfKHFLpQr6Uxul1FFGZN32A4tJE6awvwOwRmFziUKE=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=RQO1kUr4l2CckPcdzHM4mlAIk2Pi4J67sawh8WX5ktO14RUEukygM0ePyGgtO9LhT AOEbK0uQcful/s2zAS4zclYWfH0OSFx36cIhJUBZb4AgkypEg/b936lE3YyFF1Xcxk ro+1Q3l6Ztl9tKKyF47ZAFDwxBL6Xv96ortsWXEw= X-QQ-mid: zesmtpgz3t1779956344tbbf05453 X-QQ-Originating-IP: 8iWOHWTPwmeusF4wCfttTXj2BiriBmDGHpk8HJ2MsI0= Received: from localhost.localdomain ( [113.57.152.160]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 28 May 2026 16:18:55 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 1 X-BIZMAIL-ID: 17934321688194046005 EX-QQ-RecipientCnt: 15 From: Haowen Tu 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 Subject: [PATCH v2 1/2] PM: hibernate: add pm_hibernation_snapshot_done() helper Date: Thu, 28 May 2026 16:18:39 +0800 Message-Id: <20260528081840.3528089-2-tuhaowen@uniontech.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20260528081840.3528089-1-tuhaowen@uniontech.com> References: <20260428080513.1833515-1-tuhaowen@uniontech.com> <20260528081840.3528089-1-tuhaowen@uniontech.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: zesmtpgz:uniontech.com:qybglogicsvrsz:qybglogicsvrsz3b-0 X-QQ-XMAILINFO: M0IYNfr6MkC9JRNSETXnwWYtw3/WbSNoOco6Qy63t9G+I6+H8eWaFZJ+ Vl/CDl+PL8JjsyNET2+MnaZp14vOwPK0F9Hy+BsN9t78epR3ajN9iU90rRn4ArhO9p4Fzxx q5ng2CoBhtXQlzW5ZhfbiMfE1HcZIStup7STvokK5evYX9aEKVlOOicFPZnXWLOm08k6Lpz ZQyCvPiFCL8KVh3/2JFf+01w6VEd/fT0coCeRvgfx5sKAkYLvCvwIRB8c87JFQU5MdvoTzH RAyHl4/dK7rVlXI+0YPci/HEKklJtLL6vFrsWmVI3FZBZXxkRGIEwLPVHgcK5vAaeWd1yiz Bwx8WyPQmYyBI8M/cvH3Jcmahvmn1ktJ1PjoLDDGVhFHdATjcOes7nZuwl3UOU3eQn6+6vq YogSmEx7HfGV+hFuRiM8Xf8dcJLsH54xZ1AQq01zvY5V8IRlGTJEZI588vHvI7i4V2EGQ5G DzVODj0TIO2lTCLixBo7R9sFde/qNWY66gyWr71x//jWfhy8VSL5MdyBGW6tsuEijl3Lfk7 /AFRLOR5PQQ01ocb5ufwppDyfmgUBmnshxM4txBvvKhGDKUhb3HudH1Leu0hz1tYMDZSPnx i/PWSjOY3SymMPW/6edHsJUT4u3P/Wsvaihq7rIliA/XJiMpJlcmjAoenB5nHr73QsuoYqF +kCjRnTvXs2T23kxECdMbp1v3y7p6ip7x4oR/bXwFz+Lw4FJKskrA0QHf9OsNbxvpxwhurq kX9a+FPtqtTwZ2yjRThiLTL4gmdQawQ3kjraq6eb11CBOCgCKzd4UCF5NzlgvyWaj7FhV2T +rlJ+Yua+QfPuGDKQMOHkpsimPLE5T//HPnxG5FrG2zJro0G2jdCeBmlqQAHHOEL7RHFSdZ a2sSKm0LMRQPilqHLNkkHxPXBYF578DfmyB3V24Q+sYwdPLy9g9/gxguW6/DcczitVXo/kG TUzDGAWLRjnJ+aRf6Nqz5mjWFAQCJcPe4rBH+T+/OP3J9ySXFrV5L1hE0XcHhHkzvjjjINi verj+Xa7Gd19JVjGwTy0nxQEjdcRmC8VO62tbrB6u9M3Z07+iJJw9iQy1Z0UD7JfDlLUgTu 1f6ECCid6zCpdPp8h8LbJo= X-QQ-XMRINFO: NS+P29fieYNwqS3WCnRCOn9D1NpZuCnCRA== X-QQ-RECHKSPAM: 0 Content-Type: text/plain; charset="utf-8" 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 --- 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_h= ibernation_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 pla= tform_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; } =20 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(); } =20 +/** + * pm_hibernation_snapshot_done - check if a hibernation snapshot is avail= able + * + * After create_image() saves a memory snapshot, the kernel briefly resumes + * devices with PMSG_THAW to write the image to storage before final power= down. + * 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 transitio= ns. @@ -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; =20 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 =3D in_suspend; =20 /* We may need to release the preallocated image pages here. */ - if (error || !in_suspend) + if (error || !snapshot_done) { + in_suspend =3D 0; swsusp_free(); + } =20 - msg =3D in_suspend ? (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE; + msg =3D snapshot_done ? (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE; dpm_resume(msg); =20 - if (error || !in_suspend) + if (error || !snapshot_done) pm_restore_gfp_mask(); =20 console_resume_all(); @@ -865,6 +888,7 @@ int hibernate(void) =20 pm_pr_dbg("Writing hibernation image.\n"); error =3D swsusp_write(flags); + in_suspend =3D 0; swsusp_free(); if (!error) { if (hibernation_mode =3D=3D HIBERNATION_TEST_RESUME) @@ -872,7 +896,6 @@ int hibernate(void) else power_down(); } - in_suspend =3D 0; pm_restore_gfp_mask(); } else { pm_pr_dbg("Hibernation image restored successfully.\n"); --=20 2.20.1 From nobody Mon Jun 8 16:29:10 2026 Received: from smtpbgsg1.qq.com (smtpbgsg1.qq.com [54.254.200.92]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D94FF378830 for ; Thu, 28 May 2026 08:19:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.254.200.92 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956401; cv=none; b=pngbvF9uDXS2xh9cUs22cfwdffdqMJtuoTdV/Wl5hldwA39qEQ/8kpy7DlziaUv/thih+KL+VGXWrlZYzFiuCrlhtUvkwMAdrJ68v8WhUwHwIy/3VMZ+xfNCiE1U0mvyUik2nmvWzxo0AvgLVuT2c88CO4KVZ/1h5JCCr24pWZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779956401; c=relaxed/simple; bh=MLatFh+ITEgavEN5ELhODVOrrueAp2v6chz36/OYIfQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=H4aGBlNAztLtsaUd5VrdPpRDL/xk7MghX9k9TbOax6ufA5rvsaWFoP73VN7F8XkOHMIiTFtWph7kZZou8oa7m4jQScLo9gPNvIFH+jJM0A7dux/nG3TNKxHvsz0omC105YER5z2YkM4tHpGWmafj7TPShRcYSJgezRqCj77gzKQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uniontech.com; spf=pass smtp.mailfrom=uniontech.com; dkim=pass (1024-bit key) header.d=uniontech.com header.i=@uniontech.com header.b=X8QAun7X; arc=none smtp.client-ip=54.254.200.92 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uniontech.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=uniontech.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=uniontech.com header.i=@uniontech.com header.b="X8QAun7X" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uniontech.com; s=onoh2408; t=1779956367; bh=oeURz6oicc+pZP9AWLhlYv7MHtn2iU5Ne4XKIeL0nIc=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=X8QAun7X0dwo5JUXzGYQwEi1S+GME49fm9evWcx414Va3Q2cMqu2yQz36zHQ1UkXg 48ns6cKPcT5lYKCUd9s11+cDUwj/Dgv7KQA6CFJnQrKLHyfqIGJYaTcb661IMK3M1F +9kAY1DB1693aO+fhx2iEgwLb+W4qoEToh0pVrZo= X-QQ-mid: zesmtpgz3t1779956349t15de0229 X-QQ-Originating-IP: SYALA+0AfiCbbM+XpXJbIjiqmJcJglSmxfVd4eUuncE= Received: from localhost.localdomain ( [113.57.152.160]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 28 May 2026 16:19:06 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 1 X-BIZMAIL-ID: 10008302796186427878 EX-QQ-RecipientCnt: 15 From: Haowen Tu 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 Subject: [PATCH v2 2/2] media: uvcvideo: skip resume after hibernation snapshot Date: Thu, 28 May 2026 16:18:40 +0800 Message-Id: <20260528081840.3528089-3-tuhaowen@uniontech.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20260528081840.3528089-1-tuhaowen@uniontech.com> References: <20260428080513.1833515-1-tuhaowen@uniontech.com> <20260528081840.3528089-1-tuhaowen@uniontech.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: zesmtpgz:uniontech.com:qybglogicsvrsz:qybglogicsvrsz3b-0 X-QQ-XMAILINFO: NpT1fuJyWPv/+BwCdrMBm3WVXtPNZ7A1brXWiYFJ7JOUJ7GAkT4YlaXc RPQikeRPYgNGPt9ms6hXGGfjiKe/zp+K9glSg+539kqTBPZ7caK1WSNtEIG4yqqrnQyQZWQ yEprgIYUym0kLyB9tuGOjKKC7TqsEQa2maCrOIfb4Pg0vBLk04xUQNZdR7XDkDu7xL3t09D mXeP5SzBNUcpWqit4eOi8Yt/WJl6oecZKwzsXhEIFnSpCan7/5po9J4ynN0e7OizFuE4kNs DXbctlxjRCFtDSkaIXM8jpgvstUnmWrt8/0mhL+34F+SJk+KeoK38v5Z8mRhyqmcH0meWVd jA/tZ0X6A/vQGX7KD/GW4h/bag7PZ365EPJ153yvvQWTG154h4L92lIH9QYsuvIu//LWNAt QWF8eN/6hF0LFGvVzXkO6db0N9UptcLgVZp8NgkUBNbXA8VjWVfDif9XKklwsrffiRRQVTl ja6bcuQ8jBtK3R1Vcr6X/USpYVFCDnqDPVhniDPV86XGtrvkC5I1jC7qN3spFHAY/ypbduY asNxA6CDc+8VoKU7WXnriDekkJv8M7lNmyD+PDTgkbn+SmwHWFTc9+i9wcmaMQbjx1GbmDI 8UAVA3Ge42nU/W97IpIVHFscaPS6ugLJbSp4dVf63mWYWo01dB4FmVYJ3FXEL4bmRF5kYVz MGs0i3AxiWtoFEWmEZxxKpHVO2BbKxo0PL7YliYvV7MBYN61tp19hI46Rz73CwRlGX20u5Q dpLHRr7gFmcZddBkKuuwWJi8rtYkTuUU+hqoo14NF5lVYV/hY324na9g2ePV5hygtIH46X+ L5gQ2QIguabEGoCZnMy78ekG3XFUulv69WKf1wIjhl++EpCMmj6+h/Qb3rDpBRPNUvjNmc7 BQa/ip5aUNkvbil/fhnMHgdQ0iIMeaWi+lawQTNr2qlgS9x7h30/KvoOHLrAPvr8xkLoqoZ doVGaOBYOljIaou7oiVXJAJi15EAB0Ci5zOHNQ7NHTxjgHa3sCixK3RYCo1w+xSqg/g6MYS uGGjrIfvhs/IjD9QdByGOyhm1CyP7/gRCCyGhU9UIKcDR4kNVs0QS0NDSBTsib3rVush3LJ kgXnwhJ3uau X-QQ-XMRINFO: NS+P29fieYNwqS3WCnRCOn9D1NpZuCnCRA== X-QQ-RECHKSPAM: 0 Content-Type: text/plain; charset="utf-8" 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 --- 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 #include #include +#include #include #include #include @@ -2151,6 +2152,17 @@ int uvc_video_resume(struct uvc_streaming *stream, i= nt reset) if (!uvc_queue_streaming(&stream->queue)) return 0; =20 + /* + * 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 =3D uvc_commit_video(stream, &stream->ctrl); if (ret < 0) return ret; --=20 2.20.1