Date: Tue, 24 Sep 2013 20:38:55 +0000 (UTC) From: John Baldwin <jhb@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r255862 - stable/9/sys/kern Message-ID: <201309242038.r8OKctft033611@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jhb Date: Tue Sep 24 20:38:55 2013 New Revision: 255862 URL: http://svnweb.freebsd.org/changeset/base/255862 Log: MFC 240424,244582: Improve check coverage about idle threads. Idle threads are not allowed to acquire any lock but spinlocks. Deny any attempt to do so by panicing at the locking operation when INVARIANTS is on. Then, remove the check on blocking on a turnstile. The check in sleepqueues is left because they are not allowed to use tsleep() either which could happen still. On entering KDB backends, the hijacked thread to run interrupt context can still be idlethread. At that point, without the panic condition, it can still happen that idlethread then will try to acquire some locks to carry on some operations. Skip the idlethread check on block/sleep lock operations when KDB is active. Modified: stable/9/sys/kern/kern_lock.c stable/9/sys/kern/kern_mutex.c stable/9/sys/kern/kern_rmlock.c stable/9/sys/kern/kern_rwlock.c stable/9/sys/kern/kern_sx.c Directory Properties: stable/9/sys/ (props changed) Modified: stable/9/sys/kern/kern_lock.c ============================================================================== --- stable/9/sys/kern/kern_lock.c Tue Sep 24 20:14:59 2013 (r255861) +++ stable/9/sys/kern/kern_lock.c Tue Sep 24 20:38:55 2013 (r255862) @@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> +#include <sys/kdb.h> #include <sys/ktr.h> #include <sys/lock.h> #include <sys/lock_profile.h> @@ -472,6 +473,9 @@ __lockmgr_args(struct lock *lk, u_int fl KASSERT((flags & LK_INTERLOCK) == 0 || ilk != NULL, ("%s: LK_INTERLOCK passed without valid interlock @ %s:%d", __func__, file, line)); + KASSERT(kdb_active != 0 || !TD_IS_IDLETHREAD(curthread), + ("%s: idle thread %p on lockmgr %s @ %s:%d", __func__, curthread, + lk->lock_object.lo_name, file, line)); class = (flags & LK_INTERLOCK) ? LOCK_CLASS(ilk) : NULL; if (panicstr != NULL) { Modified: stable/9/sys/kern/kern_mutex.c ============================================================================== --- stable/9/sys/kern/kern_mutex.c Tue Sep 24 20:14:59 2013 (r255861) +++ stable/9/sys/kern/kern_mutex.c Tue Sep 24 20:38:55 2013 (r255862) @@ -199,6 +199,9 @@ _mtx_lock_flags(struct mtx *m, int opts, if (SCHEDULER_STOPPED()) return; + KASSERT(kdb_active != 0 || !TD_IS_IDLETHREAD(curthread), + ("mtx_lock() by idle thread %p on sleep mutex %s @ %s:%d", + curthread, m->lock_object.lo_name, file, line)); KASSERT(m->mtx_lock != MTX_DESTROYED, ("mtx_lock() of destroyed mutex @ %s:%d", file, line)); KASSERT(LOCK_CLASS(&m->lock_object) == &lock_class_mtx_sleep, @@ -295,6 +298,9 @@ _mtx_trylock(struct mtx *m, int opts, co if (SCHEDULER_STOPPED()) return (1); + KASSERT(kdb_active != 0 || !TD_IS_IDLETHREAD(curthread), + ("mtx_trylock() by idle thread %p on sleep mutex %s @ %s:%d", + curthread, m->lock_object.lo_name, file, line)); KASSERT(m->mtx_lock != MTX_DESTROYED, ("mtx_trylock() of destroyed mutex @ %s:%d", file, line)); KASSERT(LOCK_CLASS(&m->lock_object) == &lock_class_mtx_sleep, Modified: stable/9/sys/kern/kern_rmlock.c ============================================================================== --- stable/9/sys/kern/kern_rmlock.c Tue Sep 24 20:14:59 2013 (r255861) +++ stable/9/sys/kern/kern_rmlock.c Tue Sep 24 20:38:55 2013 (r255862) @@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$"); #include <sys/systm.h> #include <sys/kernel.h> +#include <sys/kdb.h> #include <sys/ktr.h> #include <sys/lock.h> #include <sys/mutex.h> @@ -494,6 +495,9 @@ void _rm_wlock_debug(struct rmlock *rm, if (SCHEDULER_STOPPED()) return; + KASSERT(kdb_active != 0 || !TD_IS_IDLETHREAD(curthread), + ("rm_wlock() by idle thread %p on rmlock %s @ %s:%d", + curthread, rm->lock_object.lo_name, file, line)); WITNESS_CHECKORDER(&rm->lock_object, LOP_NEWORDER | LOP_EXCLUSIVE, file, line, NULL); @@ -536,6 +540,9 @@ _rm_rlock_debug(struct rmlock *rm, struc if (SCHEDULER_STOPPED()) return (1); + KASSERT(kdb_active != 0 || !TD_IS_IDLETHREAD(curthread), + ("rm_rlock() by idle thread %p on rmlock %s @ %s:%d", + curthread, rm->lock_object.lo_name, file, line)); if (!trylock && (rm->lock_object.lo_flags & RM_SLEEPABLE)) WITNESS_CHECKORDER(&rm->rm_lock_sx.lock_object, LOP_NEWORDER, file, line, NULL); Modified: stable/9/sys/kern/kern_rwlock.c ============================================================================== --- stable/9/sys/kern/kern_rwlock.c Tue Sep 24 20:14:59 2013 (r255861) +++ stable/9/sys/kern/kern_rwlock.c Tue Sep 24 20:38:55 2013 (r255862) @@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$"); #include "opt_no_adaptive_rwlocks.h" #include <sys/param.h> +#include <sys/kdb.h> #include <sys/ktr.h> #include <sys/kernel.h> #include <sys/lock.h> @@ -237,6 +238,9 @@ _rw_wlock(struct rwlock *rw, const char if (SCHEDULER_STOPPED()) return; + KASSERT(kdb_active != 0 || !TD_IS_IDLETHREAD(curthread), + ("rw_wlock() by idle thread %p on rwlock %s @ %s:%d", + curthread, rw->lock_object.lo_name, file, line)); KASSERT(rw->rw_lock != RW_DESTROYED, ("rw_wlock() of destroyed rwlock @ %s:%d", file, line)); WITNESS_CHECKORDER(&rw->lock_object, LOP_NEWORDER | LOP_EXCLUSIVE, file, @@ -255,6 +259,9 @@ _rw_try_wlock(struct rwlock *rw, const c if (SCHEDULER_STOPPED()) return (1); + KASSERT(kdb_active != 0 || !TD_IS_IDLETHREAD(curthread), + ("rw_try_wlock() by idle thread %p on rwlock %s @ %s:%d", + curthread, rw->lock_object.lo_name, file, line)); KASSERT(rw->rw_lock != RW_DESTROYED, ("rw_try_wlock() of destroyed rwlock @ %s:%d", file, line)); @@ -327,6 +334,9 @@ _rw_rlock(struct rwlock *rw, const char if (SCHEDULER_STOPPED()) return; + KASSERT(kdb_active != 0 || !TD_IS_IDLETHREAD(curthread), + ("rw_rlock() by idle thread %p on rwlock %s @ %s:%d", + curthread, rw->lock_object.lo_name, file, line)); KASSERT(rw->rw_lock != RW_DESTROYED, ("rw_rlock() of destroyed rwlock @ %s:%d", file, line)); KASSERT(rw_wowner(rw) != curthread, @@ -515,6 +525,10 @@ _rw_try_rlock(struct rwlock *rw, const c if (SCHEDULER_STOPPED()) return (1); + KASSERT(kdb_active != 0 || !TD_IS_IDLETHREAD(curthread), + ("rw_try_rlock() by idle thread %p on rwlock %s @ %s:%d", + curthread, rw->lock_object.lo_name, file, line)); + for (;;) { x = rw->rw_lock; KASSERT(rw->rw_lock != RW_DESTROYED, Modified: stable/9/sys/kern/kern_sx.c ============================================================================== --- stable/9/sys/kern/kern_sx.c Tue Sep 24 20:14:59 2013 (r255861) +++ stable/9/sys/kern/kern_sx.c Tue Sep 24 20:38:55 2013 (r255862) @@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/systm.h> +#include <sys/kdb.h> #include <sys/ktr.h> #include <sys/lock.h> #include <sys/mutex.h> @@ -246,6 +247,9 @@ _sx_slock(struct sx *sx, int opts, const if (SCHEDULER_STOPPED()) return (0); + KASSERT(kdb_active != 0 || !TD_IS_IDLETHREAD(curthread), + ("sx_slock() by idle thread %p on sx %s @ %s:%d", + curthread, sx->lock_object.lo_name, file, line)); KASSERT(sx->sx_lock != SX_LOCK_DESTROYED, ("sx_slock() of destroyed sx @ %s:%d", file, line)); WITNESS_CHECKORDER(&sx->lock_object, LOP_NEWORDER, file, line, NULL); @@ -267,6 +271,10 @@ _sx_try_slock(struct sx *sx, const char if (SCHEDULER_STOPPED()) return (1); + KASSERT(kdb_active != 0 || !TD_IS_IDLETHREAD(curthread), + ("sx_try_slock() by idle thread %p on sx %s @ %s:%d", + curthread, sx->lock_object.lo_name, file, line)); + for (;;) { x = sx->sx_lock; KASSERT(x != SX_LOCK_DESTROYED, @@ -292,6 +300,9 @@ _sx_xlock(struct sx *sx, int opts, const if (SCHEDULER_STOPPED()) return (0); + KASSERT(kdb_active != 0 || !TD_IS_IDLETHREAD(curthread), + ("sx_xlock() by idle thread %p on sx %s @ %s:%d", + curthread, sx->lock_object.lo_name, file, line)); KASSERT(sx->sx_lock != SX_LOCK_DESTROYED, ("sx_xlock() of destroyed sx @ %s:%d", file, line)); WITNESS_CHECKORDER(&sx->lock_object, LOP_NEWORDER | LOP_EXCLUSIVE, file, @@ -315,6 +326,9 @@ _sx_try_xlock(struct sx *sx, const char if (SCHEDULER_STOPPED()) return (1); + KASSERT(kdb_active != 0 || !TD_IS_IDLETHREAD(curthread), + ("sx_try_xlock() by idle thread %p on sx %s @ %s:%d", + curthread, sx->lock_object.lo_name, file, line)); KASSERT(sx->sx_lock != SX_LOCK_DESTROYED, ("sx_try_xlock() of destroyed sx @ %s:%d", file, line));
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201309242038.r8OKctft033611>