Received: by 10.223.185.116 with SMTP id b49csp6063319wrg; Wed, 28 Feb 2018 03:25:14 -0800 (PST) X-Google-Smtp-Source: AH8x224febl/T1BwXbRnGEu8E4U2iYDIrSRy+hVkU/I9HEP4FfnverzVbR1C7DxuF8rvZLv+6Ckd X-Received: by 2002:a17:902:2de4:: with SMTP id p91-v6mr17789306plb.405.1519817114303; Wed, 28 Feb 2018 03:25:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519817114; cv=none; d=google.com; s=arc-20160816; b=cPe0xjUq/04Csfa+g0oPJzApo0XfGvEFgD943wUAAGhnyYITQ+b1ITOYGYJhlskSgB 3YEqBFrnIxTBb89NfEujPjBtv8DwfAKTjsTdY2GDdxs2bAAi6cP16lPSYphNYyPrrKvd lv+jPwy2Wqsc9O5ABiG974X7N8ewbgLhNipjIROKRlFJ+nrs2I8pGHj3sbbdEP+grr83 B4ZKqjCrh85j/9A+WiCIo1ziu6a6goKRhDUo97BAOsHwUYyX8X0MUgpXCqwXudy1RocA ELNEFT/wIWycDP9HQFL7+OFmipyl5yhdjeyDbkfCfChyMSjG1jpo56cfkCXMpZMIqI6v 2JOA== 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=CBG7Z+R+28SxmWOj4dRIaVBcJykfj4bEvxuW/kAjLgw=; b=F9hTNZ5XFtQkw2+uAiNu4bd2AysDCi9Qx3lCbMBjqKa2Uck8+ToXSjeDCd2ibiKSQr 6sOeLOY/wiB17g4MciopUbptejjmJHj/V4FmI0irPbMC5dksaPxtL+Uz4dhs08Whd5Te TC4+Bamcf4eHykgwFY8UDUkZfEAqOLPBoZNLY3v8Bj1mdK5pZqubuw5XfcvPxPFhhRYM kRktH7Ws0tevCGdiAsu0RVk32wk6luVXSQpz/3w2XLpiaD0iI1Q2PGCXa5d0BqJ7WYob og+cdjeesJeTxwb7mwDWf3xryHnLmLi7oVao84DFzA8o+fKH9knl+8lNIJL/UcyFxrzr k0PA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=SN1PDxWF; 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 j8si1089751pfn.234.2018.02.28.03.24.57; Wed, 28 Feb 2018 03:25:14 -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=SN1PDxWF; 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 S1752257AbeB1LYM (ORCPT + 99 others); Wed, 28 Feb 2018 06:24:12 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:42203 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751899AbeB1LYL (ORCPT ); Wed, 28 Feb 2018 06:24:11 -0500 Received: by mail-wr0-f196.google.com with SMTP id k9so1990561wre.9 for ; Wed, 28 Feb 2018 03:24:10 -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=CBG7Z+R+28SxmWOj4dRIaVBcJykfj4bEvxuW/kAjLgw=; b=SN1PDxWFUO7IPl4ct5sDb7brt4WNBAxSxPhFJzmkk1XCrOQr+qvmC4wz2gnI/4K2zp RAr6q12PSKcgTdVJ051SfoTRxljASAuctC8kRe33CaN4MNyduwV6FIEql9SuxhTtxmy4 cazS03mmePqeZ+rzs6gAYSGYIUzvp714951qpaXTMA0Dz130CMomQY6ixNll89xwSRA+ G/V1P8/FvD+s2lIzsspqV2FspEDoyzI7yJdT61XWNsN7KlMF+b4Dr6yvfv3ko7wohemn DBUGn6fFKBqc4uBdqS4fjtO49gmIgRCvRQ+GK5epXv5yTGDoxULveNaXCr+4Igg5mtnK YXJQ== 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=CBG7Z+R+28SxmWOj4dRIaVBcJykfj4bEvxuW/kAjLgw=; b=QHsevhBvzWGTa0RcsA3NDhmVVtb//DV7/5CFa5S+eVFKWPewNj91LxP+OBBJXP9JoM QS32ezzrOGFYyc6YHuxBVAcMrS7As/E/BAlmN1dKzeuharbCnBoGhR4Ii4t3bJCB19ql f3jNLizBzRVsSlj8wvaTD+ZWLqUsmBvct5xWhdM5RG9NQBcsPkBe9reAdNVsE+6z9KU4 S4ugcbPnjnppsi2nLWjfWB1AGVXuU1RXfc33TPX3rWTAg7MWut4MQWQnEaO6sCw/l9rh AUKLbQqhUr2MPHVMG+Q6bqLSnV9Juu7Rt68eKfk7dLtcQyrI7pVdp4s7OkzngsJfXVMf 3vDg== X-Gm-Message-State: APf1xPCvCiKpgIMV/yJhg78cDW6HU/WuJSg1zfn4n+E/3XxkcEeN1sQx cGv1AZQjabECXVGciewRLiU= X-Received: by 10.223.153.51 with SMTP id x48mr14847398wrb.216.1519817049727; Wed, 28 Feb 2018 03:24:09 -0800 (PST) Received: from andrea (85.100.broadband17.iol.cz. [109.80.100.85]) by smtp.gmail.com with ESMTPSA id 198sm3089666wmg.8.2018.02.28.03.24.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Feb 2018 03:24:09 -0800 (PST) Date: Wed, 28 Feb 2018 12:24:03 +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: <20180228112403.GA32228@andrea> References: <1519814372-19941-1-git-send-email-parri.andrea@gmail.com> <20180228105631.GA7681@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180228105631.GA7681@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 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 ... > > 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 ... Andrea > > Will