xref: /openbmc/linux/kernel/rcu/update.c (revision 9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e)
138b4df64SPaul E. McKenney // SPDX-License-Identifier: GPL-2.0+
24102adabSPaul E. McKenney /*
34102adabSPaul E. McKenney  * Read-Copy Update mechanism for mutual exclusion
44102adabSPaul E. McKenney  *
54102adabSPaul E. McKenney  * Copyright IBM Corporation, 2001
64102adabSPaul E. McKenney  *
74102adabSPaul E. McKenney  * Authors: Dipankar Sarma <dipankar@in.ibm.com>
84102adabSPaul E. McKenney  *	    Manfred Spraul <manfred@colorfullife.com>
94102adabSPaul E. McKenney  *
1038b4df64SPaul E. McKenney  * Based on the original work by Paul McKenney <paulmck@linux.ibm.com>
114102adabSPaul E. McKenney  * and inputs from Rusty Russell, Andrea Arcangeli and Andi Kleen.
124102adabSPaul E. McKenney  * Papers:
134102adabSPaul E. McKenney  * http://www.rdrop.com/users/paulmck/paper/rclockpdcsproof.pdf
144102adabSPaul E. McKenney  * http://lse.sourceforge.net/locking/rclock_OLS.2001.05.01c.sc.pdf (OLS2001)
154102adabSPaul E. McKenney  *
164102adabSPaul E. McKenney  * For detailed explanation of Read-Copy Update mechanism see -
174102adabSPaul E. McKenney  *		http://lse.sourceforge.net/locking/rcupdate.html
184102adabSPaul E. McKenney  *
194102adabSPaul E. McKenney  */
204102adabSPaul E. McKenney #include <linux/types.h>
214102adabSPaul E. McKenney #include <linux/kernel.h>
224102adabSPaul E. McKenney #include <linux/init.h>
234102adabSPaul E. McKenney #include <linux/spinlock.h>
244102adabSPaul E. McKenney #include <linux/smp.h>
254102adabSPaul E. McKenney #include <linux/interrupt.h>
263f07c014SIngo Molnar #include <linux/sched/signal.h>
27b17b0153SIngo Molnar #include <linux/sched/debug.h>
284102adabSPaul E. McKenney #include <linux/atomic.h>
294102adabSPaul E. McKenney #include <linux/bitops.h>
304102adabSPaul E. McKenney #include <linux/percpu.h>
314102adabSPaul E. McKenney #include <linux/notifier.h>
324102adabSPaul E. McKenney #include <linux/cpu.h>
334102adabSPaul E. McKenney #include <linux/mutex.h>
344102adabSPaul E. McKenney #include <linux/export.h>
354102adabSPaul E. McKenney #include <linux/hardirq.h>
364102adabSPaul E. McKenney #include <linux/delay.h>
37e77b7041SPaul Gortmaker #include <linux/moduleparam.h>
388315f422SPaul E. McKenney #include <linux/kthread.h>
394ff475edSPaul E. McKenney #include <linux/tick.h>
40f9411ebeSIngo Molnar #include <linux/rcupdate_wait.h>
4178634061SFrederic Weisbecker #include <linux/sched/isolation.h>
42a39f15b9SMasami Hiramatsu #include <linux/kprobes.h>
43a35d1690SByungchul Park #include <linux/slab.h>
44b38f57c1SPaul E. McKenney #include <linux/irq_work.h>
455b3cc99bSPaul E. McKenney #include <linux/rcupdate_trace.h>
464102adabSPaul E. McKenney 
474102adabSPaul E. McKenney #define CREATE_TRACE_POINTS
484102adabSPaul E. McKenney 
494102adabSPaul E. McKenney #include "rcu.h"
504102adabSPaul E. McKenney 
514102adabSPaul E. McKenney #ifdef MODULE_PARAM_PREFIX
524102adabSPaul E. McKenney #undef MODULE_PARAM_PREFIX
534102adabSPaul E. McKenney #endif
544102adabSPaul E. McKenney #define MODULE_PARAM_PREFIX "rcupdate."
554102adabSPaul E. McKenney 
5679cfea02SPaul E. McKenney #ifndef CONFIG_TINY_RCU
571eac0075SJuri Lelli module_param(rcu_expedited, int, 0444);
581eac0075SJuri Lelli module_param(rcu_normal, int, 0444);
5936221e10SJulia Cartwright static int rcu_normal_after_boot = IS_ENABLED(CONFIG_PREEMPT_RT);
60ebb6d30dSJuri Lelli #if !defined(CONFIG_PREEMPT_RT) || defined(CONFIG_NO_HZ_FULL)
611eac0075SJuri Lelli module_param(rcu_normal_after_boot, int, 0444);
6236221e10SJulia Cartwright #endif
6379cfea02SPaul E. McKenney #endif /* #ifndef CONFIG_TINY_RCU */
643e42ec1aSPaul E. McKenney 
65293e2421SBoqun Feng #ifdef CONFIG_DEBUG_LOCK_ALLOC
66d5671f6bSDenys Vlasenko /**
6728875945SJoel Fernandes (Google)  * rcu_read_lock_held_common() - might we be in RCU-sched read-side critical section?
6828875945SJoel Fernandes (Google)  * @ret:	Best guess answer if lockdep cannot be relied on
69d5671f6bSDenys Vlasenko  *
70c28d5c09SMauro Carvalho Chehab  * Returns true if lockdep must be ignored, in which case ``*ret`` contains
7128875945SJoel Fernandes (Google)  * the best guess described below.  Otherwise returns false, in which
72c28d5c09SMauro Carvalho Chehab  * case ``*ret`` tells the caller nothing and the caller should instead
7328875945SJoel Fernandes (Google)  * consult lockdep.
7428875945SJoel Fernandes (Google)  *
75c28d5c09SMauro Carvalho Chehab  * If CONFIG_DEBUG_LOCK_ALLOC is selected, set ``*ret`` to nonzero iff in an
76d5671f6bSDenys Vlasenko  * RCU-sched read-side critical section.  In absence of
77d5671f6bSDenys Vlasenko  * CONFIG_DEBUG_LOCK_ALLOC, this assumes we are in an RCU-sched read-side
78d5671f6bSDenys Vlasenko  * critical section unless it can prove otherwise.  Note that disabling
79d5671f6bSDenys Vlasenko  * of preemption (including disabling irqs) counts as an RCU-sched
80d5671f6bSDenys Vlasenko  * read-side critical section.  This is useful for debug checks in functions
81d5671f6bSDenys Vlasenko  * that required that they be called within an RCU-sched read-side
82d5671f6bSDenys Vlasenko  * critical section.
83d5671f6bSDenys Vlasenko  *
84d5671f6bSDenys Vlasenko  * Check debug_lockdep_rcu_enabled() to prevent false positives during boot
85d5671f6bSDenys Vlasenko  * and while lockdep is disabled.
86d5671f6bSDenys Vlasenko  *
8728875945SJoel Fernandes (Google)  * Note that if the CPU is in the idle loop from an RCU point of view (ie:
88e67198ccSFrederic Weisbecker  * that we are in the section between ct_idle_enter() and ct_idle_exit())
89c28d5c09SMauro Carvalho Chehab  * then rcu_read_lock_held() sets ``*ret`` to false even if the CPU did an
9028875945SJoel Fernandes (Google)  * rcu_read_lock().  The reason for this is that RCU ignores CPUs that are
9128875945SJoel Fernandes (Google)  * in such a section, considering these as in extended quiescent state,
9228875945SJoel Fernandes (Google)  * so such a CPU is effectively never in an RCU read-side critical section
9328875945SJoel Fernandes (Google)  * regardless of what RCU primitives it invokes.  This state of affairs is
9428875945SJoel Fernandes (Google)  * required --- we need to keep an RCU-free window in idle where the CPU may
9528875945SJoel Fernandes (Google)  * possibly enter into low power mode. This way we can notice an extended
9628875945SJoel Fernandes (Google)  * quiescent state to other CPUs that started a grace period. Otherwise
9728875945SJoel Fernandes (Google)  * we would delay any grace period as long as we run in the idle task.
98d5671f6bSDenys Vlasenko  *
9928875945SJoel Fernandes (Google)  * Similarly, we avoid claiming an RCU read lock held if the current
100d5671f6bSDenys Vlasenko  * CPU is offline.
101d5671f6bSDenys Vlasenko  */
rcu_read_lock_held_common(bool * ret)10228875945SJoel Fernandes (Google) static bool rcu_read_lock_held_common(bool *ret)
10328875945SJoel Fernandes (Google) {
10428875945SJoel Fernandes (Google) 	if (!debug_lockdep_rcu_enabled()) {
105a66dbda7SJules Irenge 		*ret = true;
10628875945SJoel Fernandes (Google) 		return true;
10728875945SJoel Fernandes (Google) 	}
10828875945SJoel Fernandes (Google) 	if (!rcu_is_watching()) {
109a66dbda7SJules Irenge 		*ret = false;
11028875945SJoel Fernandes (Google) 		return true;
11128875945SJoel Fernandes (Google) 	}
11228875945SJoel Fernandes (Google) 	if (!rcu_lockdep_current_cpu_online()) {
113a66dbda7SJules Irenge 		*ret = false;
11428875945SJoel Fernandes (Google) 		return true;
11528875945SJoel Fernandes (Google) 	}
11628875945SJoel Fernandes (Google) 	return false;
11728875945SJoel Fernandes (Google) }
11828875945SJoel Fernandes (Google) 
rcu_read_lock_sched_held(void)119d5671f6bSDenys Vlasenko int rcu_read_lock_sched_held(void)
120d5671f6bSDenys Vlasenko {
12128875945SJoel Fernandes (Google) 	bool ret;
122d5671f6bSDenys Vlasenko 
12328875945SJoel Fernandes (Google) 	if (rcu_read_lock_held_common(&ret))
12428875945SJoel Fernandes (Google) 		return ret;
1259147089bSJoel Fernandes (Google) 	return lock_is_held(&rcu_sched_lock_map) || !preemptible();
126d5671f6bSDenys Vlasenko }
127d5671f6bSDenys Vlasenko EXPORT_SYMBOL(rcu_read_lock_sched_held);
128d5671f6bSDenys Vlasenko #endif
129d5671f6bSDenys Vlasenko 
1300d39482cSPaul E. McKenney #ifndef CONFIG_TINY_RCU
1310d39482cSPaul E. McKenney 
1325a9be7c6SPaul E. McKenney /*
1335a9be7c6SPaul E. McKenney  * Should expedited grace-period primitives always fall back to their
1345a9be7c6SPaul E. McKenney  * non-expedited counterparts?  Intended for use within RCU.  Note
1355a9be7c6SPaul E. McKenney  * that if the user specifies both rcu_expedited and rcu_normal, then
13652d7e48bSPaul E. McKenney  * rcu_normal wins.  (Except during the time period during boot from
137900b1028SPaul E. McKenney  * when the first task is spawned until the rcu_set_runtime_mode()
13852d7e48bSPaul E. McKenney  * core_initcall() is invoked, at which point everything is expedited.)
1395a9be7c6SPaul E. McKenney  */
rcu_gp_is_normal(void)1405a9be7c6SPaul E. McKenney bool rcu_gp_is_normal(void)
1415a9be7c6SPaul E. McKenney {
14252d7e48bSPaul E. McKenney 	return READ_ONCE(rcu_normal) &&
14352d7e48bSPaul E. McKenney 	       rcu_scheduler_active != RCU_SCHEDULER_INIT;
1445a9be7c6SPaul E. McKenney }
1454f2a848cSPaul E. McKenney EXPORT_SYMBOL_GPL(rcu_gp_is_normal);
1465a9be7c6SPaul E. McKenney 
147*6efdda8bSJoel Fernandes (Google) static atomic_t rcu_async_hurry_nesting = ATOMIC_INIT(1);
148*6efdda8bSJoel Fernandes (Google) /*
149*6efdda8bSJoel Fernandes (Google)  * Should call_rcu() callbacks be processed with urgency or are
150*6efdda8bSJoel Fernandes (Google)  * they OK being executed with arbitrary delays?
151*6efdda8bSJoel Fernandes (Google)  */
rcu_async_should_hurry(void)152*6efdda8bSJoel Fernandes (Google) bool rcu_async_should_hurry(void)
153*6efdda8bSJoel Fernandes (Google) {
154*6efdda8bSJoel Fernandes (Google) 	return !IS_ENABLED(CONFIG_RCU_LAZY) ||
155*6efdda8bSJoel Fernandes (Google) 	       atomic_read(&rcu_async_hurry_nesting);
156*6efdda8bSJoel Fernandes (Google) }
157*6efdda8bSJoel Fernandes (Google) EXPORT_SYMBOL_GPL(rcu_async_should_hurry);
1580d39482cSPaul E. McKenney 
159*6efdda8bSJoel Fernandes (Google) /**
160*6efdda8bSJoel Fernandes (Google)  * rcu_async_hurry - Make future async RCU callbacks not lazy.
161*6efdda8bSJoel Fernandes (Google)  *
162*6efdda8bSJoel Fernandes (Google)  * After a call to this function, future calls to call_rcu()
163*6efdda8bSJoel Fernandes (Google)  * will be processed in a timely fashion.
164*6efdda8bSJoel Fernandes (Google)  */
rcu_async_hurry(void)165*6efdda8bSJoel Fernandes (Google) void rcu_async_hurry(void)
166*6efdda8bSJoel Fernandes (Google) {
167*6efdda8bSJoel Fernandes (Google) 	if (IS_ENABLED(CONFIG_RCU_LAZY))
168*6efdda8bSJoel Fernandes (Google) 		atomic_inc(&rcu_async_hurry_nesting);
169*6efdda8bSJoel Fernandes (Google) }
170*6efdda8bSJoel Fernandes (Google) EXPORT_SYMBOL_GPL(rcu_async_hurry);
171*6efdda8bSJoel Fernandes (Google) 
172*6efdda8bSJoel Fernandes (Google) /**
173*6efdda8bSJoel Fernandes (Google)  * rcu_async_relax - Make future async RCU callbacks lazy.
174*6efdda8bSJoel Fernandes (Google)  *
175*6efdda8bSJoel Fernandes (Google)  * After a call to this function, future calls to call_rcu()
176*6efdda8bSJoel Fernandes (Google)  * will be processed in a lazy fashion.
177*6efdda8bSJoel Fernandes (Google)  */
rcu_async_relax(void)178*6efdda8bSJoel Fernandes (Google) void rcu_async_relax(void)
179*6efdda8bSJoel Fernandes (Google) {
180*6efdda8bSJoel Fernandes (Google) 	if (IS_ENABLED(CONFIG_RCU_LAZY))
181*6efdda8bSJoel Fernandes (Google) 		atomic_dec(&rcu_async_hurry_nesting);
182*6efdda8bSJoel Fernandes (Google) }
183*6efdda8bSJoel Fernandes (Google) EXPORT_SYMBOL_GPL(rcu_async_relax);
184*6efdda8bSJoel Fernandes (Google) 
185*6efdda8bSJoel Fernandes (Google) static atomic_t rcu_expedited_nesting = ATOMIC_INIT(1);
1860d39482cSPaul E. McKenney /*
1870d39482cSPaul E. McKenney  * Should normal grace-period primitives be expedited?  Intended for
1880d39482cSPaul E. McKenney  * use within RCU.  Note that this function takes the rcu_expedited
18952d7e48bSPaul E. McKenney  * sysfs/boot variable and rcu_scheduler_active into account as well
19052d7e48bSPaul E. McKenney  * as the rcu_expedite_gp() nesting.  So looping on rcu_unexpedite_gp()
19152d7e48bSPaul E. McKenney  * until rcu_gp_is_expedited() returns false is a -really- bad idea.
1920d39482cSPaul E. McKenney  */
rcu_gp_is_expedited(void)1930d39482cSPaul E. McKenney bool rcu_gp_is_expedited(void)
1940d39482cSPaul E. McKenney {
195b823cafaSPaul E. McKenney 	return rcu_expedited || atomic_read(&rcu_expedited_nesting);
1960d39482cSPaul E. McKenney }
1970d39482cSPaul E. McKenney EXPORT_SYMBOL_GPL(rcu_gp_is_expedited);
1980d39482cSPaul E. McKenney 
1990d39482cSPaul E. McKenney /**
2000d39482cSPaul E. McKenney  * rcu_expedite_gp - Expedite future RCU grace periods
2010d39482cSPaul E. McKenney  *
2020d39482cSPaul E. McKenney  * After a call to this function, future calls to synchronize_rcu() and
2030d39482cSPaul E. McKenney  * friends act as the corresponding synchronize_rcu_expedited() function
2040d39482cSPaul E. McKenney  * had instead been called.
2050d39482cSPaul E. McKenney  */
rcu_expedite_gp(void)2060d39482cSPaul E. McKenney void rcu_expedite_gp(void)
2070d39482cSPaul E. McKenney {
2080d39482cSPaul E. McKenney 	atomic_inc(&rcu_expedited_nesting);
2090d39482cSPaul E. McKenney }
2100d39482cSPaul E. McKenney EXPORT_SYMBOL_GPL(rcu_expedite_gp);
2110d39482cSPaul E. McKenney 
2120d39482cSPaul E. McKenney /**
2130d39482cSPaul E. McKenney  * rcu_unexpedite_gp - Cancel prior rcu_expedite_gp() invocation
2140d39482cSPaul E. McKenney  *
2150d39482cSPaul E. McKenney  * Undo a prior call to rcu_expedite_gp().  If all prior calls to
2160d39482cSPaul E. McKenney  * rcu_expedite_gp() are undone by a subsequent call to rcu_unexpedite_gp(),
2170d39482cSPaul E. McKenney  * and if the rcu_expedited sysfs/boot parameter is not set, then all
2180d39482cSPaul E. McKenney  * subsequent calls to synchronize_rcu() and friends will return to
2190d39482cSPaul E. McKenney  * their normal non-expedited behavior.
2200d39482cSPaul E. McKenney  */
rcu_unexpedite_gp(void)2210d39482cSPaul E. McKenney void rcu_unexpedite_gp(void)
2220d39482cSPaul E. McKenney {
2230d39482cSPaul E. McKenney 	atomic_dec(&rcu_expedited_nesting);
2240d39482cSPaul E. McKenney }
2250d39482cSPaul E. McKenney EXPORT_SYMBOL_GPL(rcu_unexpedite_gp);
2260d39482cSPaul E. McKenney 
22759ee0326SPaul E. McKenney static bool rcu_boot_ended __read_mostly;
22859ee0326SPaul E. McKenney 
229ee42571fSPaul E. McKenney /*
230ee42571fSPaul E. McKenney  * Inform RCU of the end of the in-kernel boot sequence.
231ee42571fSPaul E. McKenney  */
rcu_end_inkernel_boot(void)232ee42571fSPaul E. McKenney void rcu_end_inkernel_boot(void)
233ee42571fSPaul E. McKenney {
234ee42571fSPaul E. McKenney 	rcu_unexpedite_gp();
235*6efdda8bSJoel Fernandes (Google) 	rcu_async_relax();
2363e42ec1aSPaul E. McKenney 	if (rcu_normal_after_boot)
2373e42ec1aSPaul E. McKenney 		WRITE_ONCE(rcu_normal, 1);
238e40bb921SJules Irenge 	rcu_boot_ended = true;
239ee42571fSPaul E. McKenney }
2400d39482cSPaul E. McKenney 
24159ee0326SPaul E. McKenney /*
24259ee0326SPaul E. McKenney  * Let rcutorture know when it is OK to turn it up to eleven.
24359ee0326SPaul E. McKenney  */
rcu_inkernel_boot_has_ended(void)24459ee0326SPaul E. McKenney bool rcu_inkernel_boot_has_ended(void)
24559ee0326SPaul E. McKenney {
24659ee0326SPaul E. McKenney 	return rcu_boot_ended;
24759ee0326SPaul E. McKenney }
24859ee0326SPaul E. McKenney EXPORT_SYMBOL_GPL(rcu_inkernel_boot_has_ended);
24959ee0326SPaul E. McKenney 
25079cfea02SPaul E. McKenney #endif /* #ifndef CONFIG_TINY_RCU */
25179cfea02SPaul E. McKenney 
252900b1028SPaul E. McKenney /*
253900b1028SPaul E. McKenney  * Test each non-SRCU synchronous grace-period wait API.  This is
254900b1028SPaul E. McKenney  * useful just after a change in mode for these primitives, and
255900b1028SPaul E. McKenney  * during early boot.
256900b1028SPaul E. McKenney  */
rcu_test_sync_prims(void)257900b1028SPaul E. McKenney void rcu_test_sync_prims(void)
258900b1028SPaul E. McKenney {
259900b1028SPaul E. McKenney 	if (!IS_ENABLED(CONFIG_PROVE_RCU))
260900b1028SPaul E. McKenney 		return;
261748bf47aSPaul E. McKenney 	pr_info("Running RCU synchronous self tests\n");
262900b1028SPaul E. McKenney 	synchronize_rcu();
263900b1028SPaul E. McKenney 	synchronize_rcu_expedited();
264900b1028SPaul E. McKenney }
265900b1028SPaul E. McKenney 
2660cd7e350SPaul E. McKenney #if !defined(CONFIG_TINY_RCU)
267900b1028SPaul E. McKenney 
268900b1028SPaul E. McKenney /*
269900b1028SPaul E. McKenney  * Switch to run-time mode once RCU has fully initialized.
270900b1028SPaul E. McKenney  */
rcu_set_runtime_mode(void)271900b1028SPaul E. McKenney static int __init rcu_set_runtime_mode(void)
272900b1028SPaul E. McKenney {
273900b1028SPaul E. McKenney 	rcu_test_sync_prims();
274900b1028SPaul E. McKenney 	rcu_scheduler_active = RCU_SCHEDULER_RUNNING;
275a35d1690SByungchul Park 	kfree_rcu_scheduler_running();
276900b1028SPaul E. McKenney 	rcu_test_sync_prims();
277900b1028SPaul E. McKenney 	return 0;
278900b1028SPaul E. McKenney }
279900b1028SPaul E. McKenney core_initcall(rcu_set_runtime_mode);
280900b1028SPaul E. McKenney 
2810cd7e350SPaul E. McKenney #endif /* #if !defined(CONFIG_TINY_RCU) */
282900b1028SPaul E. McKenney 
2834102adabSPaul E. McKenney #ifdef CONFIG_DEBUG_LOCK_ALLOC
2844102adabSPaul E. McKenney static struct lock_class_key rcu_lock_key;
285de8f5e4fSPeter Zijlstra struct lockdep_map rcu_lock_map = {
286de8f5e4fSPeter Zijlstra 	.name = "rcu_read_lock",
287de8f5e4fSPeter Zijlstra 	.key = &rcu_lock_key,
288de8f5e4fSPeter Zijlstra 	.wait_type_outer = LD_WAIT_FREE,
289a2e05dddSZhouyi Zhou 	.wait_type_inner = LD_WAIT_CONFIG, /* PREEMPT_RT implies PREEMPT_RCU */
290de8f5e4fSPeter Zijlstra };
2914102adabSPaul E. McKenney EXPORT_SYMBOL_GPL(rcu_lock_map);
2924102adabSPaul E. McKenney 
2934102adabSPaul E. McKenney static struct lock_class_key rcu_bh_lock_key;
294de8f5e4fSPeter Zijlstra struct lockdep_map rcu_bh_lock_map = {
295de8f5e4fSPeter Zijlstra 	.name = "rcu_read_lock_bh",
296de8f5e4fSPeter Zijlstra 	.key = &rcu_bh_lock_key,
297de8f5e4fSPeter Zijlstra 	.wait_type_outer = LD_WAIT_FREE,
298a2e05dddSZhouyi Zhou 	.wait_type_inner = LD_WAIT_CONFIG, /* PREEMPT_RT makes BH preemptible. */
299de8f5e4fSPeter Zijlstra };
3004102adabSPaul E. McKenney EXPORT_SYMBOL_GPL(rcu_bh_lock_map);
3014102adabSPaul E. McKenney 
3024102adabSPaul E. McKenney static struct lock_class_key rcu_sched_lock_key;
303de8f5e4fSPeter Zijlstra struct lockdep_map rcu_sched_lock_map = {
304de8f5e4fSPeter Zijlstra 	.name = "rcu_read_lock_sched",
305de8f5e4fSPeter Zijlstra 	.key = &rcu_sched_lock_key,
306de8f5e4fSPeter Zijlstra 	.wait_type_outer = LD_WAIT_FREE,
307de8f5e4fSPeter Zijlstra 	.wait_type_inner = LD_WAIT_SPIN,
308de8f5e4fSPeter Zijlstra };
3094102adabSPaul E. McKenney EXPORT_SYMBOL_GPL(rcu_sched_lock_map);
3104102adabSPaul E. McKenney 
311f8466f94SPaul E. McKenney // Tell lockdep when RCU callbacks are being invoked.
31224ef659aSPaul E. McKenney static struct lock_class_key rcu_callback_key;
31324ef659aSPaul E. McKenney struct lockdep_map rcu_callback_map =
31424ef659aSPaul E. McKenney 	STATIC_LOCKDEP_MAP_INIT("rcu_callback", &rcu_callback_key);
31524ef659aSPaul E. McKenney EXPORT_SYMBOL_GPL(rcu_callback_map);
31624ef659aSPaul E. McKenney 
debug_lockdep_rcu_enabled(void)317ff5c4f5cSThomas Gleixner noinstr int notrace debug_lockdep_rcu_enabled(void)
3184102adabSPaul E. McKenney {
31930668200SPaul E. McKenney 	return rcu_scheduler_active != RCU_SCHEDULER_INACTIVE && READ_ONCE(debug_locks) &&
3204102adabSPaul E. McKenney 	       current->lockdep_recursion == 0;
3214102adabSPaul E. McKenney }
3224102adabSPaul E. McKenney EXPORT_SYMBOL_GPL(debug_lockdep_rcu_enabled);
3234102adabSPaul E. McKenney 
3244102adabSPaul E. McKenney /**
32585b39d30SOleg Nesterov  * rcu_read_lock_held() - might we be in RCU read-side critical section?
32685b39d30SOleg Nesterov  *
32785b39d30SOleg Nesterov  * If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an RCU
32885b39d30SOleg Nesterov  * read-side critical section.  In absence of CONFIG_DEBUG_LOCK_ALLOC,
32985b39d30SOleg Nesterov  * this assumes we are in an RCU read-side critical section unless it can
33085b39d30SOleg Nesterov  * prove otherwise.  This is useful for debug checks in functions that
33185b39d30SOleg Nesterov  * require that they be called within an RCU read-side critical section.
33285b39d30SOleg Nesterov  *
33385b39d30SOleg Nesterov  * Checks debug_lockdep_rcu_enabled() to prevent false positives during boot
33485b39d30SOleg Nesterov  * and while lockdep is disabled.
33585b39d30SOleg Nesterov  *
33685b39d30SOleg Nesterov  * Note that rcu_read_lock() and the matching rcu_read_unlock() must
33785b39d30SOleg Nesterov  * occur in the same context, for example, it is illegal to invoke
33885b39d30SOleg Nesterov  * rcu_read_unlock() in process context if the matching rcu_read_lock()
33985b39d30SOleg Nesterov  * was invoked from within an irq handler.
34085b39d30SOleg Nesterov  *
34185b39d30SOleg Nesterov  * Note that rcu_read_lock() is disallowed if the CPU is either idle or
34285b39d30SOleg Nesterov  * offline from an RCU perspective, so check for those as well.
34385b39d30SOleg Nesterov  */
rcu_read_lock_held(void)34485b39d30SOleg Nesterov int rcu_read_lock_held(void)
34585b39d30SOleg Nesterov {
34628875945SJoel Fernandes (Google) 	bool ret;
34728875945SJoel Fernandes (Google) 
34828875945SJoel Fernandes (Google) 	if (rcu_read_lock_held_common(&ret))
34928875945SJoel Fernandes (Google) 		return ret;
35085b39d30SOleg Nesterov 	return lock_is_held(&rcu_lock_map);
35185b39d30SOleg Nesterov }
35285b39d30SOleg Nesterov EXPORT_SYMBOL_GPL(rcu_read_lock_held);
35385b39d30SOleg Nesterov 
35485b39d30SOleg Nesterov /**
3554102adabSPaul E. McKenney  * rcu_read_lock_bh_held() - might we be in RCU-bh read-side critical section?
3564102adabSPaul E. McKenney  *
3574102adabSPaul E. McKenney  * Check for bottom half being disabled, which covers both the
3584102adabSPaul E. McKenney  * CONFIG_PROVE_RCU and not cases.  Note that if someone uses
3594102adabSPaul E. McKenney  * rcu_read_lock_bh(), but then later enables BH, lockdep (if enabled)
3604102adabSPaul E. McKenney  * will show the situation.  This is useful for debug checks in functions
3614102adabSPaul E. McKenney  * that require that they be called within an RCU read-side critical
3624102adabSPaul E. McKenney  * section.
3634102adabSPaul E. McKenney  *
3644102adabSPaul E. McKenney  * Check debug_lockdep_rcu_enabled() to prevent false positives during boot.
3654102adabSPaul E. McKenney  *
36682fcecfaSPaul E. McKenney  * Note that rcu_read_lock_bh() is disallowed if the CPU is either idle or
3674102adabSPaul E. McKenney  * offline from an RCU perspective, so check for those as well.
3684102adabSPaul E. McKenney  */
rcu_read_lock_bh_held(void)3694102adabSPaul E. McKenney int rcu_read_lock_bh_held(void)
3704102adabSPaul E. McKenney {
37128875945SJoel Fernandes (Google) 	bool ret;
37228875945SJoel Fernandes (Google) 
37328875945SJoel Fernandes (Google) 	if (rcu_read_lock_held_common(&ret))
37428875945SJoel Fernandes (Google) 		return ret;
3754102adabSPaul E. McKenney 	return in_softirq() || irqs_disabled();
3764102adabSPaul E. McKenney }
3774102adabSPaul E. McKenney EXPORT_SYMBOL_GPL(rcu_read_lock_bh_held);
3784102adabSPaul E. McKenney 
rcu_read_lock_any_held(void)37928875945SJoel Fernandes (Google) int rcu_read_lock_any_held(void)
38028875945SJoel Fernandes (Google) {
38128875945SJoel Fernandes (Google) 	bool ret;
38228875945SJoel Fernandes (Google) 
38328875945SJoel Fernandes (Google) 	if (rcu_read_lock_held_common(&ret))
38428875945SJoel Fernandes (Google) 		return ret;
38528875945SJoel Fernandes (Google) 	if (lock_is_held(&rcu_lock_map) ||
38628875945SJoel Fernandes (Google) 	    lock_is_held(&rcu_bh_lock_map) ||
38728875945SJoel Fernandes (Google) 	    lock_is_held(&rcu_sched_lock_map))
38828875945SJoel Fernandes (Google) 		return 1;
38928875945SJoel Fernandes (Google) 	return !preemptible();
39028875945SJoel Fernandes (Google) }
39128875945SJoel Fernandes (Google) EXPORT_SYMBOL_GPL(rcu_read_lock_any_held);
39228875945SJoel Fernandes (Google) 
3934102adabSPaul E. McKenney #endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
3944102adabSPaul E. McKenney 
395ee376dbdSPaul E. McKenney /**
396ee376dbdSPaul E. McKenney  * wakeme_after_rcu() - Callback function to awaken a task after grace period
397ee376dbdSPaul E. McKenney  * @head: Pointer to rcu_head member within rcu_synchronize structure
398ee376dbdSPaul E. McKenney  *
399ee376dbdSPaul E. McKenney  * Awaken the corresponding task now that a grace period has elapsed.
4004102adabSPaul E. McKenney  */
wakeme_after_rcu(struct rcu_head * head)401ee376dbdSPaul E. McKenney void wakeme_after_rcu(struct rcu_head *head)
4024102adabSPaul E. McKenney {
4034102adabSPaul E. McKenney 	struct rcu_synchronize *rcu;
4044102adabSPaul E. McKenney 
4054102adabSPaul E. McKenney 	rcu = container_of(head, struct rcu_synchronize, head);
4064102adabSPaul E. McKenney 	complete(&rcu->completion);
4074102adabSPaul E. McKenney }
408ec90a194SPaul E. McKenney EXPORT_SYMBOL_GPL(wakeme_after_rcu);
4094102adabSPaul E. McKenney 
__wait_rcu_gp(bool checktiny,int n,call_rcu_func_t * crcu_array,struct rcu_synchronize * rs_array)410ec90a194SPaul E. McKenney void __wait_rcu_gp(bool checktiny, int n, call_rcu_func_t *crcu_array,
411ec90a194SPaul E. McKenney 		   struct rcu_synchronize *rs_array)
4124102adabSPaul E. McKenney {
413ec90a194SPaul E. McKenney 	int i;
41468ab0b42SPaul E. McKenney 	int j;
4154102adabSPaul E. McKenney 
41606462efcSPaul E. McKenney 	/* Initialize and register callbacks for each crcu_array element. */
417ec90a194SPaul E. McKenney 	for (i = 0; i < n; i++) {
418ec90a194SPaul E. McKenney 		if (checktiny &&
419309ba859SPaul E. McKenney 		    (crcu_array[i] == call_rcu)) {
420ec90a194SPaul E. McKenney 			might_sleep();
421ec90a194SPaul E. McKenney 			continue;
4224102adabSPaul E. McKenney 		}
42368ab0b42SPaul E. McKenney 		for (j = 0; j < i; j++)
42468ab0b42SPaul E. McKenney 			if (crcu_array[j] == crcu_array[i])
42568ab0b42SPaul E. McKenney 				break;
4267ee880b7SWei Yang 		if (j == i) {
4277ee880b7SWei Yang 			init_rcu_head_on_stack(&rs_array[i].head);
4287ee880b7SWei Yang 			init_completion(&rs_array[i].completion);
429ec90a194SPaul E. McKenney 			(crcu_array[i])(&rs_array[i].head, wakeme_after_rcu);
430ec90a194SPaul E. McKenney 		}
4317ee880b7SWei Yang 	}
432ec90a194SPaul E. McKenney 
433ec90a194SPaul E. McKenney 	/* Wait for all callbacks to be invoked. */
434ec90a194SPaul E. McKenney 	for (i = 0; i < n; i++) {
435ec90a194SPaul E. McKenney 		if (checktiny &&
436309ba859SPaul E. McKenney 		    (crcu_array[i] == call_rcu))
437ec90a194SPaul E. McKenney 			continue;
43868ab0b42SPaul E. McKenney 		for (j = 0; j < i; j++)
43968ab0b42SPaul E. McKenney 			if (crcu_array[j] == crcu_array[i])
44068ab0b42SPaul E. McKenney 				break;
4417ee880b7SWei Yang 		if (j == i) {
442ec90a194SPaul E. McKenney 			wait_for_completion(&rs_array[i].completion);
443ec90a194SPaul E. McKenney 			destroy_rcu_head_on_stack(&rs_array[i].head);
444ec90a194SPaul E. McKenney 		}
445ec90a194SPaul E. McKenney 	}
4467ee880b7SWei Yang }
447ec90a194SPaul E. McKenney EXPORT_SYMBOL_GPL(__wait_rcu_gp);
4484102adabSPaul E. McKenney 
finish_rcuwait(struct rcuwait * w)44958d4292bSIngo Molnar void finish_rcuwait(struct rcuwait *w)
45058d4292bSIngo Molnar {
45158d4292bSIngo Molnar 	rcu_assign_pointer(w->task, NULL);
45258d4292bSIngo Molnar 	__set_current_state(TASK_RUNNING);
45358d4292bSIngo Molnar }
45458d4292bSIngo Molnar EXPORT_SYMBOL_GPL(finish_rcuwait);
45558d4292bSIngo Molnar 
4564102adabSPaul E. McKenney #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
init_rcu_head(struct rcu_head * head)457546a9d85SPaul E. McKenney void init_rcu_head(struct rcu_head *head)
4584102adabSPaul E. McKenney {
4594102adabSPaul E. McKenney 	debug_object_init(head, &rcuhead_debug_descr);
4604102adabSPaul E. McKenney }
461156baec3SPaul E. McKenney EXPORT_SYMBOL_GPL(init_rcu_head);
4624102adabSPaul E. McKenney 
destroy_rcu_head(struct rcu_head * head)463546a9d85SPaul E. McKenney void destroy_rcu_head(struct rcu_head *head)
4644102adabSPaul E. McKenney {
4654102adabSPaul E. McKenney 	debug_object_free(head, &rcuhead_debug_descr);
4664102adabSPaul E. McKenney }
467156baec3SPaul E. McKenney EXPORT_SYMBOL_GPL(destroy_rcu_head);
4684102adabSPaul E. McKenney 
rcuhead_is_static_object(void * addr)469b9fdac7fSDu, Changbin static bool rcuhead_is_static_object(void *addr)
4704102adabSPaul E. McKenney {
4713263d28eSDu, Changbin 	return true;
4724102adabSPaul E. McKenney }
4734102adabSPaul E. McKenney 
4744102adabSPaul E. McKenney /**
4754102adabSPaul E. McKenney  * init_rcu_head_on_stack() - initialize on-stack rcu_head for debugobjects
4764102adabSPaul E. McKenney  * @head: pointer to rcu_head structure to be initialized
4774102adabSPaul E. McKenney  *
4784102adabSPaul E. McKenney  * This function informs debugobjects of a new rcu_head structure that
4794102adabSPaul E. McKenney  * has been allocated as an auto variable on the stack.  This function
4804102adabSPaul E. McKenney  * is not required for rcu_head structures that are statically defined or
4814102adabSPaul E. McKenney  * that are dynamically allocated on the heap.  This function has no
4824102adabSPaul E. McKenney  * effect for !CONFIG_DEBUG_OBJECTS_RCU_HEAD kernel builds.
4834102adabSPaul E. McKenney  */
init_rcu_head_on_stack(struct rcu_head * head)4844102adabSPaul E. McKenney void init_rcu_head_on_stack(struct rcu_head *head)
4854102adabSPaul E. McKenney {
4864102adabSPaul E. McKenney 	debug_object_init_on_stack(head, &rcuhead_debug_descr);
4874102adabSPaul E. McKenney }
4884102adabSPaul E. McKenney EXPORT_SYMBOL_GPL(init_rcu_head_on_stack);
4894102adabSPaul E. McKenney 
4904102adabSPaul E. McKenney /**
4914102adabSPaul E. McKenney  * destroy_rcu_head_on_stack() - destroy on-stack rcu_head for debugobjects
4924102adabSPaul E. McKenney  * @head: pointer to rcu_head structure to be initialized
4934102adabSPaul E. McKenney  *
4944102adabSPaul E. McKenney  * This function informs debugobjects that an on-stack rcu_head structure
4954102adabSPaul E. McKenney  * is about to go out of scope.  As with init_rcu_head_on_stack(), this
4964102adabSPaul E. McKenney  * function is not required for rcu_head structures that are statically
4974102adabSPaul E. McKenney  * defined or that are dynamically allocated on the heap.  Also as with
4984102adabSPaul E. McKenney  * init_rcu_head_on_stack(), this function has no effect for
4994102adabSPaul E. McKenney  * !CONFIG_DEBUG_OBJECTS_RCU_HEAD kernel builds.
5004102adabSPaul E. McKenney  */
destroy_rcu_head_on_stack(struct rcu_head * head)5014102adabSPaul E. McKenney void destroy_rcu_head_on_stack(struct rcu_head *head)
5024102adabSPaul E. McKenney {
5034102adabSPaul E. McKenney 	debug_object_free(head, &rcuhead_debug_descr);
5044102adabSPaul E. McKenney }
5054102adabSPaul E. McKenney EXPORT_SYMBOL_GPL(destroy_rcu_head_on_stack);
5064102adabSPaul E. McKenney 
507f9e62f31SStephen Boyd const struct debug_obj_descr rcuhead_debug_descr = {
5084102adabSPaul E. McKenney 	.name = "rcu_head",
509b9fdac7fSDu, Changbin 	.is_static_object = rcuhead_is_static_object,
5104102adabSPaul E. McKenney };
5114102adabSPaul E. McKenney EXPORT_SYMBOL_GPL(rcuhead_debug_descr);
5124102adabSPaul E. McKenney #endif /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
5134102adabSPaul E. McKenney 
514b3e627d3SLai Jiangshan #if defined(CONFIG_TREE_RCU) || defined(CONFIG_RCU_TRACE)
do_trace_rcu_torture_read(const char * rcutorturename,struct rcu_head * rhp,unsigned long secs,unsigned long c_old,unsigned long c)5154102adabSPaul E. McKenney void do_trace_rcu_torture_read(const char *rcutorturename, struct rcu_head *rhp,
5164102adabSPaul E. McKenney 			       unsigned long secs,
5174102adabSPaul E. McKenney 			       unsigned long c_old, unsigned long c)
5184102adabSPaul E. McKenney {
5194102adabSPaul E. McKenney 	trace_rcu_torture_read(rcutorturename, rhp, secs, c_old, c);
5204102adabSPaul E. McKenney }
5214102adabSPaul E. McKenney EXPORT_SYMBOL_GPL(do_trace_rcu_torture_read);
5224102adabSPaul E. McKenney #else
5234102adabSPaul E. McKenney #define do_trace_rcu_torture_read(rcutorturename, rhp, secs, c_old, c) \
5244102adabSPaul E. McKenney 	do { } while (0)
5254102adabSPaul E. McKenney #endif
5264102adabSPaul E. McKenney 
527c682db55SPaul E. McKenney #if IS_ENABLED(CONFIG_RCU_TORTURE_TEST) || IS_MODULE(CONFIG_RCU_TORTURE_TEST)
528c682db55SPaul E. McKenney /* Get rcutorture access to sched_setaffinity(). */
rcutorture_sched_setaffinity(pid_t pid,const struct cpumask * in_mask)529c682db55SPaul E. McKenney long rcutorture_sched_setaffinity(pid_t pid, const struct cpumask *in_mask)
530c682db55SPaul E. McKenney {
531c682db55SPaul E. McKenney 	int ret;
532c682db55SPaul E. McKenney 
533c682db55SPaul E. McKenney 	ret = sched_setaffinity(pid, in_mask);
534c682db55SPaul E. McKenney 	WARN_ONCE(ret, "%s: sched_setaffinity() returned %d\n", __func__, ret);
535c682db55SPaul E. McKenney 	return ret;
536c682db55SPaul E. McKenney }
537c682db55SPaul E. McKenney EXPORT_SYMBOL_GPL(rcutorture_sched_setaffinity);
538c682db55SPaul E. McKenney #endif
539c682db55SPaul E. McKenney 
5404102adabSPaul E. McKenney #ifdef CONFIG_RCU_STALL_COMMON
541cdc694b2SPaul E. McKenney int rcu_cpu_stall_ftrace_dump __read_mostly;
542cdc694b2SPaul E. McKenney module_param(rcu_cpu_stall_ftrace_dump, int, 0644);
54358c53360SPaul E. McKenney int rcu_cpu_stall_suppress __read_mostly; // !0 = suppress stall warnings.
544f22ce091SPaul E. McKenney EXPORT_SYMBOL_GPL(rcu_cpu_stall_suppress);
5454102adabSPaul E. McKenney module_param(rcu_cpu_stall_suppress, int, 0644);
54610462d6fSPaul E. McKenney int rcu_cpu_stall_timeout __read_mostly = CONFIG_RCU_CPU_STALL_TIMEOUT;
5474102adabSPaul E. McKenney module_param(rcu_cpu_stall_timeout, int, 0644);
54828b3ae42SUladzislau Rezki int rcu_exp_cpu_stall_timeout __read_mostly = CONFIG_RCU_EXP_CPU_STALL_TIMEOUT;
54928b3ae42SUladzislau Rezki module_param(rcu_exp_cpu_stall_timeout, int, 0644);
550be42f00bSZhen Lei int rcu_cpu_stall_cputime __read_mostly = IS_ENABLED(CONFIG_RCU_CPU_STALL_CPUTIME);
551be42f00bSZhen Lei module_param(rcu_cpu_stall_cputime, int, 0644);
55292987fe8SPaul E. McKenney bool rcu_exp_stall_task_details __read_mostly;
55392987fe8SPaul E. McKenney module_param(rcu_exp_stall_task_details, bool, 0644);
5544102adabSPaul E. McKenney #endif /* #ifdef CONFIG_RCU_STALL_COMMON */
5558315f422SPaul E. McKenney 
55658c53360SPaul E. McKenney // Suppress boot-time RCU CPU stall warnings and rcutorture writer stall
55758c53360SPaul E. McKenney // warnings.  Also used by rcutorture even if stall warnings are excluded.
55858c53360SPaul E. McKenney int rcu_cpu_stall_suppress_at_boot __read_mostly; // !0 = suppress boot stalls.
55958c53360SPaul E. McKenney EXPORT_SYMBOL_GPL(rcu_cpu_stall_suppress_at_boot);
56058c53360SPaul E. McKenney module_param(rcu_cpu_stall_suppress_at_boot, int, 0444);
56158c53360SPaul E. McKenney 
562414c1238SPaul E. McKenney /**
563414c1238SPaul E. McKenney  * get_completed_synchronize_rcu - Return a pre-completed polled state cookie
564414c1238SPaul E. McKenney  *
565414c1238SPaul E. McKenney  * Returns a value that will always be treated by functions like
566414c1238SPaul E. McKenney  * poll_state_synchronize_rcu() as a cookie whose grace period has already
567414c1238SPaul E. McKenney  * completed.
568414c1238SPaul E. McKenney  */
get_completed_synchronize_rcu(void)569414c1238SPaul E. McKenney unsigned long get_completed_synchronize_rcu(void)
570414c1238SPaul E. McKenney {
571414c1238SPaul E. McKenney 	return RCU_GET_STATE_COMPLETED;
572414c1238SPaul E. McKenney }
573414c1238SPaul E. McKenney EXPORT_SYMBOL_GPL(get_completed_synchronize_rcu);
574414c1238SPaul E. McKenney 
575aa23c6fbSPranith Kumar #ifdef CONFIG_PROVE_RCU
576aa23c6fbSPranith Kumar 
577aa23c6fbSPranith Kumar /*
57872ce30ddSPaul E. McKenney  * Early boot self test parameters.
579aa23c6fbSPranith Kumar  */
580aa23c6fbSPranith Kumar static bool rcu_self_test;
581aa23c6fbSPranith Kumar module_param(rcu_self_test, bool, 0444);
582aa23c6fbSPranith Kumar 
583aa23c6fbSPranith Kumar static int rcu_self_test_counter;
584aa23c6fbSPranith Kumar 
test_callback(struct rcu_head * r)585aa23c6fbSPranith Kumar static void test_callback(struct rcu_head *r)
586aa23c6fbSPranith Kumar {
587aa23c6fbSPranith Kumar 	rcu_self_test_counter++;
588aa23c6fbSPranith Kumar 	pr_info("RCU test callback executed %d\n", rcu_self_test_counter);
589aa23c6fbSPranith Kumar }
590aa23c6fbSPranith Kumar 
591e0fcba9aSPaul E. McKenney DEFINE_STATIC_SRCU(early_srcu);
5920a580fa6SFrederic Weisbecker static unsigned long early_srcu_cookie;
593e0fcba9aSPaul E. McKenney 
594a35d1690SByungchul Park struct early_boot_kfree_rcu {
595a35d1690SByungchul Park 	struct rcu_head rh;
596a35d1690SByungchul Park };
597a35d1690SByungchul Park 
early_boot_test_call_rcu(void)598aa23c6fbSPranith Kumar static void early_boot_test_call_rcu(void)
599aa23c6fbSPranith Kumar {
600aa23c6fbSPranith Kumar 	static struct rcu_head head;
601efa3c40cSPaul E. McKenney 	int idx;
602e0fcba9aSPaul E. McKenney 	static struct rcu_head shead;
603a35d1690SByungchul Park 	struct early_boot_kfree_rcu *rhp;
604aa23c6fbSPranith Kumar 
605efa3c40cSPaul E. McKenney 	idx = srcu_down_read(&early_srcu);
606efa3c40cSPaul E. McKenney 	srcu_up_read(&early_srcu, idx);
607aa23c6fbSPranith Kumar 	call_rcu(&head, test_callback);
6080a580fa6SFrederic Weisbecker 	early_srcu_cookie = start_poll_synchronize_srcu(&early_srcu);
609e0fcba9aSPaul E. McKenney 	call_srcu(&early_srcu, &shead, test_callback);
610a35d1690SByungchul Park 	rhp = kmalloc(sizeof(*rhp), GFP_KERNEL);
611a35d1690SByungchul Park 	if (!WARN_ON_ONCE(!rhp))
612a35d1690SByungchul Park 		kfree_rcu(rhp, rh);
613aa23c6fbSPranith Kumar }
614aa23c6fbSPranith Kumar 
rcu_early_boot_tests(void)615aa23c6fbSPranith Kumar void rcu_early_boot_tests(void)
616aa23c6fbSPranith Kumar {
617aa23c6fbSPranith Kumar 	pr_info("Running RCU self tests\n");
618aa23c6fbSPranith Kumar 
619aa23c6fbSPranith Kumar 	if (rcu_self_test)
620aa23c6fbSPranith Kumar 		early_boot_test_call_rcu();
62152d7e48bSPaul E. McKenney 	rcu_test_sync_prims();
622aa23c6fbSPranith Kumar }
623aa23c6fbSPranith Kumar 
rcu_verify_early_boot_tests(void)624aa23c6fbSPranith Kumar static int rcu_verify_early_boot_tests(void)
625aa23c6fbSPranith Kumar {
626aa23c6fbSPranith Kumar 	int ret = 0;
627aa23c6fbSPranith Kumar 	int early_boot_test_counter = 0;
628aa23c6fbSPranith Kumar 
629aa23c6fbSPranith Kumar 	if (rcu_self_test) {
630aa23c6fbSPranith Kumar 		early_boot_test_counter++;
631aa23c6fbSPranith Kumar 		rcu_barrier();
632aa23c6fbSPranith Kumar 		early_boot_test_counter++;
633e0fcba9aSPaul E. McKenney 		srcu_barrier(&early_srcu);
6340a580fa6SFrederic Weisbecker 		WARN_ON_ONCE(!poll_state_synchronize_srcu(&early_srcu, early_srcu_cookie));
63566ea1029SZqiang 		cleanup_srcu_struct(&early_srcu);
636aa23c6fbSPranith Kumar 	}
637aa23c6fbSPranith Kumar 	if (rcu_self_test_counter != early_boot_test_counter) {
638aa23c6fbSPranith Kumar 		WARN_ON(1);
639aa23c6fbSPranith Kumar 		ret = -1;
640aa23c6fbSPranith Kumar 	}
641aa23c6fbSPranith Kumar 
642aa23c6fbSPranith Kumar 	return ret;
643aa23c6fbSPranith Kumar }
644aa23c6fbSPranith Kumar late_initcall(rcu_verify_early_boot_tests);
645aa23c6fbSPranith Kumar #else
rcu_early_boot_tests(void)646aa23c6fbSPranith Kumar void rcu_early_boot_tests(void) {}
647aa23c6fbSPranith Kumar #endif /* CONFIG_PROVE_RCU */
64859d80fd8SPaul E. McKenney 
649eacd6f04SPaul E. McKenney #include "tasks.h"
650eacd6f04SPaul E. McKenney 
65159d80fd8SPaul E. McKenney #ifndef CONFIG_TINY_RCU
65259d80fd8SPaul E. McKenney 
65359d80fd8SPaul E. McKenney /*
65459d80fd8SPaul E. McKenney  * Print any significant non-default boot-time settings.
65559d80fd8SPaul E. McKenney  */
rcupdate_announce_bootup_oddness(void)65659d80fd8SPaul E. McKenney void __init rcupdate_announce_bootup_oddness(void)
65759d80fd8SPaul E. McKenney {
65859d80fd8SPaul E. McKenney 	if (rcu_normal)
65959d80fd8SPaul E. McKenney 		pr_info("\tNo expedited grace period (rcu_normal).\n");
66059d80fd8SPaul E. McKenney 	else if (rcu_normal_after_boot)
66159d80fd8SPaul E. McKenney 		pr_info("\tNo expedited grace period (rcu_normal_after_boot).\n");
66259d80fd8SPaul E. McKenney 	else if (rcu_expedited)
66359d80fd8SPaul E. McKenney 		pr_info("\tAll grace periods are expedited (rcu_expedited).\n");
66459d80fd8SPaul E. McKenney 	if (rcu_cpu_stall_suppress)
66559d80fd8SPaul E. McKenney 		pr_info("\tRCU CPU stall warnings suppressed (rcu_cpu_stall_suppress).\n");
66659d80fd8SPaul E. McKenney 	if (rcu_cpu_stall_timeout != CONFIG_RCU_CPU_STALL_TIMEOUT)
66759d80fd8SPaul E. McKenney 		pr_info("\tRCU CPU stall warnings timeout set to %d (rcu_cpu_stall_timeout).\n", rcu_cpu_stall_timeout);
66859d80fd8SPaul E. McKenney 	rcu_tasks_bootup_oddness();
66959d80fd8SPaul E. McKenney }
67059d80fd8SPaul E. McKenney 
67159d80fd8SPaul E. McKenney #endif /* #ifndef CONFIG_TINY_RCU */
672