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
32 - In the special case where data is added but is never removed
38 - You are only permitted to use rcu_dereference() on pointer values.
44 - Set bits and clear bits down in the must-be-zero low-order
49 - XOR bits to translate pointers, as is done in some
50 classic buddy-allocator algorithms.
55 - Avoid cancellation when using the "+" and "-" infix arithmetic
57 "(x-(uintptr_t)x)" for char* pointers. The compiler is within its
64 "p+a-b" is safe because its value still necessarily depends on
67 - If you are using RCU to protect JITed functions, so that the
68 "()" function-invocation operator is applied to a value obtained
70 interact directly with the hardware to flush instruction caches.
74 - Do not use the results from relational operators ("==", "!=",
90 weak-memory machines such as ARM or PowerPC do order stores
94 - Be very careful about comparing pointers obtained from
95 rcu_dereference() against non-NULL values. As Linus Torvalds
102 do_default(p->a);
112 On ARM and Power hardware, the load from "default_struct.a"
118 - The comparison was against the NULL pointer. If the
121 non-equal, the compiler is none the wiser. Therefore,
125 - The pointer is never dereferenced after being compared.
128 to reorder the non-existent subsequent dereferences.
130 RCU-protected circular linked lists.
133 of an RCU read-side critical section, and the pointer
140 Within an RCU read-side critical section, there is little
143 - The comparison is against a pointer that references memory
150 - Compile time.
152 - Boot time.
154 - Module-init time for module code.
156 - Prior to kthread creation for kthread code.
158 - During some prior acquisition of the lock that
161 - Before mod_timer() time for a timer handler.
167 - The pointer being compared against also came from
176 "EXAMPLE OF AMPLIFIED RCU-USAGE BUG".
178 - All of the accesses following the comparison are stores,
182 Documentation/memory-barriers.txt for more details.
184 - The pointers are not equal *and* the compiler does
190 pointer takes on only one of two values, a not-equal
194 - Disable any value-speculation optimizations that your compiler
195 might provide, especially if you are making use of feedback-based
197 value-speculation optimizations reorder operations by design.
199 There is one exception to this rule: Value-speculation
200 optimizations that leverage the branch-prediction hardware are
203 command-line options wisely!
206 EXAMPLE OF AMPLIFIED RCU-USAGE BUG
207 ----------------------------------
229 p->a = 42; /* Each field in its own cache line. */
230 p->b = 43;
231 p->c = 44;
233 p->b = 143;
234 p->c = 144;
248 r1 = p->b; /* Guaranteed to get 143. */
249 q = rcu_dereference(gp1); /* Guaranteed non-NULL. */
251 /* The compiler decides that q->c is same as p->c. */
252 r2 = p->c; /* Could get 44 on weakly order system. */
254 r2 = p->c - r1; /* Unconditional access to p->c. */
286 spin_lock(&p->lock);
287 p->a = 42; /* Each field in its own cache line. */
288 p->b = 43;
289 p->c = 44;
290 spin_unlock(&p->lock);
292 spin_lock(&p->lock);
293 p->b = 143;
294 p->c = 144;
295 spin_unlock(&p->lock);
309 spin_lock(&p->lock);
310 r1 = p->b; /* Guaranteed to get 143. */
311 q = rcu_dereference(gp1); /* Guaranteed non-NULL. */
313 /* The compiler decides that q->c is same as p->c. */
314 r2 = p->c; /* Locking guarantees r2 == 144. */
316 spin_lock(&q->lock);
317 r2 = q->c - r1;
318 spin_unlock(&q->lock);
321 spin_unlock(&p->lock);
329 -----------------------------------------
331 If a pointer obtained from rcu_dereference() compares not-equal to some
366 return p->a; /* Must be variable1.a. */
368 return p->b; /* Must be variable2.b. */
374 the exact value of "p" even in the not-equals case. This allows the
377 return values. This can result in "p->b" returning pre-initialization
385 ------------------------------------------------------------
393 1. If the access needs to be within an RCU read-side critical
395 RCU flavors, an RCU read-side critical section is entered
400 2. If the access might be within an RCU read-side critical section
401 on the one hand, or protected by (say) my_lock on the other,
404 p1 = rcu_dereference_check(p->rcu_protected_pointer,
408 3. If the access might be within an RCU read-side critical section
409 on the one hand, or protected by either my_lock or your_lock on
412 p1 = rcu_dereference_check(p->rcu_protected_pointer,
416 4. If the access is on the update side, so that it is always protected
419 p1 = rcu_dereference_protected(p->rcu_protected_pointer,
431 there are data-locking cases where any one of a very large number
441 SPARSE CHECKING OF RCU-PROTECTED POINTERS
442 -----------------------------------------
444 The sparse static-analysis tool checks for non-RCU access to RCU-protected
449 p = q->rcu_protected_pointer;
450 do_something_with(p->a);
451 do_something_else_with(p->b);
456 do_something_with(q->rcu_protected_pointer->a);
457 do_something_else_with(q->rcu_protected_pointer->b);
459 This could fatally disappoint your code if q->rcu_protected_pointer
462 colleagues) a three-day weekend back in the early 1990s.
470 p = rcu_dereference(q->rcu_protected_pointer);
471 do_something_with(p->a);
472 do_something_else_with(p->b);
480 and friends. For example, ->rcu_protected_pointer might be declared as
485 Use of "__rcu" is opt-in. If you choose not to use it, then you should