Linux Power Management development
 help / color / mirror / Atom feed
* [PATCH v2] PM: hibernate: Explicitly set `PM_SUSPEND_MAX` at hibernate entry
@ 2025-05-08 21:17 Mario Limonciello
  2025-05-09  8:22 ` kernel test robot
  2025-05-09 12:43 ` Rafael J. Wysocki
  0 siblings, 2 replies; 3+ messages in thread
From: Mario Limonciello @ 2025-05-08 21:17 UTC (permalink / raw)
  To: mario.limonciello, rafael, pavel, len.brown; +Cc: linux-pm

From: Mario Limonciello <mario.limonciello@amd.com>

`pm_debug_messages` only works at suspend time, not hibernate. This is
because during hibernate the `pm_suspend_target_state` is not set.

Explicitly set pm_suspend_target_state at hibernate time. Since the symbol
is only enabled under `CONFIG_SUSPEND`, adjust symbol location and allow it
under `CONFIG_HIBERNATION` too.

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
v2:
 * Fix for lkp robot failure where no CONFIG_SUSPEND
---
 include/linux/suspend.h  | 9 ++++++---
 kernel/power/hibernate.c | 2 ++
 kernel/power/main.c      | 3 +++
 kernel/power/suspend.c   | 2 --
 4 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/include/linux/suspend.h b/include/linux/suspend.h
index da6ebca3ff774..b66be47ef5282 100644
--- a/include/linux/suspend.h
+++ b/include/linux/suspend.h
@@ -142,8 +142,13 @@ struct platform_s2idle_ops {
 	void (*end)(void);
 };
 
-#ifdef CONFIG_SUSPEND
+#if defined(CONFIG_SUSPEND) || defined(CONFIG_HIBERNATION)
 extern suspend_state_t pm_suspend_target_state;
+#else
+#define pm_suspend_target_state	(PM_SUSPEND_ON)
+#endif
+
+#ifdef CONFIG_SUSPEND
 extern suspend_state_t mem_sleep_current;
 extern suspend_state_t mem_sleep_default;
 
@@ -279,8 +284,6 @@ extern bool sync_on_suspend_enabled;
 #else /* !CONFIG_SUSPEND */
 #define suspend_valid_only_mem	NULL
 
-#define pm_suspend_target_state	(PM_SUSPEND_ON)
-
 static inline void pm_suspend_clear_flags(void) {}
 static inline void pm_set_suspend_via_firmware(void) {}
 static inline void pm_set_resume_via_firmware(void) {}
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index f0db9d1896e80..8fb82a62b85f1 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -772,6 +772,7 @@ int hibernate(void)
 	}
 
 	pr_info("hibernation entry\n");
+	pm_suspend_target_state = PM_SUSPEND_MAX;
 	pm_prepare_console();
 	error = pm_notifier_call_chain_robust(PM_HIBERNATION_PREPARE, PM_POST_HIBERNATION);
 	if (error)
@@ -852,6 +853,7 @@ int hibernate(void)
 	hibernate_release();
  Unlock:
 	unlock_system_sleep(sleep_flags);
+	pm_suspend_target_state = PM_SUSPEND_ON;
 	pr_info("hibernation exit\n");
 
 	return error;
diff --git a/kernel/power/main.c b/kernel/power/main.c
index 97746f08b762b..0440644695c76 100644
--- a/kernel/power/main.c
+++ b/kernel/power/main.c
@@ -20,6 +20,9 @@
 
 #include "power.h"
 
+suspend_state_t pm_suspend_target_state;
+EXPORT_SYMBOL_GPL(pm_suspend_target_state);
+
 #ifdef CONFIG_PM_SLEEP
 /*
  * The following functions are used by the suspend/hibernate code to temporarily
diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
index 8eaec4ab121d4..08cb71991795d 100644
--- a/kernel/power/suspend.c
+++ b/kernel/power/suspend.c
@@ -48,8 +48,6 @@ const char *mem_sleep_states[PM_SUSPEND_MAX];
 
 suspend_state_t mem_sleep_current = PM_SUSPEND_TO_IDLE;
 suspend_state_t mem_sleep_default = PM_SUSPEND_MAX;
-suspend_state_t pm_suspend_target_state;
-EXPORT_SYMBOL_GPL(pm_suspend_target_state);
 
 unsigned int pm_suspend_global_flags;
 EXPORT_SYMBOL_GPL(pm_suspend_global_flags);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-05-09 12:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-08 21:17 [PATCH v2] PM: hibernate: Explicitly set `PM_SUSPEND_MAX` at hibernate entry Mario Limonciello
2025-05-09  8:22 ` kernel test robot
2025-05-09 12:43 ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox