Received: by 10.223.185.116 with SMTP id b49csp4769094wrg; Tue, 27 Feb 2018 02:13:35 -0800 (PST) X-Google-Smtp-Source: AH8x225oKrA7ZnU1RLZzKi2ITOsRSW1wGk2qQZ8Uy9rQ/19S9F91OjgfhGSJXOfkaQ6AnSo3ZOBF X-Received: by 10.98.102.155 with SMTP id s27mr13722133pfj.198.1519726415304; Tue, 27 Feb 2018 02:13:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519726415; cv=none; d=google.com; s=arc-20160816; b=dxtDTYUfxYv1LS2T/MGe70rWIcBg5FxoRiqPL9Kh73W13ynP13G2xeOmurixIjb4FU wPAZxkJ4eASWp0U2hQYh6hcrb7jgOWc69ndMUewnaXByDMsGH6/PW2SViPGlhjmBXH4x wE8abzmtf34ueIxW5qYI5UekHNk+/RYWADlWcYTq4GTEk4fikNSZppos8YOPagt/ZGl8 jUWJm1biVVKp2b4WPEr367M9WwnIzTRJ+QPDWVVU8VDuBWQZFEFs7naJpE0uZ4pz90/3 4scqMs3FU0XINEeDWmuT+WxbbOje3rCIa4Cl9rPZNnFupEmdXzcftcepcjcFeXyDcBD9 WsIA== 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=aXx6Ajcm+Z5aknxq4T1YMFbSPHz1Di5gxHXsK3XqsJU=; b=A0rbCl6TnS9b36o5bNChKgx2DHLNldEWEQpo1M+zWRdMvJb9HN08QcajvCCCs1UWon 3+WIt6d5vhlWPquJT9InlCObzzQl1k/gU9RubDMg8XiUXYn96JicrTVIloLfgf0GO6zv t89ainw2KRx2uqvsKA+StA0DW/BFdlk/zsBRz3/2RLpijIVvJrk9Ks2TQY2NHTmCI7Fj /nBkp6RioKNR6SzzYkHnY9Lxw2yGEK/f2GU74SzyyCwwfFq23Kb2JGhKJSgYuDg/R5GY snkMwAcosvOGKQc5jlK/r667MvVKmMYDx/bXaMmmY8doZbc738FEWYYIDUCj2nE6aGb3 9/IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cBuELSG9; 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 o18si6879119pgc.4.2018.02.27.02.13.19; Tue, 27 Feb 2018 02:13:35 -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=cBuELSG9; 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 S1752634AbeB0KMl (ORCPT + 99 others); Tue, 27 Feb 2018 05:12:41 -0500 Received: from mail-wm0-f41.google.com ([74.125.82.41]:36910 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752384AbeB0KMj (ORCPT ); Tue, 27 Feb 2018 05:12:39 -0500 Received: by mail-wm0-f41.google.com with SMTP id 139so9512455wmn.2 for ; Tue, 27 Feb 2018 02:12:38 -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=aXx6Ajcm+Z5aknxq4T1YMFbSPHz1Di5gxHXsK3XqsJU=; b=cBuELSG9zLXHk03Pc0bobsDAVQfDOJsgsLmPGq4v8SnBEgCKXAuIJzKNIC+BugoISv 9VppJY9uJS4ICPih6PIt8/g7ckVKX5uzbHo+v2hxKyNYTkkCyl7L97ApDjwnYv+lAl4n PoWwEC8iHJV9HuConSABxarHMjaCR5sQXgK9XG8KeG3VyS2rrYw3cZMea1YS5xxfIjdc OD2vcEVJg5HXh3tV6j9A3f7enVY59j7hCt3SJVSNxxTE76bbp3PuWtdoLzuvGqZNXkZP LiwVzw/cSB9KGAQjoTi3SpQWgKnPIhpn4u9rRHJ2wln30WxN3TH5ZRPusxIesVdQd5xT 4jaQ== 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=aXx6Ajcm+Z5aknxq4T1YMFbSPHz1Di5gxHXsK3XqsJU=; b=pZosaL62Gl4uEK5rYcvVlYiJeQuJZqHnrhNSZlJY5i8cBbEHcsH2Lwhb8eWyJ6EQsr GOq78GIqM8ZRNQiZVIwHKgdFnhbVbrsQ3HkTFnGFq+AuWsKv3ulV9XgUMFuKhWCt2fUU JRbZzjNec12c39ZBp4hjm8WNcpjg4+Zn/o+fDUqeygIqJ2WJm29aNYW3sLwgeLgaITmk +DVS3BmbpmLWAztJm4j+AvOJxHv6MrhMxQa5KiY/RC2xml18n99hV7wAn7Vv/wWxMuST 03fxOC/S5fqdNoHU2Gf28tmFei2o3oAwrYf3Ef5GQonLwKprQ8y2V+5Gz9hoGpCTt8Ad Av6g== X-Gm-Message-State: APf1xPCJfk3NLESn5oSI2T/Jbq1g9xND546qPPHaCdUXpP6TD4hJwkuG DwthHqHvzxT4Xhoj2zIXtj8= X-Received: by 10.80.206.22 with SMTP id y22mr1458340edi.137.1519726357690; Tue, 27 Feb 2018 02:12:37 -0800 (PST) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id m1sm9044567ede.39.2018.02.27.02.12.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Feb 2018 02:12:36 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id 3C691210C0; Tue, 27 Feb 2018 05:12:33 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute6.internal (MEProxy); Tue, 27 Feb 2018 05:12:33 -0500 X-ME-Sender: Received: from localhost (unknown [45.32.128.109]) by mail.messagingengine.com (Postfix) with ESMTPA id 9BFBE247E8; Tue, 27 Feb 2018 05:12:32 -0500 (EST) Date: Tue, 27 Feb 2018 18:16:05 +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: <20180227101605.tlo37kjhc673pzqj@tardis> References: <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> <20180227050635.es5v5yogz3x4qrtz@tardis> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="igtgcicfi4tjp6fy" Content-Disposition: inline In-Reply-To: <20180227050635.es5v5yogz3x4qrtz@tardis> User-Agent: NeoMutt/20171215 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --igtgcicfi4tjp6fy Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Feb 27, 2018 at 01:06:35PM +0800, Boqun Feng wrote: > 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 = wrote: > > > > > > > > That is, locks are not implemented from more basic primitive but ar= e specified. > > > > The specification can be described as behaving that way: > > > > - A lock behaves as a read-modify-write. the read behaving as a r= ead-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 >=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. >=20 > Regards, > Boqun >=20 > > and that could fire. Is that relied on somewhere? > >=20 My bad, I misunderstood your mail. So you were saying the BUG_ON() can be triggered in currently implementations. Never mind my reply above. Regards, Boqun > > Will --igtgcicfi4tjp6fy Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEj5IosQTPz8XU1wRHSXnow7UH+rgFAlqVL+IACgkQSXnow7UH +rig/wf9HxNie+FgAAzVu4KyG9gEoXpAnhjMLnaOBI669E0oevin3ofeH+0jKUXt 3aB94uubyzWM3ssA+15cIMZ0cOKAKRFiY6+lGQBpZaJV4lnQabieDl9DMftDTWuB agIPwINLRFJXmfC/fSkGqVxgzBW0fiy2kAcmfVLxTZx/SiTAZwr0EoOkrgDscaUv TujrM4iDfpOYht971f8V8ZeyTB2+dYjS4H6OayUEim/94gBfkXRsfblJky4lfMOS ozgHK9ro1jBopm/CR0O6vMRj5CmKKUM03pCpHMTnSNiCCUUFBQsHvA/uqqLAhiEe rqQkBxkhPsXy/i98RryOja7lMx5DlQ== =5XUX -----END PGP SIGNATURE----- --igtgcicfi4tjp6fy--