diff options
Diffstat (limited to 'include/linux/rcupdate.h')
| -rw-r--r-- | include/linux/rcupdate.h | 242 |
1 files changed, 220 insertions, 22 deletions
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h index 3ebd0b7bcb08..db266bbed23f 100644 --- a/include/linux/rcupdate.h +++ b/include/linux/rcupdate.h | |||
| @@ -41,6 +41,10 @@ | |||
| 41 | #include <linux/lockdep.h> | 41 | #include <linux/lockdep.h> |
| 42 | #include <linux/completion.h> | 42 | #include <linux/completion.h> |
| 43 | 43 | ||
| 44 | #ifdef CONFIG_RCU_TORTURE_TEST | ||
| 45 | extern int rcutorture_runnable; /* for sysctl */ | ||
| 46 | #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */ | ||
| 47 | |||
| 44 | /** | 48 | /** |
| 45 | * struct rcu_head - callback structure for use with RCU | 49 | * struct rcu_head - callback structure for use with RCU |
| 46 | * @next: next update requests in a list | 50 | * @next: next update requests in a list |
| @@ -52,11 +56,6 @@ struct rcu_head { | |||
| 52 | }; | 56 | }; |
| 53 | 57 | ||
| 54 | /* Exported common interfaces */ | 58 | /* Exported common interfaces */ |
| 55 | #ifdef CONFIG_TREE_PREEMPT_RCU | ||
| 56 | extern void synchronize_rcu(void); | ||
| 57 | #else /* #ifdef CONFIG_TREE_PREEMPT_RCU */ | ||
| 58 | #define synchronize_rcu synchronize_sched | ||
| 59 | #endif /* #else #ifdef CONFIG_TREE_PREEMPT_RCU */ | ||
| 60 | extern void synchronize_rcu_bh(void); | 59 | extern void synchronize_rcu_bh(void); |
| 61 | extern void synchronize_sched(void); | 60 | extern void synchronize_sched(void); |
| 62 | extern void rcu_barrier(void); | 61 | extern void rcu_barrier(void); |
| @@ -67,12 +66,13 @@ extern int sched_expedited_torture_stats(char *page); | |||
| 67 | 66 | ||
| 68 | /* Internal to kernel */ | 67 | /* Internal to kernel */ |
| 69 | extern void rcu_init(void); | 68 | extern void rcu_init(void); |
| 70 | extern void rcu_scheduler_starting(void); | ||
| 71 | extern int rcu_needs_cpu(int cpu); | ||
| 72 | extern int rcu_scheduler_active; | 69 | extern int rcu_scheduler_active; |
| 70 | extern void rcu_scheduler_starting(void); | ||
| 73 | 71 | ||
| 74 | #if defined(CONFIG_TREE_RCU) || defined(CONFIG_TREE_PREEMPT_RCU) | 72 | #if defined(CONFIG_TREE_RCU) || defined(CONFIG_TREE_PREEMPT_RCU) |
| 75 | #include <linux/rcutree.h> | 73 | #include <linux/rcutree.h> |
| 74 | #elif defined(CONFIG_TINY_RCU) | ||
| 75 | #include <linux/rcutiny.h> | ||
| 76 | #else | 76 | #else |
| 77 | #error "Unknown RCU implementation specified to kernel configuration" | 77 | #error "Unknown RCU implementation specified to kernel configuration" |
| 78 | #endif | 78 | #endif |
| @@ -84,14 +84,185 @@ extern int rcu_scheduler_active; | |||
| 84 | } while (0) | 84 | } while (0) |
| 85 | 85 | ||
| 86 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | 86 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
| 87 | |||
| 87 | extern struct lockdep_map rcu_lock_map; | 88 | extern struct lockdep_map rcu_lock_map; |
| 88 | # define rcu_read_acquire() \ | 89 | # define rcu_read_acquire() \ |
| 89 | lock_acquire(&rcu_lock_map, 0, 0, 2, 1, NULL, _THIS_IP_) | 90 | lock_acquire(&rcu_lock_map, 0, 0, 2, 1, NULL, _THIS_IP_) |
| 90 | # define rcu_read_release() lock_release(&rcu_lock_map, 1, _THIS_IP_) | 91 | # define rcu_read_release() lock_release(&rcu_lock_map, 1, _THIS_IP_) |
| 91 | #else | 92 | |
| 92 | # define rcu_read_acquire() do { } while (0) | 93 | extern struct lockdep_map rcu_bh_lock_map; |
| 93 | # define rcu_read_release() do { } while (0) | 94 | # define rcu_read_acquire_bh() \ |
| 94 | #endif | 95 | lock_acquire(&rcu_bh_lock_map, 0, 0, 2, 1, NULL, _THIS_IP_) |
| 96 | # define rcu_read_release_bh() lock_release(&rcu_bh_lock_map, 1, _THIS_IP_) | ||
| 97 | |||
| 98 | extern struct lockdep_map rcu_sched_lock_map; | ||
| 99 | # define rcu_read_acquire_sched() \ | ||
| 100 | lock_acquire(&rcu_sched_lock_map, 0, 0, 2, 1, NULL, _THIS_IP_) | ||
| 101 | # define rcu_read_release_sched() \ | ||
| 102 | lock_release(&rcu_sched_lock_map, 1, _THIS_IP_) | ||
| 103 | |||
| 104 | extern int debug_lockdep_rcu_enabled(void); | ||
| 105 | |||
| 106 | /** | ||
| 107 | * rcu_read_lock_held - might we be in RCU read-side critical section? | ||
| 108 | * | ||
| 109 | * If CONFIG_PROVE_LOCKING is selected and enabled, returns nonzero iff in | ||
| 110 | * an RCU read-side critical section. In absence of CONFIG_PROVE_LOCKING, | ||
| 111 | * this assumes we are in an RCU read-side critical section unless it can | ||
| 112 | * prove otherwise. | ||
| 113 | * | ||
| 114 | * Check rcu_scheduler_active to prevent false positives during boot. | ||
| 115 | */ | ||
| 116 | static inline int rcu_read_lock_held(void) | ||
| 117 | { | ||
| 118 | if (!debug_lockdep_rcu_enabled()) | ||
| 119 | return 1; | ||
| 120 | return lock_is_held(&rcu_lock_map); | ||
| 121 | } | ||
| 122 | |||
| 123 | /* | ||
| 124 | * rcu_read_lock_bh_held() is defined out of line to avoid #include-file | ||
| 125 | * hell. | ||
| 126 | */ | ||
| 127 | extern int rcu_read_lock_bh_held(void); | ||
| 128 | |||
| 129 | /** | ||
| 130 | * rcu_read_lock_sched_held - might we be in RCU-sched read-side critical section? | ||
| 131 | * | ||
| 132 | * If CONFIG_PROVE_LOCKING is selected and enabled, returns nonzero iff in an | ||
| 133 | * RCU-sched read-side critical section. In absence of CONFIG_PROVE_LOCKING, | ||
| 134 | * this assumes we are in an RCU-sched read-side critical section unless it | ||
| 135 | * can prove otherwise. Note that disabling of preemption (including | ||
| 136 | * disabling irqs) counts as an RCU-sched read-side critical section. | ||
| 137 | * | ||
| 138 | * Check rcu_scheduler_active to prevent false positives during boot. | ||
| 139 | */ | ||
| 140 | #ifdef CONFIG_PREEMPT | ||
| 141 | static inline int rcu_read_lock_sched_held(void) | ||
| 142 | { | ||
| 143 | int lockdep_opinion = 0; | ||
| 144 | |||
| 145 | if (!debug_lockdep_rcu_enabled()) | ||
| 146 | return 1; | ||
| 147 | if (debug_locks) | ||
| 148 | lockdep_opinion = lock_is_held(&rcu_sched_lock_map); | ||
| 149 | return lockdep_opinion || preempt_count() != 0 || irqs_disabled(); | ||
| 150 | } | ||
| 151 | #else /* #ifdef CONFIG_PREEMPT */ | ||
| 152 | static inline int rcu_read_lock_sched_held(void) | ||
| 153 | { | ||
| 154 | return 1; | ||
| 155 | } | ||
| 156 | #endif /* #else #ifdef CONFIG_PREEMPT */ | ||
| 157 | |||
| 158 | #else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */ | ||
| 159 | |||
| 160 | # define rcu_read_acquire() do { } while (0) | ||
| 161 | # define rcu_read_release() do { } while (0) | ||
| 162 | # define rcu_read_acquire_bh() do { } while (0) | ||
| 163 | # define rcu_read_release_bh() do { } while (0) | ||
| 164 | # define rcu_read_acquire_sched() do { } while (0) | ||
| 165 | # define rcu_read_release_sched() do { } while (0) | ||
| 166 | |||
| 167 | static inline int rcu_read_lock_held(void) | ||
| 168 | { | ||
| 169 | return 1; | ||
| 170 | } | ||
| 171 | |||
| 172 | static inline int rcu_read_lock_bh_held(void) | ||
| 173 | { | ||
| 174 | return 1; | ||
| 175 | } | ||
| 176 | |||
| 177 | #ifdef CONFIG_PREEMPT | ||
| 178 | static inline int rcu_read_lock_sched_held(void) | ||
| 179 | { | ||
| 180 | return !rcu_scheduler_active || preempt_count() != 0 || irqs_disabled(); | ||
| 181 | } | ||
| 182 | #else /* #ifdef CONFIG_PREEMPT */ | ||
| 183 | static inline int rcu_read_lock_sched_held(void) | ||
| 184 | { | ||
| 185 | return 1; | ||
| 186 | } | ||
| 187 | #endif /* #else #ifdef CONFIG_PREEMPT */ | ||
| 188 | |||
| 189 | #endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */ | ||
| 190 | |||
| 191 | #ifdef CONFIG_PROVE_RCU | ||
| 192 | |||
| 193 | extern int rcu_my_thread_group_empty(void); | ||
| 194 | |||
| 195 | /** | ||
| 196 | * rcu_dereference_check - rcu_dereference with debug checking | ||
| 197 | * @p: The pointer to read, prior to dereferencing | ||
| 198 | * @c: The conditions under which the dereference will take place | ||
| 199 | * | ||
| 200 | * Do an rcu_dereference(), but check that the conditions under which the | ||
| 201 | * dereference will take place are correct. Typically the conditions indicate | ||
| 202 | * the various locking conditions that should be held at that point. The check | ||
| 203 | * should return true if the conditions are satisfied. | ||
| 204 | * | ||
| 205 | * For example: | ||
| 206 | * | ||
| 207 | * bar = rcu_dereference_check(foo->bar, rcu_read_lock_held() || | ||
| 208 | * lockdep_is_held(&foo->lock)); | ||
| 209 | * | ||
| 210 | * could be used to indicate to lockdep that foo->bar may only be dereferenced | ||
| 211 | * if either the RCU read lock is held, or that the lock required to replace | ||
| 212 | * the bar struct at foo->bar is held. | ||
| 213 | * | ||
| 214 | * Note that the list of conditions may also include indications of when a lock | ||
| 215 | * need not be held, for example during initialisation or destruction of the | ||
| 216 | * target struct: | ||
| 217 | * | ||
| 218 | * bar = rcu_dereference_check(foo->bar, rcu_read_lock_held() || | ||
| 219 | * lockdep_is_held(&foo->lock) || | ||
| 220 | * atomic_read(&foo->usage) == 0); | ||
| 221 | */ | ||
| 222 | #define rcu_dereference_check(p, c) \ | ||
| 223 | ({ \ | ||
| 224 | if (debug_lockdep_rcu_enabled() && !(c)) \ | ||
| 225 | lockdep_rcu_dereference(__FILE__, __LINE__); \ | ||
| 226 | rcu_dereference_raw(p); \ | ||
| 227 | }) | ||
| 228 | |||
| 229 | /** | ||
| 230 | * rcu_dereference_protected - fetch RCU pointer when updates prevented | ||
| 231 | * | ||
| 232 | * Return the value of the specified RCU-protected pointer, but omit | ||
| 233 | * both the smp_read_barrier_depends() and the ACCESS_ONCE(). This | ||
| 234 | * is useful in cases where update-side locks prevent the value of the | ||
| 235 | * pointer from changing. Please note that this primitive does -not- | ||
| 236 | * prevent the compiler from repeating this reference or combining it | ||
| 237 | * with other references, so it should not be used without protection | ||
| 238 | * of appropriate locks. | ||
| 239 | */ | ||
| 240 | #define rcu_dereference_protected(p, c) \ | ||
| 241 | ({ \ | ||
| 242 | if (debug_lockdep_rcu_enabled() && !(c)) \ | ||
| 243 | lockdep_rcu_dereference(__FILE__, __LINE__); \ | ||
| 244 | (p); \ | ||
| 245 | }) | ||
| 246 | |||
| 247 | #else /* #ifdef CONFIG_PROVE_RCU */ | ||
| 248 | |||
| 249 | #define rcu_dereference_check(p, c) rcu_dereference_raw(p) | ||
| 250 | #define rcu_dereference_protected(p, c) (p) | ||
| 251 | |||
| 252 | #endif /* #else #ifdef CONFIG_PROVE_RCU */ | ||
| 253 | |||
| 254 | /** | ||
| 255 | * rcu_access_pointer - fetch RCU pointer with no dereferencing | ||
| 256 | * | ||
| 257 | * Return the value of the specified RCU-protected pointer, but omit the | ||
| 258 | * smp_read_barrier_depends() and keep the ACCESS_ONCE(). This is useful | ||
| 259 | * when the value of this pointer is accessed, but the pointer is not | ||
| 260 | * dereferenced, for example, when testing an RCU-protected pointer against | ||
| 261 | * NULL. This may also be used in cases where update-side locks prevent | ||
| 262 | * the value of the pointer from changing, but rcu_dereference_protected() | ||
| 263 | * is a lighter-weight primitive for this use case. | ||
| 264 | */ | ||
| 265 | #define rcu_access_pointer(p) ACCESS_ONCE(p) | ||
| 95 | 266 | ||
| 96 | /** | 267 | /** |
| 97 | * rcu_read_lock - mark the beginning of an RCU read-side critical section. | 268 | * rcu_read_lock - mark the beginning of an RCU read-side critical section. |
| @@ -166,7 +337,7 @@ static inline void rcu_read_lock_bh(void) | |||
| 166 | { | 337 | { |
| 167 | __rcu_read_lock_bh(); | 338 | __rcu_read_lock_bh(); |
| 168 | __acquire(RCU_BH); | 339 | __acquire(RCU_BH); |
| 169 | rcu_read_acquire(); | 340 | rcu_read_acquire_bh(); |
| 170 | } | 341 | } |
| 171 | 342 | ||
| 172 | /* | 343 | /* |
| @@ -176,7 +347,7 @@ static inline void rcu_read_lock_bh(void) | |||
| 176 | */ | 347 | */ |
| 177 | static inline void rcu_read_unlock_bh(void) | 348 | static inline void rcu_read_unlock_bh(void) |
| 178 | { | 349 | { |
| 179 | rcu_read_release(); | 350 | rcu_read_release_bh(); |
| 180 | __release(RCU_BH); | 351 | __release(RCU_BH); |
| 181 | __rcu_read_unlock_bh(); | 352 | __rcu_read_unlock_bh(); |
| 182 | } | 353 | } |
| @@ -194,7 +365,7 @@ static inline void rcu_read_lock_sched(void) | |||
| 194 | { | 365 | { |
| 195 | preempt_disable(); | 366 | preempt_disable(); |
| 196 | __acquire(RCU_SCHED); | 367 | __acquire(RCU_SCHED); |
| 197 | rcu_read_acquire(); | 368 | rcu_read_acquire_sched(); |
| 198 | } | 369 | } |
| 199 | 370 | ||
| 200 | /* Used by lockdep and tracing: cannot be traced, cannot call lockdep. */ | 371 | /* Used by lockdep and tracing: cannot be traced, cannot call lockdep. */ |
| @@ -211,7 +382,7 @@ static inline notrace void rcu_read_lock_sched_notrace(void) | |||
| 211 | */ | 382 | */ |
| 212 | static inline void rcu_read_unlock_sched(void) | 383 | static inline void rcu_read_unlock_sched(void) |
| 213 | { | 384 | { |
| 214 | rcu_read_release(); | 385 | rcu_read_release_sched(); |
| 215 | __release(RCU_SCHED); | 386 | __release(RCU_SCHED); |
| 216 | preempt_enable(); | 387 | preempt_enable(); |
| 217 | } | 388 | } |
| @@ -225,22 +396,49 @@ static inline notrace void rcu_read_unlock_sched_notrace(void) | |||
| 225 | 396 | ||
| 226 | 397 | ||
| 227 | /** | 398 | /** |
| 228 | * rcu_dereference - fetch an RCU-protected pointer in an | 399 | * rcu_dereference_raw - fetch an RCU-protected pointer |
| 229 | * RCU read-side critical section. This pointer may later | 400 | * |
| 230 | * be safely dereferenced. | 401 | * The caller must be within some flavor of RCU read-side critical |
| 402 | * section, or must be otherwise preventing the pointer from changing, | ||
| 403 | * for example, by holding an appropriate lock. This pointer may later | ||
| 404 | * be safely dereferenced. It is the caller's responsibility to have | ||
| 405 | * done the right thing, as this primitive does no checking of any kind. | ||
| 231 | * | 406 | * |
| 232 | * Inserts memory barriers on architectures that require them | 407 | * Inserts memory barriers on architectures that require them |
| 233 | * (currently only the Alpha), and, more importantly, documents | 408 | * (currently only the Alpha), and, more importantly, documents |
| 234 | * exactly which pointers are protected by RCU. | 409 | * exactly which pointers are protected by RCU. |
| 235 | */ | 410 | */ |
| 236 | 411 | #define rcu_dereference_raw(p) ({ \ | |
| 237 | #define rcu_dereference(p) ({ \ | ||
| 238 | typeof(p) _________p1 = ACCESS_ONCE(p); \ | 412 | typeof(p) _________p1 = ACCESS_ONCE(p); \ |
| 239 | smp_read_barrier_depends(); \ | 413 | smp_read_barrier_depends(); \ |
| 240 | (_________p1); \ | 414 | (_________p1); \ |
| 241 | }) | 415 | }) |
| 242 | 416 | ||
| 243 | /** | 417 | /** |
| 418 | * rcu_dereference - fetch an RCU-protected pointer, checking for RCU | ||
| 419 | * | ||
| 420 | * Makes rcu_dereference_check() do the dirty work. | ||
| 421 | */ | ||
| 422 | #define rcu_dereference(p) \ | ||
| 423 | rcu_dereference_check(p, rcu_read_lock_held()) | ||
| 424 | |||
| 425 | /** | ||
| 426 | * rcu_dereference_bh - fetch an RCU-protected pointer, checking for RCU-bh | ||
| 427 | * | ||
| 428 | * Makes rcu_dereference_check() do the dirty work. | ||
| 429 | */ | ||
| 430 | #define rcu_dereference_bh(p) \ | ||
| 431 | rcu_dereference_check(p, rcu_read_lock_bh_held()) | ||
| 432 | |||
| 433 | /** | ||
| 434 | * rcu_dereference_sched - fetch RCU-protected pointer, checking for RCU-sched | ||
| 435 | * | ||
| 436 | * Makes rcu_dereference_check() do the dirty work. | ||
| 437 | */ | ||
| 438 | #define rcu_dereference_sched(p) \ | ||
| 439 | rcu_dereference_check(p, rcu_read_lock_sched_held()) | ||
| 440 | |||
| 441 | /** | ||
| 244 | * rcu_assign_pointer - assign (publicize) a pointer to a newly | 442 | * rcu_assign_pointer - assign (publicize) a pointer to a newly |
| 245 | * initialized structure that will be dereferenced by RCU read-side | 443 | * initialized structure that will be dereferenced by RCU read-side |
| 246 | * critical sections. Returns the value assigned. | 444 | * critical sections. Returns the value assigned. |
