Received: by 10.223.185.116 with SMTP id b49csp6073247wrg; Wed, 28 Feb 2018 03:36:12 -0800 (PST) X-Google-Smtp-Source: AH8x225xyKFPbOgvygkA38jzh3ORSH29zoIavxdPiF8HJG8+e7JfbN0RgaDUNdzFz7ufHKRYPBPH X-Received: by 10.98.171.24 with SMTP id p24mr17408695pff.71.1519817772640; Wed, 28 Feb 2018 03:36:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519817772; cv=none; d=google.com; s=arc-20160816; b=XZWpJJSO8YfYuPJWtCZRb1P519qP+IyfjqRSsydHcCQyPRBu5rlYIbFi6PUABBoXaA jYKDUIpyzDITMiNFSPs80268oJBxUZjQCuR+p+6AsQbq7VbQIi+l2zh2Ze0RzYJhG60i 1++qaefn40iEW4O0hrN5ym8zsZTp6eYrFMsx3B4WSUeLcUohlWkuJo3gNzEoA6qQePrx Pnx6af/naWxU7v8ooF6kTcqbh0oVRiUeyq1EBZUQU7T8Jehu6IUBXulH6wKDyMCabqfF 7v6MHksfKJPHr1ZZ5stDNQ781ZQpPTTPPlWDFoDhWK43Rqi/khsrMFuKT0LknMhCps+U wDYw== 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:arc-authentication-results; bh=jvDINUfaLaETYnph1mLK9R3n6vsz3SCN+p2ROeweYmE=; b=ZYAOjL63gW/enTfb+UMEUQZdynQ8i7Plh+SBaLbdkv905zEqNQg6SbKxlUiOIft2Vp mqHQFUZ23MJJMxk9iSoQ8aVuJqOVZJ+GnLpfxS7Lbj2fPfwB0B6du+US/PgVClwvUsO1 v9Z9HFjwiArYewQydo3ntoo/i5ycwcUafsDdvWDahrPBuKOs8Q8P1m/a0vjx2dZZKupk ZBA6je/qIqBZOUF1qOVbix6IW5AJ9nyUNKolv9nSNoq9R9QsIxWVKRqqQ9RumOyg4NFp aFTaW4G2RHCiu14gyUbUJlz9Lhnh7UWjm/Mu/aG8/X++W41LwMW1lR6nvP1G8YCtBvnb 5JZw== ARC-Authentication-Results: i=1; mx.google.com; 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 m39-v6si1142166plg.447.2018.02.28.03.35.57; Wed, 28 Feb 2018 03:36:12 -0800 (PST) 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; 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 S1752226AbeB1Le4 (ORCPT + 99 others); Wed, 28 Feb 2018 06:34:56 -0500 Received: from foss.arm.com ([217.140.101.70]:48118 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751997AbeB1Lez (ORCPT ); Wed, 28 Feb 2018 06:34:55 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CD8A71435; Wed, 28 Feb 2018 03:34:54 -0800 (PST) Received: from edgewater-inn.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9F0613F25C; Wed, 28 Feb 2018 03:34:54 -0800 (PST) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id CDD9F1AE53BC; Wed, 28 Feb 2018 11:34:56 +0000 (GMT) Date: Wed, 28 Feb 2018 11:34:56 +0000 From: Will Deacon To: Andrea Parri Cc: linux-kernel@vger.kernel.org, Alan Stern , Peter Zijlstra , Boqun Feng , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , "Paul E. McKenney" , Akira Yokosawa Subject: Re: [PATCH] Documentation/locking: Document the semantics of spin_is_locked() Message-ID: <20180228113456.GC7681@arm.com> References: <1519814372-19941-1-git-send-email-parri.andrea@gmail.com> <20180228105631.GA7681@arm.com> <20180228112403.GA32228@andrea> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180228112403.GA32228@andrea> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 28, 2018 at 12:24:03PM +0100, Andrea Parri wrote: > On Wed, Feb 28, 2018 at 10:56:32AM +0000, Will Deacon wrote: > > On Wed, Feb 28, 2018 at 11:39:32AM +0100, Andrea Parri wrote: > > > There appeared to be a certain, recurrent uncertainty concerning the > > > semantics of spin_is_locked(), likely a consequence of the fact that > > > this semantics remains undocumented or that it has been historically > > > linked to the (likewise unclear) semantics of spin_unlock_wait(). > > > > > > Document this semantics. > > > > > > Signed-off-by: Andrea Parri > > > Cc: Alan Stern > > > Cc: Will Deacon > > > Cc: Peter Zijlstra > > > Cc: Boqun Feng > > > Cc: Nicholas Piggin > > > Cc: David Howells > > > Cc: Jade Alglave > > > Cc: Luc Maranget > > > Cc: "Paul E. McKenney" > > > Cc: Akira Yokosawa > > > --- > > > include/linux/spinlock.h | 11 +++++++++++ > > > 1 file changed, 11 insertions(+) > > > > > > diff --git a/include/linux/spinlock.h b/include/linux/spinlock.h > > > index 4894d322d2584..2639fdc9a916c 100644 > > > --- a/include/linux/spinlock.h > > > +++ b/include/linux/spinlock.h > > > @@ -380,6 +380,17 @@ static __always_inline int spin_trylock_irq(spinlock_t *lock) > > > raw_spin_trylock_irqsave(spinlock_check(lock), flags); \ > > > }) > > > > > > +/** > > > + * spin_is_locked() - Check whether a spinlock is locked. > > > + * @lock: Pointer to the spinlock. > > > + * > > > + * This function is NOT required to provide any memory ordering > > > + * guarantees; it could be used for debugging purposes or, when > > > + * additional synchronization is needed, accompanied with other > > > + * constructs (memory barriers) enforcing the synchronization. > > > + * > > > + * Return: 1, if @lock is (found to be) locked; 0, otherwise. > > > + */ > > > > I also don't think this is quite right, since the spin_is_locked check > > must be ordered after all prior lock acquisitions (to any lock) on the same > > CPU. That's why we have an smp_mb() in there on arm64 (see 38b850a73034f). > > So, arm64 (and powerpc) complies to the semantics I _have_ in mind ... Sure, but they're offering more than that at present. If I can remove the smp_mb() in our spin_is_locked implementation, I will, but we need to know what that will break even if you consider that code to be broken because it relies on something undocumented. > > So this is a change in semantics and we need to audit the users before > > proceeding. We should also keep spin_is_locked consistent with the versions > > for mutex, rwsem, bit_spin. > > Well, strictly speaking, it isn't (given that the current semantics is, > as reported above, currently undocumented); for the same reason, cases > relying on anything more than _nothing_ (if any) are already broken ... I suppose it depends on whether you consider the code or the documentation to be authoritative. I tend to err on the side of the former for the kernel. To be clear: I'm perfectly ok relaxing the semantics, but only if there's some evidence that you've looked at the callsites and determined that they won't break. That's why I think a better first step would be to convert a bunch of them to using lockdep for the "assert that I hold this lock" checks, so we can start to see where the interesting cases are. Will