Received: by 10.223.185.116 with SMTP id b49csp4542572wrg; Mon, 26 Feb 2018 21:04:29 -0800 (PST) X-Google-Smtp-Source: AH8x224ZlGfSo/KQwwedzLYZXFnKaRMNumjExqLo3wofpmrGm9G6REOuV1ekH6WrRLGbAg92KxS5 X-Received: by 10.99.146.68 with SMTP id s4mr10294384pgn.295.1519707869374; Mon, 26 Feb 2018 21:04:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519707869; cv=none; d=google.com; s=arc-20160816; b=ezJPliC4gkmaoe6Z8YUXUqmo6ZGATbRBdDsuNFJBRWW7wvyQfjtirGB2/qOB0h7ZLZ TeWDht4LRV5Lr0LEBUSDzML+D4bJ2BFG4cFHs2qpV6BCc8NabjHodpYbXtX1JWKhT+Yo wNaZLNnBKZ/QJWfjLERmz7AycZETcjfx+Gjl+y0hCSoGmPb1suNv53OP174P+0loL3+u Ni16YcMrq/PezAVJKvcsrs4piZ/Ct24om6uHwOnlZ+kJCkSL1dZDBAgHcc8NsdtbiCSg zaKev+QwBRV8dD7HJ9dhE3JhSZCydeIr7Vu+RTZFH/WSMSevc9qWO44a4RkWSGprbtEa CFtw== 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=XJY+P0KEQvnN4Dwc1NzQM1AqJUQYd9pjxfgV8G1BFT0=; b=jy41MCfiqbUNRgre+gEHZgXa4LlqbrB+t7lxNZzX1sn1XBrbaAWlXBiCiYBGoyxky8 j16Tjl7NdxWQMERBk55XHWUGN1lOE0ZsE3o8N6efpJSb7sgyct8gBSXLyqf6HYBuvEIW 7Y7Jdi6nOgjn0KIn1Km1NdRj6vGkDiOzSIA7GowoBnWQj/bFsXDMIcD4AJhQMDxrTwKz LxOvWS8qw3vKn6l/WgMmU4WCnwETNYs+NnelIXbuFvUHJ58mmn/tFIzk0ZwfxsbKlcez zyEGnH65vsPcKvejZ3a8pC7KcSXdR94lfIYEZVliNvTsqLAWvRRVW3lOYiYElz4Z0RYv 3pfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ny/ploZT; 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 b7-v6si7840476plx.805.2018.02.26.21.04.14; Mon, 26 Feb 2018 21:04:29 -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=Ny/ploZT; 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 S1751117AbeB0FDG (ORCPT + 99 others); Tue, 27 Feb 2018 00:03:06 -0500 Received: from mail-qk0-f195.google.com ([209.85.220.195]:35986 "EHLO mail-qk0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750789AbeB0FDF (ORCPT ); Tue, 27 Feb 2018 00:03:05 -0500 Received: by mail-qk0-f195.google.com with SMTP id d206so22054331qkb.3 for ; Mon, 26 Feb 2018 21:03:05 -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=XJY+P0KEQvnN4Dwc1NzQM1AqJUQYd9pjxfgV8G1BFT0=; b=Ny/ploZTgwNvNol9E0c6wviJWDIUe7s+6tWgTv3I8LcU5iq94EH7DkKHTTVDJU7O/8 h63CQIDuhBM3+nHErdHY/a2JcVVtw90YSEXNJTjN6LO1kvhyNuwR4d3uMYDG7hZtRf0m ckkVnRLFsqtXzvFD5NOFOIOIwE/XA+DvFwU+zqFbGigh9NFSQidOMs/VLA5aJMYCG3q8 vXi5c8fn5VrNg14HynHdU6pcoBIb0WUrUs0CV5+dwVeQuoaSmVYOxXJo7l5zyZogvWSs 3/OlnkaUI7sXlhTGO8YLSJqXWEiz+8zhjFH8ckb0z8tNGzjO8oIVHt3Ddi+P5L+EZ4KM /B8w== 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=XJY+P0KEQvnN4Dwc1NzQM1AqJUQYd9pjxfgV8G1BFT0=; b=rkJoQymfqPsUs4mnQhbVPSiBjLCap9x4ucBP69xLAWdiwp6oUt1dWWG6E/7x110Vra bMK0RX6qzN42k+tjrfc4Dcta4HlsWSOaNmbd+sWxyLCMOaMpSmzTNCe/fC3A50aXIQ3+ AQ1cchwHMMLUdQZ6EULUgV/pE94zL+M36V0XWsq1QgCcbG+O3NWynDKJdEQxr6/vcesK jtqX7RXG7IwFmYejS2ZnHDlmTDR8uB9nI5lwjgiruNzRse5og+ybaKNy8mm61nVlrNXh /zWZIafp+3QARWlmeGfp8MrX7ATJ+ljt6cq/0dCW3fSP5T6YjHUMWDIgEYTEkl13kUq0 ufPA== X-Gm-Message-State: APf1xPAgBA6BRinNKuJEyg0V4IgNhlvUHsK3/KFTTRB4wJbEQjxB5Yu0 XSctb3R+Iqe37rBNE6TTHQsA7CiX X-Received: by 10.55.16.21 with SMTP id a21mr21309197qkh.61.1519707784654; Mon, 26 Feb 2018 21:03:04 -0800 (PST) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id h127sm5371437qkc.70.2018.02.26.21.03.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Feb 2018 21:03:03 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id 1315720CCD; Tue, 27 Feb 2018 00:03:03 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute6.internal (MEProxy); Tue, 27 Feb 2018 00:03:03 -0500 X-ME-Sender: Received: from localhost (unknown [45.32.128.109]) by mail.messagingengine.com (Postfix) with ESMTPA id 6E991243C4; Tue, 27 Feb 2018 00:03:02 -0500 (EST) Date: Tue, 27 Feb 2018 13:06:35 +0800 From: Boqun Feng To: Will Deacon Cc: Linus Torvalds , Luc Maranget , Daniel Lustig , Peter Zijlstra , "Paul E. McKenney" , Andrea Parri , Linux Kernel Mailing List , Palmer Dabbelt , Albert Ou , Alan Stern , Nicholas Piggin , David Howells , Jade Alglave , Akira Yokosawa , Ingo Molnar , linux-riscv@lists.infradead.org Subject: Re: [RFC PATCH] riscv/locking: Strengthen spin_lock() and spin_unlock() Message-ID: <20180227050635.es5v5yogz3x4qrtz@tardis> References: <1519301990-11766-1-git-send-email-parri.andrea@gmail.com> <20180222134004.GN25181@hirez.programming.kicks-ass.net> <20180222141249.GA14033@andrea> <82beae6a-2589-6136-b563-3946d7c4fc60@nvidia.com> <20180222181317.GI2855@linux.vnet.ibm.com> <20180222182717.GS25181@hirez.programming.kicks-ass.net> <563431d0-4fb5-9efd-c393-83cc5197e934@nvidia.com> <20180226142107.uid5vtv5r7zbso33@yquem.inria.fr> <20180226162426.GB17158@arm.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="xreb33oq7irsncof" Content-Disposition: inline In-Reply-To: <20180226162426.GB17158@arm.com> User-Agent: NeoMutt/20171215 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --xreb33oq7irsncof Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Feb 26, 2018 at 04:24:27PM +0000, Will Deacon wrote: > On Mon, Feb 26, 2018 at 08:06:59AM -0800, Linus Torvalds wrote: > > On Mon, Feb 26, 2018 at 6:21 AM, Luc Maranget w= rote: > > > > > > That is, locks are not implemented from more basic primitive but are = specified. > > > The specification can be described as behaving that way: > > > - A lock behaves as a read-modify-write. the read behaving as a rea= d-acquire > >=20 > > This is wrong, or perhaps just misleading. > >=20 > > The *whole* r-m-w acts as an acquire. Not just the read part. The > > write is very much part of it. > >=20 > > Maybe that's what you meant, but it read to me as "just the read part > > of the rmw behaves as a read-acquire". > >=20 > > Because it is very important that the _write_ part of the rmw is also > > ordered wrt everything that is inside the spinlock. > >=20 > > So doing a spinlock as > >=20 > > (a) read-locked-acquire > > modify > > (c) write-conditional > >=20 > > would be wrong, because the accesses inside the spinlock are ordered > > not just wrt the read-acquire, they have to be ordered wrt the write > > too. > >=20 > > So it is closer to say that it's the _write_ of the r-m-w sequence > > that has the acquire semantics, not the read. >=20 > Strictly speaking, that's not what we've got implemented on arm64: only > the read part of the RmW has Acquire semantics, but there is a total > order on the lock/unlock operations for the lock. For example, if one > CPU does: >=20 > spin_lock(&lock); > WRITE_ONCE(foo, 42); >=20 > then another CPU could do: >=20 > if (smp_load_acquire(&foo) =3D=3D 42) > BUG_ON(!spin_is_locked(&lock)); >=20 Hmm.. this is new to me. So the write part of spin_lock() and the WRITE_ONCE() will not get reordered? Could you explain more about this or point where I should look in the document? I understand the write part of spin_lock() must be committed earlier than the WRITE_ONCE() committed due to the ll/sc, but I thought the ordering of their arrivals in memory system is undefined/arbitary. Regards, Boqun > and that could fire. Is that relied on somewhere? >=20 > Will --xreb33oq7irsncof Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEj5IosQTPz8XU1wRHSXnow7UH+rgFAlqU51gACgkQSXnow7UH +rhZlQf/Qw9tLoKGXTMM//TJoOoReDlWxLq4jNBOFnq/rWhBh9b5uYajj5n73++I ON+d+tpkOiNTD1vVTQtZEGXIqriDVMa88XSPbkPkUTn8zOTEXi7XbV+f6zl/MCK5 brMdbKkCV3erBzOTjeIX5lL74mV119k/NgH/i2nb2A/bjmwq5dE+mcGI2za6MWfO 8Dy6ziqQeC1/6HgXQVA5qUZiXjRIXj1AroJFUZV5m4iMQ+wK91hFB2q6O/ahAmJH RnsDNJGjMl03EXC1biOMWuQk8A6eno3eYA6Oz2Sqo4FviRG+e/PvzSdlQj/vz58c B92MHEgxkW6ZAlplbPwWsMUIll95ZA== =zGTb -----END PGP SIGNATURE----- --xreb33oq7irsncof--