From nobody Sat Sep 26 08:37:10 2026 Received: from smtpbgsg2.qq.com (smtpbgsg2.qq.com [54.254.200.128]) (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 8449A34165B for ; Thu, 3 Sep 2026 02:16:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.254.200.128 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788401774; cv=none; b=e+QuF0dOLbIjWr9I5nyuCMjpKoNTyycTzA89oSliM47PkMV9zYgWnfUIqdsOBM/lJ4b16UfwRzW/N4WiwS6bQ8seITjxTpz98ei88rSVS7TYWw2w5rKpol5A7xOTYqA8iB2CngOlCLmNPYeYae7tnCxxFinty/u+s5EjgQDEOP0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788401774; c=relaxed/simple; bh=7uDxDA+9YGPfFObepLXMSaNMgViB4yTDUFprc9wOwvQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rz9OmuX9MzQ1nEJyR0myNRz6gV0t7v31eGa/1qZsfbfxE9v0v+NIcHixPCUuevLCGonDYIlQffU7+cFRajSzJ+9rasc2pqlYeODNBUvRxS2Fc9zM75NKjMmoBo0T07zmNBbZ4xACg1qfYNwPECVmzfxK/T4+24oChFzIeeZmADs= 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=ORWCSIhl; arc=none smtp.client-ip=54.254.200.128 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="ORWCSIhl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uniontech.com; s=onoh2408; t=1788401718; bh=e1VUNUQlMg1MCx8hA5n24AtoXedvcMVZEK6NYKkfTKg=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=ORWCSIhla07GA7oppnADl/3g7RLe/w590zxolRcn9gSoxg9gMoWXJ4Yc5jg3csAQI L06Xv+5kjeXWfd/7LRnLr6evAgQ5Lz93Er/tPffcMn6eACdsULt/UgwqvhUS7NuD1S yVUih3xMhL7JCwgAHgeuJv0wy/4zF7cDxTFx4XIM= X-QQ-mid: esmtpgz16t1788401712t3e9f05e1 X-QQ-Originating-IP: bMS2EqBMEyD8n8HuSXP+i7ZyiGSYTxj0CYMPqPnOlp0= Received: from localhost.localdomain ( [113.57.152.160]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 03 Sep 2026 10:15:10 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 1 X-BIZMAIL-ID: 6501738363549994098 EX-QQ-RecipientCnt: 15 From: Haowen Tu To: rafael@kernel.org, laurent.pinchart@ideasonboard.com Cc: tuhaowen@uniontech.com, gregkh@linuxfoundation.org, hansg@kernel.org, huangbibo@uniontech.com, lenb@kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, mchehab@kernel.org, oneukum@suse.com, pavel@kernel.org, stern@rowland.harvard.edu Subject: [PATCH v5 1/4] PM: hibernate: clear in_suspend before freeing the snapshot Date: Thu, 3 Sep 2026 10:14:56 +0800 Message-Id: <55f5c4da1e27b13d97266989166e2d877f518957.1788399733.git.tuhaowen@uniontech.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: <20260730153817.GA1555869@killaraus.ideasonboard.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: esmtpgz:uniontech.com:qybglogicsvrsz:qybglogicsvrsz3b-0 X-QQ-XMAILINFO: MzCu24z+DPuU/c4yQWhZHbt0qK33nVkZQZO5/j/455jd7xEsYg9UZkGo KfgOjaa1fcWWIDh6ODTSty+NHWnJoL5EVOrxzCJ9ujmeXR7Yyw8Wq2WuQ331UQWtJ4Y8LG3 862YdzqKF5214U6GSpftaulD66yP+SWg/PAbvIb9Lb8o0M5wpTQ3s1q2jex92PR8a4Ix8UR fYIsDm8Y5x83Sm+KNZKgJEME0AXTgROmdjXWRvjWNnjvi55MaAlS2abOqI4UutlrR1C48+x fA4viu8WoAm4hKGm6jTvomckyHSzayy7U60SPT0oH2Z3B3gzJazkkZQ2H4numccEmB4maFd wWz9G7NYwH8DhLyaVcaZQwe1V2qBVoeucQYLypLfqUGqIjQiJCPDlbC9RrmyciFYF7kCBtr R5vmA64cL1XteRi87y2Egq6nexo7MeWwib4r2pSfP0Zkl5JdIIOptu/nESGR53BWfsO6mDF XZdJ4KIIDe0zCjQgSrJ7ucX6y7ZozxLJSAZU31x6TDHZBC0GARxVAcYT/hM4lFY6oDn74vm fiygGLXI6usLV8ZjCZCVHGZ7N2eP//1SQxDztocyDTk/xtJA0YrBAzRdzOSlg9nGmyNEswR 4xZyBTgJXBhtusRd6beXZrk0ONqMGKCwyGKkBAaqpCAOTg1lfjSPvt926Aot5JqImi4c1I7 Lly5Q8ityrwfVC79NVJNk1V/0ec6PrpJokn7vRdkMrXPWyUVlPFxTqAULH8GOtZ7eIuq6bf 4+juM320RcDNqatuPN1I76gjnwfDsAZ5FGXnOIAdUnuxlfhmFC3HCfBEdr78Idtp6h65f/N Aq++yD0wFKY17YnPzEVOGyBfoY22w8/vKTX1Re/8ukQNQdGv7OUdSxfs/jFevMJRUG2Q3Oo pC4+Mj3ta+wZ6ygB843BgryI5qzBkwrV/ZrJFT8H6FqZ69ZM7i3ztmHGXQ2gWtH4f45SX/F 0tj1fNMRv03Ih+yBPKcBWqwmk1QM9w+9+jTlzr1kkjIqQkUYji98B2igRYWBHkmdp4yKHRS kOqgFoMvH6ZicH4EI/4Dn+2nAR5SGs6f/Zt72WuMw31vmE3r8Rr3XUgo1x3n+rxj5Zv0oxA g== X-QQ-XMRINFO: MSVp+SPm3vtSI1QTLgDHQqIV1w2oNKDqfg== X-QQ-RECHKSPAM: 0 Content-Type: text/plain; charset="utf-8" in_suspend indicates that a hibernation snapshot has been created and is still available. Keep that state consistent with the lifetime of the snapshot memory by clearing in_suspend before swsusp_free() releases it. If image creation fails after in_suspend has been set, hibernation_snapshot() releases the snapshot memory but currently leaves in_suspend set. Preserve its value locally long enough to select the appropriate device resume message, then clear it before releasing the snapshot. Also clear in_suspend before releasing the snapshot after swsusp_write() returns. Signed-off-by: Haowen Tu Acked-by: Rafael J. Wysocki (Intel) --- kernel/power/hibernate.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index af8d07bafe02..6d3e637c5a02 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -418,6 +418,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 +475,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 +869,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 +877,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 Sat Sep 26 08:37:10 2026 Received: from smtpbgbr2.qq.com (smtpbgbr2.qq.com [54.207.22.56]) (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 EB251212542 for ; Thu, 3 Sep 2026 02:17:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.207.22.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788401870; cv=none; b=dR5PJFXI2rndGx/Ag9oaEHbYX8fLj08dSt93AwYLka3xbkhVlNNuzzwyEkgUj91hqWZC6SJOlIqD7+N3Ig5pkhDa8Ja+c/V2uDzEamz3ojdm4qBci6mLZKc9iGuYgH8gKMCXFuo69KSXLlp3nVRjGZKXwj+jNd7LscKRyHUyXVg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788401870; c=relaxed/simple; bh=vnu+7OTVyrfngxBgjEV+wbBsUgwuLr2CGX38vK2EnYU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mAbx51q+tD9hA4hZVRQ+OJ914lqHiqkdkfO13geuOw0LywJLmPFkPyXX8VJu7QHEeqxzo672X0lSeCIhRf2lBHH7N2KdkDqaCiPbOy893x5FpZa901KlaTrOEwgMephjJELEYk1ctwxX17R3wo+PDIPnfAdYx8nKm5MTCUTvLg8= 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=Mfbm8y+d; arc=none smtp.client-ip=54.207.22.56 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="Mfbm8y+d" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uniontech.com; s=onoh2408; t=1788401722; bh=TDmE22prZiWyICupTJBxOHtt4OkSMDD7JlVtXA21HRM=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=Mfbm8y+dpqDPaV3yADYCDFllKIcl9c2Kiu8QPbafPiO7Pi4jjC9VjKvQbQ1hiuTQt xQ+BEIyxPJ0Pmf5FCTLYlL5i9daIyOXEx+Mue2EajjoCy84BoGqYiNQ4/fNDSUxUMx PytMRsS7Usp/pADc9BB9h+Zistvog2frGUv7/3Qw= X-QQ-mid: esmtpgz16t1788401716t09e2fba8 X-QQ-Originating-IP: HWN1kVLmaxC5DhOLmv1XOyn9IGplrGoyhXFMvCPmKtw= Received: from localhost.localdomain ( [113.57.152.160]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 03 Sep 2026 10:15:14 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 1 X-BIZMAIL-ID: 11223455846511623105 EX-QQ-RecipientCnt: 15 From: Haowen Tu To: rafael@kernel.org, laurent.pinchart@ideasonboard.com Cc: tuhaowen@uniontech.com, gregkh@linuxfoundation.org, hansg@kernel.org, huangbibo@uniontech.com, lenb@kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, mchehab@kernel.org, oneukum@suse.com, pavel@kernel.org, stern@rowland.harvard.edu Subject: [PATCH v5 2/4] PM: hibernate: add pm_hibernation_snapshot_done() helper Date: Thu, 3 Sep 2026 10:14:57 +0800 Message-Id: <0a72acf8defd73508bfc5d2fb7c985521696630f.1788399733.git.tuhaowen@uniontech.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: <20260730153817.GA1555869@killaraus.ideasonboard.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: esmtpgz:uniontech.com:qybglogicsvrsz:qybglogicsvrsz3b-0 X-QQ-XMAILINFO: Nt9LS5Tya5fqVcSbLF5cPkXXPQ6NsO3JdfcI8FaoQekdQhgZ6w8MuoTM b3kHZSePM7O3ylFU6fX51RbRx5gjdWAdbsDIncfob60H2FAnrnQ2Ih9rSwvuCWGo0DtKdLv +ZOZqIutohCZmsh3URIvd4RIW7E8NCIlpFO8LluDTUb7oii0BBKxGrldOFL2JE6mSapogkP r5QAqPg0zWAKBC/sBSV+AW5gWeuPEpd8qDAiXc4sfN7gslhdJCeaS/uKXow1Hs7zy7h+UNn L0f3P2JtW/2tm52NUYOinokXb2KHWzPNiSok4VTChyjzVpypcHESc1VJLrKDyzVOrTjDp0L 70enCXVWa5/jtNlDoPnRsTvq1dI2+CuM+dF7Bqiz1uQHlm+LFOK+H+snW6QNnFO+FTXmfUk 6t6FrjXCsDZW4534z7d9P6Jw6qLp68gfsAg6zC07RE8/8wCClyoHnpXPQCiFIqxZzkTuKPz iFSGvGgvPlieeE9qr1fZetzN/PHf5Yq5FqEVswSlQhEAlJDh7d1uN7ITpgPe10oODk/NCWi gfxPTKra5xk/U9vNlkPQ6eL29c+rNPZ7Y1zJoU0JPdfGSmfThTAAnFVp5wTHJJMVdX3or1x pm8gn2qq88vDCbJjgIET/0c2WQcPE1QJt/XP3aRnCixYb9dIjUcW9KwabSXpTiZepOzns6n efEv1YBzcmQ5MwhpRxlJbChiMy9uzj8AZCdvvK11pjl1/5ydM02+eJBdqDUHosVkaBQDZQg Y79EmOvawk6hkhO+ycnTZ3jDHmwC7sXd1dlevEZtckx59eNkuhcNVQoJq+jpekTGofLx4fy lj2K2tbfwDO0LAUWHTAeJ4vGEKAJsp7mzLQU8CZBVnF49d4+/Yq8pOOH2eVM2wsXdea8Btu 8qv/TU8PaTo97n7COcFflrfIc+4K/X28xdMZeFL/nnm/+3eV+jwhppMs2H/hGvYGGaVHJ+U 5MyHCRPHr1k1mFg899iJqa2dLpdLz+MuOeZXQItQmP+N34D8uYkE8Gf/qbx7VAoSri29eLS SUXKrvHy3eRR6t1SrzgShGUlH4/90S917np+tSm46Vxvdo9rn1BAdouldFZvefhIwUWZ8gD BMYej2ckL7Nf8ZCyP9lgyw= X-QQ-XMRINFO: OD9hHCdaPRBwH5bRRRw8tsiH4UAatJqXfg== X-QQ-RECHKSPAM: 0 Content-Type: text/plain; charset="utf-8" Some subsystem resume callbacks do not receive the PM event and therefore cannot distinguish the PMSG_THAW phase after snapshot creation from the PMSG_RESTORE phase. Export pm_hibernation_snapshot_done() so a driver can query whether the hibernation snapshot has been created and is still available. The helper only exposes the PM state; callers remain responsible for ensuring that any device-specific behavior is safe, including subsequent poweroff or shutdown handling. The helper returns !!in_suspend. This variable is set before swsusp_arch_suspend(), cleared before the snapshot memory is released, and marked __nosavedata, so it remains clear on the restore path. Signed-off-by: Haowen Tu Acked-by: Rafael J. Wysocki (Intel) --- include/linux/suspend.h | 2 ++ kernel/power/hibernate.c | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/linux/suspend.h b/include/linux/suspend.h index b02876f1ae38..2cebbec3e2f7 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); +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 6d3e637c5a02..045d29f55011 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -113,6 +113,18 @@ bool hibernation_available(void) !secretmem_active() && !cxl_mem_active(); } =20 +/** + * pm_hibernation_snapshot_done - check if a hibernation snapshot is avail= able + * + * 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. --=20 2.20.1 From nobody Sat Sep 26 08:37:10 2026 Received: from smtpbguseast1.qq.com (smtpbguseast1.qq.com [54.204.34.129]) (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 B35DF33A9CF for ; Thu, 3 Sep 2026 02:17:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.204.34.129 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788401856; cv=none; b=BHjiOlBE2A8922PiVFzYrWuKLmH4sTOsZNQA9X/FrzAg3z/ASIIurz35GSHRVamX8QmakRNo0gGPPyBqO5tbVzMfLWkIlhV7Sh5nRGkAO7U+gSmxnIoxRTiDw6knPdbxlS5cW6BmX1PfZESdTRHBbuIVs5YFdrZCbEIPcPX/m9s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788401856; c=relaxed/simple; bh=xjvhQV7JgSAHkuf8f39ZXls4swNavrnogBN4k1AH/I0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pIZ1BGH8ekytOHbriRZ50B7Le8LGoj8mWkgtBElJ3nwjpd1FiBeNb6lGt/wPPNnDPFkMo/B0fFPhBJvQZbAUTRrH6gUaeezxkLMuG1xwzlUswaztHrEfggBP/sNwFkOsaMJmQaZCfV9BAMTGwASOzVK4rTRZsz9qwB8c0CJJHMY= 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=ZJV62J9V; arc=none smtp.client-ip=54.204.34.129 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="ZJV62J9V" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uniontech.com; s=onoh2408; t=1788401731; bh=a9hMr+L6f3/B1Vj5w6E1NGhMLLBJcOGtJdWdCHblVoA=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=ZJV62J9VGyAbKWeexa8QoaPQ6Q3pcv8ZgixPZjv+MP4BvM8qmOvMUdovupTqJQCBp KcHh6+AegRz/TW9g6yIvrg8oJCFORhcmAVKznNd0fZQ/NxHLn60RmTaja0hZ6kj5SM ASqZlqjKXhk8WxTGN5kMfFCg1LP7d3y1j+otP+Gc= X-QQ-mid: esmtpgz16t1788401720t8f68330f X-QQ-Originating-IP: k5mkv1xJVZdiidrCRPCo3sxvOTrtGtZNdWaCF/38Uw0= Received: from localhost.localdomain ( [113.57.152.160]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 03 Sep 2026 10:15:18 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 1 X-BIZMAIL-ID: 12543063456713375474 EX-QQ-RecipientCnt: 15 From: Haowen Tu To: rafael@kernel.org, laurent.pinchart@ideasonboard.com Cc: tuhaowen@uniontech.com, gregkh@linuxfoundation.org, hansg@kernel.org, huangbibo@uniontech.com, lenb@kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, mchehab@kernel.org, oneukum@suse.com, pavel@kernel.org, stern@rowland.harvard.edu Subject: [PATCH v5 3/4] PM: hibernate: allow devices to skip post-snapshot THAW Date: Thu, 3 Sep 2026 10:14:58 +0800 Message-Id: <5cbc30863de487f42bcd395ec2d7d738d05189bb.1788399733.git.tuhaowen@uniontech.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: <20260730153817.GA1555869@killaraus.ideasonboard.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: esmtpgz:uniontech.com:qybglogicsvrsz:qybglogicsvrsz3b-0 X-QQ-XMAILINFO: N2q/xI6AIc+93cJbqaJKmMwsaXauMjaxX+eOQmoU9JIj9vlTq+ZM4+ce b0aIJWw5eV0Ce0gaF5EUL/k7+CabRV0o/x11s5gP44BV+X6mU2PNyMCjyZw6aZPlzjOSkgN xf3R5bJq070+sqqLaKyu1a2c1fhAnnsDIFjMPL5Uc0KfPuSxhOR7udbe+XsrSkW+iQ5H8TO s7kT+XcarGz3LyRSWptO1XWPI/caiRlYXYQEA09pe6e8iTF8kFA15fv9H+boHZDZdc9SVPH DTsxYPzk3L0RpJSMtZ+hVCvwxkuMjrhKbteORRamFON/2b5El/X+nVh0U8eu92geGNnQuF7 ZUSzvMff+4nJeWPnrmudUs2XbGCNxK7V7HHj4ac+nekN+sNz8CuFo6dA2/YoFW3ghiUuNqe djYAM6K+LgcLhViXl5lemi6AGumfvyBiQPOR1qHj9Wb8TNWVkbdo0hH31tWJhmDDcFISm2z 7gCwhcufoCjcm/VAoiNNacYXYQ7i7kGYRe5KoIvQA6HBbrWltrKtVFt2hdf1hlauZKCs67x LSYbTxpNWWQX+met7vvJUSgvEp9aHGmVe8JBIAbcesECUKh4+fBDbLfi4U/c+1LTbUJGMN2 iO3pnunL3ySZytiy2uO8FFR/IjxTf0PgPFXIR5qYIX9ywCwfD/9E7qSstD6OLaTIrNuKthz EHVfkpmZTSkxzluaRjgOJSswNpna7VK6ocS3ngQKAMzH+0mRGnQ9DDkRJdiJPzk8tJHXkKo 1JLpPZ1jnpFYpEHT8l/hNHPZc3hZzDUspUo+aniMAAHE4sy5QW+vuj0QbL27VpGFb6QbL41 clnlvixfQpWQMRB548dxPR+RT5gtplaBw5AFphR3gtnTkvcrnlFQip5btN8px41acmIdOIh 4ZKnEgLKbc9jdpV1ojWcUUX2zkd6lWLp8yFb+IRFaPe4+e7vr1dJANtL2dhRv3F3rTln0d/ H9lCl5ZmW7JDpwZQiVAf9wNz/oO9AjzRFUnEDe14n+gfPxQmHYf2wsK2JKFgcc8RbkfY/A0 ah06Yph8tTeXXrUixC6alMUS+ABPCJZuC0vKxfSIyNd83/OL39mZ8NcoDpEX6fkgLdQ83m6 ssYU1TCkXepjFqgBOEbTERLdV4U5+WKB8mXa1c5TUNfY/490YRzul4= X-QQ-XMRINFO: Nq+8W0+stu50tPAe92KXseR0ZZmBTk3gLg== X-QQ-RECHKSPAM: 0 Content-Type: text/plain; charset="utf-8" After a hibernation snapshot has been created, the PM core resumes devices with PMSG_THAW so that the image can be written out. Some devices are not involved in image writeout and do not need to be resumed during that transient phase. Add DPM_FLAG_SKIP_HIBERNATION_THAW to let drivers opt a device out of the post-snapshot THAW resume. Skipped devices remain suspended while the image is written. If the original kernel continues running instead of powering down, resume the skipped devices before userspace is thawed. The skip is limited to the original kernel's post-snapshot THAW path by checking pm_hibernation_snapshot_done(). Other THAW paths, including recovery from failed image restore in the restore kernel, continue to resume devices normally. Signed-off-by: Haowen Tu --- Documentation/driver-api/pm/devices.rst | 17 +++++++ drivers/base/power/main.c | 65 +++++++++++++++++++++++++ include/linux/pm.h | 4 ++ kernel/power/hibernate.c | 14 +++++- 4 files changed, 98 insertions(+), 2 deletions(-) diff --git a/Documentation/driver-api/pm/devices.rst b/Documentation/driver= -api/pm/devices.rst index 36d5c9c9fd11..c2933931ca33 100644 --- a/Documentation/driver-api/pm/devices.rst +++ b/Documentation/driver-api/pm/devices.rst @@ -878,3 +878,20 @@ callback back-to-back with its "late" and "noirq" susp= end ones. [For instance, that is not a concern if the driver sets both ``DPM_FLAG_SMART_SUSPEND`` a= nd ``DPM_FLAG_MAY_SKIP_RESUME`` and uses the same pair of suspend/resume call= back functions for runtime PM and system-wide suspend/resume.] + + +The ``DPM_FLAG_SKIP_HIBERNATION_THAW`` Driver Flag +-------------------------------------------------- + +During hibernation, the PM core resumes devices with ``PMSG_THAW`` after t= he +hibernation snapshot has been created so that the image can be written out. +Some devices do not need to be resumed during that image-write phase. + +Drivers for such devices can set ``DPM_FLAG_SKIP_HIBERNATION_THAW`` to all= ow +the PM core to leave the device suspended during the post-snapshot ``THAW`= `. +If the original kernel continues running instead of powering down, the PM = core +will resume the skipped devices before userspace is thawed. + +Drivers must only set this flag for devices that are not needed for writin= g the +hibernation image and can remain suspended until the system either powers = off or +the original kernel continues running. diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index e1b550664bab..e68b97608eb2 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c @@ -55,11 +55,13 @@ typedef int (*pm_callback_t)(struct device *); LIST_HEAD(dpm_list); static LIST_HEAD(dpm_prepared_list); static LIST_HEAD(dpm_suspended_list); +static LIST_HEAD(dpm_hibernation_skipped_list); static LIST_HEAD(dpm_late_early_list); static LIST_HEAD(dpm_noirq_list); =20 static DEFINE_MUTEX(dpm_list_mtx); static pm_message_t pm_transition; +static bool dpm_in_hibernation_thaw; =20 static DEFINE_MUTEX(async_wip_mtx); static int async_error; @@ -1033,6 +1035,20 @@ EXPORT_SYMBOL_GPL(dpm_resume_start); =20 static void async_resume(void *data, async_cookie_t cookie); =20 +static bool dpm_skip_hibernation_thaw(struct device *dev, pm_message_t sta= te) +{ + if (!dpm_in_hibernation_thaw || state.event !=3D PM_EVENT_THAW || + !pm_hibernation_snapshot_done()) + return false; + + return dev_pm_test_driver_flags(dev, DPM_FLAG_SKIP_HIBERNATION_THAW); +} + +static void dpm_set_hibernation_thaw(bool enable) +{ + dpm_in_hibernation_thaw =3D enable; +} + /** * device_resume - Execute "resume" callbacks for given device. * @dev: Device to handle. @@ -1141,7 +1157,11 @@ static void async_resume(void *data, async_cookie_t = cookie) { struct device *dev =3D data; =20 + if (dpm_skip_hibernation_thaw(dev, pm_transition)) + goto out; + device_resume(dev, pm_transition, true); +out: put_device(dev); } =20 @@ -1170,12 +1190,22 @@ void dpm_resume(pm_message_t state) */ list_for_each_entry(dev, &dpm_suspended_list, power.entry) { dpm_clear_async_state(dev); + if (dpm_skip_hibernation_thaw(dev, state)) + continue; + if (dpm_root_device(dev)) dpm_async_with_cleanup(dev, async_resume); } =20 while (!list_empty(&dpm_suspended_list)) { dev =3D to_device(dpm_suspended_list.next); + if (dpm_skip_hibernation_thaw(dev, state)) { + list_move_tail(&dev->power.entry, + &dpm_hibernation_skipped_list); + complete_all(&dev->power.completion); + continue; + } + list_move_tail(&dev->power.entry, &dpm_prepared_list); =20 if (!dpm_async_fn(dev, async_resume)) { @@ -1201,6 +1231,41 @@ void dpm_resume(pm_message_t state) trace_suspend_resume(TPS("dpm_resume"), state.event, false); } =20 +/** + * dpm_resume_hibernation_thaw - Execute the post-snapshot THAW callbacks. + * + * Execute THAW callbacks for devices required during hibernation image wr= iteout. + * Devices with DPM_FLAG_SKIP_HIBERNATION_THAW set are left suspended. + */ +void dpm_resume_hibernation_thaw(void) +{ + dpm_set_hibernation_thaw(true); + dpm_resume(PMSG_THAW); + dpm_set_hibernation_thaw(false); +} + +/** + * dpm_resume_skipped_hibernation_devices - Resume devices skipped in THAW. + * + * Resume devices whose post-snapshot THAW callbacks were skipped because = they + * are not required during hibernation image writeout. + */ +void dpm_resume_skipped_hibernation_devices(void) +{ + mutex_lock(&dpm_list_mtx); + if (list_empty(&dpm_hibernation_skipped_list)) { + mutex_unlock(&dpm_list_mtx); + return; + } + + list_splice_tail_init(&dpm_hibernation_skipped_list, + &dpm_suspended_list); + mutex_unlock(&dpm_list_mtx); + + dpm_resume(PMSG_THAW); + dpm_complete(PMSG_THAW); +} + /** * device_complete - Complete a PM transition for given device. * @dev: Device to handle. diff --git a/include/linux/pm.h b/include/linux/pm.h index afcaaa37a812..3d7f52c63f7e 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -655,6 +655,7 @@ struct pm_subsys_data { * SMART_PREPARE: Take the driver ->prepare callback return value into acc= ount. * SMART_SUSPEND: Avoid resuming the device from runtime suspend. * MAY_SKIP_RESUME: Allow driver "noirq" and "early" callbacks to be skipp= ed. + * SKIP_HIBERNATION_THAW: Do not resume the device during post-snapshot TH= AW. * * See Documentation/driver-api/pm/devices.rst for details. */ @@ -662,6 +663,7 @@ struct pm_subsys_data { #define DPM_FLAG_SMART_PREPARE BIT(1) #define DPM_FLAG_SMART_SUSPEND BIT(2) #define DPM_FLAG_MAY_SKIP_RESUME BIT(3) +#define DPM_FLAG_SKIP_HIBERNATION_THAW BIT(4) =20 struct dev_pm_info { pm_message_t power_state; @@ -819,6 +821,8 @@ extern void dpm_resume_end(pm_message_t state); extern void dpm_resume_noirq(pm_message_t state); extern void dpm_resume_early(pm_message_t state); extern void dpm_resume(pm_message_t state); +void dpm_resume_hibernation_thaw(void); +void dpm_resume_skipped_hibernation_devices(void); extern void dpm_complete(pm_message_t state); =20 extern void device_pm_unlock(void); diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index 045d29f55011..da3ce0382f6d 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -496,7 +496,10 @@ int hibernation_snapshot(int platform_mode) } =20 msg =3D snapshot_done ? (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE; - dpm_resume(msg); + if (msg.event =3D=3D PM_EVENT_THAW) + dpm_resume_hibernation_thaw(); + else + dpm_resume(msg); =20 if (error || !snapshot_done) pm_restore_gfp_mask(); @@ -804,6 +807,7 @@ static int load_image_and_restore(void) int hibernate(void) { bool snapshot_test =3D false; + bool resume_skipped =3D false; unsigned int sleep_flags; int error; =20 @@ -883,11 +887,14 @@ int hibernate(void) error =3D swsusp_write(flags); in_suspend =3D 0; swsusp_free(); - if (!error) { + if (error) { + resume_skipped =3D true; + } else { if (hibernation_mode =3D=3D HIBERNATION_TEST_RESUME) snapshot_test =3D true; else power_down(); + resume_skipped =3D true; } pm_restore_gfp_mask(); } else { @@ -903,7 +910,10 @@ int hibernate(void) error =3D swsusp_check(false); if (!error) error =3D load_image_and_restore(); + resume_skipped =3D true; } + if (resume_skipped) + dpm_resume_skipped_hibernation_devices(); thaw_processes(); =20 /* Don't bother checking whether freezer_test_done is true */ --=20 2.20.1 From nobody Sat Sep 26 08:37: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 8982033939A for ; Thu, 3 Sep 2026 02:17:20 +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=1788401843; cv=none; b=jB+m7QLrSYG1KEe6IJZoNNLpCHwrjcQfw1wqY8b3W4CE8J3QFesOtNgwPZTmvOG9/waBIBN/fme6NIvKF/M2OrjHDWSqKHWEFHwTBsd4b1uyLl2LIHCt8+7E6cQYv19SOhYdFeTHibGcDJSS7eDoyL0+lIvMW+uIl5TueDtz8KY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788401843; c=relaxed/simple; bh=ltGCsPM9g4dL27hzeJYprlsMCLIuGBzrExUAh+1/n8c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=d3P+SjnUEcJx+SX/VSG8WEeBBMO6PKBBP97V+rmzsJOSgdocQkM31oh1ighSmZ/ASsLFIFI+P2fOEL3BEWI9Dpy0tNfbunscFhPIcuoneHkIqGR9hwnp/TXiXTegG8h/DBzbuGJQaC0Z0I5B5uzBTYrRirS4MCFhceINjx3ndi0= 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=Ru7EJkGu; 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="Ru7EJkGu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uniontech.com; s=onoh2408; t=1788401730; bh=NNBPer/UqmzXtzPtWUFkVQGu/BhnIGA3Q4Ww1JPF9B0=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=Ru7EJkGuPrPb2cHBDMZxwYoWhdN+k8Un0xTngdnHxsRmi7J+Db+IcIB3CeI1/BphE m8yIhS7D28qaKc0WDUMEGX4OE5+RWeT2YyhAnJI4SWCmYQClrAMUET+6E3a+J4WLKo mz0kjVo6sh73lrBBFFp7lsKUzDYcw68CUbTOCJZw= X-QQ-mid: esmtpgz16t1788401724t6d55b7c7 X-QQ-Originating-IP: o1bCMaKcd5K4sGAPBG6wOUQ88v1EnArt+Z/BFPA4eFM= Received: from localhost.localdomain ( [113.57.152.160]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 03 Sep 2026 10:15:22 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 1 X-BIZMAIL-ID: 7393804203611463141 EX-QQ-RecipientCnt: 15 From: Haowen Tu To: rafael@kernel.org, laurent.pinchart@ideasonboard.com Cc: tuhaowen@uniontech.com, gregkh@linuxfoundation.org, hansg@kernel.org, huangbibo@uniontech.com, lenb@kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, mchehab@kernel.org, oneukum@suse.com, pavel@kernel.org, stern@rowland.harvard.edu Subject: [PATCH v5 4/4] media: uvcvideo: skip post-snapshot hibernation THAW Date: Thu, 3 Sep 2026 10:14:59 +0800 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: <20260730153817.GA1555869@killaraus.ideasonboard.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: esmtpgz:uniontech.com:qybglogicsvrsz:qybglogicsvrsz3b-0 X-QQ-XMAILINFO: ML8hOghqQD+0+AnvW5UypZvMXjLVHB4KkNxGe4/bhDpG2TUzLJfOAdVs zbUkT38jf+q8tdMQHWqoFuxAmEjC+SLdXqUxikW/yFajWTNNMKiPZ8biqacGv+2W0edgnL6 FlGhi0t+ROoBMQxrX6en6A3Xkd7s/1raD+yJYGpvnq7MFGZ00/kYsE9BwaK7Ivm41VsNGv5 ld0TXAurZZlB4AnYE6j7Op+lJ9Ejn3YS81zvW0/Yxw7bi+fo2WL0b5rD6LEtrWHCrNSLwuk CdA8e9eYlMUm2C2S0bN8vR+tx7b1Offt8Uv99WBykDhxubGe9nbf1VrvU9GXv6zH1EhllsD X3jJIskxBNh+CdcMCIwQ1SZevHkA4cyxFigdz0ccvUmi019Tp6qeFMI9oW5CE9TvIpJYhxc P3Cpbs+5EefMNwmto+ceyzRxrLYZ4/2Fnt6XzcPCRS6KVKh63SEdE2jXnYknWcxpSEI/6ax q4WeF3qYAFgqno0ucncrcdgfFZntxv3FxFsksI3EnMDEGYEtkS/FPudKKE2WzK5u6HDSo0k MsUXegFBeng7xNvNUvBshO1BqmVOsd8OxnJ4sDb3IxgS/dn/pUi/yaMfob7SNemhjky8zsp We0KFFRStSgYca5GD74wZ82FyVBgQxbtW2/vPs2toFMju4ql9GPYQaFIom6pa4O+yHT916V Im1wrS2xNNr4IDKMuc1w76mqrNyq+FxsQlh2N6yMML8vpmJrCqz6y74Zm4VIT5RMAbuIPbr 9llzZTvX7DCN9HEu+BHcuLXXcyrr2KZELEIlLGCP6AGNwXrnAg6quuZ1R/TbOqdWDhUwz9/ ail4D66sfjR0TG6um0OPAIOpzH0VFpRT1ucY1Zc3xRgNxoU8NjHe/MOfJ8znFsAESr4TwsA VWwBj9Mt2KW/T9q+biG/q+Iox7UhmfyO+CCEYIV6FzIUu00gzkamYMK1DvMrCjsMAN3sX9T G6mG0ejSEjpY1NteITXlPCCBT9hwlp+7BM6jySmBgYPpNa3IGxPkqioSCQB4ieimx3WuCXb 3oT/zED+GeHdIwKxDTO2rg5UH14BSGQ/tnjkgnMVvIobk7ngi/sw/mOtWN/Dey5RNkpUU46 lHIlHRkwA6k0Qi+7v9Od2E= X-QQ-XMRINFO: M/715EihBoGS47X28/vv4NpnfpeBLnr4Qg== X-QQ-RECHKSPAM: 0 Content-Type: text/plain; charset="utf-8" When a UVC camera is streaming and the system enters hibernation, the streaming interface is frozen before the snapshot is created. The original kernel then resumes devices with PMSG_THAW so it can write the hibernation image. The UVC streaming interface is not needed for image writeout. Mark it with DPM_FLAG_SKIP_HIBERNATION_THAW so the PM core can leave it suspended during the post-snapshot THAW phase. This avoids restarting the streaming hardware and turning the camera indicator LED back on while the image is being written. If the original kernel continues running instead of powering down, the PM core resumes devices skipped this way before userspace is thawed. Signed-off-by: Haowen Tu --- drivers/media/usb/uvc/uvc_driver.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc= _driver.c index 31b4ac3b48c1..d44c17c99daf 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -559,6 +559,7 @@ static int uvc_parse_streaming(struct uvc_device *dev, intf->altsetting[0].desc.bInterfaceNumber); return -EINVAL; } + dev_pm_set_driver_flags(&intf->dev, DPM_FLAG_SKIP_HIBERNATION_THAW); =20 streaming =3D uvc_stream_new(dev, intf); if (streaming =3D=3D NULL) { --=20 2.20.1