diff options
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_fork.c | 4 | ||||
-rw-r--r-- | sys/kern/kern_mutex.c | 10 | ||||
-rw-r--r-- | sys/kern/subr_turnstile.c | 10 | ||||
-rw-r--r-- | sys/kern/subr_witness.c | 10 |
4 files changed, 28 insertions, 6 deletions
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index c6776de..2f9b3aa 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -406,6 +406,10 @@ again: if (p1->p_sflag & PS_PROFIL) startprofclock(p2); mtx_unlock_spin(&sched_lock); + /* + * We start off holding one spinlock after fork: sched_lock. + */ + p2->p_spinlocks = 1; PROC_UNLOCK(p2); MALLOC(p2->p_cred, struct pcred *, sizeof(struct pcred), M_SUBPROC, M_WAITOK); diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c index 1ca5cca..6540b56 100644 --- a/sys/kern/kern_mutex.c +++ b/sys/kern/kern_mutex.c @@ -1094,6 +1094,8 @@ witness_enter(struct mtx *m, int flags, const char *file, int line) } PCPU_SET(witness_spin_check, i | w->w_level); mtx_unlock_spin_flags(&w_mtx, MTX_QUIET); + p->p_spinlocks++; + MPASS(p->p_spinlocks > 0); w->w_file = file; w->w_line = line; m->mtx_line = line; @@ -1116,7 +1118,7 @@ witness_enter(struct mtx *m, int flags, const char *file, int line) if (cold) goto out; - if (!mtx_legal2block()) + if (p->p_spinlocks != 0) panic("blockable mtx_lock() of %s when not legal @ %s:%d", m->mtx_description, file, line); /* @@ -1263,10 +1265,12 @@ void witness_exit(struct mtx *m, int flags, const char *file, int line) { struct witness *w; + struct proc *p; if (witness_cold || m->mtx_witness == NULL || panicstr) return; w = m->mtx_witness; + p = curproc; if (flags & MTX_SPIN) { if ((m->mtx_flags & MTX_SPIN) == 0) @@ -1283,6 +1287,8 @@ witness_exit(struct mtx *m, int flags, const char *file, int line) PCPU_SET(witness_spin_check, PCPU_GET(witness_spin_check) & ~w->w_level); mtx_unlock_spin_flags(&w_mtx, MTX_QUIET); + MPASS(p->p_spinlocks > 0); + p->p_spinlocks--; return; } if ((m->mtx_flags & MTX_SPIN) != 0) @@ -1297,7 +1303,7 @@ witness_exit(struct mtx *m, int flags, const char *file, int line) return; } - if ((flags & MTX_NOSWITCH) == 0 && !mtx_legal2block() && !cold) + if ((flags & MTX_NOSWITCH) == 0 && p->p_spinlocks != 0 && !cold) panic("switchable mtx_unlock() of %s when not legal @ %s:%d", m->mtx_description, file, line); LIST_REMOVE(m, mtx_held); diff --git a/sys/kern/subr_turnstile.c b/sys/kern/subr_turnstile.c index 1ca5cca..6540b56 100644 --- a/sys/kern/subr_turnstile.c +++ b/sys/kern/subr_turnstile.c @@ -1094,6 +1094,8 @@ witness_enter(struct mtx *m, int flags, const char *file, int line) } PCPU_SET(witness_spin_check, i | w->w_level); mtx_unlock_spin_flags(&w_mtx, MTX_QUIET); + p->p_spinlocks++; + MPASS(p->p_spinlocks > 0); w->w_file = file; w->w_line = line; m->mtx_line = line; @@ -1116,7 +1118,7 @@ witness_enter(struct mtx *m, int flags, const char *file, int line) if (cold) goto out; - if (!mtx_legal2block()) + if (p->p_spinlocks != 0) panic("blockable mtx_lock() of %s when not legal @ %s:%d", m->mtx_description, file, line); /* @@ -1263,10 +1265,12 @@ void witness_exit(struct mtx *m, int flags, const char *file, int line) { struct witness *w; + struct proc *p; if (witness_cold || m->mtx_witness == NULL || panicstr) return; w = m->mtx_witness; + p = curproc; if (flags & MTX_SPIN) { if ((m->mtx_flags & MTX_SPIN) == 0) @@ -1283,6 +1287,8 @@ witness_exit(struct mtx *m, int flags, const char *file, int line) PCPU_SET(witness_spin_check, PCPU_GET(witness_spin_check) & ~w->w_level); mtx_unlock_spin_flags(&w_mtx, MTX_QUIET); + MPASS(p->p_spinlocks > 0); + p->p_spinlocks--; return; } if ((m->mtx_flags & MTX_SPIN) != 0) @@ -1297,7 +1303,7 @@ witness_exit(struct mtx *m, int flags, const char *file, int line) return; } - if ((flags & MTX_NOSWITCH) == 0 && !mtx_legal2block() && !cold) + if ((flags & MTX_NOSWITCH) == 0 && p->p_spinlocks != 0 && !cold) panic("switchable mtx_unlock() of %s when not legal @ %s:%d", m->mtx_description, file, line); LIST_REMOVE(m, mtx_held); diff --git a/sys/kern/subr_witness.c b/sys/kern/subr_witness.c index 1ca5cca..6540b56 100644 --- a/sys/kern/subr_witness.c +++ b/sys/kern/subr_witness.c @@ -1094,6 +1094,8 @@ witness_enter(struct mtx *m, int flags, const char *file, int line) } PCPU_SET(witness_spin_check, i | w->w_level); mtx_unlock_spin_flags(&w_mtx, MTX_QUIET); + p->p_spinlocks++; + MPASS(p->p_spinlocks > 0); w->w_file = file; w->w_line = line; m->mtx_line = line; @@ -1116,7 +1118,7 @@ witness_enter(struct mtx *m, int flags, const char *file, int line) if (cold) goto out; - if (!mtx_legal2block()) + if (p->p_spinlocks != 0) panic("blockable mtx_lock() of %s when not legal @ %s:%d", m->mtx_description, file, line); /* @@ -1263,10 +1265,12 @@ void witness_exit(struct mtx *m, int flags, const char *file, int line) { struct witness *w; + struct proc *p; if (witness_cold || m->mtx_witness == NULL || panicstr) return; w = m->mtx_witness; + p = curproc; if (flags & MTX_SPIN) { if ((m->mtx_flags & MTX_SPIN) == 0) @@ -1283,6 +1287,8 @@ witness_exit(struct mtx *m, int flags, const char *file, int line) PCPU_SET(witness_spin_check, PCPU_GET(witness_spin_check) & ~w->w_level); mtx_unlock_spin_flags(&w_mtx, MTX_QUIET); + MPASS(p->p_spinlocks > 0); + p->p_spinlocks--; return; } if ((m->mtx_flags & MTX_SPIN) != 0) @@ -1297,7 +1303,7 @@ witness_exit(struct mtx *m, int flags, const char *file, int line) return; } - if ((flags & MTX_NOSWITCH) == 0 && !mtx_legal2block() && !cold) + if ((flags & MTX_NOSWITCH) == 0 && p->p_spinlocks != 0 && !cold) panic("switchable mtx_unlock() of %s when not legal @ %s:%d", m->mtx_description, file, line); LIST_REMOVE(m, mtx_held); |