From mboxrd@z Thu Jan 1 00:00:00 1970 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 4C08433FE02; Tue, 28 Apr 2026 08:06:08 +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=1777363573; cv=none; b=o2NlxmpDoWfPu52V/qnrpQZCWXRmZ5R2xuQzA4ZObsDZGwinBvAOJ88NdS+FAnqYEkT+2fyuZpsdDHL/lobJEeHs0sUwSFXbo1vkg5nPJwPKRUABh/qp21dRJbWT7Gvbeaa9d4o9+IBMTtf00Qxia+KYA6FXo2TCAI5X0pKbSk0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777363573; c=relaxed/simple; bh=Icyu9mDyR5XC6EJ+fw6HwbZeEumToytyMGuJSUYBJjM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IT+t/OQAh4/IrpS4LplmK/k2EATVtjneHjpH5zxR0xj59RvohAMPTb6Z2rYP4ock1WI9h6PI82vtzMg/IJKcyKdbOV/HD4sEqoOImzKbUVFXtSVTVFgL+EGd29F+GxRbizpxDb2jphdDw8hQDB4ndDN5B5kXm8as7boyvjhsMco= 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=Aye0e1UH; 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="Aye0e1UH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uniontech.com; s=onoh2408; t=1777363550; bh=1RR1YtVSBXfVSJxUBB2AKFR+yLwoFEUBMjDD17hxsj0=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=Aye0e1UHPypow8bO7Ki7AodHq8zTZuDSDKUM/cwcSnOumDOJsIGIVbV9F27/wPHcc RYUouvPMdqISa8wWAPmspoOCZNpMRbhBjv6KkYXTQSvUBTrOtcVJ5//TRL4bO4CT6T PSbDQ8S8Ie1XgzbY33zCUpKr8Odk30q3h+TFraZ4= X-QQ-mid: zesmtpip2t1777363545t07a96599 X-QQ-Originating-IP: zOGsRQ4vEgqT/NE82VSDH4QQPothkDoKChOOIb4l5hM= Received: from localhost.localdomain ( [localhost]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 28 Apr 2026 16:05:23 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 1 X-BIZMAIL-ID: 9221135693376165927 EX-QQ-RecipientCnt: 10 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, linux-kernel@vger.kernel.org, Haowen Tu Subject: [PATCH 1/2] PM: hibernate: add pm_hibernation_storing_image() helper Date: Tue, 28 Apr 2026 16:05:12 +0800 Message-Id: <20260428080513.1833515-2-tuhaowen@uniontech.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20260428080513.1833515-1-tuhaowen@uniontech.com> References: <20260428080513.1833515-1-tuhaowen@uniontech.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: zesmtpip:uniontech.com:qybglogics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e7Fd IObcWZ7NEcjz/WfEDnNmbbj5uCaRfKe3bODhE+ez04rqLlhVIA X-QQ-XMRINFO: MSVp+SPm3vtSI1QTLgDHQqIV1w2oNKDqfg== X-QQ-RECHKSPAM: 0 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_storing_image() for this purpose. The implementation returns !!in_suspend, which is set to 1 in create_image() just before swsusp_arch_suspend() and reset to 0 in hibernate() after swsusp_write() completes. Because in_suspend is marked __nosavedata, it is not saved into the hibernation image; on the restore path the variable remains 0 throughout, so the helper correctly returns false during PMSG_RESTORE device resume. Signed-off-by: Haowen Tu --- include/linux/suspend.h | 2 ++ kernel/power/hibernate.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/linux/suspend.h b/include/linux/suspend.h index b02876f1ae38..28b454def83d 100644 --- a/include/linux/suspend.h +++ b/include/linux/suspend.h @@ -393,6 +393,7 @@ extern void hibernation_set_ops(const struct platform_hibernation_ops *ops); extern int hibernate(void); extern bool system_entering_hibernation(void); extern bool hibernation_available(void); +extern bool pm_hibernation_storing_image(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 platform_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_storing_image(void) { return false; } 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..bc632cce40ff 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -113,6 +113,25 @@ bool hibernation_available(void) !secretmem_active() && !cxl_mem_active(); } +/** + * pm_hibernation_storing_image - check if system is writing the hibernation image + * + * After create_image() saves a memory snapshot, the kernel briefly resumes + * devices with PMSG_THAW to write the image to storage before final powerdown. + * Drivers for hardware not involved in storage I/O 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 the system is + * in the process of writing the image to persistent storage. + */ +bool pm_hibernation_storing_image(void) +{ + return !!in_suspend; +} +EXPORT_SYMBOL_GPL(pm_hibernation_storing_image); + /** * hibernation_set_ops - Set the global hibernate operations. * @ops: Hibernation operations to use in subsequent hibernation transitions. -- 2.20.1