Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3805596imj; Tue, 12 Feb 2019 05:05:54 -0800 (PST) X-Google-Smtp-Source: AHgI3Iav6YlL4iOYG9FFyuq69SyWCFdmtADuzi4TeUmPg4LnhZDchmoSyhlgLad99TQeUquC11nu X-Received: by 2002:a17:902:9683:: with SMTP id n3mr3983083plp.333.1549976754689; Tue, 12 Feb 2019 05:05:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549976754; cv=none; d=google.com; s=arc-20160816; b=e2F4uvDppo3C2w7Qv+7PPF3Gp6Q0j0fqnu8VQ7Q4t3rkH/vCc+Wo40U3weP5wTzQAj mNffnq6VX+gIu1rf8xl3du0rx+7rWL9jPPYvREb7SWM/oXtGhxSAjnTBu5oztWAdQYD2 sCw7M3RT63EMlZNIqZLygx0lJl27GymarI/95uhkDhlhVDglOnIarEvQhsaH1K6gMYmt FRNp28i7lAd9i/wG+9m4KtLNhgHDD3vU0rPaROBnTk2O7azrCEBVnnI1gNxG5Eh4AANM z5YIU21iayCqB/J+yYUsYoyZMvWrwEBYNZnHnahYKjIByHIAjkQAWBo1me/qDm2Eyc7M f1Ug== 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=ux3rfab6xB0htyN4go6KoVC5wYUNHtBdesVWyPhjIbU=; b=cQsgWDV4WmoumHTbszx21drd5TT+EWr5Rov4jkvFoa1fqcSqPiDikzYHgfWve4+Du1 SlqcMHtGOL6n84/p3vAC/v6VUUVcNXKaqGgcRnrJWlHD/eR8cX/b1QMB/yBY6RXrAdvn npuYyR5LlBQxo8qJ5aMAy9qGCWnIkts9ITv/S7sJ8mAbXfgV+uPwU6iUeTANwAa+YWOS reWxJPAU83jxCC6zFZ33xKbKOvK4HZV2QsoYjMtetiih9RHTBN7EzasTpQPITRo26anS /2yrzqpa84X1Zg/nlRnZYiKXdA2Usen48NHzko7+jk5TbmRylyXLqPcYrOYa93DEm1ia j9Cw== 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 j1si12379857pff.42.2019.02.12.05.05.37; Tue, 12 Feb 2019 05:05: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 S1729297AbfBLNDY (ORCPT + 99 others); Tue, 12 Feb 2019 08:03:24 -0500 Received: from mail-qt1-f194.google.com ([209.85.160.194]:46474 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727750AbfBLNDY (ORCPT ); Tue, 12 Feb 2019 08:03:24 -0500 Received: by mail-qt1-f194.google.com with SMTP id y20so2711738qtm.13; Tue, 12 Feb 2019 05:03:23 -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=ux3rfab6xB0htyN4go6KoVC5wYUNHtBdesVWyPhjIbU=; b=QI55gHL0MLykQbbhQ6J3wViG9BRRp6x/9ts1SdyMASjojYXcWcDeA/HoiXP2LBSfeg +rd96wnS7Q05Rdq/d1BtKNFQBRkMAL4RCSAy/+uHhUC98OiH+lNjNgg3uZNVfrZ5Qp3w BzrULhsJdmsv1maHRt06sY5C2+wjr3qlUpQKpAhX+qUfL/UQXqJMLA/+uvcB/YAgBFOI MULzYL5KoDLapuz7u5+AP+6mHJby4sSjEND3zsb1s/3bTSHOJ+p95P6BlUW6rQuzYACP RwQMPOqinAQPJGSK59DWXni13pljN2xXJNjCJNBaXhSEXFn+uhljEpR/AOHB9w1cq8jP eu2w== X-Gm-Message-State: AHQUAuaJsCBicOHx+hmLnaHOaKClCPHfz2OzcEaeEe/bR9EjoX6MTfP0 wJUEMBGvCQ7hJ0BrOoJnhhb92wxrevTLEGcx74Y= X-Received: by 2002:a0c:d791:: with SMTP id z17mr2482788qvi.149.1549976602405; Tue, 12 Feb 2019 05:03:22 -0800 (PST) MIME-Version: 1.0 References: <20190211172948.3322-1-will.deacon@arm.com> In-Reply-To: <20190211172948.3322-1-will.deacon@arm.com> From: Arnd Bergmann Date: Tue, 12 Feb 2019 14:03:04 +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 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. > + 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. > (*) 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. > +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. Arnd