Skip to content
  • Herbert Xu's avatar
    [PATCH] list: add missing rcu_dereference on first element · b24d18aa
    Herbert Xu authored
    
    
    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: default avatarHerbert Xu <herbert@gondor.apana.org.au>
    Acked-by: default avatar"Paul E. McKenney" <paulmck@us.ibm.com>
    Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
    b24d18aa