diff options
author | attilio <attilio@FreeBSD.org> | 2012-09-12 22:10:53 +0000 |
---|---|---|
committer | attilio <attilio@FreeBSD.org> | 2012-09-12 22:10:53 +0000 |
commit | a634dfc320608f9955ab0350a7f78ee73064b909 (patch) | |
tree | 139a9f57a8c17d9b87a87568fbf9be1819e671f0 /sys/kern/kern_sx.c | |
parent | ac29dac65b70ec7f821f36ac07f086e6a514fe1a (diff) | |
download | FreeBSD-src-a634dfc320608f9955ab0350a7f78ee73064b909.zip FreeBSD-src-a634dfc320608f9955ab0350a7f78ee73064b909.tar.gz |
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.
Reviewed by: bde, jhb, kib
MFC after: 1 week
Diffstat (limited to 'sys/kern/kern_sx.c')
-rw-r--r-- | sys/kern/kern_sx.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/sys/kern/kern_sx.c b/sys/kern/kern_sx.c index bcd7acd..487a324 100644 --- a/sys/kern/kern_sx.c +++ b/sys/kern/kern_sx.c @@ -250,6 +250,9 @@ _sx_slock(struct sx *sx, int opts, const char *file, int line) if (SCHEDULER_STOPPED()) return (0); MPASS(curthread != NULL); + KASSERT(!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); @@ -271,6 +274,10 @@ sx_try_slock_(struct sx *sx, const char *file, int line) if (SCHEDULER_STOPPED()) return (1); + KASSERT(!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, @@ -297,6 +304,9 @@ _sx_xlock(struct sx *sx, int opts, const char *file, int line) if (SCHEDULER_STOPPED()) return (0); MPASS(curthread != NULL); + KASSERT(!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, @@ -321,6 +331,9 @@ sx_try_xlock_(struct sx *sx, const char *file, int line) return (1); MPASS(curthread != NULL); + KASSERT(!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)); |