diff options
author | Peter Zijlstra <a.p.zijlstra@chello.nl> | 2012-03-20 10:57:01 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2012-03-27 08:50:14 -0400 |
commit | 2baab4e90495ebc9826c93f79d74d6e60a828d24 (patch) | |
tree | 6e6316694a9bc69e517e50b0d01043c4c9e83888 /kernel/cpuset.c | |
parent | bc758133ed73d4b06952bec21da23e28e62bf3ba (diff) |
sched: Fix select_fallback_rq() vs cpu_active/cpu_online
Commit 5fbd036b55 ("sched: Cleanup cpu_active madness"), which was
supposed to finally sort the cpu_active mess, instead uncovered more.
Since CPU_STARTING is ran before setting the cpu online, there's a
(small) window where the cpu has active,!online.
If during this time there's a wakeup of a task that used to reside on
that cpu select_task_rq() will use select_fallback_rq() to compute an
alternative cpu to run on since we find !online.
select_fallback_rq() however will compute the new cpu against
cpu_active, this means that it can return the same cpu it started out
with, the !online one, since that cpu is in fact marked active.
This results in us trying to scheduling a task on an offline cpu and
triggering a WARN in the IPI code.
The solution proposed by Chuansheng Liu of setting cpu_active in
set_cpu_online() is buggy, firstly not all archs actually use
set_cpu_online(), secondly, not all archs call set_cpu_online() with
IRQs disabled, this means we would introduce either the same race or
the race from fd8a7de17 ("x86: cpu-hotplug: Prevent softirq wakeup on
wrong CPU") -- albeit much narrower.
[ By setting online first and active later we have a window of
online,!active, fresh and bound kthreads have task_cpu() of 0 and
since cpu0 isn't in tsk_cpus_allowed() we end up in
select_fallback_rq() which excludes !active, resulting in a reset
of ->cpus_allowed and the thread running all over the place. ]
The solution is to re-work select_fallback_rq() to require active
_and_ online. This makes the active,!online case work as expected,
OTOH archs running CPU_STARTING after setting online are now
vulnerable to the issue from fd8a7de17 -- these are alpha and
blackfin.
Reported-by: Chuansheng Liu <chuansheng.liu@intel.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: linux-alpha@vger.kernel.org
Link: http://lkml.kernel.org/n/tip-hubqk1i10o4dpvlm06gq7v6j@git.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel/cpuset.c')
-rw-r--r-- | kernel/cpuset.c | 20 |
1 files changed, 4 insertions, 16 deletions
diff --git a/kernel/cpuset.c b/kernel/cpuset.c index a09ac2b9a661..c9837b74ab96 100644 --- a/kernel/cpuset.c +++ b/kernel/cpuset.c | |||
@@ -2195,7 +2195,7 @@ void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask) | |||
2195 | mutex_unlock(&callback_mutex); | 2195 | mutex_unlock(&callback_mutex); |
2196 | } | 2196 | } |
2197 | 2197 | ||
2198 | int cpuset_cpus_allowed_fallback(struct task_struct *tsk) | 2198 | void cpuset_cpus_allowed_fallback(struct task_struct *tsk) |
2199 | { | 2199 | { |
2200 | const struct cpuset *cs; | 2200 | const struct cpuset *cs; |
2201 | int cpu; | 2201 | int cpu; |
@@ -2219,22 +2219,10 @@ int cpuset_cpus_allowed_fallback(struct task_struct *tsk) | |||
2219 | * changes in tsk_cs()->cpus_allowed. Otherwise we can temporary | 2219 | * changes in tsk_cs()->cpus_allowed. Otherwise we can temporary |
2220 | * set any mask even if it is not right from task_cs() pov, | 2220 | * set any mask even if it is not right from task_cs() pov, |
2221 | * the pending set_cpus_allowed_ptr() will fix things. | 2221 | * the pending set_cpus_allowed_ptr() will fix things. |
2222 | * | ||
2223 | * select_fallback_rq() will fix things ups and set cpu_possible_mask | ||
2224 | * if required. | ||
2222 | */ | 2225 | */ |
2223 | |||
2224 | cpu = cpumask_any_and(&tsk->cpus_allowed, cpu_active_mask); | ||
2225 | if (cpu >= nr_cpu_ids) { | ||
2226 | /* | ||
2227 | * Either tsk->cpus_allowed is wrong (see above) or it | ||
2228 | * is actually empty. The latter case is only possible | ||
2229 | * if we are racing with remove_tasks_in_empty_cpuset(). | ||
2230 | * Like above we can temporary set any mask and rely on | ||
2231 | * set_cpus_allowed_ptr() as synchronization point. | ||
2232 | */ | ||
2233 | do_set_cpus_allowed(tsk, cpu_possible_mask); | ||
2234 | cpu = cpumask_any(cpu_active_mask); | ||
2235 | } | ||
2236 | |||
2237 | return cpu; | ||
2238 | } | 2226 | } |
2239 | 2227 | ||
2240 | void cpuset_init_current_mems_allowed(void) | 2228 | void cpuset_init_current_mems_allowed(void) |