Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern kern: Assert softint does not net acquire kernel lo...



details:   https://anonhg.NetBSD.org/src/rev/6db0ac4ba55a
branches:  trunk
changeset: 364585:6db0ac4ba55a
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Wed Mar 30 17:02:02 2022 +0000

description:
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.

diffstat:

 sys/kern/kern_softint.c |  8 ++++++--
 sys/kern/kern_timeout.c |  7 +++++--
 2 files changed, 11 insertions(+), 4 deletions(-)

diffs (57 lines):

diff -r 8d0556b36e5b -r 6db0ac4ba55a sys/kern/kern_softint.c
--- a/sys/kern/kern_softint.c   Wed Mar 30 16:35:28 2022 +0000
+++ b/sys/kern/kern_softint.c   Wed Mar 30 17:02:02 2022 +0000
@@ -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 @@
                /* 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();
        }
diff -r 8d0556b36e5b -r 6db0ac4ba55a sys/kern/kern_timeout.c
--- a/sys/kern/kern_timeout.c   Wed Mar 30 16:35:28 2022 +0000
+++ b/sys/kern/kern_timeout.c   Wed Mar 30 17:02:02 2022 +0000
@@ -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 @@
                        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);
 
                /*



Home | Main Index | Thread Index | Old Index