aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2010-04-19 11:35:47 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-04-19 11:35:47 -0400
commit85341c61361cc45a9cc0e11c01e8f4479ef460ac (patch)
tree8d5e8e98aaef7f77f9749d851dd409ac356f0258 /include
parent375db4810b27306ea400ab39d3d6f7a063ac9ff6 (diff)
parentbc293d62b26ec590afc90a9e0a31c45d355b7bd8 (diff)
Merge branch 'core-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'core-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: rcu: Make RCU lockdep check the lockdep_recursion variable rcu: Update docs for rcu_access_pointer and rcu_dereference_protected rcu: Better explain the condition parameter of rcu_dereference_check() rcu: Add rcu_access_pointer and rcu_dereference_protected
Diffstat (limited to 'include')
-rw-r--r--include/linux/rcupdate.h65
1 files changed, 56 insertions, 9 deletions
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index 872a98e13d6a..07db2feb8572 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -101,10 +101,7 @@ extern struct lockdep_map rcu_sched_lock_map;
101# define rcu_read_release_sched() \ 101# define rcu_read_release_sched() \
102 lock_release(&rcu_sched_lock_map, 1, _THIS_IP_) 102 lock_release(&rcu_sched_lock_map, 1, _THIS_IP_)
103 103
104static inline int debug_lockdep_rcu_enabled(void) 104extern int debug_lockdep_rcu_enabled(void);
105{
106 return likely(rcu_scheduler_active && debug_locks);
107}
108 105
109/** 106/**
110 * rcu_read_lock_held - might we be in RCU read-side critical section? 107 * rcu_read_lock_held - might we be in RCU read-side critical section?
@@ -195,12 +192,30 @@ static inline int rcu_read_lock_sched_held(void)
195 192
196/** 193/**
197 * rcu_dereference_check - rcu_dereference with debug checking 194 * rcu_dereference_check - rcu_dereference with debug checking
195 * @p: The pointer to read, prior to dereferencing
196 * @c: The conditions under which the dereference will take place
197 *
198 * Do an rcu_dereference(), but check that the conditions under which the
199 * dereference will take place are correct. Typically the conditions indicate
200 * the various locking conditions that should be held at that point. The check
201 * should return true if the conditions are satisfied.
202 *
203 * For example:
204 *
205 * bar = rcu_dereference_check(foo->bar, rcu_read_lock_held() ||
206 * lockdep_is_held(&foo->lock));
198 * 207 *
199 * Do an rcu_dereference(), but check that the context is correct. 208 * could be used to indicate to lockdep that foo->bar may only be dereferenced
200 * For example, rcu_dereference_check(gp, rcu_read_lock_held()) to 209 * if either the RCU read lock is held, or that the lock required to replace
201 * ensure that the rcu_dereference_check() executes within an RCU 210 * the bar struct at foo->bar is held.
202 * read-side critical section. It is also possible to check for 211 *
203 * locks being held, for example, by using lockdep_is_held(). 212 * Note that the list of conditions may also include indications of when a lock
213 * need not be held, for example during initialisation or destruction of the
214 * target struct:
215 *
216 * bar = rcu_dereference_check(foo->bar, rcu_read_lock_held() ||
217 * lockdep_is_held(&foo->lock) ||
218 * atomic_read(&foo->usage) == 0);
204 */ 219 */
205#define rcu_dereference_check(p, c) \ 220#define rcu_dereference_check(p, c) \
206 ({ \ 221 ({ \
@@ -209,13 +224,45 @@ static inline int rcu_read_lock_sched_held(void)
209 rcu_dereference_raw(p); \ 224 rcu_dereference_raw(p); \
210 }) 225 })
211 226
227/**
228 * rcu_dereference_protected - fetch RCU pointer when updates prevented
229 *
230 * Return the value of the specified RCU-protected pointer, but omit
231 * both the smp_read_barrier_depends() and the ACCESS_ONCE(). This
232 * is useful in cases where update-side locks prevent the value of the
233 * pointer from changing. Please note that this primitive does -not-
234 * prevent the compiler from repeating this reference or combining it
235 * with other references, so it should not be used without protection
236 * of appropriate locks.
237 */
238#define rcu_dereference_protected(p, c) \
239 ({ \
240 if (debug_lockdep_rcu_enabled() && !(c)) \
241 lockdep_rcu_dereference(__FILE__, __LINE__); \
242 (p); \
243 })
244
212#else /* #ifdef CONFIG_PROVE_RCU */ 245#else /* #ifdef CONFIG_PROVE_RCU */
213 246
214#define rcu_dereference_check(p, c) rcu_dereference_raw(p) 247#define rcu_dereference_check(p, c) rcu_dereference_raw(p)
248#define rcu_dereference_protected(p, c) (p)
215 249
216#endif /* #else #ifdef CONFIG_PROVE_RCU */ 250#endif /* #else #ifdef CONFIG_PROVE_RCU */
217 251
218/** 252/**
253 * rcu_access_pointer - fetch RCU pointer with no dereferencing
254 *
255 * Return the value of the specified RCU-protected pointer, but omit the
256 * smp_read_barrier_depends() and keep the ACCESS_ONCE(). This is useful
257 * when the value of this pointer is accessed, but the pointer is not
258 * dereferenced, for example, when testing an RCU-protected pointer against
259 * NULL. This may also be used in cases where update-side locks prevent
260 * the value of the pointer from changing, but rcu_dereference_protected()
261 * is a lighter-weight primitive for this use case.
262 */
263#define rcu_access_pointer(p) ACCESS_ONCE(p)
264
265/**
219 * rcu_read_lock - mark the beginning of an RCU read-side critical section. 266 * rcu_read_lock - mark the beginning of an RCU read-side critical section.
220 * 267 *
221 * When synchronize_rcu() is invoked on one CPU while other CPUs 268 * When synchronize_rcu() is invoked on one CPU while other CPUs