PERFORCE change 102584 for review
John Baldwin
jhb at FreeBSD.org
Thu Jul 27 19:26:37 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=102584
Change 102584 by jhb at 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
More information about the p4-projects
mailing list