On Thu, May 22, 2025 at 4:35 AM Zihuan Zhang <zhangzihuan@kylinos.cn> wrote:
>
> This patch series introduces wrapper functions for locking
> system_transition_mutex used in system sleep (suspend/hibernate) code,
> and refactors the existing usage in kernel/power to improve maintainability,
> readability, and future extensibility.
>
> Currently, mutex_lock/unlock(&system_transition_mutex) is used directly
> in multiple places in the suspend and hibernation paths. This results in
> boilerplate repetition and makes it harder to change the locking mechanism
> later if needed (e.g., for debugging, tracing, or replacing the mutex
> with another primitive).
>
> Summary:
>
> - Patch 1 replaces mutex_lock with lock_system_sleep.
>
> - Patch 2 adds a non-blocking `try_lock_system_sleep()` for code paths that
> should proceed only if the lock is immediately available.
>
> - Patch 3 replaces remaining uses of `system_transition_mutex` in
> `kernel/power/` with the new helper functions.
>
> This change brings all system sleep transition locking behind well-named
> abstractions, preparing the code for future evolution while simplifying
> reasoning and avoiding repeated direct mutex usage.
>
> change log:
> V2:
> Fix PF_NOFREEZE leakage on try_lock_system_sleep() failure.
>
> Zihuan Zhang (3):
> PM / Sleep: Replace mutex_[un]lock(&system_transition_mutex) with
> [un]lock_system_sleep()
> PM / Sleep: Introduce try_lock_system_sleep()
> PM / Sleep: Replace mutex_trylock(&system_transition_mutex) with
> try_lock_system_sleep()
>
> include/linux/suspend.h | 2 ++
> kernel/power/hibernate.c | 11 +++++++----
> kernel/power/main.c | 14 ++++++++++++++
> kernel/power/suspend.c | 7 +++++--
> kernel/power/user.c | 6 ++++--
> kernel/reboot.c | 5 +++--
> 6 files changed, 35 insertions(+), 10 deletions(-)
>
> --
This is a bit too late for 6.16, please resubmit when 6.16-rc1 is out.
Thanks!