Date: Wed, 17 Apr 2002 13:08:58 -0700 (PDT) From: John Baldwin <jhb@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 9932 for review Message-ID: <200204172008.g3HK8ww70397@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://people.freebsd.org/~peter/p4db/chv.cgi?CH=9932 Change 9932 by jhb@jhb_laptop on 2002/04/17 13:08:14 - Shuffle a few things up before locking the proctree_lock. - Interlock proctree_lock and the lock on the parent proces at the end of exit1() and before the parent sleeps at the end of wait1() to properly close the race of a parent missing the wakeup from one of it's children exiting. Affected files ... ... //depot/projects/smpng/sys/kern/kern_exit.c#36 edit Differences ... ==== //depot/projects/smpng/sys/kern/kern_exit.c#36 (text+ko) ==== @@ -313,6 +313,25 @@ } /* + * Release our limits structure. + */ + mtx_assert(&Giant, MA_OWNED); + if (--p->p_limit->p_refcnt == 0) { + FREE(p->p_limit, M_SUBPROC); + p->p_limit = NULL; + } + + /* + * Release this thread's reference to the ucred. The actual proc + * reference will stay around until the proc is harvested by + * wait(). At this point the ucred is immutable (no other threads + * from this proc are around that can change it) so we leave the + * per-thread ucred pointer intact in case it is needed although + * in theory nothing should be using it at this point. + */ + crfree(td->td_ucred); + + /* * Remove proc from allproc queue and pidhash chain. * Place onto zombproc. Unlink from parent's child list. */ @@ -391,35 +410,8 @@ if (p->p_flag & P_KTHREAD) wakeup((caddr_t)p); PROC_UNLOCK(p); - sx_xunlock(&proctree_lock); /* - * Clear curproc after we've done all operations - * that could block, and before tearing down the rest - * of the process state that might be used from clock, etc. - * Also, can't clear curproc while we're still runnable, - * as we're not on a run queue (we are current, just not - * a proper proc any longer!). - * - * Other substructures are freed from wait(). - */ - mtx_assert(&Giant, MA_OWNED); - if (--p->p_limit->p_refcnt == 0) { - FREE(p->p_limit, M_SUBPROC); - p->p_limit = NULL; - } - - /* - * Release this thread's reference to the ucred. The actual proc - * reference will stay around until the proc is harvested by - * wait(). At this point the ucred is immutable (no other threads - * from this proc are around that can change it) so we leave the - * per-thread ucred pointer intact in case it is needed although - * in theory nothing should be using it at this point. - */ - crfree(td->td_ucred); - - /* * Finally, call machine-dependent code to release the remaining * resources including address space, the kernel stack and pcb. * The address space is released by "vmspace_exitfree(p)" in @@ -429,6 +421,7 @@ PROC_LOCK(p); PROC_LOCK(p->p_pptr); + sx_xunlock(&proctree_lock); mtx_lock_spin(&sched_lock); while (mtx_owned(&Giant)) mtx_unlock(&Giant); @@ -697,17 +690,19 @@ } PROC_UNLOCK(p); } - sx_xunlock(&proctree_lock); if (nfound == 0) { + sx_xunlock(&proctree_lock); mtx_unlock(&Giant); return (ECHILD); } if (uap->options & WNOHANG) { + sx_xunlock(&proctree_lock); td->td_retval[0] = 0; mtx_unlock(&Giant); return (0); } PROC_LOCK(q); + sx_xunlock(&proctree_lock); error = msleep((caddr_t)q, &q->p_mtx, PWAIT | PCATCH, "wait", 0); PROC_UNLOCK(q); if (error) { To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe p4-projects" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200204172008.g3HK8ww70397>