DragonFly BSD
DragonFly commits List (threaded) for 2011-06
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: git: kernel: Remove an extra p_lock == 0 check


From: Matthew Dillon <dillon@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 2 Jun 2011 13:37:33 -0700 (PDT)

:commit 4a7e6f5530dd5eb9ca5195aeb18a0ebd59b0fa41
:Author: YONETANI Tomokazu <y0netan1@dragonflybsd.org>
:Date:   Thu Jun 2 14:17:46 2011 +0900
:
:    kernel: Remove an extra p_lock == 0 check
:    
:    proc_remove_zombie() waits for p_lock to drop to zero before removing
:    the process off zombproc, so this assertion is not needed (any more).
:
:Summary of changes:
: sys/kern/kern_exit.c |    1 -
: 1 files changed, 0 insertions(+), 1 deletions(-)
:
:http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/4a7e6f5530dd5eb9ca5195aeb18a0ebd59b0fa41
:

    I think we need one more addition.  Since p_lock can be acquired during
    the process removal there need to be a final wait loop after the proc
    has been removed from all queues, just before the kfree(p).  It will be
    a very rare case but it definitely can still occur if e.g. the SYSCTL_OUT
    code blocks on a VM fault or something like that.

    (untested patch below)

					-Matt
					Matthew Dillon 
					<dillon@backplane.com>

diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index 1e5a110..274f153 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -934,6 +934,17 @@ loop:
 			}
 
 			vm_waitproc(p);
+
+			/*
+			 * Temporary refs may still have been acquired while
+			 * we removed the process, make sure they are all
+			 * gone before kfree()ing.  Now that the process has
+			 * been removed from all lists and all references to
+			 * it have gone away, no new refs can occur.
+			 */
+			while (p->p_lock)
+				tsleep(p, 0, "reap4", hz);
+
 			kfree(p, M_PROC);
 			nprocs--;
 			error = 0;




[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]