From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932645AbcHJAGF (ORCPT ); Tue, 9 Aug 2016 20:06:05 -0400 Received: from gate.crashing.org ([63.228.1.57]:59410 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752544AbcHJAGC (ORCPT ); Tue, 9 Aug 2016 20:06:02 -0400 Message-ID: <1470787537.3015.83.camel@kernel.crashing.org> Subject: Re: spin_lock implicit/explicit memory barrier From: Benjamin Herrenschmidt To: Manfred Spraul , Michael Ellerman Cc: Andrew Morton , Davidlohr Bueso , Linux Kernel Mailing List , Susi Sonnenschein <1vier1@web.de>, "Paul E. McKenney" Date: Wed, 10 Aug 2016 10:05:37 +1000 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.20.4 (3.20.4-1.fc24) Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2016-08-09 at 20:52 +0200, Manfred Spraul wrote: > Hi Benjamin, Hi Michael, > > regarding commit 51d7d5205d33 ("powerpc: Add smp_mb() to  > arch_spin_is_locked()"): > > For the ipc/sem code, I would like to replace the spin_is_locked() with  > a smp_load_acquire(), see: > > http://git.cmpxchg.org/cgit.cgi/linux-mmots.git/tree/ipc/sem.c#n367 > > http://www.ozlabs.org/~akpm/mmots/broken-out/ipc-semc-fix-complex_count-vs-simple-op-race.patch > > To my understanding, I must now add a smp_mb(), otherwise it would be  > broken on PowerPC: > > The approach that the memory barrier is added into spin_is_locked()  > doesn't work because the code doesn't use spin_is_locked(). > > Correct? Right, otherwise you aren't properly ordered. The current powerpc locks provide good protection between what's inside vs. what's outside the lock but not vs. the lock *value* itself, so if, like you do in the sem code, use the lock value as something that is relevant in term of ordering, you probably need an explicit full barrier. Adding Paul McKenney. Cheers, Ben.