Date: Thu, 27 Jul 2006 19:26:36 GMT From: John Baldwin <jhb@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 102584 for review Message-ID: <200607271926.k6RJQaAx012799@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=102584 Change 102584 by jhb@jhb_mutex on 2006/07/27 19:25:38 Explicitly write a trash value that will always force any mtx_lock() operations to block into a mutex when it is being destroyed. Previously, the mutex operations on the mutex would actually still work, and if a lock was destroyed while it was held, then it would look like the lock was still held by the thread that destroyed it. Affected files ... .. //depot/projects/smpng/sys/kern/kern_mutex.c#132 edit .. //depot/projects/smpng/sys/modules/crash/crash.c#33 edit .. //depot/projects/smpng/sys/sys/mutex.h#64 edit Differences ... ==== //depot/projects/smpng/sys/kern/kern_mutex.c#132 (text+ko) ==== @@ -276,6 +276,8 @@ { MPASS(curthread != NULL); + KASSERT(m->mtx_lock != MTX_DESTROYED, + ("mtx_lock() of destroyed mutex @ %s:%d", file, line)); KASSERT(LOCK_CLASS(&m->mtx_object) == &lock_class_mtx_sleep, ("mtx_lock() of spin mutex %s @ %s:%d", m->mtx_object.lo_name, file, line)); @@ -302,6 +304,8 @@ { MPASS(curthread != NULL); + KASSERT(m->mtx_lock != MTX_DESTROYED, + ("mtx_unlock() of destroyed mutex @ %s:%d", file, line)); KASSERT(LOCK_CLASS(&m->mtx_object) == &lock_class_mtx_sleep, ("mtx_unlock() of spin mutex %s @ %s:%d", m->mtx_object.lo_name, file, line)); @@ -382,6 +386,8 @@ { MPASS(curthread != NULL); + KASSERT(m->mtx_lock != MTX_DESTROYED, + ("mtx_lock_spin() of destroyed mutex @ %s:%d", file, line)); KASSERT(LOCK_CLASS(&m->mtx_object) == &lock_class_mtx_spin, ("mtx_lock_spin() of sleep mutex %s @ %s:%d", m->mtx_object.lo_name, file, line)); @@ -398,6 +404,8 @@ { MPASS(curthread != NULL); + KASSERT(m->mtx_lock != MTX_DESTROYED, + ("mtx_unlock_spin() of destroyed mutex @ %s:%d", file, line)); KASSERT(LOCK_CLASS(&m->mtx_object) == &lock_class_mtx_spin, ("mtx_unlock_spin() of sleep mutex %s @ %s:%d", m->mtx_object.lo_name, file, line)); @@ -419,6 +427,8 @@ int rval; MPASS(curthread != NULL); + KASSERT(m->mtx_lock != MTX_DESTROYED, + ("mtx_trylock() of destroyed mutex @ %s:%d", file, line)); KASSERT(LOCK_CLASS(&m->mtx_object) == &lock_class_mtx_sleep, ("mtx_trylock() of spin mutex %s @ %s:%d", m->mtx_object.lo_name, file, line)); @@ -920,6 +930,7 @@ __LINE__); } + m->mtx_lock = MTX_DESTROYED; lock_destroy(&m->mtx_object); } ==== //depot/projects/smpng/sys/modules/crash/crash.c#33 (text+ko) ==== @@ -87,6 +87,20 @@ /* Events. */ static void +lock_destroyed_mtx(void) +{ + + bzero(&test1_mtx, sizeof(test1_mtx)); + mtx_init(&test1_mtx, "test1", NULL, MTX_DEF | MTX_RECURSE); + mtx_lock(&test1_mtx); + mtx_destroy(&test1_mtx); + kdb_enter("examine test1"); + mtx_lock(&test1_mtx); + kdb_enter("examine again"); +} +CRASH_EVENT("lock destroyed mutex", lock_destroyed_mtx); + +static void upgrade_baz(void) { rw_init(&baz, "baz"); ==== //depot/projects/smpng/sys/sys/mutex.h#64 (text+ko) ==== @@ -73,6 +73,11 @@ #define MTX_UNOWNED 0x00000004 /* Cookie for free mutex */ #define MTX_FLAGMASK (MTX_RECURSED | MTX_CONTESTED | MTX_UNOWNED) +/* + * Value stored in mutex->mtx_lock to denote a destroyed mutex. + */ +#define MTX_DESTROYED (MTX_CONTESTED | MTX_UNOWNED) + #endif /* _KERNEL */ #ifndef LOCORE
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200607271926.k6RJQaAx012799>