Received: by 10.223.185.111 with SMTP id b44csp775674wrg; Fri, 9 Mar 2018 13:31:45 -0800 (PST) X-Google-Smtp-Source: AG47ELt42p74KgwHDaWQun+zkV1b/UvCSUupITFe1mKAhalrXChV7ZslHDihaePBuJBetmuQ/jFB X-Received: by 2002:a17:902:22f:: with SMTP id 44-v6mr708724plc.377.1520631105033; Fri, 09 Mar 2018 13:31:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520631105; cv=none; d=google.com; s=arc-20160816; b=Rf80itxbKrVffgbvc31GR3Ck3DuKzU8wR8k+jVJTWgp74/3s5JEUXIqeQXCighnNbA HBenCahzKW4GRQkBcsyHEQy5ccuQdFeRwR/GeM7Yb4LEM663Jk/QfMliqj2eyGRCO1Ox xRgSP19VKHs8rC472hzPxGVHsyul2ffWqrqRVYQeUjAyPCtU1r7nXwzHswYYjP2Cffyc 4QAchj8dVG/D95hBEXbeVRgM+32PAJpSa0EWcLlnXk/4MkD0Q6AD10jYXnLd+GOsKnAY 4AAA/T2ZJAkkZ47Qc8qKukB1gutEIdHQYYYsQD/QE339DjSYBl4EvvbNt5MB3m73N5yX 0RgA== 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=wxSYBIKQjUrMUDKBZ4pa/5NokiVdMsdAJ61X3tvp3T0=; b=sKJF19wvo1s0U/SE803hSG/kC/fRTi4nxbGveH2EK5Gop9RnxYT+Uz4eEAXfzQdCtW EvbxvNneRYbdaKbtk0/9FopkSwIYLH5Ptk4rzZ8F8rAys2iU4o+OSnCMq+oQnCXWPLh8 sPgK+cH6b/g6pMy/rGWtG60Eq8qMy+CSDwGT4qEIHuhG3pfHQFBJye1x8g2NNljtwtIC CUNCA9roSjehiSO7PjDjPfbJGS0CUmCBP/HhDr+aA9EUNFUbfOvzxnrKelg/CkosnPq+ djv1I/Z27qBXcXjjfncikAJzE1ANtFGchkdlWdc982BxyM1LrBs3dQkP+5xoLhyB32CD Lllw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NxFBTXKL; 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 g2-v6si1529652plo.567.2018.03.09.13.31.30; Fri, 09 Mar 2018 13:31: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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NxFBTXKL; 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 S932535AbeCIVaS (ORCPT + 99 others); Fri, 9 Mar 2018 16:30:18 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:38815 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932133AbeCIVaQ (ORCPT ); Fri, 9 Mar 2018 16:30:16 -0500 Received: by mail-wr0-f196.google.com with SMTP id n7so10291095wrn.5 for ; Fri, 09 Mar 2018 13:30:16 -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=wxSYBIKQjUrMUDKBZ4pa/5NokiVdMsdAJ61X3tvp3T0=; b=NxFBTXKLtxQkIuxz0W2AuIX+jOji1CXosZZZq+rxv29LIM+Ob1FiO61Z/8UHkYAVPk PIAhrE3REIsl3Egf4wA1CoscCW1l6VBc3JDcqnyRzhSA8D6oPAILfoUb3yWUcJyP8wP0 xejztA5WfcasSVYOfCEJBjct+3mSM7SMwNt330xtOjxNXMrI3EoXowGdq/VcZvmtJIoq w1ZThzzOoExT7kvCyZKLjBtqqKM/HVwc+RI0lk/jg4XoYayVUjsptObDGo8AX3mc+KIT jMHU9y9eAgJ38Mfo8bJyyfMC/j2XQHzrs6JVWr2Qff78aRjSGdGARSs7zGNpHVZ9wJsR P6gQ== 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=wxSYBIKQjUrMUDKBZ4pa/5NokiVdMsdAJ61X3tvp3T0=; b=O5AQti3qHTsSjCqdQMDosFoL2Qy5qhdYPWYheOWjbbwn+stW5CrpZrfJ9hBxAI0jaf neNuXQ1evLmRd8Xh5xyVrtiElLRlGgDOkQtzAjmpdE8zLg+r4Uo1+Ozk8MH4/oxXBfXH uTijKdxfcqKthimlmyL+BSPcWNXlRJ6WcQ9JDzNBPlOaxDyVSAwwU7BIHPu4dzpSrpDL gXlAdswCHY65HJHjBZTZ4hbqBvjjyeWQDb8lSKoVvI8qwPY8cjim+iIRP4KWOE9HzwyA KRTHb2+HpDQE1o5WHA1qI/kxM1ReBRa4BjRUvvYqYwyp3dZIiCwsaQWiJVgHbWKpNNeo 7TFQ== X-Gm-Message-State: APf1xPAs4xdzblc8RMaoHXPWyiaLadVizfQbOO/PbXkRs23Sw8a+gPtb eNy4/sIiWFPlrejhuZZOshk= X-Received: by 10.223.196.143 with SMTP id m15mr25900449wrf.207.1520631015454; Fri, 09 Mar 2018 13:30:15 -0800 (PST) Received: from andrea ([94.230.152.15]) by smtp.gmail.com with ESMTPSA id q14sm1687048wre.83.2018.03.09.13.30.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Mar 2018 13:30:15 -0800 (PST) Date: Fri, 9 Mar 2018 22:30:08 +0100 From: Andrea Parri To: Palmer Dabbelt Cc: albert@sifive.com, Daniel Lustig , 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: <20180309213008.GA3154@andrea> References: <20180309183644.GA3092@andrea> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 10:54:27AM -0800, Palmer Dabbelt wrote: > On Fri, 09 Mar 2018 10:36:44 PST (-0800), parri.andrea@gmail.com wrote: [...] > >This belongs to the "few style fixes" (in the specific, 80-chars lines) > >mentioned in the cover letter; I could not resist ;-), but I'll remove > >them in v3 if you like so. > > No problem, just next time it's a bit easier to not mix the really complicated > stuff (memory model changes) with the really simple stuff (whitespace changes). Got it. > >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. Andrea