lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250522021649.55228-3-zhangzihuan@kylinos.cn>
Date: Thu, 22 May 2025 10:16:48 +0800
From: Zihuan Zhang <zhangzihuan@...inos.cn>
To: rafael@...nel.org,
	len.brown@...el.com,
	pavel@...nel.org
Cc: linux-pm@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	akpm@...ux-foundation.org,
	tzungbi@...nel.org,
	a.fatoum@...gutronix.de,
	jani.nikula@...el.com,
	joel.granados@...nel.org,
	paulmck@...nel.org,
	zhangguopeng@...inos.cn,
	linux@...ssschuh.net,
	Zihuan Zhang <zhangzihuan@...inos.cn>
Subject: [PATCH v2 2/3] PM / Sleep:  Introduce try_lock_system_sleep()

The suspend subsystem uses system_transition_mutex to serialize
suspend and hibernate transitions. The existing lock_system_sleep()
wrapper both acquires the mutex and sets PF_NOFREEZE on the current
task to avoid it being frozen during the suspend process.

However, in some places such as enter_state(), mutex_trylock() is
used instead. This path currently lacks PF_NOFREEZE protection.

This patch introduces a new wrapper:

    try_lock_system_sleep()

It sets PF_NOFREEZE and then performs mutex_trylock(), mirroring the
existing lock_system_sleep() implementation. This improves consistency
and enables future cleanup of raw trylock calls.

Signed-off-by: Zihuan Zhang <zhangzihuan@...inos.cn>
---
 include/linux/suspend.h |  2 ++
 kernel/power/main.c     | 14 ++++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/include/linux/suspend.h b/include/linux/suspend.h
index da6ebca3ff77..6c9e8fe0c446 100644
--- a/include/linux/suspend.h
+++ b/include/linux/suspend.h
@@ -468,6 +468,7 @@ extern void pm_wakep_autosleep_enabled(bool set);
 extern void pm_print_active_wakeup_sources(void);
 
 extern unsigned int lock_system_sleep(void);
+extern unsigned int try_lock_system_sleep(void);
 extern void unlock_system_sleep(unsigned int);
 
 #else /* !CONFIG_PM_SLEEP */
@@ -496,6 +497,7 @@ static inline void pm_wakeup_clear(bool reset) {}
 static inline void pm_system_irq_wakeup(unsigned int irq_number) {}
 
 static inline unsigned int lock_system_sleep(void) { return 0; }
+static inline unsigned int try_lock_system_sleep(void) { return 0; }
 static inline void unlock_system_sleep(unsigned int flags) {}
 
 #endif /* !CONFIG_PM_SLEEP */
diff --git a/kernel/power/main.c b/kernel/power/main.c
index 6254814d4817..0d3f94f62664 100644
--- a/kernel/power/main.c
+++ b/kernel/power/main.c
@@ -58,6 +58,20 @@ unsigned int lock_system_sleep(void)
 }
 EXPORT_SYMBOL_GPL(lock_system_sleep);
 
+unsigned int try_lock_system_sleep(void)
+{
+	unsigned int flags = current->flags;
+	current->flags |= PF_NOFREEZE;
+
+	if (!mutex_trylock(&system_transition_mutex)) {
+		current->flags = flags;
+		return 0;
+	}
+
+	return flags;
+}
+EXPORT_SYMBOL_GPL(try_lock_system_sleep);
+
 void unlock_system_sleep(unsigned int flags)
 {
 	if (!(flags & PF_NOFREEZE))
-- 
2.25.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ