kernel - Add requires p->p_token locking and holds around fork()'s child proc
authorMatthew Dillon <dillon@apollo.backplane.com>
Thu, 1 Dec 2011 01:24:11 +0000 (17:24 -0800)
committerMatthew Dillon <dillon@apollo.backplane.com>
Thu, 1 Dec 2011 01:24:11 +0000 (17:24 -0800)
commitde7ac1d675b7dd4a7e0108b0482570e5ec02afc1
treed4d6582d98fa088a18b4b731d750dd1310667a9c
parent7a175765de62a14e3e3d660aac14f91810647a4e
kernel - Add requires p->p_token locking and holds around fork()'s child proc

* fork() and vfork() allocate a new process, p2, initialize, and add it to
  the allproc list as well as other lists.

* These functions failed to acquire p2's token, p2 becomes visible to the
  rest of the system when it's added to the allproc list.  Even though p2's
  state is set to SIDL, this is insufficient protection.

  Acquire the token prior to adding p2 to allproc and keep holding the token
  until after we have finished initializing p2.

* We must also PHOLD()/PRELE() p2 around the start_forked_proc() call
  to prevent it from getting ripped out from under us (if it exits
  quickly and/or detaches itself from its parent).

* Possibly fixes the random seg-faulting issue we've seen under very heavy
  fork/exec (parallel compile) loads on the 48-core monster.
sys/kern/kern_fork.c