diff options
| -rw-r--r-- | include/linux/compiler.h | 4 | ||||
| -rw-r--r-- | include/linux/rcupdate.h | 352 | ||||
| -rw-r--r-- | include/linux/srcu.h | 27 | ||||
| -rw-r--r-- | kernel/rcupdate.c | 6 | ||||
| -rw-r--r-- | lib/Kconfig.debug | 13 |
5 files changed, 257 insertions, 145 deletions
diff --git a/include/linux/compiler.h b/include/linux/compiler.h index c1a62c56a660..320d6c94ff84 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h | |||
| @@ -16,7 +16,11 @@ | |||
| 16 | # define __release(x) __context__(x,-1) | 16 | # define __release(x) __context__(x,-1) |
| 17 | # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0) | 17 | # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0) |
| 18 | # define __percpu __attribute__((noderef, address_space(3))) | 18 | # define __percpu __attribute__((noderef, address_space(3))) |
| 19 | #ifdef CONFIG_SPARSE_RCU_POINTER | ||
| 20 | # define __rcu __attribute__((noderef, address_space(4))) | ||
| 21 | #else | ||
| 19 | # define __rcu | 22 | # define __rcu |
| 23 | #endif | ||
| 20 | extern void __chk_user_ptr(const volatile void __user *); | 24 | extern void __chk_user_ptr(const volatile void __user *); |
| 21 | extern void __chk_io_ptr(const volatile void __iomem *); | 25 | extern void __chk_io_ptr(const volatile void __iomem *); |
| 22 | #else | 26 | #else |
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h index 9fbc54a2585d..b973dea2d6b0 100644 --- a/include/linux/rcupdate.h +++ b/include/linux/rcupdate.h | |||
| @@ -41,6 +41,7 @@ | |||
| 41 | #include <linux/lockdep.h> | 41 | #include <linux/lockdep.h> |
| 42 | #include <linux/completion.h> | 42 | #include <linux/completion.h> |
| 43 | #include <linux/debugobjects.h> | 43 | #include <linux/debugobjects.h> |
| 44 | #include <linux/compiler.h> | ||
| 44 | 45 | ||
| 45 | #ifdef CONFIG_RCU_TORTURE_TEST | 46 | #ifdef CONFIG_RCU_TORTURE_TEST |
| 46 | extern int rcutorture_runnable; /* for sysctl */ | 47 | extern int rcutorture_runnable; /* for sysctl */ |
| @@ -120,14 +121,15 @@ extern struct lockdep_map rcu_sched_lock_map; | |||
| 120 | extern int debug_lockdep_rcu_enabled(void); | 121 | extern int debug_lockdep_rcu_enabled(void); |
| 121 | 122 | ||
| 122 | /** | 123 | /** |
| 123 | * rcu_read_lock_held - might we be in RCU read-side critical section? | 124 | * rcu_read_lock_held() - might we be in RCU read-side critical section? |
| 124 | * | 125 | * |
| 125 | * If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an RCU | 126 | * If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an RCU |
| 126 | * read-side critical section. In absence of CONFIG_DEBUG_LOCK_ALLOC, | 127 | * read-side critical section. In absence of CONFIG_DEBUG_LOCK_ALLOC, |
| 127 | * this assumes we are in an RCU read-side critical section unless it can | 128 | * this assumes we are in an RCU read-side critical section unless it can |
| 128 | * prove otherwise. | 129 | * prove otherwise. This is useful for debug checks in functions that |
| 130 | * require that they be called within an RCU read-side critical section. | ||
| 129 | * | 131 | * |
| 130 | * Check debug_lockdep_rcu_enabled() to prevent false positives during boot | 132 | * Checks debug_lockdep_rcu_enabled() to prevent false positives during boot |
| 131 | * and while lockdep is disabled. | 133 | * and while lockdep is disabled. |
| 132 | */ | 134 | */ |
| 133 | static inline int rcu_read_lock_held(void) | 135 | static inline int rcu_read_lock_held(void) |
| @@ -144,14 +146,16 @@ static inline int rcu_read_lock_held(void) | |||
| 144 | extern int rcu_read_lock_bh_held(void); | 146 | extern int rcu_read_lock_bh_held(void); |
| 145 | 147 | ||
| 146 | /** | 148 | /** |
| 147 | * rcu_read_lock_sched_held - might we be in RCU-sched read-side critical section? | 149 | * rcu_read_lock_sched_held() - might we be in RCU-sched read-side critical section? |
| 148 | * | 150 | * |
| 149 | * If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an | 151 | * If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an |
| 150 | * RCU-sched read-side critical section. In absence of | 152 | * RCU-sched read-side critical section. In absence of |
| 151 | * CONFIG_DEBUG_LOCK_ALLOC, this assumes we are in an RCU-sched read-side | 153 | * CONFIG_DEBUG_LOCK_ALLOC, this assumes we are in an RCU-sched read-side |
| 152 | * critical section unless it can prove otherwise. Note that disabling | 154 | * critical section unless it can prove otherwise. Note that disabling |
| 153 | * of preemption (including disabling irqs) counts as an RCU-sched | 155 | * of preemption (including disabling irqs) counts as an RCU-sched |
| 154 | * read-side critical section. | 156 | * read-side critical section. This is useful for debug checks in functions |
| 157 | * that required that they be called within an RCU-sched read-side | ||
| 158 | * critical section. | ||
| 155 | * | 159 | * |
| 156 | * Check debug_lockdep_rcu_enabled() to prevent false positives during boot | 160 | * Check debug_lockdep_rcu_enabled() to prevent false positives during boot |
| 157 | * and while lockdep is disabled. | 161 | * and while lockdep is disabled. |
| @@ -220,41 +224,155 @@ extern int rcu_my_thread_group_empty(void); | |||
| 220 | } \ | 224 | } \ |
| 221 | } while (0) | 225 | } while (0) |
| 222 | 226 | ||
| 227 | #else /* #ifdef CONFIG_PROVE_RCU */ | ||
| 228 | |||
| 229 | #define __do_rcu_dereference_check(c) do { } while (0) | ||
| 230 | |||
| 231 | #endif /* #else #ifdef CONFIG_PROVE_RCU */ | ||
| 232 | |||
| 233 | /* | ||
| 234 | * Helper functions for rcu_dereference_check(), rcu_dereference_protected() | ||
| 235 | * and rcu_assign_pointer(). Some of these could be folded into their | ||
| 236 | * callers, but they are left separate in order to ease introduction of | ||
| 237 | * multiple flavors of pointers to match the multiple flavors of RCU | ||
| 238 | * (e.g., __rcu_bh, * __rcu_sched, and __srcu), should this make sense in | ||
| 239 | * the future. | ||
| 240 | */ | ||
| 241 | #define __rcu_access_pointer(p, space) \ | ||
| 242 | ({ \ | ||
| 243 | typeof(*p) *_________p1 = (typeof(*p)*__force )ACCESS_ONCE(p); \ | ||
| 244 | (void) (((typeof (*p) space *)p) == p); \ | ||
| 245 | ((typeof(*p) __force __kernel *)(_________p1)); \ | ||
| 246 | }) | ||
| 247 | #define __rcu_dereference_check(p, c, space) \ | ||
| 248 | ({ \ | ||
| 249 | typeof(*p) *_________p1 = (typeof(*p)*__force )ACCESS_ONCE(p); \ | ||
| 250 | __do_rcu_dereference_check(c); \ | ||
| 251 | (void) (((typeof (*p) space *)p) == p); \ | ||
| 252 | smp_read_barrier_depends(); \ | ||
| 253 | ((typeof(*p) __force __kernel *)(_________p1)); \ | ||
| 254 | }) | ||
| 255 | #define __rcu_dereference_protected(p, c, space) \ | ||
| 256 | ({ \ | ||
| 257 | __do_rcu_dereference_check(c); \ | ||
| 258 | (void) (((typeof (*p) space *)p) == p); \ | ||
| 259 | ((typeof(*p) __force __kernel *)(p)); \ | ||
| 260 | }) | ||
| 261 | |||
| 262 | #define __rcu_dereference_index_check(p, c) \ | ||
| 263 | ({ \ | ||
| 264 | typeof(p) _________p1 = ACCESS_ONCE(p); \ | ||
| 265 | __do_rcu_dereference_check(c); \ | ||
| 266 | smp_read_barrier_depends(); \ | ||
| 267 | (_________p1); \ | ||
| 268 | }) | ||
| 269 | #define __rcu_assign_pointer(p, v, space) \ | ||
| 270 | ({ \ | ||
| 271 | if (!__builtin_constant_p(v) || \ | ||
| 272 | ((v) != NULL)) \ | ||
| 273 | smp_wmb(); \ | ||
| 274 | (p) = (typeof(*v) __force space *)(v); \ | ||
| 275 | }) | ||
| 276 | |||
| 277 | |||
| 278 | /** | ||
| 279 | * rcu_access_pointer() - fetch RCU pointer with no dereferencing | ||
| 280 | * @p: The pointer to read | ||
| 281 | * | ||
| 282 | * Return the value of the specified RCU-protected pointer, but omit the | ||
| 283 | * smp_read_barrier_depends() and keep the ACCESS_ONCE(). This is useful | ||
| 284 | * when the value of this pointer is accessed, but the pointer is not | ||
| 285 | * dereferenced, for example, when testing an RCU-protected pointer against | ||
| 286 | * NULL. Although rcu_access_pointer() may also be used in cases where | ||
| 287 | * update-side locks prevent the value of the pointer from changing, you | ||
| 288 | * should instead use rcu_dereference_protected() for this use case. | ||
| 289 | */ | ||
| 290 | #define rcu_access_pointer(p) __rcu_access_pointer((p), __rcu) | ||
| 291 | |||
| 223 | /** | 292 | /** |
| 224 | * rcu_dereference_check - rcu_dereference with debug checking | 293 | * rcu_dereference_check() - rcu_dereference with debug checking |
| 225 | * @p: The pointer to read, prior to dereferencing | 294 | * @p: The pointer to read, prior to dereferencing |
| 226 | * @c: The conditions under which the dereference will take place | 295 | * @c: The conditions under which the dereference will take place |
| 227 | * | 296 | * |
| 228 | * Do an rcu_dereference(), but check that the conditions under which the | 297 | * Do an rcu_dereference(), but check that the conditions under which the |
| 229 | * dereference will take place are correct. Typically the conditions indicate | 298 | * dereference will take place are correct. Typically the conditions |
| 230 | * the various locking conditions that should be held at that point. The check | 299 | * indicate the various locking conditions that should be held at that |
| 231 | * should return true if the conditions are satisfied. | 300 | * point. The check should return true if the conditions are satisfied. |
| 301 | * An implicit check for being in an RCU read-side critical section | ||
| 302 | * (rcu_read_lock()) is included. | ||
| 232 | * | 303 | * |
| 233 | * For example: | 304 | * For example: |
| 234 | * | 305 | * |
| 235 | * bar = rcu_dereference_check(foo->bar, rcu_read_lock_held() || | 306 | * bar = rcu_dereference_check(foo->bar, lockdep_is_held(&foo->lock)); |
| 236 | * lockdep_is_held(&foo->lock)); | ||
| 237 | * | 307 | * |
| 238 | * could be used to indicate to lockdep that foo->bar may only be dereferenced | 308 | * could be used to indicate to lockdep that foo->bar may only be dereferenced |
| 239 | * if either the RCU read lock is held, or that the lock required to replace | 309 | * if either rcu_read_lock() is held, or that the lock required to replace |
| 240 | * the bar struct at foo->bar is held. | 310 | * the bar struct at foo->bar is held. |
| 241 | * | 311 | * |
| 242 | * Note that the list of conditions may also include indications of when a lock | 312 | * Note that the list of conditions may also include indications of when a lock |
| 243 | * need not be held, for example during initialisation or destruction of the | 313 | * need not be held, for example during initialisation or destruction of the |
| 244 | * target struct: | 314 | * target struct: |
| 245 | * | 315 | * |
| 246 | * bar = rcu_dereference_check(foo->bar, rcu_read_lock_held() || | 316 | * bar = rcu_dereference_check(foo->bar, lockdep_is_held(&foo->lock) || |
| 247 | * lockdep_is_held(&foo->lock) || | ||
| 248 | * atomic_read(&foo->usage) == 0); | 317 | * atomic_read(&foo->usage) == 0); |
| 318 | * | ||
