From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759883AbcBYIVv (ORCPT ); Thu, 25 Feb 2016 03:21:51 -0500 Received: from casper.infradead.org ([85.118.1.10]:53704 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758272AbcBYIVu (ORCPT ); Thu, 25 Feb 2016 03:21:50 -0500 Date: Thu, 25 Feb 2016 09:21:43 +0100 From: Peter Zijlstra To: "Paul E. McKenney" Cc: Mathieu Desnoyers , linux-kernel@vger.kernel.org, Ingo Molnar , Lai Jiangshan , dipankar@in.ibm.com, Andrew Morton , josh@joshtriplett.org, Thomas Gleixner , rostedt , David Howells , edumazet@google.com, dvhart@linux.intel.com, fweisbec@gmail.com, Oleg Nesterov , bobby prani Subject: Re: [PATCH tip/core/rcu 02/14] documentation: Fix control dependency and identical stores Message-ID: <20160225082143.GZ6357@twins.programming.kicks-ass.net> References: <20160224050021.GA14616@linux.vnet.ibm.com> <1456290047-16654-2-git-send-email-paulmck@linux.vnet.ibm.com> <467632883.7240.1456348324456.JavaMail.zimbra@efficios.com> <20160224214013.GF3522@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160224214013.GF3522@linux.vnet.ibm.com> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 24, 2016 at 01:40:13PM -0800, Paul E. McKenney wrote: > > > + (*) If both legs of the "if" statement begin with identical stores to > > > + the same variable, then those stores must be ordered, either by > > > + preceding both of them with smp_mb() or by using smp_store_release() > > > + to carry out the stores. Please note that it is -not- sufficient > > > + to use barrier() at beginning of each leg of the "if" statement, > > > + as optimizing compilers do not necessarily respect barrier() > > > + in this case. > Let's take the example, replace barrier() with smp_mb(), and see what > happens: > > q = READ_ONCE(a); > if (q) { > smp_mb(); > WRITE_ONCE(b, p); > do_something(); > } else { > smp_mb(); > WRITE_ONCE(b, p); > do_something_else(); > } Why would an optimizing compiler be allowed to lift _anything_ over a barrier() ? Isn't that a bug? I thought the whole point of barrier() was to tell the compiler to not do such things.