Re: Memory corruption due to word sharing

2012-02-01 Thread Linus Torvalds
On Wed, Feb 1, 2012 at 10:45 AM, Jeff Law wrote: > > Torvald Riegel & I were told that was kernel policy when we brought up the > upcoming bitfield semantic changes with some of the linux kernel folks last > year. Btw, one reason this is true is that the bitfield ordering/packing is so unspecifie

Re: Memory corruption due to word sharing

2012-02-01 Thread Linus Torvalds
On Wed, Feb 1, 2012 at 9:42 AM, Torvald Riegel wrote: > > We need a proper memory model. Not really. The fact is, the kernel will happily take the memory model of the underlying hardware. Trying to impose some compiler description of the memory model is actually horribly bad, because it automati

Re: Memory corruption due to word sharing

2012-02-01 Thread Linus Torvalds
On Wed, Feb 1, 2012 at 11:40 AM, Jakub Jelinek wrote: > > Well, the C++11/C11 model doesn't allow to use the underlying type > for accesses, consider e.g. > > struct S { long s1; unsigned int s2 : 5; unsigned int s3 : 19; unsigned char > s4; unsigned int s5; }; > struct T { long s1 : 16; unsigned

Re: Memory corruption due to word sharing

2012-02-01 Thread Linus Torvalds
On Wed, Feb 1, 2012 at 12:01 PM, Linus Torvalds wrote: > >  - However, while using the *smallest* possible access may generate > correct code, it often generates really *crappy* code. Which is > exactly the bug that I reported in > >   http://gcc.gnu.org/bugzilla/show_bug.cgi?i

Re: Memory corruption due to word sharing

2012-02-01 Thread Linus Torvalds
On Wed, Feb 1, 2012 at 12:16 PM, Jakub Jelinek wrote: >> >> So the kernel really doesn't care what you do to things *within* the >> bitfield. > > But what is *within* the bitfield?  Do you consider s4 or t2 fields > (non-bitfield fields that just the ABI wants to pack together with > the bitfield

Re: Memory corruption due to word sharing

2012-02-01 Thread Linus Torvalds
On Wed, Feb 1, 2012 at 12:41 PM, Torvald Riegel wrote: > > You do rely on the compiler to do common transformations I suppose: > hoist loads out of loops, CSE, etc.  How do you expect the compiler to > know whether they are allowed for a particular piece of code or not? We have barriers. Compile

Re: Memory corruption due to word sharing

2012-02-01 Thread Linus Torvalds
On Wed, Feb 1, 2012 at 12:53 PM, Torvald Riegel wrote: > > For volatile, I agree. > > However, the original btrfs example was *without* a volatile, and that's > why I raised the memory model point.  This triggered an error in a > concurrent execution, so that's memory model land, at least in C > l

Re: Memory corruption due to word sharing

2012-02-01 Thread Linus Torvalds
On Wed, Feb 1, 2012 at 1:24 PM, Torvald Riegel wrote: >> It's not the only thing we do. We have cases where it's not that you >> can't hoist things outside of loops, it's that you have to read things >> exactly *once*, and then use that particular value (ie the compiler >> can't be allowed to relo

Re: Memory corruption due to word sharing

2012-02-01 Thread Linus Torvalds
On Wed, Feb 1, 2012 at 1:25 PM, Boehm, Hans wrote: > > Here are some more interesting ones that illustrate the issues (all > declarations are non-local, unless stated otherwise): > > struct { char a; int b:9; int c:7; char d} x; > > Is x.b = 1 allowed to overwrite x.a?  C11 says no, essentially r

Re: Memory corruption due to word sharing

2012-02-01 Thread Linus Torvalds
On Wed, Feb 1, 2012 at 2:45 PM, Paul E. McKenney 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

Re: Memory corruption due to word sharing

2012-02-02 Thread Linus Torvalds
On Thu, Feb 2, 2012 at 8:28 AM, Michael Matz wrote: > > Sure.  Simplest example: struct s {int i:24;} __attribute__((packed)). > > You must access only three bytes, no matter what.  The basetype (int) is > four bytes. Ok, so here's a really *stupid* (but also really really simple) patch attached.

Re: Memory corruption due to word sharing

2012-02-02 Thread Linus Torvalds
On Thu, Feb 2, 2012 at 10:42 AM, Paul E. McKenney wrote: >> >> SMP-atomic or percpu atomic? Or both? > > Only SMP-atomic. And I assume that since the compiler does them, that would now make it impossible for us to gather a list of all the 'lock' prefixes so that we can undo them if it turns out t

Re: Memory corruption due to word sharing

2012-02-03 Thread Linus Torvalds
On Fri, Feb 3, 2012 at 8:38 AM, Andrew MacLeod wrote: > > The atomic intrinsics were created for c++11  memory model compliance, but I > am certainly open to enhancements that would make them more useful.   I am > planning some enhancements for 4.8 now, and it sounds like you may have some > sugge

Re: Memory corruption due to word sharing

2012-02-03 Thread Linus Torvalds
On Fri, Feb 3, 2012 at 11:16 AM, Andrew MacLeod wrote: >>    The special cases are because older x86 cannot do the generic >> "add_return" efficiently - it needs xadd - but can do atomic versions >> that test the end result and give zero or sign information. > > Since these are older x86 only, cou

Re: BUG: GCC-4.4.x changes the function frame on some functions

2009-11-19 Thread Linus Torvalds
On Thu, 19 Nov 2009, Thomas Gleixner wrote: > > standard function start: > >push %ebp >mov%esp, %ebp > >call mcount > > modified function start on a handful of functions only seen with gcc > 4.4.x on x86 32 bit: > > push %edi > lea

Re: BUG: GCC-4.4.x changes the function frame on some functions

2009-11-19 Thread Linus Torvalds
On Thu, 19 Nov 2009, Richard Guenther wrote: > > Note that I only can reproduce the issue with > -mincoming-stack-boundary=2, not with -mpreferred-stack-boundary=2. Since you can reproduce it with -mincoming-stack-boundary=2, I woul suggest just fixing mcount handling that way regardless of an

Re: BUG: GCC-4.4.x changes the function frame on some functions

2009-11-19 Thread Linus Torvalds
On Thu, 19 Nov 2009, Andrew Haley wrote: > > I've got all that off-list. I found the cause, and replied in another > email. It's not a bug. Oh Gods, are we back to gcc people saying "sure, we do stupid things, but it's allowed, so we don't consider it a bug because it doesn't matter that re

Re: BUG: GCC-4.4.x changes the function frame on some functions

2009-11-19 Thread Linus Torvalds
On Thu, 19 Nov 2009, Linus Torvalds wrote: > > Oh Gods, are we back to gcc people saying "sure, we do stupid things, but > it's allowed, so we don't consider it a bug because it doesn't matter that > real people care about real life, we only care about some

Re: BUG: GCC-4.4.x changes the function frame on some functions

2009-11-19 Thread Linus Torvalds
On Thu, 19 Nov 2009, Linus Torvalds wrote: > > I bet other people than just the kernel use the mcount hook for subtler > things than just doing profiles. And even if they don't, the quoted code > generation is just crazy _crap_. For the kernel, if the only case is that t

Re: BUG: GCC-4.4.x changes the function frame on some functions

2009-11-19 Thread Linus Torvalds
On Thu, 19 Nov 2009, H. Peter Anvin wrote: > > Calling the profiler immediately at the entry point is clearly the more > sane option. It means the ABI is well-defined, stable, and independent > of what the actual function contents are. It means that ABI isn't the > normal C ABI (the __fentry__

Re: BUG: GCC-4.4.x changes the function frame on some functions

2009-11-19 Thread Linus Torvalds
On Thu, 19 Nov 2009, Frederic Weisbecker wrote: > > > That way the lr would have the current function, and the parent would > > still be at 8(%sp) > > Yeah right, we need at least such very tiny prologue for > archs that store return addresses in a reg. Well, it will be architecture-dependent.

Re: BUG: GCC-4.4.x changes the function frame on some functions

2009-11-19 Thread Linus Torvalds
On Fri, 20 Nov 2009, Thomas Gleixner wrote: > > While testing various kernel configs we found out that the problem > comes and goes. Finally I started to compare the gcc command line > options and after some fiddling it turned out that the following > minimal deltas change the code generator beh

Re: gcc 4.5.1 / as 2.20.51.0.11 miscompiling drivers/char/i8k.c ?

2010-11-14 Thread Linus Torvalds
On Sun, Nov 14, 2010 at 4:52 PM, James Cloos wrote: > Gcc 4.5.1 running on an amd64 box "cross"-compiling for a P3 i8k fails > to compile the module since commit 6b4e81db2552bad04100e7d5ddeed7e848f53b48 > with: > >  CC      drivers/char/i8k.o > drivers/char/i8k.c: In function ‘i8k_smm’: > drivers/

Re: gcc 4.5.1 / as 2.20.51.0.11 miscompiling drivers/char/i8k.c ?

2010-11-15 Thread Linus Torvalds
On Mon, Nov 15, 2010 at 3:16 AM, Jakub Jelinek wrote: > > I don't see any problems on the assembly level.  i8k_smm is > not inlined in this case and checks all 3 conditions. If it really is related to gcc not understanding that "*regs" has changed due to the memory being an automatic variable, an

Re: gcc 4.5.1 / as 2.20.51.0.11 miscompiling drivers/char/i8k.c ?

2010-11-15 Thread Linus Torvalds
On Mon, Nov 15, 2010 at 9:40 AM, Jim Bos wrote: > > Hmm, that doesn't work. > > [ Not sure if you read to whole thread but initial workaround was to > change the asm(..) to asm volatile(..) which did work. ] Since I have a different gcc than yours (and I'm not going to compile my own), have you p

Re: gcc 4.5.1 / as 2.20.51.0.11 miscompiling drivers/char/i8k.c ?

2010-11-15 Thread Linus Torvalds
On Mon, Nov 15, 2010 at 10:30 AM, Jim Bos wrote: > > Attached version with plain 2.6.36 source and version with the committed > patch, i.e with the '"+m" (*regs)' Looks 100% identical in i8k_smm() itself, and I'm not seeing anything bad. The asm has certainly not been optimized away as implied in

Re: gcc 4.5.1 / as 2.20.51.0.11 miscompiling drivers/char/i8k.c ?

2010-11-15 Thread Linus Torvalds
On Mon, Nov 15, 2010 at 10:45 AM, Jeff Law wrote: > > A memory clobber should clobber anything in memory, including autos in > memory; if it doesn't, then that seems like a major problem.  I'd like to > see the rationale behind not clobbering autos in memory. Yes. It turns out that the "asm optim

Re: gcc 4.5.1 / as 2.20.51.0.11 miscompiling drivers/char/i8k.c ?

2010-11-15 Thread Linus Torvalds
On Mon, Nov 15, 2010 at 11:12 AM, Jakub Jelinek wrote: > > Ah, the problem is that memory_identifier_string is only initialized in > ipa-reference.c's initialization, so it can be (and is in this case) NULL in > ipa-pure-const.c. Ok. And I guess you can verify that all versions of gcc do this cor

<    1   2