Skip to contentSkip to conversation

PM: s2idle: Don't allow s2idle when cpuidle isn't supported

PATCH In review Kazuki Hashimoto 3 participants 4 messages Feb 14, 2023 – Mar 15, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PM: s2idle: Don't allow s2idle when cpuidle isn't supported

s2idle isn't supported on platforms that don't support cpuidle as of 31a3409065d1 ("cpuidle / sleep: Do sanity checks in cpuidle_enter_freeze() too"), so update the suspend framework to reflect this in order to avoid breakages.

Fixes 31a3409065d1 ("cpuidle / sleep: Do sanity checks in cpuidle_enter_freeze() too")
---
 kernel/power/suspend.c | 6 ++++++
 1 file changed, 6 insertions(+)
kernel/power/suspend.c +6 -0
index 3f436282547c..27507ae7c9c9 100644
@@ -556,6 +556,12 @@ static int enter_state(suspend_state_t state)
 
 	trace_suspend_resume(TPS("suspend_enter"), state, true);
 	if (state == PM_SUSPEND_TO_IDLE) {
+		struct cpuidle_device *dev = cpuidle_get_device();
+		struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
+
+		if (cpuidle_not_available(drv, dev))
+			return -EINVAL;
+
 #ifdef CONFIG_PM_DEBUG
 		if (pm_test_level != TEST_NONE && pm_test_level <= TEST_CPUS) {
 			pr_warn("Unsupported test mode for suspend to idle, please choose none/freezer/devices/platform.\n");
Signature · 1 line
2.39.1
#1 lore raw
Quoted 19 lines · Kazuki Hashimoto

s2idle isn't supported on platforms that don't support cpuidle as of 31a3409065d1 ("cpuidle / sleep: Do sanity checks in cpuidle_enter_freeze() too"), so update the suspend framework to reflect this in order to avoid breakages.

Fixes 31a3409065d1 ("cpuidle / sleep: Do sanity checks in cpuidle_enter_freeze() too")
---
 kernel/power/suspend.c | 6 ++++++
 1 file changed, 6 insertions(+)
kernel/power/suspend.c +0 -0
index 3f436282547c..27507ae7c9c9 100644
@@ -556,6 +556,12 @@ static int enter_state(suspend_state_t state)
 
 	trace_suspend_resume(TPS("suspend_enter"), state, true);

kernel/power/suspend.c static int enter_state(suspend_state_t state) · line 567

Quoted 10 lines
kernel/power/suspend.c +6 -0
 	if (state == PM_SUSPEND_TO_IDLE) {
+		struct cpuidle_device *dev = cpuidle_get_device();
+		struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
+
+		if (cpuidle_not_available(drv, dev))
+			return -EINVAL;
+
 #ifdef CONFIG_PM_DEBUG
 		if (pm_test_level != TEST_NONE && pm_test_level <= TEST_CPUS) {
 			pr_warn("Unsupported test mode for suspend to idle, please choose none/freezer/devices/platform.\n");

Well... this turns s2idle from "slighly broken" to "fully broken". I'm not sure that's a good idea.

If this (or something equivalent) goes in, we'll have to carry a revert in the Asahi tree until the PSCI-replacement story goes in, because lots of people are using the current somewhat broken s2idle. It's a lot better than having no sleep modes at all.

Also, if you intend to disable s2idle on these platforms, you have to actually stop advertising it. Advertising it and then refusing to enter s2idle is not acceptable, it means people will get "sleep" buttons and expect sleep to work and then it won't. But then that could also introduce race conditions with userspace checking for sleep support before the cpuidle driver loads. So there is definitely a can of worms here.

- Hector

#2 lore raw
In reply to Kazuki Hashimoto
Quoted 5 lines · Kazuki Hashimoto

s2idle isn't supported on platforms that don't support cpuidle as of 31a3409065d1 ("cpuidle / sleep: Do sanity checks in cpuidle_enter_freeze() too"), so update the suspend framework to reflect this in order to avoid breakages.

Hmm. Doesn't the cpuidle_not_available() check in cpuidle_idle_call() trigger then?

The commit mentioned above hasn't changed that AFAICS.

author
#3 lore raw
Quoted 7 lines · Rafael J. Wysocki
Quoted 5 lines · Kazuki Hashimoto

s2idle isn't supported on platforms that don't support cpuidle as of 31a3409065d1 ("cpuidle / sleep: Do sanity checks in cpuidle_enter_freeze() too"), so update the suspend framework to reflect this in order to avoid breakages.

Hello, apologies for the late reply.

Quoted 4 lines

Hmm. Doesn't the cpuidle_not_available() check in cpuidle_idle_call() trigger then?

The commit mentioned above hasn't changed that AFAICS.

Yes it does, but there's nothing in enter_state() that's preventing the system from entering s2idle. Both the suspend and cpuidle subsystems need to be aware that the system is entering s2idle, otherwise it'll result in breakges.

Thanks,
Kazuki