All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kerne.org,
	geert@linux-m68k.org, torvalds@linux-foundation.org,
	VICTORK@il.ibm.com, oleg@redhat.com, anton@samba.org,
	benh@kernel.crashing.org, fweisbec@gmail.com,
	mathieu.desnoyers@polymtl.ca, michael@ellerman.id.au,
	mikey@neuling.org, linux@arm.linux.org.uk,
	schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com,
	tony.luck@intel.com, Will Deacon <will.deacon@arm.com>
Subject: Re: [PATCH 4/4] arch: Introduce smp_load_acquire(), smp_store_release()
Date: Tue, 17 Dec 2013 05:58:16 -0800	[thread overview]
Message-ID: <20131217135815.GD5919@linux.vnet.ibm.com> (raw)
In-Reply-To: <20131217091430.GB21999@twins.programming.kicks-ass.net>

On Tue, Dec 17, 2013 at 10:14:30AM +0100, Peter Zijlstra wrote:
> On Mon, Dec 16, 2013 at 01:37:20PM -0800, Paul E. McKenney wrote:
> > rcu: Define rcu_assign_pointer() in terms of smp_store_release()
> > 
> > The new smp_store_release() function provides better guarantees than did
> > rcu_assign_pointer(), and potentially less overhead on some architectures.
> > The guarantee that smp_store_release() provides that rcu_assign_pointer()
> > does that is obscure, but its lack could cause considerable confusion.
> > This guarantee is illustrated by the following code fragment:
> >     
> >     	struct foo {
> >     		int a;
> >     		int b;
> >     		int c;
> >     		struct foo *next;
> >     	};
> >     	struct foo foo1;
> >     	struct foo foo2;
> >     	struct foo __rcu *foop;
> >     
> >     	...
> >     
> >     	foo2.a = 1;
> >     	foo2.b = 2;
> >     	BUG_ON(foo2.c);
> >     	rcu_assign_pointer(foop, &foo);
> >     
> >     	...
> >     
> >     	fp = rcu_dereference(foop);
> >     	fp.c = 3;
> > 
> > The current rcu_assign_pointer() semantics permit the BUG_ON() to
> > trigger because rcu_assign_pointer()'s smp_wmb() is not guaranteed to
> > order prior reads against later writes.  This commit therefore upgrades
> > rcu_assign_pointer() from smp_wmb() to smp_store_release() to avoid this
> > counter-intuitive outcome.
> 
> This of course raises the obvious question; why doesn't
> rcu_dereference() need to be a smp_load_acquire?
> 
> And I think I know the answer; which would be that the data dependency
> is still sufficient. But the situation does create an unpleasant
> asymmetry in things.

Yep, rcu_dereference() does rely on data dependency rather than explicit
barriers.  That said, for TSO architectures, the code emitted for
data dependency and for the acquire memory barrier is often identical.
And no, many the C/C++11 guys didn't like this asymmetry much either.  ;-)

							Thanx, Paul

  reply	other threads:[~2013-12-17 13:58 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-13 14:56 [PATCH 0/4] arch: Introduce smp_load_acquire() and smp_store_release() Peter Zijlstra
2013-12-13 14:56 ` [PATCH 1/4] doc: Rename LOCK/UNLOCK to ACQUIRE/RELEASE Peter Zijlstra
2013-12-16 20:11   ` Paul E. McKenney
2013-12-17  9:24     ` Peter Zijlstra
2013-12-17 15:31       ` Paul E. McKenney
2014-01-12 18:43       ` [tip:core/locking] locking/doc: Rename LOCK/UNLOCK to ACQUIRE/ RELEASE tip-bot for Peter Zijlstra
2013-12-17 10:13     ` [PATCH 1/4] doc: Rename LOCK/UNLOCK to ACQUIRE/RELEASE Peter Zijlstra
2013-12-17 13:59       ` Paul E. McKenney
2013-12-13 14:56 ` [PATCH 2/4] arch: Move smp_mb__{before,after}_atomic_{inc,dec}.h into asm/atomic.h Peter Zijlstra
2013-12-16 20:13   ` Paul E. McKenney
2013-12-18 13:40   ` Vineet Gupta
2014-01-12 18:43   ` [tip:core/locking] arch: Move smp_mb__{before,after}_atomic_{inc, dec}.h " tip-bot for Peter Zijlstra
2013-12-13 14:57 ` [PATCH 3/4] arch: Clean up asm/barrier.h implementations using asm-generic/barrier.h Peter Zijlstra
2013-12-13 19:16   ` Geert Uytterhoeven
2013-12-13 19:17     ` Fwd: " Geert Uytterhoeven
2013-12-13 19:53     ` Peter Zijlstra
2013-12-16 20:14   ` Paul E. McKenney
2014-01-12 18:43   ` [tip:core/locking] arch: Clean up asm/ barrier.h " tip-bot for Peter Zijlstra
2013-12-13 14:57 ` [PATCH 4/4] arch: Introduce smp_load_acquire(), smp_store_release() Peter Zijlstra
2013-12-16 16:40   ` Will Deacon
2013-12-17  9:07     ` Peter Zijlstra
2013-12-16 21:37   ` Paul E. McKenney
2013-12-17  9:14     ` Peter Zijlstra
2013-12-17 13:58       ` Paul E. McKenney [this message]
2014-01-12 18:43   ` [tip:core/locking] " tip-bot for Peter Zijlstra
2013-12-18 19:08 [PATCH 0/4] arch: Introduce smp_load_acquire() and smp_store_release() Peter Zijlstra
2013-12-18 19:08 ` [PATCH 4/4] arch: Introduce smp_load_acquire(), smp_store_release() Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131217135815.GD5919@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=VICTORK@il.ibm.com \
    --cc=anton@samba.org \
    --cc=benh@kernel.crashing.org \
    --cc=fweisbec@gmail.com \
    --cc=geert@linux-m68k.org \
    --cc=heiko.carstens@de.ibm.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kerne.org \
    --cc=linux@arm.linux.org.uk \
    --cc=mathieu.desnoyers@polymtl.ca \
    --cc=michael@ellerman.id.au \
    --cc=mikey@neuling.org \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=schwidefsky@de.ibm.com \
    --cc=tony.luck@intel.com \
    --cc=torvalds@linux-foundation.org \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.