subr_witness.c revision 81489
165557Sjasone/*- 265557Sjasone * Copyright (c) 1998 Berkeley Software Design, Inc. All rights reserved. 365557Sjasone * 465557Sjasone * Redistribution and use in source and binary forms, with or without 565557Sjasone * modification, are permitted provided that the following conditions 665557Sjasone * are met: 765557Sjasone * 1. Redistributions of source code must retain the above copyright 865557Sjasone * notice, this list of conditions and the following disclaimer. 965557Sjasone * 2. Redistributions in binary form must reproduce the above copyright 1065557Sjasone * notice, this list of conditions and the following disclaimer in the 1165557Sjasone * documentation and/or other materials provided with the distribution. 1265557Sjasone * 3. Berkeley Software Design Inc's name may not be used to endorse or 1365557Sjasone * promote products derived from this software without specific prior 1465557Sjasone * written permission. 1565557Sjasone * 1665557Sjasone * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND 1765557Sjasone * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1865557Sjasone * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1965557Sjasone * ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE 2065557Sjasone * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2165557Sjasone * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2265557Sjasone * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2365557Sjasone * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2465557Sjasone * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2565557Sjasone * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2665557Sjasone * SUCH DAMAGE. 2765557Sjasone * 2865557Sjasone * from BSDI $Id: mutex_witness.c,v 1.1.2.20 2000/04/27 03:10:27 cp Exp $ 2967352Sjhb * and BSDI $Id: synch_machdep.c,v 2.3.2.39 2000/04/27 03:10:25 cp Exp $ 3065557Sjasone * $FreeBSD: head/sys/kern/subr_witness.c 81489 2001-08-10 22:33:59Z jhb $ 3165557Sjasone */ 3265557Sjasone 3365557Sjasone/* 3474912Sjhb * Implementation of the `witness' lock verifier. Originally implemented for 3574912Sjhb * mutexes in BSD/OS. Extended to handle generic lock objects and lock 3674912Sjhb * classes in FreeBSD. 3772200Sbmilekic */ 3872200Sbmilekic 3972200Sbmilekic/* 4065557Sjasone * Main Entry: witness 4165557Sjasone * Pronunciation: 'wit-n&s 4265557Sjasone * Function: noun 4365557Sjasone * Etymology: Middle English witnesse, from Old English witnes knowledge, 4465557Sjasone * testimony, witness, from 2wit 4565557Sjasone * Date: before 12th century 4665557Sjasone * 1 : attestation of a fact or event : TESTIMONY 4765557Sjasone * 2 : one that gives evidence; specifically : one who testifies in 4865557Sjasone * a cause or before a judicial tribunal 4965557Sjasone * 3 : one asked to be present at a transaction so as to be able to 5065557Sjasone * testify to its having taken place 5165557Sjasone * 4 : one who has personal knowledge of something 5265557Sjasone * 5 a : something serving as evidence or proof : SIGN 5365557Sjasone * b : public affirmation by word or example of usually 5465557Sjasone * religious faith or conviction <the heroic witness to divine 5565557Sjasone * life -- Pilot> 5665557Sjasone * 6 capitalized : a member of the Jehovah's Witnesses 5765557Sjasone */ 5865557Sjasone 5968790Sjhb#include "opt_ddb.h" 6067676Sjhb#include "opt_witness.h" 6167676Sjhb 6265557Sjasone#include <sys/param.h> 6367352Sjhb#include <sys/bus.h> 6467352Sjhb#include <sys/kernel.h> 6574912Sjhb#include <sys/ktr.h> 6674912Sjhb#include <sys/lock.h> 6767352Sjhb#include <sys/malloc.h> 6874912Sjhb#include <sys/mutex.h> 6965557Sjasone#include <sys/proc.h> 7067676Sjhb#include <sys/sysctl.h> 7165557Sjasone#include <sys/systm.h> 7265557Sjasone 7368790Sjhb#include <ddb/ddb.h> 7468790Sjhb 7574912Sjhb#define WITNESS_COUNT 200 7674912Sjhb#define WITNESS_CHILDCOUNT (WITNESS_COUNT * 4) 7765557Sjasone/* 7874912Sjhb * XXX: This is somewhat bogus, as we assume here that at most 1024 processes 7974912Sjhb * will hold LOCK_NCHILDREN * 2 locks. We handle failure ok, and we should 8074912Sjhb * probably be safe for the most part, but it's still a SWAG. 8167352Sjhb */ 8274912Sjhb#define LOCK_CHILDCOUNT (MAXCPU + 1024) * 2 8371352Sjasone 8474912Sjhb#define WITNESS_NCHILDREN 6 8571352Sjasone 8674912Sjhbstruct witness_child_list_entry; 8771352Sjasone 8874912Sjhbstruct witness { 8974912Sjhb const char *w_name; 9074912Sjhb struct lock_class *w_class; 9174912Sjhb STAILQ_ENTRY(witness) w_list; /* List of all witnesses. */ 9274912Sjhb STAILQ_ENTRY(witness) w_typelist; /* Witnesses of a type. */ 9374912Sjhb struct witness_child_list_entry *w_children; /* Great evilness... */ 9474912Sjhb const char *w_file; 9574912Sjhb int w_line; 9674912Sjhb u_int w_level; 9774912Sjhb u_int w_refcount; 9874912Sjhb u_char w_Giant_squawked:1; 9974912Sjhb u_char w_other_squawked:1; 10074912Sjhb u_char w_same_squawked:1; 10174912Sjhb}; 10271352Sjasone 10374912Sjhbstruct witness_child_list_entry { 10474912Sjhb struct witness_child_list_entry *wcl_next; 10574912Sjhb struct witness *wcl_children[WITNESS_NCHILDREN]; 10674912Sjhb u_int wcl_count; 10774912Sjhb}; 10871352Sjasone 10974912SjhbSTAILQ_HEAD(witness_list, witness); 11071352Sjasone 11174912Sjhbstruct witness_blessed { 11274912Sjhb const char *b_lock1; 11374912Sjhb const char *b_lock2; 11474912Sjhb}; 11571352Sjasone 11674912Sjhbstruct witness_order_list_entry { 11774912Sjhb const char *w_name; 11874912Sjhb struct lock_class *w_class; 11974912Sjhb}; 12071352Sjasone 12174912Sjhbstatic struct witness *enroll(const char *description, 12274912Sjhb struct lock_class *lock_class); 12374912Sjhbstatic int itismychild(struct witness *parent, struct witness *child); 12474912Sjhbstatic void removechild(struct witness *parent, struct witness *child); 12574912Sjhbstatic int isitmychild(struct witness *parent, struct witness *child); 12674912Sjhbstatic int isitmydescendant(struct witness *parent, struct witness *child); 12774912Sjhbstatic int dup_ok(struct witness *); 12874912Sjhbstatic int blessed(struct witness *, struct witness *); 12974912Sjhbstatic void witness_display_list(void(*prnt)(const char *fmt, ...), 13074912Sjhb struct witness_list *list); 13174912Sjhbstatic void witness_displaydescendants(void(*)(const char *fmt, ...), 13274912Sjhb struct witness *); 13374912Sjhbstatic void witness_leveldescendents(struct witness *parent, int level); 13474912Sjhbstatic void witness_levelall(void); 13574912Sjhbstatic struct witness *witness_get(void); 13674912Sjhbstatic void witness_free(struct witness *m); 13774912Sjhbstatic struct witness_child_list_entry *witness_child_get(void); 13874912Sjhbstatic void witness_child_free(struct witness_child_list_entry *wcl); 13974912Sjhbstatic struct lock_list_entry *witness_lock_list_get(void); 14074912Sjhbstatic void witness_lock_list_free(struct lock_list_entry *lle); 14174912Sjhbstatic void witness_display(void(*)(const char *fmt, ...)); 14276272Sjhbstatic struct lock_instance *find_instance(struct lock_list_entry *lock_list, 14376272Sjhb struct lock_object *lock); 14472200Sbmilekic 14574912SjhbMALLOC_DEFINE(M_WITNESS, "witness", "witness structure"); 14672200Sbmilekic 14777843Speterstatic int witness_watch = 1; 14877900SpeterTUNABLE_INT("debug.witness_watch", &witness_watch); 14974912SjhbSYSCTL_INT(_debug, OID_AUTO, witness_watch, CTLFLAG_RD, &witness_watch, 0, ""); 15071352Sjasone 15167352Sjhb#ifdef DDB 15272200Sbmilekic/* 15367676Sjhb * When DDB is enabled and witness_ddb is set to 1, it will cause the system to 15465557Sjasone * drop into kdebug() when: 15565557Sjasone * - a lock heirarchy violation occurs 15665557Sjasone * - locks are held when going to sleep. 15765557Sjasone */ 15867676Sjhb#ifdef WITNESS_DDB 15977843Speterint witness_ddb = 1; 16067676Sjhb#else 16177843Speterint witness_ddb = 0; 16265557Sjasone#endif 16377900SpeterTUNABLE_INT("debug.witness_ddb", &witness_ddb); 16467676SjhbSYSCTL_INT(_debug, OID_AUTO, witness_ddb, CTLFLAG_RW, &witness_ddb, 0, ""); 16567676Sjhb#endif /* DDB */ 16665557Sjasone 16767676Sjhb#ifdef WITNESS_SKIPSPIN 16877843Speterint witness_skipspin = 1; 16967676Sjhb#else 17077843Speterint witness_skipspin = 0; 17165557Sjasone#endif 17277900SpeterTUNABLE_INT("debug.witness_skipspin", &witness_skipspin); 17367676SjhbSYSCTL_INT(_debug, OID_AUTO, witness_skipspin, CTLFLAG_RD, &witness_skipspin, 0, 17467676Sjhb ""); 17565557Sjasone 17674912Sjhbstatic struct mtx w_mtx; 17774912Sjhbstatic struct witness_list w_free = STAILQ_HEAD_INITIALIZER(w_free); 17874912Sjhbstatic struct witness_list w_all = STAILQ_HEAD_INITIALIZER(w_all); 17974912Sjhbstatic struct witness_list w_spin = STAILQ_HEAD_INITIALIZER(w_spin); 18074912Sjhbstatic struct witness_list w_sleep = STAILQ_HEAD_INITIALIZER(w_sleep); 18174912Sjhbstatic struct witness_child_list_entry *w_child_free = NULL; 18274912Sjhbstatic struct lock_list_entry *w_lock_list_free = NULL; 18374912Sjhbstatic int witness_dead; /* fatal error, probably no memory */ 18465557Sjasone 18574912Sjhbstatic struct witness w_data[WITNESS_COUNT]; 18674912Sjhbstatic struct witness_child_list_entry w_childdata[WITNESS_CHILDCOUNT]; 18774912Sjhbstatic struct lock_list_entry w_locklistdata[LOCK_CHILDCOUNT]; 18865557Sjasone 18974912Sjhbstatic struct witness_order_list_entry order_lists[] = { 19074912Sjhb { "Giant", &lock_class_mtx_sleep }, 19174912Sjhb { "proctree", &lock_class_sx }, 19274912Sjhb { "allproc", &lock_class_sx }, 19374912Sjhb { "process lock", &lock_class_mtx_sleep }, 19474912Sjhb { "uidinfo hash", &lock_class_mtx_sleep }, 19574912Sjhb { "uidinfo struct", &lock_class_mtx_sleep }, 19674912Sjhb { NULL, NULL }, 19775464Sjhb /* 19875464Sjhb * spin locks 19975464Sjhb */ 20072224Sjhb#if defined(__i386__) && defined (SMP) 20174912Sjhb { "com", &lock_class_mtx_spin }, 20272224Sjhb#endif 20374912Sjhb { "sio", &lock_class_mtx_spin }, 20472224Sjhb#ifdef __i386__ 20574912Sjhb { "cy", &lock_class_mtx_spin }, 20672224Sjhb#endif 20774912Sjhb { "ng_node", &lock_class_mtx_spin }, 20874912Sjhb { "ng_worklist", &lock_class_mtx_spin }, 20974912Sjhb { "ithread table lock", &lock_class_mtx_spin }, 21074912Sjhb { "sched lock", &lock_class_mtx_spin }, 21174912Sjhb { "callout", &lock_class_mtx_spin }, 21265557Sjasone /* 21365557Sjasone * leaf locks 21465557Sjasone */ 21572224Sjhb#ifdef SMP 21675464Sjhb { "ap boot", &lock_class_mtx_spin }, 21771576Sjasone#ifdef __i386__ 21874912Sjhb { "imen", &lock_class_mtx_spin }, 21971576Sjasone#endif 22074912Sjhb { "smp rendezvous", &lock_class_mtx_spin }, 22172224Sjhb#endif 22278785Sjhb { "clk", &lock_class_mtx_spin }, 22374912Sjhb { NULL, NULL }, 22474912Sjhb { NULL, NULL } 22565557Sjasone}; 22665557Sjasone 22774912Sjhbstatic const char *dup_list[] = { 22873912Sjhb "process lock", 22965557Sjasone NULL 23065557Sjasone}; 23165557Sjasone 23265557Sjasone/* 23365557Sjasone * Pairs of locks which have been blessed 23465557Sjasone * Don't complain about order problems with blessed locks 23565557Sjasone */ 23665856Sjhbstatic struct witness_blessed blessed_list[] = { 23765557Sjasone}; 23872200Sbmilekicstatic int blessed_count = 23972200Sbmilekic sizeof(blessed_list) / sizeof(struct witness_blessed); 24065557Sjasone 24174912Sjhb/* 24274912Sjhb * List of all locks in the system. 24374912Sjhb */ 24474912SjhbSTAILQ_HEAD(, lock_object) all_locks = STAILQ_HEAD_INITIALIZER(all_locks); 24574912Sjhb 24674912Sjhbstatic struct mtx all_mtx = { 24774912Sjhb { &lock_class_mtx_sleep, /* mtx_object.lo_class */ 24874912Sjhb "All locks list", /* mtx_object.lo_name */ 24974912Sjhb LO_INITIALIZED, /* mtx_object.lo_flags */ 25074912Sjhb { NULL }, /* mtx_object.lo_list */ 25174912Sjhb NULL }, /* mtx_object.lo_witness */ 25274912Sjhb MTX_UNOWNED, 0, /* mtx_lock, mtx_recurse */ 25374912Sjhb 0, /* mtx_savecrit */ 25474912Sjhb TAILQ_HEAD_INITIALIZER(all_mtx.mtx_blocked), 25574912Sjhb { NULL, NULL } /* mtx_contested */ 25674912Sjhb}; 25774912Sjhb 25874912Sjhb/* 25974912Sjhb * This global is set to 0 once it becomes safe to use the witness code. 26074912Sjhb */ 26174912Sjhbstatic int witness_cold = 1; 26274912Sjhb 26374912Sjhb/* 26474912Sjhb * Global variables for book keeping. 26574912Sjhb */ 26674912Sjhbstatic int lock_cur_cnt; 26774912Sjhbstatic int lock_max_cnt; 26874912Sjhb 26974912Sjhb/* 27074912Sjhb * The WITNESS-enabled diagnostic code. 27174912Sjhb */ 27271352Sjasonestatic void 27374912Sjhbwitness_initialize(void *dummy __unused) 27465557Sjasone{ 27574912Sjhb struct lock_object *lock; 27674912Sjhb struct witness_order_list_entry *order; 27774912Sjhb struct witness *w, *w1; 27874912Sjhb int i; 27965557Sjasone 28074912Sjhb /* 28174912Sjhb * We have to release Giant before initializing its witness 28274912Sjhb * structure so that WITNESS doesn't get confused. 28374912Sjhb */ 28474912Sjhb mtx_unlock(&Giant); 28574912Sjhb mtx_assert(&Giant, MA_NOTOWNED); 28674912Sjhb 28778871Sjhb CTR0(KTR_WITNESS, __func__ ": initializing witness"); 28874912Sjhb STAILQ_INSERT_HEAD(&all_locks, &all_mtx.mtx_object, lo_list); 28974912Sjhb mtx_init(&w_mtx, "witness lock", MTX_SPIN | MTX_QUIET | MTX_NOWITNESS); 29074912Sjhb for (i = 0; i < WITNESS_COUNT; i++) 29174912Sjhb witness_free(&w_data[i]); 29274912Sjhb for (i = 0; i < WITNESS_CHILDCOUNT; i++) 29374912Sjhb witness_child_free(&w_childdata[i]); 29474912Sjhb for (i = 0; i < LOCK_CHILDCOUNT; i++) 29574912Sjhb witness_lock_list_free(&w_locklistdata[i]); 29674912Sjhb 29774912Sjhb /* First add in all the specified order lists. */ 29874912Sjhb for (order = order_lists; order->w_name != NULL; order++) { 29974912Sjhb w = enroll(order->w_name, order->w_class); 30075569Sjhb if (w == NULL) 30175569Sjhb continue; 30274912Sjhb w->w_file = "order list"; 30374912Sjhb for (order++; order->w_name != NULL; order++) { 30474912Sjhb w1 = enroll(order->w_name, order->w_class); 30575569Sjhb if (w1 == NULL) 30675569Sjhb continue; 30774912Sjhb w1->w_file = "order list"; 30874912Sjhb itismychild(w, w1); 30974912Sjhb w = w1; 31065557Sjasone } 31165557Sjasone } 31265557Sjasone 31374912Sjhb /* Iterate through all locks and add them to witness. */ 31474912Sjhb mtx_lock(&all_mtx); 31574912Sjhb STAILQ_FOREACH(lock, &all_locks, lo_list) { 31674912Sjhb if (lock->lo_flags & LO_WITNESS) 31774912Sjhb lock->lo_witness = enroll(lock->lo_name, 31874912Sjhb lock->lo_class); 31974912Sjhb else 32074912Sjhb lock->lo_witness = NULL; 32174912Sjhb } 32274912Sjhb mtx_unlock(&all_mtx); 32374912Sjhb 32474912Sjhb /* Mark the witness code as being ready for use. */ 32574912Sjhb atomic_store_rel_int(&witness_cold, 0); 32674912Sjhb 32774912Sjhb mtx_lock(&Giant); 32865557Sjasone} 32974912SjhbSYSINIT(witness_init, SI_SUB_WITNESS, SI_ORDER_FIRST, witness_initialize, NULL) 33065557Sjasone 33174912Sjhbvoid 33274912Sjhbwitness_init(struct lock_object *lock) 33374912Sjhb{ 33474912Sjhb struct lock_class *class; 33574912Sjhb 33674912Sjhb class = lock->lo_class; 33774912Sjhb if (lock->lo_flags & LO_INITIALIZED) 33874912Sjhb panic("%s: lock (%s) %s is already initialized!\n", __func__, 33974912Sjhb class->lc_name, lock->lo_name); 34074912Sjhb 34174912Sjhb if ((lock->lo_flags & LO_RECURSABLE) != 0 && 34274912Sjhb (class->lc_flags & LC_RECURSABLE) == 0) 34374912Sjhb panic("%s: lock (%s) %s can not be recursable!\n", __func__, 34474912Sjhb class->lc_name, lock->lo_name); 34576272Sjhb 34674912Sjhb if ((lock->lo_flags & LO_SLEEPABLE) != 0 && 34774912Sjhb (class->lc_flags & LC_SLEEPABLE) == 0) 34874912Sjhb panic("%s: lock (%s) %s can not be sleepable!\n", __func__, 34974912Sjhb class->lc_name, lock->lo_name); 35076272Sjhb 35174912Sjhb mtx_lock(&all_mtx); 35274912Sjhb STAILQ_INSERT_TAIL(&all_locks, lock, lo_list); 35374912Sjhb lock->lo_flags |= LO_INITIALIZED; 35474912Sjhb lock_cur_cnt++; 35574912Sjhb if (lock_cur_cnt > lock_max_cnt) 35674912Sjhb lock_max_cnt = lock_cur_cnt; 35774912Sjhb mtx_unlock(&all_mtx); 35880747Sjhb if (!witness_cold && !witness_dead && panicstr == NULL && 35974912Sjhb (lock->lo_flags & LO_WITNESS) != 0) 36074912Sjhb lock->lo_witness = enroll(lock->lo_name, class); 36174912Sjhb else 36274912Sjhb lock->lo_witness = NULL; 36374912Sjhb} 36474912Sjhb 36574912Sjhbvoid 36674912Sjhbwitness_destroy(struct lock_object *lock) 36774912Sjhb{ 36875362Sjhb struct witness *w; 36974912Sjhb 37074912Sjhb if (witness_cold) 37174912Sjhb panic("lock (%s) %s destroyed while witness_cold", 37274912Sjhb lock->lo_class->lc_name, lock->lo_name); 37374912Sjhb 37474912Sjhb if ((lock->lo_flags & LO_INITIALIZED) == 0) 37574912Sjhb panic("%s: lock (%s) %s is not initialized!\n", __func__, 37674912Sjhb lock->lo_class->lc_name, lock->lo_name); 37774912Sjhb 37876272Sjhb /* XXX: need to verify that no one holds the lock */ 37975362Sjhb w = lock->lo_witness; 38075362Sjhb if (w != NULL) { 38175362Sjhb mtx_lock_spin(&w_mtx); 38275362Sjhb w->w_refcount--; 38375362Sjhb if (w->w_refcount == 0) { 38478871Sjhb CTR1(KTR_WITNESS, 38578871Sjhb __func__ ": marking witness %s as dead", w->w_name); 38675362Sjhb w->w_name = "(dead)"; 38775362Sjhb w->w_file = "(dead)"; 38875362Sjhb w->w_line = 0; 38975362Sjhb } 39075362Sjhb mtx_unlock_spin(&w_mtx); 39175362Sjhb } 39275362Sjhb 39374912Sjhb mtx_lock(&all_mtx); 39474912Sjhb lock_cur_cnt--; 39574912Sjhb STAILQ_REMOVE(&all_locks, lock, lock_object, lo_list); 39680055Sjhb lock->lo_flags &= ~LO_INITIALIZED; 39774912Sjhb mtx_unlock(&all_mtx); 39874912Sjhb} 39974912Sjhb 40071352Sjasonestatic void 40174912Sjhbwitness_display_list(void(*prnt)(const char *fmt, ...), 40274912Sjhb struct witness_list *list) 40371352Sjasone{ 40471352Sjasone struct witness *w, *w1; 40574912Sjhb int found; 40671352Sjasone 40774912Sjhb STAILQ_FOREACH(w, list, w_typelist) { 40874912Sjhb if (w->w_file == NULL) 40971352Sjasone continue; 41074912Sjhb found = 0; 41174912Sjhb STAILQ_FOREACH(w1, list, w_typelist) { 41274912Sjhb if (isitmychild(w1, w)) { 41374912Sjhb found++; 41471352Sjasone break; 41574912Sjhb } 41671352Sjasone } 41774912Sjhb if (found) 41871352Sjasone continue; 41971352Sjasone /* 42071352Sjasone * This lock has no anscestors, display its descendants. 42171352Sjasone */ 42271352Sjasone witness_displaydescendants(prnt, w); 42371352Sjasone } 42474912Sjhb} 42572224Sjhb 42674912Sjhbstatic void 42774912Sjhbwitness_display(void(*prnt)(const char *fmt, ...)) 42874912Sjhb{ 42974912Sjhb struct witness *w; 43074912Sjhb 43174912Sjhb KASSERT(!witness_cold, ("%s: witness_cold\n", __func__)); 43274912Sjhb witness_levelall(); 43374912Sjhb 43472224Sjhb /* 43574930Sjhb * First, handle sleep locks which have been acquired at least 43674912Sjhb * once. 43774912Sjhb */ 43874912Sjhb prnt("Sleep locks:\n"); 43974912Sjhb witness_display_list(prnt, &w_sleep); 44074912Sjhb 44174912Sjhb /* 44274930Sjhb * Now do spin locks which have been acquired at least once. 44372224Sjhb */ 44474912Sjhb prnt("\nSpin locks:\n"); 44574912Sjhb witness_display_list(prnt, &w_spin); 44672224Sjhb 44772224Sjhb /* 44874930Sjhb * Finally, any locks which have not been acquired yet. 44972224Sjhb */ 45074912Sjhb prnt("\nLocks which were never acquired:\n"); 45174912Sjhb STAILQ_FOREACH(w, &w_all, w_list) { 45271352Sjasone if (w->w_file != NULL) 45371352Sjasone continue; 45474912Sjhb prnt("%s\n", w->w_name); 45571352Sjasone } 45671352Sjasone} 45771352Sjasone 45865557Sjasonevoid 45974912Sjhbwitness_lock(struct lock_object *lock, int flags, const char *file, int line) 46065557Sjasone{ 46174912Sjhb struct lock_list_entry **lock_list, *lle; 46276272Sjhb struct lock_instance *lock1, *lock2; 46374912Sjhb struct lock_class *class; 46465856Sjhb struct witness *w, *w1; 46565557Sjasone struct proc *p; 46674912Sjhb int i, j; 46767676Sjhb#ifdef DDB 46867676Sjhb int go_into_ddb = 0; 46967676Sjhb#endif /* DDB */ 47065557Sjasone 47174912Sjhb if (witness_cold || witness_dead || lock->lo_witness == NULL || 47280747Sjhb panicstr != NULL) 47371320Sjasone return; 47474912Sjhb w = lock->lo_witness; 47574912Sjhb class = lock->lo_class; 47672393Sbmilekic p = curproc; 47765557Sjasone 47874944Sjhb /* 47974944Sjhb * We have to hold a spinlock to keep lock_list valid across the check 48074944Sjhb * in the LC_SLEEPLOCK case. In the LC_SPINLOCK case, it is already 48174944Sjhb * protected by the spinlock we are currently performing the witness 48274944Sjhb * checks on, so it is ok to release the lock after performing this 48374944Sjhb * check. All we have to protect is the LC_SLEEPLOCK case when no 48474944Sjhb * spinlocks are held as we may get preempted during this check and 48574944Sjhb * lock_list could end up pointing to some other CPU's spinlock list. 48674944Sjhb */ 48774944Sjhb mtx_lock_spin(&w_mtx); 48874912Sjhb lock_list = PCPU_PTR(spinlocks); 48974912Sjhb if (class->lc_flags & LC_SLEEPLOCK) { 49076772Sjhb if (*lock_list != NULL && (flags & LOP_TRYLOCK) == 0) { 49174944Sjhb mtx_unlock_spin(&w_mtx); 49274912Sjhb panic("blockable sleep lock (%s) %s @ %s:%d", 49374912Sjhb class->lc_name, lock->lo_name, file, line); 49474944Sjhb } 49574912Sjhb lock_list = &p->p_sleeplocks; 49674912Sjhb } 49774944Sjhb mtx_unlock_spin(&w_mtx); 49865557Sjasone 49976772Sjhb /* 50076772Sjhb * Try locks do not block if they fail to acquire the lock, thus 50176772Sjhb * there is no danger of deadlocks or of switching while holding a 50276772Sjhb * spin lock if we acquire a lock via a try operation. 50376772Sjhb */ 50474912Sjhb if (flags & LOP_TRYLOCK) 50565557Sjasone goto out; 50665557Sjasone 50765557Sjasone /* 50874912Sjhb * Is this the first lock acquired? If so, then no order checking 50974912Sjhb * is needed. 51065557Sjasone */ 51174912Sjhb if (*lock_list == NULL) 51265557Sjasone goto out; 51365557Sjasone 51474912Sjhb /* 51576272Sjhb * Check to see if we are recursing on a lock we already own. 51676272Sjhb */ 51776272Sjhb lock1 = find_instance(*lock_list, lock); 51876272Sjhb if (lock1 != NULL) { 51976272Sjhb if ((lock1->li_flags & LI_EXCLUSIVE) != 0 && 52076272Sjhb (flags & LOP_EXCLUSIVE) == 0) { 52176272Sjhb printf("shared lock of (%s) %s @ %s:%d\n", 52276272Sjhb class->lc_name, lock->lo_name, file, line); 52376272Sjhb printf("while exclusively locked from %s:%d\n", 52476272Sjhb lock1->li_file, lock1->li_line); 52576272Sjhb panic("share->excl"); 52676272Sjhb } 52776272Sjhb if ((lock1->li_flags & LI_EXCLUSIVE) == 0 && 52876272Sjhb (flags & LOP_EXCLUSIVE) != 0) { 52976272Sjhb printf("exclusive lock of (%s) %s @ %s:%d\n", 53076272Sjhb class->lc_name, lock->lo_name, file, line); 53176272Sjhb printf("while share locked from %s:%d\n", 53276272Sjhb lock1->li_file, lock1->li_line); 53376272Sjhb panic("excl->share"); 53476272Sjhb } 53576272Sjhb lock1->li_flags++; 53676272Sjhb if ((lock->lo_flags & LO_RECURSABLE) == 0) { 53776272Sjhb printf( 53876272Sjhb "recursed on non-recursive lock (%s) %s @ %s:%d\n", 53976272Sjhb class->lc_name, lock->lo_name, file, line); 54076272Sjhb printf("first acquired @ %s:%d\n", lock1->li_file, 54176272Sjhb lock1->li_line); 54276272Sjhb panic("recurse"); 54376272Sjhb } 54478871Sjhb CTR3(KTR_WITNESS, __func__ ": pid %d recursed on %s r=%d", 54578785Sjhb curproc->p_pid, lock->lo_name, 54678785Sjhb lock1->li_flags & LI_RECURSEMASK); 54776272Sjhb lock1->li_file = file; 54876272Sjhb lock1->li_line = line; 54976272Sjhb return; 55076272Sjhb } 55176272Sjhb 55276272Sjhb /* 55374912Sjhb * Check for duplicate locks of the same type. Note that we only 55474912Sjhb * have to check for this on the last lock we just acquired. Any 55574912Sjhb * other cases will be caught as lock order violations. 55674912Sjhb */ 55776272Sjhb lock1 = &(*lock_list)->ll_children[(*lock_list)->ll_count - 1]; 55876272Sjhb w1 = lock1->li_lock->lo_witness; 55974912Sjhb if (w1 == w) { 56065557Sjasone if (w->w_same_squawked || dup_ok(w)) 56165557Sjasone goto out; 56265557Sjasone w->w_same_squawked = 1; 56375755Sjhb printf("acquiring duplicate lock of same type: \"%s\"\n", 56474912Sjhb lock->lo_name); 56576272Sjhb printf(" 1st @ %s:%d\n", lock1->li_file, lock1->li_line); 56665557Sjasone printf(" 2nd @ %s:%d\n", file, line); 56767676Sjhb#ifdef DDB 56867676Sjhb go_into_ddb = 1; 56967676Sjhb#endif /* DDB */ 57065557Sjasone goto out; 57165557Sjasone } 57265557Sjasone MPASS(!mtx_owned(&w_mtx)); 57374912Sjhb mtx_lock_spin(&w_mtx); 57465557Sjasone /* 57565557Sjasone * If we have a known higher number just say ok 57665557Sjasone */ 57765557Sjasone if (witness_watch > 1 && w->w_level > w1->w_level) { 57874912Sjhb mtx_unlock_spin(&w_mtx); 57965557Sjasone goto out; 58065557Sjasone } 58174912Sjhb if (isitmydescendant(w1, w)) { 58274912Sjhb mtx_unlock_spin(&w_mtx); 58365557Sjasone goto out; 58465557Sjasone } 58574912Sjhb for (j = 0, lle = *lock_list; lle != NULL; lle = lle->ll_next) { 58674912Sjhb for (i = lle->ll_count - 1; i >= 0; i--, j++) { 58765557Sjasone 58874912Sjhb MPASS(j < WITNESS_COUNT); 58976272Sjhb lock1 = &lle->ll_children[i]; 59076272Sjhb w1 = lock1->li_lock->lo_witness; 59174912Sjhb 59274912Sjhb /* 59374912Sjhb * If this lock doesn't undergo witness checking, 59474912Sjhb * then skip it. 59574912Sjhb */ 59674912Sjhb if (w1 == NULL) { 59776272Sjhb KASSERT((lock1->li_lock->lo_flags & LO_WITNESS) == 0, 59874912Sjhb ("lock missing witness structure")); 59974912Sjhb continue; 60074912Sjhb } 60176272Sjhb /* 60276272Sjhb * If we are locking Giant and we slept with this 60376272Sjhb * lock, then skip it. 60476272Sjhb */ 60576272Sjhb if ((lock1->li_flags & LI_SLEPT) != 0 && 60676272Sjhb lock == &Giant.mtx_object) 60776272Sjhb continue; 60874912Sjhb if (!isitmydescendant(w, w1)) 60974912Sjhb continue; 61074912Sjhb /* 61174912Sjhb * We have a lock order violation, check to see if it 61274912Sjhb * is allowed or has already been yelled about. 61374912Sjhb */ 61474912Sjhb mtx_unlock_spin(&w_mtx); 61565557Sjasone if (blessed(w, w1)) 61665557Sjasone goto out; 61776272Sjhb if (lock1->li_lock == &Giant.mtx_object) { 61865557Sjasone if (w1->w_Giant_squawked) 61965557Sjasone goto out; 62065557Sjasone else 62165557Sjasone w1->w_Giant_squawked = 1; 62265557Sjasone } else { 62365557Sjasone if (w1->w_other_squawked) 62465557Sjasone goto out; 62565557Sjasone else 62665557Sjasone w1->w_other_squawked = 1; 62765557Sjasone } 62874912Sjhb /* 62974912Sjhb * Ok, yell about it. 63074912Sjhb */ 63165557Sjasone printf("lock order reversal\n"); 63274912Sjhb /* 63374912Sjhb * Try to locate an earlier lock with 63474912Sjhb * witness w in our list. 63574912Sjhb */ 63674912Sjhb do { 63776272Sjhb lock2 = &lle->ll_children[i]; 63876272Sjhb MPASS(lock2->li_lock != NULL); 63976272Sjhb if (lock2->li_lock->lo_witness == w) 64074912Sjhb break; 64174912Sjhb i--; 64274912Sjhb if (i == 0 && lle->ll_next != NULL) { 64374912Sjhb lle = lle->ll_next; 64474912Sjhb i = lle->ll_count - 1; 64574912Sjhb MPASS(i != 0); 64674912Sjhb } 64774912Sjhb } while (i >= 0); 64876272Sjhb if (i < 0) { 64976272Sjhb printf(" 1st %p %s @ %s:%d\n", lock1->li_lock, 65076272Sjhb lock1->li_lock->lo_name, lock1->li_file, 65176272Sjhb lock1->li_line); 65276272Sjhb printf(" 2nd %p %s @ %s:%d\n", lock, 65376272Sjhb lock->lo_name, file, line); 65476272Sjhb } else { 65576272Sjhb printf(" 1st %p %s @ %s:%d\n", lock2->li_lock, 65676272Sjhb lock2->li_lock->lo_name, lock2->li_file, 65776272Sjhb lock2->li_line); 65876272Sjhb printf(" 2nd %p %s @ %s:%d\n", lock1->li_lock, 65976272Sjhb lock1->li_lock->lo_name, lock1->li_file, 66076272Sjhb lock1->li_line); 66176272Sjhb printf(" 3rd %p %s @ %s:%d\n", lock, 66276272Sjhb lock->lo_name, file, line); 66376272Sjhb } 66467676Sjhb#ifdef DDB 66567676Sjhb go_into_ddb = 1; 66667676Sjhb#endif /* DDB */ 66765557Sjasone goto out; 66865557Sjasone } 66965557Sjasone } 67076272Sjhb lock1 = &(*lock_list)->ll_children[(*lock_list)->ll_count - 1]; 67178871Sjhb /* 67278871Sjhb * Don't build a new relationship if we are locking Giant just 67378871Sjhb * after waking up and the previous lock in the list was acquired 67478871Sjhb * prior to blocking. 67578871Sjhb */ 67678871Sjhb if (lock == &Giant.mtx_object && (lock1->li_flags & LI_SLEPT) != 0) 67774912Sjhb mtx_unlock_spin(&w_mtx); 67878871Sjhb else { 67978871Sjhb CTR2(KTR_WITNESS, __func__ ": adding %s as a child of %s", 68078871Sjhb lock->lo_name, lock1->li_lock->lo_name); 68178871Sjhb if (!itismychild(lock1->li_lock->lo_witness, w)) 68278871Sjhb mtx_unlock_spin(&w_mtx); 68378871Sjhb } 68465557Sjasone 68565557Sjasoneout: 68667676Sjhb#ifdef DDB 68767676Sjhb if (witness_ddb && go_into_ddb) 68875711Sjhb Debugger(__func__); 68967676Sjhb#endif /* DDB */ 69065557Sjasone w->w_file = file; 69165557Sjasone w->w_line = line; 69274912Sjhb 69374912Sjhb lle = *lock_list; 69476272Sjhb if (lle == NULL || lle->ll_count == LOCK_NCHILDREN) { 69578785Sjhb lle = witness_lock_list_get(); 69678785Sjhb if (lle == NULL) 69765557Sjasone return; 69878785Sjhb lle->ll_next = *lock_list; 69978871Sjhb CTR2(KTR_WITNESS, __func__ ": pid %d added lle %p", 70078785Sjhb curproc->p_pid, lle); 70178785Sjhb *lock_list = lle; 70265557Sjasone } 70376272Sjhb lock1 = &lle->ll_children[lle->ll_count++]; 70476272Sjhb lock1->li_lock = lock; 70576272Sjhb lock1->li_line = line; 70676272Sjhb lock1->li_file = file; 70776272Sjhb if ((flags & LOP_EXCLUSIVE) != 0) 70876272Sjhb lock1->li_flags = LI_EXCLUSIVE; 70976272Sjhb else 71076272Sjhb lock1->li_flags = 0; 71178871Sjhb CTR3(KTR_WITNESS, __func__ ": pid %d added %s as lle[%d]", 71278785Sjhb curproc->p_pid, lock->lo_name, lle->ll_count - 1); 71365557Sjasone} 71465557Sjasone 71565557Sjasonevoid 71674912Sjhbwitness_unlock(struct lock_object *lock, int flags, const char *file, int line) 71765557Sjasone{ 71874912Sjhb struct lock_list_entry **lock_list, *lle; 71976272Sjhb struct lock_instance *instance; 72074912Sjhb struct lock_class *class; 72174016Sjhb struct proc *p; 72278785Sjhb critical_t s; 72374912Sjhb int i, j; 72465557Sjasone 72574912Sjhb if (witness_cold || witness_dead || lock->lo_witness == NULL || 72680747Sjhb panicstr != NULL) 72771352Sjasone return; 72874016Sjhb p = curproc; 72974912Sjhb class = lock->lo_class; 73076272Sjhb if (class->lc_flags & LC_SLEEPLOCK) 73174912Sjhb lock_list = &p->p_sleeplocks; 73276272Sjhb else 73374912Sjhb lock_list = PCPU_PTR(spinlocks); 73474912Sjhb for (; *lock_list != NULL; lock_list = &(*lock_list)->ll_next) 73576272Sjhb for (i = 0; i < (*lock_list)->ll_count; i++) { 73676272Sjhb instance = &(*lock_list)->ll_children[i]; 73776272Sjhb if (instance->li_lock == lock) { 73876272Sjhb if ((instance->li_flags & LI_EXCLUSIVE) != 0 && 73976272Sjhb (flags & LOP_EXCLUSIVE) == 0) { 74076272Sjhb printf( 74176272Sjhb "shared unlock of (%s) %s @ %s:%d\n", 74276272Sjhb class->lc_name, lock->lo_name, 74376272Sjhb file, line); 74476272Sjhb printf( 74576272Sjhb "while exclusively locked from %s:%d\n", 74676272Sjhb instance->li_file, 74776272Sjhb instance->li_line); 74876272Sjhb panic("excl->ushare"); 74976272Sjhb } 75076272Sjhb if ((instance->li_flags & LI_EXCLUSIVE) == 0 && 75176272Sjhb (flags & LOP_EXCLUSIVE) != 0) { 75276272Sjhb printf( 75376272Sjhb "exclusive unlock of (%s) %s @ %s:%d\n", 75476272Sjhb class->lc_name, lock->lo_name, 75576272Sjhb file, line); 75676272Sjhb printf( 75776272Sjhb "while share locked from %s:%d\n", 75876272Sjhb instance->li_file, 75976272Sjhb instance->li_line); 76076272Sjhb panic("share->uexcl"); 76176272Sjhb } 76276272Sjhb /* If we are recursed, unrecurse. */ 76376272Sjhb if ((instance->li_flags & LI_RECURSEMASK) > 0) { 76478785Sjhb CTR3(KTR_WITNESS, 76578871Sjhb __func__ ": pid %d unrecursed on %s r=%d", 76678785Sjhb curproc->p_pid, 76778785Sjhb instance->li_lock->lo_name, 76878785Sjhb instance->li_flags); 76976272Sjhb instance->li_flags--; 77076272Sjhb goto out; 77176272Sjhb } 77278785Sjhb s = critical_enter(); 77378785Sjhb CTR3(KTR_WITNESS, 77478871Sjhb __func__ ": pid %d removed %s from lle[%d]", 77578785Sjhb curproc->p_pid, instance->li_lock->lo_name, 77678785Sjhb (*lock_list)->ll_count - 1); 77774912Sjhb (*lock_list)->ll_count--; 77874912Sjhb for (j = i; j < (*lock_list)->ll_count; j++) 77974912Sjhb (*lock_list)->ll_children[j] = 78074912Sjhb (*lock_list)->ll_children[j + 1]; 78178785Sjhb critical_exit(s); 78274912Sjhb if ((*lock_list)->ll_count == 0) { 78374912Sjhb lle = *lock_list; 78474912Sjhb *lock_list = lle->ll_next; 78578785Sjhb CTR2(KTR_WITNESS, 78678871Sjhb __func__ ": pid %d removed lle %p", 78778785Sjhb curproc->p_pid, lle); 78874912Sjhb witness_lock_list_free(lle); 78974912Sjhb } 79076272Sjhb goto out; 79174912Sjhb } 79276272Sjhb } 79376272Sjhb panic("lock (%s) %s not locked @ %s:%d", class->lc_name, lock->lo_name, 79476272Sjhb file, line); 79576272Sjhbout: 79676272Sjhb /* 79776272Sjhb * We don't need to protect this PCPU_GET() here against preemption 79876272Sjhb * because if we hold any spinlocks then we are already protected, 79976272Sjhb * and if we don't we will get NULL if we hold no spinlocks even if 80076272Sjhb * we switch CPU's while reading it. 80176272Sjhb */ 80276272Sjhb if (class->lc_flags & LC_SLEEPLOCK) { 80376272Sjhb if ((flags & LOP_NOSWITCH) == 0 && PCPU_GET(spinlocks) != NULL) 80476272Sjhb panic("switchable sleep unlock (%s) %s @ %s:%d", 80576272Sjhb class->lc_name, lock->lo_name, file, line); 80676272Sjhb } 80765557Sjasone} 80865557Sjasone 80974912Sjhb/* 81074912Sjhb * Warn if any held locks are not sleepable. Note that Giant and the lock 81174912Sjhb * passed in are both special cases since they are both released during the 81274912Sjhb * sleep process and aren't actually held while the process is asleep. 81374912Sjhb */ 81465557Sjasoneint 81574912Sjhbwitness_sleep(int check_only, struct lock_object *lock, const char *file, 81674912Sjhb int line) 81765557Sjasone{ 81874912Sjhb struct lock_list_entry **lock_list, *lle; 81976272Sjhb struct lock_instance *lock1; 82065557Sjasone struct proc *p; 82174912Sjhb critical_t savecrit; 82274912Sjhb int i, n; 82365557Sjasone 82480747Sjhb if (witness_dead || panicstr != NULL) 82574912Sjhb return (0); 82674912Sjhb KASSERT(!witness_cold, ("%s: witness_cold\n", __func__)); 82774912Sjhb n = 0; 82874912Sjhb /* 82974912Sjhb * Preemption bad because we need PCPU_PTR(spinlocks) to not change. 83074912Sjhb */ 83174912Sjhb savecrit = critical_enter(); 83272393Sbmilekic p = curproc; 83374912Sjhb lock_list = &p->p_sleeplocks; 83474912Sjhbagain: 83574912Sjhb for (lle = *lock_list; lle != NULL; lle = lle->ll_next) 83674912Sjhb for (i = lle->ll_count - 1; i >= 0; i--) { 83776272Sjhb lock1 = &lle->ll_children[i]; 83876272Sjhb if (lock1->li_lock == lock || 83976272Sjhb lock1->li_lock == &Giant.mtx_object) 84074912Sjhb continue; 84176272Sjhb if ((lock1->li_lock->lo_flags & LO_SLEEPABLE) != 0) { 84278785Sjhb if (check_only == 0) { 84378785Sjhb CTR3(KTR_WITNESS, 84478871Sjhb "pid %d: sleeping with lock (%s) %s held", 84578785Sjhb curproc->p_pid, 84678785Sjhb lock1->li_lock->lo_class->lc_name, 84778785Sjhb lock1->li_lock->lo_name); 84876272Sjhb lock1->li_flags |= LI_SLEPT; 84978785Sjhb } 85076272Sjhb continue; 85176272Sjhb } 85274912Sjhb n++; 85374912Sjhb printf("%s:%d: %s with \"%s\" locked from %s:%d\n", 85474912Sjhb file, line, check_only ? "could sleep" : "sleeping", 85576272Sjhb lock1->li_lock->lo_name, lock1->li_file, 85676272Sjhb lock1->li_line); 85774912Sjhb } 85874912Sjhb if (lock_list == &p->p_sleeplocks) { 85974912Sjhb lock_list = PCPU_PTR(spinlocks); 86074912Sjhb goto again; 86165557Sjasone } 86267676Sjhb#ifdef DDB 86367676Sjhb if (witness_ddb && n) 86475711Sjhb Debugger(__func__); 86567676Sjhb#endif /* DDB */ 86674912Sjhb critical_exit(savecrit); 86765557Sjasone return (n); 86865557Sjasone} 86965557Sjasone 87065856Sjhbstatic struct witness * 87174912Sjhbenroll(const char *description, struct lock_class *lock_class) 87265557Sjasone{ 87374912Sjhb struct witness *w; 87465557Sjasone 87580747Sjhb if (!witness_watch || witness_dead || panicstr != NULL) 87665557Sjasone return (NULL); 87765557Sjasone 87874912Sjhb if ((lock_class->lc_flags & LC_SPINLOCK) && witness_skipspin) 87965557Sjasone return (NULL); 88074912Sjhb mtx_lock_spin(&w_mtx); 88174912Sjhb STAILQ_FOREACH(w, &w_all, w_list) { 88274912Sjhb if (strcmp(description, w->w_name) == 0) { 88375362Sjhb w->w_refcount++; 88474912Sjhb mtx_unlock_spin(&w_mtx); 88574912Sjhb if (lock_class != w->w_class) 88674912Sjhb panic( 88774912Sjhb "lock (%s) %s does not match earlier (%s) lock", 88874912Sjhb description, lock_class->lc_name, 88974912Sjhb w->w_class->lc_name); 89065557Sjasone return (w); 89165557Sjasone } 89265557Sjasone } 89374912Sjhb /* 89474912Sjhb * This isn't quite right, as witness_cold is still 0 while we 89574912Sjhb * enroll all the locks initialized before witness_initialize(). 89674912Sjhb */ 89775364Sbp if ((lock_class->lc_flags & LC_SPINLOCK) && !witness_cold) { 89875364Sbp mtx_unlock_spin(&w_mtx); 89974912Sjhb panic("spin lock %s not in order list", description); 90075364Sbp } 90165557Sjasone if ((w = witness_get()) == NULL) 90265557Sjasone return (NULL); 90374912Sjhb w->w_name = description; 90474912Sjhb w->w_class = lock_class; 90575362Sjhb w->w_refcount = 1; 90674912Sjhb STAILQ_INSERT_HEAD(&w_all, w, w_list); 90774912Sjhb if (lock_class->lc_flags & LC_SPINLOCK) 90874912Sjhb STAILQ_INSERT_HEAD(&w_spin, w, w_typelist); 90974912Sjhb else if (lock_class->lc_flags & LC_SLEEPLOCK) 91074912Sjhb STAILQ_INSERT_HEAD(&w_sleep, w, w_typelist); 91175364Sbp else { 91275364Sbp mtx_unlock_spin(&w_mtx); 91374912Sjhb panic("lock class %s is not sleep or spin", 91474912Sjhb lock_class->lc_name); 91575364Sbp } 91674912Sjhb mtx_unlock_spin(&w_mtx); 91771228Sbmilekic 91865557Sjasone return (w); 91965557Sjasone} 92065557Sjasone 92165557Sjasonestatic int 92265856Sjhbitismychild(struct witness *parent, struct witness *child) 92365557Sjasone{ 92465557Sjasone static int recursed; 92574912Sjhb struct witness_child_list_entry **wcl; 92674912Sjhb struct witness_list *list; 92765557Sjasone 92874912Sjhb MPASS(child != NULL && parent != NULL); 92974912Sjhb if ((parent->w_class->lc_flags & (LC_SLEEPLOCK | LC_SPINLOCK)) != 93074912Sjhb (child->w_class->lc_flags & (LC_SLEEPLOCK | LC_SPINLOCK))) 93174912Sjhb panic( 93274912Sjhb "%s: parent (%s) and child (%s) are not the same lock type", 93374912Sjhb __func__, parent->w_class->lc_name, 93474912Sjhb child->w_class->lc_name); 93574912Sjhb 93665557Sjasone /* 93765557Sjasone * Insert "child" after "parent" 93865557Sjasone */ 93974912Sjhb wcl = &parent->w_children; 94074912Sjhb while (*wcl != NULL && (*wcl)->wcl_count == WITNESS_NCHILDREN) 94174912Sjhb wcl = &(*wcl)->wcl_next; 94265557Sjasone 94374912Sjhb if (*wcl == NULL) { 94474912Sjhb *wcl = witness_child_get(); 94574912Sjhb if (*wcl == NULL) 94665557Sjasone return (1); 94765557Sjasone } 94874912Sjhb 94974912Sjhb (*wcl)->wcl_children[(*wcl)->wcl_count++] = child; 95074912Sjhb 95165557Sjasone /* 95274912Sjhb * Now prune whole tree. We look for cases where a lock is now 95374912Sjhb * both a descendant and a direct child of a given lock. In that 95474912Sjhb * case, we want to remove the direct child link from the tree. 95565557Sjasone */ 95665557Sjasone if (recursed) 95765557Sjasone return (0); 95865557Sjasone recursed = 1; 95974912Sjhb if (parent->w_class->lc_flags & LC_SLEEPLOCK) 96074912Sjhb list = &w_sleep; 96174912Sjhb else 96274912Sjhb list = &w_spin; 96374912Sjhb STAILQ_FOREACH(child, list, w_typelist) { 96474912Sjhb STAILQ_FOREACH(parent, list, w_typelist) { 96565557Sjasone if (!isitmychild(parent, child)) 96665557Sjasone continue; 96765557Sjasone removechild(parent, child); 96865557Sjasone if (isitmydescendant(parent, child)) 96965557Sjasone continue; 97065557Sjasone itismychild(parent, child); 97165557Sjasone } 97265557Sjasone } 97365557Sjasone recursed = 0; 97465557Sjasone witness_levelall(); 97565557Sjasone return (0); 97665557Sjasone} 97765557Sjasone 97865557Sjasonestatic void 97965856Sjhbremovechild(struct witness *parent, struct witness *child) 98065557Sjasone{ 98174912Sjhb struct witness_child_list_entry **wcl, *wcl1; 98265557Sjasone int i; 98365557Sjasone 98474912Sjhb for (wcl = &parent->w_children; *wcl != NULL; wcl = &(*wcl)->wcl_next) 98574912Sjhb for (i = 0; i < (*wcl)->wcl_count; i++) 98674912Sjhb if ((*wcl)->wcl_children[i] == child) 98765557Sjasone goto found; 98865557Sjasone return; 98965557Sjasonefound: 99074912Sjhb (*wcl)->wcl_count--; 99174912Sjhb if ((*wcl)->wcl_count > i) 99274912Sjhb (*wcl)->wcl_children[i] = 99374912Sjhb (*wcl)->wcl_children[(*wcl)->wcl_count]; 99474912Sjhb MPASS((*wcl)->wcl_children[i] != NULL); 99565557Sjasone 99674912Sjhb if ((*wcl)->wcl_count != 0) 99765557Sjasone return; 99865557Sjasone 99974912Sjhb wcl1 = *wcl; 100074912Sjhb *wcl = wcl1->wcl_next; 100174912Sjhb witness_child_free(wcl1); 100265557Sjasone} 100365557Sjasone 100465557Sjasonestatic int 100565856Sjhbisitmychild(struct witness *parent, struct witness *child) 100665557Sjasone{ 100774912Sjhb struct witness_child_list_entry *wcl; 100865557Sjasone int i; 100965557Sjasone 101074912Sjhb for (wcl = parent->w_children; wcl != NULL; wcl = wcl->wcl_next) { 101174912Sjhb for (i = 0; i < wcl->wcl_count; i++) { 101274912Sjhb if (wcl->wcl_children[i] == child) 101365557Sjasone return (1); 101465557Sjasone } 101565557Sjasone } 101665557Sjasone return (0); 101765557Sjasone} 101865557Sjasone 101965557Sjasonestatic int 102065856Sjhbisitmydescendant(struct witness *parent, struct witness *child) 102165557Sjasone{ 102274912Sjhb struct witness_child_list_entry *wcl; 102374912Sjhb int i, j; 102465557Sjasone 102574912Sjhb if (isitmychild(parent, child)) 102674912Sjhb return (1); 102774912Sjhb j = 0; 102874912Sjhb for (wcl = parent->w_children; wcl != NULL; wcl = wcl->wcl_next) { 102967352Sjhb MPASS(j < 1000); 103074912Sjhb for (i = 0; i < wcl->wcl_count; i++) { 103174912Sjhb if (isitmydescendant(wcl->wcl_children[i], child)) 103265557Sjasone return (1); 103365557Sjasone } 103474912Sjhb j++; 103565557Sjasone } 103665557Sjasone return (0); 103765557Sjasone} 103865557Sjasone 103965557Sjasonevoid 104065557Sjasonewitness_levelall (void) 104165557Sjasone{ 104274912Sjhb struct witness_list *list; 104365856Sjhb struct witness *w, *w1; 104465557Sjasone 104574912Sjhb /* 104674912Sjhb * First clear all levels. 104774912Sjhb */ 104874912Sjhb STAILQ_FOREACH(w, &w_all, w_list) { 104974912Sjhb w->w_level = 0; 105074912Sjhb } 105174912Sjhb 105274912Sjhb /* 105374912Sjhb * Look for locks with no parent and level all their descendants. 105474912Sjhb */ 105574912Sjhb STAILQ_FOREACH(w, &w_all, w_list) { 105674912Sjhb /* 105774912Sjhb * This is just an optimization, technically we could get 105874912Sjhb * away just walking the all list each time. 105974912Sjhb */ 106074912Sjhb if (w->w_class->lc_flags & LC_SLEEPLOCK) 106174912Sjhb list = &w_sleep; 106274912Sjhb else 106374912Sjhb list = &w_spin; 106474912Sjhb STAILQ_FOREACH(w1, list, w_typelist) { 106565557Sjasone if (isitmychild(w1, w)) 106674912Sjhb goto skip; 106765557Sjasone } 106865557Sjasone witness_leveldescendents(w, 0); 106974912Sjhb skip: 107065557Sjasone } 107165557Sjasone} 107265557Sjasone 107365557Sjasonestatic void 107465856Sjhbwitness_leveldescendents(struct witness *parent, int level) 107565557Sjasone{ 107674912Sjhb struct witness_child_list_entry *wcl; 107765557Sjasone int i; 107865557Sjasone 107965557Sjasone if (parent->w_level < level) 108065557Sjasone parent->w_level = level; 108165557Sjasone level++; 108274912Sjhb for (wcl = parent->w_children; wcl != NULL; wcl = wcl->wcl_next) 108374912Sjhb for (i = 0; i < wcl->wcl_count; i++) 108474912Sjhb witness_leveldescendents(wcl->wcl_children[i], level); 108565557Sjasone} 108665557Sjasone 108765557Sjasonestatic void 108865856Sjhbwitness_displaydescendants(void(*prnt)(const char *fmt, ...), 108965856Sjhb struct witness *parent) 109065557Sjasone{ 109174912Sjhb struct witness_child_list_entry *wcl; 109274912Sjhb int i, level; 109365557Sjasone 109474912Sjhb level = parent->w_level; 109572224Sjhb 109674912Sjhb prnt("%-2d", level); 109765557Sjasone for (i = 0; i < level; i++) 109865557Sjasone prnt(" "); 109974912Sjhb prnt("%s", parent->w_name); 110072224Sjhb if (parent->w_file != NULL) 110172224Sjhb prnt(" -- last acquired @ %s:%d\n", parent->w_file, 110272224Sjhb parent->w_line); 110365557Sjasone 110474912Sjhb for (wcl = parent->w_children; wcl != NULL; wcl = wcl->wcl_next) 110574912Sjhb for (i = 0; i < wcl->wcl_count; i++) 110674912Sjhb witness_displaydescendants(prnt, 110774912Sjhb wcl->wcl_children[i]); 110874912Sjhb} 110965557Sjasone 111065557Sjasonestatic int 111165856Sjhbdup_ok(struct witness *w) 111265557Sjasone{ 111374912Sjhb const char **dup; 111465557Sjasone 111574912Sjhb for (dup = dup_list; *dup != NULL; dup++) 111674912Sjhb if (strcmp(w->w_name, *dup) == 0) 111765557Sjasone return (1); 111865557Sjasone return (0); 111965557Sjasone} 112065557Sjasone 112165557Sjasonestatic int 112265856Sjhbblessed(struct witness *w1, struct witness *w2) 112365557Sjasone{ 112465557Sjasone int i; 112565856Sjhb struct witness_blessed *b; 112665557Sjasone 112765557Sjasone for (i = 0; i < blessed_count; i++) { 112865557Sjasone b = &blessed_list[i]; 112974912Sjhb if (strcmp(w1->w_name, b->b_lock1) == 0) { 113074912Sjhb if (strcmp(w2->w_name, b->b_lock2) == 0) 113165557Sjasone return (1); 113265557Sjasone continue; 113365557Sjasone } 113474912Sjhb if (strcmp(w1->w_name, b->b_lock2) == 0) 113574912Sjhb if (strcmp(w2->w_name, b->b_lock1) == 0) 113665557Sjasone return (1); 113765557Sjasone } 113865557Sjasone return (0); 113965557Sjasone} 114065557Sjasone 114165856Sjhbstatic struct witness * 114274912Sjhbwitness_get(void) 114365557Sjasone{ 114465856Sjhb struct witness *w; 114565557Sjasone 114676481Sjhb if (witness_dead) { 114776481Sjhb mtx_unlock_spin(&w_mtx); 114876481Sjhb return (NULL); 114976481Sjhb } 115074912Sjhb if (STAILQ_EMPTY(&w_free)) { 115165557Sjasone witness_dead = 1; 115274912Sjhb mtx_unlock_spin(&w_mtx); 115374912Sjhb printf("%s: witness exhausted\n", __func__); 115465557Sjasone return (NULL); 115565557Sjasone } 115674912Sjhb w = STAILQ_FIRST(&w_free); 115774912Sjhb STAILQ_REMOVE_HEAD(&w_free, w_list); 115865856Sjhb bzero(w, sizeof(*w)); 115965557Sjasone return (w); 116065557Sjasone} 116165557Sjasone 116265557Sjasonestatic void 116365856Sjhbwitness_free(struct witness *w) 116465557Sjasone{ 116574912Sjhb 116674912Sjhb STAILQ_INSERT_HEAD(&w_free, w, w_list); 116765557Sjasone} 116865557Sjasone 116974912Sjhbstatic struct witness_child_list_entry * 117074912Sjhbwitness_child_get(void) 117165557Sjasone{ 117274912Sjhb struct witness_child_list_entry *wcl; 117365557Sjasone 117476481Sjhb if (witness_dead) { 117576481Sjhb mtx_unlock_spin(&w_mtx); 117676481Sjhb return (NULL); 117776481Sjhb } 117874912Sjhb wcl = w_child_free; 117974912Sjhb if (wcl == NULL) { 118074912Sjhb witness_dead = 1; 118174912Sjhb mtx_unlock_spin(&w_mtx); 118274912Sjhb printf("%s: witness exhausted\n", __func__); 118374912Sjhb return (NULL); 118465557Sjasone } 118574912Sjhb w_child_free = wcl->wcl_next; 118674912Sjhb bzero(wcl, sizeof(*wcl)); 118774912Sjhb return (wcl); 118874912Sjhb} 118969881Sjake 119074912Sjhbstatic void 119174912Sjhbwitness_child_free(struct witness_child_list_entry *wcl) 119274912Sjhb{ 119374912Sjhb 119474912Sjhb wcl->wcl_next = w_child_free; 119574912Sjhb w_child_free = wcl; 119665557Sjasone} 119765557Sjasone 119874912Sjhbstatic struct lock_list_entry * 119974912Sjhbwitness_lock_list_get(void) 120074912Sjhb{ 120174912Sjhb struct lock_list_entry *lle; 120271709Sjhb 120376481Sjhb if (witness_dead) 120476481Sjhb return (NULL); 120574912Sjhb mtx_lock_spin(&w_mtx); 120674912Sjhb lle = w_lock_list_free; 120774912Sjhb if (lle == NULL) { 120874912Sjhb witness_dead = 1; 120974912Sjhb mtx_unlock_spin(&w_mtx); 121074912Sjhb printf("%s: witness exhausted\n", __func__); 121174912Sjhb return (NULL); 121274912Sjhb } 121374912Sjhb w_lock_list_free = lle->ll_next; 121474912Sjhb mtx_unlock_spin(&w_mtx); 121574912Sjhb bzero(lle, sizeof(*lle)); 121674912Sjhb return (lle); 121774912Sjhb} 121874912Sjhb 121974912Sjhbstatic void 122074912Sjhbwitness_lock_list_free(struct lock_list_entry *lle) 122171709Sjhb{ 122271709Sjhb 122374912Sjhb mtx_lock_spin(&w_mtx); 122474912Sjhb lle->ll_next = w_lock_list_free; 122574912Sjhb w_lock_list_free = lle; 122674912Sjhb mtx_unlock_spin(&w_mtx); 122771709Sjhb} 122871709Sjhb 122976272Sjhbstatic struct lock_instance * 123076272Sjhbfind_instance(struct lock_list_entry *lock_list, struct lock_object *lock) 123176272Sjhb{ 123276272Sjhb struct lock_list_entry *lle; 123376272Sjhb struct lock_instance *instance; 123476272Sjhb int i; 123576272Sjhb 123676272Sjhb for (lle = lock_list; lle != NULL; lle = lle->ll_next) 123776272Sjhb for (i = lle->ll_count - 1; i >= 0; i--) { 123876272Sjhb instance = &lle->ll_children[i]; 123976272Sjhb if (instance->li_lock == lock) 124076272Sjhb return (instance); 124176272Sjhb } 124276272Sjhb return (NULL); 124376272Sjhb} 124476272Sjhb 124574912Sjhbint 124675273Sjhbwitness_list_locks(struct lock_list_entry **lock_list) 124772224Sjhb{ 124875273Sjhb struct lock_list_entry *lle; 124976272Sjhb struct lock_instance *instance; 125074912Sjhb struct lock_object *lock; 125174912Sjhb int i, nheld; 125272224Sjhb 125374912Sjhb nheld = 0; 125474912Sjhb for (lle = *lock_list; lle != NULL; lle = lle->ll_next) 125574912Sjhb for (i = lle->ll_count - 1; i >= 0; i--) { 125676272Sjhb instance = &lle->ll_children[i]; 125776272Sjhb lock = instance->li_lock; 125876272Sjhb printf("%s (%s) %s (%p) locked @ %s:%d\n", 125976272Sjhb (instance->li_flags & LI_EXCLUSIVE) != 0 ? 126076272Sjhb "exclusive" : "shared", 126174912Sjhb lock->lo_class->lc_name, lock->lo_name, lock, 126276272Sjhb instance->li_file, instance->li_line); 126374912Sjhb nheld++; 126474912Sjhb } 126575273Sjhb return (nheld); 126675273Sjhb} 126775273Sjhb 126875273Sjhb/* 126975273Sjhb * Calling this on p != curproc is bad unless we are in ddb. 127075273Sjhb */ 127175273Sjhbint 127275273Sjhbwitness_list(struct proc *p) 127375273Sjhb{ 127475273Sjhb critical_t savecrit; 127575273Sjhb int nheld; 127675273Sjhb 127781489Sjhb KASSERT(!witness_cold, ("%s: witness_cold", __func__)); 127881489Sjhb#ifdef DDB 127975273Sjhb KASSERT(p == curproc || db_active, 128075273Sjhb ("%s: p != curproc and we aren't in the debugger", __func__)); 128175273Sjhb 128276481Sjhb if (!db_active && witness_dead) 128376481Sjhb return (0); 128481489Sjhb#else 128581489Sjhb KASSERT(p == curproc, ("%s: p != curproc", __func__)); 128676481Sjhb 128781489Sjhb if (witness_dead) 128881489Sjhb return (0); 128981489Sjhb#endif 129075273Sjhb nheld = witness_list_locks(&p->p_sleeplocks); 129175273Sjhb 129274912Sjhb /* 129374912Sjhb * We only handle spinlocks if p == curproc. This is somewhat broken 129474912Sjhb * if p is currently executing on some other CPU and holds spin locks 129575273Sjhb * as we won't display those locks. If we had a MI way of getting 129675273Sjhb * the per-cpu data for a given cpu then we could use p->p_oncpu to 129775273Sjhb * get the list of spinlocks for this process and "fix" this. 129874912Sjhb */ 129975273Sjhb if (p == curproc) { 130075273Sjhb /* 130175273Sjhb * Preemption bad because we need PCPU_PTR(spinlocks) to not 130275273Sjhb * change. 130375273Sjhb */ 130475273Sjhb savecrit = critical_enter(); 130575273Sjhb nheld += witness_list_locks(PCPU_PTR(spinlocks)); 130675273Sjhb critical_exit(savecrit); 130774912Sjhb } 130874912Sjhb 130974912Sjhb return (nheld); 131072224Sjhb} 131171709Sjhb 131265557Sjasonevoid 131374912Sjhbwitness_save(struct lock_object *lock, const char **filep, int *linep) 131465557Sjasone{ 131576272Sjhb struct lock_instance *instance; 131671320Sjasone 131774912Sjhb KASSERT(!witness_cold, ("%s: witness_cold\n", __func__)); 131880747Sjhb if (lock->lo_witness == NULL || witness_dead || panicstr != NULL) 131971352Sjasone return; 132071352Sjasone 132176272Sjhb KASSERT(lock->lo_class->lc_flags & LC_SLEEPLOCK, 132276272Sjhb ("%s: lock (%s) %s is not a sleep lock", __func__, 132376272Sjhb lock->lo_class->lc_name, lock->lo_name)); 132476272Sjhb instance = find_instance(curproc->p_sleeplocks, lock); 132576272Sjhb KASSERT(instance != NULL, ("%s: lock (%s) %s not locked", __func__, 132676272Sjhb lock->lo_class->lc_name, lock->lo_name)); 132776272Sjhb 132876272Sjhb *filep = instance->li_file; 132976272Sjhb *linep = instance->li_line; 133065557Sjasone} 133165557Sjasone 133265557Sjasonevoid 133374912Sjhbwitness_restore(struct lock_object *lock, const char *file, int line) 133465557Sjasone{ 133576272Sjhb struct lock_instance *instance; 133671320Sjasone 133774912Sjhb KASSERT(!witness_cold, ("%s: witness_cold\n", __func__)); 133880747Sjhb if (lock->lo_witness == NULL || witness_dead || panicstr != NULL) 133971352Sjasone return; 134071352Sjasone 134176272Sjhb KASSERT(lock->lo_class->lc_flags & LC_SLEEPLOCK, 134276272Sjhb ("%s: lock (%s) %s is not a sleep lock", __func__, 134376272Sjhb lock->lo_class->lc_name, lock->lo_name)); 134476272Sjhb instance = find_instance(curproc->p_sleeplocks, lock); 134576272Sjhb KASSERT(instance != NULL, ("%s: lock (%s) %s not locked", __func__, 134676272Sjhb lock->lo_class->lc_name, lock->lo_name)); 134776272Sjhb 134874912Sjhb lock->lo_witness->w_file = file; 134974912Sjhb lock->lo_witness->w_line = line; 135076272Sjhb instance->li_file = file; 135176272Sjhb instance->li_line = line; 135265557Sjasone} 135365557Sjasone 135478871Sjhbvoid 135578871Sjhbwitness_assert(struct lock_object *lock, int flags, const char *file, int line) 135678871Sjhb{ 135778871Sjhb#ifdef INVARIANT_SUPPORT 135878871Sjhb struct lock_instance *instance; 135978871Sjhb 136080747Sjhb if (lock->lo_witness == NULL || witness_dead || panicstr != NULL) 136178941Sjhb return; 136278941Sjhb 136378871Sjhb if ((lock->lo_class->lc_flags & LC_SLEEPLOCK) != 0) 136478871Sjhb instance = find_instance(curproc->p_sleeplocks, lock); 136578871Sjhb else if ((lock->lo_class->lc_flags & LC_SPINLOCK) != 0) 136678871Sjhb instance = find_instance(PCPU_GET(spinlocks), lock); 136778871Sjhb else 136878871Sjhb panic("Lock (%s) %s is not sleep or spin!", 136978871Sjhb lock->lo_class->lc_name, lock->lo_name); 137078871Sjhb switch (flags) { 137178871Sjhb case LA_UNLOCKED: 137278871Sjhb if (instance != NULL) 137378871Sjhb panic("Lock (%s) %s locked @ %s:%d.", 137478871Sjhb lock->lo_class->lc_name, lock->lo_name, file, line); 137578871Sjhb break; 137678871Sjhb case LA_LOCKED: 137778871Sjhb case LA_LOCKED | LA_RECURSED: 137878871Sjhb case LA_LOCKED | LA_NOTRECURSED: 137978871Sjhb case LA_SLOCKED: 138078871Sjhb case LA_SLOCKED | LA_RECURSED: 138178871Sjhb case LA_SLOCKED | LA_NOTRECURSED: 138278871Sjhb case LA_XLOCKED: 138378871Sjhb case LA_XLOCKED | LA_RECURSED: 138478871Sjhb case LA_XLOCKED | LA_NOTRECURSED: 138578871Sjhb if (instance == NULL) 138678871Sjhb panic("Lock (%s) %s not locked @ %s:%d.", 138778871Sjhb lock->lo_class->lc_name, lock->lo_name, file, line); 138878871Sjhb if ((flags & LA_XLOCKED) != 0 && 138978871Sjhb (instance->li_flags & LI_EXCLUSIVE) == 0) 139078871Sjhb panic("Lock (%s) %s not exclusively locked @ %s:%d.", 139178871Sjhb lock->lo_class->lc_name, lock->lo_name, file, line); 139278871Sjhb if ((flags & LA_SLOCKED) != 0 && 139378871Sjhb (instance->li_flags & LI_EXCLUSIVE) != 0) 139478871Sjhb panic("Lock (%s) %s exclusively locked @ %s:%d.", 139578871Sjhb lock->lo_class->lc_name, lock->lo_name, file, line); 139678871Sjhb if ((flags & LA_RECURSED) != 0 && 139778871Sjhb (instance->li_flags & LI_RECURSEMASK) == 0) 139878871Sjhb panic("Lock (%s) %s not recursed @ %s:%d.", 139978871Sjhb lock->lo_class->lc_name, lock->lo_name, file, line); 140078871Sjhb if ((flags & LA_NOTRECURSED) != 0 && 140178871Sjhb (instance->li_flags & LI_RECURSEMASK) != 0) 140278871Sjhb panic("Lock (%s) %s recursed @ %s:%d.", 140378871Sjhb lock->lo_class->lc_name, lock->lo_name, file, line); 140478871Sjhb break; 140578871Sjhb default: 140678871Sjhb panic("Invalid lock assertion at %s:%d.", file, line); 140778871Sjhb 140878871Sjhb } 140978871Sjhb#endif /* INVARIANT_SUPPORT */ 141078871Sjhb} 141178871Sjhb 141274912Sjhb#ifdef DDB 141374912Sjhb 141474930SjhbDB_SHOW_COMMAND(locks, db_witness_list) 141574912Sjhb{ 141675273Sjhb struct proc *p; 141775273Sjhb pid_t pid; 141874912Sjhb 141975273Sjhb if (have_addr) { 142075273Sjhb pid = (addr % 16) + ((addr >> 4) % 16) * 10 + 142175273Sjhb ((addr >> 8) % 16) * 100 + ((addr >> 12) % 16) * 1000 + 142275273Sjhb ((addr >> 16) % 16) * 10000; 142375273Sjhb 142475273Sjhb /* sx_slock(&allproc_lock); */ 142575273Sjhb LIST_FOREACH(p, &allproc, p_list) { 142675273Sjhb if (p->p_pid == pid) 142775273Sjhb break; 142875273Sjhb } 142975273Sjhb /* sx_sunlock(&allproc_lock); */ 143075273Sjhb if (p == NULL) { 143175273Sjhb db_printf("pid %d not found\n", pid); 143275273Sjhb return; 143375273Sjhb } 143475273Sjhb } else 143575273Sjhb p = curproc; 143675273Sjhb 143775273Sjhb witness_list(p); 143874912Sjhb} 143974912Sjhb 144074912SjhbDB_SHOW_COMMAND(witness, db_witness_display) 144174912Sjhb{ 144274912Sjhb 144374912Sjhb witness_display(db_printf); 144474912Sjhb} 144574912Sjhb#endif 1446