Index: sys/kern/kern_rmlock.c =================================================================== --- sys/kern/kern_rmlock.c +++ sys/kern/kern_rmlock.c @@ -652,8 +652,8 @@ KASSERT(!rm_wowned(rm), ("rm_rlock: wlock already held for %s @ %s:%d", rm->lock_object.lo_name, file, line)); - WITNESS_CHECKORDER(&rm->lock_object, LOP_NEWORDER, file, line, - NULL); + WITNESS_CHECKORDER(&rm->lock_object, + LOP_NEWORDER | LOP_NOSLEEP, file, line, NULL); } if (_rm_rlock(rm, tracker, trylock)) { @@ -663,7 +663,7 @@ else LOCK_LOG_LOCK("RMRLOCK", &rm->lock_object, 0, 0, file, line); - WITNESS_LOCK(&rm->lock_object, 0, file, line); + WITNESS_LOCK(&rm->lock_object, LOP_NOSLEEP, file, line); TD_LOCKS_INC(curthread); return (1); } else if (trylock) Index: sys/kern/subr_witness.c =================================================================== --- sys/kern/subr_witness.c +++ sys/kern/subr_witness.c @@ -131,6 +131,7 @@ #define LI_RECURSEMASK 0x0000ffff /* Recursion depth of lock instance. */ #define LI_EXCLUSIVE 0x00010000 /* Exclusive lock instance. */ #define LI_NORELEASE 0x00020000 /* Lock not allowed to be released. */ +#define LI_SLEEPABLE 0x00040000 /* Lock may be held while sleeping. */ #ifndef WITNESS_COUNT #define WITNESS_COUNT 1536 @@ -1302,7 +1303,7 @@ * If we are locking Giant and this is a sleepable * lock, then skip it. */ - if ((lock1->li_lock->lo_flags & LO_SLEEPABLE) != 0 && + if ((lock1->li_flags & LI_SLEEPABLE) != 0 && lock == &Giant.lock_object) continue; @@ -1311,6 +1312,7 @@ * is Giant, then skip it. */ if ((lock->lo_flags & LO_SLEEPABLE) != 0 && + (flags & LOP_NOSLEEP) == 0 && lock1->li_lock == &Giant.lock_object) continue; @@ -1320,15 +1322,16 @@ * order violation to enfore a general lock order of * sleepable locks before non-sleepable locks. */ - if (((lock->lo_flags & LO_SLEEPABLE) != 0 && - (lock1->li_lock->lo_flags & LO_SLEEPABLE) == 0)) + if ((lock->lo_flags & LO_SLEEPABLE) != 0 && + (flags & LOP_NOSLEEP) == 0 && + (lock1->li_flags & LI_SLEEPABLE) == 0) goto reversal; /* * If we are locking Giant and this is a non-sleepable * lock, then treat it as a reversal. */ - if ((lock1->li_lock->lo_flags & LO_SLEEPABLE) == 0 && + if ((lock1->li_flags & LI_SLEEPABLE) == 0 && lock == &Giant.lock_object) goto reversal; @@ -1378,11 +1381,12 @@ /* * Ok, yell about it. */ - if (((lock->lo_flags & LO_SLEEPABLE) != 0 && - (lock1->li_lock->lo_flags & LO_SLEEPABLE) == 0)) + if ((lock->lo_flags & LO_SLEEPABLE) != 0 && + (flags & LOP_NOSLEEP) == 0 && + (lock1->li_flags & LI_SLEEPABLE) == 0) witness_output( "lock order reversal: (sleepable after non-sleepable)\n"); - else if ((lock1->li_lock->lo_flags & LO_SLEEPABLE) == 0 + else if ((lock1->li_flags & LI_SLEEPABLE) == 0 && lock == &Giant.lock_object) witness_output( "lock order reversal: (Giant after non-sleepable)\n"); @@ -1440,7 +1444,8 @@ */ if (flags & LOP_NEWORDER && !(plock->li_lock == &Giant.lock_object && - (lock->lo_flags & LO_SLEEPABLE) != 0)) { + (lock->lo_flags & LO_SLEEPABLE) != 0 && + (flags & LOP_NOSLEEP) == 0)) { CTR3(KTR_WITNESS, "%s: adding %s as a child of %s", __func__, w->w_name, plock->li_lock->lo_witness->w_name); itismychild(plock->li_lock->lo_witness, w); @@ -1500,10 +1505,11 @@ instance->li_lock = lock; instance->li_line = line; instance->li_file = file; + instance->li_flags = 0; if ((flags & LOP_EXCLUSIVE) != 0) - instance->li_flags = LI_EXCLUSIVE; - else - instance->li_flags = 0; + instance->li_flags |= LI_EXCLUSIVE; + if ((lock->lo_flags & LO_SLEEPABLE) != 0 && (flags & LOP_NOSLEEP) == 0) + instance->li_flags |= LI_SLEEPABLE; CTR4(KTR_WITNESS, "%s: pid %d added %s as lle[%d]", __func__, td->td_proc->p_pid, lock->lo_name, lle->ll_count - 1); } @@ -1763,7 +1769,7 @@ lock1->li_lock == &Giant.lock_object) continue; if (flags & WARN_SLEEPOK && - (lock1->li_lock->lo_flags & LO_SLEEPABLE) != 0) + (lock1->li_flags & LI_SLEEPABLE) != 0) continue; if (n == 0) { va_start(ap, fmt); Index: sys/sys/lock.h =================================================================== --- sys/sys/lock.h +++ sys/sys/lock.h @@ -107,6 +107,7 @@ #define LOP_TRYLOCK 0x00000004 /* Don't check lock order. */ #define LOP_EXCLUSIVE 0x00000008 /* Exclusive lock. */ #define LOP_DUPOK 0x00000010 /* Don't check for duplicate acquires */ +#define LOP_NOSLEEP 0x00000020 /* Non-sleepable despite LO_SLEEPABLE */ /* Flags passed to witness_assert. */ #define LA_MASKASSERT 0x000000ff /* Mask for witness defined asserts. */