Module Name: src Committed By: riastradh Date: Wed Mar 30 17:02:02 UTC 2022
Modified Files: src/sys/kern: kern_softint.c kern_timeout.c Log Message: kern: Assert softint does not net acquire kernel locks. This redoes previous change where I mistakenly used the CPU's biglock count, which is not necessarily stable -- the softint lwp may sleep on a mutex, and the lwp it interrupted may start up again and release the kernel lock, so by the time the softint lwp wakes up again and the softint function returns, the CPU may not be holding any kernel locks. But the softint lwp should never hold kernel locks except when it's in a (usually, non-MPSAFE) softint function. Same with callout. To generate a diff of this commit: cvs rdiff -u -r1.69 -r1.70 src/sys/kern/kern_softint.c cvs rdiff -u -r1.68 -r1.69 src/sys/kern/kern_timeout.c 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_softint.c diff -u src/sys/kern/kern_softint.c:1.69 src/sys/kern/kern_softint.c:1.70 --- src/sys/kern/kern_softint.c:1.69 Wed Mar 30 14:54:29 2022 +++ src/sys/kern/kern_softint.c Wed Mar 30 17:02:02 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_softint.c,v 1.69 2022/03/30 14:54:29 riastradh Exp $ */ +/* $NetBSD: kern_softint.c,v 1.70 2022/03/30 17:02:02 riastradh Exp $ */ /*- * Copyright (c) 2007, 2008, 2019, 2020 The NetBSD Foundation, Inc. @@ -170,7 +170,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: kern_softint.c,v 1.69 2022/03/30 14:54:29 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_softint.c,v 1.70 2022/03/30 17:02:02 riastradh Exp $"); #include <sys/param.h> #include <sys/proc.h> @@ -576,6 +576,10 @@ softint_execute(lwp_t *l, int s) /* Diagnostic: check that psrefs have not leaked. */ KASSERTMSG(l->l_psrefs == 0, "%s: l_psrefs=%d, sh_func=%p\n", __func__, l->l_psrefs, sh->sh_func); + /* Diagnostic: check that biglocks have not leaked. */ + KASSERTMSG(l->l_blcnt == 0, + "%s: sh_func=%p leaked %d biglocks", + __func__, sh->sh_func, curlwp->l_blcnt); (void)splhigh(); } Index: src/sys/kern/kern_timeout.c diff -u src/sys/kern/kern_timeout.c:1.68 src/sys/kern/kern_timeout.c:1.69 --- src/sys/kern/kern_timeout.c:1.68 Wed Mar 30 14:54:29 2022 +++ src/sys/kern/kern_timeout.c Wed Mar 30 17:02:02 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_timeout.c,v 1.68 2022/03/30 14:54:29 riastradh Exp $ */ +/* $NetBSD: kern_timeout.c,v 1.69 2022/03/30 17:02:02 riastradh Exp $ */ /*- * Copyright (c) 2003, 2006, 2007, 2008, 2009, 2019 The NetBSD Foundation, Inc. @@ -59,7 +59,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: kern_timeout.c,v 1.68 2022/03/30 14:54:29 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_timeout.c,v 1.69 2022/03/30 17:02:02 riastradh Exp $"); /* * Timeouts are kept in a hierarchical timing wheel. The c_time is the @@ -783,6 +783,9 @@ callout_softclock(void *v) KERNEL_UNLOCK_ONE(NULL); } else (*func)(arg); + KASSERTMSG(l->l_blcnt == 0, + "callout %p func %p leaked %d biglocks", + c, func, l->l_blcnt); mutex_spin_enter(cc->cc_lock); /*