diff options
Diffstat (limited to 'include/linux/rcupdate.h')
-rw-r--r-- | include/linux/rcupdate.h | 67 |
1 files changed, 58 insertions, 9 deletions
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h index 872a98e13d6a..db266bbed23f 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 | ||
104 | static inline int debug_lockdep_rcu_enabled(void) | 104 | extern 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? |
@@ -193,14 +190,34 @@ static inline int rcu_read_lock_sched_held(void) | |||
193 | 190 | ||
194 | #ifdef CONFIG_PROVE_RCU | 191 | #ifdef CONFIG_PROVE_RCU |
195 | 192 | ||
193 | extern int rcu_my_thread_group_empty(void); | ||
194 | |||
196 | /** | 195 | /** |
197 | * rcu_dereference_check - rcu_dereference with debug checking | 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: | ||
198 | * | 206 | * |
199 | * Do an rcu_dereference(), but check that the context is correct. | 207 | * bar = rcu_dereference_check(foo->bar, rcu_read_lock_held() || |
200 | * For example, rcu_dereference_check(gp, rcu_read_lock_held()) to | 208 | * lockdep_is_held(&foo->lock)); |
201 | * ensure that the rcu_dereference_check() executes within an RCU | 209 | * |
202 | * read-side critical section. It is also possible to check for | 210 | * could be used to indicate to lockdep that foo->bar may only be dereferenced |
203 | * locks being held, for example, by using lockdep_is_held(). | 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); | ||
204 | */ | 221 | */ |
205 | #define rcu_dereference_check(p, c) \ | 222 | #define rcu_dereference_check(p, c) \ |
206 | ({ \ | 223 | ({ \ |
@@ -209,13 +226,45 @@ static inline int rcu_read_lock_sched_held(void) | |||
209 | rcu_dereference_raw(p); \ | 226 | rcu_dereference_raw(p); \ |
210 | }) | 227 | }) |
211 | 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 | |||
212 | #else /* #ifdef CONFIG_PROVE_RCU */ | 247 | #else /* #ifdef CONFIG_PROVE_RCU */ |
213 | 248 | ||
214 | #define rcu_dereference_check(p, c) rcu_dereference_raw(p) | 249 | #define rcu_dereference_check(p, c) rcu_dereference_raw(p) |
250 | #define rcu_dereference_protected(p, c) (p) | ||
215 | 251 | ||
216 | #endif /* #else #ifdef CONFIG_PROVE_RCU */ | 252 | #endif /* #else #ifdef CONFIG_PROVE_RCU */ |
217 | 253 | ||
218 | /** | 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) | ||
266 | |||
267 | /** | ||
219 | * 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. |
220 | * | 269 | * |
221 | * When synchronize_rcu() is invoked on one CPU while other CPUs | 270 | * When synchronize_rcu() is invoked on one CPU while other CPUs |