]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commit
kthread: Prevent unpark race which puts threads on the wrong cpu
authorThomas Gleixner <tglx@linutronix.de>
Tue, 9 Apr 2013 07:33:34 +0000 (09:33 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Fri, 12 Apr 2013 12:18:43 +0000 (14:18 +0200)
commitf2530dc71cf0822f90bb63ea4600caaef33a66bb
tree182473ca3a295cdbd907826aa22bae94c52fa486
parentcfb63bafdb87bbcdc5d6dbbca623d3f69475f118
kthread: Prevent unpark race which puts threads on the wrong cpu

The smpboot threads rely on the park/unpark mechanism which binds per
cpu threads on a particular core. Though the functionality is racy:

CPU0           CPU1             CPU2
unpark(T)     wake_up_process(T)
  clear(SHOULD_PARK) T runs
leave parkme() due to !SHOULD_PARK
  bind_to(CPU2) BUG_ON(wrong CPU)

We cannot let the tasks move themself to the target CPU as one of
those tasks is actually the migration thread itself, which requires
that it starts running on the target cpu right away.

The solution to this problem is to prevent wakeups in park mode which
are not from unpark(). That way we can guarantee that the association
of the task to the target cpu is working correctly.

Add a new task state (TASK_PARKED) which prevents other wakeups and
use this state explicitly for the unpark wakeup.

Peter noticed: Also, since the task state is visible to userspace and
all the parked tasks are still in the PID space, its a good hint in ps
and friends that these tasks aren't really there for the moment.

The migration thread has another related issue.

CPU0               CPU1
Bring up CPU2
create_thread(T)
park(T)
 wait_for_completion()
 parkme()
 complete()
sched_set_stop_task()
 schedule(TASK_PARKED)

The sched_set_stop_task() call is issued while the task is on the
runqueue of CPU1 and that confuses the hell out of the stop_task class
on that cpu. So we need the same synchronizaion before
sched_set_stop_task().

Reported-by: Dave Jones <davej@redhat.com>
Reported-and-tested-by: Dave Hansen <dave@sr71.net>
Reported-and-tested-by: Borislav Petkov <bp@alien8.de>
Acked-by: Peter Ziljstra <peterz@infradead.org>
Cc: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Cc: dhillf@gmail.com
Cc: Ingo Molnar <mingo@kernel.org>
Cc: stable@vger.kernel.org
Link: http://lkml.kernel.org/r/alpine.LFD.2.02.1304091635430.21884@ionos
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
fs/proc/array.c
include/linux/sched.h
include/trace/events/sched.h
kernel/kthread.c
kernel/smpboot.c