Pull up following revision(s) (requested by ozaki-r in ticket #405): sys/sys/pserialize.h: revision 1.2 sys/kern/kern_lock.c: revision 1.160 sys/kern/subr_pserialize.c: revision 1.9 sys/rump/librump/rumpkern/emul.c: revision 1.184 sys/rump/librump/rumpkern/emul.c: revision 1.185 sys/rump/librump/rumpkern/rump.c: revision 1.330 Implement debugging feature for pserialize(9) The debugging feature detects violations of pserialize constraints. It causes a panic: - if a context switch happens in a read section, or - if a sleepable function is called in a read section. The feature is enabled only if LOCKDEBUG is on. Discussed on tech-kern@ Add missing inclusion of pserialize.h (fix build)diff -r1.158 -r1.158.6.1 src/sys/kern/kern_lock.c
(martin)
--- src/sys/kern/kern_lock.c 2017/01/26 04:11:56 1.158
+++ src/sys/kern/kern_lock.c 2017/11/30 14:40:46 1.158.6.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: kern_lock.c,v 1.158 2017/01/26 04:11:56 christos Exp $ */ | 1 | /* $NetBSD: kern_lock.c,v 1.158.6.1 2017/11/30 14:40:46 martin Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2002, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2002, 2006, 2007, 2008, 2009 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,38 +21,39 @@ | @@ -21,38 +21,39 @@ | |||
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.158 2017/01/26 04:11:56 christos Exp $"); | 34 | __KERNEL_RCSID(0, "$NetBSD: kern_lock.c,v 1.158.6.1 2017/11/30 14:40:46 martin Exp $"); | |
35 | 35 | |||
36 | #include <sys/param.h> | 36 | #include <sys/param.h> | |
37 | #include <sys/proc.h> | 37 | #include <sys/proc.h> | |
38 | #include <sys/lock.h> | 38 | #include <sys/lock.h> | |
39 | #include <sys/systm.h> | 39 | #include <sys/systm.h> | |
40 | #include <sys/kernel.h> | 40 | #include <sys/kernel.h> | |
41 | #include <sys/lockdebug.h> | 41 | #include <sys/lockdebug.h> | |
42 | #include <sys/cpu.h> | 42 | #include <sys/cpu.h> | |
43 | #include <sys/syslog.h> | 43 | #include <sys/syslog.h> | |
44 | #include <sys/atomic.h> | 44 | #include <sys/atomic.h> | |
45 | #include <sys/lwp.h> | 45 | #include <sys/lwp.h> | |
46 | #include <sys/pserialize.h> | |||
46 | 47 | |||
47 | #include <machine/lock.h> | 48 | #include <machine/lock.h> | |
48 | 49 | |||
49 | #include <dev/lockstat.h> | 50 | #include <dev/lockstat.h> | |
50 | 51 | |||
51 | #define RETURN_ADDRESS (uintptr_t)__builtin_return_address(0) | 52 | #define RETURN_ADDRESS (uintptr_t)__builtin_return_address(0) | |
52 | 53 | |||
53 | bool kernel_lock_dodebug; | 54 | bool kernel_lock_dodebug; | |
54 | 55 | |||
55 | __cpu_simple_lock_t kernel_lock[CACHE_LINE_SIZE / sizeof(__cpu_simple_lock_t)] | 56 | __cpu_simple_lock_t kernel_lock[CACHE_LINE_SIZE / sizeof(__cpu_simple_lock_t)] | |
56 | __cacheline_aligned; | 57 | __cacheline_aligned; | |
57 | 58 | |||
58 | void | 59 | void | |
@@ -78,26 +79,29 @@ assert_sleepable(void) | @@ -78,26 +79,29 @@ assert_sleepable(void) | |||
78 | } while (pctr != lwp_pctr()); | 79 | } while (pctr != lwp_pctr()); | |
79 | 80 | |||
80 | reason = NULL; | 81 | reason = NULL; | |
81 | if (idle && !cold && | 82 | if (idle && !cold && | |
82 | kcpuset_isset(kcpuset_running, cpu_index(curcpu()))) { | 83 | kcpuset_isset(kcpuset_running, cpu_index(curcpu()))) { | |
83 | reason = "idle"; | 84 | reason = "idle"; | |
84 | } | 85 | } | |
85 | if (cpu_intr_p()) { | 86 | if (cpu_intr_p()) { | |
86 | reason = "interrupt"; | 87 | reason = "interrupt"; | |
87 | } | 88 | } | |
88 | if (cpu_softintr_p()) { | 89 | if (cpu_softintr_p()) { | |
89 | reason = "softint"; | 90 | reason = "softint"; | |
90 | } | 91 | } | |
92 | if (!pserialize_not_in_read_section()) { | |||
93 | reason = "pserialize"; | |||
94 | } | |||
91 | 95 | |||
92 | if (reason) { | 96 | if (reason) { | |
93 | panic("%s: %s caller=%p", __func__, reason, | 97 | panic("%s: %s caller=%p", __func__, reason, | |
94 | (void *)RETURN_ADDRESS); | 98 | (void *)RETURN_ADDRESS); | |
95 | } | 99 | } | |
96 | } | 100 | } | |
97 | 101 | |||
98 | /* | 102 | /* | |
99 | * Functions for manipulating the kernel_lock. We put them here | 103 | * Functions for manipulating the kernel_lock. We put them here | |
100 | * so that they show up in profiles. | 104 | * so that they show up in profiles. | |
101 | */ | 105 | */ | |
102 | 106 | |||
103 | #define _KERNEL_LOCK_ABORT(msg) \ | 107 | #define _KERNEL_LOCK_ABORT(msg) \ |
--- src/sys/kern/subr_pserialize.c 2015/06/12 19:18:30 1.8
+++ src/sys/kern/subr_pserialize.c 2017/11/30 14:40:46 1.8.10.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: subr_pserialize.c,v 1.8 2015/06/12 19:18:30 dholland Exp $ */ | 1 | /* $NetBSD: subr_pserialize.c,v 1.8.10.1 2017/11/30 14:40:46 martin Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -28,27 +28,27 @@ | @@ -28,27 +28,27 @@ | |||
28 | 28 | |||
29 | /* | 29 | /* | |
30 | * Passive serialization. | 30 | * Passive serialization. | |
31 | * | 31 | * | |
32 | * Implementation accurately matches the lapsed US patent 4809168, therefore | 32 | * Implementation accurately matches the lapsed US patent 4809168, therefore | |
33 | * code is patent-free in the United States. Your use of this code is at | 33 | * code is patent-free in the United States. Your use of this code is at | |
34 | * your own risk. | 34 | * your own risk. | |
35 | * | 35 | * | |
36 | * Note for NetBSD developers: all changes to this source file must be | 36 | * Note for NetBSD developers: all changes to this source file must be | |
37 | * approved by the <core>. | 37 | * approved by the <core>. | |
38 | */ | 38 | */ | |
39 | 39 | |||
40 | #include <sys/cdefs.h> | 40 | #include <sys/cdefs.h> | |
41 | __KERNEL_RCSID(0, "$NetBSD: subr_pserialize.c,v 1.8 2015/06/12 19:18:30 dholland Exp $"); | 41 | __KERNEL_RCSID(0, "$NetBSD: subr_pserialize.c,v 1.8.10.1 2017/11/30 14:40:46 martin Exp $"); | |
42 | 42 | |||
43 | #include <sys/param.h> | 43 | #include <sys/param.h> | |
44 | 44 | |||
45 | #include <sys/condvar.h> | 45 | #include <sys/condvar.h> | |
46 | #include <sys/cpu.h> | 46 | #include <sys/cpu.h> | |
47 | #include <sys/evcnt.h> | 47 | #include <sys/evcnt.h> | |
48 | #include <sys/kmem.h> | 48 | #include <sys/kmem.h> | |
49 | #include <sys/mutex.h> | 49 | #include <sys/mutex.h> | |
50 | #include <sys/pserialize.h> | 50 | #include <sys/pserialize.h> | |
51 | #include <sys/proc.h> | 51 | #include <sys/proc.h> | |
52 | #include <sys/queue.h> | 52 | #include <sys/queue.h> | |
53 | #include <sys/xcall.h> | 53 | #include <sys/xcall.h> | |
54 | 54 | |||
@@ -63,42 +63,51 @@ static u_int psz_work_todo __cacheline | @@ -63,42 +63,51 @@ static u_int psz_work_todo __cacheline | |||
63 | static kmutex_t psz_lock __cacheline_aligned; | 63 | static kmutex_t psz_lock __cacheline_aligned; | |
64 | static struct evcnt psz_ev_excl __cacheline_aligned; | 64 | static struct evcnt psz_ev_excl __cacheline_aligned; | |
65 | 65 | |||
66 | /* | 66 | /* | |
67 | * As defined in "Method 1": | 67 | * As defined in "Method 1": | |
68 | * q0: "0 MP checkpoints have occured". | 68 | * q0: "0 MP checkpoints have occured". | |
69 | * q1: "1 MP checkpoint has occured". | 69 | * q1: "1 MP checkpoint has occured". | |
70 | * q2: "2 MP checkpoints have occured". | 70 | * q2: "2 MP checkpoints have occured". | |
71 | */ | 71 | */ | |
72 | static TAILQ_HEAD(, pserialize) psz_queue0 __cacheline_aligned; | 72 | static TAILQ_HEAD(, pserialize) psz_queue0 __cacheline_aligned; | |
73 | static TAILQ_HEAD(, pserialize) psz_queue1 __cacheline_aligned; | 73 | static TAILQ_HEAD(, pserialize) psz_queue1 __cacheline_aligned; | |
74 | static TAILQ_HEAD(, pserialize) psz_queue2 __cacheline_aligned; | 74 | static TAILQ_HEAD(, pserialize) psz_queue2 __cacheline_aligned; | |
75 | 75 | |||
76 | #ifdef LOCKDEBUG | |||
77 | #include <sys/percpu.h> | |||
78 | ||||
79 | static percpu_t *psz_debug_nreads __cacheline_aligned; | |||
80 | #endif | |||
81 | ||||
76 | /* | 82 | /* | |
77 | * pserialize_init: | 83 | * pserialize_init: | |
78 | * | 84 | * | |
79 | * Initialize passive serialization structures. | 85 | * Initialize passive serialization structures. | |
80 | */ | 86 | */ | |
81 | void | 87 | void | |
82 | pserialize_init(void) | 88 | pserialize_init(void) | |
83 | { | 89 | { | |
84 | 90 | |||
85 | psz_work_todo = 0; | 91 | psz_work_todo = 0; | |
86 | TAILQ_INIT(&psz_queue0); | 92 | TAILQ_INIT(&psz_queue0); | |
87 | TAILQ_INIT(&psz_queue1); | 93 | TAILQ_INIT(&psz_queue1); | |
88 | TAILQ_INIT(&psz_queue2); | 94 | TAILQ_INIT(&psz_queue2); | |
89 | mutex_init(&psz_lock, MUTEX_DEFAULT, IPL_SCHED); | 95 | mutex_init(&psz_lock, MUTEX_DEFAULT, IPL_SCHED); | |
90 | evcnt_attach_dynamic(&psz_ev_excl, EVCNT_TYPE_MISC, NULL, | 96 | evcnt_attach_dynamic(&psz_ev_excl, EVCNT_TYPE_MISC, NULL, | |
91 | "pserialize", "exclusive access"); | 97 | "pserialize", "exclusive access"); | |
98 | #ifdef LOCKDEBUG | |||
99 | psz_debug_nreads = percpu_alloc(sizeof(uint32_t)); | |||
100 | #endif | |||
92 | } | 101 | } | |
93 | 102 | |||
94 | /* | 103 | /* | |
95 | * pserialize_create: | 104 | * pserialize_create: | |
96 | * | 105 | * | |
97 | * Create and initialize a passive serialization object. | 106 | * Create and initialize a passive serialization object. | |
98 | */ | 107 | */ | |
99 | pserialize_t | 108 | pserialize_t | |
100 | pserialize_create(void) | 109 | pserialize_create(void) | |
101 | { | 110 | { | |
102 | pserialize_t psz; | 111 | pserialize_t psz; | |
103 | 112 | |||
104 | psz = kmem_zalloc(sizeof(struct pserialize), KM_SLEEP); | 113 | psz = kmem_zalloc(sizeof(struct pserialize), KM_SLEEP); | |
@@ -175,50 +184,75 @@ pserialize_perform(pserialize_t psz) | @@ -175,50 +184,75 @@ pserialize_perform(pserialize_t psz) | |||
175 | 184 | |||
176 | mutex_spin_enter(&psz_lock); | 185 | mutex_spin_enter(&psz_lock); | |
177 | } while (!kcpuset_iszero(psz->psz_target)); | 186 | } while (!kcpuset_iszero(psz->psz_target)); | |
178 | 187 | |||
179 | psz_ev_excl.ev_count++; | 188 | psz_ev_excl.ev_count++; | |
180 | mutex_spin_exit(&psz_lock); | 189 | mutex_spin_exit(&psz_lock); | |
181 | 190 | |||
182 | psz->psz_owner = NULL; | 191 | psz->psz_owner = NULL; | |
183 | } | 192 | } | |
184 | 193 | |||
185 | int | 194 | int | |
186 | pserialize_read_enter(void) | 195 | pserialize_read_enter(void) | |
187 | { | 196 | { | |
197 | int s; | |||
188 | 198 | |||
189 | KASSERT(!cpu_intr_p()); | 199 | KASSERT(!cpu_intr_p()); | |
190 | return splsoftserial(); | 200 | s = splsoftserial(); | |
201 | #ifdef LOCKDEBUG | |||
202 | { | |||
203 | uint32_t *nreads; | |||
204 | nreads = percpu_getref(psz_debug_nreads); | |||
205 | (*nreads)++; | |||
206 | if (*nreads == 0) | |||
207 | panic("nreads overflow"); | |||
208 | percpu_putref(psz_debug_nreads); | |||
209 | } | |||
210 | #endif | |||
211 | return s; | |||
191 | } | 212 | } | |
192 | 213 | |||
193 | void | 214 | void | |
194 | pserialize_read_exit(int s) | 215 | pserialize_read_exit(int s) | |
195 | { | 216 | { | |
196 | 217 | |||
218 | #ifdef LOCKDEBUG | |||
219 | { | |||
220 | uint32_t *nreads; | |||
221 | nreads = percpu_getref(psz_debug_nreads); | |||
222 | (*nreads)--; | |||
223 | if (*nreads == UINT_MAX) | |||
224 | panic("nreads underflow"); | |||
225 | percpu_putref(psz_debug_nreads); | |||
226 | } | |||
227 | #endif | |||
197 | splx(s); | 228 | splx(s); | |
198 | } | 229 | } | |
199 | 230 | |||
200 | /* | 231 | /* | |
201 | * pserialize_switchpoint: | 232 | * pserialize_switchpoint: | |
202 | * | 233 | * | |
203 | * Monitor system context switch activity. Called from machine | 234 | * Monitor system context switch activity. Called from machine | |
204 | * independent code after mi_switch() returns. | 235 | * independent code after mi_switch() returns. | |
205 | */ | 236 | */ | |
206 | void | 237 | void | |
207 | pserialize_switchpoint(void) | 238 | pserialize_switchpoint(void) | |
208 | { | 239 | { | |
209 | pserialize_t psz, next; | 240 | pserialize_t psz, next; | |
210 | cpuid_t cid; | 241 | cpuid_t cid; | |
211 | 242 | |||
243 | /* We must to ensure not to come here from inside a read section. */ | |||
244 | KASSERT(pserialize_not_in_read_section()); | |||
245 | ||||
212 | /* | 246 | /* | |
213 | * If no updates pending, bail out. No need to lock in order to | 247 | * If no updates pending, bail out. No need to lock in order to | |
214 | * test psz_work_todo; the only ill effect of missing an update | 248 | * test psz_work_todo; the only ill effect of missing an update | |
215 | * would be to delay LWPs waiting in pserialize_perform(). That | 249 | * would be to delay LWPs waiting in pserialize_perform(). That | |
216 | * will not happen because updates are on the queue before an | 250 | * will not happen because updates are on the queue before an | |
217 | * xcall is generated (serialization) to tickle every CPU. | 251 | * xcall is generated (serialization) to tickle every CPU. | |
218 | */ | 252 | */ | |
219 | if (__predict_true(psz_work_todo == 0)) { | 253 | if (__predict_true(psz_work_todo == 0)) { | |
220 | return; | 254 | return; | |
221 | } | 255 | } | |
222 | mutex_spin_enter(&psz_lock); | 256 | mutex_spin_enter(&psz_lock); | |
223 | cid = cpu_index(curcpu()); | 257 | cid = cpu_index(curcpu()); | |
224 | 258 | |||
@@ -251,13 +285,71 @@ pserialize_switchpoint(void) | @@ -251,13 +285,71 @@ pserialize_switchpoint(void) | |||
251 | TAILQ_INSERT_TAIL(&psz_queue1, psz, psz_chain); | 285 | TAILQ_INSERT_TAIL(&psz_queue1, psz, psz_chain); | |
252 | } | 286 | } | |
253 | /* | 287 | /* | |
254 | * Process the third queue: entries have been seen twice on every | 288 | * Process the third queue: entries have been seen twice on every | |
255 | * processor, remove from the queue and notify the updating thread. | 289 | * processor, remove from the queue and notify the updating thread. | |
256 | */ | 290 | */ | |
257 | while ((psz = TAILQ_FIRST(&psz_queue2)) != NULL) { | 291 | while ((psz = TAILQ_FIRST(&psz_queue2)) != NULL) { | |
258 | TAILQ_REMOVE(&psz_queue2, psz, psz_chain); | 292 | TAILQ_REMOVE(&psz_queue2, psz, psz_chain); | |
259 | kcpuset_zero(psz->psz_target); | 293 | kcpuset_zero(psz->psz_target); | |
260 | psz_work_todo--; | 294 | psz_work_todo--; | |
261 | } | 295 | } | |
262 | mutex_spin_exit(&psz_lock); | 296 | mutex_spin_exit(&psz_lock); | |
263 | } | 297 | } | |
298 | ||||
299 | /* | |||
300 | * pserialize_in_read_section: | |||
301 | * | |||
302 | * True if the caller is in a pserialize read section. To be used only | |||
303 | * for diagnostic assertions where we want to guarantee the condition like: | |||
304 | * | |||
305 | * KASSERT(pserialize_in_read_section()); | |||
306 | */ | |||
307 | bool | |||
308 | pserialize_in_read_section(void) | |||
309 | { | |||
310 | #ifdef LOCKDEBUG | |||
311 | uint32_t *nreads; | |||
312 | bool in; | |||
313 | ||||
314 | /* Not initialized yet */ | |||
315 | if (__predict_false(psz_debug_nreads == NULL)) | |||
316 | return true; | |||
317 | ||||
318 | nreads = percpu_getref(psz_debug_nreads); | |||
319 | in = *nreads != 0; | |||
320 | percpu_putref(psz_debug_nreads); | |||
321 | ||||
322 | return in; | |||
323 | #else | |||
324 | return true; | |||
325 | #endif | |||
326 | } | |||
327 | ||||
328 | /* | |||
329 | * pserialize_not_in_read_section: | |||
330 | * | |||
331 | * True if the caller is not in a pserialize read section. To be used only | |||
332 | * for diagnostic assertions where we want to guarantee the condition like: | |||
333 | * | |||
334 | * KASSERT(pserialize_not_in_read_section()); | |||
335 | */ | |||
336 | bool | |||
337 | pserialize_not_in_read_section(void) | |||
338 | { | |||
339 | #ifdef LOCKDEBUG | |||
340 | uint32_t *nreads; | |||
341 | bool notin; | |||
342 | ||||
343 | /* Not initialized yet */ | |||
344 | if (__predict_false(psz_debug_nreads == NULL)) | |||
345 | return true; | |||
346 | ||||
347 | nreads = percpu_getref(psz_debug_nreads); | |||
348 | notin = *nreads == 0; | |||
349 | percpu_putref(psz_debug_nreads); | |||
350 | ||||
351 | return notin; | |||
352 | #else | |||
353 | return true; | |||
354 | #endif | |||
355 | } |
--- src/sys/rump/librump/rumpkern/emul.c 2017/06/04 20:35:01 1.181.6.1
+++ src/sys/rump/librump/rumpkern/emul.c 2017/11/30 14:40:46 1.181.6.2
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: emul.c,v 1.181.6.1 2017/06/04 20:35:01 bouyer Exp $ */ | 1 | /* $NetBSD: emul.c,v 1.181.6.2 2017/11/30 14:40:46 martin Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2007-2011 Antti Kantee. All Rights Reserved. | 4 | * Copyright (c) 2007-2011 Antti Kantee. All Rights Reserved. | |
5 | * | 5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | 6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions | 7 | * modification, are permitted provided that the following conditions | |
8 | * are met: | 8 | * are met: | |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. | |
11 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. | |
14 | * | 14 | * | |
@@ -16,36 +16,37 @@ | @@ -16,36 +16,37 @@ | |||
16 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 16 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
18 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | 18 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
25 | * SUCH DAMAGE. | 25 | * SUCH DAMAGE. | |
26 | */ | 26 | */ | |
27 | 27 | |||
28 | #include <sys/cdefs.h> | 28 | #include <sys/cdefs.h> | |
29 | __KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.181.6.1 2017/06/04 20:35:01 bouyer Exp $"); | 29 | __KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.181.6.2 2017/11/30 14:40:46 martin Exp $"); | |
30 | 30 | |||
31 | #include <sys/param.h> | 31 | #include <sys/param.h> | |
32 | #include <sys/cprng.h> | 32 | #include <sys/cprng.h> | |
33 | #include <sys/filedesc.h> | 33 | #include <sys/filedesc.h> | |
34 | #include <sys/fstrans.h> | 34 | #include <sys/fstrans.h> | |
35 | #include <sys/kauth.h> | 35 | #include <sys/kauth.h> | |
36 | #include <sys/module.h> | 36 | #include <sys/module.h> | |
37 | #include <sys/reboot.h> | 37 | #include <sys/reboot.h> | |
38 | #include <sys/syscall.h> | 38 | #include <sys/syscall.h> | |
39 | #include <sys/pserialize.h> | |||
39 | #ifdef LOCKDEBUG | 40 | #ifdef LOCKDEBUG | |
40 | #include <sys/sleepq.h> | 41 | #include <sys/sleepq.h> | |
41 | #endif | 42 | #endif | |
42 | 43 | |||
43 | #include <dev/cons.h> | 44 | #include <dev/cons.h> | |
44 | 45 | |||
45 | #include <rump-sys/kern.h> | 46 | #include <rump-sys/kern.h> | |
46 | 47 | |||
47 | #include <rump/rumpuser.h> | 48 | #include <rump/rumpuser.h> | |
48 | 49 | |||
49 | void (*rump_vfs_fini)(void) = (void *)nullop; | 50 | void (*rump_vfs_fini)(void) = (void *)nullop; | |
50 | 51 | |||
51 | /* | 52 | /* | |
@@ -155,31 +156,43 @@ kpause(const char *wmesg, bool intr, int | @@ -155,31 +156,43 @@ kpause(const char *wmesg, bool intr, int | |||
155 | 156 | |||
156 | vaddr_t | 157 | vaddr_t | |
157 | calc_cache_size(vsize_t vasz, int pct, int va_pct) | 158 | calc_cache_size(vsize_t vasz, int pct, int va_pct) | |
158 | { | 159 | { | |
159 | paddr_t t; | 160 | paddr_t t; | |
160 | 161 | |||
161 | t = (paddr_t)physmem * pct / 100 * PAGE_SIZE; | 162 | t = (paddr_t)physmem * pct / 100 * PAGE_SIZE; | |
162 | if ((vaddr_t)t != t) { | 163 | if ((vaddr_t)t != t) { | |
163 | panic("%s: needs tweak", __func__); | 164 | panic("%s: needs tweak", __func__); | |
164 | } | 165 | } | |
165 | return t; | 166 | return t; | |
166 | } | 167 | } | |
167 | 168 | |||
169 | #define RETURN_ADDRESS (uintptr_t)__builtin_return_address(0) | |||
170 | ||||
168 | void | 171 | void | |
169 | assert_sleepable(void) | 172 | assert_sleepable(void) | |
170 | { | 173 | { | |
174 | const char *reason = NULL; | |||
171 | 175 | |||
172 | /* always sleepable, although we should improve this */ | 176 | /* always sleepable, although we should improve this */ | |
177 | ||||
178 | if (!pserialize_not_in_read_section()) { | |||
179 | reason = "pserialize"; | |||
180 | } | |||
181 | ||||
182 | if (reason) { | |||
183 | panic("%s: %s caller=%p", __func__, reason, | |||
184 | (void *)RETURN_ADDRESS); | |||
185 | } | |||
173 | } | 186 | } | |
174 | 187 | |||
175 | void | 188 | void | |
176 | module_init_md(void) | 189 | module_init_md(void) | |
177 | { | 190 | { | |
178 | 191 | |||
179 | /* | 192 | /* | |
180 | * Nothing for now. However, we should load the librump | 193 | * Nothing for now. However, we should load the librump | |
181 | * symbol table. | 194 | * symbol table. | |
182 | */ | 195 | */ | |
183 | } | 196 | } | |
184 | 197 | |||
185 | /* | 198 | /* |
--- src/sys/rump/librump/rumpkern/rump.c 2016/03/08 14:30:48 1.329
+++ src/sys/rump/librump/rumpkern/rump.c 2017/11/30 14:40:46 1.329.10.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: rump.c,v 1.329 2016/03/08 14:30:48 joerg Exp $ */ | 1 | /* $NetBSD: rump.c,v 1.329.10.1 2017/11/30 14:40:46 martin Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2007-2011 Antti Kantee. All Rights Reserved. | 4 | * Copyright (c) 2007-2011 Antti Kantee. All Rights Reserved. | |
5 | * | 5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | 6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions | 7 | * modification, are permitted provided that the following conditions | |
8 | * are met: | 8 | * are met: | |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. | |
11 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. | |
14 | * | 14 | * | |
@@ -16,27 +16,27 @@ | @@ -16,27 +16,27 @@ | |||
16 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 16 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
18 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | 18 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
25 | * SUCH DAMAGE. | 25 | * SUCH DAMAGE. | |
26 | */ | 26 | */ | |
27 | 27 | |||
28 | #include <sys/cdefs.h> | 28 | #include <sys/cdefs.h> | |
29 | __KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.329 2016/03/08 14:30:48 joerg Exp $"); | 29 | __KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.329.10.1 2017/11/30 14:40:46 martin Exp $"); | |
30 | 30 | |||
31 | #include <sys/systm.h> | 31 | #include <sys/systm.h> | |
32 | #define ELFSIZE ARCH_ELFSIZE | 32 | #define ELFSIZE ARCH_ELFSIZE | |
33 | 33 | |||
34 | #include <sys/param.h> | 34 | #include <sys/param.h> | |
35 | #include <sys/atomic.h> | 35 | #include <sys/atomic.h> | |
36 | #include <sys/buf.h> | 36 | #include <sys/buf.h> | |
37 | #include <sys/callout.h> | 37 | #include <sys/callout.h> | |
38 | #include <sys/conf.h> | 38 | #include <sys/conf.h> | |
39 | #include <sys/cpu.h> | 39 | #include <sys/cpu.h> | |
40 | #include <sys/device.h> | 40 | #include <sys/device.h> | |
41 | #include <sys/evcnt.h> | 41 | #include <sys/evcnt.h> | |
42 | #include <sys/event.h> | 42 | #include <sys/event.h> | |
@@ -291,26 +291,27 @@ rump_init(void) | @@ -291,26 +291,27 @@ rump_init(void) | |||
291 | kernconfig_lock_init(); | 291 | kernconfig_lock_init(); | |
292 | prop_kern_init(); | 292 | prop_kern_init(); | |
293 | 293 | |||
294 | kmem_init(); | 294 | kmem_init(); | |
295 | 295 | |||
296 | uvm_ra_init(); | 296 | uvm_ra_init(); | |
297 | uao_init(); | 297 | uao_init(); | |
298 | 298 | |||
299 | mutex_obj_init(); | 299 | mutex_obj_init(); | |
300 | rw_obj_init(); | 300 | rw_obj_init(); | |
301 | callout_startup(); | 301 | callout_startup(); | |
302 | 302 | |||
303 | kprintf_init(); | 303 | kprintf_init(); | |
304 | percpu_init(); | |||
304 | pserialize_init(); | 305 | pserialize_init(); | |
305 | 306 | |||
306 | kauth_init(); | 307 | kauth_init(); | |
307 | 308 | |||
308 | secmodel_init(); | 309 | secmodel_init(); | |
309 | sysctl_init(); | 310 | sysctl_init(); | |
310 | /* | 311 | /* | |
311 | * The above call to sysctl_init() only initializes sysctl nodes | 312 | * The above call to sysctl_init() only initializes sysctl nodes | |
312 | * from link sets. Initialize sysctls in case we used ctors. | 313 | * from link sets. Initialize sysctls in case we used ctors. | |
313 | */ | 314 | */ | |
314 | #ifdef RUMP_USE_CTOR | 315 | #ifdef RUMP_USE_CTOR | |
315 | { | 316 | { | |
316 | struct sysctl_setup_chain *ssc; | 317 | struct sysctl_setup_chain *ssc; | |
@@ -341,27 +342,26 @@ rump_init(void) | @@ -341,27 +342,26 @@ rump_init(void) | |||
341 | lwp_initspecific(&lwp0); | 342 | lwp_initspecific(&lwp0); | |
342 | 343 | |||
343 | loginit(); | 344 | loginit(); | |
344 | 345 | |||
345 | rump_biglock_init(); | 346 | rump_biglock_init(); | |
346 | 347 | |||
347 | rump_scheduler_init(numcpu); | 348 | rump_scheduler_init(numcpu); | |
348 | /* revert temporary context and schedule a semireal context */ | 349 | /* revert temporary context and schedule a semireal context */ | |
349 | rump_lwproc_curlwp_clear(l); | 350 | rump_lwproc_curlwp_clear(l); | |
350 | initproc = &proc0; /* borrow proc0 before we get initproc started */ | 351 | initproc = &proc0; /* borrow proc0 before we get initproc started */ | |
351 | rump_schedule(); | 352 | rump_schedule(); | |
352 | bootlwp = curlwp; | 353 | bootlwp = curlwp; | |
353 | 354 | |||
354 | percpu_init(); | |||
355 | inittimecounter(); | 355 | inittimecounter(); | |
356 | ntp_init(); | 356 | ntp_init(); | |
357 | 357 | |||
358 | #ifdef KTRACE | 358 | #ifdef KTRACE | |
359 | ktrinit(); | 359 | ktrinit(); | |
360 | #endif | 360 | #endif | |
361 | 361 | |||
362 | ts = boottime; | 362 | ts = boottime; | |
363 | tc_setclock(&ts); | 363 | tc_setclock(&ts); | |
364 | 364 | |||
365 | extern krwlock_t exec_lock; | 365 | extern krwlock_t exec_lock; | |
366 | rw_init(&exec_lock); | 366 | rw_init(&exec_lock); | |
367 | 367 |
--- src/sys/sys/pserialize.h 2011/07/30 17:01:04 1.1
+++ src/sys/sys/pserialize.h 2017/11/30 14:40:46 1.1.46.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: pserialize.h,v 1.1 2011/07/30 17:01:04 christos Exp $ */ | 1 | /* $NetBSD: pserialize.h,v 1.1.46.1 2017/11/30 14:40:46 martin Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -34,16 +34,18 @@ | @@ -34,16 +34,18 @@ | |||
34 | struct pserialize; | 34 | struct pserialize; | |
35 | typedef struct pserialize *pserialize_t; | 35 | typedef struct pserialize *pserialize_t; | |
36 | 36 | |||
37 | void pserialize_init(void); | 37 | void pserialize_init(void); | |
38 | void pserialize_switchpoint(void); | 38 | void pserialize_switchpoint(void); | |
39 | 39 | |||
40 | pserialize_t pserialize_create(void); | 40 | pserialize_t pserialize_create(void); | |
41 | void pserialize_destroy(pserialize_t); | 41 | void pserialize_destroy(pserialize_t); | |
42 | void pserialize_perform(pserialize_t); | 42 | void pserialize_perform(pserialize_t); | |
43 | 43 | |||
44 | int pserialize_read_enter(void); | 44 | int pserialize_read_enter(void); | |
45 | void pserialize_read_exit(int); | 45 | void pserialize_read_exit(int); | |
46 | 46 | |||
47 | bool pserialize_in_read_section(void); | |||
48 | bool pserialize_not_in_read_section(void); | |||
47 | #endif /* _KERNEL */ | 49 | #endif /* _KERNEL */ | |
48 | 50 | |||
49 | #endif /* _SYS_PSERIALIZE_H_ */ | 51 | #endif /* _SYS_PSERIALIZE_H_ */ |