Skip to content

Commit 67bdbff

Browse files
arndbpaulmck
authored andcommitted
rculist: avoid __rcu annotations
This avoids warnings from missing __rcu annotations in the rculist implementation, making it possible to use the same lists in both RCU and non-RCU cases. We can add rculist annotations later, together with lockdep support for rculist, which is missing as well, but that may involve changing all the users. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Pavel Emelyanov <xemul@openvz.org> Cc: Sukadev Bhattiprolu <sukadev@us.ibm.com> Reviewed-by: Josh Triplett <josh@joshtriplett.org>
1 parent ca5ecdd commit 67bdbff

3 files changed

Lines changed: 46 additions & 25 deletions

File tree

‎include/linux/rculist.h‎

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
#include <linux/list.h>
1010
#include <linux/rcupdate.h>
1111

12+
/*
13+
* return the ->next pointer of a list_head in an rcu safe
14+
* way, we must not access it directly
15+
*/
16+
#define list_next_rcu(list) (*((struct list_head __rcu **)(&(list)->next)))
17+
1218
/*
1319
* Insert a new entry between two known consecutive entries.
1420
*
@@ -20,7 +26,7 @@ static inline void __list_add_rcu(struct list_head *new,
2026
{
2127
new->next = next;
2228
new->prev = prev;
23-
rcu_assign_pointer(prev->next, new);
29+
rcu_assign_pointer(list_next_rcu(prev), new);
2430
next->prev = new;
2531
}
2632

@@ -138,7 +144,7 @@ static inline void list_replace_rcu(struct list_head *old,
138144
{
139145
new->next = old->next;
140146
new->prev = old->prev;
141-
rcu_assign_pointer(new->prev->next, new);
147+
rcu_assign_pointer(list_next_rcu(new->prev), new);
142148
new->next->prev = new;
143149
old->prev = LIST_POISON2;
144150
}
@@ -193,7 +199,7 @@ static inline void list_splice_init_rcu(struct list_head *list,
193199
*/
194200

195201
last->next = at;
196-
rcu_assign_pointer(head->next, first);
202+
rcu_assign_pointer(list_next_rcu(head), first);
197203
first->prev = head;
198204
at->prev = last;
199205
}
@@ -208,7 +214,9 @@ static inline void list_splice_init_rcu(struct list_head *list,
208214
* primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock().
209215
*/
210216
#define list_entry_rcu(ptr, type, member) \
211-
container_of(rcu_dereference_raw(ptr), type, member)
217+
({typeof (*ptr) __rcu *__ptr = (typeof (*ptr) __rcu __force *)ptr; \
218+
container_of((typeof(ptr))rcu_dereference_raw(__ptr), type, member); \
219+
})
212220

213221
/**
214222
* list_first_entry_rcu - get the first element from a list
@@ -225,9 +233,9 @@ static inline void list_splice_init_rcu(struct list_head *list,
225233
list_entry_rcu((ptr)->next, type, member)
226234

227235
#define __list_for_each_rcu(pos, head) \
228-
for (pos = rcu_dereference_raw((head)->next); \
236+
for (pos = rcu_dereference_raw(list_next_rcu(head)); \
229237
pos != (head); \
230-
pos = rcu_dereference_raw(pos->next))
238+
pos = rcu_dereference_raw(list_next_rcu((pos)))
231239

232240
/**
233241
* list_for_each_entry_rcu - iterate over rcu list of given type
@@ -257,9 +265,9 @@ static inline void list_splice_init_rcu(struct list_head *list,
257265
* as long as the traversal is guarded by rcu_read_lock().
258266
*/
259267
#define list_for_each_continue_rcu(pos, head) \
260-
for ((pos) = rcu_dereference_raw((pos)->next); \
268+
for ((pos) = rcu_dereference_raw(list_next_rcu(pos)); \
261269
prefetch((pos)->next), (pos) != (head); \
262-
(pos) = rcu_dereference_raw((pos)->next))
270+
(pos) = rcu_dereference_raw(list_next_rcu(pos)))
263271

264272
/**
265273
* list_for_each_entry_continue_rcu - continue iteration over list of given type
@@ -314,12 +322,19 @@ static inline void hlist_replace_rcu(struct hlist_node *old,
314322

315323
new->next = next;
316324
new->pprev = old->pprev;
317-
rcu_assign_pointer(*new->pprev, new);
325+
rcu_assign_pointer(*(struct hlist_node __rcu **)new->pprev, new);
318326
if (next)
319327
new->next->pprev = &new->next;
320328
old->pprev = LIST_POISON2;
321329
}
322330

331+
/*
332+
* return the first or the next element in an RCU protected hlist
333+
*/
334+
#define hlist_first_rcu(head) (*((struct hlist_node __rcu **)(&(head)->first)))
335+
#define hlist_next_rcu(node) (*((struct hlist_node __rcu **)(&(node)->next)))
336+
#define hlist_pprev_rcu(node) (*((struct hlist_node __rcu **)((node)->pprev)))
337+
323338
/**
324339
* hlist_add_head_rcu
325340
* @n: the element to add to the hash list.
@@ -346,7 +361,7 @@ static inline void hlist_add_head_rcu(struct hlist_node *n,
346361

347362
n->next = first;
348363
n->pprev = &h->first;
349-
rcu_assign_pointer(h->first, n);
364+
rcu_assign_pointer(hlist_first_rcu(h), n);
350365
if (first)
351366
first->pprev = &n->next;
352367
}
@@ -374,7 +389,7 @@ static inline void hlist_add_before_rcu(struct hlist_node *n,
374389
{
375390
n->pprev = next->pprev;
376391
n->next = next;
377-
rcu_assign_pointer(*(n->pprev), n);
392+
rcu_assign_pointer(hlist_pprev_rcu(n), n);
378393
next->pprev = &n->next;
379394
}
380395

@@ -401,15 +416,15 @@ static inline void hlist_add_after_rcu(struct hlist_node *prev,
401416
{
402417
n->next = prev->next;
403418
n->pprev = &prev->next;
404-
rcu_assign_pointer(prev->next, n);
419+
rcu_assign_pointer(hlist_next_rcu(prev), n);
405420
if (n->next)
406421
n->next->pprev = &n->next;
407422
}
408423

409-
#define __hlist_for_each_rcu(pos, head) \
410-
for (pos = rcu_dereference((head)->first); \
411-
pos && ({ prefetch(pos->next); 1; }); \
412-
pos = rcu_dereference(pos->next))
424+
#define __hlist_for_each_rcu(pos, head) \
425+
for (pos = rcu_dereference(hlist_first_rcu(head)); \
426+
pos && ({ prefetch(pos->next); 1; }); \
427+
pos = rcu_dereference(hlist_next_rcu(pos)))
413428

414429
/**
415430
* hlist_for_each_entry_rcu - iterate over rcu list of given type
@@ -422,11 +437,11 @@ static inline void hlist_add_after_rcu(struct hlist_node *prev,
422437
* the _rcu list-mutation primitives such as hlist_add_head_rcu()
423438
* as long as the traversal is guarded by rcu_read_lock().
424439
*/
425-
#define hlist_for_each_entry_rcu(tpos, pos, head, member) \
426-
for (pos = rcu_dereference_raw((head)->first); \
440+
#define hlist_for_each_entry_rcu(tpos, pos, head, member) \
441+
for (pos = rcu_dereference_raw(hlist_first_rcu(head)); \
427442
pos && ({ prefetch(pos->next); 1; }) && \
428443
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1; }); \
429-
pos = rcu_dereference_raw(pos->next))
444+
pos = rcu_dereference_raw(hlist_next_rcu(pos)))
430445

431446
/**
432447
* hlist_for_each_entry_rcu_bh - iterate over rcu list of given type

‎include/linux/rculist_nulls.h‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ static inline void hlist_nulls_del_init_rcu(struct hlist_nulls_node *n)
3737
}
3838
}
3939

40+
#define hlist_nulls_first_rcu(head) \
41+
(*((struct hlist_nulls_node __rcu __force **)&(head)->first))
42+
43+
#define hlist_nulls_next_rcu(node) \
44+
(*((struct hlist_nulls_node __rcu __force **)&(node)->next))
45+
4046
/**
4147
* hlist_nulls_del_rcu - deletes entry from hash list without re-initialization
4248
* @n: the element to delete from the hash list.
@@ -88,7 +94,7 @@ static inline void hlist_nulls_add_head_rcu(struct hlist_nulls_node *n,
8894

8995
n->next = first;
9096
n->pprev = &h->first;
91-
rcu_assign_pointer(h->first, n);
97+
rcu_assign_pointer(hlist_nulls_first_rcu(h), n);
9298
if (!is_a_nulls(first))
9399
first->pprev = &n->next;
94100
}
@@ -100,11 +106,11 @@ static inline void hlist_nulls_add_head_rcu(struct hlist_nulls_node *n,
100106
* @member: the name of the hlist_nulls_node within the struct.
101107
*
102108
*/
103-
#define hlist_nulls_for_each_entry_rcu(tpos, pos, head, member) \
104-
for (pos = rcu_dereference_raw((head)->first); \
105-
(!is_a_nulls(pos)) && \
109+
#define hlist_nulls_for_each_entry_rcu(tpos, pos, head, member) \
110+
for (pos = rcu_dereference_raw(hlist_nulls_first_rcu(head)); \
111+
(!is_a_nulls(pos)) && \
106112
({ tpos = hlist_nulls_entry(pos, typeof(*tpos), member); 1; }); \
107-
pos = rcu_dereference_raw(pos->next))
113+
pos = rcu_dereference_raw(hlist_nulls_next_rcu(pos)))
108114

109115
#endif
110116
#endif

‎kernel/pid.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ struct task_struct *pid_task(struct pid *pid, enum pid_type type)
401401
struct task_struct *result = NULL;
402402
if (pid) {
403403
struct hlist_node *first;
404-
first = rcu_dereference_check(pid->tasks[type].first,
404+
first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
405405
rcu_read_lock_held() ||
406406
lockdep_tasklist_lock_is_held());
407407
if (first)

0 commit comments

Comments
 (0)