Module Name: src Committed By: ad Date: Wed Jan 22 12:23:04 UTC 2020
Modified Files: src/sys/kern: kern_exit.c kern_lwp.c src/sys/sys: userret.h Log Message: Catch a leaked hold of kernel_lock sooner with DIAGNOSTIC and make the message a bit more informative. To generate a diff of this commit: cvs rdiff -u -r1.279 -r1.280 src/sys/kern/kern_exit.c cvs rdiff -u -r1.219 -r1.220 src/sys/kern/kern_lwp.c cvs rdiff -u -r1.31 -r1.32 src/sys/sys/userret.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/kern_exit.c diff -u src/sys/kern/kern_exit.c:1.279 src/sys/kern/kern_exit.c:1.280 --- src/sys/kern/kern_exit.c:1.279 Wed Jan 8 17:38:42 2020 +++ src/sys/kern/kern_exit.c Wed Jan 22 12:23:04 2020 @@ -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 s /* 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); Index: src/sys/kern/kern_lwp.c diff -u src/sys/kern/kern_lwp.c:1.219 src/sys/kern/kern_lwp.c:1.220 --- src/sys/kern/kern_lwp.c:1.219 Sun Jan 12 13:15:08 2020 +++ src/sys/kern/kern_lwp.c Wed Jan 22 12:23:04 2020 @@ -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 */ } Index: src/sys/sys/userret.h diff -u src/sys/sys/userret.h:1.31 src/sys/sys/userret.h:1.32 --- src/sys/sys/userret.h:1.31 Sat Nov 30 17:49:03 2019 +++ src/sys/sys/userret.h Wed Jan 22 12:23:04 2020 @@ -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;