linux/fs/proc
Thomas Gleixner f2530dc71c 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>
2013-04-12 14:18:43 +02:00
..
array.c kthread: Prevent unpark race which puts threads on the wrong cpu 2013-04-12 14:18:43 +02:00
base.c fs/proc: clean up printks 2013-02-27 19:10:11 -08:00
cmdline.c
consoles.c
cpuinfo.c
devices.c
fd.c
fd.h
generic.c procfs: add proc_remove_subtree() 2013-04-09 14:09:17 -04:00
inode.c vfs,proc: guarantee unique inodes in /proc 2013-03-22 11:44:04 -07:00
internal.h coredump: remove redundant defines for dumpable states 2013-02-27 19:10:11 -08:00
interrupts.c
Kconfig
kcore.c fs/proc: clean up printks 2013-02-27 19:10:11 -08:00
kmsg.c
loadavg.c
Makefile tty: Added a CONFIG_TTY option to allow removal of TTY 2013-01-18 16:15:27 -08:00
meminfo.c swap: make each swap partition have one address_space 2013-02-23 17:50:17 -08:00
mmu.c
namespaces.c proc: Use nd_jump_link in proc_ns_follow_link 2013-03-09 00:14:45 -08:00
nommu.c new helper: file_inode(file) 2013-02-22 23:31:31 -05:00
page.c
proc_devtree.c fs/proc: clean up printks 2013-02-27 19:10:11 -08:00
proc_net.c Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2013-02-26 20:16:07 -08:00
proc_sysctl.c fs/proc: clean up printks 2013-02-27 19:10:11 -08:00
proc_tty.c
root.c userns: Restrict when proc and sysfs can be mounted 2013-03-27 07:50:08 -07:00
self.c
softirqs.c
stat.c
task_mmu.c new helper: file_inode(file) 2013-02-22 23:31:31 -05:00
task_nommu.c new helper: file_inode(file) 2013-02-22 23:31:31 -05:00
uptime.c
version.c
vmcore.c fs/proc/vmcore.c: put if tests in the top of the while loop to reduce duplication 2013-02-27 19:10:11 -08:00