Received: by 10.213.65.68 with SMTP id h4csp76900imn; Tue, 3 Apr 2018 15:53:52 -0700 (PDT) X-Google-Smtp-Source: AIpwx49xYeAQU+dKD1ebgtUuvAFC64Wb9++s+lAt35yJ2tWhJB9EhruTPG5xF95XWeuWc02ANW/d X-Received: by 2002:a17:902:86:: with SMTP id a6-v6mr16312098pla.298.1522796032768; Tue, 03 Apr 2018 15:53:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522796032; cv=none; d=google.com; s=arc-20160816; b=kwtOcvS6qCDma5R97jTsBGrKb4BQJm/V9nT+02r9659C1Vgl0UIW53fRuHOLzATv5b 1ihPK3wtQn+8qR+M6LUn2nB4Uzbtr2KXIk8vuoqaeu1Dij2mqxE7T1Ztwzqji+ePgS93 zdn8TJ/ZPeL7JlGF70jsg8E46gLjTlMWqKRzpn9HaRV8RwvYdIDMX3+vKEJ6Laqj2hNb M8jJcGHZmn4/ruehNrBRdP4JraCvXzwdddsExx13WTCg3IGtZ+GTWSPPyZSf2aiP8tfk q5KfT8+s2KEXO56MGGcRcubg3oODNCTHtDX/NT5BuEw4n9VZuzJ5zOzy24ZNPnyMP8Pc mNYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:to:from:cc:in-reply-to:subject:date:dkim-signature :arc-authentication-results; bh=7YKsgqxTGbSc9hhWIkUEH3D3MiLY17UZCr2Hs9WF/0k=; b=HEjDTgSYxLEI5EAqD7nHxd2yTFk66uQBrAGGJJlSuEwY0zc029BoRdNeVUPgMZv23s e79l4KW2PEJn2FuC9rQXg4KNBfmjq2K/eCsb0Eh1EhaxpZ0f3IyrmNh3QGFsPpXxaB5K iZevNgmV0tjySasCOFu8ZeweMg4xZtEFJNk5+58spElemuZnsaMXCHnNaHKtrChc5fo/ MVRwDIOeW4p+nBlruXFFXs479Pbk+AQUzaaoNcbDqbig2x3uqEmNzOIZzlmlb2xFbuLH TrSzX1Sx9eWpOIUxlGobqMAZm26BeO9Bu1vh/aIrKBQFxZG1szRDz/H7idtt2K9ErJnQ /bqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=FBIpb5NV; 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 y11si2616105pgp.243.2018.04.03.15.53.26; Tue, 03 Apr 2018 15:53:52 -0700 (PDT) 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=@sifive.com header.s=google header.b=FBIpb5NV; 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 S1756230AbeDCWeD (ORCPT + 99 others); Tue, 3 Apr 2018 18:34:03 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:37182 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756133AbeDCW3m (ORCPT ); Tue, 3 Apr 2018 18:29:42 -0400 Received: by mail-pl0-f67.google.com with SMTP id v5-v6so9096833plo.4 for ; Tue, 03 Apr 2018 15:29:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=date:subject:in-reply-to:cc:from:to:message-id:mime-version :content-transfer-encoding; bh=7YKsgqxTGbSc9hhWIkUEH3D3MiLY17UZCr2Hs9WF/0k=; b=FBIpb5NVk5lxtbk1/DBaJv25IRTGEme78BRO8yoKXZSwUz8XZF//WaTXNa4zQ6zp+/ OGoJfo2bvPm3lxre57OISZh9vRIWW4ZkcWKS18EjfkyGgSMFFInJNw8GorvzLFaX3iRg FNpFa2zOz6RpDo8QTurMzr30GkzPyIIZMHUOi11qMAVlzC3XcyaJ0RFBfA8CbbkzLwYY Wnii+eEeSmt2gtG2if+/QJDVdbq6L2tu5ngQ7U52+yepsnVSXF6eLkiAwNIvI27ocTjE ae+nRWO/rZtznzP6ElHcoBcKv+ojNifZUTMnJD+rtDdbtq69/kv1ZiK9vKcCsHfAX2v4 io6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:subject:in-reply-to:cc:from:to:message-id :mime-version:content-transfer-encoding; bh=7YKsgqxTGbSc9hhWIkUEH3D3MiLY17UZCr2Hs9WF/0k=; b=KJx/9r3rTvmWEtcVnNxfVt0ySJn9k9Ikd7tmiXZNghwiuNnRRcw/nSkZx7t3LrsMHV 0DJtXQ2HV7G45jK/k0mXOg80zqP29DVC6iX+TP1/dVEfZDutIbdTCe3FxjNdlHdp0u74 +467E7f4qifhzZ8X1ftH8VS5Hy3CUmz/8XD34r4Bw6obpoRxQ9l6etQHzhnGf76d+/qd Rlub0OybmmRYxinO8g1ZdcXTWTwuDOfyjT2gUH+xf4hVTRXWVRa4eOu0VwuY3Nod5ckz oDp395J5D74z8f/VGR3NbcUeEGsKZ/Nws7VLy23x+XZCPkFl2hqQsYSUnwkp8mrLUD98 AUnA== X-Gm-Message-State: AElRT7Fg/PNnBTDyhas8KAiUlIP31dwwtn90Cv1bK8Afmsb0tsWwcxsr q3e9uqLusqtv8XUlYqQbw9T5OQ== X-Received: by 2002:a17:902:bb8e:: with SMTP id m14-v6mr15683336pls.286.1522794581648; Tue, 03 Apr 2018 15:29:41 -0700 (PDT) Received: from localhost ([12.206.222.5]) by smtp.gmail.com with ESMTPSA id t25sm7320664pfj.187.2018.04.03.15.29.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Apr 2018 15:29:40 -0700 (PDT) Date: Tue, 03 Apr 2018 15:29:40 -0700 (PDT) X-Google-Original-Date: Tue, 03 Apr 2018 15:29:39 PDT (-0700) Subject: Re: [PATCH v2 2/2] io: prevent compiler reordering on the default readX() implementation In-Reply-To: CC: okaya@codeaurora.org, mark.rutland@arm.com, timur@codeaurora.org, sulrich@codeaurora.org, linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org From: Palmer Dabbelt To: Arnd Bergmann Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 03 Apr 2018 05:56:18 PDT (-0700), Arnd Bergmann wrote: > On Tue, Apr 3, 2018 at 2:44 PM, Sinan Kaya wrote: >> On 4/3/2018 7:13 AM, Arnd Bergmann wrote: >>> On Tue, Apr 3, 2018 at 12:49 PM, Mark Rutland wrote: >>>> Hi, >>>> >>>> On Fri, Mar 30, 2018 at 11:58:13AM -0400, Sinan Kaya wrote: >>>>> The default implementation of mapping readX() to __raw_readX() is wrong. >>>>> readX() has stronger ordering semantics. Compiler is allowed to reorder >>>>> __raw_readX(). >>>> >>>> Could you please specify what the compiler is potentially reordering >>>> __raw_readX() against, and why this would be wrong? >>>> >>>> e.g. do we care about prior normal memory accesses, subsequent normal >>>> memory accesses, and/or other IO accesses? >>>> >>>> I assume that the asm-generic __raw_{read,write}X() implementations are >>>> all ordered w.r.t. each other (at least for a specific device). >>> >>> I think that is correct: the compiler won't reorder those because of the >>> 'volatile' pointer dereference, but it can reorder access to a normal >>> pointer against a __raw_readl()/__raw_writel(), which breaks the scenario >>> of using writel to trigger a DMA, or using a readl to see if a DMA has >>> completed. >> >> Yes, we are worried about memory update vs. IO update ordering here. >> That was the reason why barrier() was introduced in this patch. I'll try to >> clarify that better in the commit text. >> >>> >>> The question is whether we should use a stronger barrier such >>> as rmb() amd wmb() here rather than a simple compiler barrier. >>> >>> I would assume that on complex architectures with write buffers and >>> out-of-order prefetching, those are required, while on architectures >>> without those features, the barriers are cheap. >> >> That's my reasoning too. I'm trying to follow the x86 example here where there >> is a compiler barrier in writeX() and readX() family of functions. > > I think x86 is the special case here because it implicitly guarantees > the strict ordering in the hardware, as long as the compiler gets it > right. For the asm-generic version, it may be better to play safe and > do the safest version, requiring architectures to override that barrier > if they want to be faster. > > We could use the same macros that riscv has, using __io_br(), > __io_ar(), __io_bw() and __io_aw() for before/after read/write. FWIW, when I wrote this I wasn't sure what the RISC-V memory model was going to be so I just picked something generic. In other words, it's already a generic interface, just one that we're the only users of :).