| .. | .. |
|---|
| 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 | * Author: Dipankar Sarma <dipankar@in.ibm.com> |
|---|
| 21 | 8 | * |
|---|
| 22 | | - * Based on the original work by Paul McKenney <paulmck@us.ibm.com> |
|---|
| 9 | + * Based on the original work by Paul McKenney <paulmck@vnet.ibm.com> |
|---|
| 23 | 10 | * and inputs from Rusty Russell, Andrea Arcangeli and Andi Kleen. |
|---|
| 24 | 11 | * Papers: |
|---|
| 25 | 12 | * http://www.rdrop.com/users/paulmck/paper/rclockpdcsproof.pdf |
|---|
| .. | .. |
|---|
| 46 | 33 | #define ULONG_CMP_GE(a, b) (ULONG_MAX / 2 >= (a) - (b)) |
|---|
| 47 | 34 | #define ULONG_CMP_LT(a, b) (ULONG_MAX / 2 < (a) - (b)) |
|---|
| 48 | 35 | #define ulong2long(a) (*(long *)(&(a))) |
|---|
| 36 | +#define USHORT_CMP_GE(a, b) (USHRT_MAX / 2 >= (unsigned short)((a) - (b))) |
|---|
| 37 | +#define USHORT_CMP_LT(a, b) (USHRT_MAX / 2 < (unsigned short)((a) - (b))) |
|---|
| 49 | 38 | |
|---|
| 50 | 39 | /* Exported common interfaces */ |
|---|
| 51 | | - |
|---|
| 52 | | -#ifdef CONFIG_PREEMPT_RCU |
|---|
| 53 | 40 | void call_rcu(struct rcu_head *head, rcu_callback_t func); |
|---|
| 54 | | -#else /* #ifdef CONFIG_PREEMPT_RCU */ |
|---|
| 55 | | -#define call_rcu call_rcu_sched |
|---|
| 56 | | -#endif /* #else #ifdef CONFIG_PREEMPT_RCU */ |
|---|
| 57 | | - |
|---|
| 58 | | -void call_rcu_bh(struct rcu_head *head, rcu_callback_t func); |
|---|
| 59 | | -void call_rcu_sched(struct rcu_head *head, rcu_callback_t func); |
|---|
| 60 | | -void synchronize_sched(void); |
|---|
| 61 | 41 | void rcu_barrier_tasks(void); |
|---|
| 42 | +void rcu_barrier_tasks_rude(void); |
|---|
| 43 | +void synchronize_rcu(void); |
|---|
| 62 | 44 | |
|---|
| 63 | 45 | #ifdef CONFIG_PREEMPT_RCU |
|---|
| 64 | 46 | |
|---|
| 65 | 47 | void __rcu_read_lock(void); |
|---|
| 66 | 48 | void __rcu_read_unlock(void); |
|---|
| 67 | | -void synchronize_rcu(void); |
|---|
| 68 | 49 | |
|---|
| 69 | 50 | /* |
|---|
| 70 | 51 | * Defined as a macro as it is a very low level header included from |
|---|
| .. | .. |
|---|
| 76 | 57 | |
|---|
| 77 | 58 | #else /* #ifdef CONFIG_PREEMPT_RCU */ |
|---|
| 78 | 59 | |
|---|
| 60 | +#ifdef CONFIG_TINY_RCU |
|---|
| 61 | +#define rcu_read_unlock_strict() do { } while (0) |
|---|
| 62 | +#else |
|---|
| 63 | +void rcu_read_unlock_strict(void); |
|---|
| 64 | +#endif |
|---|
| 65 | + |
|---|
| 79 | 66 | static inline void __rcu_read_lock(void) |
|---|
| 80 | 67 | { |
|---|
| 81 | 68 | preempt_disable(); |
|---|
| .. | .. |
|---|
| 84 | 71 | static inline void __rcu_read_unlock(void) |
|---|
| 85 | 72 | { |
|---|
| 86 | 73 | preempt_enable(); |
|---|
| 87 | | -} |
|---|
| 88 | | - |
|---|
| 89 | | -static inline void synchronize_rcu(void) |
|---|
| 90 | | -{ |
|---|
| 91 | | - synchronize_sched(); |
|---|
| 74 | + rcu_read_unlock_strict(); |
|---|
| 92 | 75 | } |
|---|
| 93 | 76 | |
|---|
| 94 | 77 | static inline int rcu_preempt_depth(void) |
|---|
| .. | .. |
|---|
| 100 | 83 | |
|---|
| 101 | 84 | /* Internal to kernel */ |
|---|
| 102 | 85 | void rcu_init(void); |
|---|
| 103 | | -extern int rcu_scheduler_active __read_mostly; |
|---|
| 104 | | -void rcu_sched_qs(void); |
|---|
| 105 | | -void rcu_bh_qs(void); |
|---|
| 106 | | -void rcu_check_callbacks(int user); |
|---|
| 86 | +extern int rcu_scheduler_active; |
|---|
| 87 | +void rcu_sched_clock_irq(int user); |
|---|
| 107 | 88 | void rcu_report_dead(unsigned int cpu); |
|---|
| 108 | 89 | void rcutree_migrate_callbacks(int cpu); |
|---|
| 90 | + |
|---|
| 91 | +#ifdef CONFIG_TASKS_RCU_GENERIC |
|---|
| 92 | +void rcu_init_tasks_generic(void); |
|---|
| 93 | +#else |
|---|
| 94 | +static inline void rcu_init_tasks_generic(void) { } |
|---|
| 95 | +#endif |
|---|
| 109 | 96 | |
|---|
| 110 | 97 | #ifdef CONFIG_RCU_STALL_COMMON |
|---|
| 111 | 98 | void rcu_sysrq_start(void); |
|---|
| .. | .. |
|---|
| 125 | 112 | |
|---|
| 126 | 113 | #ifdef CONFIG_RCU_NOCB_CPU |
|---|
| 127 | 114 | void rcu_init_nohz(void); |
|---|
| 115 | +void rcu_nocb_flush_deferred_wakeup(void); |
|---|
| 128 | 116 | #else /* #ifdef CONFIG_RCU_NOCB_CPU */ |
|---|
| 129 | 117 | static inline void rcu_init_nohz(void) { } |
|---|
| 118 | +static inline void rcu_nocb_flush_deferred_wakeup(void) { } |
|---|
| 130 | 119 | #endif /* #else #ifdef CONFIG_RCU_NOCB_CPU */ |
|---|
| 131 | 120 | |
|---|
| 132 | 121 | /** |
|---|
| 133 | 122 | * RCU_NONIDLE - Indicate idle-loop code that needs RCU readers |
|---|
| 134 | 123 | * @a: Code that RCU needs to pay attention to. |
|---|
| 135 | 124 | * |
|---|
| 136 | | - * RCU, RCU-bh, and RCU-sched read-side critical sections are forbidden |
|---|
| 137 | | - * in the inner idle loop, that is, between the rcu_idle_enter() and |
|---|
| 138 | | - * the rcu_idle_exit() -- RCU will happily ignore any such read-side |
|---|
| 139 | | - * critical sections. However, things like powertop need tracepoints |
|---|
| 140 | | - * in the inner idle loop. |
|---|
| 125 | + * RCU read-side critical sections are forbidden in the inner idle loop, |
|---|
| 126 | + * that is, between the rcu_idle_enter() and the rcu_idle_exit() -- RCU |
|---|
| 127 | + * will happily ignore any such read-side critical sections. However, |
|---|
| 128 | + * things like powertop need tracepoints in the inner idle loop. |
|---|
| 141 | 129 | * |
|---|
| 142 | 130 | * This macro provides the way out: RCU_NONIDLE(do_something_with_RCU()) |
|---|
| 143 | 131 | * will tell RCU that it needs to pay attention, invoke its argument |
|---|
| .. | .. |
|---|
| 159 | 147 | * Note a quasi-voluntary context switch for RCU-tasks's benefit. |
|---|
| 160 | 148 | * This is a macro rather than an inline function to avoid #include hell. |
|---|
| 161 | 149 | */ |
|---|
| 162 | | -#ifdef CONFIG_TASKS_RCU |
|---|
| 163 | | -#define rcu_tasks_qs(t) \ |
|---|
| 164 | | - do { \ |
|---|
| 165 | | - if (READ_ONCE((t)->rcu_tasks_holdout)) \ |
|---|
| 166 | | - WRITE_ONCE((t)->rcu_tasks_holdout, false); \ |
|---|
| 167 | | - } while (0) |
|---|
| 168 | | -#define rcu_note_voluntary_context_switch(t) \ |
|---|
| 169 | | - do { \ |
|---|
| 170 | | - rcu_all_qs(); \ |
|---|
| 171 | | - rcu_tasks_qs(t); \ |
|---|
| 150 | +#ifdef CONFIG_TASKS_RCU_GENERIC |
|---|
| 151 | + |
|---|
| 152 | +# ifdef CONFIG_TASKS_RCU |
|---|
| 153 | +# define rcu_tasks_classic_qs(t, preempt) \ |
|---|
| 154 | + do { \ |
|---|
| 155 | + if (!(preempt) && READ_ONCE((t)->rcu_tasks_holdout)) \ |
|---|
| 156 | + WRITE_ONCE((t)->rcu_tasks_holdout, false); \ |
|---|
| 172 | 157 | } while (0) |
|---|
| 173 | 158 | void call_rcu_tasks(struct rcu_head *head, rcu_callback_t func); |
|---|
| 174 | 159 | void synchronize_rcu_tasks(void); |
|---|
| 160 | +# else |
|---|
| 161 | +# define rcu_tasks_classic_qs(t, preempt) do { } while (0) |
|---|
| 162 | +# define call_rcu_tasks call_rcu |
|---|
| 163 | +# define synchronize_rcu_tasks synchronize_rcu |
|---|
| 164 | +# endif |
|---|
| 165 | + |
|---|
| 166 | +# ifdef CONFIG_TASKS_TRACE_RCU |
|---|
| 167 | +# define rcu_tasks_trace_qs(t) \ |
|---|
| 168 | + do { \ |
|---|
| 169 | + if (!likely(READ_ONCE((t)->trc_reader_checked)) && \ |
|---|
| 170 | + !unlikely(READ_ONCE((t)->trc_reader_nesting))) { \ |
|---|
| 171 | + smp_store_release(&(t)->trc_reader_checked, true); \ |
|---|
| 172 | + smp_mb(); /* Readers partitioned by store. */ \ |
|---|
| 173 | + } \ |
|---|
| 174 | + } while (0) |
|---|
| 175 | +# else |
|---|
| 176 | +# define rcu_tasks_trace_qs(t) do { } while (0) |
|---|
| 177 | +# endif |
|---|
| 178 | + |
|---|
| 179 | +#define rcu_tasks_qs(t, preempt) \ |
|---|
| 180 | +do { \ |
|---|
| 181 | + rcu_tasks_classic_qs((t), (preempt)); \ |
|---|
| 182 | + rcu_tasks_trace_qs((t)); \ |
|---|
| 183 | +} while (0) |
|---|
| 184 | + |
|---|
| 185 | +# ifdef CONFIG_TASKS_RUDE_RCU |
|---|
| 186 | +void call_rcu_tasks_rude(struct rcu_head *head, rcu_callback_t func); |
|---|
| 187 | +void synchronize_rcu_tasks_rude(void); |
|---|
| 188 | +# endif |
|---|
| 189 | + |
|---|
| 190 | +#define rcu_note_voluntary_context_switch(t) rcu_tasks_qs(t, false) |
|---|
| 175 | 191 | void exit_tasks_rcu_start(void); |
|---|
| 192 | +void exit_tasks_rcu_stop(void); |
|---|
| 176 | 193 | void exit_tasks_rcu_finish(void); |
|---|
| 177 | | -#else /* #ifdef CONFIG_TASKS_RCU */ |
|---|
| 178 | | -#define rcu_tasks_qs(t) do { } while (0) |
|---|
| 179 | | -#define rcu_note_voluntary_context_switch(t) rcu_all_qs() |
|---|
| 180 | | -#define call_rcu_tasks call_rcu_sched |
|---|
| 181 | | -#define synchronize_rcu_tasks synchronize_sched |
|---|
| 194 | +#else /* #ifdef CONFIG_TASKS_RCU_GENERIC */ |
|---|
| 195 | +#define rcu_tasks_qs(t, preempt) do { } while (0) |
|---|
| 196 | +#define rcu_note_voluntary_context_switch(t) do { } while (0) |
|---|
| 197 | +#define call_rcu_tasks call_rcu |
|---|
| 198 | +#define synchronize_rcu_tasks synchronize_rcu |
|---|
| 182 | 199 | static inline void exit_tasks_rcu_start(void) { } |
|---|
| 200 | +static inline void exit_tasks_rcu_stop(void) { } |
|---|
| 183 | 201 | static inline void exit_tasks_rcu_finish(void) { } |
|---|
| 184 | | -#endif /* #else #ifdef CONFIG_TASKS_RCU */ |
|---|
| 202 | +#endif /* #else #ifdef CONFIG_TASKS_RCU_GENERIC */ |
|---|
| 185 | 203 | |
|---|
| 186 | 204 | /** |
|---|
| 187 | 205 | * cond_resched_tasks_rcu_qs - Report potential quiescent states to RCU |
|---|
| 188 | 206 | * |
|---|
| 189 | 207 | * This macro resembles cond_resched(), except that it is defined to |
|---|
| 190 | 208 | * report potential quiescent states to RCU-tasks even if the cond_resched() |
|---|
| 191 | | - * machinery were to be shut off, as some advocate for PREEMPT kernels. |
|---|
| 209 | + * machinery were to be shut off, as some advocate for PREEMPTION kernels. |
|---|
| 192 | 210 | */ |
|---|
| 193 | 211 | #define cond_resched_tasks_rcu_qs() \ |
|---|
| 194 | 212 | do { \ |
|---|
| 195 | | - rcu_tasks_qs(current); \ |
|---|
| 213 | + rcu_tasks_qs(current, false); \ |
|---|
| 196 | 214 | cond_resched(); \ |
|---|
| 197 | 215 | } while (0) |
|---|
| 198 | 216 | |
|---|
| .. | .. |
|---|
| 201 | 219 | * TREE_RCU and rcu_barrier_() primitives in TINY_RCU. |
|---|
| 202 | 220 | */ |
|---|
| 203 | 221 | |
|---|
| 204 | | -#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU) |
|---|
| 222 | +#if defined(CONFIG_TREE_RCU) |
|---|
| 205 | 223 | #include <linux/rcutree.h> |
|---|
| 206 | 224 | #elif defined(CONFIG_TINY_RCU) |
|---|
| 207 | 225 | #include <linux/rcutiny.h> |
|---|
| .. | .. |
|---|
| 244 | 262 | |
|---|
| 245 | 263 | static inline void rcu_lock_release(struct lockdep_map *map) |
|---|
| 246 | 264 | { |
|---|
| 247 | | - lock_release(map, 1, _THIS_IP_); |
|---|
| 265 | + lock_release(map, _THIS_IP_); |
|---|
| 248 | 266 | } |
|---|
| 249 | 267 | |
|---|
| 250 | 268 | extern struct lockdep_map rcu_lock_map; |
|---|
| .. | .. |
|---|
| 255 | 273 | int rcu_read_lock_held(void); |
|---|
| 256 | 274 | int rcu_read_lock_bh_held(void); |
|---|
| 257 | 275 | int rcu_read_lock_sched_held(void); |
|---|
| 276 | +int rcu_read_lock_any_held(void); |
|---|
| 258 | 277 | |
|---|
| 259 | 278 | #else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */ |
|---|
| 260 | 279 | |
|---|
| .. | .. |
|---|
| 275 | 294 | { |
|---|
| 276 | 295 | return !preemptible(); |
|---|
| 277 | 296 | } |
|---|
| 297 | + |
|---|
| 298 | +static inline int rcu_read_lock_any_held(void) |
|---|
| 299 | +{ |
|---|
| 300 | + return !preemptible(); |
|---|
| 301 | +} |
|---|
| 302 | + |
|---|
| 278 | 303 | #endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */ |
|---|
| 279 | 304 | |
|---|
| 280 | 305 | #ifdef CONFIG_PROVE_RCU |
|---|
| .. | .. |
|---|
| 283 | 308 | * RCU_LOCKDEP_WARN - emit lockdep splat if specified condition is met |
|---|
| 284 | 309 | * @c: condition to check |
|---|
| 285 | 310 | * @s: informative message |
|---|
| 311 | + * |
|---|
| 312 | + * This checks debug_lockdep_rcu_enabled() before checking (c) to |
|---|
| 313 | + * prevent early boot splats due to lockdep not yet being initialized, |
|---|
| 314 | + * and rechecks it after checking (c) to prevent false-positive splats |
|---|
| 315 | + * due to races with lockdep being disabled. See commit 3066820034b5dd |
|---|
| 316 | + * ("rcu: Reject RCU_LOCKDEP_WARN() false positives") for more detail. |
|---|
| 286 | 317 | */ |
|---|
| 287 | 318 | #define RCU_LOCKDEP_WARN(c, s) \ |
|---|
| 288 | 319 | do { \ |
|---|
| 289 | | - static bool __section(.data.unlikely) __warned; \ |
|---|
| 290 | | - if (debug_lockdep_rcu_enabled() && !__warned && (c)) { \ |
|---|
| 320 | + static bool __section(".data.unlikely") __warned; \ |
|---|
| 321 | + if (debug_lockdep_rcu_enabled() && (c) && \ |
|---|
| 322 | + debug_lockdep_rcu_enabled() && !__warned) { \ |
|---|
| 291 | 323 | __warned = true; \ |
|---|
| 292 | 324 | lockdep_rcu_suspicious(__FILE__, __LINE__, s); \ |
|---|
| 293 | 325 | } \ |
|---|
| .. | .. |
|---|
| 323 | 355 | * Helper functions for rcu_dereference_check(), rcu_dereference_protected() |
|---|
| 324 | 356 | * and rcu_assign_pointer(). Some of these could be folded into their |
|---|
| 325 | 357 | * callers, but they are left separate in order to ease introduction of |
|---|
| 326 | | - * multiple flavors of pointers to match the multiple flavors of RCU |
|---|
| 327 | | - * (e.g., __rcu_bh, * __rcu_sched, and __srcu), should this make sense in |
|---|
| 328 | | - * the future. |
|---|
| 358 | + * multiple pointers markings to match different RCU implementations |
|---|
| 359 | + * (e.g., __srcu), should this make sense in the future. |
|---|
| 329 | 360 | */ |
|---|
| 330 | 361 | |
|---|
| 331 | 362 | #ifdef __CHECKER__ |
|---|
| 332 | | -#define rcu_dereference_sparse(p, space) \ |
|---|
| 363 | +#define rcu_check_sparse(p, space) \ |
|---|
| 333 | 364 | ((void)(((typeof(*p) space *)p) == p)) |
|---|
| 334 | 365 | #else /* #ifdef __CHECKER__ */ |
|---|
| 335 | | -#define rcu_dereference_sparse(p, space) |
|---|
| 366 | +#define rcu_check_sparse(p, space) |
|---|
| 336 | 367 | #endif /* #else #ifdef __CHECKER__ */ |
|---|
| 337 | 368 | |
|---|
| 338 | 369 | #define __rcu_access_pointer(p, space) \ |
|---|
| 339 | 370 | ({ \ |
|---|
| 340 | 371 | typeof(*p) *_________p1 = (typeof(*p) *__force)READ_ONCE(p); \ |
|---|
| 341 | | - rcu_dereference_sparse(p, space); \ |
|---|
| 372 | + rcu_check_sparse(p, space); \ |
|---|
| 342 | 373 | ((typeof(*p) __force __kernel *)(_________p1)); \ |
|---|
| 343 | 374 | }) |
|---|
| 344 | 375 | #define __rcu_dereference_check(p, c, space) \ |
|---|
| .. | .. |
|---|
| 346 | 377 | /* Dependency order vs. p above. */ \ |
|---|
| 347 | 378 | typeof(*p) *________p1 = (typeof(*p) *__force)READ_ONCE(p); \ |
|---|
| 348 | 379 | RCU_LOCKDEP_WARN(!(c), "suspicious rcu_dereference_check() usage"); \ |
|---|
| 349 | | - rcu_dereference_sparse(p, space); \ |
|---|
| 380 | + rcu_check_sparse(p, space); \ |
|---|
| 350 | 381 | ((typeof(*p) __force __kernel *)(________p1)); \ |
|---|
| 351 | 382 | }) |
|---|
| 352 | 383 | #define __rcu_dereference_protected(p, c, space) \ |
|---|
| 353 | 384 | ({ \ |
|---|
| 354 | 385 | RCU_LOCKDEP_WARN(!(c), "suspicious rcu_dereference_protected() usage"); \ |
|---|
| 355 | | - rcu_dereference_sparse(p, space); \ |
|---|
| 386 | + rcu_check_sparse(p, space); \ |
|---|
| 356 | 387 | ((typeof(*p) __force __kernel *)(p)); \ |
|---|
| 357 | 388 | }) |
|---|
| 358 | 389 | #define rcu_dereference_raw(p) \ |
|---|
| .. | .. |
|---|
| 400 | 431 | * other macros that it invokes. |
|---|
| 401 | 432 | */ |
|---|
| 402 | 433 | #define rcu_assign_pointer(p, v) \ |
|---|
| 403 | | -({ \ |
|---|
| 434 | +do { \ |
|---|
| 404 | 435 | uintptr_t _r_a_p__v = (uintptr_t)(v); \ |
|---|
| 436 | + rcu_check_sparse(p, __rcu); \ |
|---|
| 405 | 437 | \ |
|---|
| 406 | 438 | if (__builtin_constant_p(v) && (_r_a_p__v) == (uintptr_t)NULL) \ |
|---|
| 407 | 439 | WRITE_ONCE((p), (typeof(p))(_r_a_p__v)); \ |
|---|
| 408 | 440 | else \ |
|---|
| 409 | 441 | smp_store_release(&p, RCU_INITIALIZER((typeof(p))_r_a_p__v)); \ |
|---|
| 410 | | - _r_a_p__v; \ |
|---|
| 411 | | -}) |
|---|
| 442 | +} while (0) |
|---|
| 412 | 443 | |
|---|
| 413 | 444 | /** |
|---|
| 414 | | - * rcu_swap_protected() - swap an RCU and a regular pointer |
|---|
| 415 | | - * @rcu_ptr: RCU pointer |
|---|
| 445 | + * rcu_replace_pointer() - replace an RCU pointer, returning its old value |
|---|
| 446 | + * @rcu_ptr: RCU pointer, whose old value is returned |
|---|
| 416 | 447 | * @ptr: regular pointer |
|---|
| 417 | | - * @c: the conditions under which the dereference will take place |
|---|
| 448 | + * @c: the lockdep conditions under which the dereference will take place |
|---|
| 418 | 449 | * |
|---|
| 419 | | - * Perform swap(@rcu_ptr, @ptr) where @rcu_ptr is an RCU-annotated pointer and |
|---|
| 420 | | - * @c is the argument that is passed to the rcu_dereference_protected() call |
|---|
| 421 | | - * used to read that pointer. |
|---|
| 450 | + * Perform a replacement, where @rcu_ptr is an RCU-annotated |
|---|
| 451 | + * pointer and @c is the lockdep argument that is passed to the |
|---|
| 452 | + * rcu_dereference_protected() call used to read that pointer. The old |
|---|
| 453 | + * value of @rcu_ptr is returned, and @rcu_ptr is set to @ptr. |
|---|
| 422 | 454 | */ |
|---|
| 423 | | -#define rcu_swap_protected(rcu_ptr, ptr, c) do { \ |
|---|
| 455 | +#define rcu_replace_pointer(rcu_ptr, ptr, c) \ |
|---|
| 456 | +({ \ |
|---|
| 424 | 457 | typeof(ptr) __tmp = rcu_dereference_protected((rcu_ptr), (c)); \ |
|---|
| 425 | 458 | rcu_assign_pointer((rcu_ptr), (ptr)); \ |
|---|
| 426 | | - (ptr) = __tmp; \ |
|---|
| 427 | | -} while (0) |
|---|
| 459 | + __tmp; \ |
|---|
| 460 | +}) |
|---|
| 428 | 461 | |
|---|
| 429 | 462 | /** |
|---|
| 430 | 463 | * rcu_access_pointer() - fetch RCU pointer with no dereferencing |
|---|
| .. | .. |
|---|
| 511 | 544 | * The no-tracing version of rcu_dereference_raw() must not call |
|---|
| 512 | 545 | * rcu_read_lock_held(). |
|---|
| 513 | 546 | */ |
|---|
| 514 | | -#define rcu_dereference_raw_notrace(p) __rcu_dereference_check((p), 1, __rcu) |
|---|
| 547 | +#define rcu_dereference_raw_check(p) __rcu_dereference_check((p), 1, __rcu) |
|---|
| 515 | 548 | |
|---|
| 516 | 549 | /** |
|---|
| 517 | 550 | * rcu_dereference_protected() - fetch RCU pointer when updates prevented |
|---|
| .. | .. |
|---|
| 608 | 641 | * |
|---|
| 609 | 642 | * You can avoid reading and understanding the next paragraph by |
|---|
| 610 | 643 | * following this rule: don't put anything in an rcu_read_lock() RCU |
|---|
| 611 | | - * read-side critical section that would block in a !PREEMPT kernel. |
|---|
| 644 | + * read-side critical section that would block in a !PREEMPTION kernel. |
|---|
| 612 | 645 | * But if you want the full story, read on! |
|---|
| 613 | 646 | * |
|---|
| 614 | | - * In non-preemptible RCU implementations (TREE_RCU and TINY_RCU), |
|---|
| 647 | + * In non-preemptible RCU implementations (pure TREE_RCU and TINY_RCU), |
|---|
| 615 | 648 | * it is illegal to block while in an RCU read-side critical section. |
|---|
| 616 | | - * In preemptible RCU implementations (PREEMPT_RCU) in CONFIG_PREEMPT |
|---|
| 649 | + * In preemptible RCU implementations (PREEMPT_RCU) in CONFIG_PREEMPTION |
|---|
| 617 | 650 | * kernel builds, RCU read-side critical sections may be preempted, |
|---|
| 618 | 651 | * but explicit blocking is illegal. Finally, in preemptible RCU |
|---|
| 619 | 652 | * implementations in real-time (with -rt patchset) kernel builds, RCU |
|---|
| .. | .. |
|---|
| 684 | 717 | /** |
|---|
| 685 | 718 | * rcu_read_lock_bh() - mark the beginning of an RCU-bh critical section |
|---|
| 686 | 719 | * |
|---|
| 687 | | - * This is equivalent of rcu_read_lock(), but to be used when updates |
|---|
| 688 | | - * are being done using call_rcu_bh() or synchronize_rcu_bh(). Since |
|---|
| 689 | | - * both call_rcu_bh() and synchronize_rcu_bh() consider completion of a |
|---|
| 690 | | - * softirq handler to be a quiescent state, a process in RCU read-side |
|---|
| 691 | | - * critical section must be protected by disabling softirqs. Read-side |
|---|
| 692 | | - * critical sections in interrupt context can use just rcu_read_lock(), |
|---|
| 693 | | - * though this should at least be commented to avoid confusing people |
|---|
| 694 | | - * reading the code. |
|---|
| 720 | + * This is equivalent of rcu_read_lock(), but also disables softirqs. |
|---|
| 721 | + * Note that anything else that disables softirqs can also serve as |
|---|
| 722 | + * an RCU read-side critical section. |
|---|
| 695 | 723 | * |
|---|
| 696 | 724 | * Note that rcu_read_lock_bh() and the matching rcu_read_unlock_bh() |
|---|
| 697 | 725 | * must occur in the same context, for example, it is illegal to invoke |
|---|
| .. | .. |
|---|
| 707 | 735 | "rcu_read_lock_bh() used illegally while idle"); |
|---|
| 708 | 736 | } |
|---|
| 709 | 737 | |
|---|
| 710 | | -/* |
|---|
| 711 | | - * rcu_read_unlock_bh - marks the end of a softirq-only RCU critical section |
|---|
| 738 | +/** |
|---|
| 739 | + * rcu_read_unlock_bh() - marks the end of a softirq-only RCU critical section |
|---|
| 712 | 740 | * |
|---|
| 713 | 741 | * See rcu_read_lock_bh() for more information. |
|---|
| 714 | 742 | */ |
|---|
| .. | .. |
|---|
| 724 | 752 | /** |
|---|
| 725 | 753 | * rcu_read_lock_sched() - mark the beginning of a RCU-sched critical section |
|---|
| 726 | 754 | * |
|---|
| 727 | | - * This is equivalent of rcu_read_lock(), but to be used when updates |
|---|
| 728 | | - * are being done using call_rcu_sched() or synchronize_rcu_sched(). |
|---|
| 729 | | - * Read-side critical sections can also be introduced by anything that |
|---|
| 730 | | - * disables preemption, including local_irq_disable() and friends. |
|---|
| 755 | + * This is equivalent of rcu_read_lock(), but disables preemption. |
|---|
| 756 | + * Read-side critical sections can also be introduced by anything else |
|---|
| 757 | + * that disables preemption, including local_irq_disable() and friends. |
|---|
| 731 | 758 | * |
|---|
| 732 | 759 | * Note that rcu_read_lock_sched() and the matching rcu_read_unlock_sched() |
|---|
| 733 | 760 | * must occur in the same context, for example, it is illegal to invoke |
|---|
| .. | .. |
|---|
| 750 | 777 | __acquire(RCU_SCHED); |
|---|
| 751 | 778 | } |
|---|
| 752 | 779 | |
|---|
| 753 | | -/* |
|---|
| 754 | | - * rcu_read_unlock_sched - marks the end of a RCU-classic critical section |
|---|
| 780 | +/** |
|---|
| 781 | + * rcu_read_unlock_sched() - marks the end of a RCU-classic critical section |
|---|
| 755 | 782 | * |
|---|
| 756 | | - * See rcu_read_lock_sched for more information. |
|---|
| 783 | + * See rcu_read_lock_sched() for more information. |
|---|
| 757 | 784 | */ |
|---|
| 758 | 785 | static inline void rcu_read_unlock_sched(void) |
|---|
| 759 | 786 | { |
|---|
| .. | .. |
|---|
| 811 | 838 | */ |
|---|
| 812 | 839 | #define RCU_INIT_POINTER(p, v) \ |
|---|
| 813 | 840 | do { \ |
|---|
| 814 | | - rcu_dereference_sparse(p, __rcu); \ |
|---|
| 841 | + rcu_check_sparse(p, __rcu); \ |
|---|
| 815 | 842 | WRITE_ONCE(p, RCU_INITIALIZER(v)); \ |
|---|
| 816 | 843 | } while (0) |
|---|
| 817 | 844 | |
|---|
| .. | .. |
|---|
| 827 | 854 | |
|---|
| 828 | 855 | /* |
|---|
| 829 | 856 | * Does the specified offset indicate that the corresponding rcu_head |
|---|
| 830 | | - * structure can be handled by kfree_rcu()? |
|---|
| 857 | + * structure can be handled by kvfree_rcu()? |
|---|
| 831 | 858 | */ |
|---|
| 832 | | -#define __is_kfree_rcu_offset(offset) ((offset) < 4096) |
|---|
| 859 | +#define __is_kvfree_rcu_offset(offset) ((offset) < 4096) |
|---|
| 833 | 860 | |
|---|
| 834 | 861 | /* |
|---|
| 835 | 862 | * Helper macro for kfree_rcu() to prevent argument-expansion eyestrain. |
|---|
| 836 | 863 | */ |
|---|
| 837 | | -#define __kfree_rcu(head, offset) \ |
|---|
| 864 | +#define __kvfree_rcu(head, offset) \ |
|---|
| 838 | 865 | do { \ |
|---|
| 839 | | - BUILD_BUG_ON(!__is_kfree_rcu_offset(offset)); \ |
|---|
| 840 | | - kfree_call_rcu(head, (rcu_callback_t)(unsigned long)(offset)); \ |
|---|
| 866 | + BUILD_BUG_ON(!__is_kvfree_rcu_offset(offset)); \ |
|---|
| 867 | + kvfree_call_rcu(head, (rcu_callback_t)(unsigned long)(offset)); \ |
|---|
| 841 | 868 | } while (0) |
|---|
| 842 | 869 | |
|---|
| 843 | 870 | /** |
|---|
| 844 | 871 | * kfree_rcu() - kfree an object after a grace period. |
|---|
| 845 | 872 | * @ptr: pointer to kfree |
|---|
| 846 | | - * @rcu_head: the name of the struct rcu_head within the type of @ptr. |
|---|
| 873 | + * @rhf: the name of the struct rcu_head within the type of @ptr. |
|---|
| 847 | 874 | * |
|---|
| 848 | 875 | * Many rcu callbacks functions just call kfree() on the base structure. |
|---|
| 849 | 876 | * These functions are trivial, but their size adds up, and furthermore |
|---|
| .. | .. |
|---|
| 856 | 883 | * Because the functions are not allowed in the low-order 4096 bytes of |
|---|
| 857 | 884 | * kernel virtual memory, offsets up to 4095 bytes can be accommodated. |
|---|
| 858 | 885 | * If the offset is larger than 4095 bytes, a compile-time error will |
|---|
| 859 | | - * be generated in __kfree_rcu(). If this error is triggered, you can |
|---|
| 886 | + * be generated in __kvfree_rcu(). If this error is triggered, you can |
|---|
| 860 | 887 | * either fall back to use of call_rcu() or rearrange the structure to |
|---|
| 861 | 888 | * position the rcu_head structure into the first 4096 bytes. |
|---|
| 862 | 889 | * |
|---|
| .. | .. |
|---|
| 866 | 893 | * The BUILD_BUG_ON check must not involve any function calls, hence the |
|---|
| 867 | 894 | * checks are done in macros here. |
|---|
| 868 | 895 | */ |
|---|
| 869 | | -#define kfree_rcu(ptr, rcu_head) \ |
|---|
| 870 | | - __kfree_rcu(&((ptr)->rcu_head), offsetof(typeof(*(ptr)), rcu_head)) |
|---|
| 896 | +#define kfree_rcu(ptr, rhf) \ |
|---|
| 897 | +do { \ |
|---|
| 898 | + typeof (ptr) ___p = (ptr); \ |
|---|
| 899 | + \ |
|---|
| 900 | + if (___p) \ |
|---|
| 901 | + __kvfree_rcu(&((___p)->rhf), offsetof(typeof(*(ptr)), rhf)); \ |
|---|
| 902 | +} while (0) |
|---|
| 871 | 903 | |
|---|
| 904 | +/** |
|---|
| 905 | + * kvfree_rcu() - kvfree an object after a grace period. |
|---|
| 906 | + * |
|---|
| 907 | + * This macro consists of one or two arguments and it is |
|---|
| 908 | + * based on whether an object is head-less or not. If it |
|---|
| 909 | + * has a head then a semantic stays the same as it used |
|---|
| 910 | + * to be before: |
|---|
| 911 | + * |
|---|
| 912 | + * kvfree_rcu(ptr, rhf); |
|---|
| 913 | + * |
|---|
| 914 | + * where @ptr is a pointer to kvfree(), @rhf is the name |
|---|
| 915 | + * of the rcu_head structure within the type of @ptr. |
|---|
| 916 | + * |
|---|
| 917 | + * When it comes to head-less variant, only one argument |
|---|
| 918 | + * is passed and that is just a pointer which has to be |
|---|
| 919 | + * freed after a grace period. Therefore the semantic is |
|---|
| 920 | + * |
|---|
| 921 | + * kvfree_rcu(ptr); |
|---|
| 922 | + * |
|---|
| 923 | + * where @ptr is a pointer to kvfree(). |
|---|
| 924 | + * |
|---|
| 925 | + * Please note, head-less way of freeing is permitted to |
|---|
| 926 | + * use from a context that has to follow might_sleep() |
|---|
| 927 | + * annotation. Otherwise, please switch and embed the |
|---|
| 928 | + * rcu_head structure within the type of @ptr. |
|---|
| 929 | + */ |
|---|
| 930 | +#define kvfree_rcu(...) KVFREE_GET_MACRO(__VA_ARGS__, \ |
|---|
| 931 | + kvfree_rcu_arg_2, kvfree_rcu_arg_1)(__VA_ARGS__) |
|---|
| 932 | + |
|---|
| 933 | +#define KVFREE_GET_MACRO(_1, _2, NAME, ...) NAME |
|---|
| 934 | +#define kvfree_rcu_arg_2(ptr, rhf) kfree_rcu(ptr, rhf) |
|---|
| 935 | +#define kvfree_rcu_arg_1(ptr) \ |
|---|
| 936 | +do { \ |
|---|
| 937 | + typeof(ptr) ___p = (ptr); \ |
|---|
| 938 | + \ |
|---|
| 939 | + if (___p) \ |
|---|
| 940 | + kvfree_call_rcu(NULL, (rcu_callback_t) (___p)); \ |
|---|
| 941 | +} while (0) |
|---|
| 872 | 942 | |
|---|
| 873 | 943 | /* |
|---|
| 874 | 944 | * Place this after a lock-acquisition primitive to guarantee that |
|---|
| .. | .. |
|---|
| 883 | 953 | #endif /* #else #ifdef CONFIG_ARCH_WEAK_RELEASE_ACQUIRE */ |
|---|
| 884 | 954 | |
|---|
| 885 | 955 | |
|---|
| 956 | +/* Has the specified rcu_head structure been handed to call_rcu()? */ |
|---|
| 957 | + |
|---|
| 958 | +/** |
|---|
| 959 | + * rcu_head_init - Initialize rcu_head for rcu_head_after_call_rcu() |
|---|
| 960 | + * @rhp: The rcu_head structure to initialize. |
|---|
| 961 | + * |
|---|
| 962 | + * If you intend to invoke rcu_head_after_call_rcu() to test whether a |
|---|
| 963 | + * given rcu_head structure has already been passed to call_rcu(), then |
|---|
| 964 | + * you must also invoke this rcu_head_init() function on it just after |
|---|
| 965 | + * allocating that structure. Calls to this function must not race with |
|---|
| 966 | + * calls to call_rcu(), rcu_head_after_call_rcu(), or callback invocation. |
|---|
| 967 | + */ |
|---|
| 968 | +static inline void rcu_head_init(struct rcu_head *rhp) |
|---|
| 969 | +{ |
|---|
| 970 | + rhp->func = (rcu_callback_t)~0L; |
|---|
| 971 | +} |
|---|
| 972 | + |
|---|
| 973 | +/** |
|---|
| 974 | + * rcu_head_after_call_rcu() - Has this rcu_head been passed to call_rcu()? |
|---|
| 975 | + * @rhp: The rcu_head structure to test. |
|---|
| 976 | + * @f: The function passed to call_rcu() along with @rhp. |
|---|
| 977 | + * |
|---|
| 978 | + * Returns @true if the @rhp has been passed to call_rcu() with @func, |
|---|
| 979 | + * and @false otherwise. Emits a warning in any other case, including |
|---|
| 980 | + * the case where @rhp has already been invoked after a grace period. |
|---|
| 981 | + * Calls to this function must not race with callback invocation. One way |
|---|
| 982 | + * to avoid such races is to enclose the call to rcu_head_after_call_rcu() |
|---|
| 983 | + * in an RCU read-side critical section that includes a read-side fetch |
|---|
| 984 | + * of the pointer to the structure containing @rhp. |
|---|
| 985 | + */ |
|---|
| 986 | +static inline bool |
|---|
| 987 | +rcu_head_after_call_rcu(struct rcu_head *rhp, rcu_callback_t f) |
|---|
| 988 | +{ |
|---|
| 989 | + rcu_callback_t func = READ_ONCE(rhp->func); |
|---|
| 990 | + |
|---|
| 991 | + if (func == f) |
|---|
| 992 | + return true; |
|---|
| 993 | + WARN_ON_ONCE(func != (rcu_callback_t)~0L); |
|---|
| 994 | + return false; |
|---|
| 995 | +} |
|---|
| 996 | + |
|---|
| 997 | +/* kernel/ksysfs.c definitions */ |
|---|
| 998 | +extern int rcu_expedited; |
|---|
| 999 | +extern int rcu_normal; |
|---|
| 1000 | + |
|---|
| 886 | 1001 | #endif /* __LINUX_RCUPDATE_H */ |
|---|