[RFC 1/4] PM: hibernate: export hibernation_in_progress()

Muhammad Usama Anjum posted 4 patches 3 months, 3 weeks ago
There is a newer version of this series
[RFC 1/4] PM: hibernate: export hibernation_in_progress()
Posted by Muhammad Usama Anjum 3 months, 3 weeks ago
Export hibernation_in_progress() to be used by other modules. Add its
signature when hibernation config isn't enabled as well.

Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
---
 include/linux/suspend.h  | 2 ++
 kernel/power/hibernate.c | 1 +
 2 files changed, 3 insertions(+)

diff --git a/include/linux/suspend.h b/include/linux/suspend.h
index b02876f1ae38a..348831cdb60e4 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 hibernation_in_progress(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 hibernation_in_progress(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 14e85ff235512..aadf82f57e868 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -105,6 +105,7 @@ bool hibernation_in_progress(void)
 {
 	return !atomic_read(&hibernate_atomic);
 }
+EXPORT_SYMBOL_GPL(hibernation_in_progress);
 
 bool hibernation_available(void)
 {
-- 
2.47.3
Re: [RFC 1/4] PM: hibernate: export hibernation_in_progress()
Posted by Mario Limonciello (AMD) (kernel.org) 3 months, 2 weeks ago

On 10/18/2025 9:21 AM, Muhammad Usama Anjum wrote:
> Export hibernation_in_progress() to be used by other modules. Add its
> signature when hibernation config isn't enabled as well.

I wonder if you actually want to have pm_sleep_transition_in_progress() 
exported instead.  "Logically" I would expect cancelling a hibernate and 
cancelling a suspend should work similarly.
> 
> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> ---
>   include/linux/suspend.h  | 2 ++
>   kernel/power/hibernate.c | 1 +
>   2 files changed, 3 insertions(+)
> 
> diff --git a/include/linux/suspend.h b/include/linux/suspend.h
> index b02876f1ae38a..348831cdb60e4 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 hibernation_in_progress(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 hibernation_in_progress(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 14e85ff235512..aadf82f57e868 100644
> --- a/kernel/power/hibernate.c
> +++ b/kernel/power/hibernate.c
> @@ -105,6 +105,7 @@ bool hibernation_in_progress(void)
>   {
>   	return !atomic_read(&hibernate_atomic);
>   }
> +EXPORT_SYMBOL_GPL(hibernation_in_progress);
>   
>   bool hibernation_available(void)
>   {
Re: [RFC 1/4] PM: hibernate: export hibernation_in_progress()
Posted by Rafael J. Wysocki 3 months, 2 weeks ago
On Tue, Oct 21, 2025 at 11:07 PM Mario Limonciello (AMD) (kernel.org)
<superm1@kernel.org> wrote:
>
>
>
> On 10/18/2025 9:21 AM, Muhammad Usama Anjum wrote:
> > Export hibernation_in_progress() to be used by other modules. Add its
> > signature when hibernation config isn't enabled as well.
>
> I wonder if you actually want to have pm_sleep_transition_in_progress()
> exported instead.  "Logically" I would expect cancelling a hibernate and
> cancelling a suspend should work similarly.

Well, it does AFAICS, except that only the "freeze" and "poweroff"
transitions can be aborted during hibernation.  This is analogous to
aborting a suspend transition.

The missing part is a mechanism to cancel hibernation between image
creation and the "poweroff" transition.
Re: [RFC 1/4] PM: hibernate: export hibernation_in_progress()
Posted by Muhammad Usama Anjum 3 months, 2 weeks ago
On 10/22/25 2:53 PM, Rafael J. Wysocki wrote:
> On Tue, Oct 21, 2025 at 11:07 PM Mario Limonciello (AMD) (kernel.org)
> <superm1@kernel.org> wrote:
>>
>>
>>
>> On 10/18/2025 9:21 AM, Muhammad Usama Anjum wrote:
>>> Export hibernation_in_progress() to be used by other modules. Add its
>>> signature when hibernation config isn't enabled as well.
>>
>> I wonder if you actually want to have pm_sleep_transition_in_progress()
>> exported instead.  "Logically" I would expect cancelling a hibernate and
>> cancelling a suspend should work similarly.
> 
> Well, it does AFAICS, except that only the "freeze" and "poweroff"
> transitions can be aborted during hibernation.  This is analogous to
> aborting a suspend transition.
I'll switch up with pm_sleep_transition_in_progress().

> 
> The missing part is a mechanism to cancel hibernation between image
> creation and the "poweroff" transition.
I'll add wakeup checking there and see if it works.


-- 
---
Thanks,
Usama