Check for lockmgr recursion in case of disown and downgrade and panic

also in !debugging kernel rather than having "undefined" behaviour.

Tested by:	avg
MFC after:	1 week
This commit is contained in:
Attilio Rao 2012-12-05 15:11:01 +00:00
parent 8d36e2f17b
commit 1c7d98d0df
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=243900

View File

@ -934,9 +934,19 @@ __lockmgr_args(struct lock *lk, u_int flags, struct lock_object *ilk,
}
break;
case LK_DOWNGRADE:
_lockmgr_assert(lk, KA_XLOCKED | KA_NOTRECURSED, file, line);
_lockmgr_assert(lk, KA_XLOCKED, file, line);
LOCK_LOG_LOCK("XDOWNGRADE", &lk->lock_object, 0, 0, file, line);
WITNESS_DOWNGRADE(&lk->lock_object, 0, file, line);
/*
* Panic if the lock is recursed.
*/
if (lockmgr_xlocked(lk) && lockmgr_recursed(lk)) {
if (flags & LK_INTERLOCK)
class->lc_unlock(ilk);
panic("%s: downgrade a recursed lockmgr %s @ %s:%d\n",
__func__, iwmesg, file, line);
}
TD_SLOCKS_INC(curthread);
/*
@ -1254,7 +1264,14 @@ _lockmgr_disown(struct lock *lk, const char *file, int line)
return;
tid = (uintptr_t)curthread;
_lockmgr_assert(lk, KA_XLOCKED | KA_NOTRECURSED, file, line);
_lockmgr_assert(lk, KA_XLOCKED, file, line);
/*
* Panic if the lock is recursed.
*/
if (lockmgr_xlocked(lk) && lockmgr_recursed(lk))
panic("%s: disown a recursed lockmgr @ %s:%d\n",
__func__, file, line);
/*
* If the owner is already LK_KERNPROC just skip the whole operation.