Received: by 10.213.65.68 with SMTP id h4csp1072024imn; Fri, 6 Apr 2018 14:06:10 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+HzdxWirRgWDflOk/Zv5q9NatLHNTMNEWzK4pKeO9Y9GNeKk0i8Za9QvKcNkagg/7zQsuG X-Received: by 10.99.130.199 with SMTP id w190mr18854783pgd.15.1523048770927; Fri, 06 Apr 2018 14:06:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523048770; cv=none; d=google.com; s=arc-20160816; b=cvLvL5lDsEif/rJsHGxEfguE2p6gyHk/xVOzo3CpjT5TN6QfQK+ZzfaEv7q4RglfuJ rM+H1cHxTSQstV1v0dFziFBc3KrPL9zcA2aHyOc71oiJr63WDBiFmWb5W+urugZyaLQW OnPU6qca8oArrXv67wO7/pWNqRCEhZKQxJCpIoi6uyBCiMmXiDvyRi9avoNBmt9Dk2tM CivGZChy2Lub/lC7h/y/d/WaPmdNXH2WRoAfjnJxRFJVD6riMoYCx6WAinu0rNfq9JSh FfQtSI9s1HT4GcXengTLo1kc6qUx2W1cycYUcx6vk7HjFFe8ggjiQh7Corgeiq+6t8XY 2LCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=JZbQwSnQP6mGWy+ERlqYkIEYWy9ctfRZvoxAYIZsTes=; b=Ekal5wZdw6KLopWKsF68GeCAHsTfeURT6u5j7ssaWbSUECd7v7YhaL5jugBBaxCbSP Dhxvblv/q+XOYrpbQ72TgRh7rewKUI75G4B1WP6FT0QhGnN7hIX5cLYZuUnpkzAzgPyX +vF31UM7rZml8RYq68uEEefioQEXcj/aMX+bbWexkgQ8qz1hmSJ6g6+oz6vG9CyqjNZn YUlM1pTPxSmY5LH5d61iXJojheN8UvOrXzJK2gm/5JRuvu6LjrY4Oo8hnT242YzgfQh8 WjwzvJpG56/yLR/HLvjyDlEZOqBX/ozd4i1rHqTjfrDcsK0VCDleMtAzni/FVIbpF9SS Sc4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=TdXt50Zl; 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 i188si7452349pgc.178.2018.04.06.14.05.33; Fri, 06 Apr 2018 14:06:10 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=TdXt50Zl; 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 S1752374AbeDFVBy (ORCPT + 99 others); Fri, 6 Apr 2018 17:01:54 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:42762 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751410AbeDFVBx (ORCPT ); Fri, 6 Apr 2018 17:01:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: Content-Type:In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To: Subject:Sender:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=JZbQwSnQP6mGWy+ERlqYkIEYWy9ctfRZvoxAYIZsTes=; b=TdXt50ZlYuDiq37Eb/ACY72cu OcVcsl92jAXG72EwXRvPWsfwnakT+XODbKhS+JwbB+i+eE+aqoZB+v5mRRKNk2YDAGxu4EfbFDfkw 833/R1M7H4jejKVEyvnnttf9YbRmKyhB8ziFhFWaNOz1bPZ6pSvr39CaqEK5mqCp7888Kr4PU29ZN 0/uVAv43ViJMlzsSLWqygGt8HkdwLTedjOox5h3A5+m6htfOEYlvgVvxhmZP6w9x3732gKTpWCmai CZsDYmMeBDAcNfnDBi5TuGUvtYOMWtKYkQ9oJfR6FSBsjbUo2hECCmoGTg5m5+SD5RIAIol1zRrTy Cpjksr3cg==; Received: from static-50-53-52-16.bvtn.or.frontiernet.net ([50.53.52.16] helo=midway.dunlab) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1f4YUQ-000199-RK; Fri, 06 Apr 2018 21:01:42 +0000 Subject: Re: [PATCH v4 1/3] locking: Document the semantics of spin_is_locked() To: Andrea Parri , paulmck@linux.vnet.ibm.com Cc: linux-kernel@vger.kernel.org, Alan Stern , David Howells , Will Deacon , Peter Zijlstra , Boqun Feng , Nicholas Piggin , Jade Alglave , Luc Maranget , Akira Yokosawa , Ingo Molnar References: <1522600912-6208-2-git-send-email-andrea.parri@amarulasolutions.com> <1523044060-5568-1-git-send-email-andrea.parri@amarulasolutions.com> From: Randy Dunlap Message-ID: Date: Fri, 6 Apr 2018 14:01:41 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <1523044060-5568-1-git-send-email-andrea.parri@amarulasolutions.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/06/2018 12:47 PM, 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(). > > A recent auditing [1] of the callers of the primitive confirmed that > none of them are relying on particular ordering guarantees; document > this semantics by adding a docbook header to spin_is_locked(). Also, > describe behaviors specific to certain CONFIG_SMP=n builds. > > [1] https://marc.info/?l=linux-kernel&m=151981440005264&w=2 > https://marc.info/?l=linux-kernel&m=152042843808540&w=2 > https://marc.info/?l=linux-kernel&m=152043346110262&w=2 > > Co-Developed-by: Andrea Parri > Co-Developed-by: Alan Stern > Co-Developed-by: David Howells > Signed-off-by: Andrea Parri > Signed-off-by: Alan Stern > Signed-off-by: David Howells > Cc: Will Deacon > Cc: Peter Zijlstra > Cc: Boqun Feng > Cc: Nicholas Piggin > Cc: Jade Alglave > Cc: Luc Maranget > Cc: "Paul E. McKenney" > Cc: Akira Yokosawa > Cc: Ingo Molnar > --- > include/linux/spinlock.h | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) > > diff --git a/include/linux/spinlock.h b/include/linux/spinlock.h > index 4894d322d2584..1e8a464358384 100644 > --- a/include/linux/spinlock.h > +++ b/include/linux/spinlock.h > @@ -380,6 +380,24 @@ 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. > + * > + * Returns: 1 if @lock is locked, 0 otherwise. Sorry, minor nit: s/Returns:/Return:/ (according to kernel-doc.rst) although I agree that "Returns:" is better. [I should have changed that years ago.] > + * > + * Note that the function only tells you that the spinlock is > + * seen to be locked, not that it is locked on your CPU. > + * > + * Further, on CONFIG_SMP=n builds with CONFIG_DEBUG_SPINLOCK=n, > + * the return value is always 0 (see include/linux/spinlock_up.h). > + * Therefore you should not rely heavily on the return value. > + */ > static __always_inline int spin_is_locked(spinlock_t *lock) > { > return raw_spin_is_locked(&lock->rlock); > -- ~Randy