Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2723556imj; Mon, 18 Feb 2019 10:58:43 -0800 (PST) X-Google-Smtp-Source: AHgI3IYQMjIDz2vGDlwUR+eQJzDCY42t8gymChUxBCw9zKM+Nd+iT/tjyZ+k5OuNBaNMfN41TodF X-Received: by 2002:a17:902:44c:: with SMTP id 70mr25648004ple.318.1550516322947; Mon, 18 Feb 2019 10:58:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550516322; cv=none; d=google.com; s=arc-20160816; b=YV7ScQSs8AmNWDvVVrn4SFy5h5OHG1e0Sbf+JmFNdB8n8sR+j/thW7piYCnsFHKgS0 Ppp7vKRNzxQUASVc91MjMeLAq8Wa5kzdmEh7XivMDEWJPpchyJBmh0YrEKFJ82fRk6GH MSTH/7QLhoGeyVo8bmtqw2bybNEUDdZdPpZft5p0aRff+BUPbAJpob2Ef/Xy/ldecLfh lT/4DrRHO/B8o51QD/Tx/QOIYxn0ZJ+KcWfLGevLqel1nXmW0nMGtfYIW7UXzmx2S3Lq 6SDqGNDTmLeuOEePyp3CPIV4IqlFlY3bwKD93PSK+JEP17y8lntzSGtLLHPa55qGC+PQ PH+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=Cm4QjnGHjUB288xZcWgBrFnOWtMJAEJPD9RVeEyfrVw=; b=VHagdGFcQS+ZVZD8M/7c59u4AGW5R/PIC2olnNeg9LJ9/IZXZL3j6ZDOE1f9o2cBUg 3rUO9yDtz6ro+wV9obp2iMGqh4uUrVwZiX4xf4DGK+zdG3DbEXRubkGgJAJZ4HQVwy9F Fc/LWc3mR4lXqqp4vKgxZgyEDiur7CReQwpt6m/33PPtzCglX2B/sExHJHf/ESENI9g4 8xZkTJTw5TsKf2Mls9SOrScOTLT7Cefw4Qlisf/+/gV5mHbVNgkmjSjOkKVsSxKKFFxb TLLqmNzyf9i8vtMfk4DWb0Wny95bfFYqpAt/32s6cr3A1MbsJZfX2NJdkX+jANKOUMSc 9C4g== 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 j7si14642685plb.349.2019.02.18.10.58.27; Mon, 18 Feb 2019 10:58:42 -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 S2390731AbfBRQ7c (ORCPT + 99 others); Mon, 18 Feb 2019 11:59:32 -0500 Received: from mail-qt1-f194.google.com ([209.85.160.194]:40766 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733067AbfBRQ7b (ORCPT ); Mon, 18 Feb 2019 11:59:31 -0500 Received: by mail-qt1-f194.google.com with SMTP id j36so19914691qta.7; Mon, 18 Feb 2019 08:59:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Cm4QjnGHjUB288xZcWgBrFnOWtMJAEJPD9RVeEyfrVw=; b=rEgbf0bA3ihnaHdffXVQdfXP+bpUAez85ckBhRIKbKGqZ0alhp6V5wEBL3S4kUcaU6 RIfClHm9jZSVsZEYcXJQBoitjr7uGf2JWHfZo5GHu9O0IYVEEhY75DU+0wfg+GmKgwzv 6NDiJm5H1qNtFti9/kyzwS6/MA6nDm8XC1T95qG/cFx5Llhl6IF5vrORxDqftlC11AWU 1thRHkDINwWsBU4kI/zfS8RT5JhM4QS8eUMmbnStwh6xzSBahRrqq/coPrzDD+mBQHnJ CNVxJOvbP3WpX3TvsZ4KCCQIYHzNJD4vHSJSoQXL6uNKEQH3i7eRMC2ENc3XYqPHJrHc iVcA== X-Gm-Message-State: AHQUAuZNsZ+R7b9rFNEmm4g1dB9gbA7MwShz/8OHkPCU6DeuN3Q1X0eL Sd03clybaLQs2b8zh0EtXghnwUp9uMXKlFJuaCQ= X-Received: by 2002:a0c:98c8:: with SMTP id g8mr18450200qvd.161.1550509170391; Mon, 18 Feb 2019 08:59:30 -0800 (PST) MIME-Version: 1.0 References: <20190211172948.3322-1-will.deacon@arm.com> <20190218162954.GB16713@fuggles.cambridge.arm.com> In-Reply-To: <20190218162954.GB16713@fuggles.cambridge.arm.com> From: Arnd Bergmann Date: Mon, 18 Feb 2019 17:59:13 +0100 Message-ID: Subject: Re: [RFC PATCH] docs/memory-barriers.txt: Rewrite "KERNEL I/O BARRIER EFFECTS" section To: Will Deacon Cc: linux-arch , Linux Kernel Mailing List , "Paul E. McKenney" , Benjamin Herrenschmidt , Peter Zijlstra , Andrea Parri , Daniel Lustig , David Howells , Alan Stern , Linus Torvalds Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 18, 2019 at 5:30 PM Will Deacon wrote: > > 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. > ... > > 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. That's fine, my worry is more that you are already saying too much by describing a behavior for ioremap_wc+relaxed+barrier that is neither a good idea or guaranteed to do what you describe. > > > + 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. Ok. > > > (*) 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? I would say we should strengthen the behavior of outX() where possible. I don't know if arm64 actually has a way of doing that, my understanding earlier was that the AXI bus was already posted, so there is not much you can do here to define __io_paw() in a way that will prevent posted writes. > > > +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. Fair enough. Arnd