Sun Mar 8 15:05:18 2020 UTC ()
Kill off kernel_lock_plug_leak(), and go back to dropping kernel_lock in
exit1(), since there seems little hope of finding the leaking code any
time soon.  Can still be caught with LOCKDEBUG.


(ad)
diff -r1.284 -r1.285 src/sys/kern/kern_exit.c
diff -r1.169 -r1.170 src/sys/kern/kern_lock.c
diff -r1.61 -r1.62 src/sys/kern/kern_softint.c
diff -r1.88 -r1.89 src/sys/sys/lock.h

cvs diff -r1.284 -r1.285 src/sys/kern/kern_exit.c (expand / switch to unified diff)

--- src/sys/kern/kern_exit.c 2020/02/22 21:07:46 1.284
+++ src/sys/kern/kern_exit.c 2020/03/08 15:05:18 1.285
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: kern_exit.c,v 1.284 2020/02/22 21:07:46 ad Exp $ */ 1/* $NetBSD: kern_exit.c,v 1.285 2020/03/08 15:05:18 ad Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1998, 1999, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998, 1999, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center, and by Andrew Doran. 9 * NASA Ames Research Center, and by Andrew Doran.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -57,27 +57,27 @@ @@ -57,27 +57,27 @@
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE. 64 * SUCH DAMAGE.
65 * 65 *
66 * @(#)kern_exit.c 8.10 (Berkeley) 2/23/95 66 * @(#)kern_exit.c 8.10 (Berkeley) 2/23/95
67 */ 67 */
68 68
69#include <sys/cdefs.h> 69#include <sys/cdefs.h>
70__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.284 2020/02/22 21:07:46 ad Exp $"); 70__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.285 2020/03/08 15:05:18 ad Exp $");
71 71
72#include "opt_ktrace.h" 72#include "opt_ktrace.h"
73#include "opt_dtrace.h" 73#include "opt_dtrace.h"
74#include "opt_sysv.h" 74#include "opt_sysv.h"
75 75
76#include <sys/param.h> 76#include <sys/param.h>
77#include <sys/systm.h> 77#include <sys/systm.h>
78#include <sys/ioctl.h> 78#include <sys/ioctl.h>
79#include <sys/tty.h> 79#include <sys/tty.h>
80#include <sys/time.h> 80#include <sys/time.h>
81#include <sys/resource.h> 81#include <sys/resource.h>
82#include <sys/kernel.h> 82#include <sys/kernel.h>
83#include <sys/proc.h> 83#include <sys/proc.h>
@@ -196,32 +196,32 @@ sys_exit(struct lwp *l, const struct sys @@ -196,32 +196,32 @@ sys_exit(struct lwp *l, const struct sys
196 */ 196 */
197void 197void
198exit1(struct lwp *l, int exitcode, int signo) 198exit1(struct lwp *l, int exitcode, int signo)
199{ 199{
200 struct proc *p, *child, *next_child, *old_parent, *new_parent; 200 struct proc *p, *child, *next_child, *old_parent, *new_parent;
201 struct pgrp *pgrp; 201 struct pgrp *pgrp;
202 ksiginfo_t ksi; 202 ksiginfo_t ksi;
203 ksiginfoq_t kq; 203 ksiginfoq_t kq;
204 int wakeinit; 204 int wakeinit;
205 struct lwp *l2 __diagused; 205 struct lwp *l2 __diagused;
206 206
207 p = l->l_proc; 207 p = l->l_proc;
208 208
209 /* XXX Temporary. */ 
210 kernel_lock_plug_leak(); 
211 
212 /* Verify that we hold no locks other than p->p_lock. */ 209 /* Verify that we hold no locks other than p->p_lock. */
213 LOCKDEBUG_BARRIER(p->p_lock, 0); 210 LOCKDEBUG_BARRIER(p->p_lock, 0);
214 KASSERTMSG(curcpu()->ci_biglock_count == 0, "kernel_lock leaked"); 211
 212 /* XXX Temporary: something is leaking kernel_lock. */
 213 KERNEL_UNLOCK_ALL(l, NULL);
 214
215 KASSERT(mutex_owned(p->p_lock)); 215 KASSERT(mutex_owned(p->p_lock));
216 KASSERT(p->p_vmspace != NULL); 216 KASSERT(p->p_vmspace != NULL);
217 217
218 if (__predict_false(p == initproc)) { 218 if (__predict_false(p == initproc)) {
219 panic("init died (signal %d, exit %d)", signo, exitcode); 219 panic("init died (signal %d, exit %d)", signo, exitcode);
220 } 220 }
221 221
222 p->p_sflag |= PS_WEXIT; 222 p->p_sflag |= PS_WEXIT;
223 223
224 /* 224 /*
225 * Force all other LWPs to exit before we do. Only then can we 225 * Force all other LWPs to exit before we do. Only then can we
226 * begin to tear down the rest of the process state. 226 * begin to tear down the rest of the process state.
227 */ 227 */

cvs diff -r1.169 -r1.170 src/sys/kern/kern_lock.c (expand / switch to unified diff)

--- src/sys/kern/kern_lock.c 2020/02/10 22:11:09 1.169
+++ src/sys/kern/kern_lock.c 2020/03/08 15:05:18 1.170
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: kern_lock.c,v 1.169 2020/02/10 22:11:09 christos Exp $ */ 1/* $NetBSD: kern_lock.c,v 1.170 2020/03/08 15:05:18 ad Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2002, 2006, 2007, 2008, 2009, 2020 The NetBSD Foundation, Inc. 4 * Copyright (c) 2002, 2006, 2007, 2008, 2009, 2020 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center, and by Andrew Doran. 9 * NASA Ames Research Center, and by Andrew Doran.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE. 30 * POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33#include <sys/cdefs.h> 33#include <sys/cdefs.h>
34__KERNEL_RCSID(0, "$NetBSD: kern_lock.c,v 1.169 2020/02/10 22:11:09 christos Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: kern_lock.c,v 1.170 2020/03/08 15:05:18 ad Exp $");
35 35
36#ifdef _KERNEL_OPT 36#ifdef _KERNEL_OPT
37#include "opt_lockdebug.h" 37#include "opt_lockdebug.h"
38#endif 38#endif
39 39
40#include <sys/param.h> 40#include <sys/param.h>
41#include <sys/proc.h> 41#include <sys/proc.h>
42#include <sys/lock.h> 42#include <sys/lock.h>
43#include <sys/systm.h> 43#include <sys/systm.h>
44#include <sys/kernel.h> 44#include <sys/kernel.h>
45#include <sys/lockdebug.h> 45#include <sys/lockdebug.h>
46#include <sys/cpu.h> 46#include <sys/cpu.h>
47#include <sys/syslog.h> 47#include <sys/syslog.h>
@@ -333,33 +333,13 @@ _kernel_unlock(int nlocks, int *countp) @@ -333,33 +333,13 @@ _kernel_unlock(int nlocks, int *countp)
333 l->l_blcnt -= nlocks; 333 l->l_blcnt -= nlocks;
334 splx(s); 334 splx(s);
335 } 335 }
336 336
337 if (countp != NULL) 337 if (countp != NULL)
338 *countp = olocks; 338 *countp = olocks;
339} 339}
340 340
341bool 341bool
342_kernel_locked_p(void) 342_kernel_locked_p(void)
343{ 343{
344 return __SIMPLELOCK_LOCKED_P(kernel_lock); 344 return __SIMPLELOCK_LOCKED_P(kernel_lock);
345} 345}
346 
347void 
348kernel_lock_plug_leak(void) 
349{ 
350#ifndef LOCKDEBUG 
351# ifdef DIAGNOSTIC 
352 int biglocks = 0; 
353 KERNEL_UNLOCK_ALL(curlwp, &biglocks); 
354 if (biglocks != 0) { 
355 const char *sym = "(unknown)"; 
356 ksyms_getname(NULL, &sym, (vaddr_t)curlwp->l_ld_wanted, 
357 KSYMS_CLOSEST|KSYMS_PROC|KSYMS_ANY); 
358 printf("kernel_lock leak detected. last acquired: %s / %p\n", 
359 sym, curlwp->l_ld_wanted); 
360 } 
361# else 
362 KERNEL_UNLOCK_ALL(curlwp, NULL); 
363# endif 
364#endif 
365} 

cvs diff -r1.61 -r1.62 src/sys/kern/kern_softint.c (expand / switch to unified diff)

--- src/sys/kern/kern_softint.c 2020/02/17 21:44:42 1.61
+++ src/sys/kern/kern_softint.c 2020/03/08 15:05:18 1.62
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: kern_softint.c,v 1.61 2020/02/17 21:44:42 ad Exp $ */ 1/* $NetBSD: kern_softint.c,v 1.62 2020/03/08 15:05:18 ad Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2007, 2008, 2019, 2020 The NetBSD Foundation, Inc. 4 * Copyright (c) 2007, 2008, 2019, 2020 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran. 8 * by Andrew Doran.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -160,27 +160,27 @@ @@ -160,27 +160,27 @@
160 * interrupt; 160 * interrupt;
161 * } 161 * }
162 * 162 *
163 * Once the soft interrupt has fired (and even if it has blocked), 163 * Once the soft interrupt has fired (and even if it has blocked),
164 * no further soft interrupts at that level will be triggered by 164 * no further soft interrupts at that level will be triggered by
165 * MI code until the soft interrupt handler has ceased execution.  165 * MI code until the soft interrupt handler has ceased execution.
166 * If a soft interrupt handler blocks and is resumed, it resumes 166 * If a soft interrupt handler blocks and is resumed, it resumes
167 * execution as a normal LWP (kthread) and gains VM context. Only 167 * execution as a normal LWP (kthread) and gains VM context. Only
168 * when it has completed and is ready to fire again will it 168 * when it has completed and is ready to fire again will it
169 * interrupt other threads. 169 * interrupt other threads.
170 */ 170 */
171 171
172#include <sys/cdefs.h> 172#include <sys/cdefs.h>
173__KERNEL_RCSID(0, "$NetBSD: kern_softint.c,v 1.61 2020/02/17 21:44:42 ad Exp $"); 173__KERNEL_RCSID(0, "$NetBSD: kern_softint.c,v 1.62 2020/03/08 15:05:18 ad Exp $");
174 174
175#include <sys/param.h> 175#include <sys/param.h>
176#include <sys/proc.h> 176#include <sys/proc.h>
177#include <sys/intr.h> 177#include <sys/intr.h>
178#include <sys/ipi.h> 178#include <sys/ipi.h>
179#include <sys/lock.h> 179#include <sys/lock.h>
180#include <sys/mutex.h> 180#include <sys/mutex.h>
181#include <sys/kernel.h> 181#include <sys/kernel.h>
182#include <sys/kthread.h> 182#include <sys/kthread.h>
183#include <sys/evcnt.h> 183#include <sys/evcnt.h>
184#include <sys/cpu.h> 184#include <sys/cpu.h>
185#include <sys/xcall.h> 185#include <sys/xcall.h>
186 186
@@ -880,29 +880,26 @@ softint_dispatch(lwp_t *pinned, int s) @@ -880,29 +880,26 @@ softint_dispatch(lwp_t *pinned, int s)
880 if (timing) { 880 if (timing) {
881 binuptime(&l->l_stime); 881 binuptime(&l->l_stime);
882 membar_producer(); /* for calcru */ 882 membar_producer(); /* for calcru */
883 l->l_pflag |= LP_TIMEINTR; 883 l->l_pflag |= LP_TIMEINTR;
884 } 884 }
885 l->l_pflag |= LP_RUNNING; 885 l->l_pflag |= LP_RUNNING;
886 softint_execute(si, l, s); 886 softint_execute(si, l, s);
887 if (timing) { 887 if (timing) {
888 binuptime(&now); 888 binuptime(&now);
889 updatertime(l, &now); 889 updatertime(l, &now);
890 l->l_pflag &= ~LP_TIMEINTR; 890 l->l_pflag &= ~LP_TIMEINTR;
891 } 891 }
892 892
893 /* XXX temporary */ 
894 kernel_lock_plug_leak(); 
895 
896 /* 893 /*
897 * If we blocked while handling the interrupt, the pinned LWP is 894 * If we blocked while handling the interrupt, the pinned LWP is
898 * gone so switch to the idle LWP. It will select a new LWP to 895 * gone so switch to the idle LWP. It will select a new LWP to
899 * run. 896 * run.
900 * 897 *
901 * We must drop the priority level as switching at IPL_HIGH could 898 * We must drop the priority level as switching at IPL_HIGH could
902 * deadlock the system. We have already set si->si_active = 0, 899 * deadlock the system. We have already set si->si_active = 0,
903 * which means another interrupt at this level can be triggered.  900 * which means another interrupt at this level can be triggered.
904 * That's not be a problem: we are lowering to level 's' which will 901 * That's not be a problem: we are lowering to level 's' which will
905 * prevent softint_dispatch() from being reentered at level 's', 902 * prevent softint_dispatch() from being reentered at level 's',
906 * until the priority is finally dropped to IPL_NONE on entry to 903 * until the priority is finally dropped to IPL_NONE on entry to
907 * the LWP chosen by mi_switch(). 904 * the LWP chosen by mi_switch().
908 */ 905 */

cvs diff -r1.88 -r1.89 src/sys/sys/lock.h (expand / switch to unified diff)

--- src/sys/sys/lock.h 2020/01/27 21:05:43 1.88
+++ src/sys/sys/lock.h 2020/03/08 15:05:18 1.89
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lock.h,v 1.88 2020/01/27 21:05:43 ad Exp $ */ 1/* $NetBSD: lock.h,v 1.89 2020/03/08 15:05:18 ad Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999, 2000, 2006, 2007 The NetBSD Foundation, Inc. 4 * Copyright (c) 1999, 2000, 2006, 2007 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center, by Ross Harvey, and by Andrew Doran. 9 * NASA Ames Research Center, by Ross Harvey, and by Andrew Doran.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -99,18 +99,16 @@ do { \ @@ -99,18 +99,16 @@ do { \
99 } \ 99 } \
100 if ((count) < SPINLOCK_BACKOFF_MAX) \ 100 if ((count) < SPINLOCK_BACKOFF_MAX) \
101 (count) += (count); \ 101 (count) += (count); \
102} while (/* CONSTCOND */ 0); 102} while (/* CONSTCOND */ 0);
103 103
104#ifdef LOCKDEBUG 104#ifdef LOCKDEBUG
105#define SPINLOCK_SPINOUT(spins) ((spins)++ > 0x0fffffff) 105#define SPINLOCK_SPINOUT(spins) ((spins)++ > 0x0fffffff)
106#else 106#else
107#define SPINLOCK_SPINOUT(spins) ((void)(spins), 0) 107#define SPINLOCK_SPINOUT(spins) ((void)(spins), 0)
108#endif 108#endif
109 109
110extern __cpu_simple_lock_t kernel_lock[]; 110extern __cpu_simple_lock_t kernel_lock[];
111 111
112void kernel_lock_plug_leak(void); 
113 
114#endif /* _KERNEL */ 112#endif /* _KERNEL */
115 113
116#endif /* _SYS_LOCK_H_ */ 114#endif /* _SYS_LOCK_H_ */