Source-Changes-HG archive

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

[src/netbsd-6]: src/sys/kern Pull up following revision(s) (requested by pgoy...



details:   https://anonhg.NetBSD.org/src/rev/29c6b3f219fb
branches:  netbsd-6
changeset: 777013:29c6b3f219fb
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Sun Nov 15 20:37:04 2015 +0000

description:
Pull up following revision(s) (requested by pgoyette in ticket #1333):
        sys/kern/kern_exec.c: revision 1.420
        sys/kern/kern_synch.c: revision 1.309
        sys/kern/kern_exit.c: revision 1.246
        sys/kern/kern_exit.c: revision 1.247
        sys/kern/kern_exec.c: revision 1.419
In execve_runproc(), update the p_waited entry for the process being
moved to SSTOP state, not for its parent.  (It is correct to update
the parent's p_nstopchild count.)  If the value is not already zero,
it could prevent its parent from waiting for the process.
Fixes PR kern/50298
Pullups will be requested for:
        NetBSD-7, -6, -6-0, -6-1, -5, -5-0, -5-1, and -5-2
When clearing out the scheduler queues during system shutdown, we move
all processes to the SSTOP state.  Make sure we update each process's
p_waited and the parents' p_nstopchild counters to maintain consistent
values.  Should not make any real difference this late in the shutdown
process, but we should still be consistent just in case.
Fixes PR kern/50318
Pullups will be requested for:
        NetBSD-7, -6, -6-0, -6-1, -5, -5-0, -5-1, and -5-2
Currently, if a process is exiting and its parent has indicated no intent
of reaping the process (nor any other children), the process wil get
reparented to init.  Since the state of the exiting process at this point
is SDEAD, proc_reparent() will not update either the old or new parent's
p_nstopchild counters.
This change causes both old and new parents to be properly updated.
Fixes PR kern/50300
Pullups will be requested for:
        NetBSD-7, -6, -6-0, -6-1, -5, -5-0, -5-1, and -5-2
For processes marked with PS_STOPEXIT, update the process's p_waited
value, and update its parent's p_nstopchild value when marking the
process's p_stat to SSTOP.  The process needed to be SACTIVE to get
here, so this transition represents an additional process for which
the parent needs to wait.
Fixes PR kern/50308
Pullups will be requested for:
        NetBSD-7, -6, -6-0, -6-1, -5, -5-0, -5-1, and -5-2
In spawn_return() we temporarily move the process state to SSTOP, but
without updating its p_waited value or its parent's p_nstopchild
counter.  Later, we restore the original state, again without any
adjustment of the related values.  This leaves a relatively short
window when the values are inconsistent and could interfere with the
proper operation of sys_wait() for the parent (if it manages to be
scheduled;  it's not totally clear what, if anything, prevents
scheduling/execution of the parent).
If during this window, any of the checks being made result in an
error, we call exit1() which will eventually migrate the process's
state to SDEAD (with an intermediate transition to SDYING).  At
this point the other variables get updated, and we finally restore
a consistent state.
This change updates the p_waited and parent's p_nstopchild at each
step to eliminate any windows during which the values could lead to
incorrect decisions.
Fixes PR kern/50330
Pullups will be requested for NetBSD-7, -6, -6-0, and -6-1

diffstat:

 sys/kern/kern_exec.c  |  36 +++++++++++++++++++++++++++---------
 sys/kern/kern_exit.c  |  15 +++++++++++----
 sys/kern/kern_synch.c |  12 +++++++++---
 3 files changed, 47 insertions(+), 16 deletions(-)

diffs (204 lines):

diff -r d546053e4f7b -r 29c6b3f219fb sys/kern/kern_exec.c
--- a/sys/kern/kern_exec.c      Sun Nov 15 20:27:34 2015 +0000
+++ b/sys/kern/kern_exec.c      Sun Nov 15 20:37:04 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_exec.c,v 1.339.2.9 2014/04/21 10:00:10 bouyer Exp $       */
+/*     $NetBSD: kern_exec.c,v 1.339.2.10 2015/11/15 20:37:04 bouyer Exp $      */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.339.2.9 2014/04/21 10:00:10 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.339.2.10 2015/11/15 20:37:04 bouyer Exp $");
 
 #include "opt_exec.h"
 #include "opt_ktrace.h"
@@ -1412,7 +1412,7 @@
        if (p->p_sflag & PS_STOPEXEC) {
                KERNEL_UNLOCK_ALL(l, &l->l_biglocks);
                p->p_pptr->p_nstopchild++;
-               p->p_pptr->p_waited = 0;
+               p->p_waited = 0;
                mutex_enter(p->p_lock);
                ksiginfo_queue_init(&kq);
                sigclearall(p, &contsigmask, &kq);
@@ -1849,6 +1849,7 @@
        struct spawn_exec_data *spawn_data = arg;
        struct lwp *l = curlwp;
        int error, newfd;
+       int ostat;
        size_t i;
        const struct posix_spawn_file_actions_entry *fae;
        pid_t ppid;
@@ -1921,7 +1922,6 @@
 
        /* handle posix_spawnattr */
        if (spawn_data->sed_attrs != NULL) {
-               int ostat;
                struct sigaction sigact;
                sigact._sa_u._sa_handler = SIG_DFL;
                sigact.sa_flags = 0;
@@ -1930,8 +1930,18 @@
                 * set state to SSTOP so that this proc can be found by pid.
                 * see proc_enterprp, do_sched_setparam below
                 */
+               mutex_enter(proc_lock);
+               /*
+                * p_stat should be SACTIVE, so we need to adjust the
+                * parent's p_nstopchild here.  For safety, just make
+                * we're on the good side of SDEAD before we adjust.
+                */
                ostat = l->l_proc->p_stat;
+               KASSERT(ostat < SSTOP);
                l->l_proc->p_stat = SSTOP;
+               l->l_proc->p_waited = 0;
+               l->l_proc->p_pptr->p_nstopchild++;
+               mutex_exit(proc_lock);
 
                /* Set process group */
                if (spawn_data->sed_attrs->sa_flags & POSIX_SPAWN_SETPGROUP) {
@@ -1944,7 +1954,7 @@
                        error = proc_enterpgrp(spawn_data->sed_parent,
                            mypid, pgrp, false);
                        if (error)
-                               goto report_error;
+                               goto report_error_stopped;
                }
 
                /* Set scheduler policy */
@@ -1958,7 +1968,7 @@
                            SCHED_NONE, &spawn_data->sed_attrs->sa_schedparam);
                }
                if (error)
-                       goto report_error;
+                       goto report_error_stopped;
 
                /* Reset user ID's */
                if (spawn_data->sed_attrs->sa_flags & POSIX_SPAWN_RESETIDS) {
@@ -1966,12 +1976,12 @@
                             kauth_cred_getgid(l->l_cred), -1,
                             ID_E_EQ_R | ID_E_EQ_S);
                        if (error)
-                               goto report_error;
+                               goto report_error_stopped;
                        error = do_setresuid(l, -1,
                            kauth_cred_getuid(l->l_cred), -1,
                            ID_E_EQ_R | ID_E_EQ_S);
                        if (error)
-                               goto report_error;
+                               goto report_error_stopped;
                }
 
                /* Set signal masks/defaults */
@@ -1981,7 +1991,7 @@
                            &spawn_data->sed_attrs->sa_sigmask, NULL);
                        mutex_exit(l->l_proc->p_lock);
                        if (error)
-                               goto report_error;
+                               goto report_error_stopped;
                }
 
                if (spawn_data->sed_attrs->sa_flags & POSIX_SPAWN_SETSIGDEF) {
@@ -1992,7 +2002,10 @@
                                            0);
                        }
                }
+               mutex_enter(proc_lock);
                l->l_proc->p_stat = ostat;
+               l->l_proc->p_pptr->p_nstopchild--;
+               mutex_exit(proc_lock);
        }
 
        /* now do the real exec */
@@ -2019,6 +2032,11 @@
        /* NOTREACHED */
        return;
 
+ report_error_stopped:
+       mutex_enter(proc_lock);
+       l->l_proc->p_stat = ostat;
+       l->l_proc->p_pptr->p_nstopchild--;
+       mutex_exit(proc_lock);
  report_error:
        if (have_reflock) {
                /*
diff -r d546053e4f7b -r 29c6b3f219fb sys/kern/kern_exit.c
--- a/sys/kern/kern_exit.c      Sun Nov 15 20:27:34 2015 +0000
+++ b/sys/kern/kern_exit.c      Sun Nov 15 20:37:04 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_exit.c,v 1.236.2.3 2014/05/21 21:04:31 bouyer Exp $       */
+/*     $NetBSD: kern_exit.c,v 1.236.2.4 2015/11/15 20:37:04 bouyer Exp $       */
 
 /*-
  * Copyright (c) 1998, 1999, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.236.2.3 2014/05/21 21:04:31 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.236.2.4 2015/11/15 20:37:04 bouyer Exp $");
 
 #include "opt_ktrace.h"
 #include "opt_perfctrs.h"
@@ -240,8 +240,15 @@
        if (__predict_false(p->p_sflag & PS_STOPEXIT)) {
                KERNEL_UNLOCK_ALL(l, &l->l_biglocks);
                sigclearall(p, &contsigmask, &kq);
+
+               if (!mutex_tryenter(proc_lock)) {
+                       mutex_exit(p->p_lock);
+                       mutex_enter(proc_lock);
+                       mutex_enter(p->p_lock);
+               }
                p->p_waited = 0;
-               membar_producer();
+               p->p_pptr->p_nstopchild++;
+               mutex_exit(proc_lock);
                p->p_stat = SSTOP;
                lwp_lock(l);
                p->p_nrlwps--;
@@ -998,7 +1005,7 @@
        if (child->p_pptr == parent)
                return;
 
-       if (child->p_stat == SZOMB ||
+       if (child->p_stat == SZOMB || child->p_stat == SDEAD ||
            (child->p_stat == SSTOP && !child->p_waited)) {
                child->p_pptr->p_nstopchild--;
                parent->p_nstopchild++;
diff -r d546053e4f7b -r 29c6b3f219fb sys/kern/kern_synch.c
--- a/sys/kern/kern_synch.c     Sun Nov 15 20:27:34 2015 +0000
+++ b/sys/kern/kern_synch.c     Sun Nov 15 20:37:04 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_synch.c,v 1.297.2.1 2012/08/19 17:36:41 riz Exp $ */
+/*     $NetBSD: kern_synch.c,v 1.297.2.2 2015/11/15 20:37:04 bouyer Exp $      */
 
 /*-
  * Copyright (c) 1999, 2000, 2004, 2006, 2007, 2008, 2009
@@ -69,7 +69,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.297.2.1 2012/08/19 17:36:41 riz Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.297.2.2 2015/11/15 20:37:04 bouyer Exp $");
 
 #include "opt_kstack.h"
 #include "opt_perfctrs.h"
@@ -1010,7 +1010,13 @@
                        continue;
                }
 
-               p->p_stat = SSTOP;
+               if (p->p_stat != SSTOP) {
+                       if (p->p_stat != SZOMB && p->p_stat != SDEAD) {
+                               p->p_pptr->p_nstopchild++;
+                               p->p_waited = 0;
+                       }
+                       p->p_stat = SSTOP;
+               }
 
                LIST_FOREACH(l, &p->p_lwps, l_sibling) {
                        if (l == curlwp)



Home | Main Index | Thread Index | Old Index