Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2719111imj; Mon, 18 Feb 2019 10:52:55 -0800 (PST) X-Google-Smtp-Source: AHgI3Iaz8raVcGBOH6l3HAjVNcJhSdzlHy7ePabqwke0fQT3TunXZeQ2kmNCYAdnSNsTnwo/rKIM X-Received: by 2002:aa7:82ca:: with SMTP id f10mr25257480pfn.131.1550515974944; Mon, 18 Feb 2019 10:52:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550515974; cv=none; d=google.com; s=arc-20160816; b=Ed7u9z+s68p4gSD5GcFtNdtJkaOrjAgDNEMhuOwCr6SsTxUlSm2O4Hc1p+axNM6y79 IFcV31yYXM5S4yX79Iga260WrxRG58RTYVIkZT7OpDFC0YIss3wPgq20aIYxzJIhVl6y aoC+h1IfOaaOIyERpmqSRZFQA+BjHKA6iQP2flvC4qoGdqJrMBQjDce6ECW9XhfA8sJd F7N3FJDBWXnZAzs+O4h2ItnR/g0pBqtxbLf07ajm8nsLUWGOq6m4ysknZhjASzPKsEYA hrTskANOSDh6JR7aQ82Qiiq4gNbo2u7sGM7wSPM2Lc+WoaF03pl+RCb4pM7atV2pzMSa 0kfA== 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; bh=zaTPPBjOV9khlXaEu5Y2XQInYFibk6OFBd/HRxxNM7c=; b=Vk6DfV9FCF+U+lQKZH1n3V36xR+HNke6UnTJVGbrBB4+tvbtcnhZqu2xJQaWMbzxyp mgz0BTNYlbCkmhVnDQylmpwvBzpedoULhzpJqe5eT0Y/s1gaRM4KuFXCeXi4nqjOxWIw lAcv7RuYXfWRm303GysxFLNUE+xoDkpqc47dzl3j3sEISRchVQTAp4LLmAwAfY/qEn41 1vOrYcoMaFLqktepj1jO1ktHB4RiUCsEru/Y/rN6idz4lU+yau3OKc6aSGczaEKkTL3R 8KfoJEqJzQnCsMXmQaHFMPzalhCD0fSMUnrYKNlQ/zgwdHGifeUZLXAUB53jz+kGqgtV BV7Q== 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 h8si5969568pls.365.2019.02.18.10.52.39; Mon, 18 Feb 2019 10:52:54 -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 S1732138AbfBRQaF (ORCPT + 99 others); Mon, 18 Feb 2019 11:30:05 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:33896 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730711AbfBRQaF (ORCPT ); Mon, 18 Feb 2019 11:30:05 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 76E2180D; Mon, 18 Feb 2019 08:30:03 -0800 (PST) Received: from fuggles.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 824583F675; Mon, 18 Feb 2019 08:29:56 -0800 (PST) Date: Mon, 18 Feb 2019 16:29:54 +0000 From: Will Deacon To: Arnd Bergmann Cc: linux-arch , Linux Kernel Mailing List , "Paul E. McKenney" , Benjamin Herrenschmidt , Peter Zijlstra , Andrea Parri , Daniel Lustig , David Howells , Alan Stern , Linus Torvalds Subject: Re: [RFC PATCH] docs/memory-barriers.txt: Rewrite "KERNEL I/O BARRIER EFFECTS" section Message-ID: <20190218162954.GB16713@fuggles.cambridge.arm.com> References: <20190211172948.3322-1-will.deacon@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.1+86 (6f28e57d73f2) () Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Arnd, On Tue, Feb 12, 2019 at 02:03:04PM +0100, Arnd Bergmann wrote: > On Mon, Feb 11, 2019 at 6:29 PM Will Deacon wrote: > > > + __iomem pointers obtained with non-default attributes (e.g. those returned > > + by ioremap_wc()) are unlikely to provide many of these guarantees. If > > + ordering is required for such mappings, then the mandatory barriers should > > + be used in conjunction with the _relaxed() accessors defined below. > > I wonder if we are even able to guarantee consistent behavior across > architectures > in the last case here (wc mapping with relaxed accessors and barriers). > > Fortunately, there are only five implementations that actually differ from > ioremap_nocache(): arm32, arm64, ppc32, ppc64 and x86 (both 32/64), so > that is something we can probably figure out between the people on Cc. I'd be keen to try to document this as a follow-up patch, otherwise there's the risk of biting off more than I can chew, which is easily done with this stuff! For arm32 (v7) and arm64, ioremap_wc() returns "normal, non-cacheable memory". Some notable differences between this and the memory type returned by ioremap() are: * ioremap_wc() allows speculative reads * ioremap_wc() allows unaligned access * ioremap_wc() allows reordering of accesses to different addresses * ioremap_wc() allows merging of accesses so for us, you really only want to use it to map things that look an awful lot like memory. > The problem with recommending *_relaxed() + barrier() is that it ends > up being more expensive than the non-relaxed accessors whenever > _relaxed() implies the barrier already (true on most architectures other > than arm). > > ioremap_wc() in turn is used almost exclusively to map RAM behind > a bus, (typically for frame buffers) and we may be better off not > assuming any particular MMIO barrier semantics for it at all, but possibly > audit the few uses that are not frame buffers. Right, my expectation is actually that you very rarely need ordering guarantees for wc mappings, and so saying "relaxed + mandatory barriers" is the best thing to say for portable driver code. I'm deliberately /not/ trying to enumerate arch or device-specific behaviours. > > + Since many CPU architectures ultimately access these peripherals via an > > + internal virtual memory mapping, the portable ordering guarantees provided > > + by inX() and outX() are the same as those provided by readX() and writeX() > > + respectively when accessing a mapping with the default I/O attributes. > > This is notably weaker than the PCI mandated non-posted write semantics. > As I said earlier, not all architectures or PCI host implementations can provide > non-posted writes though, but maybe we can document that fact here, e.g. > > | Device drivers may expect outX() to be a non-posted write, i.e. waiting for > | a completion response from the I/O device, which may not be possible > | on a particular hardware. I can add something along these lines, since this seems like it could be a bit of a "gotcha" given the macro names and implicit x86 heritage. > > (*) ioreadX(), iowriteX() > > > > These will perform appropriately for the type of access they're actually > > doing, be it inX()/outX() or readX()/writeX(). > > This probably needs clarification as well then: On architectures that > have a stronger barrier after outX() than writeX() but that use memory > mapped access for both, the statement is currently not true. We could > either strengthen the requirement by requiring CONFIG_GENERIC_IOMAP > on such architectures, or we could document the current behavior > as intentional and explicitly not allow iowriteX() on I/O ports to be posted. At least on arm and arm64, the heavy barrier in outX() is *before* the I/O access, and so it does nothing to prevent the access from being posted. It looks like the asm-generic/io.h behaviour is the same in the case that none of the __io_* barriers are provided by the architecture. Do you think this is something we actually need to strengthen, or are drivers that rely on this going to be x86-specific anyway? > > +All of these accessors assume that the underlying peripheral is little-endian, > > +and will therefore perform byte-swapping operations on big-endian architectures. > > This sounds like a useful addition and the only sane way to do it IMHO, but > I think at least traditionally we've had architectures that do not work like > this but that make readX()/writeX() do native big-endian loads and stores, with > a hardware byteswap on the PCI bus. Sure, hence my disclaimer at the beginning about non-portable drivers :) My goal here is really to document the portable semantics for the common architectures, so that driver developers and reviewers can get the usual case right. Will