From: Matthew Dillon Date: Thu, 3 Nov 2011 17:49:16 +0000 (-0700) Subject: kernel - Hold required token when accessing p_flags, adjust kmem access X-Git-Tag: v3.0.0~745 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/616516c8288329f72f40dd9143c9ea79b23e65fd kernel - Hold required token when accessing p_flags, adjust kmem access * Numerous adjustments to p->p_flag were not being done with p->p_token held. In particular uiomove(). * Replace P_DEADLKTREAT with LWP_DEADLKTREAT in several places where it had not been previously converted. * Allow DMAP access in is_globaldata_space() for x86-64 --- diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c index 47a0e635b3..697b327ea9 100644 --- a/sys/kern/kern_clock.c +++ b/sys/kern/kern_clock.c @@ -937,6 +937,8 @@ startprofclock(struct proc *p) /* * Stop profiling on a process. + * + * caller must hold p->p_token */ void stopprofclock(struct proc *p) diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 93aebb8ea9..796f15ec49 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -323,7 +323,11 @@ kern_fcntl(int fd, int cmd, union fcntl_dat *dat, struct ucred *cred) error = EBADF; break; } - p->p_leader->p_flag |= P_ADVLOCK; + if ((p->p_leader->p_flag & P_ADVLOCK) == 0) { + lwkt_gettoken(&p->p_leader->p_token); + p->p_leader->p_flag |= P_ADVLOCK; + lwkt_reltoken(&p->p_leader->p_token); + } error = VOP_ADVLOCK(vp, (caddr_t)p->p_leader, F_SETLK, &dat->fc_flock, flg); break; @@ -332,7 +336,11 @@ kern_fcntl(int fd, int cmd, union fcntl_dat *dat, struct ucred *cred) error = EBADF; break; } - p->p_leader->p_flag |= P_ADVLOCK; + if ((p->p_leader->p_flag & P_ADVLOCK) == 0) { + lwkt_gettoken(&p->p_leader->p_token); + p->p_leader->p_flag |= P_ADVLOCK; + lwkt_reltoken(&p->p_leader->p_token); + } error = VOP_ADVLOCK(vp, (caddr_t)p->p_leader, F_SETLK, &dat->fc_flock, flg); break; diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index 053711f9db..a684ad68ce 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -193,6 +193,8 @@ sys_extexit(struct extexit_args *uap) * * If forexec is non-zero the current thread and process flags are * cleaned up so they can be reused. + * + * Caller must hold curproc->p_token */ int killalllwps(int forexec) diff --git a/sys/kern/kern_jail.c b/sys/kern/kern_jail.c index 8043eba3b0..4842b6079a 100644 --- a/sys/kern/kern_jail.c +++ b/sys/kern/kern_jail.c @@ -117,9 +117,11 @@ kern_jail_attach(int jid) return(error); prison_hold(pr); + lwkt_gettoken(&p->p_token); cratom(&p->p_ucred); p->p_ucred->cr_prison = pr; p->p_flag |= P_JAILED; + lwkt_reltoken(&p->p_token); return(0); } diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index a2efb1ecc6..2ec3fcb4d1 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -291,10 +291,12 @@ enterpgrp(struct proc *p, pid_t pgid, int mksess) sess->s_ttyp = NULL; bcopy(p->p_session->s_login, sess->s_login, sizeof(sess->s_login)); - p->p_flag &= ~P_CONTROLT; pgrp->pg_session = sess; KASSERT(p == curproc, ("enterpgrp: mksession and p != curproc")); + lwkt_gettoken(&p->p_token); + p->p_flag &= ~P_CONTROLT; + lwkt_reltoken(&p->p_token); } else { pgrp->pg_session = p->p_session; sess_hold(pgrp->pg_session); diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c index a48ca4fd77..b77b0cc228 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -1210,9 +1210,11 @@ setsugid(void) struct proc *p = curproc; KKASSERT(p != NULL); + lwkt_gettoken(&p->p_token); p->p_flag |= P_SUGID; if (!(p->p_pfsflags & PF_ISUGID)) p->p_stops = 0; + lwkt_reltoken(&p->p_token); } /* diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index 3ff4400b1d..9fc1c3c5ff 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -2102,7 +2102,9 @@ postsig(int sig) if (SIGISMEMBER(ps->ps_sigmailbox, sig)) { int sig_copy = sig; copyout(&sig_copy, (void *)action, sizeof(int)); + lwkt_gettoken(&curproc->p_token); curproc->p_flag |= P_MAILBOX; + lwkt_reltoken(&curproc->p_token); crit_exit(); goto done; } diff --git a/sys/kern/kern_subr.c b/sys/kern/kern_subr.c index 666e13faf1..044fb59b3e 100644 --- a/sys/kern/kern_subr.c +++ b/sys/kern/kern_subr.c @@ -77,6 +77,7 @@ SYSCTL_INT(_kern, KERN_IOV_MAX, iov_max, CTLFLAG_RD, NULL, UIO_MAXIOV, int uiomove(caddr_t cp, size_t n, struct uio *uio) { + thread_t td = curthread; struct iovec *iov; size_t cnt; int error = 0; @@ -84,13 +85,13 @@ uiomove(caddr_t cp, size_t n, struct uio *uio) KASSERT(uio->uio_rw == UIO_READ || uio->uio_rw == UIO_WRITE, ("uiomove: mode")); - KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread, + KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == td, ("uiomove proc")); - if (curproc) { - save = curproc->p_flag & P_DEADLKTREAT; - curproc->p_flag |= P_DEADLKTREAT; - } + crit_enter(); + save = td->td_flags & TDF_DEADLKTREAT; + td->td_flags |= TDF_DEADLKTREAT; + crit_exit(); while (n > 0 && uio->uio_resid) { iov = uio->uio_iov; @@ -131,8 +132,9 @@ uiomove(caddr_t cp, size_t n, struct uio *uio) cp += cnt; n -= cnt; } - if (curproc) - curproc->p_flag = (curproc->p_flag & ~P_DEADLKTREAT) | save; + crit_enter(); + td->td_flags = (td->td_flags & ~TDF_DEADLKTREAT) | save; + crit_exit(); return (error); } diff --git a/sys/kern/subr_prof.c b/sys/kern/subr_prof.c index f1d23488bc..c625fb1122 100644 --- a/sys/kern/subr_prof.c +++ b/sys/kern/subr_prof.c @@ -298,6 +298,7 @@ sysctl_kern_prof(SYSCTL_HANDLER_ARGS) return (error); if (!req->newptr) return (0); + lwkt_gettoken(&proc0.p_token); if (state == GMON_PROF_OFF) { gp->state = state; stopprofclock(&proc0); @@ -315,9 +316,11 @@ sysctl_kern_prof(SYSCTL_HANDLER_ARGS) startguprof(gp); gp->state = state; #endif - } else if (state != gp->state) - return (EINVAL); - return (0); + } else if (state != gp->state) { + error = EINVAL; + } + lwkt_reltoken(&proc0.p_token); + return (error); case GPROF_COUNT: return (sysctl_handle_opaque(oidp, gp->kcount, gp->kcountsize, req)); diff --git a/sys/kern/tty.c b/sys/kern/tty.c index c0e41d3733..1d67899c13 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -859,6 +859,7 @@ ttioctl(struct tty *tp, u_long cmd, void *data, int flag) KKASSERT(p); lwkt_gettoken(&tty_token); lwkt_gettoken(&proc_token); + lwkt_gettoken(&p->p_token); /* If the ioctl involves modification, hang if in the background. */ switch (cmd) { @@ -898,6 +899,7 @@ ttioctl(struct tty *tp, u_long cmd, void *data, int flag) !SIGISMEMBER(p->p_sigignore, SIGTTOU) && !SIGISMEMBER(lp->lwp_sigmask, SIGTTOU)) { if (p->p_pgrp->pg_jobc == 0) { + lwkt_reltoken(&p->p_token); lwkt_reltoken(&proc_token); lwkt_reltoken(&tty_token); return (EIO); @@ -906,6 +908,7 @@ ttioctl(struct tty *tp, u_long cmd, void *data, int flag) error = ttysleep(tp, &lbolt, PCATCH, "ttybg1", 0); if (error) { + lwkt_reltoken(&p->p_token); lwkt_reltoken(&proc_token); lwkt_reltoken(&tty_token); return (error); @@ -935,6 +938,7 @@ ttioctl(struct tty *tp, u_long cmd, void *data, int flag) * controlling tty */ if (tp->t_session != NULL && !isctty(p, tp)) { + lwkt_reltoken(&p->p_token); lwkt_reltoken(&proc_token); lwkt_reltoken(&tty_token); return (ENOTTY); @@ -942,6 +946,7 @@ ttioctl(struct tty *tp, u_long cmd, void *data, int flag) error = fsetown(*(int *)data, &tp->t_sigio); if (error) { + lwkt_reltoken(&p->p_token); lwkt_reltoken(&proc_token); lwkt_reltoken(&tty_token); return (error); @@ -949,6 +954,7 @@ ttioctl(struct tty *tp, u_long cmd, void *data, int flag) break; case FIOGETOWN: if (tp->t_session != NULL && !isctty(p, tp)) { + lwkt_reltoken(&p->p_token); lwkt_reltoken(&proc_token); lwkt_reltoken(&tty_token); return (ENOTTY); @@ -975,12 +981,14 @@ ttioctl(struct tty *tp, u_long cmd, void *data, int flag) if (*(int *)data) { if (constty && constty != tp && ISSET(constty->t_state, TS_CONNECTED)) { + lwkt_reltoken(&p->p_token); lwkt_reltoken(&proc_token); lwkt_reltoken(&tty_token); return (EBUSY); } #ifndef UCONSOLE if ((error = priv_check(td, PRIV_ROOT)) != 0) { + lwkt_reltoken(&p->p_token); lwkt_reltoken(&proc_token); lwkt_reltoken(&tty_token); return (error); @@ -993,6 +1001,7 @@ ttioctl(struct tty *tp, u_long cmd, void *data, int flag) case TIOCDRAIN: /* wait till output drained */ error = ttywait(tp); if (error) { + lwkt_reltoken(&p->p_token); lwkt_reltoken(&proc_token); lwkt_reltoken(&tty_token); return (error); @@ -1012,6 +1021,7 @@ ttioctl(struct tty *tp, u_long cmd, void *data, int flag) break; case TIOCGPGRP: /* get pgrp of tty */ if (!isctty(p, tp)) { + lwkt_reltoken(&p->p_token); lwkt_reltoken(&proc_token); lwkt_reltoken(&tty_token); return (ENOTTY); @@ -1020,6 +1030,7 @@ ttioctl(struct tty *tp, u_long cmd, void *data, int flag) break; case TIOCGSID: /* get sid of tty */ if (!isctty(p, tp)) { + lwkt_reltoken(&p->p_token); lwkt_reltoken(&proc_token); lwkt_reltoken(&tty_token); return (ENOTTY); @@ -1051,6 +1062,7 @@ ttioctl(struct tty *tp, u_long cmd, void *data, int flag) if (t->c_ispeed == 0) t->c_ispeed = tp->t_ospeed; if (t->c_ispeed == 0) { + lwkt_reltoken(&p->p_token); lwkt_reltoken(&proc_token); lwkt_reltoken(&tty_token); return (EINVAL); @@ -1060,6 +1072,7 @@ ttioctl(struct tty *tp, u_long cmd, void *data, int flag) error = ttywait(tp); if (error) { crit_exit(); + lwkt_reltoken(&p->p_token); lwkt_reltoken(&proc_token); lwkt_reltoken(&tty_token); return (error); @@ -1073,6 +1086,7 @@ ttioctl(struct tty *tp, u_long cmd, void *data, int flag) */ if (tp->t_param && (error = (*tp->t_param)(tp, t))) { crit_exit(); + lwkt_reltoken(&p->p_token); lwkt_reltoken(&proc_token); lwkt_reltoken(&tty_token); return (error); @@ -1150,6 +1164,7 @@ ttioctl(struct tty *tp, u_long cmd, void *data, int flag) cdev_t device = tp->t_dev; if ((u_int)t >= nlinesw) { + lwkt_reltoken(&p->p_token); lwkt_reltoken(&proc_token); lwkt_reltoken(&tty_token); return (ENXIO); @@ -1161,6 +1176,7 @@ ttioctl(struct tty *tp, u_long cmd, void *data, int flag) if (error) { (void)(*linesw[tp->t_line].l_open)(device, tp); crit_exit(); + lwkt_reltoken(&p->p_token); lwkt_reltoken(&proc_token); lwkt_reltoken(&tty_token); return (error); @@ -1182,11 +1198,13 @@ ttioctl(struct tty *tp, u_long cmd, void *data, int flag) break; case TIOCSTI: /* simulate terminal input */ if ((flag & FREAD) == 0 && priv_check(td, PRIV_ROOT)) { + lwkt_reltoken(&p->p_token); lwkt_reltoken(&proc_token); lwkt_reltoken(&tty_token); return (EPERM); } if (!isctty(p, tp) && priv_check(td, PRIV_ROOT)) { + lwkt_reltoken(&p->p_token); lwkt_reltoken(&proc_token); lwkt_reltoken(&tty_token); return (EACCES); @@ -1208,6 +1226,7 @@ ttioctl(struct tty *tp, u_long cmd, void *data, int flag) if (!SESS_LEADER(p) || ((p->p_session->s_ttyvp || tp->t_session) && (tp->t_session != p->p_session))) { + lwkt_reltoken(&p->p_token); lwkt_reltoken(&proc_token); lwkt_reltoken(&tty_token); return (EPERM); @@ -1231,11 +1250,13 @@ ttioctl(struct tty *tp, u_long cmd, void *data, int flag) pid_t pgid = *(int *)data; if (!isctty(p, tp)) { + lwkt_reltoken(&p->p_token); lwkt_reltoken(&proc_token); lwkt_reltoken(&tty_token); return (ENOTTY); } else if (pgid < 1 || pgid > PID_MAX) { + lwkt_reltoken(&p->p_token); lwkt_reltoken(&proc_token); lwkt_reltoken(&tty_token); return (EINVAL); @@ -1244,6 +1265,7 @@ ttioctl(struct tty *tp, u_long cmd, void *data, int flag) if (pgrp == NULL || pgrp->pg_session != p->p_session) { if (pgrp) pgrel(pgrp); + lwkt_reltoken(&p->p_token); lwkt_reltoken(&proc_token); lwkt_reltoken(&tty_token); return (EPERM); @@ -1272,6 +1294,7 @@ ttioctl(struct tty *tp, u_long cmd, void *data, int flag) case TIOCSDRAINWAIT: error = priv_check(td, PRIV_ROOT); if (error) { + lwkt_reltoken(&p->p_token); lwkt_reltoken(&proc_token); lwkt_reltoken(&tty_token); return (error); @@ -1285,15 +1308,18 @@ ttioctl(struct tty *tp, u_long cmd, void *data, int flag) break; default: #if defined(COMPAT_43) || defined(COMPAT_SUNOS) + lwkt_reltoken(&p->p_token); lwkt_reltoken(&proc_token); lwkt_reltoken(&tty_token); return (ttcompat(tp, cmd, data, flag)); #else + lwkt_reltoken(&p->p_token); lwkt_reltoken(&proc_token); lwkt_reltoken(&tty_token); return (ENOIOCTL); #endif } + lwkt_reltoken(&p->p_token); lwkt_reltoken(&proc_token); lwkt_reltoken(&tty_token); return (0); diff --git a/sys/kern/tty_tty.c b/sys/kern/tty_tty.c index a0cab40037..e427db78d6 100644 --- a/sys/kern/tty_tty.c +++ b/sys/kern/tty_tty.c @@ -219,10 +219,12 @@ cttyioctl(struct dev_ioctl_args *ap) struct proc *p = curproc; KKASSERT(p); + lwkt_gettoken(&p->p_token); lwkt_gettoken(&proc_token); ttyvp = cttyvp(p); if (ttyvp == NULL) { lwkt_reltoken(&proc_token); + lwkt_gettoken(&p->p_token); return (EIO); } /* @@ -231,19 +233,23 @@ cttyioctl(struct dev_ioctl_args *ap) */ if (ap->a_cmd == TIOCSCTTY) { lwkt_reltoken(&proc_token); + lwkt_gettoken(&p->p_token); return EINVAL; } if (ap->a_cmd == TIOCNOTTY) { if (!SESS_LEADER(p)) { p->p_flag &= ~P_CONTROLT; lwkt_reltoken(&proc_token); + lwkt_gettoken(&p->p_token); return (0); } else { lwkt_reltoken(&proc_token); + lwkt_gettoken(&p->p_token); return (EINVAL); } } lwkt_reltoken(&proc_token); + lwkt_gettoken(&p->p_token); return (VOP_IOCTL(ttyvp, ap->a_cmd, ap->a_data, ap->a_fflag, ap->a_cred, ap->a_sysmsg)); diff --git a/sys/kern/usched_dummy.c b/sys/kern/usched_dummy.c index 7f0cc20892..1cecb235fa 100644 --- a/sys/kern/usched_dummy.c +++ b/sys/kern/usched_dummy.c @@ -259,7 +259,7 @@ dummy_select_curproc(globaldata_t gd) * the current process on the userland scheduler's run queue prior * to calling dummy_select_curproc(). * - * The caller may set P_PASSIVE_ACQ in p_flag to indicate that we should + * The caller may set LWP_PASSIVE_ACQ in lwp_flag to indicate that we should * attempt to leave the thread on the current cpu. * * MPSAFE diff --git a/sys/platform/pc32/i386/machdep.c b/sys/platform/pc32/i386/machdep.c index 958af52633..51ac305c34 100644 --- a/sys/platform/pc32/i386/machdep.c +++ b/sys/platform/pc32/i386/machdep.c @@ -703,8 +703,11 @@ sys_sigreturn(struct sigreturn_args *uap) * Merge saved signal mailbox pending flag to maintain interlock * semantics against system calls. */ - if (ucp->uc_mcontext.mc_xflags & PGEX_MAILBOX) + if (ucp->uc_mcontext.mc_xflags & PGEX_MAILBOX) { + lwkt_gettoken(&p->p_token); p->p_flag |= P_MAILBOX; + lwkt_reltoken(&p->p_token); + } if (ucp->uc_mcontext.mc_onstack & 1) lp->lwp_sigstk.ss_flags |= SS_ONSTACK; diff --git a/sys/platform/pc32/i386/trap.c b/sys/platform/pc32/i386/trap.c index b2c3b8f052..2b4b900fe5 100644 --- a/sys/platform/pc32/i386/trap.c +++ b/sys/platform/pc32/i386/trap.c @@ -300,6 +300,7 @@ recheck: * aware of our situation, we do not have to wake it up. */ if (p->p_flag & P_SWAPPEDOUT) { + lwkt_gettoken(&p->p_token); get_mplock(); p->p_flag |= P_SWAPWAIT; swapin_request(); @@ -307,6 +308,7 @@ recheck: tsleep(p, PCATCH, "SWOUT", 0); p->p_flag &= ~P_SWAPWAIT; rel_mplock(); + lwkt_reltoken(&p->p_token); goto recheck; } @@ -1454,9 +1456,9 @@ generic_lwp_return(struct lwp *lp, struct trapframe *frame) if (KTRPOINT(lp->lwp_thread, KTR_SYSRET)) ktrsysret(lp, SYS_fork, 0, 0); #endif - p->p_flag |= P_PASSIVE_ACQ; + lp->lwp_flag |= LWP_PASSIVE_ACQ; userexit(lp); - p->p_flag &= ~P_PASSIVE_ACQ; + lp->lwp_flag &= ~LWP_PASSIVE_ACQ; } /* diff --git a/sys/platform/pc64/x86_64/machdep.c b/sys/platform/pc64/x86_64/machdep.c index 39361c2242..ab3930168d 100644 --- a/sys/platform/pc64/x86_64/machdep.c +++ b/sys/platform/pc64/x86_64/machdep.c @@ -724,8 +724,11 @@ sys_sigreturn(struct sigreturn_args *uap) * Merge saved signal mailbox pending flag to maintain interlock * semantics against system calls. */ - if (ucp->uc_mcontext.mc_xflags & PGEX_MAILBOX) + if (ucp->uc_mcontext.mc_xflags & PGEX_MAILBOX) { + lwkt_gettoken(&p->p_token); p->p_flag |= P_MAILBOX; + lwkt_reltoken(&p->p_token); + } if (ucp->uc_mcontext.mc_onstack & 1) lp->lwp_sigstk.ss_flags |= SS_ONSTACK; @@ -1990,6 +1993,8 @@ is_globaldata_space(vm_offset_t saddr, vm_offset_t eaddr) eaddr <= (vm_offset_t)&CPU_prvspace[MAXCPU]) { return (TRUE); } + if (saddr >= DMAP_MIN_ADDRESS && eaddr <= DMAP_MAX_ADDRESS) + return (TRUE); return (FALSE); } diff --git a/sys/platform/pc64/x86_64/trap.c b/sys/platform/pc64/x86_64/trap.c index 863005d7f0..795fbfcfb9 100644 --- a/sys/platform/pc64/x86_64/trap.c +++ b/sys/platform/pc64/x86_64/trap.c @@ -277,6 +277,7 @@ recheck: * aware of our situation, we do not have to wake it up. */ if (p->p_flag & P_SWAPPEDOUT) { + lwkt_gettoken(&p->p_token); get_mplock(); p->p_flag |= P_SWAPWAIT; swapin_request(); @@ -284,6 +285,7 @@ recheck: tsleep(p, PCATCH, "SWOUT", 0); p->p_flag &= ~P_SWAPWAIT; rel_mplock(); + lwkt_reltoken(&p->p_token); goto recheck; } @@ -1352,9 +1354,9 @@ generic_lwp_return(struct lwp *lp, struct trapframe *frame) if (KTRPOINT(lp->lwp_thread, KTR_SYSRET)) ktrsysret(lp, SYS_fork, 0, 0); #endif - p->p_flag |= P_PASSIVE_ACQ; + lp->lwp_flag |= LWP_PASSIVE_ACQ; userexit(lp); - p->p_flag &= ~P_PASSIVE_ACQ; + lp->lwp_flag &= ~LWP_PASSIVE_ACQ; } /* diff --git a/sys/platform/vkernel/i386/cpu_regs.c b/sys/platform/vkernel/i386/cpu_regs.c index 2dc5ba047c..de5d1434cc 100644 --- a/sys/platform/vkernel/i386/cpu_regs.c +++ b/sys/platform/vkernel/i386/cpu_regs.c @@ -506,8 +506,11 @@ sys_sigreturn(struct sigreturn_args *uap) * Merge saved signal mailbox pending flag to maintain interlock * semantics against system calls. */ - if (ucp.uc_mcontext.mc_xflags & PGEX_MAILBOX) + if (ucp.uc_mcontext.mc_xflags & PGEX_MAILBOX) { + lwkt_gettoken(&p->p_token); p->p_flag |= P_MAILBOX; + lwkt_reltoken(&p->p_token); + } if (ucp.uc_mcontext.mc_onstack & 1) lp->lwp_sigstk.ss_flags |= SS_ONSTACK; diff --git a/sys/platform/vkernel/i386/trap.c b/sys/platform/vkernel/i386/trap.c index fc025de5ed..3d36f4e442 100644 --- a/sys/platform/vkernel/i386/trap.c +++ b/sys/platform/vkernel/i386/trap.c @@ -272,6 +272,7 @@ recheck: * aware of our situation, we do not have to wake it up. */ if (p->p_flag & P_SWAPPEDOUT) { + lwkt_gettoken(&p->p_token); get_mplock(); p->p_flag |= P_SWAPWAIT; swapin_request(); @@ -279,6 +280,7 @@ recheck: tsleep(p, PCATCH, "SWOUT", 0); p->p_flag &= ~P_SWAPWAIT; rel_mplock(); + lwkt_reltoken(&p->p_token); goto recheck; } @@ -1329,9 +1331,9 @@ generic_lwp_return(struct lwp *lp, struct trapframe *frame) if (KTRPOINT(lp->lwp_thread, KTR_SYSRET)) ktrsysret(lp, SYS_fork, 0, 0); #endif - p->p_flag |= P_PASSIVE_ACQ; + lp->lwp_flag |= LWP_PASSIVE_ACQ; userexit(lp); - p->p_flag &= ~P_PASSIVE_ACQ; + lp->lwp_flag &= ~LWP_PASSIVE_ACQ; } /* diff --git a/sys/platform/vkernel64/x86_64/cpu_regs.c b/sys/platform/vkernel64/x86_64/cpu_regs.c index 7ffb915749..b326e9ea55 100644 --- a/sys/platform/vkernel64/x86_64/cpu_regs.c +++ b/sys/platform/vkernel64/x86_64/cpu_regs.c @@ -511,8 +511,11 @@ sys_sigreturn(struct sigreturn_args *uap) * Merge saved signal mailbox pending flag to maintain interlock * semantics against system calls. */ - if (ucp->uc_mcontext.mc_xflags & PGEX_MAILBOX) + if (ucp->uc_mcontext.mc_xflags & PGEX_MAILBOX) { + lwkt_gettoken(&p->p_token); p->p_flag |= P_MAILBOX; + lwkt_reltoken(&p->p_token); + } if (ucp->uc_mcontext.mc_onstack & 1) lp->lwp_sigstk.ss_flags |= SS_ONSTACK; diff --git a/sys/platform/vkernel64/x86_64/trap.c b/sys/platform/vkernel64/x86_64/trap.c index ca73b68405..9398421738 100644 --- a/sys/platform/vkernel64/x86_64/trap.c +++ b/sys/platform/vkernel64/x86_64/trap.c @@ -272,6 +272,7 @@ recheck: * aware of our situation, we do not have to wake it up. */ if (p->p_flag & P_SWAPPEDOUT) { + lwkt_gettoken(&p->p_token); get_mplock(); p->p_flag |= P_SWAPWAIT; swapin_request(); @@ -279,6 +280,7 @@ recheck: tsleep(p, PCATCH, "SWOUT", 0); p->p_flag &= ~P_SWAPWAIT; rel_mplock(); + lwkt_reltoken(&p->p_token); goto recheck; } @@ -1379,9 +1381,9 @@ generic_lwp_return(struct lwp *lp, struct trapframe *frame) if (KTRPOINT(lp->lwp_thread, KTR_SYSRET)) ktrsysret(lp, SYS_fork, 0, 0); #endif - p->p_flag |= P_PASSIVE_ACQ; + lp->lwp_flag |= LWP_PASSIVE_ACQ; userexit(lp); - p->p_flag &= ~P_PASSIVE_ACQ; + lp->lwp_flag &= ~LWP_PASSIVE_ACQ; } /* diff --git a/sys/sys/proc.h b/sys/sys/proc.h index af776c097b..8ab2ec117a 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -364,13 +364,12 @@ struct proc { #define P_UNUSED07 0x100000 /* was: on a user scheduling run queue */ #define P_KTHREADP 0x200000 /* Process is really a kernel thread */ #define P_IDLESWAP 0x400000 /* Swapout was due to idleswap, not load */ -#define P_DEADLKTREAT 0x800000 /* lock aquisition - deadlock treatment */ #define P_JAILED 0x1000000 /* Process is in jail */ #define P_UNUSED0 0x2000000 /* need to restore mask before pause */ #define P_UNUSED1 0x4000000 /* have alternate signal stack */ #define P_INEXEC 0x8000000 /* Process is in execve(). */ -#define P_PASSIVE_ACQ 0x10000000 /* Passive acquire cpu (see kern_switch) */ +#define P_UNUSED1000 0x10000000 #define P_UPCALLWAIT 0x20000000 /* Wait for upcall or signal */ #define P_XCPU 0x40000000 /* SIGXCPU */ @@ -391,6 +390,7 @@ struct proc { #define LWP_ONRUNQ 0x0000020 /* on a user scheduling run queue */ #define LWP_WEXIT 0x0000040 /* working on exiting */ #define LWP_WSTOP 0x0000080 /* working on stopping */ +#define LWP_PASSIVE_ACQ 0x0000100 /* Passive acquire cpu (see kern_switch) */ #define FIRST_LWP_IN_PROC(p) RB_FIRST(lwp_rb_tree, &(p)->p_lwp_tree) #define FOREACH_LWP_IN_PROC(lp, p) \ diff --git a/sys/vm/vm_vmspace.c b/sys/vm/vm_vmspace.c index fcab966a4f..7f4c1ebc7f 100644 --- a/sys/vm/vm_vmspace.c +++ b/sys/vm/vm_vmspace.c @@ -203,7 +203,9 @@ sys_vmspace_ctl(struct vmspace_ctl_args *uap) * Signal mailbox interlock */ if (p->p_flag & P_MAILBOX) { + lwkt_gettoken(&p->p_token); p->p_flag &= ~P_MAILBOX; + lwkt_reltoken(&p->p_token); error = EINTR; goto done; }