From owner-p4-projects@FreeBSD.ORG Mon Aug 22 20:30:49 2005 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 732ED16A421; Mon, 22 Aug 2005 20:30:49 +0000 (GMT) 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 4DD8516A41F for ; Mon, 22 Aug 2005 20:30:49 +0000 (GMT) (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 0349E43D48 for ; Mon, 22 Aug 2005 20:30:48 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id j7MKUmBj063286 for ; Mon, 22 Aug 2005 20:30:48 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id j7MKUm24063283 for perforce@freebsd.org; Mon, 22 Aug 2005 20:30:48 GMT (envelope-from jhb@freebsd.org) Date: Mon, 22 Aug 2005 20:30:48 GMT Message-Id: <200508222030.j7MKUm24063283@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 82421 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: Mon, 22 Aug 2005 20:30:50 -0000 http://perforce.freebsd.org/chv.cgi?CH=82421 Change 82421 by jhb@jhb_slimer on 2005/08/22 20:30:35 Merge in some more anti-foot shooting from jhb_lock. Affected files ... .. //depot/projects/smpng/sys/kern/kern_mutex.c#103 edit Differences ... ==== //depot/projects/smpng/sys/kern/kern_mutex.c#103 (text+ko) ==== @@ -412,6 +412,9 @@ int rval; MPASS(curthread != NULL); + KASSERT(m->mtx_object.lo_class == &lock_class_mtx_sleep, + ("mtx_trylock() of spin mutex %s @ %s:%d", m->mtx_object.lo_name, + file, line)); if (mtx_owned(m) && (m->mtx_object.lo_flags & LO_RECURSABLE) != 0) { m->mtx_recurse++; @@ -460,6 +463,15 @@ return; } + /* + * If we have already panic'd and this is the thread that called + * panic(), then don't block on any mutexes but silently succeed. + * Otherwise, the kernel will deadlock since the scheduler isn't + * going to run the thread that holds the lock we need. + */ + if (panicstr != NULL && curthread->td_flags & TDF_INPANIC) + return; + if (LOCK_LOG_TEST(&m->mtx_object, opts)) CTR4(KTR_LOCK, "_mtx_lock_sleep: %s contested (lock=%p) at %s:%d", @@ -607,7 +619,7 @@ } if (i < 60000000) DELAY(1); - else if (!kdb_active) { + else if (!kdb_active && !panicstr) { printf("spin lock %s held by %p for > 5 seconds\n", m->mtx_object.lo_name, (void *)m->mtx_lock); #ifdef WITNESS @@ -654,6 +666,15 @@ return; } + /* + * If we failed to unlock this lock and we are a thread that has + * called panic(), it may be due to the bypass in _mtx_lock_sleep() + * above. In that case, just return and leave the lock alone to + * avoid changing the state. + */ + if (panicstr != NULL && curthread->td_flags & TDF_INPANIC) + return; + turnstile_lock(&m->mtx_object); ts = turnstile_lookup(&m->mtx_object); if (LOCK_LOG_TEST(&m->mtx_object, opts))