Received: by 10.223.185.116 with SMTP id b49csp3802423wrg; Mon, 26 Feb 2018 06:22:22 -0800 (PST) X-Google-Smtp-Source: AH8x224l760LuKh/RsomKJlIsri4gapqWgEibFZA8nTrJkvgRBk7NUCpUFvcrniQGyQRWOoEWOoc X-Received: by 10.99.63.139 with SMTP id m133mr8472189pga.174.1519654942410; Mon, 26 Feb 2018 06:22:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519654942; cv=none; d=google.com; s=arc-20160816; b=SrrwikwOHODl7/32lZYe3yWWyv7ettZmWLO4KAS5jsPm/9/ebKV6wlaXH6nMXFOH+D cbbwKHtICA5IHHDM0DHBKp4EBnZzOUdOxxSd0r6a8aGNt3zO/kycuLimVpX2NLV8jwhW e2g7p5Lv/wEsqcRWw4eMAgUDeNZCNiN9xP4W3avMnIoxsEAEjp0d1SS3UVtenIJQ27dq tm2SWNWQwkM1WPLm4CVRtr6LdZFrpGxTKoquaP5GHuWqsivSDz/gu8+uBymUhHdgOXzC W+P7iVMwbM8TbhvfwuddYAE/5yA8fwifWEt2vfV/bJ2a0gHNjZ39lCkqhX1iSOYvs+6z 3JLA== 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:date:from:arc-authentication-results; bh=uNqlC8MtzUCphtDKKOO8y1go3Lx+TH219GCYpu3BpcU=; b=EEHnSPN1/bPJwHDp9WjHHP+/540CR8Ag6rGS3T/ohDpjzWEDy0D95emzLdvPFz1mll HCIjN3KVfmwTKYdWOqKb5HbOwIS+ORMcIm6ETsPoXEXggH63GZMn0jfj8blZ6yKxuYD+ rT12ePU83/oHP25GnOVIBkMznhrRwJJVjNdiaU8o4tyTWa2rL57Ny+xMH9wzJpT9xAsH S4mFVYuJET4To2a4vgVuaUZa4yjCDSWlG/C/eZ+xLRHSHYq0TMg+cblVpP2HywrKrJ8V eAWK64/pQydQIMN+KWyhoncZ9xoVBX4cM3zwIbhgIzHzlAiU4W2G8QDdFlyvXptzPDjn c7Wg== 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 l29-v6si186666pli.25.2018.02.26.06.22.07; Mon, 26 Feb 2018 06:22:22 -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 S1753376AbeBZOVL (ORCPT + 99 others); Mon, 26 Feb 2018 09:21:11 -0500 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:41909 "EHLO mail3-relais-sop.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753298AbeBZOVK (ORCPT ); Mon, 26 Feb 2018 09:21:10 -0500 From: Luc Maranget X-IronPort-AV: E=Sophos;i="5.47,396,1515452400"; d="scan'208";a="256138438" Received: from yquem.paris.inria.fr (HELO yquem.inria.fr) ([128.93.101.33]) by mail3-relais-sop.national.inria.fr with ESMTP; 26 Feb 2018 15:21:07 +0100 Received: by yquem.inria.fr (Postfix, from userid 18041) id 5CA92E1D56; Mon, 26 Feb 2018 15:21:07 +0100 (CET) Date: Mon, 26 Feb 2018 15:21:07 +0100 To: Daniel Lustig Cc: Peter Zijlstra , "Paul E. McKenney" , Andrea Parri , linux-kernel@vger.kernel.org, Palmer Dabbelt , Albert Ou , Alan Stern , Will Deacon , Boqun Feng , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , Akira Yokosawa , Ingo Molnar , Linus Torvalds , linux-riscv@lists.infradead.org Subject: Re: [RFC PATCH] riscv/locking: Strengthen spin_lock() and spin_unlock() Message-ID: <20180226142107.uid5vtv5r7zbso33@yquem.inria.fr> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <563431d0-4fb5-9efd-c393-83cc5197e934@nvidia.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On 2/22/2018 10:27 AM, Peter Zijlstra wrote: > > On Thu, Feb 22, 2018 at 10:13:17AM -0800, Paul E. McKenney wrote: > >> So we have something that is not all that rare in the Linux kernel > >> community, namely two conflicting more-or-less concurrent changes. > >> This clearly needs to be resolved, either by us not strengthening the > >> Linux-kernel memory model in the way we were planning to or by you > >> strengthening RISC-V to be no weaker than PowerPC for these sorts of > >> externally viewed release-acquire situations. > >> > >> Other thoughts? > > > > Like said in the other email, I would _much_ prefer to not go weaker > > than PPC, I find that PPC is already painfully weak at times. > > Sure, and RISC-V could make this work too by using RCsc instructions > and/or by using lightweight fences instead. It just wasn't clear at > first whether smp_load_acquire() and smp_store_release() were RCpc, > RCsc, or something else, As far as I now understand, they are something else. Something in-between. Basically, considering a multi-copy atomic model, and following RISCV axiomatic herd notations RCpc [Acq];po in ppo (ie Acquire "half barrier") po;[Rel] in ppo (ie Release "half barrier") RCsc adds the rule [Rel];po;[Acq] in ppo. (ie Store release followed by load Acquire is kept in order) While LKMM has a less constrained additional rule [Rel];po-loc;[Acq] (ie Store release followed by load Acquire from the SAME location is kept in order) (For specialists LKMM is formulated differently, the overall effect is the same) > and hence whether RISC-V would actually need > to use something stronger than pure RCpc there. Likewise for > spin_unlock()/spin_lock() and everywhere else this comes up. On may here observe that the LKMM rule is here precisely to forbid Andrea's test. In that aspect,the suggested RISCv implemention of lock and unlock on spinlock_t is too weak as it allows the test. However, I cannot conclude on smp_load_acquire/smp_store_release (see below). > > As Paul's email in the other thread observed, RCpc seems to be > OK for smp_load_acquire()/smp_store_release() at least according > to the current LKMM herd spec. Unlock/lock are stronger already > I guess. But if there's an active proposal to strengthen them all > to something stricter than pure RCpc, then that's good to know. As illustrated above RCpc is not enough to implement LLKM smp_load_acquire()/smp_store_release(). However, I do not know for sure what the current implementation of smp_load_acquire() and smp_store_release() (ie LLKM primitives) in RISCV. As far as I could find the current implementation is the generic default that uses strong fences and is safe. On a related note, it may not be clear yet to everyone that LLKM has "platonic spinlocks". 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. teh read behaving as a read-acquire - A unlock behaves as a store release. - Lock and Unlock operation (to a given lock variable) alternate in some total order. This order induces teh usal relations between accesses to a given location. This of course strongly suggest implementing lock with a RWM (R being acquire, ie amoswap.aq in RISCV) and unlock as a store release (ie amoswap.rl in RISCV). And again, this is too weak given LKMM additional rule for RC. However, nothing prevents from a different implemention provided it is safe. As regards LKMM spinlocks, I am not sure that having strong implementations of lock/unlock in Power (lwsync) and ARMv8 (RCsc?) commands a specification stronger than the current one. > > My understanding from earlier discussions is that ARM has no plans > to use their own RCpc instruction for smp_load_acquire() instead > of their RCsc instructions. Is that still true? If they were to > use the RCpc load there, that would cause them to have the same > problem we're discussing here, right? Just checking. > > Dan