From owner-p4-projects Wed Apr 17 13: 9:39 2002 Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 8D11337B416; Wed, 17 Apr 2002 13:08:59 -0700 (PDT) Delivered-To: perforce@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id A7DD437B405 for ; Wed, 17 Apr 2002 13:08:58 -0700 (PDT) Received: (from perforce@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id g3HK8ww70397 for perforce@freebsd.org; Wed, 17 Apr 2002 13:08:58 -0700 (PDT) (envelope-from jhb@freebsd.org) Date: Wed, 17 Apr 2002 13:08:58 -0700 (PDT) Message-Id: <200204172008.g3HK8ww70397@freefall.freebsd.org> X-Authentication-Warning: freefall.freebsd.org: perforce set sender to jhb@freebsd.org using -f From: John Baldwin Subject: PERFORCE change 9932 for review To: Perforce Change Reviews Sender: owner-p4-projects@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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