aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/RCU/rcu_dereference.txt
diff options
context:
space:
mode:
authorPaul E. McKenney <paulmck@linux.vnet.ibm.com>2015-04-20 09:09:27 -0400
committerPaul E. McKenney <paulmck@linux.vnet.ibm.com>2015-05-27 15:56:17 -0400
commitcf9fbf8017e2ab5cb33b6602b626f7f005718124 (patch)
treeca2ca92b0454c408c420fd9f744975eb08b3b9eb /Documentation/RCU/rcu_dereference.txt
parent1ebee8017d84ec8a0ba893cf7b8be3f70ead088b (diff)
documentation: RCU-protected array indexes no longer supported
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Diffstat (limited to 'Documentation/RCU/rcu_dereference.txt')
-rw-r--r--Documentation/RCU/rcu_dereference.txt33
1 files changed, 12 insertions, 21 deletions
diff --git a/Documentation/RCU/rcu_dereference.txt b/Documentation/RCU/rcu_dereference.txt
index ceb05da5a5ac..66864d2a7f60 100644
--- a/Documentation/RCU/rcu_dereference.txt
+++ b/Documentation/RCU/rcu_dereference.txt
@@ -25,17 +25,6 @@ o You must use one of the rcu_dereference() family of primitives
25 for an example where the compiler can in fact deduce the exact 25 for an example where the compiler can in fact deduce the exact
26 value of the pointer, and thus cause misordering. 26 value of the pointer, and thus cause misordering.
27 27
28o Do not use single-element RCU-protected arrays. The compiler
29 is within its right to assume that the value of an index into
30 such an array must necessarily evaluate to zero. The compiler
31 could then substitute the constant zero for the computation, so
32 that the array index no longer depended on the value returned
33 by rcu_dereference(). If the array index no longer depends
34 on rcu_dereference(), then both the compiler and the CPU
35 are within their rights to order the array access before the
36 rcu_dereference(), which can cause the array access to return
37 garbage.
38
39o Avoid cancellation when using the "+" and "-" infix arithmetic 28o Avoid cancellation when using the "+" and "-" infix arithmetic
40 operators. For example, for a given variable "x", avoid 29 operators. For example, for a given variable "x", avoid
41 "(x-x)". There are similar arithmetic pitfalls from other 30 "(x-x)". There are similar arithmetic pitfalls from other
@@ -76,14 +65,15 @@ o Do not use the results from the boolean "&&" and "||" when
76 dereferencing. For example, the following (rather improbable) 65 dereferencing. For example, the following (rather improbable)
77 code is buggy: 66 code is buggy:
78 67
79 int a[2]; 68 int *p;
80 int index; 69 int *q;
81 int force_zero_index = 1;
82 70
83 ... 71 ...
84 72
85 r1 = rcu_dereference(i1) 73 p = rcu_dereference(gp)
86 r2 = a[r1 && force_zero_index]; /* BUGGY!!! */ 74 q = &global_q;
75 q += p != &oom_p1 && p != &oom_p2;
76 r1 = *q; /* BUGGY!!! */
87 77
88 The reason this is buggy is that "&&" and "||" are often compiled 78 The reason this is buggy is that "&&" and "||" are often compiled
89 using branches. While weak-memory machines such as ARM or PowerPC 79 using branches. While weak-memory machines such as ARM or PowerPC
@@ -94,14 +84,15 @@ o Do not use the results from relational operators ("==", "!=",
94 ">", ">=", "<", or "<=") when dereferencing. For example, 84 ">", ">=", "<", or "<=") when dereferencing. For example,
95 the following (quite strange) code is buggy: 85 the following (quite strange) code is buggy:
96 86
97 int a[2]; 87 int *p;
98 int index; 88 int *q;
99 int flip_index = 0;
100 89
101 ... 90 ...
102 91
103 r1 = rcu_dereference(i1) 92 p = rcu_dereference(gp)
104 r2 = a[r1 != flip_index]; /* BUGGY!!! */ 93 q = &global_q;
94 q += p > &oom_p;
95 r1 = *q; /* BUGGY!!! */
105 96
106 As before, the reason this is buggy is that relational operators 97 As before, the reason this is buggy is that relational operators
107 are often compiled using branches. And as before, although 98 are often compiled using branches. And as before, although