Rev 6936 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6936 | Rev 7143 | ||
---|---|---|---|
1 | #ifndef _LINUX_RCULIST_H |
1 | #ifndef _LINUX_RCULIST_H |
2 | #define _LINUX_RCULIST_H |
2 | #define _LINUX_RCULIST_H |
3 | 3 | ||
4 | #ifdef __KERNEL__ |
4 | #ifdef __KERNEL__ |
5 | 5 | ||
6 | /* |
6 | /* |
7 | * RCU-protected list version |
7 | * RCU-protected list version |
8 | */ |
8 | */ |
9 | #include |
9 | #include |
10 | #include |
10 | #include |
11 | 11 | ||
12 | /* |
12 | /* |
13 | * Why is there no list_empty_rcu()? Because list_empty() serves this |
13 | * Why is there no list_empty_rcu()? Because list_empty() serves this |
14 | * purpose. The list_empty() function fetches the RCU-protected pointer |
14 | * purpose. The list_empty() function fetches the RCU-protected pointer |
15 | * and compares it to the address of the list head, but neither dereferences |
15 | * and compares it to the address of the list head, but neither dereferences |
16 | * this pointer itself nor provides this pointer to the caller. Therefore, |
16 | * this pointer itself nor provides this pointer to the caller. Therefore, |
17 | * it is not necessary to use rcu_dereference(), so that list_empty() can |
17 | * it is not necessary to use rcu_dereference(), so that list_empty() can |
18 | * be used anywhere you would want to use a list_empty_rcu(). |
18 | * be used anywhere you would want to use a list_empty_rcu(). |
19 | */ |
19 | */ |
20 | 20 | ||
21 | /* |
21 | /* |
22 | * INIT_LIST_HEAD_RCU - Initialize a list_head visible to RCU readers |
22 | * INIT_LIST_HEAD_RCU - Initialize a list_head visible to RCU readers |
23 | * @list: list to be initialized |
23 | * @list: list to be initialized |
24 | * |
24 | * |
25 | * You should instead use INIT_LIST_HEAD() for normal initialization and |
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. |
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 |
27 | * However, if the list being initialized is visible to readers, you |
28 | * need to keep the compiler from being too mischievous. |
28 | * need to keep the compiler from being too mischievous. |
29 | */ |
29 | */ |
30 | static inline void INIT_LIST_HEAD_RCU(struct list_head *list) |
30 | static inline void INIT_LIST_HEAD_RCU(struct list_head *list) |
31 | { |
31 | { |
32 | WRITE_ONCE(list->next, list); |
32 | WRITE_ONCE(list->next, list); |
33 | WRITE_ONCE(list->prev, list); |
33 | WRITE_ONCE(list->prev, list); |
34 | } |
34 | } |
35 | 35 | ||
36 | /* |
36 | /* |
37 | * 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 |
38 | * way, we must not access it directly |
38 | * way, we must not access it directly |
39 | */ |
39 | */ |
40 | #define list_next_rcu(list) (*((struct list_head __rcu **)(&(list)->next))) |
40 | #define list_next_rcu(list) (*((struct list_head __rcu **)(&(list)->next))) |
41 | 41 | ||
42 | /* |
42 | /* |
43 | * Insert a new entry between two known consecutive entries. |
43 | * Insert a new entry between two known consecutive entries. |
44 | * |
44 | * |
45 | * This is only for internal list manipulation where we know |
45 | * This is only for internal list manipulation where we know |
46 | * the prev/next entries already! |
46 | * the prev/next entries already! |
47 | */ |
47 | */ |
48 | #ifndef CONFIG_DEBUG_LIST |
48 | #ifndef CONFIG_DEBUG_LIST |
49 | static inline void __list_add_rcu(struct list_head *new, |
49 | static inline void __list_add_rcu(struct list_head *new, |
50 | struct list_head *prev, struct list_head *next) |
50 | struct list_head *prev, struct list_head *next) |
51 | { |
51 | { |
52 | new->next = next; |
52 | new->next = next; |
53 | new->prev = prev; |
53 | new->prev = prev; |
54 | rcu_assign_pointer(list_next_rcu(prev), new); |
54 | rcu_assign_pointer(list_next_rcu(prev), new); |
55 | next->prev = new; |
55 | next->prev = new; |
56 | } |
56 | } |
57 | #else |
57 | #else |
58 | void __list_add_rcu(struct list_head *new, |
58 | void __list_add_rcu(struct list_head *new, |
59 | struct list_head *prev, struct list_head *next); |
59 | struct list_head *prev, struct list_head *next); |
60 | #endif |
60 | #endif |
61 | 61 | ||
62 | /** |
62 | /** |
63 | * list_add_rcu - add a new entry to rcu-protected list |
63 | * list_add_rcu - add a new entry to rcu-protected list |
64 | * @new: new entry to be added |
64 | * @new: new entry to be added |
65 | * @head: list head to add it after |
65 | * @head: list head to add it after |
66 | * |
66 | * |
67 | * Insert a new entry after the specified head. |
67 | * Insert a new entry after the specified head. |
68 | * This is good for implementing stacks. |
68 | * This is good for implementing stacks. |
69 | * |
69 | * |
70 | * The caller must take whatever precautions are necessary |
70 | * The caller must take whatever precautions are necessary |
71 | * (such as holding appropriate locks) to avoid racing |
71 | * (such as holding appropriate locks) to avoid racing |
72 | * with another list-mutation primitive, such as list_add_rcu() |
72 | * with another list-mutation primitive, such as list_add_rcu() |
73 | * or list_del_rcu(), running on this same list. |
73 | * or list_del_rcu(), running on this same list. |
74 | * However, it is perfectly legal to run concurrently with |
74 | * However, it is perfectly legal to run concurrently with |
75 | * the _rcu list-traversal primitives, such as |
75 | * the _rcu list-traversal primitives, such as |
76 | * list_for_each_entry_rcu(). |
76 | * list_for_each_entry_rcu(). |
77 | */ |
77 | */ |
78 | static inline void list_add_rcu(struct list_head *new, struct list_head *head) |
78 | static inline void list_add_rcu(struct list_head *new, struct list_head *head) |
79 | { |
79 | { |
80 | __list_add_rcu(new, head, head->next); |
80 | __list_add_rcu(new, head, head->next); |
81 | } |
81 | } |
82 | 82 | ||
83 | /** |
83 | /** |
84 | * list_add_tail_rcu - add a new entry to rcu-protected list |
84 | * list_add_tail_rcu - add a new entry to rcu-protected list |
85 | * @new: new entry to be added |
85 | * @new: new entry to be added |
86 | * @head: list head to add it before |
86 | * @head: list head to add it before |
87 | * |
87 | * |
88 | * Insert a new entry before the specified head. |
88 | * Insert a new entry before the specified head. |
89 | * This is useful for implementing queues. |
89 | * This is useful for implementing queues. |
90 | * |
90 | * |
91 | * The caller must take whatever precautions are necessary |
91 | * The caller must take whatever precautions are necessary |
92 | * (such as holding appropriate locks) to avoid racing |
92 | * (such as holding appropriate locks) to avoid racing |
93 | * with another list-mutation primitive, such as list_add_tail_rcu() |
93 | * with another list-mutation primitive, such as list_add_tail_rcu() |
94 | * or list_del_rcu(), running on this same list. |
94 | * or list_del_rcu(), running on this same list. |
95 | * However, it is perfectly legal to run concurrently with |
95 | * However, it is perfectly legal to run concurrently with |
96 | * the _rcu list-traversal primitives, such as |
96 | * the _rcu list-traversal primitives, such as |
97 | * list_for_each_entry_rcu(). |
97 | * list_for_each_entry_rcu(). |
98 | */ |
98 | */ |
99 | static inline void list_add_tail_rcu(struct list_head *new, |
99 | static inline void list_add_tail_rcu(struct list_head *new, |
100 | struct list_head *head) |
100 | struct list_head *head) |
101 | { |
101 | { |
102 | __list_add_rcu(new, head->prev, head); |
102 | __list_add_rcu(new, head->prev, head); |
103 | } |
103 | } |
104 | 104 | ||
105 | /** |
105 | /** |
106 | * list_del_rcu - deletes entry from list without re-initialization |
106 | * list_del_rcu - deletes entry from list without re-initialization |
107 | * @entry: the element to delete from the list. |
107 | * @entry: the element to delete from the list. |
108 | * |
108 | * |
109 | * Note: list_empty() on entry does not return true after this, |
109 | * Note: list_empty() on entry does not return true after this, |
110 | * the entry is in an undefined state. It is useful for RCU based |
110 | * the entry is in an undefined state. It is useful for RCU based |
111 | * lockfree traversal. |
111 | * lockfree traversal. |
112 | * |
112 | * |
113 | * In particular, it means that we can not poison the forward |
113 | * In particular, it means that we can not poison the forward |
114 | * pointers that may still be used for walking the list. |
114 | * pointers that may still be used for walking the list. |
115 | * |
115 | * |
116 | * The caller must take whatever precautions are necessary |
116 | * The caller must take whatever precautions are necessary |
117 | * (such as holding appropriate locks) to avoid racing |
117 | * (such as holding appropriate locks) to avoid racing |
118 | * with another list-mutation primitive, such as list_del_rcu() |
118 | * with another list-mutation primitive, such as list_del_rcu() |
119 | * or list_add_rcu(), running on this same list. |
119 | * or list_add_rcu(), running on this same list. |
120 | * However, it is perfectly legal to run concurrently with |
120 | * However, it is perfectly legal to run concurrently with |
121 | * the _rcu list-traversal primitives, such as |
121 | * the _rcu list-traversal primitives, such as |
122 | * list_for_each_entry_rcu(). |
122 | * list_for_each_entry_rcu(). |
123 | * |
123 | * |
124 | * Note that the caller is not permitted to immediately free |
124 | * Note that the caller is not permitted to immediately free |
125 | * the newly deleted entry. Instead, either synchronize_rcu() |
125 | * the newly deleted entry. Instead, either synchronize_rcu() |
126 | * or call_rcu() must be used to defer freeing until an RCU |
126 | * or call_rcu() must be used to defer freeing until an RCU |
127 | * grace period has elapsed. |
127 | * grace period has elapsed. |
128 | */ |
128 | */ |
129 | static inline void list_del_rcu(struct list_head *entry) |
129 | static inline void list_del_rcu(struct list_head *entry) |
130 | { |
130 | { |
131 | __list_del_entry(entry); |
131 | __list_del_entry(entry); |
132 | entry->prev = LIST_POISON2; |
132 | entry->prev = LIST_POISON2; |
133 | } |
133 | } |
134 | 134 | ||
135 | /** |
135 | /** |
136 | * hlist_del_init_rcu - deletes entry from hash list with re-initialization |
136 | * hlist_del_init_rcu - deletes entry from hash list with re-initialization |
137 | * @n: the element to delete from the hash list. |
137 | * @n: the element to delete from the hash list. |
138 | * |
138 | * |
139 | * Note: list_unhashed() on the node return true after this. It is |
139 | * Note: list_unhashed() on the node return true after this. It is |
140 | * useful for RCU based read lockfree traversal if the writer side |
140 | * useful for RCU based read lockfree traversal if the writer side |
141 | * must know if the list entry is still hashed or already unhashed. |
141 | * must know if the list entry is still hashed or already unhashed. |
142 | * |
142 | * |
143 | * In particular, it means that we can not poison the forward pointers |
143 | * In particular, it means that we can not poison the forward pointers |
144 | * that may still be used for walking the hash list and we can only |
144 | * that may still be used for walking the hash list and we can only |
145 | * zero the pprev pointer so list_unhashed() will return true after |
145 | * zero the pprev pointer so list_unhashed() will return true after |
146 | * this. |
146 | * this. |
147 | * |
147 | * |
148 | * The caller must take whatever precautions are necessary (such as |
148 | * The caller must take whatever precautions are necessary (such as |
149 | * holding appropriate locks) to avoid racing with another |
149 | * holding appropriate locks) to avoid racing with another |
150 | * list-mutation primitive, such as hlist_add_head_rcu() or |
150 | * list-mutation primitive, such as hlist_add_head_rcu() or |
151 | * hlist_del_rcu(), running on this same list. However, it is |
151 | * hlist_del_rcu(), running on this same list. However, it is |
152 | * perfectly legal to run concurrently with the _rcu list-traversal |
152 | * perfectly legal to run concurrently with the _rcu list-traversal |
153 | * primitives, such as hlist_for_each_entry_rcu(). |
153 | * primitives, such as hlist_for_each_entry_rcu(). |
154 | */ |
154 | */ |
155 | static inline void hlist_del_init_rcu(struct hlist_node *n) |
155 | static inline void hlist_del_init_rcu(struct hlist_node *n) |
156 | { |
156 | { |
157 | if (!hlist_unhashed(n)) { |
157 | if (!hlist_unhashed(n)) { |
158 | __hlist_del(n); |
158 | __hlist_del(n); |
159 | n->pprev = NULL; |
159 | n->pprev = NULL; |
160 | } |
160 | } |
161 | } |
161 | } |
162 | 162 | ||
163 | /** |
163 | /** |
164 | * list_replace_rcu - replace old entry by new one |
164 | * list_replace_rcu - replace old entry by new one |
165 | * @old : the element to be replaced |
165 | * @old : the element to be replaced |
166 | * @new : the new element to insert |
166 | * @new : the new element to insert |
167 | * |
167 | * |
168 | * The @old entry will be replaced with the @new entry atomically. |
168 | * The @old entry will be replaced with the @new entry atomically. |
169 | * Note: @old should not be empty. |
169 | * Note: @old should not be empty. |
170 | */ |
170 | */ |
171 | static inline void list_replace_rcu(struct list_head *old, |
171 | static inline void list_replace_rcu(struct list_head *old, |
172 | struct list_head *new) |
172 | struct list_head *new) |
173 | { |
173 | { |
174 | new->next = old->next; |
174 | new->next = old->next; |
175 | new->prev = old->prev; |
175 | new->prev = old->prev; |
176 | rcu_assign_pointer(list_next_rcu(new->prev), new); |
176 | rcu_assign_pointer(list_next_rcu(new->prev), new); |
177 | new->next->prev = new; |
177 | new->next->prev = new; |
178 | old->prev = LIST_POISON2; |
178 | old->prev = LIST_POISON2; |
179 | } |
179 | } |
180 | 180 | ||
181 | /** |
181 | /** |
182 | * __list_splice_init_rcu - join an RCU-protected list into an existing list. |
182 | * __list_splice_init_rcu - join an RCU-protected list into an existing list. |
183 | * @list: the RCU-protected list to splice |
183 | * @list: the RCU-protected list to splice |
184 | * @prev: points to the last element of the existing list |
184 | * @prev: points to the last element of the existing list |
185 | * @next: points to the first element of the existing list |
185 | * @next: points to the first element of the existing list |
186 | * @sync: function to sync: synchronize_rcu(), synchronize_sched(), ... |
186 | * @sync: function to sync: synchronize_rcu(), synchronize_sched(), ... |
187 | * |
187 | * |
188 | * The list pointed to by @prev and @next can be RCU-read traversed |
188 | * The list pointed to by @prev and @next can be RCU-read traversed |
189 | * concurrently with this function. |
189 | * concurrently with this function. |
190 | * |
190 | * |
191 | * Note that this function blocks. |
191 | * Note that this function blocks. |
192 | * |
192 | * |
193 | * Important note: the caller must take whatever action is necessary to prevent |
193 | * Important note: the caller must take whatever action is necessary to prevent |
194 | * any other updates to the existing list. In principle, it is possible to |
194 | * any other updates to the existing list. In principle, it is possible to |
195 | * modify the list as soon as sync() begins execution. If this sort of thing |
195 | * modify the list as soon as sync() begins execution. If this sort of thing |
196 | * becomes necessary, an alternative version based on call_rcu() could be |
196 | * becomes necessary, an alternative version based on call_rcu() could be |
197 | * created. But only if -really- needed -- there is no shortage of RCU API |
197 | * created. But only if -really- needed -- there is no shortage of RCU API |
198 | * members. |
198 | * members. |
199 | */ |
199 | */ |
200 | static inline void __list_splice_init_rcu(struct list_head *list, |
200 | static inline void __list_splice_init_rcu(struct list_head *list, |
201 | struct list_head *prev, |
201 | struct list_head *prev, |
202 | struct list_head *next, |
202 | struct list_head *next, |
203 | void (*sync)(void)) |
203 | void (*sync)(void)) |
204 | { |
204 | { |
205 | struct list_head *first = list->next; |
205 | struct list_head *first = list->next; |
206 | struct list_head *last = list->prev; |
206 | struct list_head *last = list->prev; |
207 | 207 | ||
208 | /* |
208 | /* |
209 | * "first" and "last" tracking list, so initialize it. RCU readers |
209 | * "first" and "last" tracking list, so initialize it. RCU readers |
210 | * have access to this list, so we must use INIT_LIST_HEAD_RCU() |
210 | * have access to this list, so we must use INIT_LIST_HEAD_RCU() |
211 | * instead of INIT_LIST_HEAD(). |
211 | * instead of INIT_LIST_HEAD(). |
212 | */ |
212 | */ |
213 | 213 | ||
214 | INIT_LIST_HEAD_RCU(list); |
214 | INIT_LIST_HEAD_RCU(list); |
215 | 215 | ||
216 | /* |
216 | /* |
217 | * At this point, the list body still points to the source list. |
217 | * At this point, the list body still points to the source list. |
218 | * Wait for any readers to finish using the list before splicing |
218 | * Wait for any readers to finish using the list before splicing |
219 | * the list body into the new list. Any new readers will see |
219 | * the list body into the new list. Any new readers will see |
220 | * an empty list. |
220 | * an empty list. |
221 | */ |
221 | */ |
222 | 222 | ||
223 | sync(); |
223 | sync(); |
224 | 224 | ||
225 | /* |
225 | /* |
226 | * Readers are finished with the source list, so perform splice. |
226 | * Readers are finished with the source list, so perform splice. |
227 | * The order is important if the new list is global and accessible |
227 | * The order is important if the new list is global and accessible |
228 | * to concurrent RCU readers. Note that RCU readers are not |
228 | * to concurrent RCU readers. Note that RCU readers are not |
229 | * permitted to traverse the prev pointers without excluding |
229 | * permitted to traverse the prev pointers without excluding |
230 | * this function. |
230 | * this function. |
231 | */ |
231 | */ |
232 | 232 | ||
233 | last->next = next; |
233 | last->next = next; |
234 | rcu_assign_pointer(list_next_rcu(prev), first); |
234 | rcu_assign_pointer(list_next_rcu(prev), first); |
235 | first->prev = prev; |
235 | first->prev = prev; |
236 | next->prev = last; |
236 | next->prev = last; |
237 | } |
237 | } |
238 | 238 | ||
239 | /** |
239 | /** |
240 | * list_splice_init_rcu - splice an RCU-protected list into an existing list, |
240 | * list_splice_init_rcu - splice an RCU-protected list into an existing list, |
241 | * designed for stacks. |
241 | * designed for stacks. |
242 | * @list: the RCU-protected list to splice |
242 | * @list: the RCU-protected list to splice |
243 | * @head: the place in the existing list to splice the first list into |
243 | * @head: the place in the existing list to splice the first list into |
244 | * @sync: function to sync: synchronize_rcu(), synchronize_sched(), ... |
244 | * @sync: function to sync: synchronize_rcu(), synchronize_sched(), ... |
245 | */ |
245 | */ |
246 | static inline void list_splice_init_rcu(struct list_head *list, |
246 | static inline void list_splice_init_rcu(struct list_head *list, |
247 | struct list_head *head, |
247 | struct list_head *head, |
248 | void (*sync)(void)) |
248 | void (*sync)(void)) |
249 | { |
249 | { |
250 | if (!list_empty(list)) |
250 | if (!list_empty(list)) |
251 | __list_splice_init_rcu(list, head, head->next, sync); |
251 | __list_splice_init_rcu(list, head, head->next, sync); |
252 | } |
252 | } |
253 | 253 | ||
254 | /** |
254 | /** |
255 | * list_splice_tail_init_rcu - splice an RCU-protected list into an existing |
255 | * list_splice_tail_init_rcu - splice an RCU-protected list into an existing |
256 | * list, designed for queues. |
256 | * list, designed for queues. |
257 | * @list: the RCU-protected list to splice |
257 | * @list: the RCU-protected list to splice |
258 | * @head: the place in the existing list to splice the first list into |
258 | * @head: the place in the existing list to splice the first list into |
259 | * @sync: function to sync: synchronize_rcu(), synchronize_sched(), ... |
259 | * @sync: function to sync: synchronize_rcu(), synchronize_sched(), ... |
260 | */ |
260 | */ |
261 | static inline void list_splice_tail_init_rcu(struct list_head *list, |
261 | static inline void list_splice_tail_init_rcu(struct list_head *list, |
262 | struct list_head *head, |
262 | struct list_head *head, |
263 | void (*sync)(void)) |
263 | void (*sync)(void)) |
264 | { |
264 | { |
265 | if (!list_empty(list)) |
265 | if (!list_empty(list)) |
266 | __list_splice_init_rcu(list, head->prev, head, sync); |
266 | __list_splice_init_rcu(list, head->prev, head, sync); |
267 | } |
267 | } |
268 | 268 | ||
269 | /** |
269 | /** |
270 | * list_entry_rcu - get the struct for this entry |
270 | * list_entry_rcu - get the struct for this entry |
271 | * @ptr: the &struct list_head pointer. |
271 | * @ptr: the &struct list_head pointer. |
272 | * @type: the type of the struct this is embedded in. |
272 | * @type: the type of the struct this is embedded in. |
273 | * @member: the name of the list_head within the struct. |
273 | * @member: the name of the list_head within the struct. |
274 | * |
274 | * |
275 | * This primitive may safely run concurrently with the _rcu list-mutation |
275 | * This primitive may safely run concurrently with the _rcu list-mutation |
276 | * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock(). |
276 | * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock(). |
277 | */ |
277 | */ |
278 | #define list_entry_rcu(ptr, type, member) \ |
278 | #define list_entry_rcu(ptr, type, member) \ |
279 | container_of(lockless_dereference(ptr), type, member) |
279 | container_of(lockless_dereference(ptr), type, member) |
280 | 280 | ||
281 | /** |
281 | /** |
282 | * Where are list_empty_rcu() and list_first_entry_rcu()? |
282 | * Where are list_empty_rcu() and list_first_entry_rcu()? |
283 | * |
283 | * |
284 | * Implementing those functions following their counterparts list_empty() and |
284 | * Implementing those functions following their counterparts list_empty() and |
285 | * list_first_entry() is not advisable because they lead to subtle race |
285 | * list_first_entry() is not advisable because they lead to subtle race |
286 | * conditions as the following snippet shows: |
286 | * conditions as the following snippet shows: |
287 | * |
287 | * |
288 | * if (!list_empty_rcu(mylist)) { |
288 | * if (!list_empty_rcu(mylist)) { |
289 | * struct foo *bar = list_first_entry_rcu(mylist, struct foo, list_member); |
289 | * struct foo *bar = list_first_entry_rcu(mylist, struct foo, list_member); |
290 | * do_something(bar); |
290 | * do_something(bar); |
291 | * } |
291 | * } |
292 | * |
292 | * |
293 | * The list may not be empty when list_empty_rcu checks it, but it may be when |
293 | * The list may not be empty when list_empty_rcu checks it, but it may be when |
294 | * list_first_entry_rcu rereads the ->next pointer. |
294 | * list_first_entry_rcu rereads the ->next pointer. |
295 | * |
295 | * |
296 | * Rereading the ->next pointer is not a problem for list_empty() and |
296 | * Rereading the ->next pointer is not a problem for list_empty() and |
297 | * list_first_entry() because they would be protected by a lock that blocks |
297 | * list_first_entry() because they would be protected by a lock that blocks |
298 | * writers. |
298 | * writers. |
299 | * |
299 | * |
300 | * See list_first_or_null_rcu for an alternative. |
300 | * See list_first_or_null_rcu for an alternative. |
301 | */ |
301 | */ |
302 | 302 | ||
303 | /** |
303 | /** |
304 | * list_first_or_null_rcu - get the first element from a list |
304 | * list_first_or_null_rcu - get the first element from a list |
305 | * @ptr: the list head to take the element from. |
305 | * @ptr: the list head to take the element from. |
306 | * @type: the type of the struct this is embedded in. |
306 | * @type: the type of the struct this is embedded in. |
307 | * @member: the name of the list_head within the struct. |
307 | * @member: the name of the list_head within the struct. |
308 | * |
308 | * |
309 | * Note that if the list is empty, it returns NULL. |
309 | * Note that if the list is empty, it returns NULL. |
310 | * |
310 | * |
311 | * This primitive may safely run concurrently with the _rcu list-mutation |
311 | * This primitive may safely run concurrently with the _rcu list-mutation |
312 | * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock(). |
312 | * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock(). |
313 | */ |
313 | */ |
314 | #define list_first_or_null_rcu(ptr, type, member) \ |
314 | #define list_first_or_null_rcu(ptr, type, member) \ |
315 | ({ \ |
315 | ({ \ |
316 | struct list_head *__ptr = (ptr); \ |
316 | struct list_head *__ptr = (ptr); \ |
317 | struct list_head *__next = READ_ONCE(__ptr->next); \ |
317 | struct list_head *__next = READ_ONCE(__ptr->next); \ |
318 | likely(__ptr != __next) ? list_entry_rcu(__next, type, member) : NULL; \ |
318 | likely(__ptr != __next) ? list_entry_rcu(__next, type, member) : NULL; \ |
319 | }) |
319 | }) |
- | 320 | ||
- | 321 | /** |
|
- | 322 | * list_next_or_null_rcu - get the first element from a list |
|
- | 323 | * @head: the head for the list. |
|
- | 324 | * @ptr: the list head to take the next element from. |
|
- | 325 | * @type: the type of the struct this is embedded in. |
|
- | 326 | * @member: the name of the list_head within the struct. |
|
- | 327 | * |
|
- | 328 | * Note that if the ptr is at the end of the list, NULL is returned. |
|
- | 329 | * |
|
- | 330 | * This primitive may safely run concurrently with the _rcu list-mutation |
|
- | 331 | * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock(). |
|
- | 332 | */ |
|
- | 333 | #define list_next_or_null_rcu(head, ptr, type, member) \ |
|
- | 334 | ({ \ |
|
- | 335 | struct list_head *__head = (head); \ |
|
- | 336 | struct list_head *__ptr = (ptr); \ |
|
- | 337 | struct list_head *__next = READ_ONCE(__ptr->next); \ |
|
- | 338 | likely(__next != __head) ? list_entry_rcu(__next, type, \ |
|
- | 339 | member) : NULL; \ |
|
- | 340 | }) |
|
320 | 341 | ||
321 | /** |
342 | /** |
322 | * list_for_each_entry_rcu - iterate over rcu list of given type |
343 | * list_for_each_entry_rcu - iterate over rcu list of given type |
323 | * @pos: the type * to use as a loop cursor. |
344 | * @pos: the type * to use as a loop cursor. |
324 | * @head: the head for your list. |
345 | * @head: the head for your list. |
325 | * @member: the name of the list_head within the struct. |
346 | * @member: the name of the list_head within the struct. |
326 | * |
347 | * |
327 | * This list-traversal primitive may safely run concurrently with |
348 | * This list-traversal primitive may safely run concurrently with |
328 | * the _rcu list-mutation primitives such as list_add_rcu() |
349 | * the _rcu list-mutation primitives such as list_add_rcu() |
329 | * as long as the traversal is guarded by rcu_read_lock(). |
350 | * as long as the traversal is guarded by rcu_read_lock(). |
330 | */ |
351 | */ |
331 | #define list_for_each_entry_rcu(pos, head, member) \ |
352 | #define list_for_each_entry_rcu(pos, head, member) \ |
332 | for (pos = list_entry_rcu((head)->next, typeof(*pos), member); \ |
353 | for (pos = list_entry_rcu((head)->next, typeof(*pos), member); \ |
333 | &pos->member != (head); \ |
354 | &pos->member != (head); \ |
334 | pos = list_entry_rcu(pos->member.next, typeof(*pos), member)) |
355 | pos = list_entry_rcu(pos->member.next, typeof(*pos), member)) |
335 | 356 | ||
336 | /** |
357 | /** |
337 | * list_entry_lockless - get the struct for this entry |
358 | * list_entry_lockless - get the struct for this entry |
338 | * @ptr: the &struct list_head pointer. |
359 | * @ptr: the &struct list_head pointer. |
339 | * @type: the type of the struct this is embedded in. |
360 | * @type: the type of the struct this is embedded in. |
340 | * @member: the name of the list_head within the struct. |
361 | * @member: the name of the list_head within the struct. |
341 | * |
362 | * |
342 | * This primitive may safely run concurrently with the _rcu list-mutation |
363 | * This primitive may safely run concurrently with the _rcu list-mutation |
343 | * primitives such as list_add_rcu(), but requires some implicit RCU |
364 | * primitives such as list_add_rcu(), but requires some implicit RCU |
344 | * read-side guarding. One example is running within a special |
365 | * read-side guarding. One example is running within a special |
345 | * exception-time environment where preemption is disabled and where |
366 | * exception-time environment where preemption is disabled and where |
346 | * lockdep cannot be invoked (in which case updaters must use RCU-sched, |
367 | * lockdep cannot be invoked (in which case updaters must use RCU-sched, |
347 | * as in synchronize_sched(), call_rcu_sched(), and friends). Another |
368 | * as in synchronize_sched(), call_rcu_sched(), and friends). Another |
348 | * example is when items are added to the list, but never deleted. |
369 | * example is when items are added to the list, but never deleted. |
349 | */ |
370 | */ |
350 | #define list_entry_lockless(ptr, type, member) \ |
371 | #define list_entry_lockless(ptr, type, member) \ |
351 | container_of((typeof(ptr))lockless_dereference(ptr), type, member) |
372 | container_of((typeof(ptr))lockless_dereference(ptr), type, member) |
352 | 373 | ||
353 | /** |
374 | /** |
354 | * list_for_each_entry_lockless - iterate over rcu list of given type |
375 | * list_for_each_entry_lockless - iterate over rcu list of given type |
355 | * @pos: the type * to use as a loop cursor. |
376 | * @pos: the type * to use as a loop cursor. |
356 | * @head: the head for your list. |
377 | * @head: the head for your list. |
357 | * @member: the name of the list_struct within the struct. |
378 | * @member: the name of the list_struct within the struct. |
358 | * |
379 | * |
359 | * This primitive may safely run concurrently with the _rcu list-mutation |
380 | * This primitive may safely run concurrently with the _rcu list-mutation |
360 | * primitives such as list_add_rcu(), but requires some implicit RCU |
381 | * primitives such as list_add_rcu(), but requires some implicit RCU |
361 | * read-side guarding. One example is running within a special |
382 | * read-side guarding. One example is running within a special |
362 | * exception-time environment where preemption is disabled and where |
383 | * exception-time environment where preemption is disabled and where |
363 | * lockdep cannot be invoked (in which case updaters must use RCU-sched, |
384 | * lockdep cannot be invoked (in which case updaters must use RCU-sched, |
364 | * as in synchronize_sched(), call_rcu_sched(), and friends). Another |
385 | * as in synchronize_sched(), call_rcu_sched(), and friends). Another |
365 | * example is when items are added to the list, but never deleted. |
386 | * example is when items are added to the list, but never deleted. |
366 | */ |
387 | */ |
367 | #define list_for_each_entry_lockless(pos, head, member) \ |
388 | #define list_for_each_entry_lockless(pos, head, member) \ |
368 | for (pos = list_entry_lockless((head)->next, typeof(*pos), member); \ |
389 | for (pos = list_entry_lockless((head)->next, typeof(*pos), member); \ |
369 | &pos->member != (head); \ |
390 | &pos->member != (head); \ |
370 | pos = list_entry_lockless(pos->member.next, typeof(*pos), member)) |
391 | pos = list_entry_lockless(pos->member.next, typeof(*pos), member)) |
371 | 392 | ||
372 | /** |
393 | /** |
373 | * list_for_each_entry_continue_rcu - continue iteration over list of given type |
394 | * list_for_each_entry_continue_rcu - continue iteration over list of given type |
374 | * @pos: the type * to use as a loop cursor. |
395 | * @pos: the type * to use as a loop cursor. |
375 | * @head: the head for your list. |
396 | * @head: the head for your list. |
376 | * @member: the name of the list_head within the struct. |
397 | * @member: the name of the list_head within the struct. |
377 | * |
398 | * |
378 | * Continue to iterate over list of given type, continuing after |
399 | * Continue to iterate over list of given type, continuing after |
379 | * the current position. |
400 | * the current position. |
380 | */ |
401 | */ |
381 | #define list_for_each_entry_continue_rcu(pos, head, member) \ |
402 | #define list_for_each_entry_continue_rcu(pos, head, member) \ |
382 | for (pos = list_entry_rcu(pos->member.next, typeof(*pos), member); \ |
403 | for (pos = list_entry_rcu(pos->member.next, typeof(*pos), member); \ |
383 | &pos->member != (head); \ |
404 | &pos->member != (head); \ |
384 | pos = list_entry_rcu(pos->member.next, typeof(*pos), member)) |
405 | pos = list_entry_rcu(pos->member.next, typeof(*pos), member)) |
385 | 406 | ||
386 | /** |
407 | /** |
387 | * hlist_del_rcu - deletes entry from hash list without re-initialization |
408 | * hlist_del_rcu - deletes entry from hash list without re-initialization |
388 | * @n: the element to delete from the hash list. |
409 | * @n: the element to delete from the hash list. |
389 | * |
410 | * |
390 | * Note: list_unhashed() on entry does not return true after this, |
411 | * Note: list_unhashed() on entry does not return true after this, |
391 | * the entry is in an undefined state. It is useful for RCU based |
412 | * the entry is in an undefined state. It is useful for RCU based |
392 | * lockfree traversal. |
413 | * lockfree traversal. |
393 | * |
414 | * |
394 | * In particular, it means that we can not poison the forward |
415 | * In particular, it means that we can not poison the forward |
395 | * pointers that may still be used for walking the hash list. |
416 | * pointers that may still be used for walking the hash list. |
396 | * |
417 | * |
397 | * The caller must take whatever precautions are necessary |
418 | * The caller must take whatever precautions are necessary |
398 | * (such as holding appropriate locks) to avoid racing |
419 | * (such as holding appropriate locks) to avoid racing |
399 | * with another list-mutation primitive, such as hlist_add_head_rcu() |
420 | * with another list-mutation primitive, such as hlist_add_head_rcu() |
400 | * or hlist_del_rcu(), running on this same list. |
421 | * or hlist_del_rcu(), running on this same list. |
401 | * However, it is perfectly legal to run concurrently with |
422 | * However, it is perfectly legal to run concurrently with |
402 | * the _rcu list-traversal primitives, such as |
423 | * the _rcu list-traversal primitives, such as |
403 | * hlist_for_each_entry(). |
424 | * hlist_for_each_entry(). |
404 | */ |
425 | */ |
405 | static inline void hlist_del_rcu(struct hlist_node *n) |
426 | static inline void hlist_del_rcu(struct hlist_node *n) |
406 | { |
427 | { |
407 | __hlist_del(n); |
428 | __hlist_del(n); |
408 | n->pprev = LIST_POISON2; |
429 | n->pprev = LIST_POISON2; |
409 | } |
430 | } |
410 | 431 | ||
411 | /** |
432 | /** |
412 | * hlist_replace_rcu - replace old entry by new one |
433 | * hlist_replace_rcu - replace old entry by new one |
413 | * @old : the element to be replaced |
434 | * @old : the element to be replaced |
414 | * @new : the new element to insert |
435 | * @new : the new element to insert |
415 | * |
436 | * |
416 | * The @old entry will be replaced with the @new entry atomically. |
437 | * The @old entry will be replaced with the @new entry atomically. |
417 | */ |
438 | */ |
418 | static inline void hlist_replace_rcu(struct hlist_node *old, |
439 | static inline void hlist_replace_rcu(struct hlist_node *old, |
419 | struct hlist_node *new) |
440 | struct hlist_node *new) |
420 | { |
441 | { |
421 | struct hlist_node *next = old->next; |
442 | struct hlist_node *next = old->next; |
422 | 443 | ||
423 | new->next = next; |
444 | new->next = next; |
424 | new->pprev = old->pprev; |
445 | new->pprev = old->pprev; |
425 | rcu_assign_pointer(*(struct hlist_node __rcu **)new->pprev, new); |
446 | rcu_assign_pointer(*(struct hlist_node __rcu **)new->pprev, new); |
426 | if (next) |
447 | if (next) |
427 | new->next->pprev = &new->next; |
448 | new->next->pprev = &new->next; |
428 | old->pprev = LIST_POISON2; |
449 | old->pprev = LIST_POISON2; |
429 | } |
450 | } |
430 | 451 | ||
431 | /* |
452 | /* |
432 | * return the first or the next element in an RCU protected hlist |
453 | * return the first or the next element in an RCU protected hlist |
433 | */ |
454 | */ |
434 | #define hlist_first_rcu(head) (*((struct hlist_node __rcu **)(&(head)->first))) |
455 | #define hlist_first_rcu(head) (*((struct hlist_node __rcu **)(&(head)->first))) |
435 | #define hlist_next_rcu(node) (*((struct hlist_node __rcu **)(&(node)->next))) |
456 | #define hlist_next_rcu(node) (*((struct hlist_node __rcu **)(&(node)->next))) |
436 | #define hlist_pprev_rcu(node) (*((struct hlist_node __rcu **)((node)->pprev))) |
457 | #define hlist_pprev_rcu(node) (*((struct hlist_node __rcu **)((node)->pprev))) |
437 | 458 | ||
438 | /** |
459 | /** |
439 | * hlist_add_head_rcu |
460 | * hlist_add_head_rcu |
440 | * @n: the element to add to the hash list. |
461 | * @n: the element to add to the hash list. |
441 | * @h: the list to add to. |
462 | * @h: the list to add to. |
442 | * |
463 | * |
443 | * Description: |
464 | * Description: |
444 | * Adds the specified element to the specified hlist, |
465 | * Adds the specified element to the specified hlist, |
445 | * while permitting racing traversals. |
466 | * while permitting racing traversals. |
446 | * |
467 | * |
447 | * The caller must take whatever precautions are necessary |
468 | * The caller must take whatever precautions are necessary |
448 | * (such as holding appropriate locks) to avoid racing |
469 | * (such as holding appropriate locks) to avoid racing |
449 | * with another list-mutation primitive, such as hlist_add_head_rcu() |
470 | * with another list-mutation primitive, such as hlist_add_head_rcu() |
450 | * or hlist_del_rcu(), running on this same list. |
471 | * or hlist_del_rcu(), running on this same list. |
451 | * However, it is perfectly legal to run concurrently with |
472 | * However, it is perfectly legal to run concurrently with |
452 | * the _rcu list-traversal primitives, such as |
473 | * the _rcu list-traversal primitives, such as |
453 | * hlist_for_each_entry_rcu(), used to prevent memory-consistency |
474 | * hlist_for_each_entry_rcu(), used to prevent memory-consistency |
454 | * problems on Alpha CPUs. Regardless of the type of CPU, the |
475 | * problems on Alpha CPUs. Regardless of the type of CPU, the |
455 | * list-traversal primitive must be guarded by rcu_read_lock(). |
476 | * list-traversal primitive must be guarded by rcu_read_lock(). |
456 | */ |
477 | */ |
457 | static inline void hlist_add_head_rcu(struct hlist_node *n, |
478 | static inline void hlist_add_head_rcu(struct hlist_node *n, |
458 | struct hlist_head *h) |
479 | struct hlist_head *h) |
459 | { |
480 | { |
460 | struct hlist_node *first = h->first; |
481 | struct hlist_node *first = h->first; |
461 | 482 | ||
462 | n->next = first; |
483 | n->next = first; |
463 | n->pprev = &h->first; |
484 | n->pprev = &h->first; |
464 | rcu_assign_pointer(hlist_first_rcu(h), n); |
485 | rcu_assign_pointer(hlist_first_rcu(h), n); |
465 | if (first) |
486 | if (first) |
466 | first->pprev = &n->next; |
487 | first->pprev = &n->next; |
467 | } |
488 | } |
468 | 489 | ||
469 | /** |
490 | /** |
470 | * hlist_add_before_rcu |
491 | * hlist_add_before_rcu |
471 | * @n: the new element to add to the hash list. |
492 | * @n: the new element to add to the hash list. |
472 | * @next: the existing element to add the new element before. |
493 | * @next: the existing element to add the new element before. |
473 | * |
494 | * |
474 | * Description: |
495 | * Description: |
475 | * Adds the specified element to the specified hlist |
496 | * Adds the specified element to the specified hlist |
476 | * before the specified node while permitting racing traversals. |
497 | * before the specified node while permitting racing traversals. |
477 | * |
498 | * |
478 | * The caller must take whatever precautions are necessary |
499 | * The caller must take whatever precautions are necessary |
479 | * (such as holding appropriate locks) to avoid racing |
500 | * (such as holding appropriate locks) to avoid racing |
480 | * with another list-mutation primitive, such as hlist_add_head_rcu() |
501 | * with another list-mutation primitive, such as hlist_add_head_rcu() |
481 | * or hlist_del_rcu(), running on this same list. |
502 | * or hlist_del_rcu(), running on this same list. |
482 | * However, it is perfectly legal to run concurrently with |
503 | * However, it is perfectly legal to run concurrently with |
483 | * the _rcu list-traversal primitives, such as |
504 | * the _rcu list-traversal primitives, such as |
484 | * hlist_for_each_entry_rcu(), used to prevent memory-consistency |
505 | * hlist_for_each_entry_rcu(), used to prevent memory-consistency |
485 | * problems on Alpha CPUs. |
506 | * problems on Alpha CPUs. |
486 | */ |
507 | */ |
487 | static inline void hlist_add_before_rcu(struct hlist_node *n, |
508 | static inline void hlist_add_before_rcu(struct hlist_node *n, |
488 | struct hlist_node *next) |
509 | struct hlist_node *next) |
489 | { |
510 | { |
490 | n->pprev = next->pprev; |
511 | n->pprev = next->pprev; |
491 | n->next = next; |
512 | n->next = next; |
492 | rcu_assign_pointer(hlist_pprev_rcu(n), n); |
513 | rcu_assign_pointer(hlist_pprev_rcu(n), n); |
493 | next->pprev = &n->next; |
514 | next->pprev = &n->next; |
494 | } |
515 | } |
495 | 516 | ||
496 | /** |
517 | /** |
497 | * hlist_add_behind_rcu |
518 | * hlist_add_behind_rcu |
498 | * @n: the new element to add to the hash list. |
519 | * @n: the new element to add to the hash list. |
499 | * @prev: the existing element to add the new element after. |
520 | * @prev: the existing element to add the new element after. |
500 | * |
521 | * |
501 | * Description: |
522 | * Description: |
502 | * Adds the specified element to the specified hlist |
523 | * Adds the specified element to the specified hlist |
503 | * after the specified node while permitting racing traversals. |
524 | * after the specified node while permitting racing traversals. |
504 | * |
525 | * |
505 | * The caller must take whatever precautions are necessary |
526 | * The caller must take whatever precautions are necessary |
506 | * (such as holding appropriate locks) to avoid racing |
527 | * (such as holding appropriate locks) to avoid racing |
507 | * with another list-mutation primitive, such as hlist_add_head_rcu() |
528 | * with another list-mutation primitive, such as hlist_add_head_rcu() |
508 | * or hlist_del_rcu(), running on this same list. |
529 | * or hlist_del_rcu(), running on this same list. |
509 | * However, it is perfectly legal to run concurrently with |
530 | * However, it is perfectly legal to run concurrently with |
510 | * the _rcu list-traversal primitives, such as |
531 | * the _rcu list-traversal primitives, such as |
511 | * hlist_for_each_entry_rcu(), used to prevent memory-consistency |
532 | * hlist_for_each_entry_rcu(), used to prevent memory-consistency |
512 | * problems on Alpha CPUs. |
533 | * problems on Alpha CPUs. |
513 | */ |
534 | */ |
514 | static inline void hlist_add_behind_rcu(struct hlist_node *n, |
535 | static inline void hlist_add_behind_rcu(struct hlist_node *n, |
515 | struct hlist_node *prev) |
536 | struct hlist_node *prev) |
516 | { |
537 | { |
517 | n->next = prev->next; |
538 | n->next = prev->next; |
518 | n->pprev = &prev->next; |
539 | n->pprev = &prev->next; |
519 | rcu_assign_pointer(hlist_next_rcu(prev), n); |
540 | rcu_assign_pointer(hlist_next_rcu(prev), n); |
520 | if (n->next) |
541 | if (n->next) |
521 | n->next->pprev = &n->next; |
542 | n->next->pprev = &n->next; |
522 | } |
543 | } |
523 | 544 | ||
524 | #define __hlist_for_each_rcu(pos, head) \ |
545 | #define __hlist_for_each_rcu(pos, head) \ |
525 | for (pos = rcu_dereference(hlist_first_rcu(head)); \ |
546 | for (pos = rcu_dereference(hlist_first_rcu(head)); \ |
526 | pos; \ |
547 | pos; \ |
527 | pos = rcu_dereference(hlist_next_rcu(pos))) |
548 | pos = rcu_dereference(hlist_next_rcu(pos))) |
528 | 549 | ||
529 | /** |
550 | /** |
530 | * hlist_for_each_entry_rcu - iterate over rcu list of given type |
551 | * hlist_for_each_entry_rcu - iterate over rcu list of given type |
531 | * @pos: the type * to use as a loop cursor. |
552 | * @pos: the type * to use as a loop cursor. |
532 | * @head: the head for your list. |
553 | * @head: the head for your list. |
533 | * @member: the name of the hlist_node within the struct. |
554 | * @member: the name of the hlist_node within the struct. |
534 | * |
555 | * |
535 | * This list-traversal primitive may safely run concurrently with |
556 | * This list-traversal primitive may safely run concurrently with |
536 | * the _rcu list-mutation primitives such as hlist_add_head_rcu() |
557 | * the _rcu list-mutation primitives such as hlist_add_head_rcu() |
537 | * as long as the traversal is guarded by rcu_read_lock(). |
558 | * as long as the traversal is guarded by rcu_read_lock(). |
538 | */ |
559 | */ |
539 | #define hlist_for_each_entry_rcu(pos, head, member) \ |
560 | #define hlist_for_each_entry_rcu(pos, head, member) \ |
540 | for (pos = hlist_entry_safe (rcu_dereference_raw(hlist_first_rcu(head)),\ |
561 | for (pos = hlist_entry_safe (rcu_dereference_raw(hlist_first_rcu(head)),\ |
541 | typeof(*(pos)), member); \ |
562 | typeof(*(pos)), member); \ |
542 | pos; \ |
563 | pos; \ |
543 | pos = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu(\ |
564 | pos = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu(\ |
544 | &(pos)->member)), typeof(*(pos)), member)) |
565 | &(pos)->member)), typeof(*(pos)), member)) |
545 | 566 | ||
546 | /** |
567 | /** |
547 | * hlist_for_each_entry_rcu_notrace - iterate over rcu list of given type (for tracing) |
568 | * hlist_for_each_entry_rcu_notrace - iterate over rcu list of given type (for tracing) |
548 | * @pos: the type * to use as a loop cursor. |
569 | * @pos: the type * to use as a loop cursor. |
549 | * @head: the head for your list. |
570 | * @head: the head for your list. |
550 | * @member: the name of the hlist_node within the struct. |
571 | * @member: the name of the hlist_node within the struct. |
551 | * |
572 | * |
552 | * This list-traversal primitive may safely run concurrently with |
573 | * This list-traversal primitive may safely run concurrently with |
553 | * the _rcu list-mutation primitives such as hlist_add_head_rcu() |
574 | * the _rcu list-mutation primitives such as hlist_add_head_rcu() |
554 | * as long as the traversal is guarded by rcu_read_lock(). |
575 | * as long as the traversal is guarded by rcu_read_lock(). |
555 | * |
576 | * |
556 | * This is the same as hlist_for_each_entry_rcu() except that it does |
577 | * This is the same as hlist_for_each_entry_rcu() except that it does |
557 | * not do any RCU debugging or tracing. |
578 | * not do any RCU debugging or tracing. |
558 | */ |
579 | */ |
559 | #define hlist_for_each_entry_rcu_notrace(pos, head, member) \ |
580 | #define hlist_for_each_entry_rcu_notrace(pos, head, member) \ |
560 | for (pos = hlist_entry_safe (rcu_dereference_raw_notrace(hlist_first_rcu(head)),\ |
581 | for (pos = hlist_entry_safe (rcu_dereference_raw_notrace(hlist_first_rcu(head)),\ |
561 | typeof(*(pos)), member); \ |
582 | typeof(*(pos)), member); \ |
562 | pos; \ |
583 | pos; \ |
563 | pos = hlist_entry_safe(rcu_dereference_raw_notrace(hlist_next_rcu(\ |
584 | pos = hlist_entry_safe(rcu_dereference_raw_notrace(hlist_next_rcu(\ |
564 | &(pos)->member)), typeof(*(pos)), member)) |
585 | &(pos)->member)), typeof(*(pos)), member)) |
565 | 586 | ||
566 | /** |
587 | /** |
567 | * hlist_for_each_entry_rcu_bh - iterate over rcu list of given type |
588 | * hlist_for_each_entry_rcu_bh - iterate over rcu list of given type |
568 | * @pos: the type * to use as a loop cursor. |
589 | * @pos: the type * to use as a loop cursor. |
569 | * @head: the head for your list. |
590 | * @head: the head for your list. |
570 | * @member: the name of the hlist_node within the struct. |
591 | * @member: the name of the hlist_node within the struct. |
571 | * |
592 | * |
572 | * This list-traversal primitive may safely run concurrently with |
593 | * This list-traversal primitive may safely run concurrently with |
573 | * the _rcu list-mutation primitives such as hlist_add_head_rcu() |
594 | * the _rcu list-mutation primitives such as hlist_add_head_rcu() |
574 | * as long as the traversal is guarded by rcu_read_lock(). |
595 | * as long as the traversal is guarded by rcu_read_lock(). |
575 | */ |
596 | */ |
576 | #define hlist_for_each_entry_rcu_bh(pos, head, member) \ |
597 | #define hlist_for_each_entry_rcu_bh(pos, head, member) \ |
577 | for (pos = hlist_entry_safe(rcu_dereference_bh(hlist_first_rcu(head)),\ |
598 | for (pos = hlist_entry_safe(rcu_dereference_bh(hlist_first_rcu(head)),\ |
578 | typeof(*(pos)), member); \ |
599 | typeof(*(pos)), member); \ |
579 | pos; \ |
600 | pos; \ |
580 | pos = hlist_entry_safe(rcu_dereference_bh(hlist_next_rcu(\ |
601 | pos = hlist_entry_safe(rcu_dereference_bh(hlist_next_rcu(\ |
581 | &(pos)->member)), typeof(*(pos)), member)) |
602 | &(pos)->member)), typeof(*(pos)), member)) |
582 | 603 | ||
583 | /** |
604 | /** |
584 | * hlist_for_each_entry_continue_rcu - iterate over a hlist continuing after current point |
605 | * hlist_for_each_entry_continue_rcu - iterate over a hlist continuing after current point |
585 | * @pos: the type * to use as a loop cursor. |
606 | * @pos: the type * to use as a loop cursor. |
586 | * @member: the name of the hlist_node within the struct. |
607 | * @member: the name of the hlist_node within the struct. |
587 | */ |
608 | */ |
588 | #define hlist_for_each_entry_continue_rcu(pos, member) \ |
609 | #define hlist_for_each_entry_continue_rcu(pos, member) \ |
589 | for (pos = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu( \ |
610 | for (pos = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu( \ |
590 | &(pos)->member)), typeof(*(pos)), member); \ |
611 | &(pos)->member)), typeof(*(pos)), member); \ |
591 | pos; \ |
612 | pos; \ |
592 | pos = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu( \ |
613 | pos = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu( \ |
593 | &(pos)->member)), typeof(*(pos)), member)) |
614 | &(pos)->member)), typeof(*(pos)), member)) |
594 | 615 | ||
595 | /** |
616 | /** |
596 | * hlist_for_each_entry_continue_rcu_bh - iterate over a hlist continuing after current point |
617 | * hlist_for_each_entry_continue_rcu_bh - iterate over a hlist continuing after current point |
597 | * @pos: the type * to use as a loop cursor. |
618 | * @pos: the type * to use as a loop cursor. |
598 | * @member: the name of the hlist_node within the struct. |
619 | * @member: the name of the hlist_node within the struct. |
599 | */ |
620 | */ |
600 | #define hlist_for_each_entry_continue_rcu_bh(pos, member) \ |
621 | #define hlist_for_each_entry_continue_rcu_bh(pos, member) \ |
601 | for (pos = hlist_entry_safe(rcu_dereference_bh(hlist_next_rcu( \ |
622 | for (pos = hlist_entry_safe(rcu_dereference_bh(hlist_next_rcu( \ |
602 | &(pos)->member)), typeof(*(pos)), member); \ |
623 | &(pos)->member)), typeof(*(pos)), member); \ |
603 | pos; \ |
624 | pos; \ |
604 | pos = hlist_entry_safe(rcu_dereference_bh(hlist_next_rcu( \ |
625 | pos = hlist_entry_safe(rcu_dereference_bh(hlist_next_rcu( \ |
605 | &(pos)->member)), typeof(*(pos)), member)) |
626 | &(pos)->member)), typeof(*(pos)), member)) |
606 | 627 | ||
607 | /** |
628 | /** |
608 | * hlist_for_each_entry_from_rcu - iterate over a hlist continuing from current point |
629 | * hlist_for_each_entry_from_rcu - iterate over a hlist continuing from current point |
609 | * @pos: the type * to use as a loop cursor. |
630 | * @pos: the type * to use as a loop cursor. |
610 | * @member: the name of the hlist_node within the struct. |
631 | * @member: the name of the hlist_node within the struct. |
611 | */ |
632 | */ |
612 | #define hlist_for_each_entry_from_rcu(pos, member) \ |
633 | #define hlist_for_each_entry_from_rcu(pos, member) \ |
613 | for (; pos; \ |
634 | for (; pos; \ |
614 | pos = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu( \ |
635 | pos = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu( \ |
615 | &(pos)->member)), typeof(*(pos)), member)) |
636 | &(pos)->member)), typeof(*(pos)), member)) |
616 | 637 | ||
617 | #endif /* __KERNEL__ */ |
638 | #endif /* __KERNEL__ */ |
618 | #endif |
639 | #endif |