sched/idle: Remove stale comments
Subsystems (4)
PATCH 1/3 sched/idle: Remove stale comments
rcu_idle_enter/exit() got removed in commit 1098582a0f6c ("sched,idle,rcu: Push rcu_idle deeper into the idle path"), so this comment is outdated. Remove it.
--- kernel/sched/idle.c | 6 ------ 1 file changed, 6 deletions(-)
kernel/sched/idle.c +0 -6
@@ -179,12 +179,6 @@ static void cpuidle_idle_call(void)return ; } -/* -* The RCU framework needs to be told that we are entering an idle -* section, so no more rcu read side critical sections and one more -* step to the grace period -*/ -if (cpuidle_not_available (drv, dev)) {tick_nohz_idle_stop_tick ();
Signature · 1 line
2.40.0
PATCH 2/3 cpuidle: Don't pass any values to cpuidle_not_available
There's no reason to pass any values to cpuidle_not_available() as the function works standalone. Since we're planning to use the function in other places, make it so to avoid code duplication.
--- drivers/cpuidle/cpuidle.c | 6 ++++-- include/linux/cpuidle.h | 6 ++---- kernel/sched/idle.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-)
drivers/cpuidle/cpuidle.c +4 -2
@@ -48,9 +48,11 @@ void disable_cpuidle(void) off =1 ; } -bool cpuidle_not_available (struct cpuidle_driver *drv, -struct cpuidle_device *dev) +bool cpuidle_not_available (void ) { +struct cpuidle_device *dev =cpuidle_get_device (); +struct cpuidle_driver *drv =cpuidle_get_cpu_driver (dev); +return off || !initialized || !drv || !dev || !dev->enabled; }
include/linux/cpuidle.h +2 -4
@@ -139,8 +139,7 @@ struct cpuidle_driver {#ifdef CONFIG_CPU_IDLE extern void disable_cpuidle (void ); -extern bool cpuidle_not_available (struct cpuidle_driver *drv, -struct cpuidle_device *dev); +extern bool cpuidle_not_available (void ); extern int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
@@ -174,8 +173,7 @@ static inline struct cpuidle_device *cpuidle_get_device(void) {return __this_cpu_read (cpuidle_devices); }#else static inline void disable_cpuidle (void ) { } -static inline bool cpuidle_not_available (struct cpuidle_driver *drv, -struct cpuidle_device *dev) +static inline bool cpuidle_not_available (void ) {return true; }static inline int cpuidle_select (struct cpuidle_driver *drv,struct cpuidle_device *dev,bool *stop_tick)
kernel/sched/idle.c +1 -1
@@ -179,7 +179,7 @@ static void cpuidle_idle_call(void)return ; } -if (cpuidle_not_available (drv, dev)) { +if (cpuidle_not_available ()) {tick_nohz_idle_stop_tick ();default_idle_call ();
Signature · 1 line
2.40.0
PATCH 3/3 PM: s2idle: Fully block the system from entering s2idle when cpuidle isn't supported
In reply to Kazuki Hs2idle isn't supported on platforms that don't support cpuidle as of 31a3409065d1 ("cpuidle / sleep: Do sanity checks in cpuidle_enter_freeze() too").
There is a check in the cpuidle subsystem which would prevent the system from entering s2idle. However, there is nothing in the suspend framework which prevents this, which can cause the suspend subsystem to think that the machine is entering s2idle while the cpuidle subsystem is not, which can completely break the system.
Block the machine from entering s2idle when cpuidle isn't supported in the suspend subsystem as well.
--- kernel/power/main.c | 12 +++++++++--- kernel/power/suspend.c | 5 +++++ 2 files changed, 14 insertions(+), 3 deletions(-)
kernel/power/main.c +9 -3
@@ -133,6 +133,8 @@ static ssize_t mem_sleep_show(struct kobject *kobj, struct kobj_attribute *attr,for (i =PM_SUSPEND_MIN ; i <PM_SUSPEND_MAX ; i++) {if (i >=PM_SUSPEND_MEM &&cxl_mem_active ())continue ; +if (i ==PM_SUSPEND_TO_IDLE &&cpuidle_not_available ()) +continue ;if (mem_sleep_states[i]) {const char *label = mem_sleep_states[i];
@@ -185,11 +187,15 @@ static ssize_t mem_sleep_store(struct kobject *kobj, struct kobj_attribute *attr } state =decode_suspend_state (buf, n); -if (state <PM_SUSPEND_MAX && state >PM_SUSPEND_ON ) +if (state ==PM_SUSPEND_TO_IDLE &&cpuidle_not_available ()) + goto einval; +if (state <PM_SUSPEND_MAX && state >PM_SUSPEND_ON ) { mem_sleep_current = state; -else - error = -EINVAL ; + goto out; + } + einval: + error = -EINVAL ; out:pm_autosleep_unlock ();return error ? error : n;
kernel/power/suspend.c +5 -0
@@ -556,6 +556,11 @@ static int enter_state(suspend_state_t state)trace_suspend_resume (TPS ("suspend_enter" ), state, true);if (state ==PM_SUSPEND_TO_IDLE ) { +if (cpuidle_not_available ()) { +pr_warn ("s2idle is unsupported when cpuidle is unavailable" ); +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.40.0
Rafael J. Wysocki
maintainerRe: [PATCH 3/3] PM: s2idle: Fully block the system from entering s2idle when cpuidle isn't supported
Quoted 4 lines · Kazuki H
s2idle isn't supported on platforms that don't support cpuidle as of
31a3409065d1("cpuidle / sleep: Do sanity checks incpuidle_enter_freeze()too").
This simply isn't correct.
As of the above commit, s2idle was still supported without cpuidle as long as arch_cpu_idle() worked.
Quoted 8 lines
There is a check in the cpuidle subsystem which would prevent the system from entering s2idle. However, there is nothing in the suspend framework which prevents this, which can cause the suspend subsystem to think that the machine is entering s2idle while the cpuidle subsystem is not, which can completely break the system.
Block the machine from entering s2idle when cpuidle isn't supported in the suspend subsystem as well.
First, please explain why the cpuidle_not_available() check in cpuidle_idle_call() is not sufficient to avoid the breakage.
Quoted 13 lines
Fixes 31a3409065d1 ("cpuidle / sleep: Do sanity checks in cpuidle_enter_freeze() too")Signed-off-by Kazuki H <[email protected]>--- kernel/power/main.c | 12 +++++++++--- kernel/power/suspend.c | 5 +++++ 2 files changed, 14 insertions(+), 3 deletions(-)kernel/power/main.c +0
-0
kernel/power/main.c static ssize_t mem_sleep_show(struct kobject *kobj, struct kobj_attribute *attr, · line 137
Quoted 5 lines
kernel/power/main.c +2
-0@@ -133,6 +133,8 @@ static ssize_t mem_sleep_show(struct kobject *kobj, struct kobj_attribute *attr,for (i =PM_SUSPEND_MIN ; i <PM_SUSPEND_MAX ; i++) {if (i >=PM_SUSPEND_MEM &&cxl_mem_active ())continue ; +if (i ==PM_SUSPEND_TO_IDLE &&cpuidle_not_available ()) +continue ;
Not really.
kernel/power/main.c static ssize_t mem_sleep_store(struct kobject *kobj, struct kobj_attribute *attr · line 190
Quoted 9 lines
kernel/power/main.c +1
-1if (mem_sleep_states[i]) {const char *label = mem_sleep_states[i];@@ -185,11 +187,15 @@ static ssize_t mem_sleep_store(struct kobject *kobj, struct kobj_attribute *attr } state =decode_suspend_state (buf, n); -if (state <PM_SUSPEND_MAX && state >PM_SUSPEND_ON ) +if (state ==PM_SUSPEND_TO_IDLE &&cpuidle_not_available ())
And same here.
Quoted 20 lines
kernel/power/main.c +6
-2+ goto einval; +if (state <PM_SUSPEND_MAX && state >PM_SUSPEND_ON ) { mem_sleep_current = state; - else - error = -EINVAL ; + goto out; + } + einval: + error = -EINVAL ; out:pm_autosleep_unlock ();return error ? error : n;kernel/power/suspend.c +0
-0@@ -556,6 +556,11 @@ 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)
Quoted 10 lines
kernel/power/suspend.c +5
-1if (state ==PM_SUSPEND_TO_IDLE ) { +if (cpuidle_not_available ()) { +pr_warn ("s2idle is unsupported when cpuidle is unavailable" ); +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" ); --
Again, I need to understand what the problem is in the first place.
Re: [PATCH 3/3] PM: s2idle: Fully block the system from entering s2idle when cpuidle isn't supported
Hi, apologies for the late response.
Quoted 10 lines · Rafael J. Wysocki
Quoted 4 lines · Kazuki H
s2idle isn't supported on platforms that don't support cpuidle as of
31a3409065d1("cpuidle / sleep: Do sanity checks incpuidle_enter_freeze()too").This simply isn't correct.
As of the above commit, s2idle was still supported without cpuidle as long as
arch_cpu_idle()worked.
Sorry I linked the wrong commit, ef2b22ac540c (cpuidle / sleep: Use broadcast timer for states that stop local timer) is the correct one.
This adds this block of code
if (cpuidle_not_available(drv, dev))
goto use_default;
which prevents this code, critical for s2idle, from executing
if (idle_should_freeze()) {
entered_state = cpuidle_enter_freeze(drv, dev);
if (entered_state >= 0) {
local_irq_enable();
goto exit_idle;
}
reflect = false;
next_state = cpuidle_find_deepest_state(drv, dev);
} else {
reflect = true;
/*
* Ask the cpuidle framework to choose a convenient idle state.
*/
next_state = cpuidle_select(drv, dev);
}Quoted 11 lines
Quoted 8 lines
There is a check in the cpuidle subsystem which would prevent the system from entering s2idle. However, there is nothing in the suspend framework which prevents this, which can cause the suspend subsystem to think that the machine is entering s2idle while the cpuidle subsystem is not, which can completely break the system.
Block the machine from entering s2idle when cpuidle isn't supported in the suspend subsystem as well.
First, please explain why the
cpuidle_not_available()check incpuidle_idle_call()is not sufficient to avoid the breakage.
cpuidle_idle_call() doesn't notify the PM subsystem that the host doesn't support s2idle. We need a seperate check here, otherwise the PM subsystem will happily continue entering s2idle without the other subsystem's knowledge.
Quoted 53 lines
Quoted 14 lines
Fixes 31a3409065d1 ("cpuidle / sleep: Do sanity checks in cpuidle_enter_freeze() too")Signed-off-by Kazuki H <[email protected]>--- kernel/power/main.c | 12 +++++++++--- kernel/power/suspend.c | 5 +++++ 2 files changed, 14 insertions(+), 3 deletions(-)kernel/power/main.c +0
-0kernel/power/main.c static ssize_t mem_sleep_show(struct kobject *kobj, struct kobj_attribute *attr, · line 137
Quoted 5 lines
kernel/power/main.c +2
-0@@ -133,6 +133,8 @@ static ssize_t mem_sleep_show(struct kobject *kobj, struct kobj_attribute *attr,for (i =PM_SUSPEND_MIN ; i <PM_SUSPEND_MAX ; i++) {if (i >=PM_SUSPEND_MEM &&cxl_mem_active ())continue ; +if (i ==PM_SUSPEND_TO_IDLE &&cpuidle_not_available ()) +continue ;Not really.
kernel/power/main.c static ssize_t mem_sleep_store(struct kobject *kobj, struct kobj_attribute *attr · line 190
Quoted 9 lines
kernel/power/main.c +1
-1if (mem_sleep_states[i]) {const char *label = mem_sleep_states[i];@@ -185,11 +187,15 @@ static ssize_t mem_sleep_store(struct kobject *kobj, struct kobj_attribute *attr } state =decode_suspend_state (buf, n); -if (state <PM_SUSPEND_MAX && state >PM_SUSPEND_ON ) +if (state ==PM_SUSPEND_TO_IDLE &&cpuidle_not_available ())And same here.
Quoted 19 lines
kernel/power/main.c +6
-2+ goto einval; +if (state <PM_SUSPEND_MAX && state >PM_SUSPEND_ON ) { mem_sleep_current = state; - else - error = -EINVAL ; + goto out; + } + einval: + error = -EINVAL ; out:pm_autosleep_unlock ();return error ? error : n;kernel/power/suspend.c +0
-0@@ -556,6 +556,11 @@ static int enter_state(suspend_state_t state)
Quoted 13 lines
kernel/power/suspend.c static int enter_state(suspend_state_t state)
Quoted 11 lines
kernel/power/suspend.c +5
-1trace_suspend_resume (TPS ("suspend_enter" ), state, true);if (state ==PM_SUSPEND_TO_IDLE ) { +if (cpuidle_not_available ()) { +pr_warn ("s2idle is unsupported when cpuidle is unavailable" ); +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" ); --Again, I need to understand what the problem is in the first place.
Thanks,
Kazuki