All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Nick Piggin <nickpiggin@yahoo.com.au>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>, Pavel Machek <pavel@suse.cz>,
	kernel list <linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@osdl.org>,
	mtk.manpages@gmail.com, rdunlap@xenotime.net,
	linux-doc@vger.kernel.org, segher@kernel.crashing.org,
	rth@gcc.gnu.org
Subject: Re: atomics: document that linux expects certain atomic behaviour from unsigned long
Date: Mon, 5 Jan 2009 09:30:04 -0800	[thread overview]
Message-ID: <20090105173004.GG6959@linux.vnet.ibm.com> (raw)
In-Reply-To: <200901060325.13362.nickpiggin@yahoo.com.au>

On Tue, Jan 06, 2009 at 03:25:12AM +1100, Nick Piggin wrote:
> On Tuesday 06 January 2009 03:05:01 Paul E. McKenney wrote:
> > On Mon, Jan 05, 2009 at 11:00:24PM +1100, Nick Piggin wrote:
> > > On Monday 05 January 2009 22:23:50 Alan Cox wrote:
> > > > > Pretty much everywhere that uses RCU for example does so using atomic
> > > > > pointer loads and stores. The nastiest issue IMO actually is
> > > > > reloading the value through the pointer even if it isn't explicitly
> > > > > dereferenced. RCU gets this right with ACCESS_ONCE. Probably a lot of
> > > > > code using basic types does not. x86 atomic_read maybe should be
> > > > > using ACCESS_ONCE too...
> > > >
> > > > I'm pretty sure it should. gcc makes no guarantees about not being
> > > > clever with accesses.
> > >
> > > Arguably it should. I don't know what the concurrent C standard looks
> > > like, but prohibiting reloads of potentially concurrently modified memory
> > > when there is no explicit pointer dereference is the natural complement
> > > to prohibiting stores to potentially concurrently read memory when there
> > > is no explicit store (which I think is begrudgingly agreed to be a
> > > problem).
> > >
> > > http://lkml.org/lkml/2007/10/24/673
> > >
> > > I think I would like to see multiple reloads to local variables
> > > prohibited, to avoid potential really subtle problems... But if
> > > ACCESS_ONCE is here to stay, then I do think that atomic_read etc should
> > > use it.
> >
> > The concurrency stuff in c++0x still permits the compiler to have its
> > way with loads and stores to normal variables, but provides an "atomic"
> > type that must be loaded and stored as specified in the program.
> 
> So:
> if (trylock())
>   locked = 1;
> ...
> if (locked)
>   *var = blah;
> ...
> if (locked)
>   unlock();
> 
> So the second part can still be transformed into a predicated calculation
> of blah, then an unconditional store to *var?

Assuming that "var" is an ordinary variable...

If you are asking whether the compiler guys believe that they are within
their rights to do a store to *var and then store the old value to *var
if !locked, the unfortunate answer is "yes".  Hence ACCESS_ONCE().

> > The issue with ACCESS_ONCE() is that gcc doesn't do any optimizations on
> > volatile accesses, even the obvious ones.  Speaking of which, the gcc
> > guys kicked out my bug 33102, which was complaining about this
> > situation.  :-/
> 
> Hmm. It's still quite annoying even to have to switch everything to the
> atomic type. I guarantee there will be bugs in Linux caused by the
> compiler reloading pointers/longs/ints to access local variables...

Another approach would be to change ACCESS_ONCE() to use the atomic
types.  Then we have a bigger hammer with which to beat the gcc guys
about optimizations.  We can hope, anyway...

							Thanx, Paul

  reply	other threads:[~2009-01-05 17:30 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-03 12:44 atomics: document that linux expects certain atomic behaviour from unsigned long Pavel Machek
2009-01-03 20:19 ` Alan Cox
2009-01-03 20:27   ` Pavel Machek
2009-01-03 20:30     ` Alan Cox
2009-01-03 20:56       ` Pavel Machek
2009-01-03 23:01         ` david
2009-01-03 23:14         ` Alan Cox
2009-01-05 10:54           ` Nick Piggin
2009-01-05 11:23             ` Alan Cox
2009-01-05 12:00               ` Nick Piggin
2009-01-05 16:05                 ` Paul E. McKenney
2009-01-05 16:25                   ` Nick Piggin
2009-01-05 17:30                     ` Paul E. McKenney [this message]
2009-01-05 18:25                       ` Nick Piggin
2009-01-05 22:01                         ` Paul E. McKenney
2009-01-03 23:53         ` Robert Hancock
2009-01-04 18:05       ` Tilman Schmidt

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=20090105173004.GG6959@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=akpm@osdl.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mtk.manpages@gmail.com \
    --cc=nickpiggin@yahoo.com.au \
    --cc=pavel@suse.cz \
    --cc=rdunlap@xenotime.net \
    --cc=rth@gcc.gnu.org \
    --cc=segher@kernel.crashing.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.