From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752054AbdK3KCT (ORCPT ); Thu, 30 Nov 2017 05:02:19 -0500 Received: from foss.arm.com ([217.140.101.70]:50134 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751844AbdK3KCR (ORCPT ); Thu, 30 Nov 2017 05:02:17 -0500 Date: Thu, 30 Nov 2017 10:02:20 +0000 From: Will Deacon To: Peter Zijlstra Cc: Daniel Lustig , Alan Stern , "Paul E. McKenney" , Andrea Parri , Luc Maranget , Jade Alglave , Boqun Feng , Nicholas Piggin , David Howells , Palmer Dabbelt , Kernel development list Subject: Re: Unlock-lock questions and the Linux Kernel Memory Model Message-ID: <20171130100219.GA21983@arm.com> References: <17506ed0-1ce8-791d-7cf1-c40426015a99@nvidia.com> <20171129194602.6zmjj7z5ih4ri25h@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171129194602.6zmjj7z5ih4ri25h@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 29, 2017 at 08:46:02PM +0100, Peter Zijlstra wrote: > On Wed, Nov 29, 2017 at 11:04:53AM -0800, Daniel Lustig wrote: > > > While we're here, let me ask about another test which isn't directly > > about unlock/lock but which is still somewhat related to this > > discussion: > > > > "MP+wmb+xchg-acq" (or some such) > > > > {} > > > > P0(int *x, int *y) > > { > > WRITE_ONCE(*x, 1); > > smp_wmb(); > > WRITE_ONCE(*y, 1); > > } > > > > P1(int *x, int *y) > > { > > r1 = atomic_xchg_relaxed(y, 2); > > r2 = smp_load_acquire(y); > > r3 = READ_ONCE(*x); > > } > > > > exists (1:r1=1 /\ 1:r2=2 /\ 1:r3=0) > > > > C/C++ would call the atomic_xchg_relaxed part of a release sequence > > and hence would forbid this outcome. > > That's just weird. Either its _relaxed, or its _release. Making _relaxed > mean _release is just daft. I don't think it's actually that weird. If, for example, the write to *y in P0 was part of an UNLOCK operation and the load_acquire of y in P1 was a LOCK operation, then the xchg could just be setting some waiting bit in other bits of the lock word. C/C++ also requires order here if the xchg is done on its own thread. Will