Index: sys/kern/kern_sig.c =================================================================== RCS file: /cvsroot/src/sys/kern/kern_sig.c,v retrieving revision 1.367 diff -u -r1.367 kern_sig.c --- sys/kern/kern_sig.c 8 Oct 2019 18:02:46 -0000 1.367 +++ sys/kern/kern_sig.c 12 Oct 2019 19:30:56 -0000 @@ -125,6 +125,7 @@ static int sigpost(struct lwp *, sig_t, int, int); static int sigput(sigpend_t *, struct proc *, ksiginfo_t *); static int sigunwait(struct proc *, const ksiginfo_t *); +static void sigswitch(int, int, bool); static void sigacts_poolpage_free(struct pool *, void *); static void *sigacts_poolpage_alloc(struct pool *, int); @@ -931,7 +932,7 @@ * The process is already stopping. */ if ((p->p_sflag & PS_STOPPING) != 0) { - sigswitch(0, p->p_xsig, false); + sigswitch(0, p->p_xsig, true); mutex_enter(proc_lock); mutex_enter(p->p_lock); goto repeat; /* XXX */ @@ -949,7 +950,7 @@ p->p_sigctx.ps_faked = true; p->p_sigctx.ps_lwp = ksi->ksi_lid; p->p_sigctx.ps_info = ksi->ksi_info; - sigswitch(0, signo, false); + sigswitch(0, signo, true); if (ktrpoint(KTR_PSIG)) { if (p->p_emul->e_ktrpsig) @@ -1639,7 +1640,7 @@ * The process is already stopping. */ if ((p->p_sflag & PS_STOPPING) != 0) { - sigswitch(0, p->p_xsig, false); + sigswitch(0, p->p_xsig, true); mutex_enter(proc_lock); mutex_enter(p->p_lock); goto repeat; /* XXX */ @@ -1664,7 +1665,7 @@ p->p_sigctx.ps_lwp = ksi.ksi_lid; p->p_sigctx.ps_info = ksi.ksi_info; - sigswitch(0, signo, false); + sigswitch(0, signo, true); if (code == TRAP_CHLD) { mutex_enter(proc_lock); @@ -1684,8 +1685,8 @@ /* * Stop the current process and switch away when being stopped or traced. */ -void -sigswitch(int ppmask, int signo, bool relock) +static void +sigswitch(int ppmask, int signo, bool proc_lock_held) { struct lwp *l = curlwp; struct proc *p = l->l_proc; @@ -1695,6 +1696,12 @@ KASSERT(l->l_stat == LSONPROC); KASSERT(p->p_nrlwps > 0); + if (proc_lock_held) { + KASSERT(mutex_owned(&proc_lock)); + } else { + KASSERT(!mutex_owned(&proc_lock)); + } + /* * If we are exiting, demise now. * @@ -1726,7 +1733,7 @@ * a new signal, then signal the parent. */ if ((p->p_sflag & PS_STOPPING) != 0) { - if (relock && !mutex_tryenter(proc_lock)) { + if (!proc_lock_held && !mutex_tryenter(proc_lock)) { mutex_exit(p->p_lock); mutex_enter(proc_lock); mutex_enter(p->p_lock); @@ -1746,6 +1753,7 @@ /* * Unlock and switch away. */ + KASSERT(!mutex_owned(&proc_lock)); KERNEL_UNLOCK_ALL(l, &biglocks); if (p->p_stat == SSTOP || (p->p_sflag & PS_STOPPING) != 0) { p->p_nrlwps--; @@ -1835,7 +1843,7 @@ * we awaken, check for a signal from the debugger. */ if (p->p_stat == SSTOP || (p->p_sflag & PS_STOPPING) != 0) { - sigswitch(PS_NOCLDSTOP, 0, true); + sigswitch(PS_NOCLDSTOP, 0, false); mutex_enter(p->p_lock); signo = sigchecktrace(); } else if (p->p_stat == SACTIVE) @@ -1907,7 +1915,7 @@ p->p_xsig = signo; /* Handling of signal trace */ - sigswitch(0, signo, true); + sigswitch(0, signo, false); mutex_enter(p->p_lock); /* Check for a signal from the debugger. */ @@ -1964,7 +1972,7 @@ p->p_xsig = signo; p->p_sflag &= ~PS_CONTINUED; signo = 0; - sigswitch(PS_NOCLDSTOP, p->p_xsig, true); + sigswitch(PS_NOCLDSTOP, p->p_xsig, false); mutex_enter(p->p_lock); } else if (prop & SA_IGNORE) { /* @@ -2517,7 +2525,7 @@ * The process is already stopping. */ if ((p->p_sflag & PS_STOPPING) != 0) { - sigswitch(0, p->p_xsig, true); + sigswitch(0, p->p_xsig, false); mutex_enter(p->p_lock); goto repeat; /* XXX */ } @@ -2530,7 +2538,7 @@ p->p_xsig = signo; p->p_sigctx.ps_lwp = ksi.ksi_lid; p->p_sigctx.ps_info = ksi.ksi_info; - sigswitch(0, signo, true); + sigswitch(0, signo, false); if (ktrpoint(KTR_PSIG)) { if (p->p_emul->e_ktrpsig) Index: sys/sys/signalvar.h =================================================================== RCS file: /cvsroot/src/sys/sys/signalvar.h,v retrieving revision 1.96 diff -u -r1.96 signalvar.h --- sys/sys/signalvar.h 30 Sep 2019 21:13:33 -0000 1.96 +++ sys/sys/signalvar.h 12 Oct 2019 19:30:56 -0000 @@ -153,7 +153,6 @@ int killpg1(struct lwp *, struct ksiginfo *, int, int); void proc_unstop(struct proc *p); void eventswitch(int, int, int); -void sigswitch(int, int, bool); int sigaction1(struct lwp *, int, const struct sigaction *,