linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Alexander Duyck <alexander.duyck@gmail.com>,
	Will Deacon <will.deacon@arm.com>,
	Sinan Kaya <okaya@codeaurora.org>, Arnd Bergmann <arnd@arndb.de>,
	Jason Gunthorpe <jgg@ziepe.ca>,
	David Laight <David.Laight@aculab.com>, Oliver <oohall@gmail.com>,
	"open list:LINUX FOR POWERPC (32-BIT AND 64-BIT)"
	<linuxppc-dev@lists.ozlabs.org>,
	"linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>,
	Alexander Duyck <alexander.h.duyck@redhat.com>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: RFC on writel and writel_relaxed
Date: Tue, 27 Mar 2018 16:51:58 -1000	[thread overview]
Message-ID: <CA+55aFyTeuXPmC5-1JGh2ow-rf5wMA6Vcv0aeS_q0_EnptSK9Q@mail.gmail.com> (raw)
In-Reply-To: <1522198981.7364.81.camel@kernel.crashing.org>

On Tue, Mar 27, 2018 at 3:03 PM, Benjamin Herrenschmidt
<benh@kernel.crashing.org> wrote:
>
> The discussion at hand is about
>
>         dma_buffer->foo = 1;                    /* WB */
>         writel(KICK, DMA_KICK_REGISTER);        /* UC */

Yes. That certainly is ordered on x86. In fact, afaik it's ordered
even if that writel() might be of type WC, because that only delays
writes, it doesn't move them earlier.

Whether people *do* that or not, I don't know. But I wouldn't be
surprised if they do.

So if it's a DMA buffer, it's "cached". And even cached accesses are
ordered wrt MMIO.

Basically, to get unordered writes on x86, you need to either use
explicitly nontemporal stores, or have a writecombining region with
back-to-back writes that actually combine.

And nobody really does that nontemporal store thing any more because
the hardware that cared pretty much doesn't exist any more. It was too
much pain. People use DMA and maybe an UC store for starting the DMA
(or possibly a WC buffer that gets multiple  stores in ascending order
as a stream of commands).

Things like UC will force everything to be entirely ordered, but even
without UC, loads won't pass loads, and stores won't pass stores.

> Now it appears that this wasn't fully understood back then, and some
> people are now saying that x86 might not even provide that semantic
> always.

Oh, the above UC case is absoutely guaranteed.

And I think even if it's WC, the write to kick off the DMA is ordered
wrt the cached write.

On x86, I think you need barriers only if you do things like

 - do two non-temporal stores and require them to be ordered: put a
sfence or mfence in between them.

 - do two WC stores, and make sure they do not combine: put a sfence
or mfence between them.

 - do a store, and a subsequent from a different address, and neither
of them is UC: put a mfence between them. But note that this is
literally just "load after store". A "store after load" doesn't need
one.

I think that's pretty much it.

For example, the "lfence" instruction is almost entirely pointless on
x86 - it was designed back in the time when people *thought* they
might re-order loads. But loads don't get re-ordered. At least Intel
seems to document that only non-temporal *stores* can get re-ordered
wrt each other.

End result: lfence is a historical oddity that can now be used to
guarantee that a previous  load has finished, and that in turn meant
that it is  now used in the Spectre mitigations. But it basically has
no real memory ordering meaning since nothing passes an earlier load
anyway, it's more of a pipeline thing.

But in the end, one question is just "how much do drivers actually
_rely_ on the x86 strong ordering?"

We so support "smp_wmb()" even though x86 has strong enough ordering
that just a barrier suffices. Somebody might just say "screw the x86
memory ordering, we're relaxed, and we'll fix up the drivers we care
about".

The only issue really is that 99.9% of all testing gets done on x86
unless you look at specific SoC drivers.

On ARM, for example, there is likely little reason to care about x86
memory ordering, because there is almost zero driver overlap between
x86 and ARM.

*Historically*, the reason for following the x86 IO ordering was
simply that a lot of architectures used the drivers that were
developed on x86. The alpha and powerpc workstations were *designed*
with the x86 IO bus (PCI, then PCIe) and to work with the devices that
came with it.

ARM? PCIe is almost irrelevant. For ARM servers, if they ever take
off, sure. But 99.99% of ARM is about their own SoC's, and so "x86
test coverage" is simply not an issue.

How much of an issue is it for Power? Maybe you decide it's not a big deal.

Then all the above is almost irrelevant.

       Linus

  reply	other threads:[~2018-03-28  2:52 UTC|newest]

Thread overview: 129+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-21  3:07 RFC on writel and writel_relaxed Sinan Kaya
2018-03-21  3:40 ` Oliver
2018-03-21 13:53   ` Sinan Kaya
2018-03-21 13:58     ` Sinan Kaya
2018-03-26 13:43       ` Arnd Bergmann
2018-03-26 16:00         ` Sinan Kaya
2018-03-21 14:35     ` David Laight
2018-03-21 15:04       ` Sinan Kaya
2018-03-22  5:24       ` Oliver
2018-03-22  8:20         ` Gabriel Paubert
2018-03-22  9:25           ` Oliver
2018-03-22 11:25             ` Gabriel Paubert
2018-03-22 10:37         ` David Laight
2018-03-22  4:24     ` Benjamin Herrenschmidt
2018-03-22 10:15       ` Oliver
2018-03-22 13:52         ` Benjamin Herrenschmidt
2018-03-22 17:51           ` Sinan Kaya
2018-03-23  0:16             ` Benjamin Herrenschmidt
2018-03-23 13:42               ` Sinan Kaya
2018-03-24  1:22                 ` Benjamin Herrenschmidt
2018-03-24 15:06                   ` Sinan Kaya
2018-03-26 11:44               ` Will Deacon
2018-03-26 12:11                 ` okaya
2018-03-26 12:42                   ` Sinan Kaya
2018-03-23 16:35           ` Jason Gunthorpe
2018-03-24  1:23             ` Benjamin Herrenschmidt
2018-03-26 11:08               ` David Laight
2018-03-26 16:54                 ` Jason Gunthorpe
2018-03-26 19:44                   ` Arnd Bergmann
2018-03-26 20:25                     ` Jason Gunthorpe
2018-03-26 20:43                       ` Arnd Bergmann
2018-03-26 21:09                         ` Jason Gunthorpe
2018-03-26 21:30                           ` Arnd Bergmann
2018-03-26 21:46                             ` Sinan Kaya
2018-03-26 22:01                               ` Benjamin Herrenschmidt
2018-03-26 22:08                                 ` Sinan Kaya
2018-03-26 22:28                                   ` Benjamin Herrenschmidt
2018-03-26 22:27                                 ` Jason Gunthorpe
2018-03-26 22:36                                   ` Benjamin Herrenschmidt
2018-03-26 22:42                                     ` Benjamin Herrenschmidt
2018-03-26 22:50                                     ` Jason Gunthorpe
2018-03-26 23:59                                       ` Benjamin Herrenschmidt
2018-03-27  1:39                                         ` Jason Gunthorpe
2018-03-27  7:56                                   ` Arnd Bergmann
2018-03-27  8:56                                     ` Benjamin Herrenschmidt
2018-03-27  9:44                                       ` Arnd Bergmann
2018-03-27 10:00                                         ` Will Deacon
2018-03-27 11:23                                         ` Benjamin Herrenschmidt
2018-03-27 12:22                                           ` okaya
2018-03-27 14:12                                             ` Jason Gunthorpe
2018-03-27 21:27                                               ` Benjamin Herrenschmidt
2018-03-27  9:57                                       ` Will Deacon
2018-03-27 10:05                                         ` Arnd Bergmann
2018-03-27 10:09                                           ` Will Deacon
2018-03-27 10:53                                             ` Arnd Bergmann
2018-03-27 11:02                                               ` Will Deacon
2018-03-27 11:05                                                 ` Arnd Bergmann
2018-03-27 11:25                                                 ` Benjamin Herrenschmidt
2018-03-27 13:20                                                 ` David Laight
2018-03-27 13:46                                                 ` Sinan Kaya
2018-03-27 14:36                                                   ` Will Deacon
2018-03-27 21:29                                                     ` Benjamin Herrenschmidt
2018-03-28  8:53                                                       ` Will Deacon
2018-03-28  9:00                                                         ` David Laight
2018-03-28  9:09                                                           ` Will Deacon
2018-03-28  9:56                                                             ` Benjamin Herrenschmidt
2018-03-28  9:50                                                         ` Benjamin Herrenschmidt
2018-03-28  9:55                                                           ` Arnd Bergmann
2018-03-28 10:01                                                             ` Benjamin Herrenschmidt
2018-03-28 10:13                                                               ` Will Deacon
2018-03-28 16:57                                                                 ` Jason Gunthorpe
2018-03-29  9:19                                                                   ` Will Deacon
2018-03-29 14:45                                                                     ` Jason Gunthorpe
2018-03-29 14:58                                                                       ` David Laight
2018-03-29 16:40                                                                         ` Jason Gunthorpe
2018-03-27 21:24                                                   ` Benjamin Herrenschmidt
2018-03-27 11:21                                         ` Benjamin Herrenschmidt
2018-03-27  9:42                                     ` Will Deacon
2018-03-27 11:20                                       ` Benjamin Herrenschmidt
2018-03-27 11:24                                         ` Will Deacon
2018-03-27 14:24                                       ` Jason Gunthorpe
2018-03-27 14:16                                     ` Jason Gunthorpe
2018-03-26 22:00                             ` Benjamin Herrenschmidt
2018-03-27 14:46                               ` Sinan Kaya
2018-03-27 15:01                                 ` Jose Abreu
2018-03-27 15:10                                 ` Will Deacon
2018-03-27 18:54                                   ` Alexander Duyck
2018-03-27 19:54                                     ` Arnd Bergmann
2018-03-27 20:46                                       ` Arnd Bergmann
2018-03-27 21:33                                     ` Benjamin Herrenschmidt
2018-03-28  0:39                                       ` Linus Torvalds
2018-03-28  1:03                                         ` Benjamin Herrenschmidt
2018-03-28  2:51                                           ` Linus Torvalds [this message]
2018-03-28  3:24                                             ` Sinan Kaya
2018-03-28  4:41                                               ` Benjamin Herrenschmidt
2018-03-28  6:14                                               ` Linus Torvalds
2018-03-28 11:41                                                 ` okaya
2018-03-28 15:13                                                   ` Benjamin Herrenschmidt
2018-03-28 15:55                                                     ` David Miller
2018-03-28 16:23                                                       ` Nicholas Piggin
2018-03-28 21:31                                                         ` Benjamin Herrenschmidt
2018-03-28 22:09                                                           ` Nicholas Piggin
2018-03-29  9:20                                                           ` Will Deacon
2018-03-29 13:56                                                       ` Sinan Kaya
2018-03-29 14:04                                                         ` David Miller
2018-03-29 16:29                                                         ` Arnd Bergmann
2018-03-29 16:59                                                           ` Sinan Kaya
2018-03-30  1:40                                                         ` Benjamin Herrenschmidt
2018-04-02 13:01                                                           ` Sinan Kaya
2018-03-28  4:33                                             ` Benjamin Herrenschmidt
2018-03-28  6:26                                               ` Linus Torvalds
2018-03-28  6:42                                                 ` Benjamin Herrenschmidt
2018-03-28  6:53                                                   ` Linus Torvalds
2018-03-28  6:56                                                     ` Benjamin Herrenschmidt
2018-03-28  7:11                                                       ` Arnd Bergmann
2018-03-28  7:42                                                         ` Benjamin Herrenschmidt
2018-03-28  9:07                                                   ` Will Deacon
2018-03-28  9:56                                                     ` Benjamin Herrenschmidt
2018-03-28 10:13                                                       ` Aw: " Lino Sanfilippo
2018-03-28 10:20                                                         ` Benjamin Herrenschmidt
2018-03-28 11:30                                                       ` David Laight
2018-03-28 15:12                                                         ` Benjamin Herrenschmidt
2018-03-28 16:16                                                           ` David Laight
2018-03-28  1:21                                   ` Benjamin Herrenschmidt
2018-03-27 21:35                                 ` Benjamin Herrenschmidt
2018-03-26 21:26                   ` Benjamin Herrenschmidt
  -- strict thread matches above, loose matches on Subject: below --
2018-03-27 21:54 Alexander Duyck
2018-03-27 22:35 ` Sinan Kaya
2018-03-27 23:43 ` Benjamin Herrenschmidt

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=CA+55aFyTeuXPmC5-1JGh2ow-rf5wMA6Vcv0aeS_q0_EnptSK9Q@mail.gmail.com \
    --to=torvalds@linux-foundation.org \
    --cc=David.Laight@aculab.com \
    --cc=alexander.duyck@gmail.com \
    --cc=alexander.h.duyck@redhat.com \
    --cc=arnd@arndb.de \
    --cc=benh@kernel.crashing.org \
    --cc=jgg@ziepe.ca \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=netdev@vger.kernel.org \
    --cc=okaya@codeaurora.org \
    --cc=oohall@gmail.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=will.deacon@arm.com \
    /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;
as well as URLs for NNTP newsgroup(s).