Source-Changes-HG archive

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

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



details:   https://anonhg.NetBSD.org/src/rev/e74560e81f14
branches:  netbsd-7
changeset: 799637:e74560e81f14
user:      snj <snj%NetBSD.org@localhost>
date:      Thu Nov 05 09:04:55 2015 +0000

description:
Pull up following revision(s) (requested by pgoyette in ticket #996):
        sys/kern/kern_exec.c: revisions 1.419, 1.420
        sys/kern/kern_exit.c: revisions 1.246, 1.247
        sys/kern/kern_synch.c: revision 1.309
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
--
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
--
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
--
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
--
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

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 58a78e1cda93 -r e74560e81f14 sys/kern/kern_exec.c
--- a/sys/kern/kern_exec.c      Thu Nov 05 05:27:45 2015 +0000
+++ b/sys/kern/kern_exec.c      Thu Nov 05 09:04:55 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_exec.c,v 1.408.2.3 2015/04/14 05:12:17 snj Exp $  */
+/*     $NetBSD: kern_exec.c,v 1.408.2.4 2015/11/05 09:04:55 snj 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.408.2.3 2015/04/14 05:12:17 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.408.2.4 2015/11/05 09:04:55 snj Exp $");
 
 #include "opt_exec.h"
 #include "opt_execfmt.h"
@@ -1260,7 +1260,7 @@
 
                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);
@@ -1961,6 +1961,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;
@@ -2033,7 +2034,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;
@@ -2042,8 +2042,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) {
@@ -2056,7 +2066,7 @@
                        error = proc_enterpgrp(spawn_data->sed_parent,
                            mypid, pgrp, false);
                        if (error)
-                               goto report_error;
+                               goto report_error_stopped;
                }
 
                /* Set scheduler policy */
@@ -2070,7 +2080,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) {
@@ -2078,12 +2088,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 */
@@ -2093,7 +2103,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) {
@@ -2114,7 +2124,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 */
@@ -2141,6 +2154,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 58a78e1cda93 -r e74560e81f14 sys/kern/kern_exit.c
--- a/sys/kern/kern_exit.c      Thu Nov 05 05:27:45 2015 +0000
+++ b/sys/kern/kern_exit.c      Thu Nov 05 09:04:55 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_exit.c,v 1.244 2014/05/05 15:45:32 christos Exp $ */
+/*     $NetBSD: kern_exit.c,v 1.244.2.1 2015/11/05 09:04:55 snj 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.244 2014/05/05 15:45:32 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.244.2.1 2015/11/05 09:04:55 snj Exp $");
 
 #include "opt_ktrace.h"
 #include "opt_perfctrs.h"
@@ -227,8 +227,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--;
@@ -959,7 +966,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 58a78e1cda93 -r e74560e81f14 sys/kern/kern_synch.c
--- a/sys/kern/kern_synch.c     Thu Nov 05 05:27:45 2015 +0000
+++ b/sys/kern/kern_synch.c     Thu Nov 05 09:04:55 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_synch.c,v 1.308 2014/02/28 10:16:51 skrll Exp $   */
+/*     $NetBSD: kern_synch.c,v 1.308.4.1 2015/11/05 09:04:55 snj 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.308 2014/02/28 10:16:51 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_synch.c,v 1.308.4.1 2015/11/05 09:04:55 snj Exp $");
 
 #include "opt_kstack.h"
 #include "opt_perfctrs.h"
@@ -985,7 +985,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