Lines Matching +full:hardware +full:- +full:protected
8 field selection ("->"), assignment ("="), address-of ("&"), addition and
14 - You must use one of the rcu_dereference() family of primitives
15 to load an RCU-protected pointer, otherwise CONFIG_PROVE_RCU
16 will complain. Worse yet, your code can see random memory-corruption
31 - You are only permitted to use rcu_dereference on pointer values.
37 - Set bits and clear bits down in the must-be-zero low-order
40 -not- work in general for char* pointers.
42 - XOR bits to translate pointers, as is done in some
43 classic buddy-allocator algorithms.
48 - Avoid cancellation when using the "+" and "-" infix arithmetic
50 "(x-(uintptr_t)x)" for char* pointers. The compiler is within its
57 "p+a-b" is safe because its value still necessarily depends on
60 - If you are using RCU to protect JITed functions, so that the
61 "()" function-invocation operator is applied to a value obtained
63 interact directly with the hardware to flush instruction caches.
67 - Do not use the results from relational operators ("==", "!=",
83 weak-memory machines such as ARM or PowerPC do order stores
87 - Be very careful about comparing pointers obtained from
88 rcu_dereference() against non-NULL values. As Linus Torvalds
95 do_default(p->a);
105 On ARM and Power hardware, the load from "default_struct.a"
111 - The comparison was against the NULL pointer. If the
114 non-equal, the compiler is none the wiser. Therefore,
118 - The pointer is never dereferenced after being compared.
121 to reorder the non-existent subsequent dereferences.
123 RCU-protected circular linked lists.
125 Note that if checks for being within an RCU read-side
130 - The comparison is against a pointer that references memory
137 - Compile time.
139 - Boot time.
141 - Module-init time for module code.
143 - Prior to kthread creation for kthread code.
145 - During some prior acquisition of the lock that
148 - Before mod_timer() time for a timer handler.
154 - The pointer being compared against also came from
163 "EXAMPLE OF AMPLIFIED RCU-USAGE BUG".
165 - All of the accesses following the comparison are stores,
169 Documentation/memory-barriers.txt for more details.
171 - The pointers are not equal -and- the compiler does
177 pointer takes on only one of two values, a not-equal
181 - Disable any value-speculation optimizations that your compiler
182 might provide, especially if you are making use of feedback-based
184 value-speculation optimizations reorder operations by design.
186 There is one exception to this rule: Value-speculation
187 optimizations that leverage the branch-prediction hardware are
190 command-line options wisely!
193 EXAMPLE OF AMPLIFIED RCU-USAGE BUG
194 ----------------------------------
216 p->a = 42; /* Each field in its own cache line. */
217 p->b = 43;
218 p->c = 44;
220 p->b = 143;
221 p->c = 144;
234 r1 = p->b; /* Guaranteed to get 143. */
235 q = rcu_dereference(gp1); /* Guaranteed non-NULL. */
237 /* The compiler decides that q->c is same as p->c. */
238 r2 = p->c; /* Could get 44 on weakly order system. */
269 spin_lock(&p->lock);
270 p->a = 42; /* Each field in its own cache line. */
271 p->b = 43;
272 p->c = 44;
273 spin_unlock(&p->lock);
275 spin_lock(&p->lock);
276 p->b = 143;
277 p->c = 144;
278 spin_unlock(&p->lock);
291 spin_lock(&p->lock);
292 r1 = p->b; /* Guaranteed to get 143. */
293 q = rcu_dereference(gp1); /* Guaranteed non-NULL. */
295 /* The compiler decides that q->c is same as p->c. */
296 r2 = p->c; /* Locking guarantees r2 == 144. */
298 spin_unlock(&p->lock);
306 -----------------------------------------
308 If a pointer obtained from rcu_dereference() compares not-equal to some
343 return p->a; /* Must be variable1.a. */
345 return p->b; /* Must be variable2.b. */
351 the exact value of "p" even in the not-equals case. This allows the
354 return values. This can result in "p->b" returning pre-initialization
357 In short, rcu_dereference() is -not- optional when you are going to
362 ------------------------------------------------------------
370 1. If the access needs to be within an RCU read-side critical
372 RCU flavors, an RCU read-side critical section is entered
377 2. If the access might be within an RCU read-side critical section
378 on the one hand, or protected by (say) my_lock on the other,
381 p1 = rcu_dereference_check(p->rcu_protected_pointer,
385 3. If the access might be within an RCU read-side critical section
386 on the one hand, or protected by either my_lock or your_lock on
389 p1 = rcu_dereference_check(p->rcu_protected_pointer,
393 4. If the access is on the update side, so that it is always protected
396 p1 = rcu_dereference_protected(p->rcu_protected_pointer,
408 there are data-locking cases where any one of a very large number
418 SPARSE CHECKING OF RCU-PROTECTED POINTERS
419 -----------------------------------------
421 The sparse static-analysis tool checks for direct access to RCU-protected
426 p = q->rcu_protected_pointer;
427 do_something_with(p->a);
428 do_something_else_with(p->b);
433 do_something_with(q->rcu_protected_pointer->a);
434 do_something_else_with(q->rcu_protected_pointer->b);
436 This could fatally disappoint your code if q->rcu_protected_pointer
439 colleagues) a three-day weekend back in the early 1990s.
447 p = rcu_dereference(q->rcu_protected_pointer);
448 do_something_with(p->a);
449 do_something_else_with(p->b);
457 and friends. For example, ->rcu_protected_pointer might be declared as
462 Use of "__rcu" is opt-in. If you choose not to use it, then you should