On Mon, Jun 03, 2019 at 12:01:14PM +0800, Herbert Xu wrote: > On Sun, Jun 02, 2019 at 08:47:07PM -0700, Paul E. McKenney wrote: > > > > CPU2: if (b != 1) > > CPU2: b = 1; > > Stop right there. The kernel is full of code that assumes that > assignment to an int/long is atomic. If your compiler breaks this > assumption that we can kiss the kernel good-bye.
Here you go: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55981 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56028 TL;DR: On x86, of you are doing a plain store of a 32-bit constant that has bits set only in the lower few bits of each 16-bit half of that constant, the compiler is plenty happy to use a pair of 16-bit store-immediate instructions to carry out that store. This is also known as "store tearing". The two bugs were filed (and after some back and forth, fixed) because someone forgot to exclude C11 atomics and volatile accesses from this store tearing. Thanx, Paul