public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
From: Will Deacon <will.deacon@arm.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: linux-arch <linux-arch@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	"Paul E. McKenney" <paulmck@linux.ibm.com>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Andrea Parri <andrea.parri@amarulasolutions.com>,
	Daniel Lustig <dlustig@nvidia.com>,
	David Howells <dhowells@redhat.com>,
	Alan Stern <stern@rowland.harvard.edu>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [RFC PATCH] docs/memory-barriers.txt: Rewrite "KERNEL I/O BARRIER EFFECTS" section
Date: Mon, 18 Feb 2019 17:56:25 +0000	[thread overview]
Message-ID: <20190218175625.GD16713@fuggles.cambridge.arm.com> (raw)
In-Reply-To: <CAK8P3a1TY9S=zYsdZ5O021p2yYcZhehVuwB3_65dR6x6zbkTYQ@mail.gmail.com>

On Mon, Feb 18, 2019 at 05:59:13PM +0100, Arnd Bergmann wrote:
> On Mon, Feb 18, 2019 at 5:30 PM Will Deacon <will.deacon@arm.com> 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 <will.deacon@arm.com> 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.

I could drop the mention of relaxed accessors here for now, if you like?
For example:

  "__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."

which we could flesh out if/when we have a notion of the portable semantics.

> > > >   (*) 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.

If we could map I/O space using different page table attributes (probably by
hacking pci_remap_iospace() ?) then we could disable the
early-write-acknowledge hint and implement __io_paw() as a completion
barrier, although it would be at the mercy of the system as to whether or
not that requires a response from the RC.

I would still prefer to document the weaker semantics as the portable
interface, unless there are portable drivers relying on this today (which
would imply that it's widely supported by other architectures).

Will

  parent reply	other threads:[~2019-02-18 17:56 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-11 17:29 [RFC PATCH] docs/memory-barriers.txt: Rewrite "KERNEL I/O BARRIER EFFECTS" section Will Deacon
2019-02-11 17:29 ` Will Deacon
2019-02-11 20:22 ` Paul E. McKenney
2019-02-11 20:22   ` Paul E. McKenney
2019-02-12 18:43   ` Will Deacon
2019-02-12 18:43     ` Will Deacon
2019-02-12 19:24     ` Paul E. McKenney
2019-02-12 19:24       ` Paul E. McKenney
2019-02-11 22:34 ` Linus Torvalds
2019-02-11 22:34   ` Linus Torvalds
2019-02-12  4:01   ` Benjamin Herrenschmidt
2019-02-12  4:01     ` Benjamin Herrenschmidt
2019-02-13 17:20   ` Will Deacon
2019-02-13 17:20     ` Will Deacon
2019-02-13 18:27     ` Linus Torvalds
2019-02-13 18:27       ` Linus Torvalds
2019-02-13 18:33       ` Peter Zijlstra
2019-02-13 18:33         ` Peter Zijlstra
2019-02-13 18:43         ` Luck, Tony
2019-02-13 18:43           ` Luck, Tony
2019-02-13 19:31           ` Paul E. McKenney
2019-02-13 19:31             ` Paul E. McKenney
2019-02-18 16:50       ` Will Deacon
2019-02-18 16:50         ` Will Deacon
2019-02-19 16:13         ` Will Deacon
2019-02-19 16:13           ` Will Deacon
2019-02-21  6:22           ` Michael Ellerman
2019-02-21  6:22             ` Michael Ellerman
2019-02-22 17:38             ` Will Deacon
2019-02-22 17:38               ` Will Deacon
2019-02-12 13:03 ` Arnd Bergmann
2019-02-12 13:03   ` Arnd Bergmann
2019-02-18 16:29   ` Will Deacon
2019-02-18 16:29     ` Will Deacon
2019-02-18 16:59     ` Arnd Bergmann
2019-02-18 16:59       ` Arnd Bergmann
2019-02-18 17:56       ` Will Deacon [this message]
2019-02-18 17:56         ` Will Deacon
2019-02-18 20:37         ` Arnd Bergmann
2019-02-18 20:37           ` Arnd Bergmann
2019-02-19 10:27           ` Thomas Petazzoni
2019-02-19 10:27             ` Thomas Petazzoni
2019-02-19 11:31             ` Arnd Bergmann
2019-02-19 11:31               ` Arnd Bergmann
2019-02-19 11:36               ` Will Deacon
2019-02-19 11:36                 ` Will Deacon
2019-02-19 13:01                 ` Arnd Bergmann
2019-02-19 13:01                   ` Arnd Bergmann
2019-02-19 13:20                   ` Will Deacon
2019-02-19 13:20                     ` Will Deacon
2019-02-19 13:45                     ` Arnd Bergmann
2019-02-19 13:45                       ` Arnd Bergmann
2019-02-19 11:34             ` Will Deacon
2019-02-19 11:34               ` Will Deacon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190218175625.GD16713@fuggles.cambridge.arm.com \
    --to=will.deacon@arm.com \
    --cc=andrea.parri@amarulasolutions.com \
    --cc=arnd@arndb.de \
    --cc=benh@kernel.crashing.org \
    --cc=dhowells@redhat.com \
    --cc=dlustig@nvidia.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@linux.ibm.com \
    --cc=peterz@infradead.org \
    --cc=stern@rowland.harvard.edu \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox