Received: by 10.223.185.116 with SMTP id b49csp7545057wrg; Thu, 1 Mar 2018 07:13:17 -0800 (PST) X-Google-Smtp-Source: AG47ELtesaILNJ4MCyrUz89AcsDyqHs4NyL/Zaq5yp8lHWURCaRp42LiFvTW8G0sFsJwv3EQXRBM X-Received: by 10.98.242.65 with SMTP id y1mr2237086pfl.232.1519917197819; Thu, 01 Mar 2018 07:13:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519917197; cv=none; d=google.com; s=arc-20160816; b=WxW6HYjaAhi2lPCBr2FSIv03Z1gJM3AEhpdnoy+mevsK0LMaZK0aAJjleCpWgbHrM7 3GI6hU9srOI/qIGcrA7A+nC5zIaMTFPcKjMB28OZCq9MTwfdE8yPj+je8Gpu/wRoMw7o R/pp2MrZMeQmRPAAo0UafcpWmK6mS2QPY0HXiSoqqnjTdqXHlZPn3c+Rcm7jdG8mi5b4 ibhuck5jO5YxlMBeAXNRHRkKsOS/pcvnLKtPNlRjfpCRkn8/e653asyI0zzBdNz6NYyM 5rqH9+bWmi7fwhq93jWgPJCEFWWny9znC1RxXJj9yF37TVQA9Mdv11XjGo4YfLOBuHTw 57kA== 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=slfKDBO98Lr2Cxv671dgJaxpUsK9A8EQR0//iFXUMN0=; b=pYVoDZ4juk4zkKzXeVKRDSGFj0uB1Kh6yHnfbjsmMxyTF/JQWP67nIJ1GN9bolkd1a KRw98BhmCvf6mhkDzld9JRfz5Z8VAZdE+48XGAkQOtexsaQDjWiBVe4NDOd+gmLTQ/vN WCPkTrZF+n7J78i26WavSbZEg9XzhOW3PDXj3cklCUSvovZ8BXovHcXxW+iKJOoxFRri ujiVLW5JJ6tVbrb0IOfI/AF/eg6ySnBOcj/uUqOGlg79CsuY7WyrGQxOhNXraM9Bqovx onuJ8PMmd8jtKRfl0DegcWhz71RjPv6+cNXMtdiLJl8HgUN3FZLjOxCw3BI9FfHzYj9B CSuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=C2O1ijIG; 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 p8-v6si833895plk.642.2018.03.01.07.13.02; Thu, 01 Mar 2018 07:13:17 -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=C2O1ijIG; 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 S1031687AbeCAPL5 (ORCPT + 99 others); Thu, 1 Mar 2018 10:11:57 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:46537 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031631AbeCAPL4 (ORCPT ); Thu, 1 Mar 2018 10:11:56 -0500 Received: by mail-wr0-f193.google.com with SMTP id m12so6768746wrm.13 for ; Thu, 01 Mar 2018 07:11:55 -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=slfKDBO98Lr2Cxv671dgJaxpUsK9A8EQR0//iFXUMN0=; b=C2O1ijIG7pD0ABeTrIm0ya2SgPfWw7FC5Mb3Ffavx3vshBBKqysBIAJ2ODhRh8mKlA /XdJ3SaWcNQUYbSivt4h7NmfXYszDJqjHAkbV/jXOttYKUc+w7xzOCKT5+EZDjutACz2 m+gR9tobZ8ilP4ZgamT/8Q/Xu6eN8BPIqfVpCCWHdUNLw9IIpH7z6AXMB9yFrgzj+qHG YpvHLIEq1HY/Ix2SvmMB2ipd8Mm5iY/C9YP3VDZV1o24KCBWxhXrSkqILsJsaKoRqhIJ Sd/ml/8G8CSqVrsZ4KCq8p4pVPNftwgKKOubBsBdO4H3VVcRx1hj4FyVClauflmgvssZ bGsw== 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=slfKDBO98Lr2Cxv671dgJaxpUsK9A8EQR0//iFXUMN0=; b=R0GJBcL5bWot868ViifCWw1ZekSB0ZZxaE6w1YdBahe7llLFCA+oy1fVGJBEsja8BZ aTJtUdkaB/O/9clq7oTtzq2gSZ6TkqazypeX4wEXjgElgrKMXBm6P46RXFeGkW3VJGOy YfnX+T59NKtjN/2PGRZrOyYx9vtotNyuoP7uY8Ccr17U7ekBnNszzXzrkdFQura1ngIL IQG36dQLoCHwRURZL7FtsCfIp85EKDZ9ApReKiNlTlYuBQ/aex1yJ0GUSjOPrIilmPZB 0pyjnd7y8wegL0mGfRLrbGePERgUYWFVblSAJSP859S2lABUucpOKIy2QwOmisqw6+p5 bW8Q== X-Gm-Message-State: APf1xPDaFrBQX0DVJnvcb0G6vKDxHvqG0cTnyfSUPtAnLCYhYJp835el zlOwtwZrB7fL2viIZ+VFt8Y= X-Received: by 10.223.184.147 with SMTP id i19mr2046029wrf.102.1519917114489; Thu, 01 Mar 2018 07:11:54 -0800 (PST) Received: from andrea ([91.252.214.236]) by smtp.gmail.com with ESMTPSA id 62sm5302009wml.24.2018.03.01.07.11.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Mar 2018 07:11:53 -0800 (PST) Date: Thu, 1 Mar 2018 16:11:41 +0100 From: Andrea Parri To: Daniel Lustig Cc: Peter Zijlstra , "Paul E. McKenney" , 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: <20180301151141.GA6430@andrea> 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=us-ascii Content-Disposition: inline In-Reply-To: <563431d0-4fb5-9efd-c393-83cc5197e934@nvidia.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 Hi Daniel, On Thu, Feb 22, 2018 at 11:47:57AM -0800, Daniel Lustig wrote: > 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, 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. while digging into riscv's locks and atomics to fix the issues discussed earlier in this thread, I became aware of another issue: Considering here the CMPXCHG primitives, for example, I noticed that the implementation currently provides the four variants ATOMIC_OPS( , .aqrl) ATOMIC_OPS(_acquire, .aq) ATOMIC_OPS(_release, .rl) ATOMIC_OPS(_relaxed, ) (corresponding, resp., to atomic_cmpxchg() atomic_cmpxchg_acquire() atomic_cmpxchg_release() atomic_cmpxchg_relaxed() ) so that the first variant above ends up doing 0: lr.w.aqrl %0, %addr bne %0, %old, 1f sc.w.aqrl %1, %new, %addr bnez %1, 0b 1: From Sect. 2.3.5. ("Acquire/Release Ordering") of the Spec., "AMOs with both .aq and .rl set are fully-ordered operations. Treating the load part and the store part as independent RCsc operations is not in and of itself sufficient to enforce full fencing behavior, but this subtle weak behavior is counterintuitive and not much of an advantage architecturally, especially with lr and sc also available [...]." I understand that { x = y = u = v = 0 } P0() WRITE_ONCE(x, 1); ("relaxed" store, sw) atomic_cmpxchg(&u, 0, 1); r0 = READ_ONCE(y); ("relaxed" load, lw) P1() WRITE_ONCE(y, 1); atomic_cmpxchg(&v, 0, 1); r1 = READ_ONCE(x); could result in (u = v = 1 and r0 = r1 = 0) at the end; can you confirm? Thanks, Andrea