Re: [PATCH v3] PM: hibernate: Log the hibernation mode on entry

From: Rafael J. Wysocki (Intel)

Date: Tue Oct 13 2026 - 10:30:21 EST


On Tue, Oct 13, 2026 at 4:34 AM Yongxin Yang <yangyongxin@xxxxxxxxxx> wrote:
>
> The hibernation flow is the only place where the kernel decides what
> to do after a successful image write: hand over to the platform
> firmware (ACPI S4), power the system off, reboot it, or resume from
> the image right away. That decision leaves no trace in the log. If the
> resume path later fails or hangs, the tester cannot tell which outcome
> was requested, so a report of "the system rebooted instead of powering
> off" cannot be attributed to configuration or to platform behavior.
>
> The mode is selected through /sys/power/disk and stored in
> hibernation_mode. Append its name to the existing "hibernation entry"
> message, so that the line reads "hibernation entry (platform)",
> "hibernation entry (shutdown)", "hibernation entry (reboot)",
> "hibernation entry (suspend)" or "hibernation entry (test_resume)"
> instead of a bare "hibernation entry".
>
> The names come from hibernation_modes[], the same table that
> /sys/power/disk uses, through a new hibernation_mode_name() helper, so
> that the mapping from mode to name lives in one place.
>
> No functional change.
>
> Signed-off-by: Yongxin Yang <yangyongxin@xxxxxxxxxx>
> ---
> kernel/power/hibernate.c | 32 ++++++++++++++++++++------------
> 1 file changed, 20 insertions(+), 12 deletions(-)
>
> diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
> index e365e440cd52..6f88b42b1af8 100644
> --- a/kernel/power/hibernate.c
> +++ b/kernel/power/hibernate.c
> @@ -72,6 +72,24 @@ enum {
> #define HIBERNATION_MAX (__HIBERNATION_AFTER_LAST-1)
> #define HIBERNATION_FIRST (HIBERNATION_INVALID + 1)
>
> +static const char * const hibernation_modes[] = {
> + [HIBERNATION_PLATFORM] = "platform",
> + [HIBERNATION_SHUTDOWN] = "shutdown",
> + [HIBERNATION_REBOOT] = "reboot",
> +#ifdef CONFIG_SUSPEND
> + [HIBERNATION_SUSPEND] = "suspend",
> +#endif
> + [HIBERNATION_TEST_RESUME] = "test_resume",
> +};
> +
> +static const char *hibernation_mode_name(int mode)
> +{
> + if (mode < HIBERNATION_FIRST || mode > HIBERNATION_MAX)
> + return "unknown";
> +
> + return hibernation_modes[mode];
> +}

Thanks for the update, but I really meant this:

static const char *hibernation_mode_name(int mode)
{
switch (mode) {
case HIBERNATION_PLATFORM:
return "platform";
case HIBERNATION_SHUTDOWN:
return "shutdown";
case HIBERNATION_REBOOT:
return "reboot";
case HIBERNATION_TEST_RESUME:
return "test_resume";
#ifdef CONFIG_SUSPEND
case HIBERNATION_SUSPEND:
return "suspend";
#endif
}
return "unknown";
}

> +
> static int hibernation_mode = HIBERNATION_SHUTDOWN;
>
> bool freezer_test_done;
> @@ -794,7 +812,8 @@ int hibernate(void)
> goto Unlock;
> }
>
> - pr_info("hibernation entry\n");
> + pr_info("hibernation entry (%s)\n",
> + hibernation_mode_name(hibernation_mode));
> pm_prepare_console();
> error = pm_notifier_call_chain_robust(PM_HIBERNATION_PREPARE, PM_POST_HIBERNATION);
> if (error)
> @@ -1130,17 +1149,6 @@ static int __init software_resume_initcall(void)
> }
> late_initcall_sync(software_resume_initcall);
>
> -
> -static const char * const hibernation_modes[] = {
> - [HIBERNATION_PLATFORM] = "platform",
> - [HIBERNATION_SHUTDOWN] = "shutdown",
> - [HIBERNATION_REBOOT] = "reboot",
> -#ifdef CONFIG_SUSPEND
> - [HIBERNATION_SUSPEND] = "suspend",
> -#endif
> - [HIBERNATION_TEST_RESUME] = "test_resume",
> -};
> -
> /*
> * /sys/power/disk - Control hibernation mode.
> *
> --
> 2.25.1
>