[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CA+55aFyktcMZnQHqoaCePgJVXmbi=9pTS_jz7j+j=QDuSoSFoA@mail.gmail.com>
Date: Mon, 24 Nov 2014 16:00:55 -0800
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: Alexei Starovoitov <alexei.starovoitov@...il.com>
Cc: David Howells <dhowells@...hat.com>,
Christian Borntraeger <borntraeger@...ibm.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linux-arch@...r.kernel.org" <linux-arch@...r.kernel.org>,
linux-mips <linux-mips@...ux-mips.org>,
linux-x86_64@...r.kernel.org,
linux-s390 <linux-s390@...r.kernel.org>,
Paolo Bonzini <pbonzini@...hat.com>,
Paul McKenney <paulmck@...ux.vnet.ibm.com>,
Ingo Molnar <mingo@...nel.org>,
Catalin Marinas <catalin.marinas@....com>,
Will Deacon <will.deacon@....com>
Subject: Re: [PATCH/RFC 7/7] kernel: Force ACCESS_ONCE to work only on scalar types
On Mon, Nov 24, 2014 at 2:58 PM, Alexei Starovoitov
<alexei.starovoitov@...il.com> wrote:
>
> I've changed gcc pr58145-1.c reproducer to use
> __read_once_size() approach above
I don't think you did.
> modified reproducer:
> struct S { unsigned int data; };
> void bar(int val)
> {
> struct S _s = { .data = val };
> *(volatile struct S *) 0x880000UL = ACCESS_ONCE(&_s);
> }
My approach never had "volatile struct S *". The only volatile
pointers were the actual byte/word/etc pointers, and those generated
temporary values that were then assigned to the final type through a
cast.
Also, note that the kernel is compiled without strict aliasing, so the
casting to 'void *' and various smaller types is "safe" - even if the
C standard doesn't like it.
With strict aliasing, you'd need to make the read_once() macro not
just pass in the size, there would have to be some kind of union of
the type, and that would effectively mean that you can't use an inline
function, you'd have to do it in a big macro (because the type would
be per-site).
So with strict aliasing, you'd have to make it something like
#define ACCESS_ONCE(p) \
({ union { typeof(*p) __val; char __array[sizeof(*p)]} __u;
__read_once_size(p, __u.__array, sizeof(__u)); __u.__val; })
Pretty? No. But then, the standard C aliasing rules are so broken that
"pretty" doesn't really come into play..
Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists