diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2005-10-16 23:29:20 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2005-10-17 11:59:10 -0400 |
commit | b24d18aa743dad0c42918157c5d717686269d3a8 (patch) | |
tree | ceade1641a1806c5f3db2f4b344fe9070b488bad /include/linux/list.h | |
parent | 3d80636a0d5f056ffc26472d05b6027a7a9f6e1c (diff) |
[PATCH] list: add missing rcu_dereference on first element
It seems that all the list_*_rcu primitives are missing a memory barrier
on the very first dereference. For example,
#define list_for_each_rcu(pos, head) \
for (pos = (head)->next; prefetch(pos->next), pos != (head); \
pos = rcu_dereference(pos->next))
It will go something like:
pos = (head)->next
prefetch(pos->next)
pos != (head)
do stuff
We're missing a barrier here.
pos = rcu_dereference(pos->next)
fetch pos->next
barrier given by rcu_dereference(pos->next)
store pos
Without the missing barrier, the pos->next value may turn out to be stale.
In fact, if "do stuff" were also dereferencing pos and relying on
list_for_each_rcu to provide the barrier then it may also break.
So here is a patch to make sure that we have a barrier for the first
element in the list.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Acked-by: "Paul E. McKenney" <paulmck@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'include/linux/list.h')
-rw-r--r-- | include/linux/list.h | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/include/linux/list.h b/include/linux/list.h index e6ec59682274..084971f333fe 100644 --- a/include/linux/list.h +++ b/include/linux/list.h | |||
@@ -442,12 +442,14 @@ static inline void list_splice_init(struct list_head *list, | |||
442 | * as long as the traversal is guarded by rcu_read_lock(). | 442 | * as long as the traversal is guarded by rcu_read_lock(). |
443 | */ | 443 | */ |
444 | #define list_for_each_rcu(pos, head) \ | 444 | #define list_for_each_rcu(pos, head) \ |
445 | for (pos = (head)->next; prefetch(pos->next), pos != (head); \ | 445 | for (pos = (head)->next; \ |
446 | pos = rcu_dereference(pos->next)) | 446 | prefetch(rcu_dereference(pos)->next), pos != (head); \ |
447 | pos = pos->next) | ||
447 | 448 | ||
448 | #define __list_for_each_rcu(pos, head) \ | 449 | #define __list_for_each_rcu(pos, head) \ |
449 | for (pos = (head)->next; pos != (head); \ | 450 | for (pos = (head)->next; \ |
450 | pos = rcu_dereference(pos->next)) | 451 | rcu_dereference(pos) != (head); \ |
452 | pos = pos->next) | ||
451 | 453 | ||
452 | /** | 454 | /** |
453 | * list_for_each_safe_rcu - iterate over an rcu-protected list safe | 455 | * list_for_each_safe_rcu - iterate over an rcu-protected list safe |
@@ -461,8 +463,9 @@ static inline void list_splice_init(struct list_head *list, | |||
461 | * as long as the traversal is guarded by rcu_read_lock(). | 463 | * as long as the traversal is guarded by rcu_read_lock(). |
462 | */ | 464 | */ |
463 | #define list_for_each_safe_rcu(pos, n, head) \ | 465 | #define list_for_each_safe_rcu(pos, n, head) \ |
464 | for (pos = (head)->next, n = pos->next; pos != (head); \ | 466 | for (pos = (head)->next; \ |
465 | pos = rcu_dereference(n), n = pos->next) | 467 | n = rcu_dereference(pos)->next, pos != (head); \ |
468 | pos = n) | ||
466 | 469 | ||
467 | /** | 470 | /** |
468 | * list_for_each_entry_rcu - iterate over rcu list of given type | 471 | * list_for_each_entry_rcu - iterate over rcu list of given type |
@@ -474,11 +477,11 @@ static inline void list_splice_init(struct list_head *list, | |||
474 | * the _rcu list-mutation primitives such as list_add_rcu() | 477 | * the _rcu list-mutation primitives such as list_add_rcu() |
475 | * as long as the traversal is guarded by rcu_read_lock(). | 478 | * as long as the traversal is guarded by rcu_read_lock(). |
476 | */ | 479 | */ |
477 | #define list_for_each_entry_rcu(pos, head, member) \ | 480 | #define list_for_each_entry_rcu(pos, head, member) \ |
478 | for (pos = list_entry((head)->next, typeof(*pos), member); \ | 481 | for (pos = list_entry((head)->next, typeof(*pos), member); \ |
479 | prefetch(pos->member.next), &pos->member != (head); \ | 482 | prefetch(rcu_dereference(pos)->member.next), \ |
480 | pos = rcu_dereference(list_entry(pos->member.next, \ | 483 | &pos->member != (head); \ |
481 | typeof(*pos), member))) | 484 | pos = list_entry(pos->member.next, typeof(*pos), member)) |
482 | 485 | ||
483 | 486 | ||
484 | /** | 487 | /** |
@@ -492,8 +495,9 @@ static inline void list_splice_init(struct list_head *list, | |||
492 | * as long as the traversal is guarded by rcu_read_lock(). | 495 | * as long as the traversal is guarded by rcu_read_lock(). |
493 | */ | 496 | */ |
494 | #define list_for_each_continue_rcu(pos, head) \ | 497 | #define list_for_each_continue_rcu(pos, head) \ |
495 | for ((pos) = (pos)->next; prefetch((pos)->next), (pos) != (head); \ | 498 | for ((pos) = (pos)->next; \ |
496 | (pos) = rcu_dereference((pos)->next)) | 499 | prefetch(rcu_dereference((pos))->next), (pos) != (head); \ |
500 | (pos) = (pos)->next) | ||
497 | 501 | ||
498 | /* | 502 | /* |
499 | * Double linked lists with a single pointer list head. | 503 | * Double linked lists with a single pointer list head. |
@@ -696,8 +700,9 @@ static inline void hlist_add_after_rcu(struct hlist_node *prev, | |||
696 | pos = n) | 700 | pos = n) |
697 | 701 | ||
698 | #define hlist_for_each_rcu(pos, head) \ | 702 | #define hlist_for_each_rcu(pos, head) \ |
699 | for ((pos) = (head)->first; pos && ({ prefetch((pos)->next); 1; }); \ | 703 | for ((pos) = (head)->first; \ |
700 | (pos) = rcu_dereference((pos)->next)) | 704 | rcu_dereference((pos)) && ({ prefetch((pos)->next); 1; }); \ |
705 | (pos) = (pos)->next) | ||
701 | 706 | ||
702 | /** | 707 | /** |
703 | * hlist_for_each_entry - iterate over list of given type | 708 | * hlist_for_each_entry - iterate over list of given type |
@@ -762,9 +767,9 @@ static inline void hlist_add_after_rcu(struct hlist_node *prev, | |||
762 | */ | 767 | */ |
763 | #define hlist_for_each_entry_rcu(tpos, pos, head, member) \ | 768 | #define hlist_for_each_entry_rcu(tpos, pos, head, member) \ |
764 | for (pos = (head)->first; \ | 769 | for (pos = (head)->first; \ |
765 | pos && ({ prefetch(pos->next); 1;}) && \ | 770 | rcu_dereference(pos) && ({ prefetch(pos->next); 1;}) && \ |
766 | ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ | 771 | ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ |
767 | pos = rcu_dereference(pos->next)) | 772 | pos = pos->next) |
768 | 773 | ||
769 | #else | 774 | #else |
770 | #warning "don't include kernel headers in userspace" | 775 | #warning "don't include kernel headers in userspace" |