Received: by 10.213.65.68 with SMTP id h4csp497778imn; Tue, 27 Mar 2018 03:33:33 -0700 (PDT) X-Google-Smtp-Source: AG47ELukjuN+gR6acthqaub91QpuYRbOgNTY6FdwY7C15IC5ESAr13rOFjDwlrnqfLjplYj0K6qU X-Received: by 10.99.116.85 with SMTP id e21mr30789324pgn.218.1522146813091; Tue, 27 Mar 2018 03:33:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522146813; cv=none; d=google.com; s=arc-20160816; b=IFmaP4sx0TAJ3EoYquKBFKUxSVv9EykfjTQBMOVoq1h9Vz31Kzvu1CmIY48V4UPW8L aSuQ7AWkzISt799q33/sy56J1feJSzO0GjP3d1K8MgVtkF6E9XxO6WXY2e/xH+39AsGX hJ3jNgQQRjmYRmWiT6/nq0ioxT2laYp5cZHCgXCF/dQpHA25miEMxs7eOYtz2SQXVh3c w+vNdq0dKlVSguF0dqrp/+s0yJyBgtiXlt3GBNFlgwiRcUdlZUPsQvAspAe93QEUa3J5 vrjt1EyeCXKxaGVWTvW5tQN1TQUovl/wB2Np7MjWrZDu+/5qj16zSok6nNkz1vFX6uup MjAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=cYOnI+1XL4es6I7D/P7fJKC3mFyIKk6oMAVNzCzgsDE=; b=i3MzYScqXmB2lL+tcmwhqRh1W1zN+GJKX24/RAAaDXrr09aNZbIa+MbEPKeJYT7ho/ o3JiB23Trq5bsWhXzmb0oup2eirtBegpmW0msskTLXBQ0JIrNtoCJWYptKQHZFh8luFT mlZ/pwkWj73nExplv9Gl5+f+WPt3gnTyeHYSjX7LJ4lUv96NqrUP7ALMsX0dUnBsPHUS gxQvcXW65K/9O111RlXhAge+OmzH736dh3vSYtQKJPkg892EBl37pJAATWhTmhhC+wEC 1sZskBlH9FG/WsUHcl+Fz41i5ZAFtJoPa2KsF7Z1BXpKxFHKFpjY9Dw8mUF02lIPs+3P gEZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=eZcNJCq3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 73si796975pfz.20.2018.03.27.03.33.17; Tue, 27 Mar 2018 03:33:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=eZcNJCq3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752469AbeC0KZc (ORCPT + 99 others); Tue, 27 Mar 2018 06:25:32 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:38392 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752394AbeC0KZb (ORCPT ); Tue, 27 Mar 2018 06:25:31 -0400 Received: by mail-wr0-f195.google.com with SMTP id m13so8516333wrj.5 for ; Tue, 27 Mar 2018 03:25:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=cYOnI+1XL4es6I7D/P7fJKC3mFyIKk6oMAVNzCzgsDE=; b=eZcNJCq3/GzO8rA5kZdQt+s4+EK0P1nuBwTGSaGO32dDEJp80Xya707qavnXxD1b01 5mUukLnGja6bfinIPn4WzU63OtRA3m/mSuSOectvrQmbchj5NlK0WB1qVvNTqzVBA2Af Af+G5U8X570BVnTu1HH0EXNzXLjRCinNZZRUo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=cYOnI+1XL4es6I7D/P7fJKC3mFyIKk6oMAVNzCzgsDE=; b=ncL2RWXOB6TvhEUbvv5KaK3d+I2GUJAQOs3lp7CVheN7dqYv/aIZWCFmbt7HO576k6 3MaCKMzQACGgTORX2AVTx/mIqrPAC/eE6l/i+3cECs5G5Mc5Wi7D1+VPcupCsliFWMps ae49tk/AFVjasqsartw2cx1dlacQdkIvcYNUdv9w6HVmjbznYL+hkIvjH6cGYm2xlU01 L4RgoRYoTuNmoFHvIDpfBX8kMQZ5MAaGEh2K7G0rf/oWHO4dNx3bhBKHFvpI3xnehDsP Lh/NdzDF2VmiMxMwh8XY2ofpRhghUBEZ9eyB6wDHWRHU7PNVQc6oBRRWkhjCymvEBtNH VJbA== X-Gm-Message-State: AElRT7H+pXmYKdy5PWoJyt/WrwjaIZf51hMujhuVWwl+EUSQViIZIBUc Js+l7gGUaf7WHu6cU03+jjjOpg== X-Received: by 10.223.176.237 with SMTP id j42mr34983961wra.25.1522146329693; Tue, 27 Mar 2018 03:25:29 -0700 (PDT) Received: from andrea ([213.209.242.222]) by smtp.gmail.com with ESMTPSA id r63sm1761963wmg.28.2018.03.27.03.25.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Mar 2018 03:25:29 -0700 (PDT) Date: Tue, 27 Mar 2018 12:25:21 +0200 From: Andrea Parri To: Benjamin Herrenschmidt Cc: Paul Mackerras , Michael Ellerman , Peter Zijlstra , Ingo Molnar , linux-kernel@vger.kernel.org, Linus Torvalds Subject: Re: [PATCH for-4.17 2/2] powerpc: Remove smp_mb() from arch_spin_is_locked() Message-ID: <20180327102521.GA7347@andrea> References: <1522060667-7034-1-git-send-email-andrea.parri@amarulasolutions.com> <1522109216.7364.30.camel@kernel.crashing.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1522109216.7364.30.camel@kernel.crashing.org> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 27, 2018 at 11:06:56AM +1100, Benjamin Herrenschmidt wrote: > On Mon, 2018-03-26 at 12:37 +0200, Andrea Parri wrote: > > Commit 51d7d5205d338 ("powerpc: Add smp_mb() to arch_spin_is_locked()") > > added an smp_mb() to arch_spin_is_locked(), in order to ensure that > > > > Thread 0 Thread 1 > > > > spin_lock(A); spin_lock(B); > > r0 = spin_is_locked(B) r1 = spin_is_locked(A); > > > > never ends up with r0 = r1 = 0, and reported one example (in ipc/sem.c) > > relying on such guarantee. > > > > It's however understood (and undocumented) that spin_is_locked() is not > > required to ensure such ordering guarantee, > > Shouldn't we start by documenting it ? I do sympathize with your concern about the documentation! ;) The patch in [1] was my (re)action to this concern; the sort of the patch is unclear to me by this time (and I'm not aware of other proposals in this respect). > > > guarantee that is currently > > _not_ provided by all implementations/arch, and that callers relying on > > such ordering should instead use suitable memory barriers before acting > > on the result of spin_is_locked(). > > > > Following a recent auditing[1] of the callers of {,raw_}spin_is_locked() > > revealing that none of them are relying on this guarantee anymore, this > > commit removes the leading smp_mb() from the primitive thus effectively > > reverting 51d7d5205d338. > > I would rather wait until it is properly documented. Debugging that IPC > problem took a *LOT* of time and energy, I wouldn't want these issues > to come and bite us again. I understand. And I'm grateful for this debugging as well as for the (IMO) excellent account of it you provided in 51d7d5205d338. Said this ;) I cannot except myself from saying that I would probably have resisted that solution (adding an smp_mb() in my arch_spin_is_locked), and instead "blamed"/suggested that caller to fix his memory ordering... Andrea > > > [1] https://marc.info/?l=linux-kernel&m=151981440005264&w=2 > > > > Signed-off-by: Andrea Parri > > Cc: Benjamin Herrenschmidt > > Cc: Paul Mackerras > > Cc: Michael Ellerman > > Cc: Peter Zijlstra > > Cc: Ingo Molnar > > Cc: Linus Torvalds > > --- > > arch/powerpc/include/asm/spinlock.h | 1 - > > 1 file changed, 1 deletion(-) > > > > diff --git a/arch/powerpc/include/asm/spinlock.h b/arch/powerpc/include/asm/spinlock.h > > index b9ebc3085fb79..ecc141e3f1a73 100644 > > --- a/arch/powerpc/include/asm/spinlock.h > > +++ b/arch/powerpc/include/asm/spinlock.h > > @@ -67,7 +67,6 @@ static __always_inline int arch_spin_value_unlocked(arch_spinlock_t lock) > > > > static inline int arch_spin_is_locked(arch_spinlock_t *lock) > > { > > - smp_mb(); > > return !arch_spin_value_unlocked(*lock); > > } > >