| .. | .. | 
|---|
 | 1 | +// SPDX-License-Identifier: GPL-2.0+  | 
|---|
| 1 | 2 |  /* | 
|---|
| 2 | 3 |   * Read-Copy Update mechanism for mutual exclusion | 
|---|
| 3 |  | - *  | 
|---|
| 4 |  | - * This program is free software; you can redistribute it and/or modify  | 
|---|
| 5 |  | - * it under the terms of the GNU General Public License as published by  | 
|---|
| 6 |  | - * the Free Software Foundation; either version 2 of the License, or  | 
|---|
| 7 |  | - * (at your option) any later version.  | 
|---|
| 8 |  | - *  | 
|---|
| 9 |  | - * This program is distributed in the hope that it will be useful,  | 
|---|
| 10 |  | - * but WITHOUT ANY WARRANTY; without even the implied warranty of  | 
|---|
| 11 |  | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  | 
|---|
| 12 |  | - * GNU General Public License for more details.  | 
|---|
| 13 |  | - *  | 
|---|
| 14 |  | - * You should have received a copy of the GNU General Public License  | 
|---|
| 15 |  | - * along with this program; if not, you can access it online at  | 
|---|
| 16 |  | - * http://www.gnu.org/licenses/gpl-2.0.html.  | 
|---|
| 17 | 4 |   * | 
|---|
| 18 | 5 |   * Copyright IBM Corporation, 2001 | 
|---|
| 19 | 6 |   * | 
|---|
| 20 | 7 |   * Authors: Dipankar Sarma <dipankar@in.ibm.com> | 
|---|
| 21 | 8 |   *	    Manfred Spraul <manfred@colorfullife.com> | 
|---|
| 22 | 9 |   * | 
|---|
| 23 |  | - * Based on the original work by Paul McKenney <paulmck@us.ibm.com>  | 
|---|
 | 10 | + * Based on the original work by Paul McKenney <paulmck@linux.ibm.com>  | 
|---|
| 24 | 11 |   * and inputs from Rusty Russell, Andrea Arcangeli and Andi Kleen. | 
|---|
| 25 | 12 |   * Papers: | 
|---|
| 26 | 13 |   * http://www.rdrop.com/users/paulmck/paper/rclockpdcsproof.pdf | 
|---|
| .. | .. | 
|---|
| 53 | 40 |  #include <linux/rcupdate_wait.h> | 
|---|
| 54 | 41 |  #include <linux/sched/isolation.h> | 
|---|
| 55 | 42 |  #include <linux/kprobes.h> | 
|---|
 | 43 | +#include <linux/slab.h>  | 
|---|
 | 44 | +#include <linux/irq_work.h>  | 
|---|
 | 45 | +#include <linux/rcupdate_trace.h>  | 
|---|
| 56 | 46 |   | 
|---|
| 57 | 47 |  #define CREATE_TRACE_POINTS | 
|---|
| 58 | 48 |   | 
|---|
| .. | .. | 
|---|
| 64 | 54 |  #define MODULE_PARAM_PREFIX "rcupdate." | 
|---|
| 65 | 55 |   | 
|---|
| 66 | 56 |  #ifndef CONFIG_TINY_RCU | 
|---|
| 67 |  | -extern int rcu_expedited; /* from sysctl */  | 
|---|
| 68 | 57 |  module_param(rcu_expedited, int, 0); | 
|---|
| 69 |  | -extern int rcu_normal; /* from sysctl */  | 
|---|
| 70 | 58 |  module_param(rcu_normal, int, 0); | 
|---|
| 71 |  | -static int rcu_normal_after_boot = IS_ENABLED(CONFIG_PREEMPT_RT_FULL);  | 
|---|
| 72 |  | -#ifndef CONFIG_PREEMPT_RT_FULL  | 
|---|
 | 59 | +static int rcu_normal_after_boot = IS_ENABLED(CONFIG_PREEMPT_RT);  | 
|---|
 | 60 | +#ifndef CONFIG_PREEMPT_RT  | 
|---|
| 73 | 61 |  module_param(rcu_normal_after_boot, int, 0); | 
|---|
| 74 | 62 |  #endif | 
|---|
| 75 | 63 |  #endif /* #ifndef CONFIG_TINY_RCU */ | 
|---|
| 76 | 64 |   | 
|---|
| 77 | 65 |  #ifdef CONFIG_DEBUG_LOCK_ALLOC | 
|---|
| 78 | 66 |  /** | 
|---|
| 79 |  | - * rcu_read_lock_sched_held() - might we be in RCU-sched read-side critical section?  | 
|---|
 | 67 | + * rcu_read_lock_held_common() - might we be in RCU-sched read-side critical section?  | 
|---|
 | 68 | + * @ret:	Best guess answer if lockdep cannot be relied on  | 
|---|
| 80 | 69 |   * | 
|---|
| 81 |  | - * If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an  | 
|---|
 | 70 | + * Returns true if lockdep must be ignored, in which case ``*ret`` contains  | 
|---|
 | 71 | + * the best guess described below.  Otherwise returns false, in which  | 
|---|
 | 72 | + * case ``*ret`` tells the caller nothing and the caller should instead  | 
|---|
 | 73 | + * consult lockdep.  | 
|---|
 | 74 | + *  | 
|---|
 | 75 | + * If CONFIG_DEBUG_LOCK_ALLOC is selected, set ``*ret`` to nonzero iff in an  | 
|---|
| 82 | 76 |   * RCU-sched read-side critical section.  In absence of | 
|---|
| 83 | 77 |   * CONFIG_DEBUG_LOCK_ALLOC, this assumes we are in an RCU-sched read-side | 
|---|
| 84 | 78 |   * critical section unless it can prove otherwise.  Note that disabling | 
|---|
| .. | .. | 
|---|
| 90 | 84 |   * Check debug_lockdep_rcu_enabled() to prevent false positives during boot | 
|---|
| 91 | 85 |   * and while lockdep is disabled. | 
|---|
| 92 | 86 |   * | 
|---|
| 93 |  | - * Note that if the CPU is in the idle loop from an RCU point of  | 
|---|
| 94 |  | - * view (ie: that we are in the section between rcu_idle_enter() and  | 
|---|
| 95 |  | - * rcu_idle_exit()) then rcu_read_lock_held() returns false even if the CPU  | 
|---|
| 96 |  | - * did an rcu_read_lock().  The reason for this is that RCU ignores CPUs  | 
|---|
| 97 |  | - * that are in such a section, considering these as in extended quiescent  | 
|---|
| 98 |  | - * state, so such a CPU is effectively never in an RCU read-side critical  | 
|---|
| 99 |  | - * section regardless of what RCU primitives it invokes.  This state of  | 
|---|
| 100 |  | - * affairs is required --- we need to keep an RCU-free window in idle  | 
|---|
| 101 |  | - * where the CPU may possibly enter into low power mode. This way we can  | 
|---|
| 102 |  | - * notice an extended quiescent state to other CPUs that started a grace  | 
|---|
| 103 |  | - * period. Otherwise we would delay any grace period as long as we run in  | 
|---|
| 104 |  | - * the idle task.  | 
|---|
 | 87 | + * Note that if the CPU is in the idle loop from an RCU point of view (ie:  | 
|---|
 | 88 | + * that we are in the section between rcu_idle_enter() and rcu_idle_exit())  | 
|---|
 | 89 | + * then rcu_read_lock_held() sets ``*ret`` to false even if the CPU did an  | 
|---|
 | 90 | + * rcu_read_lock().  The reason for this is that RCU ignores CPUs that are  | 
|---|
 | 91 | + * in such a section, considering these as in extended quiescent state,  | 
|---|
 | 92 | + * so such a CPU is effectively never in an RCU read-side critical section  | 
|---|
 | 93 | + * regardless of what RCU primitives it invokes.  This state of affairs is  | 
|---|
 | 94 | + * required --- we need to keep an RCU-free window in idle where the CPU may  | 
|---|
 | 95 | + * possibly enter into low power mode. This way we can notice an extended  | 
|---|
 | 96 | + * quiescent state to other CPUs that started a grace period. Otherwise  | 
|---|
 | 97 | + * we would delay any grace period as long as we run in the idle task.  | 
|---|
| 105 | 98 |   * | 
|---|
| 106 |  | - * Similarly, we avoid claiming an SRCU read lock held if the current  | 
|---|
 | 99 | + * Similarly, we avoid claiming an RCU read lock held if the current  | 
|---|
| 107 | 100 |   * CPU is offline. | 
|---|
| 108 | 101 |   */ | 
|---|
 | 102 | +static bool rcu_read_lock_held_common(bool *ret)  | 
|---|
 | 103 | +{  | 
|---|
 | 104 | +	if (!debug_lockdep_rcu_enabled()) {  | 
|---|
 | 105 | +		*ret = true;  | 
|---|
 | 106 | +		return true;  | 
|---|
 | 107 | +	}  | 
|---|
 | 108 | +	if (!rcu_is_watching()) {  | 
|---|
 | 109 | +		*ret = false;  | 
|---|
 | 110 | +		return true;  | 
|---|
 | 111 | +	}  | 
|---|
 | 112 | +	if (!rcu_lockdep_current_cpu_online()) {  | 
|---|
 | 113 | +		*ret = false;  | 
|---|
 | 114 | +		return true;  | 
|---|
 | 115 | +	}  | 
|---|
 | 116 | +	return false;  | 
|---|
 | 117 | +}  | 
|---|
 | 118 | +  | 
|---|
| 109 | 119 |  int rcu_read_lock_sched_held(void) | 
|---|
| 110 | 120 |  { | 
|---|
| 111 |  | -	int lockdep_opinion = 0;  | 
|---|
 | 121 | +	bool ret;  | 
|---|
| 112 | 122 |   | 
|---|
| 113 |  | -	if (!debug_lockdep_rcu_enabled())  | 
|---|
| 114 |  | -		return 1;  | 
|---|
| 115 |  | -	if (!rcu_is_watching())  | 
|---|
| 116 |  | -		return 0;  | 
|---|
| 117 |  | -	if (!rcu_lockdep_current_cpu_online())  | 
|---|
| 118 |  | -		return 0;  | 
|---|
| 119 |  | -	if (debug_locks)  | 
|---|
| 120 |  | -		lockdep_opinion = lock_is_held(&rcu_sched_lock_map);  | 
|---|
| 121 |  | -	return lockdep_opinion || !preemptible();  | 
|---|
 | 123 | +	if (rcu_read_lock_held_common(&ret))  | 
|---|
 | 124 | +		return ret;  | 
|---|
 | 125 | +	return lock_is_held(&rcu_sched_lock_map) || !preemptible();  | 
|---|
| 122 | 126 |  } | 
|---|
| 123 | 127 |  EXPORT_SYMBOL(rcu_read_lock_sched_held); | 
|---|
| 124 | 128 |  #endif | 
|---|
| .. | .. | 
|---|
| 151 | 155 |   */ | 
|---|
| 152 | 156 |  bool rcu_gp_is_expedited(void) | 
|---|
| 153 | 157 |  { | 
|---|
| 154 |  | -	return rcu_expedited || atomic_read(&rcu_expedited_nesting) ||  | 
|---|
| 155 |  | -	       rcu_scheduler_active == RCU_SCHEDULER_INIT;  | 
|---|
 | 158 | +	return rcu_expedited || atomic_read(&rcu_expedited_nesting);  | 
|---|
| 156 | 159 |  } | 
|---|
| 157 | 160 |  EXPORT_SYMBOL_GPL(rcu_gp_is_expedited); | 
|---|
| 158 | 161 |   | 
|---|
| .. | .. | 
|---|
| 184 | 187 |  } | 
|---|
| 185 | 188 |  EXPORT_SYMBOL_GPL(rcu_unexpedite_gp); | 
|---|
| 186 | 189 |   | 
|---|
 | 190 | +static bool rcu_boot_ended __read_mostly;  | 
|---|
 | 191 | +  | 
|---|
| 187 | 192 |  /* | 
|---|
| 188 | 193 |   * Inform RCU of the end of the in-kernel boot sequence. | 
|---|
| 189 | 194 |   */ | 
|---|
| .. | .. | 
|---|
| 192 | 197 |  	rcu_unexpedite_gp(); | 
|---|
| 193 | 198 |  	if (rcu_normal_after_boot) | 
|---|
| 194 | 199 |  		WRITE_ONCE(rcu_normal, 1); | 
|---|
 | 200 | +	rcu_boot_ended = true;  | 
|---|
| 195 | 201 |  } | 
|---|
 | 202 | +  | 
|---|
 | 203 | +/*  | 
|---|
 | 204 | + * Let rcutorture know when it is OK to turn it up to eleven.  | 
|---|
 | 205 | + */  | 
|---|
 | 206 | +bool rcu_inkernel_boot_has_ended(void)  | 
|---|
 | 207 | +{  | 
|---|
 | 208 | +	return rcu_boot_ended;  | 
|---|
 | 209 | +}  | 
|---|
 | 210 | +EXPORT_SYMBOL_GPL(rcu_inkernel_boot_has_ended);  | 
|---|
| 196 | 211 |   | 
|---|
| 197 | 212 |  #endif /* #ifndef CONFIG_TINY_RCU */ | 
|---|
| 198 | 213 |   | 
|---|
| .. | .. | 
|---|
| 206 | 221 |  	if (!IS_ENABLED(CONFIG_PROVE_RCU)) | 
|---|
| 207 | 222 |  		return; | 
|---|
| 208 | 223 |  	synchronize_rcu(); | 
|---|
| 209 |  | -	synchronize_rcu_bh();  | 
|---|
| 210 |  | -	synchronize_sched();  | 
|---|
| 211 | 224 |  	synchronize_rcu_expedited(); | 
|---|
| 212 |  | -	synchronize_rcu_bh_expedited();  | 
|---|
| 213 |  | -	synchronize_sched_expedited();  | 
|---|
| 214 | 225 |  } | 
|---|
| 215 | 226 |   | 
|---|
| 216 | 227 |  #if !defined(CONFIG_TINY_RCU) || defined(CONFIG_SRCU) | 
|---|
| .. | .. | 
|---|
| 222 | 233 |  { | 
|---|
| 223 | 234 |  	rcu_test_sync_prims(); | 
|---|
| 224 | 235 |  	rcu_scheduler_active = RCU_SCHEDULER_RUNNING; | 
|---|
 | 236 | +	kfree_rcu_scheduler_running();  | 
|---|
| 225 | 237 |  	rcu_test_sync_prims(); | 
|---|
| 226 | 238 |  	return 0; | 
|---|
| 227 | 239 |  } | 
|---|
| .. | .. | 
|---|
| 231 | 243 |   | 
|---|
| 232 | 244 |  #ifdef CONFIG_DEBUG_LOCK_ALLOC | 
|---|
| 233 | 245 |  static struct lock_class_key rcu_lock_key; | 
|---|
| 234 |  | -struct lockdep_map rcu_lock_map =  | 
|---|
| 235 |  | -	STATIC_LOCKDEP_MAP_INIT("rcu_read_lock", &rcu_lock_key);  | 
|---|
 | 246 | +struct lockdep_map rcu_lock_map = {  | 
|---|
 | 247 | +	.name = "rcu_read_lock",  | 
|---|
 | 248 | +	.key = &rcu_lock_key,  | 
|---|
 | 249 | +	.wait_type_outer = LD_WAIT_FREE,  | 
|---|
 | 250 | +	.wait_type_inner = LD_WAIT_CONFIG, /* XXX PREEMPT_RCU ? */  | 
|---|
 | 251 | +};  | 
|---|
| 236 | 252 |  EXPORT_SYMBOL_GPL(rcu_lock_map); | 
|---|
| 237 | 253 |   | 
|---|
| 238 | 254 |  static struct lock_class_key rcu_bh_lock_key; | 
|---|
| 239 |  | -struct lockdep_map rcu_bh_lock_map =  | 
|---|
| 240 |  | -	STATIC_LOCKDEP_MAP_INIT("rcu_read_lock_bh", &rcu_bh_lock_key);  | 
|---|
 | 255 | +struct lockdep_map rcu_bh_lock_map = {  | 
|---|
 | 256 | +	.name = "rcu_read_lock_bh",  | 
|---|
 | 257 | +	.key = &rcu_bh_lock_key,  | 
|---|
 | 258 | +	.wait_type_outer = LD_WAIT_FREE,  | 
|---|
 | 259 | +	.wait_type_inner = LD_WAIT_CONFIG, /* PREEMPT_LOCK also makes BH preemptible */  | 
|---|
 | 260 | +};  | 
|---|
| 241 | 261 |  EXPORT_SYMBOL_GPL(rcu_bh_lock_map); | 
|---|
| 242 | 262 |   | 
|---|
| 243 | 263 |  static struct lock_class_key rcu_sched_lock_key; | 
|---|
| 244 |  | -struct lockdep_map rcu_sched_lock_map =  | 
|---|
| 245 |  | -	STATIC_LOCKDEP_MAP_INIT("rcu_read_lock_sched", &rcu_sched_lock_key);  | 
|---|
 | 264 | +struct lockdep_map rcu_sched_lock_map = {  | 
|---|
 | 265 | +	.name = "rcu_read_lock_sched",  | 
|---|
 | 266 | +	.key = &rcu_sched_lock_key,  | 
|---|
 | 267 | +	.wait_type_outer = LD_WAIT_FREE,  | 
|---|
 | 268 | +	.wait_type_inner = LD_WAIT_SPIN,  | 
|---|
 | 269 | +};  | 
|---|
| 246 | 270 |  EXPORT_SYMBOL_GPL(rcu_sched_lock_map); | 
|---|
| 247 | 271 |   | 
|---|
 | 272 | +// Tell lockdep when RCU callbacks are being invoked.  | 
|---|
| 248 | 273 |  static struct lock_class_key rcu_callback_key; | 
|---|
| 249 | 274 |  struct lockdep_map rcu_callback_map = | 
|---|
| 250 | 275 |  	STATIC_LOCKDEP_MAP_INIT("rcu_callback", &rcu_callback_key); | 
|---|
| 251 | 276 |  EXPORT_SYMBOL_GPL(rcu_callback_map); | 
|---|
| 252 | 277 |   | 
|---|
| 253 |  | -int notrace debug_lockdep_rcu_enabled(void)  | 
|---|
 | 278 | +noinstr int notrace debug_lockdep_rcu_enabled(void)  | 
|---|
| 254 | 279 |  { | 
|---|
| 255 |  | -	return rcu_scheduler_active != RCU_SCHEDULER_INACTIVE && debug_locks &&  | 
|---|
 | 280 | +	return rcu_scheduler_active != RCU_SCHEDULER_INACTIVE && READ_ONCE(debug_locks) &&  | 
|---|
| 256 | 281 |  	       current->lockdep_recursion == 0; | 
|---|
| 257 | 282 |  } | 
|---|
| 258 | 283 |  EXPORT_SYMBOL_GPL(debug_lockdep_rcu_enabled); | 
|---|
| 259 |  | -NOKPROBE_SYMBOL(debug_lockdep_rcu_enabled);  | 
|---|
| 260 | 284 |   | 
|---|
| 261 | 285 |  /** | 
|---|
| 262 | 286 |   * rcu_read_lock_held() - might we be in RCU read-side critical section? | 
|---|
| .. | .. | 
|---|
| 280 | 304 |   */ | 
|---|
| 281 | 305 |  int rcu_read_lock_held(void) | 
|---|
| 282 | 306 |  { | 
|---|
| 283 |  | -	if (!debug_lockdep_rcu_enabled())  | 
|---|
| 284 |  | -		return 1;  | 
|---|
| 285 |  | -	if (!rcu_is_watching())  | 
|---|
| 286 |  | -		return 0;  | 
|---|
| 287 |  | -	if (!rcu_lockdep_current_cpu_online())  | 
|---|
| 288 |  | -		return 0;  | 
|---|
 | 307 | +	bool ret;  | 
|---|
 | 308 | +  | 
|---|
 | 309 | +	if (rcu_read_lock_held_common(&ret))  | 
|---|
 | 310 | +		return ret;  | 
|---|
| 289 | 311 |  	return lock_is_held(&rcu_lock_map); | 
|---|
| 290 | 312 |  } | 
|---|
| 291 | 313 |  EXPORT_SYMBOL_GPL(rcu_read_lock_held); | 
|---|
| 292 | 314 |   | 
|---|
| 293 |  | -#ifndef CONFIG_PREEMPT_RT_FULL  | 
|---|
| 294 | 315 |  /** | 
|---|
| 295 | 316 |   * rcu_read_lock_bh_held() - might we be in RCU-bh read-side critical section? | 
|---|
| 296 | 317 |   * | 
|---|
| .. | .. | 
|---|
| 303 | 324 |   * | 
|---|
| 304 | 325 |   * Check debug_lockdep_rcu_enabled() to prevent false positives during boot. | 
|---|
| 305 | 326 |   * | 
|---|
| 306 |  | - * Note that rcu_read_lock() is disallowed if the CPU is either idle or  | 
|---|
 | 327 | + * Note that rcu_read_lock_bh() is disallowed if the CPU is either idle or  | 
|---|
| 307 | 328 |   * offline from an RCU perspective, so check for those as well. | 
|---|
| 308 | 329 |   */ | 
|---|
| 309 | 330 |  int rcu_read_lock_bh_held(void) | 
|---|
| 310 | 331 |  { | 
|---|
| 311 |  | -	if (!debug_lockdep_rcu_enabled())  | 
|---|
| 312 |  | -		return 1;  | 
|---|
| 313 |  | -	if (!rcu_is_watching())  | 
|---|
| 314 |  | -		return 0;  | 
|---|
| 315 |  | -	if (!rcu_lockdep_current_cpu_online())  | 
|---|
| 316 |  | -		return 0;  | 
|---|
 | 332 | +	bool ret;  | 
|---|
 | 333 | +  | 
|---|
 | 334 | +	if (rcu_read_lock_held_common(&ret))  | 
|---|
 | 335 | +		return ret;  | 
|---|
| 317 | 336 |  	return in_softirq() || irqs_disabled(); | 
|---|
| 318 | 337 |  } | 
|---|
| 319 | 338 |  EXPORT_SYMBOL_GPL(rcu_read_lock_bh_held); | 
|---|
| 320 |  | -#endif  | 
|---|
 | 339 | +  | 
|---|
 | 340 | +int rcu_read_lock_any_held(void)  | 
|---|
 | 341 | +{  | 
|---|
 | 342 | +	bool ret;  | 
|---|
 | 343 | +  | 
|---|
 | 344 | +	if (rcu_read_lock_held_common(&ret))  | 
|---|
 | 345 | +		return ret;  | 
|---|
 | 346 | +	if (lock_is_held(&rcu_lock_map) ||  | 
|---|
 | 347 | +	    lock_is_held(&rcu_bh_lock_map) ||  | 
|---|
 | 348 | +	    lock_is_held(&rcu_sched_lock_map))  | 
|---|
 | 349 | +		return 1;  | 
|---|
 | 350 | +	return !preemptible();  | 
|---|
 | 351 | +}  | 
|---|
 | 352 | +EXPORT_SYMBOL_GPL(rcu_read_lock_any_held);  | 
|---|
| 321 | 353 |   | 
|---|
| 322 | 354 |  #endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */ | 
|---|
| 323 | 355 |   | 
|---|
| .. | .. | 
|---|
| 342 | 374 |  	int i; | 
|---|
| 343 | 375 |  	int j; | 
|---|
| 344 | 376 |   | 
|---|
| 345 |  | -	/* Initialize and register callbacks for each flavor specified. */  | 
|---|
 | 377 | +	/* Initialize and register callbacks for each crcu_array element. */  | 
|---|
| 346 | 378 |  	for (i = 0; i < n; i++) { | 
|---|
| 347 | 379 |  		if (checktiny && | 
|---|
| 348 |  | -		    (crcu_array[i] == call_rcu ||  | 
|---|
| 349 |  | -		     crcu_array[i] == call_rcu_bh)) {  | 
|---|
 | 380 | +		    (crcu_array[i] == call_rcu)) {  | 
|---|
| 350 | 381 |  			might_sleep(); | 
|---|
| 351 | 382 |  			continue; | 
|---|
| 352 | 383 |  		} | 
|---|
| 353 |  | -		init_rcu_head_on_stack(&rs_array[i].head);  | 
|---|
| 354 |  | -		init_completion(&rs_array[i].completion);  | 
|---|
| 355 | 384 |  		for (j = 0; j < i; j++) | 
|---|
| 356 | 385 |  			if (crcu_array[j] == crcu_array[i]) | 
|---|
| 357 | 386 |  				break; | 
|---|
| 358 |  | -		if (j == i)  | 
|---|
 | 387 | +		if (j == i) {  | 
|---|
 | 388 | +			init_rcu_head_on_stack(&rs_array[i].head);  | 
|---|
 | 389 | +			init_completion(&rs_array[i].completion);  | 
|---|
| 359 | 390 |  			(crcu_array[i])(&rs_array[i].head, wakeme_after_rcu); | 
|---|
 | 391 | +		}  | 
|---|
| 360 | 392 |  	} | 
|---|
| 361 | 393 |   | 
|---|
| 362 | 394 |  	/* Wait for all callbacks to be invoked. */ | 
|---|
| 363 | 395 |  	for (i = 0; i < n; i++) { | 
|---|
| 364 | 396 |  		if (checktiny && | 
|---|
| 365 |  | -		    (crcu_array[i] == call_rcu ||  | 
|---|
| 366 |  | -		     crcu_array[i] == call_rcu_bh))  | 
|---|
 | 397 | +		    (crcu_array[i] == call_rcu))  | 
|---|
| 367 | 398 |  			continue; | 
|---|
| 368 | 399 |  		for (j = 0; j < i; j++) | 
|---|
| 369 | 400 |  			if (crcu_array[j] == crcu_array[i]) | 
|---|
| 370 | 401 |  				break; | 
|---|
| 371 |  | -		if (j == i)  | 
|---|
 | 402 | +		if (j == i) {  | 
|---|
| 372 | 403 |  			wait_for_completion(&rs_array[i].completion); | 
|---|
| 373 |  | -		destroy_rcu_head_on_stack(&rs_array[i].head);  | 
|---|
 | 404 | +			destroy_rcu_head_on_stack(&rs_array[i].head);  | 
|---|
 | 405 | +		}  | 
|---|
| 374 | 406 |  	} | 
|---|
| 375 | 407 |  } | 
|---|
| 376 | 408 |  EXPORT_SYMBOL_GPL(__wait_rcu_gp); | 
|---|
| .. | .. | 
|---|
| 426 | 458 |  } | 
|---|
| 427 | 459 |  EXPORT_SYMBOL_GPL(destroy_rcu_head_on_stack); | 
|---|
| 428 | 460 |   | 
|---|
| 429 |  | -struct debug_obj_descr rcuhead_debug_descr = {  | 
|---|
 | 461 | +const struct debug_obj_descr rcuhead_debug_descr = {  | 
|---|
| 430 | 462 |  	.name = "rcu_head", | 
|---|
| 431 | 463 |  	.is_static_object = rcuhead_is_static_object, | 
|---|
| 432 | 464 |  }; | 
|---|
| 433 | 465 |  EXPORT_SYMBOL_GPL(rcuhead_debug_descr); | 
|---|
| 434 | 466 |  #endif /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */ | 
|---|
| 435 | 467 |   | 
|---|
| 436 |  | -#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU) || defined(CONFIG_RCU_TRACE)  | 
|---|
 | 468 | +#if defined(CONFIG_TREE_RCU) || defined(CONFIG_RCU_TRACE)  | 
|---|
| 437 | 469 |  void do_trace_rcu_torture_read(const char *rcutorturename, struct rcu_head *rhp, | 
|---|
| 438 | 470 |  			       unsigned long secs, | 
|---|
| 439 | 471 |  			       unsigned long c_old, unsigned long c) | 
|---|
| .. | .. | 
|---|
| 446 | 478 |  	do { } while (0) | 
|---|
| 447 | 479 |  #endif | 
|---|
| 448 | 480 |   | 
|---|
| 449 |  | -#ifdef CONFIG_RCU_STALL_COMMON  | 
|---|
 | 481 | +#if IS_ENABLED(CONFIG_RCU_TORTURE_TEST) || IS_MODULE(CONFIG_RCU_TORTURE_TEST)  | 
|---|
 | 482 | +/* Get rcutorture access to sched_setaffinity(). */  | 
|---|
 | 483 | +long rcutorture_sched_setaffinity(pid_t pid, const struct cpumask *in_mask)  | 
|---|
 | 484 | +{  | 
|---|
 | 485 | +	int ret;  | 
|---|
| 450 | 486 |   | 
|---|
| 451 |  | -#ifdef CONFIG_PROVE_RCU  | 
|---|
| 452 |  | -#define RCU_STALL_DELAY_DELTA	       (5 * HZ)  | 
|---|
| 453 |  | -#else  | 
|---|
| 454 |  | -#define RCU_STALL_DELAY_DELTA	       0  | 
|---|
 | 487 | +	ret = sched_setaffinity(pid, in_mask);  | 
|---|
 | 488 | +	WARN_ONCE(ret, "%s: sched_setaffinity() returned %d\n", __func__, ret);  | 
|---|
 | 489 | +	return ret;  | 
|---|
 | 490 | +}  | 
|---|
 | 491 | +EXPORT_SYMBOL_GPL(rcutorture_sched_setaffinity);  | 
|---|
| 455 | 492 |  #endif | 
|---|
| 456 | 493 |   | 
|---|
| 457 |  | -int rcu_cpu_stall_suppress __read_mostly; /* 1 = suppress stall warnings. */  | 
|---|
 | 494 | +#ifdef CONFIG_RCU_STALL_COMMON  | 
|---|
 | 495 | +int rcu_cpu_stall_ftrace_dump __read_mostly;  | 
|---|
 | 496 | +module_param(rcu_cpu_stall_ftrace_dump, int, 0644);  | 
|---|
 | 497 | +int rcu_cpu_stall_suppress __read_mostly; // !0 = suppress stall warnings.  | 
|---|
| 458 | 498 |  EXPORT_SYMBOL_GPL(rcu_cpu_stall_suppress); | 
|---|
| 459 |  | -static int rcu_cpu_stall_timeout __read_mostly = CONFIG_RCU_CPU_STALL_TIMEOUT;  | 
|---|
| 460 |  | -  | 
|---|
| 461 | 499 |  module_param(rcu_cpu_stall_suppress, int, 0644); | 
|---|
 | 500 | +int rcu_cpu_stall_timeout __read_mostly = CONFIG_RCU_CPU_STALL_TIMEOUT;  | 
|---|
| 462 | 501 |  module_param(rcu_cpu_stall_timeout, int, 0644); | 
|---|
| 463 |  | -  | 
|---|
| 464 |  | -int rcu_jiffies_till_stall_check(void)  | 
|---|
| 465 |  | -{  | 
|---|
| 466 |  | -	int till_stall_check = READ_ONCE(rcu_cpu_stall_timeout);  | 
|---|
| 467 |  | -  | 
|---|
| 468 |  | -	/*  | 
|---|
| 469 |  | -	 * Limit check must be consistent with the Kconfig limits  | 
|---|
| 470 |  | -	 * for CONFIG_RCU_CPU_STALL_TIMEOUT.  | 
|---|
| 471 |  | -	 */  | 
|---|
| 472 |  | -	if (till_stall_check < 3) {  | 
|---|
| 473 |  | -		WRITE_ONCE(rcu_cpu_stall_timeout, 3);  | 
|---|
| 474 |  | -		till_stall_check = 3;  | 
|---|
| 475 |  | -	} else if (till_stall_check > 300) {  | 
|---|
| 476 |  | -		WRITE_ONCE(rcu_cpu_stall_timeout, 300);  | 
|---|
| 477 |  | -		till_stall_check = 300;  | 
|---|
| 478 |  | -	}  | 
|---|
| 479 |  | -	return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;  | 
|---|
| 480 |  | -}  | 
|---|
| 481 |  | -  | 
|---|
| 482 |  | -void rcu_sysrq_start(void)  | 
|---|
| 483 |  | -{  | 
|---|
| 484 |  | -	if (!rcu_cpu_stall_suppress)  | 
|---|
| 485 |  | -		rcu_cpu_stall_suppress = 2;  | 
|---|
| 486 |  | -}  | 
|---|
| 487 |  | -  | 
|---|
| 488 |  | -void rcu_sysrq_end(void)  | 
|---|
| 489 |  | -{  | 
|---|
| 490 |  | -	if (rcu_cpu_stall_suppress == 2)  | 
|---|
| 491 |  | -		rcu_cpu_stall_suppress = 0;  | 
|---|
| 492 |  | -}  | 
|---|
| 493 |  | -  | 
|---|
| 494 |  | -static int rcu_panic(struct notifier_block *this, unsigned long ev, void *ptr)  | 
|---|
| 495 |  | -{  | 
|---|
| 496 |  | -	rcu_cpu_stall_suppress = 1;  | 
|---|
| 497 |  | -	return NOTIFY_DONE;  | 
|---|
| 498 |  | -}  | 
|---|
| 499 |  | -  | 
|---|
| 500 |  | -static struct notifier_block rcu_panic_block = {  | 
|---|
| 501 |  | -	.notifier_call = rcu_panic,  | 
|---|
| 502 |  | -};  | 
|---|
| 503 |  | -  | 
|---|
| 504 |  | -static int __init check_cpu_stall_init(void)  | 
|---|
| 505 |  | -{  | 
|---|
| 506 |  | -	atomic_notifier_chain_register(&panic_notifier_list, &rcu_panic_block);  | 
|---|
| 507 |  | -	return 0;  | 
|---|
| 508 |  | -}  | 
|---|
| 509 |  | -early_initcall(check_cpu_stall_init);  | 
|---|
| 510 |  | -  | 
|---|
| 511 | 502 |  #endif /* #ifdef CONFIG_RCU_STALL_COMMON */ | 
|---|
| 512 | 503 |   | 
|---|
| 513 |  | -#ifdef CONFIG_TASKS_RCU  | 
|---|
| 514 |  | -  | 
|---|
| 515 |  | -/*  | 
|---|
| 516 |  | - * Simple variant of RCU whose quiescent states are voluntary context  | 
|---|
| 517 |  | - * switch, cond_resched_rcu_qs(), user-space execution, and idle.  | 
|---|
| 518 |  | - * As such, grace periods can take one good long time.  There are no  | 
|---|
| 519 |  | - * read-side primitives similar to rcu_read_lock() and rcu_read_unlock()  | 
|---|
| 520 |  | - * because this implementation is intended to get the system into a safe  | 
|---|
| 521 |  | - * state for some of the manipulations involved in tracing and the like.  | 
|---|
| 522 |  | - * Finally, this implementation does not support high call_rcu_tasks()  | 
|---|
| 523 |  | - * rates from multiple CPUs.  If this is required, per-CPU callback lists  | 
|---|
| 524 |  | - * will be needed.  | 
|---|
| 525 |  | - */  | 
|---|
| 526 |  | -  | 
|---|
| 527 |  | -/* Global list of callbacks and associated lock. */  | 
|---|
| 528 |  | -static struct rcu_head *rcu_tasks_cbs_head;  | 
|---|
| 529 |  | -static struct rcu_head **rcu_tasks_cbs_tail = &rcu_tasks_cbs_head;  | 
|---|
| 530 |  | -static DECLARE_WAIT_QUEUE_HEAD(rcu_tasks_cbs_wq);  | 
|---|
| 531 |  | -static DEFINE_RAW_SPINLOCK(rcu_tasks_cbs_lock);  | 
|---|
| 532 |  | -  | 
|---|
| 533 |  | -/* Track exiting tasks in order to allow them to be waited for. */  | 
|---|
| 534 |  | -DEFINE_STATIC_SRCU(tasks_rcu_exit_srcu);  | 
|---|
| 535 |  | -  | 
|---|
| 536 |  | -/* Control stall timeouts.  Disable with <= 0, otherwise jiffies till stall. */  | 
|---|
| 537 |  | -#define RCU_TASK_STALL_TIMEOUT (HZ * 60 * 10)  | 
|---|
| 538 |  | -static int rcu_task_stall_timeout __read_mostly = RCU_TASK_STALL_TIMEOUT;  | 
|---|
| 539 |  | -module_param(rcu_task_stall_timeout, int, 0644);  | 
|---|
| 540 |  | -  | 
|---|
| 541 |  | -static struct task_struct *rcu_tasks_kthread_ptr;  | 
|---|
| 542 |  | -  | 
|---|
| 543 |  | -/**  | 
|---|
| 544 |  | - * call_rcu_tasks() - Queue an RCU for invocation task-based grace period  | 
|---|
| 545 |  | - * @rhp: structure to be used for queueing the RCU updates.  | 
|---|
| 546 |  | - * @func: actual callback function to be invoked after the grace period  | 
|---|
| 547 |  | - *  | 
|---|
| 548 |  | - * The callback function will be invoked some time after a full grace  | 
|---|
| 549 |  | - * period elapses, in other words after all currently executing RCU  | 
|---|
| 550 |  | - * read-side critical sections have completed. call_rcu_tasks() assumes  | 
|---|
| 551 |  | - * that the read-side critical sections end at a voluntary context  | 
|---|
| 552 |  | - * switch (not a preemption!), cond_resched_rcu_qs(), entry into idle,  | 
|---|
| 553 |  | - * or transition to usermode execution.  As such, there are no read-side  | 
|---|
| 554 |  | - * primitives analogous to rcu_read_lock() and rcu_read_unlock() because  | 
|---|
| 555 |  | - * this primitive is intended to determine that all tasks have passed  | 
|---|
| 556 |  | - * through a safe state, not so much for data-strcuture synchronization.  | 
|---|
| 557 |  | - *  | 
|---|
| 558 |  | - * See the description of call_rcu() for more detailed information on  | 
|---|
| 559 |  | - * memory ordering guarantees.  | 
|---|
| 560 |  | - */  | 
|---|
| 561 |  | -void call_rcu_tasks(struct rcu_head *rhp, rcu_callback_t func)  | 
|---|
| 562 |  | -{  | 
|---|
| 563 |  | -	unsigned long flags;  | 
|---|
| 564 |  | -	bool needwake;  | 
|---|
| 565 |  | -  | 
|---|
| 566 |  | -	rhp->next = NULL;  | 
|---|
| 567 |  | -	rhp->func = func;  | 
|---|
| 568 |  | -	raw_spin_lock_irqsave(&rcu_tasks_cbs_lock, flags);  | 
|---|
| 569 |  | -	needwake = !rcu_tasks_cbs_head;  | 
|---|
| 570 |  | -	*rcu_tasks_cbs_tail = rhp;  | 
|---|
| 571 |  | -	rcu_tasks_cbs_tail = &rhp->next;  | 
|---|
| 572 |  | -	raw_spin_unlock_irqrestore(&rcu_tasks_cbs_lock, flags);  | 
|---|
| 573 |  | -	/* We can't create the thread unless interrupts are enabled. */  | 
|---|
| 574 |  | -	if (needwake && READ_ONCE(rcu_tasks_kthread_ptr))  | 
|---|
| 575 |  | -		wake_up(&rcu_tasks_cbs_wq);  | 
|---|
| 576 |  | -}  | 
|---|
| 577 |  | -EXPORT_SYMBOL_GPL(call_rcu_tasks);  | 
|---|
| 578 |  | -  | 
|---|
| 579 |  | -/**  | 
|---|
| 580 |  | - * synchronize_rcu_tasks - wait until an rcu-tasks grace period has elapsed.  | 
|---|
| 581 |  | - *  | 
|---|
| 582 |  | - * Control will return to the caller some time after a full rcu-tasks  | 
|---|
| 583 |  | - * grace period has elapsed, in other words after all currently  | 
|---|
| 584 |  | - * executing rcu-tasks read-side critical sections have elapsed.  These  | 
|---|
| 585 |  | - * read-side critical sections are delimited by calls to schedule(),  | 
|---|
| 586 |  | - * cond_resched_tasks_rcu_qs(), idle execution, userspace execution, calls  | 
|---|
| 587 |  | - * to synchronize_rcu_tasks(), and (in theory, anyway) cond_resched().  | 
|---|
| 588 |  | - *  | 
|---|
| 589 |  | - * This is a very specialized primitive, intended only for a few uses in  | 
|---|
| 590 |  | - * tracing and other situations requiring manipulation of function  | 
|---|
| 591 |  | - * preambles and profiling hooks.  The synchronize_rcu_tasks() function  | 
|---|
| 592 |  | - * is not (yet) intended for heavy use from multiple CPUs.  | 
|---|
| 593 |  | - *  | 
|---|
| 594 |  | - * Note that this guarantee implies further memory-ordering guarantees.  | 
|---|
| 595 |  | - * On systems with more than one CPU, when synchronize_rcu_tasks() returns,  | 
|---|
| 596 |  | - * each CPU is guaranteed to have executed a full memory barrier since the  | 
|---|
| 597 |  | - * end of its last RCU-tasks read-side critical section whose beginning  | 
|---|
| 598 |  | - * preceded the call to synchronize_rcu_tasks().  In addition, each CPU  | 
|---|
| 599 |  | - * having an RCU-tasks read-side critical section that extends beyond  | 
|---|
| 600 |  | - * the return from synchronize_rcu_tasks() is guaranteed to have executed  | 
|---|
| 601 |  | - * a full memory barrier after the beginning of synchronize_rcu_tasks()  | 
|---|
| 602 |  | - * and before the beginning of that RCU-tasks read-side critical section.  | 
|---|
| 603 |  | - * Note that these guarantees include CPUs that are offline, idle, or  | 
|---|
| 604 |  | - * executing in user mode, as well as CPUs that are executing in the kernel.  | 
|---|
| 605 |  | - *  | 
|---|
| 606 |  | - * Furthermore, if CPU A invoked synchronize_rcu_tasks(), which returned  | 
|---|
| 607 |  | - * to its caller on CPU B, then both CPU A and CPU B are guaranteed  | 
|---|
| 608 |  | - * to have executed a full memory barrier during the execution of  | 
|---|
| 609 |  | - * synchronize_rcu_tasks() -- even if CPU A and CPU B are the same CPU  | 
|---|
| 610 |  | - * (but again only if the system has more than one CPU).  | 
|---|
| 611 |  | - */  | 
|---|
| 612 |  | -void synchronize_rcu_tasks(void)  | 
|---|
| 613 |  | -{  | 
|---|
| 614 |  | -	/* Complain if the scheduler has not started.  */  | 
|---|
| 615 |  | -	RCU_LOCKDEP_WARN(rcu_scheduler_active == RCU_SCHEDULER_INACTIVE,  | 
|---|
| 616 |  | -			 "synchronize_rcu_tasks called too soon");  | 
|---|
| 617 |  | -  | 
|---|
| 618 |  | -	/* Wait for the grace period. */  | 
|---|
| 619 |  | -	wait_rcu_gp(call_rcu_tasks);  | 
|---|
| 620 |  | -}  | 
|---|
| 621 |  | -EXPORT_SYMBOL_GPL(synchronize_rcu_tasks);  | 
|---|
| 622 |  | -  | 
|---|
| 623 |  | -/**  | 
|---|
| 624 |  | - * rcu_barrier_tasks - Wait for in-flight call_rcu_tasks() callbacks.  | 
|---|
| 625 |  | - *  | 
|---|
| 626 |  | - * Although the current implementation is guaranteed to wait, it is not  | 
|---|
| 627 |  | - * obligated to, for example, if there are no pending callbacks.  | 
|---|
| 628 |  | - */  | 
|---|
| 629 |  | -void rcu_barrier_tasks(void)  | 
|---|
| 630 |  | -{  | 
|---|
| 631 |  | -	/* There is only one callback queue, so this is easy.  ;-) */  | 
|---|
| 632 |  | -	synchronize_rcu_tasks();  | 
|---|
| 633 |  | -}  | 
|---|
| 634 |  | -EXPORT_SYMBOL_GPL(rcu_barrier_tasks);  | 
|---|
| 635 |  | -  | 
|---|
| 636 |  | -/* See if tasks are still holding out, complain if so. */  | 
|---|
| 637 |  | -static void check_holdout_task(struct task_struct *t,  | 
|---|
| 638 |  | -			       bool needreport, bool *firstreport)  | 
|---|
| 639 |  | -{  | 
|---|
| 640 |  | -	int cpu;  | 
|---|
| 641 |  | -  | 
|---|
| 642 |  | -	if (!READ_ONCE(t->rcu_tasks_holdout) ||  | 
|---|
| 643 |  | -	    t->rcu_tasks_nvcsw != READ_ONCE(t->nvcsw) ||  | 
|---|
| 644 |  | -	    !READ_ONCE(t->on_rq) ||  | 
|---|
| 645 |  | -	    (IS_ENABLED(CONFIG_NO_HZ_FULL) &&  | 
|---|
| 646 |  | -	     !is_idle_task(t) && t->rcu_tasks_idle_cpu >= 0)) {  | 
|---|
| 647 |  | -		WRITE_ONCE(t->rcu_tasks_holdout, false);  | 
|---|
| 648 |  | -		list_del_init(&t->rcu_tasks_holdout_list);  | 
|---|
| 649 |  | -		put_task_struct(t);  | 
|---|
| 650 |  | -		return;  | 
|---|
| 651 |  | -	}  | 
|---|
| 652 |  | -	rcu_request_urgent_qs_task(t);  | 
|---|
| 653 |  | -	if (!needreport)  | 
|---|
| 654 |  | -		return;  | 
|---|
| 655 |  | -	if (*firstreport) {  | 
|---|
| 656 |  | -		pr_err("INFO: rcu_tasks detected stalls on tasks:\n");  | 
|---|
| 657 |  | -		*firstreport = false;  | 
|---|
| 658 |  | -	}  | 
|---|
| 659 |  | -	cpu = task_cpu(t);  | 
|---|
| 660 |  | -	pr_alert("%p: %c%c nvcsw: %lu/%lu holdout: %d idle_cpu: %d/%d\n",  | 
|---|
| 661 |  | -		 t, ".I"[is_idle_task(t)],  | 
|---|
| 662 |  | -		 "N."[cpu < 0 || !tick_nohz_full_cpu(cpu)],  | 
|---|
| 663 |  | -		 t->rcu_tasks_nvcsw, t->nvcsw, t->rcu_tasks_holdout,  | 
|---|
| 664 |  | -		 t->rcu_tasks_idle_cpu, cpu);  | 
|---|
| 665 |  | -	sched_show_task(t);  | 
|---|
| 666 |  | -}  | 
|---|
| 667 |  | -  | 
|---|
| 668 |  | -/* RCU-tasks kthread that detects grace periods and invokes callbacks. */  | 
|---|
| 669 |  | -static int __noreturn rcu_tasks_kthread(void *arg)  | 
|---|
| 670 |  | -{  | 
|---|
| 671 |  | -	unsigned long flags;  | 
|---|
| 672 |  | -	struct task_struct *g, *t;  | 
|---|
| 673 |  | -	unsigned long lastreport;  | 
|---|
| 674 |  | -	struct rcu_head *list;  | 
|---|
| 675 |  | -	struct rcu_head *next;  | 
|---|
| 676 |  | -	LIST_HEAD(rcu_tasks_holdouts);  | 
|---|
| 677 |  | -	int fract;  | 
|---|
| 678 |  | -  | 
|---|
| 679 |  | -	/* Run on housekeeping CPUs by default.  Sysadm can move if desired. */  | 
|---|
| 680 |  | -	housekeeping_affine(current, HK_FLAG_RCU);  | 
|---|
| 681 |  | -  | 
|---|
| 682 |  | -	/*  | 
|---|
| 683 |  | -	 * Each pass through the following loop makes one check for  | 
|---|
| 684 |  | -	 * newly arrived callbacks, and, if there are some, waits for  | 
|---|
| 685 |  | -	 * one RCU-tasks grace period and then invokes the callbacks.  | 
|---|
| 686 |  | -	 * This loop is terminated by the system going down.  ;-)  | 
|---|
| 687 |  | -	 */  | 
|---|
| 688 |  | -	for (;;) {  | 
|---|
| 689 |  | -  | 
|---|
| 690 |  | -		/* Pick up any new callbacks. */  | 
|---|
| 691 |  | -		raw_spin_lock_irqsave(&rcu_tasks_cbs_lock, flags);  | 
|---|
| 692 |  | -		list = rcu_tasks_cbs_head;  | 
|---|
| 693 |  | -		rcu_tasks_cbs_head = NULL;  | 
|---|
| 694 |  | -		rcu_tasks_cbs_tail = &rcu_tasks_cbs_head;  | 
|---|
| 695 |  | -		raw_spin_unlock_irqrestore(&rcu_tasks_cbs_lock, flags);  | 
|---|
| 696 |  | -  | 
|---|
| 697 |  | -		/* If there were none, wait a bit and start over. */  | 
|---|
| 698 |  | -		if (!list) {  | 
|---|
| 699 |  | -			wait_event_interruptible(rcu_tasks_cbs_wq,  | 
|---|
| 700 |  | -						 rcu_tasks_cbs_head);  | 
|---|
| 701 |  | -			if (!rcu_tasks_cbs_head) {  | 
|---|
| 702 |  | -				WARN_ON(signal_pending(current));  | 
|---|
| 703 |  | -				schedule_timeout_interruptible(HZ/10);  | 
|---|
| 704 |  | -			}  | 
|---|
| 705 |  | -			continue;  | 
|---|
| 706 |  | -		}  | 
|---|
| 707 |  | -  | 
|---|
| 708 |  | -		/*  | 
|---|
| 709 |  | -		 * Wait for all pre-existing t->on_rq and t->nvcsw  | 
|---|
| 710 |  | -		 * transitions to complete.  Invoking synchronize_sched()  | 
|---|
| 711 |  | -		 * suffices because all these transitions occur with  | 
|---|
| 712 |  | -		 * interrupts disabled.  Without this synchronize_sched(),  | 
|---|
| 713 |  | -		 * a read-side critical section that started before the  | 
|---|
| 714 |  | -		 * grace period might be incorrectly seen as having started  | 
|---|
| 715 |  | -		 * after the grace period.  | 
|---|
| 716 |  | -		 *  | 
|---|
| 717 |  | -		 * This synchronize_sched() also dispenses with the  | 
|---|
| 718 |  | -		 * need for a memory barrier on the first store to  | 
|---|
| 719 |  | -		 * ->rcu_tasks_holdout, as it forces the store to happen  | 
|---|
| 720 |  | -		 * after the beginning of the grace period.  | 
|---|
| 721 |  | -		 */  | 
|---|
| 722 |  | -		synchronize_sched();  | 
|---|
| 723 |  | -  | 
|---|
| 724 |  | -		/*  | 
|---|
| 725 |  | -		 * There were callbacks, so we need to wait for an  | 
|---|
| 726 |  | -		 * RCU-tasks grace period.  Start off by scanning  | 
|---|
| 727 |  | -		 * the task list for tasks that are not already  | 
|---|
| 728 |  | -		 * voluntarily blocked.  Mark these tasks and make  | 
|---|
| 729 |  | -		 * a list of them in rcu_tasks_holdouts.  | 
|---|
| 730 |  | -		 */  | 
|---|
| 731 |  | -		rcu_read_lock();  | 
|---|
| 732 |  | -		for_each_process_thread(g, t) {  | 
|---|
| 733 |  | -			if (t != current && READ_ONCE(t->on_rq) &&  | 
|---|
| 734 |  | -			    !is_idle_task(t)) {  | 
|---|
| 735 |  | -				get_task_struct(t);  | 
|---|
| 736 |  | -				t->rcu_tasks_nvcsw = READ_ONCE(t->nvcsw);  | 
|---|
| 737 |  | -				WRITE_ONCE(t->rcu_tasks_holdout, true);  | 
|---|
| 738 |  | -				list_add(&t->rcu_tasks_holdout_list,  | 
|---|
| 739 |  | -					 &rcu_tasks_holdouts);  | 
|---|
| 740 |  | -			}  | 
|---|
| 741 |  | -		}  | 
|---|
| 742 |  | -		rcu_read_unlock();  | 
|---|
| 743 |  | -  | 
|---|
| 744 |  | -		/*  | 
|---|
| 745 |  | -		 * Wait for tasks that are in the process of exiting.  | 
|---|
| 746 |  | -		 * This does only part of the job, ensuring that all  | 
|---|
| 747 |  | -		 * tasks that were previously exiting reach the point  | 
|---|
| 748 |  | -		 * where they have disabled preemption, allowing the  | 
|---|
| 749 |  | -		 * later synchronize_sched() to finish the job.  | 
|---|
| 750 |  | -		 */  | 
|---|
| 751 |  | -		synchronize_srcu(&tasks_rcu_exit_srcu);  | 
|---|
| 752 |  | -  | 
|---|
| 753 |  | -		/*  | 
|---|
| 754 |  | -		 * Each pass through the following loop scans the list  | 
|---|
| 755 |  | -		 * of holdout tasks, removing any that are no longer  | 
|---|
| 756 |  | -		 * holdouts.  When the list is empty, we are done.  | 
|---|
| 757 |  | -		 */  | 
|---|
| 758 |  | -		lastreport = jiffies;  | 
|---|
| 759 |  | -  | 
|---|
| 760 |  | -		/* Start off with HZ/10 wait and slowly back off to 1 HZ wait*/  | 
|---|
| 761 |  | -		fract = 10;  | 
|---|
| 762 |  | -  | 
|---|
| 763 |  | -		for (;;) {  | 
|---|
| 764 |  | -			bool firstreport;  | 
|---|
| 765 |  | -			bool needreport;  | 
|---|
| 766 |  | -			int rtst;  | 
|---|
| 767 |  | -			struct task_struct *t1;  | 
|---|
| 768 |  | -  | 
|---|
| 769 |  | -			if (list_empty(&rcu_tasks_holdouts))  | 
|---|
| 770 |  | -				break;  | 
|---|
| 771 |  | -  | 
|---|
| 772 |  | -			/* Slowly back off waiting for holdouts */  | 
|---|
| 773 |  | -			schedule_timeout_interruptible(HZ/fract);  | 
|---|
| 774 |  | -  | 
|---|
| 775 |  | -			if (fract > 1)  | 
|---|
| 776 |  | -				fract--;  | 
|---|
| 777 |  | -  | 
|---|
| 778 |  | -			rtst = READ_ONCE(rcu_task_stall_timeout);  | 
|---|
| 779 |  | -			needreport = rtst > 0 &&  | 
|---|
| 780 |  | -				     time_after(jiffies, lastreport + rtst);  | 
|---|
| 781 |  | -			if (needreport)  | 
|---|
| 782 |  | -				lastreport = jiffies;  | 
|---|
| 783 |  | -			firstreport = true;  | 
|---|
| 784 |  | -			WARN_ON(signal_pending(current));  | 
|---|
| 785 |  | -			list_for_each_entry_safe(t, t1, &rcu_tasks_holdouts,  | 
|---|
| 786 |  | -						rcu_tasks_holdout_list) {  | 
|---|
| 787 |  | -				check_holdout_task(t, needreport, &firstreport);  | 
|---|
| 788 |  | -				cond_resched();  | 
|---|
| 789 |  | -			}  | 
|---|
| 790 |  | -		}  | 
|---|
| 791 |  | -  | 
|---|
| 792 |  | -		/*  | 
|---|
| 793 |  | -		 * Because ->on_rq and ->nvcsw are not guaranteed  | 
|---|
| 794 |  | -		 * to have a full memory barriers prior to them in the  | 
|---|
| 795 |  | -		 * schedule() path, memory reordering on other CPUs could  | 
|---|
| 796 |  | -		 * cause their RCU-tasks read-side critical sections to  | 
|---|
| 797 |  | -		 * extend past the end of the grace period.  However,  | 
|---|
| 798 |  | -		 * because these ->nvcsw updates are carried out with  | 
|---|
| 799 |  | -		 * interrupts disabled, we can use synchronize_sched()  | 
|---|
| 800 |  | -		 * to force the needed ordering on all such CPUs.  | 
|---|
| 801 |  | -		 *  | 
|---|
| 802 |  | -		 * This synchronize_sched() also confines all  | 
|---|
| 803 |  | -		 * ->rcu_tasks_holdout accesses to be within the grace  | 
|---|
| 804 |  | -		 * period, avoiding the need for memory barriers for  | 
|---|
| 805 |  | -		 * ->rcu_tasks_holdout accesses.  | 
|---|
| 806 |  | -		 *  | 
|---|
| 807 |  | -		 * In addition, this synchronize_sched() waits for exiting  | 
|---|
| 808 |  | -		 * tasks to complete their final preempt_disable() region  | 
|---|
| 809 |  | -		 * of execution, cleaning up after the synchronize_srcu()  | 
|---|
| 810 |  | -		 * above.  | 
|---|
| 811 |  | -		 */  | 
|---|
| 812 |  | -		synchronize_sched();  | 
|---|
| 813 |  | -  | 
|---|
| 814 |  | -		/* Invoke the callbacks. */  | 
|---|
| 815 |  | -		while (list) {  | 
|---|
| 816 |  | -			next = list->next;  | 
|---|
| 817 |  | -			local_bh_disable();  | 
|---|
| 818 |  | -			list->func(list);  | 
|---|
| 819 |  | -			local_bh_enable();  | 
|---|
| 820 |  | -			list = next;  | 
|---|
| 821 |  | -			cond_resched();  | 
|---|
| 822 |  | -		}  | 
|---|
| 823 |  | -		/* Paranoid sleep to keep this from entering a tight loop */  | 
|---|
| 824 |  | -		schedule_timeout_uninterruptible(HZ/10);  | 
|---|
| 825 |  | -	}  | 
|---|
| 826 |  | -}  | 
|---|
| 827 |  | -  | 
|---|
| 828 |  | -/* Spawn rcu_tasks_kthread() at core_initcall() time. */  | 
|---|
| 829 |  | -static int __init rcu_spawn_tasks_kthread(void)  | 
|---|
| 830 |  | -{  | 
|---|
| 831 |  | -	struct task_struct *t;  | 
|---|
| 832 |  | -  | 
|---|
| 833 |  | -	t = kthread_run(rcu_tasks_kthread, NULL, "rcu_tasks_kthread");  | 
|---|
| 834 |  | -	BUG_ON(IS_ERR(t));  | 
|---|
| 835 |  | -	smp_mb(); /* Ensure others see full kthread. */  | 
|---|
| 836 |  | -	WRITE_ONCE(rcu_tasks_kthread_ptr, t);  | 
|---|
| 837 |  | -	return 0;  | 
|---|
| 838 |  | -}  | 
|---|
| 839 |  | -core_initcall(rcu_spawn_tasks_kthread);  | 
|---|
| 840 |  | -  | 
|---|
| 841 |  | -/* Do the srcu_read_lock() for the above synchronize_srcu().  */  | 
|---|
| 842 |  | -void exit_tasks_rcu_start(void)  | 
|---|
| 843 |  | -{  | 
|---|
| 844 |  | -	preempt_disable();  | 
|---|
| 845 |  | -	current->rcu_tasks_idx = __srcu_read_lock(&tasks_rcu_exit_srcu);  | 
|---|
| 846 |  | -	preempt_enable();  | 
|---|
| 847 |  | -}  | 
|---|
| 848 |  | -  | 
|---|
| 849 |  | -/* Do the srcu_read_unlock() for the above synchronize_srcu().  */  | 
|---|
| 850 |  | -void exit_tasks_rcu_finish(void)  | 
|---|
| 851 |  | -{  | 
|---|
| 852 |  | -	preempt_disable();  | 
|---|
| 853 |  | -	__srcu_read_unlock(&tasks_rcu_exit_srcu, current->rcu_tasks_idx);  | 
|---|
| 854 |  | -	preempt_enable();  | 
|---|
| 855 |  | -}  | 
|---|
| 856 |  | -  | 
|---|
| 857 |  | -#endif /* #ifdef CONFIG_TASKS_RCU */  | 
|---|
| 858 |  | -  | 
|---|
| 859 |  | -#ifndef CONFIG_TINY_RCU  | 
|---|
| 860 |  | -  | 
|---|
| 861 |  | -/*  | 
|---|
| 862 |  | - * Print any non-default Tasks RCU settings.  | 
|---|
| 863 |  | - */  | 
|---|
| 864 |  | -static void __init rcu_tasks_bootup_oddness(void)  | 
|---|
| 865 |  | -{  | 
|---|
| 866 |  | -#ifdef CONFIG_TASKS_RCU  | 
|---|
| 867 |  | -	if (rcu_task_stall_timeout != RCU_TASK_STALL_TIMEOUT)  | 
|---|
| 868 |  | -		pr_info("\tTasks-RCU CPU stall warnings timeout set to %d (rcu_task_stall_timeout).\n", rcu_task_stall_timeout);  | 
|---|
| 869 |  | -	else  | 
|---|
| 870 |  | -		pr_info("\tTasks RCU enabled.\n");  | 
|---|
| 871 |  | -#endif /* #ifdef CONFIG_TASKS_RCU */  | 
|---|
| 872 |  | -}  | 
|---|
| 873 |  | -  | 
|---|
| 874 |  | -#endif /* #ifndef CONFIG_TINY_RCU */  | 
|---|
 | 504 | +// Suppress boot-time RCU CPU stall warnings and rcutorture writer stall  | 
|---|
 | 505 | +// warnings.  Also used by rcutorture even if stall warnings are excluded.  | 
|---|
 | 506 | +int rcu_cpu_stall_suppress_at_boot __read_mostly; // !0 = suppress boot stalls.  | 
|---|
 | 507 | +EXPORT_SYMBOL_GPL(rcu_cpu_stall_suppress_at_boot);  | 
|---|
 | 508 | +module_param(rcu_cpu_stall_suppress_at_boot, int, 0444);  | 
|---|
| 875 | 509 |   | 
|---|
| 876 | 510 |  #ifdef CONFIG_PROVE_RCU | 
|---|
| 877 | 511 |   | 
|---|
| 878 | 512 |  /* | 
|---|
| 879 |  | - * Early boot self test parameters, one for each flavor  | 
|---|
 | 513 | + * Early boot self test parameters.  | 
|---|
| 880 | 514 |   */ | 
|---|
| 881 | 515 |  static bool rcu_self_test; | 
|---|
| 882 |  | -static bool rcu_self_test_bh;  | 
|---|
| 883 |  | -static bool rcu_self_test_sched;  | 
|---|
| 884 |  | -  | 
|---|
| 885 | 516 |  module_param(rcu_self_test, bool, 0444); | 
|---|
| 886 |  | -module_param(rcu_self_test_bh, bool, 0444);  | 
|---|
| 887 |  | -module_param(rcu_self_test_sched, bool, 0444);  | 
|---|
| 888 | 517 |   | 
|---|
| 889 | 518 |  static int rcu_self_test_counter; | 
|---|
| 890 | 519 |   | 
|---|
| .. | .. | 
|---|
| 894 | 523 |  	pr_info("RCU test callback executed %d\n", rcu_self_test_counter); | 
|---|
| 895 | 524 |  } | 
|---|
| 896 | 525 |   | 
|---|
 | 526 | +DEFINE_STATIC_SRCU(early_srcu);  | 
|---|
 | 527 | +  | 
|---|
 | 528 | +struct early_boot_kfree_rcu {  | 
|---|
 | 529 | +	struct rcu_head rh;  | 
|---|
 | 530 | +};  | 
|---|
 | 531 | +  | 
|---|
| 897 | 532 |  static void early_boot_test_call_rcu(void) | 
|---|
| 898 | 533 |  { | 
|---|
| 899 | 534 |  	static struct rcu_head head; | 
|---|
 | 535 | +	static struct rcu_head shead;  | 
|---|
 | 536 | +	struct early_boot_kfree_rcu *rhp;  | 
|---|
| 900 | 537 |   | 
|---|
| 901 | 538 |  	call_rcu(&head, test_callback); | 
|---|
| 902 |  | -}  | 
|---|
| 903 |  | -  | 
|---|
| 904 |  | -static void early_boot_test_call_rcu_bh(void)  | 
|---|
| 905 |  | -{  | 
|---|
| 906 |  | -	static struct rcu_head head;  | 
|---|
| 907 |  | -  | 
|---|
| 908 |  | -	call_rcu_bh(&head, test_callback);  | 
|---|
| 909 |  | -}  | 
|---|
| 910 |  | -  | 
|---|
| 911 |  | -static void early_boot_test_call_rcu_sched(void)  | 
|---|
| 912 |  | -{  | 
|---|
| 913 |  | -	static struct rcu_head head;  | 
|---|
| 914 |  | -  | 
|---|
| 915 |  | -	call_rcu_sched(&head, test_callback);  | 
|---|
 | 539 | +	if (IS_ENABLED(CONFIG_SRCU))  | 
|---|
 | 540 | +		call_srcu(&early_srcu, &shead, test_callback);  | 
|---|
 | 541 | +	rhp = kmalloc(sizeof(*rhp), GFP_KERNEL);  | 
|---|
 | 542 | +	if (!WARN_ON_ONCE(!rhp))  | 
|---|
 | 543 | +		kfree_rcu(rhp, rh);  | 
|---|
| 916 | 544 |  } | 
|---|
| 917 | 545 |   | 
|---|
| 918 | 546 |  void rcu_early_boot_tests(void) | 
|---|
| .. | .. | 
|---|
| 921 | 549 |   | 
|---|
| 922 | 550 |  	if (rcu_self_test) | 
|---|
| 923 | 551 |  		early_boot_test_call_rcu(); | 
|---|
| 924 |  | -	if (rcu_self_test_bh)  | 
|---|
| 925 |  | -		early_boot_test_call_rcu_bh();  | 
|---|
| 926 |  | -	if (rcu_self_test_sched)  | 
|---|
| 927 |  | -		early_boot_test_call_rcu_sched();  | 
|---|
| 928 | 552 |  	rcu_test_sync_prims(); | 
|---|
| 929 | 553 |  } | 
|---|
| 930 | 554 |   | 
|---|
| .. | .. | 
|---|
| 936 | 560 |  	if (rcu_self_test) { | 
|---|
| 937 | 561 |  		early_boot_test_counter++; | 
|---|
| 938 | 562 |  		rcu_barrier(); | 
|---|
 | 563 | +		if (IS_ENABLED(CONFIG_SRCU)) {  | 
|---|
 | 564 | +			early_boot_test_counter++;  | 
|---|
 | 565 | +			srcu_barrier(&early_srcu);  | 
|---|
 | 566 | +		}  | 
|---|
| 939 | 567 |  	} | 
|---|
| 940 |  | -	if (rcu_self_test_bh) {  | 
|---|
| 941 |  | -		early_boot_test_counter++;  | 
|---|
| 942 |  | -		rcu_barrier_bh();  | 
|---|
| 943 |  | -	}  | 
|---|
| 944 |  | -	if (rcu_self_test_sched) {  | 
|---|
| 945 |  | -		early_boot_test_counter++;  | 
|---|
| 946 |  | -		rcu_barrier_sched();  | 
|---|
| 947 |  | -	}  | 
|---|
| 948 |  | -  | 
|---|
| 949 | 568 |  	if (rcu_self_test_counter != early_boot_test_counter) { | 
|---|
| 950 | 569 |  		WARN_ON(1); | 
|---|
| 951 | 570 |  		ret = -1; | 
|---|
| .. | .. | 
|---|
| 958 | 577 |  void rcu_early_boot_tests(void) {} | 
|---|
| 959 | 578 |  #endif /* CONFIG_PROVE_RCU */ | 
|---|
| 960 | 579 |   | 
|---|
 | 580 | +#include "tasks.h"  | 
|---|
 | 581 | +  | 
|---|
| 961 | 582 |  #ifndef CONFIG_TINY_RCU | 
|---|
| 962 | 583 |   | 
|---|
| 963 | 584 |  /* | 
|---|