From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753230AbcHOUGv (ORCPT ); Mon, 15 Aug 2016 16:06:51 -0400 Received: from mail-wm0-f41.google.com ([74.125.82.41]:38696 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752887AbcHOUGt (ORCPT ); Mon, 15 Aug 2016 16:06:49 -0400 From: Manfred Spraul Subject: Re: spin_lock implicit/explicit memory barrier To: paulmck@linux.vnet.ibm.com, Davidlohr Bueso References: <1470787537.3015.83.camel@kernel.crashing.org> <4bd34301-0c63-66ae-71b1-6fd68c9fecdd@colorfullife.com> <20160810191757.GA4952@linux-80c1.suse> <20160810210003.GM3482@linux.vnet.ibm.com> Cc: Benjamin Herrenschmidt , Michael Ellerman , Andrew Morton , Linux Kernel Mailing List , Susanne Spraul <1vier1@web.de>, Peter Zijlstra Message-ID: <021ee6e2-b55b-a2a2-a434-6f18bd120b82@colorfullife.com> Date: Mon, 15 Aug 2016 22:06:39 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <20160810210003.GM3482@linux.vnet.ibm.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Paul, On 08/10/2016 11:00 PM, Paul E. McKenney wrote: > On Wed, Aug 10, 2016 at 12:17:57PM -0700, Davidlohr Bueso wrote: >> [...] >> CPU0 CPU1 >> complex_mode = true spin_lock(l) >> smp_mb() <--- do we want a smp_mb() here? >> spin_unlock_wait(l) if (!smp_load_acquire(complex_mode)) >> foo() foo() >> >> We should not be doing an smp_mb() right after a spin_lock(), makes no sense. The >> spinlock machinery should guarantee us the barriers in the unorthodox locking cases, >> such as this. > In this case, from what I can see, we do need a store-load fence. > That said, yes, it really should be smp_mb__after_unlock_lock() rather > than smp_mb(). So if this code pattern is both desired and legitimate, > the smp_mb__after_unlock_lock() definitions probably need to move out > of kernel/rcu/tree.h to barrier.h or some such. Can you explain the function name, why smp_mb__after_unlock_lock()? I would have called it smp_mb__after_spin_lock(). For ipc/sem.c, the use case is: [sorry, I only now notice that the mailer ate the formatting]: cpu 1: complex_mode_enter(): smp_store_mb(sma->complex_mode, true); for (i = 0; i < sma->sem_nsems; i++) { sem = sma->sem_base + i; spin_unlock_wait(&sem->lock); } cpu 2: sem_lock(): spin_lock(&sem->lock); smp_mb(); if (!smp_load_acquire(&sma->complex_mode)) { What is forbidden is that both cpu1 and cpu2 proceed. -- Manfred