witness: sleepable rm locks are not sleepable in read mode
There are two classes of rm lock, one "sleepable" and one not. But even a "sleepable" rm lock is only sleepable in write mode, and is non-sleepable when taken in read mode. Warn about sleepable rm locks in read mode as non-sleepable locks. Do this by defining a new lock operation flag, LOP_NOSLEEP, to indicate that a lock is non-sleepable despite what the LO_SLEEPABLE flag would indicate, and defining a new witness lock instance flag, LI_SLEEPABLE, to track the product of LO_SLEEPABLE and LOP_NOSLEEP on the lock instance. Reviewed by: markj Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D22527
This commit is contained in:
parent
588e69e2fd
commit
59fb4a95c7
@ -652,8 +652,8 @@ _rm_rlock_debug(struct rmlock *rm, struct rm_priotracker *tracker,
|
|||||||
KASSERT(!rm_wowned(rm),
|
KASSERT(!rm_wowned(rm),
|
||||||
("rm_rlock: wlock already held for %s @ %s:%d",
|
("rm_rlock: wlock already held for %s @ %s:%d",
|
||||||
rm->lock_object.lo_name, file, line));
|
rm->lock_object.lo_name, file, line));
|
||||||
WITNESS_CHECKORDER(&rm->lock_object, LOP_NEWORDER, file, line,
|
WITNESS_CHECKORDER(&rm->lock_object,
|
||||||
NULL);
|
LOP_NEWORDER | LOP_NOSLEEP, file, line, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_rm_rlock(rm, tracker, trylock)) {
|
if (_rm_rlock(rm, tracker, trylock)) {
|
||||||
@ -663,7 +663,7 @@ _rm_rlock_debug(struct rmlock *rm, struct rm_priotracker *tracker,
|
|||||||
else
|
else
|
||||||
LOCK_LOG_LOCK("RMRLOCK", &rm->lock_object, 0, 0, file,
|
LOCK_LOG_LOCK("RMRLOCK", &rm->lock_object, 0, 0, file,
|
||||||
line);
|
line);
|
||||||
WITNESS_LOCK(&rm->lock_object, 0, file, line);
|
WITNESS_LOCK(&rm->lock_object, LOP_NOSLEEP, file, line);
|
||||||
TD_LOCKS_INC(curthread);
|
TD_LOCKS_INC(curthread);
|
||||||
return (1);
|
return (1);
|
||||||
} else if (trylock)
|
} else if (trylock)
|
||||||
|
@ -131,6 +131,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#define LI_RECURSEMASK 0x0000ffff /* Recursion depth of lock instance. */
|
#define LI_RECURSEMASK 0x0000ffff /* Recursion depth of lock instance. */
|
||||||
#define LI_EXCLUSIVE 0x00010000 /* Exclusive lock instance. */
|
#define LI_EXCLUSIVE 0x00010000 /* Exclusive lock instance. */
|
||||||
#define LI_NORELEASE 0x00020000 /* Lock not allowed to be released. */
|
#define LI_NORELEASE 0x00020000 /* Lock not allowed to be released. */
|
||||||
|
#define LI_SLEEPABLE 0x00040000 /* Lock may be held while sleeping. */
|
||||||
|
|
||||||
#ifndef WITNESS_COUNT
|
#ifndef WITNESS_COUNT
|
||||||
#define WITNESS_COUNT 1536
|
#define WITNESS_COUNT 1536
|
||||||
@ -1302,7 +1303,7 @@ witness_checkorder(struct lock_object *lock, int flags, const char *file,
|
|||||||
* If we are locking Giant and this is a sleepable
|
* If we are locking Giant and this is a sleepable
|
||||||
* lock, then skip it.
|
* lock, then skip it.
|
||||||
*/
|
*/
|
||||||
if ((lock1->li_lock->lo_flags & LO_SLEEPABLE) != 0 &&
|
if ((lock1->li_flags & LI_SLEEPABLE) != 0 &&
|
||||||
lock == &Giant.lock_object)
|
lock == &Giant.lock_object)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -1311,6 +1312,7 @@ witness_checkorder(struct lock_object *lock, int flags, const char *file,
|
|||||||
* is Giant, then skip it.
|
* is Giant, then skip it.
|
||||||
*/
|
*/
|
||||||
if ((lock->lo_flags & LO_SLEEPABLE) != 0 &&
|
if ((lock->lo_flags & LO_SLEEPABLE) != 0 &&
|
||||||
|
(flags & LOP_NOSLEEP) == 0 &&
|
||||||
lock1->li_lock == &Giant.lock_object)
|
lock1->li_lock == &Giant.lock_object)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -1320,15 +1322,16 @@ witness_checkorder(struct lock_object *lock, int flags, const char *file,
|
|||||||
* order violation to enfore a general lock order of
|
* order violation to enfore a general lock order of
|
||||||
* sleepable locks before non-sleepable locks.
|
* sleepable locks before non-sleepable locks.
|
||||||
*/
|
*/
|
||||||
if (((lock->lo_flags & LO_SLEEPABLE) != 0 &&
|
if ((lock->lo_flags & LO_SLEEPABLE) != 0 &&
|
||||||
(lock1->li_lock->lo_flags & LO_SLEEPABLE) == 0))
|
(flags & LOP_NOSLEEP) == 0 &&
|
||||||
|
(lock1->li_flags & LI_SLEEPABLE) == 0)
|
||||||
goto reversal;
|
goto reversal;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we are locking Giant and this is a non-sleepable
|
* If we are locking Giant and this is a non-sleepable
|
||||||
* lock, then treat it as a reversal.
|
* 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)
|
lock == &Giant.lock_object)
|
||||||
goto reversal;
|
goto reversal;
|
||||||
|
|
||||||
@ -1378,11 +1381,12 @@ witness_checkorder(struct lock_object *lock, int flags, const char *file,
|
|||||||
/*
|
/*
|
||||||
* Ok, yell about it.
|
* Ok, yell about it.
|
||||||
*/
|
*/
|
||||||
if (((lock->lo_flags & LO_SLEEPABLE) != 0 &&
|
if ((lock->lo_flags & LO_SLEEPABLE) != 0 &&
|
||||||
(lock1->li_lock->lo_flags & LO_SLEEPABLE) == 0))
|
(flags & LOP_NOSLEEP) == 0 &&
|
||||||
|
(lock1->li_flags & LI_SLEEPABLE) == 0)
|
||||||
witness_output(
|
witness_output(
|
||||||
"lock order reversal: (sleepable after non-sleepable)\n");
|
"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)
|
&& lock == &Giant.lock_object)
|
||||||
witness_output(
|
witness_output(
|
||||||
"lock order reversal: (Giant after non-sleepable)\n");
|
"lock order reversal: (Giant after non-sleepable)\n");
|
||||||
@ -1440,7 +1444,8 @@ witness_checkorder(struct lock_object *lock, int flags, const char *file,
|
|||||||
*/
|
*/
|
||||||
if (flags & LOP_NEWORDER &&
|
if (flags & LOP_NEWORDER &&
|
||||||
!(plock->li_lock == &Giant.lock_object &&
|
!(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__,
|
CTR3(KTR_WITNESS, "%s: adding %s as a child of %s", __func__,
|
||||||
w->w_name, plock->li_lock->lo_witness->w_name);
|
w->w_name, plock->li_lock->lo_witness->w_name);
|
||||||
itismychild(plock->li_lock->lo_witness, w);
|
itismychild(plock->li_lock->lo_witness, w);
|
||||||
@ -1500,10 +1505,11 @@ witness_lock(struct lock_object *lock, int flags, const char *file, int line)
|
|||||||
instance->li_lock = lock;
|
instance->li_lock = lock;
|
||||||
instance->li_line = line;
|
instance->li_line = line;
|
||||||
instance->li_file = file;
|
instance->li_file = file;
|
||||||
|
instance->li_flags = 0;
|
||||||
if ((flags & LOP_EXCLUSIVE) != 0)
|
if ((flags & LOP_EXCLUSIVE) != 0)
|
||||||
instance->li_flags = LI_EXCLUSIVE;
|
instance->li_flags |= LI_EXCLUSIVE;
|
||||||
else
|
if ((lock->lo_flags & LO_SLEEPABLE) != 0 && (flags & LOP_NOSLEEP) == 0)
|
||||||
instance->li_flags = 0;
|
instance->li_flags |= LI_SLEEPABLE;
|
||||||
CTR4(KTR_WITNESS, "%s: pid %d added %s as lle[%d]", __func__,
|
CTR4(KTR_WITNESS, "%s: pid %d added %s as lle[%d]", __func__,
|
||||||
td->td_proc->p_pid, lock->lo_name, lle->ll_count - 1);
|
td->td_proc->p_pid, lock->lo_name, lle->ll_count - 1);
|
||||||
}
|
}
|
||||||
@ -1763,7 +1769,7 @@ witness_warn(int flags, struct lock_object *lock, const char *fmt, ...)
|
|||||||
lock1->li_lock == &Giant.lock_object)
|
lock1->li_lock == &Giant.lock_object)
|
||||||
continue;
|
continue;
|
||||||
if (flags & WARN_SLEEPOK &&
|
if (flags & WARN_SLEEPOK &&
|
||||||
(lock1->li_lock->lo_flags & LO_SLEEPABLE) != 0)
|
(lock1->li_flags & LI_SLEEPABLE) != 0)
|
||||||
continue;
|
continue;
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
|
@ -107,6 +107,7 @@ struct lock_class {
|
|||||||
#define LOP_TRYLOCK 0x00000004 /* Don't check lock order. */
|
#define LOP_TRYLOCK 0x00000004 /* Don't check lock order. */
|
||||||
#define LOP_EXCLUSIVE 0x00000008 /* Exclusive lock. */
|
#define LOP_EXCLUSIVE 0x00000008 /* Exclusive lock. */
|
||||||
#define LOP_DUPOK 0x00000010 /* Don't check for duplicate acquires */
|
#define LOP_DUPOK 0x00000010 /* Don't check for duplicate acquires */
|
||||||
|
#define LOP_NOSLEEP 0x00000020 /* Non-sleepable despite LO_SLEEPABLE */
|
||||||
|
|
||||||
/* Flags passed to witness_assert. */
|
/* Flags passed to witness_assert. */
|
||||||
#define LA_MASKASSERT 0x000000ff /* Mask for witness defined asserts. */
|
#define LA_MASKASSERT 0x000000ff /* Mask for witness defined asserts. */
|
||||||
|
Loading…
Reference in New Issue
Block a user