public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* RCU: non-atomic assignment to long/pointer variables in gcc
@ 2013-01-15 10:30 Konstantin Khlebnikov
  2013-01-15 12:32 ` Paul E. McKenney
  0 siblings, 1 reply; 4+ messages in thread
From: Konstantin Khlebnikov @ 2013-01-15 10:30 UTC (permalink / raw)
  To: linux-kernel@vger.kernel.org; +Cc: Paul E. McKenney, Linus Torvalds

Documentation/atomic_ops.txt (182dd4b277177e8465ad11cd9f85f282946b5578)
says that pointers, longs, ints, and chars are stored and loaded atomically.

But GCC actually may split assignment to 'long' variable into two instructions.
see example in http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55981

GCC also splits assignments to 'volatile' variables and this is actually a bug in gcc.

volatile unsigned long y;

y = 0x100000001ul;

   400728:	c7 05 66 06 20 00 01 	movl   $0x1,0x200666(%rip)        # 600d98 <y>
   40072f:	00 00 00
   400732:	c7 05 60 06 20 00 01 	movl   $0x1,0x200660(%rip)        # 600d9c <y+0x4>
   400739:	00 00 00

fortunately for y = 0; it generates this:

   40071d:	48 c7 05 70 06 20 00 	movq   $0x0,0x200670(%rip)        # 600d98 <y>
   400724:	00 00 00 00

Thus NULL is safe, but constant ERR_PTR may be dangerous.

Probably rcu_assign_pointer() should use ACCESS_ONCE() around lvalue, because
splitting assignment for non-volatile variable seems like completely valid,
but this may help only after fixing that bug in GCC.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-01-15 16:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-15 10:30 RCU: non-atomic assignment to long/pointer variables in gcc Konstantin Khlebnikov
2013-01-15 12:32 ` Paul E. McKenney
2013-01-15 13:07   ` Konstantin Khlebnikov
2013-01-15 16:17     ` Paul E. McKenney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox