LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Franck Bui-Huu <vagabon.xyz@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Josh Triplett <josh@kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] rculist.h: use the rcu API
Date: Thu, 15 May 2008 07:48:31 -0700	[thread overview]
Message-ID: <20080515144831.GB9023@linux.vnet.ibm.com> (raw)
In-Reply-To: <20080515055011.GA12809@martell.zuzino.mipt.ru>

On Thu, May 15, 2008 at 09:50:11AM +0400, Alexey Dobriyan wrote:
> On Wed, May 14, 2008 at 11:26:18PM +0200, Franck Bui-Huu wrote:
> > This patch makes almost all list mutation primitives use
> > rcu_assign_pointer().
> >
> > The main point of this being readability improvement.
> 
> Which is not an improvement at all.
> 
> > --- a/include/linux/rculist.h
> > +++ b/include/linux/rculist.h
> > @@ -17,9 +18,8 @@ static inline void __list_add_rcu(struct list_head *new,
> > {
> > 	new->next = next;
> > 	new->prev = prev;
> > -	smp_wmb();
> > +	rcu_assign_pointer(prev->next, new);
> > 	next->prev = new;
> > -	prev->next = new;
> > }
> 
> Nice chunk to demonstrate.
> 
> Before one could write this like:
> 
> 	smp_wmb();			smp_wmb();
> 	next->prev = new;	or	prev->next = new;
> 	prev->next = new;		next->prev = new;
> 
> And both examples aren't buggy.
> 
> After, you can't write:
> 
> 	next->prev = new;
> 	rcu_assign_pointer(prev->next, new);
> 
> Guess why?

Strangely enough, you actually can do this, because RCU readers are
not permitted to follow the prev pointers.  Any RCU readers who try to
follow the prev pointers are subject to failures due to list_del_rcu()'s
assignment:

	entry->prev = LIST_POISON2;

So this change is not in fact relying on undocumented rcu_assign_pointer()
side effects.

							Thanx, Paul

> This barrier is related not only to next assignment, but to the whole
> group of assignments.
> 
> > @@ -108,9 +108,8 @@ static inline void list_replace_rcu(struct list_head 
> > *old,
> > {
> > 	new->next = old->next;
> > 	new->prev = old->prev;
> > -	smp_wmb();
> > +	rcu_assign_pointer(new->prev->next, new);
> > 	new->next->prev = new;
> > -	new->prev->next = new;
> > 	old->prev = LIST_POISON2;
> > }
> 

  reply	other threads:[~2008-05-15 14:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-14 21:24 [PATCH 1/2] Split list.h and move rcu-protected lists into rculist.h Franck Bui-Huu
2008-05-14 21:26 ` [PATCH 2/2] rculist.h: use the rcu API Franck Bui-Huu
2008-05-15  5:50   ` Alexey Dobriyan
2008-05-15 14:48     ` Paul E. McKenney [this message]
     [not found] <47BAC1E6.2050901@gmail.com>
2008-02-19 11:51 ` Franck Bui-Huu
  -- strict thread matches above, loose matches on Subject: below --
2008-01-17 20:46 [PATCH 0/2] Make RCU lists use the RCU API Franck Bui-Huu
2008-01-17 20:48 ` [PATCH 2/2] rculist.h: use the rcu API Franck Bui-Huu
2008-01-18  5:55   ` Paul E. McKenney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080515144831.GB9023@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=josh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vagabon.xyz@gmail.com \
    --subject='Re: [PATCH 2/2] rculist.h: use the rcu API' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).