aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/rcupdate.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/rcupdate.h')
-rw-r--r--include/linux/rcupdate.h334
1 files changed, 317 insertions, 17 deletions
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index 24440f4bf476..83af1f8d8b74 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -40,6 +40,11 @@
40#include <linux/seqlock.h> 40#include <linux/seqlock.h>
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>
44
45#ifdef CONFIG_RCU_TORTURE_TEST
46extern int rcutorture_runnable; /* for sysctl */
47#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
43 48
44/** 49/**
45 * struct rcu_head - callback structure for use with RCU 50 * struct rcu_head - callback structure for use with RCU
@@ -52,8 +57,6 @@ struct rcu_head {
52}; 57};
53 58
54/* Exported common interfaces */ 59/* Exported common interfaces */
55extern void synchronize_rcu_bh(void);
56extern void synchronize_sched(void);
57extern void rcu_barrier(void); 60extern void rcu_barrier(void);
58extern void rcu_barrier_bh(void); 61extern void rcu_barrier_bh(void);
59extern void rcu_barrier_sched(void); 62extern void rcu_barrier_sched(void);
@@ -77,15 +80,215 @@ extern void rcu_init(void);
77 (ptr)->next = NULL; (ptr)->func = NULL; \ 80 (ptr)->next = NULL; (ptr)->func = NULL; \
78} while (0) 81} while (0)
79 82
83/*
84 * init_rcu_head_on_stack()/destroy_rcu_head_on_stack() are needed for dynamic
85 * initialization and destruction of rcu_head on the stack. rcu_head structures
86 * allocated dynamically in the heap or defined statically don't need any
87 * initialization.
88 */
89#ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
90extern void init_rcu_head_on_stack(struct rcu_head *head);
91extern void destroy_rcu_head_on_stack(struct rcu_head *head);
92#else /* !CONFIG_DEBUG_OBJECTS_RCU_HEAD */
93static inline void init_rcu_head_on_stack(struct rcu_head *head)
94{
95}
96
97static inline void destroy_rcu_head_on_stack(struct rcu_head *head)
98{
99}
100#endif /* #else !CONFIG_DEBUG_OBJECTS_RCU_HEAD */
101
80#ifdef CONFIG_DEBUG_LOCK_ALLOC 102#ifdef CONFIG_DEBUG_LOCK_ALLOC
103
81extern struct lockdep_map rcu_lock_map; 104extern struct lockdep_map rcu_lock_map;
82# define rcu_read_acquire() \ 105# define rcu_read_acquire() \
83 lock_acquire(&rcu_lock_map, 0, 0, 2, 1, NULL, _THIS_IP_) 106 lock_acquire(&rcu_lock_map, 0, 0, 2, 1, NULL, _THIS_IP_)
84# define rcu_read_release() lock_release(&rcu_lock_map, 1, _THIS_IP_) 107# define rcu_read_release() lock_release(&rcu_lock_map, 1, _THIS_IP_)
85#else 108
86# define rcu_read_acquire() do { } while (0) 109extern struct lockdep_map rcu_bh_lock_map;
87# define rcu_read_release() do { } while (0) 110# define rcu_read_acquire_bh() \
88#endif 111 lock_acquire(&rcu_bh_lock_map, 0, 0, 2, 1, NULL, _THIS_IP_)
112# define rcu_read_release_bh() lock_release(&rcu_bh_lock_map, 1, _THIS_IP_)
113
114extern struct lockdep_map rcu_sched_lock_map;
115# define rcu_read_acquire_sched() \
116 lock_acquire(&rcu_sched_lock_map, 0, 0, 2, 1, NULL, _THIS_IP_)
117# define rcu_read_release_sched() \
118 lock_release(&rcu_sched_lock_map, 1, _THIS_IP_)
119
120extern int debug_lockdep_rcu_enabled(void);
121
122/**
123 * rcu_read_lock_held - might we be in RCU read-side critical section?
124 *
125 * 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 * this assumes we are in an RCU read-side critical section unless it can
128 * prove otherwise.
129 *
130 * Check debug_lockdep_rcu_enabled() to prevent false positives during boot
131 * and while lockdep is disabled.
132 */
133static inline int rcu_read_lock_held(void)
134{
135 if (!debug_lockdep_rcu_enabled())
136 return 1;
137 return lock_is_held(&rcu_lock_map);
138}
139
140/*
141 * rcu_read_lock_bh_held() is defined out of line to avoid #include-file
142 * hell.
143 */
144extern int rcu_read_lock_bh_held(void);
145
146/**
147 * rcu_read_lock_sched_held - might we be in RCU-sched read-side critical section?
148 *
149 * If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an
150 * RCU-sched read-side critical section. In absence of
151 * 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
153 * of preemption (including disabling irqs) counts as an RCU-sched
154 * read-side critical section.
155 *
156 * Check debug_lockdep_rcu_enabled() to prevent false positives during boot
157 * and while lockdep is disabled.
158 */
159#ifdef CONFIG_PREEMPT
160static inline int rcu_read_lock_sched_held(void)
161{
162 int lockdep_opinion = 0;
163
164 if (!debug_lockdep_rcu_enabled())
165 return 1;
166 if (debug_locks)
167 lockdep_opinion = lock_is_held(&rcu_sched_lock_map);
168 return lockdep_opinion || preempt_count() != 0 || irqs_disabled();
169}
170#else /* #ifdef CONFIG_PREEMPT */
171static inline int rcu_read_lock_sched_held(void)
172{
173 return 1;
174}
175#endif /* #else #ifdef CONFIG_PREEMPT */
176
177#else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
178
179# define rcu_read_acquire() do { } while (0)
180# define rcu_read_release() do { } while (0)
181# define rcu_read_acquire_bh() do { } while (0)
182# define rcu_read_release_bh() do { } while (0)
183# define rcu_read_acquire_sched() do { } while (0)
184# define rcu_read_release_sched() do { } while (0)
185
186static inline int rcu_read_lock_held(void)
187{
188 return 1;
189}
190
191static inline int rcu_read_lock_bh_held(void)
192{
193 return 1;
194}
195
196#ifdef CONFIG_PREEMPT
197static inline int rcu_read_lock_sched_held(void)
198{
199 return preempt_count() != 0 || irqs_disabled();
200}
201#else /* #ifdef CONFIG_PREEMPT */
202static inline int rcu_read_lock_sched_held(void)
203{
204 return 1;
205}
206#endif /* #else #ifdef CONFIG_PREEMPT */
207
208#endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */
209
210#ifdef CONFIG_PROVE_RCU
211
212extern int rcu_my_thread_group_empty(void);
213
214#define __do_rcu_dereference_check(c) \
215 do { \
216 static bool __warned; \
217 if (debug_lockdep_rcu_enabled() && !__warned && !(c)) { \
218 __warned = true; \
219 lockdep_rcu_dereference(__FILE__, __LINE__); \
220 } \
221 } while (0)
222
223/**
224 * rcu_dereference_check - rcu_dereference with debug checking
225 * @p: The pointer to read, prior to dereferencing
226 * @c: The conditions under which the dereference will take place
227 *
228 * Do an rcu_dereference(), but check that the conditions under which the
229 * dereference will take place are correct. Typically the conditions indicate
230 * the various locking conditions that should be held at that point. The check
231 * should return true if the conditions are satisfied.
232 *
233 * For example:
234 *
235 * bar = rcu_dereference_check(foo->bar, rcu_read_lock_held() ||
236 * lockdep_is_held(&foo->lock));
237 *
238 * 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
240 * the bar struct at foo->bar is held.
241 *
242 * 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
244 * target struct:
245 *
246 * bar = rcu_dereference_check(foo->bar, rcu_read_lock_held() ||
247 * lockdep_is_held(&foo->lock) ||
248 * atomic_read(&foo->usage) == 0);
249 */
250#define rcu_dereference_check(p, c) \
251 ({ \
252 __do_rcu_dereference_check(c); \
253 rcu_dereference_raw(p); \
254 })
255
256/**
257 * rcu_dereference_protected - fetch RCU pointer when updates prevented
258 *
259 * Return the value of the specified RCU-protected pointer, but omit
260 * both the smp_read_barrier_depends() and the ACCESS_ONCE(). This
261 * is useful in cases where update-side locks prevent the value of the
262 * pointer from changing. Please note that this primitive does -not-
263 * prevent the compiler from repeating this reference or combining it
264 * with other references, so it should not be used without protection
265 * of appropriate locks.
266 */
267#define rcu_dereference_protected(p, c) \
268 ({ \
269 __do_rcu_dereference_check(c); \
270 (p); \
271 })
272
273#else /* #ifdef CONFIG_PROVE_RCU */
274
275#define rcu_dereference_check(p, c) rcu_dereference_raw(p)
276#define rcu_dereference_protected(p, c) (p)
277
278#endif /* #else #ifdef CONFIG_PROVE_RCU */
279
280/**
281 * rcu_access_pointer - fetch RCU pointer with no dereferencing
282 *
283 * Return the value of the specified RCU-protected pointer, but omit the
284 * smp_read_barrier_depends() and keep the ACCESS_ONCE(). This is useful
285 * when the value of this pointer is accessed, but the pointer is not
286 * dereferenced, for example, when testing an RCU-protected pointer against
287 * NULL. This may also be used in cases where update-side locks prevent
288 * the value of the pointer from changing, but rcu_dereference_protected()
289 * is a lighter-weight primitive for this use case.
290 */
291#define rcu_access_pointer(p) ACCESS_ONCE(p)
89 292
90/** 293/**
91 * rcu_read_lock - mark the beginning of an RCU read-side critical section. 294 * rcu_read_lock - mark the beginning of an RCU read-side critical section.
@@ -160,7 +363,7 @@ static inline void rcu_read_lock_bh(void)
160{ 363{
161 __rcu_read_lock_bh(); 364 __rcu_read_lock_bh();
162 __acquire(RCU_BH); 365 __acquire(RCU_BH);
163 rcu_read_acquire(); 366 rcu_read_acquire_bh();
164} 367}
165 368
166/* 369/*
@@ -170,7 +373,7 @@ static inline void rcu_read_lock_bh(void)
170 */ 373 */
171static inline void rcu_read_unlock_bh(void) 374static inline void rcu_read_unlock_bh(void)
172{ 375{
173 rcu_read_release(); 376 rcu_read_release_bh();
174 __release(RCU_BH); 377 __release(RCU_BH);
175 __rcu_read_unlock_bh(); 378 __rcu_read_unlock_bh();
176} 379}
@@ -188,7 +391,7 @@ static inline void rcu_read_lock_sched(void)
188{ 391{
189 preempt_disable(); 392 preempt_disable();
190 __acquire(RCU_SCHED); 393 __acquire(RCU_SCHED);
191 rcu_read_acquire(); 394 rcu_read_acquire_sched();
192} 395}
193 396
194/* Used by lockdep and tracing: cannot be traced, cannot call lockdep. */ 397/* Used by lockdep and tracing: cannot be traced, cannot call lockdep. */
@@ -205,7 +408,7 @@ static inline notrace void rcu_read_lock_sched_notrace(void)
205 */ 408 */
206static inline void rcu_read_unlock_sched(void) 409static inline void rcu_read_unlock_sched(void)
207{ 410{
208 rcu_read_release(); 411 rcu_read_release_sched();
209 __release(RCU_SCHED); 412 __release(RCU_SCHED);
210 preempt_enable(); 413 preempt_enable();
211} 414}
@@ -219,22 +422,49 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
219 422
220 423
221/** 424/**
222 * rcu_dereference - fetch an RCU-protected pointer in an 425 * rcu_dereference_raw - fetch an RCU-protected pointer
223 * RCU read-side critical section. This pointer may later 426 *
224 * be safely dereferenced. 427 * The caller must be within some flavor of RCU read-side critical
428 * section, or must be otherwise preventing the pointer from changing,
429 * for example, by holding an appropriate lock. This pointer may later
430 * be safely dereferenced. It is the caller's responsibility to have
431 * done the right thing, as this primitive does no checking of any kind.
225 * 432 *
226 * Inserts memory barriers on architectures that require them 433 * Inserts memory barriers on architectures that require them
227 * (currently only the Alpha), and, more importantly, documents 434 * (currently only the Alpha), and, more importantly, documents
228 * exactly which pointers are protected by RCU. 435 * exactly which pointers are protected by RCU.
229 */ 436 */
230 437#define rcu_dereference_raw(p) ({ \
231#define rcu_dereference(p) ({ \
232 typeof(p) _________p1 = ACCESS_ONCE(p); \ 438 typeof(p) _________p1 = ACCESS_ONCE(p); \
233 smp_read_barrier_depends(); \ 439 smp_read_barrier_depends(); \
234 (_________p1); \ 440 (_________p1); \
235 }) 441 })
236 442
237/** 443/**
444 * rcu_dereference - fetch an RCU-protected pointer, checking for RCU
445 *
446 * Makes rcu_dereference_check() do the dirty work.
447 */
448#define rcu_dereference(p) \
449 rcu_dereference_check(p, rcu_read_lock_held())
450
451/**
452 * rcu_dereference_bh - fetch an RCU-protected pointer, checking for RCU-bh
453 *
454 * Makes rcu_dereference_check() do the dirty work.
455 */
456#define rcu_dereference_bh(p) \
457 rcu_dereference_check(p, rcu_read_lock_bh_held() || irqs_disabled())
458
459/**
460 * rcu_dereference_sched - fetch RCU-protected pointer, checking for RCU-sched
461 *
462 * Makes rcu_dereference_check() do the dirty work.
463 */
464#define rcu_dereference_sched(p) \
465 rcu_dereference_check(p, rcu_read_lock_sched_held())
466
467/**
238 * rcu_assign_pointer - assign (publicize) a pointer to a newly 468 * rcu_assign_pointer - assign (publicize) a pointer to a newly
239 * initialized structure that will be dereferenced by RCU read-side 469 * initialized structure that will be dereferenced by RCU read-side
240 * critical sections. Returns the value assigned. 470 * critical sections. Returns the value assigned.
@@ -299,4 +529,74 @@ extern void call_rcu(struct rcu_head *head,
299extern void call_rcu_bh(struct rcu_head *head, 529extern void call_rcu_bh(struct rcu_head *head,
300 void (*func)(struct rcu_head *head)); 530 void (*func)(struct rcu_head *head));
301 531
532/*
533 * debug_rcu_head_queue()/debug_rcu_head_unqueue() are used internally
534 * by call_rcu() and rcu callback execution, and are therefore not part of the
535 * RCU API. Leaving in rcupdate.h because they are used by all RCU flavors.
536 */
537
538#ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
539# define STATE_RCU_HEAD_READY 0
540# define STATE_RCU_HEAD_QUEUED 1
541
542extern struct debug_obj_descr rcuhead_debug_descr;
543
544static inline void debug_rcu_head_queue(struct rcu_head *head)
545{
546 debug_object_activate(head, &rcuhead_debug_descr);
547 debug_object_active_state(head, &rcuhead_debug_descr,
548 STATE_RCU_HEAD_READY,
549 STATE_RCU_HEAD_QUEUED);
550}
551
552static inline void debug_rcu_head_unqueue(struct rcu_head *head)
553{
554 debug_object_active_state(head, &rcuhead_debug_descr,
555 STATE_RCU_HEAD_QUEUED,
556 STATE_RCU_HEAD_READY);
557 debug_object_deactivate(head, &rcuhead_debug_descr);
558}
559#else /* !CONFIG_DEBUG_OBJECTS_RCU_HEAD */
560static inline void debug_rcu_head_queue(struct rcu_head *head)
561{
562}
563
564static inline void debug_rcu_head_unqueue(struct rcu_head *head)
565{
566}
567#endif /* #else !CONFIG_DEBUG_OBJECTS_RCU_HEAD */
568
569#ifndef CONFIG_PROVE_RCU
570#define __do_rcu_dereference_check(c) do { } while (0)
571#endif /* #ifdef CONFIG_PROVE_RCU */
572
573#define __rcu_dereference_index_check(p, c) \
574 ({ \
575 typeof(p) _________p1 = ACCESS_ONCE(p); \
576 __do_rcu_dereference_check(c); \
577 smp_read_barrier_depends(); \
578 (_________p1); \
579 })
580
581/**
582 * rcu_dereference_index_check() - rcu_dereference for indices with debug checking
583 * @p: The pointer to read, prior to dereferencing
584 * @c: The conditions under which the dereference will take place
585 *
586 * Similar to rcu_dereference_check(), but omits the sparse checking.
587 * This allows rcu_dereference_index_check() to be used on integers,
588 * which can then be used as array indices. Attempting to use
589 * rcu_dereference_check() on an integer will give compiler warnings
590 * because the sparse address-space mechanism relies on dereferencing
591 * the RCU-protected pointer. Dereferencing integers is not something
592 * that even gcc will put up with.
593 *
594 * Note that this function does not implicitly check for RCU read-side
595 * critical sections. If this function gains lots of uses, it might
596 * make sense to provide versions for each flavor of RCU, but it does
597 * not make sense as of early 2010.
598 */
599#define rcu_dereference_index_check(p, c) \
600 __rcu_dereference_index_check((p), (c))
601
302#endif /* __LINUX_RCUPDATE_H */ 602#endif /* __LINUX_RCUPDATE_H */