Received: by 10.223.185.116 with SMTP id b49csp6110555wrg; Wed, 28 Feb 2018 04:16:37 -0800 (PST) X-Google-Smtp-Source: AH8x225u76+elV2MTNUqgB8vhS6YBKfv8rjtB6FWyXeaz/r8Bd3R3EI57FQMSudx6uuTC9MmD1nl X-Received: by 10.98.139.145 with SMTP id e17mr17475522pfl.53.1519820197175; Wed, 28 Feb 2018 04:16:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519820197; cv=none; d=google.com; s=arc-20160816; b=VdXF8ofdMlpSOEKz5+2sTCCuKifWyTbzSCY7xjsXgyVcQJfFvVD/SBLvjyGZ6umBtb D+888BdFNCGzq3IXp09RmwQFR6c25jergcQuGEafzR2tLzg/EdOE+aR6LAywAnlnceGO M6PZ3KNygI0cI5lfAdtTJK9zv3RH+pXI3jrU5nEQYmBhz6kpOSex5V79sSU6G1YmKwJj 3WA5JAjq358O+AghQcVsWlHYo2j74LSKZwDmOL34so1FiZk1jLdu7spjWqCnHR/XGFJD SFTBgWcVggfl3QofxlPnLIn9C1SIvrATzDzsHUxUr3ATM3Mx+Haf1Qe5JzK39GMiGm1O Z1jQ== 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=IZjLvkhXmppiOQGStGXg4pPeT/rO3MZaK0Yme83c2iI=; b=okdg0mlnRWMEA39wD9Q4oTbD5RlaGUeNliD2PFBWSEp4HRL7NaF5Sp3AABL0PDeqDr ekIvyo2CnuoUNWDAODF7tL7xSiep52c4ktxOeLJFwns/JfXZ4nJ6ztOs7klKIBZE4teQ 7YexNY13maZNmorQChPKiOc09dUroyl8yE+KG4txl5qa5kxrMO4azRGFEntxYi9W7i1O NwkfyqUpgnZOdEtwIt/CPNdPqUE8uHCMUQBzX4xMwIhEFrRDSbBQjDdBsCBczhD0mEFb 3LOn/bl3sEWD2HewWtiNY72JHZA67QQzTqeDl2i3fEgNqFGLC1VpFQm0SNnoTNsPQZa2 smEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IShqCN5M; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 63si966949pgg.395.2018.02.28.04.16.21; Wed, 28 Feb 2018 04:16:37 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IShqCN5M; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752457AbeB1MPd (ORCPT + 99 others); Wed, 28 Feb 2018 07:15:33 -0500 Received: from mail-wr0-f195.google.com ([209.85.128.195]:36397 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752436AbeB1MPb (ORCPT ); Wed, 28 Feb 2018 07:15:31 -0500 Received: by mail-wr0-f195.google.com with SMTP id v111so2179015wrb.3 for ; Wed, 28 Feb 2018 04:15:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=IZjLvkhXmppiOQGStGXg4pPeT/rO3MZaK0Yme83c2iI=; b=IShqCN5MMnAJXHWkyQJie39nWGwu1p6/mtubdPAyizFLlHBicWXibn0fh8AerwLEMJ a3wHKOFnctFtm4p2iFO2hNGNG3WyEPVTBT+mysTok6DhgkWLPCdkE0MGxpV1IzSHis2J HWvkUms0fGu9ggvNjnkm9+wdPpRFw5oS4cVIHGad82fPGKyIL9Yml+PI253VZuDicZp8 t93jyEH5Y+VwRE7mXklTyOHgW3GoifSms6sHKPvet9+HMK8MJ6o5pGcmkV7JduJ273Il /xNARuE6/ctUgxaT+yTeYiqOO4+pNPbc8Vt2osZ/mFpHqmfiHyLHmpVLohwAK70aUTg8 hRgw== 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=IZjLvkhXmppiOQGStGXg4pPeT/rO3MZaK0Yme83c2iI=; b=b1bDCZC8LtXaTe0bxsrPfo71lRlsyZstC6v5KPDFv7XlchzybtQnJtcwzjI19VDS/b pqRM5KkKXaI5YhHKIKRhsUaG3SIGZAjkKHNgHkUUowlkndzy+IT46v2UF/R/3faZCULe WMbS86LySV5WwjnO6Z1I4U6k7w53tZ7BwIAACFkHgvI8LWhB+vjaiKq7+d901Eeh/dN6 b4vnT4SGvWnoPjxrc2XOmPBGtPZTNidN74+IHDrCW90CuVjr2p16tGa8D4LTUJUHUaTP Xdon5r24xZdxRv4Ky9a7pP554zbConni9GUNxhloJSoKvyf4lIdQRHxh6Nf8Xg6nuTJa 214Q== X-Gm-Message-State: APf1xPAMNh7RWgJ+/aszoUdktfobey1toQv9hKTBGHTu2bEdCvR+C01O qgZoKc7tcM2YkVClraGLLz8= X-Received: by 10.223.136.56 with SMTP id d53mr15325682wrd.17.1519820129659; Wed, 28 Feb 2018 04:15:29 -0800 (PST) Received: from andrea (85.100.broadband17.iol.cz. [109.80.100.85]) by smtp.gmail.com with ESMTPSA id 69sm2871301wmw.32.2018.02.28.04.15.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Feb 2018 04:15:29 -0800 (PST) Date: Wed, 28 Feb 2018 13:15:23 +0100 From: Andrea Parri To: Will Deacon 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: <20180228121523.GA354@andrea> References: <1519814372-19941-1-git-send-email-parri.andrea@gmail.com> <20180228105631.GA7681@arm.com> <20180228112403.GA32228@andrea> <20180228113456.GC7681@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180228113456.GC7681@arm.com> 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 Wed, Feb 28, 2018 at 11:34:56AM +0000, Will Deacon wrote: > 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. Sure, I'll do (queued after the RISC-V patches I'm currently working on). So I think that we could all agree that the semantics I'm proposing here would be very simple to reason with ;-). You know, OTOH, this auditing could turn out to be all but "simple"... https://marc.info/?l=linux-kernel&m=149910202928559&w=2 https://marc.info/?l=linux-kernel&m=149886113629263&w=2 https://marc.info/?l=linux-kernel&m=149912971028729&w=2 but I'll have a try, IAC. Perhaps, a temporary solution/workaround can be to simplify/clarify the semantics and to insert the smp_mb() (or the smp_mb__before_islocked(), ...) in the "dubious" use cases. Andrea > > Will