Received: by 10.223.185.116 with SMTP id b49csp3932846wrg; Mon, 26 Feb 2018 08:25:44 -0800 (PST) X-Google-Smtp-Source: AH8x227yrDBJD/1NnBr0p8AKaxMBwr6W03pt92E7k3Q2iCopWQoEbskKGZeA61BUvzu63p4Dg6w5 X-Received: by 2002:a17:902:8b88:: with SMTP id ay8-v6mr11190035plb.197.1519662344140; Mon, 26 Feb 2018 08:25:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519662344; cv=none; d=google.com; s=arc-20160816; b=r27lAcYlWTPcxeYHmbj3Njv8ADU1WnX2ELeROciB+nttgOzFSHcQPGCutsb1N2eZ/m kshUMZ8Jx7xU8VU0RpPgKAIOiNgWGkNEHO6VuTfryAhwPQJjYmwpRFygaKKjeNvUGcVH LT1GMQU4DNXypKJsdkCj+PVH71c2ZpwIFiIBR0mLSCmAYOHf2bDoHza4IMLDdx6fS/Ap el43+5XK9MJ993uQzDBuDKsW/NStSKhqoFXThdK3PJx/ir1gIKtcCE2IuG9nn1PyMuuh lHfsC/KYkQfA+Aw1DgstFQHcxlwkTj9hf8hLKFAe7Rmytt+I4X6jYj+qyHiXm+srAW3c eCvg== 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:arc-authentication-results; bh=0VksHKLiysxjnSHM7RAGQ0GiACaoksYh2X5dtV51AXc=; b=GkWPe9UCYs1ZDQJIcF9sP5uNCVdrhAuJUgCKT1lKa/oH79wmxVCluDYejrmY3OnQHR hyZT4FMZRLlEGJLv5/rP4/j0TiHnLO6HVM8BsPvHDMEWVsezUQsYdQzP5lx2cAgMWYtz WHTfZ1zeNmxPgduUKZ/Dlar/VF0UfOEGXWt44Hyhk43cU/DC6xKzQvsfUhudHNBWDHfN WBUvAamQmcFGIsTXvHOaRIgBt3XL0XG5kCCuyXiLp3ehDi2B8HbWCT1Rrq3kFqpFyE69 3NndYuQcA7vBr2lzd2RC1Rpy1/UR6p/4418cPLIDfcRFzg2HCLoAYXzvfaejblR/RTSY tgTg== ARC-Authentication-Results: i=1; mx.google.com; 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 t195si5698379pgb.692.2018.02.26.08.25.29; Mon, 26 Feb 2018 08:25:44 -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; 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 S1752121AbeBZQYn (ORCPT + 99 others); Mon, 26 Feb 2018 11:24:43 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:52686 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751735AbeBZQY0 (ORCPT ); Mon, 26 Feb 2018 11:24:26 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0641415AD; Mon, 26 Feb 2018 08:24:26 -0800 (PST) Received: from edgewater-inn.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id CA6153F24D; Mon, 26 Feb 2018 08:24:25 -0800 (PST) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 66EAD1AE5227; Mon, 26 Feb 2018 16:24:27 +0000 (GMT) Date: Mon, 26 Feb 2018 16:24:27 +0000 From: Will Deacon To: Linus Torvalds Cc: Luc Maranget , Daniel Lustig , Peter Zijlstra , "Paul E. McKenney" , Andrea Parri , Linux Kernel Mailing List , Palmer Dabbelt , Albert Ou , Alan Stern , Boqun Feng , 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: <20180226162426.GB17158@arm.com> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 are specified. > > The specification can be described as behaving that way: > > - A lock behaves as a read-modify-write. the read behaving as a read-acquire > > This is wrong, or perhaps just misleading. > > The *whole* r-m-w acts as an acquire. Not just the read part. The > write is very much part of it. > > Maybe that's what you meant, but it read to me as "just the read part > of the rmw behaves as a read-acquire". > > Because it is very important that the _write_ part of the rmw is also > ordered wrt everything that is inside the spinlock. > > So doing a spinlock as > > (a) read-locked-acquire > modify > (c) write-conditional > > 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. > > 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. 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: spin_lock(&lock); WRITE_ONCE(foo, 42); then another CPU could do: if (smp_load_acquire(&foo) == 42) BUG_ON(!spin_is_locked(&lock)); and that could fire. Is that relied on somewhere? Will