From owner-p4-projects@FreeBSD.ORG Thu Jul 27 19:26:37 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 1C25616A4DF; Thu, 27 Jul 2006 19:26:37 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id CF85F16A4DD for ; Thu, 27 Jul 2006 19:26:36 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9503B43D49 for ; Thu, 27 Jul 2006 19:26:36 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k6RJQaMu012802 for ; Thu, 27 Jul 2006 19:26:36 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k6RJQaAx012799 for perforce@freebsd.org; Thu, 27 Jul 2006 19:26:36 GMT (envelope-from jhb@freebsd.org) Date: Thu, 27 Jul 2006 19:26:36 GMT Message-Id: <200607271926.k6RJQaAx012799@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jhb@freebsd.org using -f From: John Baldwin To: Perforce Change Reviews Cc: Subject: PERFORCE change 102584 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Jul 2006 19:26:37 -0000 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