diff options
author | Paul E. McKenney <paulmck@linux.vnet.ibm.com> | 2013-08-23 12:40:42 -0400 |
---|---|---|
committer | Paul E. McKenney <paulmck@linux.vnet.ibm.com> | 2013-09-23 12:13:49 -0400 |
commit | 2a855b644c310d5db5a80b8816c0c7748c167977 (patch) | |
tree | c39eb7a56033c40a380b45b8928ab377722e6b02 | |
parent | 829511d8aa7a2179bba57ab4ab277d6f9c77ae5b (diff) |
rcu: Make list_splice_init_rcu() account for RCU readers
The list_splice_init_rcu() function allows a list visible to RCU readers
to be spliced into another list visible to RCU readers. This is OK,
except for the use of INIT_LIST_HEAD(), which does pointer updates
without doing anything to make those updates safe for concurrent readers.
Of course, most of the time INIT_LIST_HEAD() is being used in reader-free
contexts, such as initialization or cleanup, so it is OK for it to update
pointers in an unsafe-for-RCU-readers manner. This commit therefore
creates an INIT_LIST_HEAD_RCU() that uses ACCESS_ONCE() to make the updates
reader-safe. The reason that we can use ACCESS_ONCE() instead of the more
typical rcu_assign_pointer() is that list_splice_init_rcu() is updating the
pointers to reference something that is already visible to readers, so
that there is no problem with pre-initialized values.
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
-rw-r--r-- | include/linux/rculist.h | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/include/linux/rculist.h b/include/linux/rculist.h index 4106721c4e5e..45a0a9e81478 100644 --- a/include/linux/rculist.h +++ b/include/linux/rculist.h | |||
@@ -19,6 +19,21 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | * INIT_LIST_HEAD_RCU - Initialize a list_head visible to RCU readers | ||
23 | * @list: list to be initialized | ||
24 | * | ||
25 | * You should instead use INIT_LIST_HEAD() for normal initialization and | ||
26 | * cleanup tasks, when readers have no access to the list being initialized. | ||
27 | * However, if the list being initialized is visible to readers, you | ||
28 | * need to keep the compiler from being too mischievous. | ||
29 | */ | ||
30 | static inline void INIT_LIST_HEAD_RCU(struct list_head *list) | ||
31 | { | ||
32 | ACCESS_ONCE(list->next) = list; | ||
33 | ACCESS_ONCE(list->prev) = list; | ||
34 | } | ||
35 | |||
36 | /* | ||
22 | * return the ->next pointer of a list_head in an rcu safe | 37 | * return the ->next pointer of a list_head in an rcu safe |
23 | * way, we must not access it directly | 38 | * way, we must not access it directly |
24 | */ | 39 | */ |
@@ -191,9 +206,13 @@ static inline void list_splice_init_rcu(struct list_head *list, | |||
191 | if (list_empty(list)) | 206 | if (list_empty(list)) |
192 | return; | 207 | return; |
193 | 208 | ||
194 | /* "first" and "last" tracking list, so initialize it. */ | 209 | /* |
210 | * "first" and "last" tracking list, so initialize it. RCU readers | ||
211 | * have access to this list, so we must use INIT_LIST_HEAD_RCU() | ||
212 | * instead of INIT_LIST_HEAD(). | ||
213 | */ | ||
195 | 214 | ||
196 | INIT_LIST_HEAD(list); | 215 | INIT_LIST_HEAD_RCU(list); |
197 | 216 | ||
198 | /* | 217 | /* |
199 | * At this point, the list body still points to the source list. | 218 | * At this point, the list body still points to the source list. |