Catch a leaked hold of kernel_lock sooner with DIAGNOSTIC and make the

message a bit more informative.
This commit is contained in:
ad 2020-01-22 12:23:04 +00:00
parent 4e19d93e81
commit 20f33b0230
3 changed files with 13 additions and 10 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_exit.c,v 1.279 2020/01/08 17:38:42 ad Exp $ */
/* $NetBSD: kern_exit.c,v 1.280 2020/01/22 12:23:04 ad Exp $ */
/*-
* Copyright (c) 1998, 1999, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.279 2020/01/08 17:38:42 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.280 2020/01/22 12:23:04 ad Exp $");
#include "opt_ktrace.h"
#include "opt_dtrace.h"
@ -206,6 +206,7 @@ exit1(struct lwp *l, int exitcode, int signo)
/* Verify that we hold no locks other than p->p_lock. */
LOCKDEBUG_BARRIER(p->p_lock, 0);
KASSERTMSG(curcpu()->ci_biglock_count == 0, "kernel_lock leaked");
KASSERT(mutex_owned(p->p_lock));
KASSERT(p->p_vmspace != NULL);

View File

@ -1,7 +1,8 @@
/* $NetBSD: kern_lwp.c,v 1.219 2020/01/12 13:15:08 ad Exp $ */
/* $NetBSD: kern_lwp.c,v 1.220 2020/01/22 12:23:04 ad Exp $ */
/*-
* Copyright (c) 2001, 2006, 2007, 2008, 2009, 2019 The NetBSD Foundation, Inc.
* Copyright (c) 2001, 2006, 2007, 2008, 2009, 2019, 2020
* The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@ -209,7 +210,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.219 2020/01/12 13:15:08 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.220 2020/01/22 12:23:04 ad Exp $");
#include "opt_ddb.h"
#include "opt_lockdebug.h"
@ -1063,8 +1064,9 @@ lwp_exit(struct lwp *l)
SDT_PROBE(proc, kernel, , lwp__exit, l, 0, 0, 0, 0);
/* Verify that we hold no locks */
/* Verify that we hold no locks; for DIAGNOSTIC check kernel_lock. */
LOCKDEBUG_BARRIER(NULL, 0);
KASSERTMSG(curcpu()->ci_biglock_count == 0, "kernel_lock leaked");
/*
* If we are the last live LWP in a process, we need to exit the
@ -1080,7 +1082,6 @@ lwp_exit(struct lwp *l)
if (p->p_nlwps - p->p_nzlwps == 1) {
KASSERT(current == true);
KASSERT(p != &proc0);
/* XXXSMP kernel_lock not held */
exit1(l, 0, 0);
/* NOTREACHED */
}

View File

@ -1,7 +1,8 @@
/* $NetBSD: userret.h,v 1.31 2019/11/30 17:49:03 ad Exp $ */
/* $NetBSD: userret.h,v 1.32 2020/01/22 12:23:04 ad Exp $ */
/*-
* Copyright (c) 1998, 2000, 2003, 2006, 2008, 2019 The NetBSD Foundation, Inc.
* Copyright (c) 1998, 2000, 2003, 2006, 2008, 2019, 2020
* The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@ -84,8 +85,8 @@ mi_userret(struct lwp *l)
KPREEMPT_DISABLE(l);
ci = l->l_cpu;
KASSERTMSG(ci->ci_biglock_count == 0, "kernel_lock leaked");
KASSERT(l->l_blcnt == 0);
KASSERT(ci->ci_biglock_count == 0);
if (__predict_false(ci->ci_want_resched)) {
preempt();
ci = l->l_cpu;