Re: Memory corruption due to word sharing
From: Paul E. McKenney
Date: Thu Feb 02 2012 - 13:42:44 EST
On Wed, Feb 01, 2012 at 03:11:00PM -0800, Linus Torvalds wrote:
> On Wed, Feb 1, 2012 at 2:45 PM, Paul E. McKenney
> <paulmck@xxxxxxxxxxxxxxxxxx> wrote:
> > My (perhaps forlorn and naive) hope is that C++11 memory_order_relaxed
> > will eventually allow ACCESS_ONCE() to be upgraded so that (for example)
> > access-once increments can generate a single increment-memory instruction
> > on x86.
> I don't think that is a semantic issue.
> gcc could do it *today* with volatile accesses. It doesn't, because
> volatiles are scary and basically disables a lot of optimizations. Why
> would memory ordering be substantially different just because it has a
> different name?
I too would much prefer that gcc volatile worked more sanely.
But several people, including me, pushed on that and consistently got back
"the standard doesn't say we have to do that".
So I got together with the standards people and now there is something
(memory_order_relaxed atomics) that is specified to work the way we want
it to. Of course, it will likely be quite some time before it appears
in usable form in gcc, but probably quite a bit less time than we have
been pushing on the gcc folks about volatile.
> > New architectures might eventually might define things like atomic_inc()
> > in terms of C++11 atomics, but let's start with the straightforward stuff
> > as and if it makes sense.
> SMP-atomic or percpu atomic? Or both?
> We need both variants in the kernel. If the compiler generates one of
> them for us, that doesn't really much help.
I must admit that the non-x86 per-CPU atomics are, ummm, "interesting".
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/