Commit 50e76632 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar

sched/cpuset/pm: Fix cpuset vs. suspend-resume bugs

Cpusets vs. suspend-resume is _completely_ broken. And it got noticed
because it now resulted in non-cpuset usage breaking too.

On suspend cpuset_cpu_inactive() doesn't call into
cpuset_update_active_cpus() because it doesn't want to move tasks about,
there is no need, all tasks are frozen and won't run again until after
we've resumed everything.

But this means that when we finally do call into
cpuset_update_active_cpus() after resuming the last frozen cpu in
cpuset_cpu_active(), the top_cpuset will not have any difference with
the cpu_active_mask and this it will not in fact do _anything_.

So the cpuset configuration will not be restored. This was largely
hidden because we would unconditionally create identity domains and
mobile users would not in fact use cpusets much. And servers what do use
cpusets tend to not suspend-resume much.

An addition problem is that we'd not in fact wait for the cpuset work to
finish before resuming the tasks, allowing spurious migrations outside
of the specified domains.

Fix the rebuild by introducing cpuset_force_rebuild() and fix the
ordering with cpuset_wait_for_hotplug().
Reported-by: default avatarAndy Lutomirski <luto@kernel.org>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Cc: <stable@vger.kernel.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Fixes: deb7aa30 ("cpuset: reorganize CPU / memory hotplug handling")
Link: http://lkml.kernel.org/r/20170907091338.orwxrqkbfkki3c24@hirez.programming.kicks-ass.netSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent a731ebe6
...@@ -51,7 +51,9 @@ static inline void cpuset_dec(void) ...@@ -51,7 +51,9 @@ static inline void cpuset_dec(void)
extern int cpuset_init(void); extern int cpuset_init(void);
extern void cpuset_init_smp(void); extern void cpuset_init_smp(void);
extern void cpuset_force_rebuild(void);
extern void cpuset_update_active_cpus(void); extern void cpuset_update_active_cpus(void);
extern void cpuset_wait_for_hotplug(void);
extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask); extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask);
extern void cpuset_cpus_allowed_fallback(struct task_struct *p); extern void cpuset_cpus_allowed_fallback(struct task_struct *p);
extern nodemask_t cpuset_mems_allowed(struct task_struct *p); extern nodemask_t cpuset_mems_allowed(struct task_struct *p);
...@@ -164,11 +166,15 @@ static inline bool cpusets_enabled(void) { return false; } ...@@ -164,11 +166,15 @@ static inline bool cpusets_enabled(void) { return false; }
static inline int cpuset_init(void) { return 0; } static inline int cpuset_init(void) { return 0; }
static inline void cpuset_init_smp(void) {} static inline void cpuset_init_smp(void) {}
static inline void cpuset_force_rebuild(void) { }
static inline void cpuset_update_active_cpus(void) static inline void cpuset_update_active_cpus(void)
{ {
partition_sched_domains(1, NULL, NULL); partition_sched_domains(1, NULL, NULL);
} }
static inline void cpuset_wait_for_hotplug(void) { }
static inline void cpuset_cpus_allowed(struct task_struct *p, static inline void cpuset_cpus_allowed(struct task_struct *p,
struct cpumask *mask) struct cpumask *mask)
{ {
......
...@@ -2267,6 +2267,13 @@ static void cpuset_hotplug_update_tasks(struct cpuset *cs) ...@@ -2267,6 +2267,13 @@ static void cpuset_hotplug_update_tasks(struct cpuset *cs)
mutex_unlock(&cpuset_mutex); mutex_unlock(&cpuset_mutex);
} }
static bool force_rebuild;
void cpuset_force_rebuild(void)
{
force_rebuild = true;
}
/** /**
* cpuset_hotplug_workfn - handle CPU/memory hotunplug for a cpuset * cpuset_hotplug_workfn - handle CPU/memory hotunplug for a cpuset
* *
...@@ -2341,8 +2348,10 @@ static void cpuset_hotplug_workfn(struct work_struct *work) ...@@ -2341,8 +2348,10 @@ static void cpuset_hotplug_workfn(struct work_struct *work)
} }
/* rebuild sched domains if cpus_allowed has changed */ /* rebuild sched domains if cpus_allowed has changed */
if (cpus_updated) if (cpus_updated || force_rebuild) {
force_rebuild = false;
rebuild_sched_domains(); rebuild_sched_domains();
}
} }
void cpuset_update_active_cpus(void) void cpuset_update_active_cpus(void)
...@@ -2355,6 +2364,11 @@ void cpuset_update_active_cpus(void) ...@@ -2355,6 +2364,11 @@ void cpuset_update_active_cpus(void)
schedule_work(&cpuset_hotplug_work); schedule_work(&cpuset_hotplug_work);
} }
void cpuset_wait_for_hotplug(void)
{
flush_work(&cpuset_hotplug_work);
}
/* /*
* Keep top_cpuset.mems_allowed tracking node_states[N_MEMORY]. * Keep top_cpuset.mems_allowed tracking node_states[N_MEMORY].
* Call this routine anytime after node_states[N_MEMORY] changes. * Call this routine anytime after node_states[N_MEMORY] changes.
......
...@@ -20,8 +20,9 @@ ...@@ -20,8 +20,9 @@
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <linux/kmod.h> #include <linux/kmod.h>
#include <trace/events/power.h> #include <trace/events/power.h>
#include <linux/cpuset.h>
/* /*
* Timeout for stopping processes * Timeout for stopping processes
*/ */
unsigned int __read_mostly freeze_timeout_msecs = 20 * MSEC_PER_SEC; unsigned int __read_mostly freeze_timeout_msecs = 20 * MSEC_PER_SEC;
...@@ -202,6 +203,8 @@ void thaw_processes(void) ...@@ -202,6 +203,8 @@ void thaw_processes(void)
__usermodehelper_set_disable_depth(UMH_FREEZING); __usermodehelper_set_disable_depth(UMH_FREEZING);
thaw_workqueues(); thaw_workqueues();
cpuset_wait_for_hotplug();
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_process_thread(g, p) { for_each_process_thread(g, p) {
/* No other threads should have PF_SUSPEND_TASK set */ /* No other threads should have PF_SUSPEND_TASK set */
......
...@@ -5556,16 +5556,15 @@ static void cpuset_cpu_active(void) ...@@ -5556,16 +5556,15 @@ static void cpuset_cpu_active(void)
* operation in the resume sequence, just build a single sched * operation in the resume sequence, just build a single sched
* domain, ignoring cpusets. * domain, ignoring cpusets.
*/ */
num_cpus_frozen--; partition_sched_domains(1, NULL, NULL);
if (likely(num_cpus_frozen)) { if (--num_cpus_frozen)
partition_sched_domains(1, NULL, NULL);
return; return;
}
/* /*
* This is the last CPU online operation. So fall through and * This is the last CPU online operation. So fall through and
* restore the original sched domains by considering the * restore the original sched domains by considering the
* cpuset configurations. * cpuset configurations.
*/ */
cpuset_force_rebuild();
} }
cpuset_update_active_cpus(); cpuset_update_active_cpus();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment