Received: by 10.223.185.111 with SMTP id b44csp1454545wrg; Sat, 10 Mar 2018 06:20:27 -0800 (PST) X-Google-Smtp-Source: AG47ELvwDjBmyXTDeAT4V6Ge+IjrSggIbc12d97VYL9wL1dgZ65xel7J++4IXIWuL9E3hJ4/McPU X-Received: by 2002:a17:902:44:: with SMTP id 62-v6mr2206038pla.193.1520691627158; Sat, 10 Mar 2018 06:20:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520691627; cv=none; d=google.com; s=arc-20160816; b=bIK71skY8tlLKyPinSKFxbLTV0hdqnict8ebXN80uNu3phoD2vxNmSOU3KR7Ec0dm0 seM1S7Lak05shgFYWHuWUVOVfBNpffsnFJknGI0FKsfwqGeIEsZif9+/uwukbzKBNAi+ gWm3194fYa9sje9aOcnAEW/yqOUqNo7hQY7V7lY0YlDrT/G48s5mJK1i/yK+DhCgaZPC hwD9aot2KNgqjY1wsCfv7S2rgNDvM8jDKWG+mZVAtDsuqRYkmx1dqNEoR4u6qu1sxOJ2 N35GKrf8qkzjzS3YeIckJMkw12r02DTBfZfCOH0CpbWkGr6GgZfFStOXSDpvLWVU8ruN Oqbg== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=YM5h6tghFcI733JCkrboMqgz9tLSTaFIRfX2X94IYus=; b=L3SMzDTZywrpHB7H51XeQp0Ltgh6EvrBjf2JBSmAsL0ahTcIqTJveibbjBAtKOOeA+ fK55KdljpTpp6KsoJpIEYagj63+Vs8DTuDOC9OCR9pffy4CB0qnye+z+DlkOKQbbJhmN tuK517EXVbCjjiEcrb7gaShls/DWFjUm75QQx0jZx74rItrGtBPPJ2YcIPAR0Eg3BzCY rrH4GCl01IRjSkXdA5H2XLx4qhj/p4TlhB4Bi7xuriDt85G0l/2DUOGwM2s0bgr+40oP Nv0gQWJ+M5QWRCueqRtI33jZRWOojbhR7I4PLCuf6l39ECksvchUguCfVJjArbZZXWIl fpVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KK/rUOws; 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 p1-v6si1813167plb.297.2018.03.10.06.20.12; Sat, 10 Mar 2018 06:20:27 -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=KK/rUOws; 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 S933170AbeCJOSf (ORCPT + 99 others); Sat, 10 Mar 2018 09:18:35 -0500 Received: from mail-wm0-f48.google.com ([74.125.82.48]:35641 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932274AbeCJOSb (ORCPT ); Sat, 10 Mar 2018 09:18:31 -0500 Received: by mail-wm0-f48.google.com with SMTP id x7so8593031wmc.0 for ; Sat, 10 Mar 2018 06:18:30 -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:content-transfer-encoding:in-reply-to :user-agent; bh=YM5h6tghFcI733JCkrboMqgz9tLSTaFIRfX2X94IYus=; b=KK/rUOwsX3L2GRJCN5o3H7PmPTW2KlWV42CT9MIUmo/df0XYPFeh5afsKFdiH/Zfi/ 7M2+QYPlSuqcbenqP0SUfdDpQSqw4EDgrbDNPOH2fQrByOEsBRHKkQnIbOsY15QmVGiM wZ1Gy19s5VAY0KIs7O+4bkRQaKjHluHXoYzn1wIpG9F+PxFQNrqVHEBd17silr2QTzXY amlFJ3Efmb93mE6xD9RHw8Wz7yUVqlLpJB7jMYfWIXpCCARqMrRvhDVE86ql5y7VBoJq yLsTtmnbfA2h0rqC2vp74CNtAoM8Owke4SXe2ncM8j8+WP3OA2Oo6QKAs5wYb0ZlsaSC d1eA== 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:content-transfer-encoding :in-reply-to:user-agent; bh=YM5h6tghFcI733JCkrboMqgz9tLSTaFIRfX2X94IYus=; b=Eb890T5TTJ9upJ0DUUTR+iiGKxT+4yCQxubTItXf6M6ON8CxOGndoVDzIq0XCWWhyW 9TFqkfY1LYlwaNyxVzCdEx37kGiwCi4SYmLamGYy6R41l61pzeIN5VvbUc/HrWG3XyXf HsYVlMYYV8VBoPXkqVvfgoIi8CF0nN0NF8xJ8RtmlU0YGC66CKQY7Xsli3lyQF7BddB5 OX6sa/Ywd2saYYMDFPebnGug/aVpoyZEyGOEMOT4+rEE3zHYSXj14OLiYea4jw2njY/P 9hhsH8iQBwcMjJNnQrK0QhOgKniPzGRWONJ2QWARioZjsm1J0Bs7fzpyfu/0j35ffMCO c9AA== X-Gm-Message-State: AElRT7GqjcCwbex/r2RLS/kKfF3kUyZMy2P3oK5MufYqUzU6SRAmJywE UEyoG2/fZfSnv4vM2WLauhw= X-Received: by 10.28.167.151 with SMTP id q145mr1361120wme.64.1520691509643; Sat, 10 Mar 2018 06:18:29 -0800 (PST) Received: from andrea ([94.230.152.15]) by smtp.gmail.com with ESMTPSA id q6sm3629746wrc.30.2018.03.10.06.18.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 10 Mar 2018 06:18:29 -0800 (PST) Date: Sat, 10 Mar 2018 15:18:23 +0100 From: Andrea Parri To: Daniel Lustig Cc: Palmer Dabbelt , albert@sifive.com, stern@rowland.harvard.edu, Will Deacon , peterz@infradead.org, boqun.feng@gmail.com, npiggin@gmail.com, dhowells@redhat.com, j.alglave@ucl.ac.uk, luc.maranget@inria.fr, paulmck@linux.vnet.ibm.com, akiyks@gmail.com, mingo@kernel.org, Linus Torvalds , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/2] riscv/atomic: Strengthen implementations with fences Message-ID: <20180310141823.GA5420@andrea> References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 On Fri, Mar 09, 2018 at 04:21:37PM -0800, Daniel Lustig wrote: > On 3/9/2018 2:57 PM, Palmer Dabbelt wrote: > > On Fri, 09 Mar 2018 13:30:08 PST (-0800), parri.andrea@gmail.com wrote: > >> On Fri, Mar 09, 2018 at 10:54:27AM -0800, Palmer Dabbelt wrote: > >>> On Fri, 09 Mar 2018 10:36:44 PST (-0800), parri.andrea@gmail.com wrote: > >> > >> [...] > >> > >>> >This proposal relies on the generic definition, > >>> > > >>> >?? include/linux/atomic.h , > >>> > > >>> >and on the > >>> > > >>> >?? __atomic_op_acquire() > >>> >?? __atomic_op_release() > >>> > > >>> >above to build the acquire/release atomics (except for the xchg,cmpxchg, > >>> >where the ACQUIRE_BARRIER is inserted conditionally/on success). > >>> > >>> I thought we wanted to use the AQ and RL bits for AMOs, just not for LR/SC > >>> sequences.? IIRC the AMOs are safe with the current memory model, but I might > >>> just have some version mismatches in my head. > >> > >> AMO.aqrl are "safe" w.r.t. the LKMM (as they provide "full-ordering"); OTOH, > >> AMO.aq and AMO.rl present weaknesses that LKMM (and some kernel developers) > >> do not "expect".? I was probing this issue in: > >> > >> ? https://marc.info/?l=linux-kernel&m=151930201102853&w=2 > >> > >> (c.f., e.g., test "RISCV-unlock-lock-read-ordering" from that post). > >> > >> Quoting from the commit message of my patch 1/2: > >> > >> ? "Referring to the "unlock-lock-read-ordering" test reported below, > >> ?? Daniel wrote: > >> > >> ???? I think an RCpc interpretation of .aq and .rl would in fact > >> ???? allow the two normal loads in P1 to be reordered [...] > >> > >> ???? [...] > >> > >> ???? Likewise even if the unlock()/lock() is between two stores. > >> ???? A control dependency might originate from the load part of > >> ???? the amoswap.w.aq, but there still would have to be something > >> ???? to ensure that this load part in fact performs after the store > >> ???? part of the amoswap.w.rl performs globally, and that's not > >> ???? automatic under RCpc. > >> > >> ?? Simulation of the RISC-V memory consistency model confirmed this > >> ?? expectation." > >> > >> I have just (re)checked these observations against the latest specification, > >> and my results _confirmed_ these verdicts. > > > > Thanks, I must have just gotten confused about a draft spec or something.? I'm > > pulling these on top or your other memory model related patch.? I've renamed > > the branch "next-mm" to be a bit more descriptiove. > > (Sorry for being out of the loop this week, I was out to deal with > a family matter.) > > I assume you're using the herd model? Luc's doing a great job with > that, but even so, nothing is officially confirmed until we ratify > the model. In other words, the herd model may end up changing too. > If something is broken on our end, there's still time to fix it. No need to say :) if you look back at the LKMM as from 2 years ago or as presented last year in LWN, you won't recognize it as such ;-) Spec. do change/evolve, and so do implementations: if ratifications of the RISC-V memory model (or of the LKMM) will enable optimizations/modifications to these implementations (while preserving correctness), I'll be glad to do or to help with them. To answer your question: I used both the herd-based model from INRIA and the operational model from the group in Cambridge (these are referred to in the currently available RISC-V spec.). > > Regarding AMOs, let me copy from something I wrote in a previous > offline conversation: > > > it seems to us that pairing a store-release of "amoswap.rl" with > > a "ld; fence r,rw" doesn't actually give us the RC semantics we've > > been discussing for LKMM. For example: > > > > (a) sd t0,0(s0) > > (b) amoswap.d.rl x0,t1,0(s1) > > ... > > (c) ld a0,0(s1) > > (d) fence r,rw > > (e) sd t2,0(s2) > > > > There, we won't get (a) ordered before (e) regardless of whether > > (b) is RCpc or RCsc. Do you agree? > > At the moment, only the load part of (b) is in the predecessor > set of (d), but the store part of (b) is not. Likewise, the > .rl annotation applies only to the store part of (b), not the > load part. Indeed. (If you want, this is one reason why, with these patches, ".rl" and "fence r,rw" are never "mixed" as in your snipped above unless there is also a "fence rw,rw" in between.) > > This gets back to a question Linus asked last week about > whether the AMO is a single unit or whether it can be > considered to split into a load and a store part (which still > perform atomically). For RISC-V, for right now at least, the > answer is the latter. Is it still the latter for Linux too? Yes: (successful) atomic RMWs all generate (at least) one load event and one store event in LKMM. (This same approach is taken by other hardware models as well...) > > https://lkml.org/lkml/2018/2/26/606 > > > So I think we'll need to make sure we pair .rl with .aq, or that > > we pair fence-based mappings with fence-based mappings, in order > > to make the acquire/release operations work. > > This assumes we'll say that .aq and .rl are RCsc, not RCpc. > But in this case, I think .aq and .rl could still be safe to use, > as long as you don't ever try to mix in a fence-based mapping > on the same data structure like in the example above. That > might be important if we want to find the most compact legal > implementation, and hence do want to use .aq and .rl after all. > > > And since we don't have native "ld.aq" today in RISC-V, that > > would mean smp_store_release would have to remain implemented > > as "fence rw,w; s{w|d}", rather than "amoswap.{w|d}.rl", for > > example. And these seem to be further valid/strong arguments for these patches ;) (independently of how you'll end up ratifying .aq and .rl). Andrea > > Thoughts? > > Thanks, > Dan > > > > > Thanks!