linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: "Michal Suchánek" <msuchanek@suse.de>
Cc: "Nicholas Piggin" <npiggin@gmail.com>,
	"Kate Stewart" <kstewart@linuxfoundation.org>,
	"Madhavan Srinivasan" <maddy@linux.vnet.ibm.com>,
	"Mahesh Salgaonkar" <mahesh@linux.vnet.ibm.com>,
	"Al Viro" <viro@zeniv.linux.org.uk>,
	"Paul Mackerras" <paulus@samba.org>,
	"Michael Neuling" <mikey@neuling.org>,
	"Bryant G. Ly" <bryantly@linux.vnet.ibm.com>,
	"Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>,
	"Daniel Axtens" <dja@axtens.net>,
	"Cédric Le Goater" <clg@kaod.org>,
	"David Gibson" <david@gibson.dropbear.id.au>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	"Sergey Senozhatsky" <sergey.senozhatsky@gmail.com>,
	"Masami Hiramatsu" <mhiramat@kernel.org>,
	"Andrew Donnellan" <andrew.donnellan@au1.ibm.com>,
	"Philippe Ombredanne" <pombredanne@nexb.com>,
	"Joe Perches" <joe@perches.com>,
	"Oliver O'Halloran" <oohall@gmail.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	ppc-dev <linuxppc-dev@lists.ozlabs.org>,
	"Tobin C. Harding" <me@tobin.cc>
Subject: Re: [PATCH RFC rebase 3/9] powerpc/64: Use barrier_nospec in syscall entry
Date: Fri, 16 Mar 2018 10:08:37 -0700	[thread overview]
Message-ID: <CA+55aFxYOrn0XRPF8EXvizqAf3GOGmUxu-aKrqvtOsbgxwP2tg@mail.gmail.com> (raw)
In-Reply-To: <20180316101549.31238bdf@naga.suse.cz>

On Fri, Mar 16, 2018 at 2:15 AM, Michal Suchánek <msuchanek@suse.de> wrote:
>
> As far as I understand barriers they separate code before the barrier
> and code after the barrier.

Almost certainly not. Even if you were to do an expensive
serialization before the branch, the branch will still predict after
the serialization.

The thing is, it doesn't make sense to insert a barrier before a
conditional branch for Spectre mitigation.

The problem is not that the data isn't ready for the branch - the
problem is that the branch is predicted _regardless_ of the data.

Sure, some micro-architecture might not predict branches at all if
they have a stable conditional, so a barrier _can_ make sense.

But fundamentally, good branch prediction - in order to be optimal -
has to happen before instructions have even been parsed, much less
things like "stable conditional register state" having been decided
on. You'll want to do I$ prefetching etc.

So the problem is that even if the data is ready, the branch will be
predicted according to some unrelated historical data, and a barrier
to make the branch conditional be stable is pointless.

A barrier *after* the branch, making sure that you don't actually
start executing instructions past it (even if you might have predicted
and fetched stuff past it) *if* you have mis-predicted the previous
branch, is what a sane architecture would specify.

Of course, on x86, we mostly tried to avoid branch prediction being
the critical problem and having to have barriers by just making it an
address generation dependency instead. That should presumably work on
powerpc too, since address generation is part of the memory ordering
definition. But obviously a microarchitecture *could* end up
speculating and just redoing even for memory ordering, and maybe the
ppc architects prefer the barrier since they are already used to crazy
and not very well architected barriers elsewhere.

              Linus

  parent reply	other threads:[~2018-03-16 17:08 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-13 18:32 [PATCH RFC 0/8] powerpc barrier_nospec Michal Suchanek
2018-03-13 18:32 ` [PATCH RFC 1/8] powerpc: Add barrier_nospec Michal Suchanek
2018-03-13 20:01   ` Peter Zijlstra
2018-03-15 19:15     ` [PATCH RFC rebase 0/9] powerpc barrier_nospec Michal Suchanek
2018-03-15 19:15       ` [PATCH RFC rebase 1/9] powerpc: Add barrier_nospec Michal Suchanek
2018-03-15 19:15       ` [PATCH RFC rebase 2/9] powerpc: Use barrier_nospec in copy_from_user Michal Suchanek
2018-03-15 21:37         ` Linus Torvalds
2018-03-16 13:22           ` Michael Ellerman
2018-03-15 19:15       ` [PATCH RFC rebase 3/9] powerpc/64: Use barrier_nospec in syscall entry Michal Suchanek
2018-03-16  5:18         ` Nicholas Piggin
2018-03-16  9:15           ` Michal Suchánek
2018-03-16 10:46             ` Nicholas Piggin
2018-03-16 13:28             ` Michael Ellerman
2018-03-16 17:08             ` Linus Torvalds [this message]
2018-03-15 19:15       ` [PATCH RFC rebase 4/9] powerpc/64s: Use barrier_nospec in RFI_FLUSH_SLOT Michal Suchanek
2018-03-15 19:15       ` [PATCH RFC rebase 5/9] powerpc/64s: Add support for ori barrier_nospec patching Michal Suchanek
2018-03-15 19:15       ` [PATCH RFC rebase 6/9] powerpc/64: Patch barrier_nospec in modules Michal Suchanek
2018-03-15 19:15       ` [PATCH RFC rebase 7/9] powerpc/64: barrier_nospec: Add debugfs trigger Michal Suchanek
2018-03-15 19:15       ` [PATCH RFC rebase 8/9] powerpc/64s: barrier_nospec: Add hcall triggerr Michal Suchanek
2018-03-15 19:15       ` [PATCH RFC rebase 9/9] powerpc/64: barrier_nospec: Add commandline trigger Michal Suchanek
2018-03-23 15:59         ` Diana Madalina Craciun
2018-03-16  8:08       ` [PATCH RFC rebase 0/9] powerpc barrier_nospec Greg Kroah-Hartman
2018-03-16  9:31         ` Michal Suchánek
2018-03-13 18:33 ` [PATCH RFC 2/8] powerpc: Use barrier_nospec in copy_from_user Michal Suchanek
2018-03-13 18:33 ` [PATCH RFC 3/8] powerpc/64: Use barrier_nospec in syscall entry Michal Suchanek
2018-03-13 18:33 ` [PATCH RFC 4/8] powerpc/64s: Add support for ori barrier_nospec Michal Suchanek
2018-03-13 18:33 ` [PATCH RFC 5/8] powerpc/64: Patch barrier_nospec in modules Michal Suchanek
2018-03-13 18:33 ` [PATCH RFC 6/8] powerpc/64: barrier_nospec: Add debugfs trigger Michal Suchanek
2018-03-13 18:33 ` [PATCH RFC 7/8] powerpc/64s: barrier_nospec: Add hcall triggerr Michal Suchanek
2018-03-13 18:33 ` [PATCH RFC 8/8] powerpc/64: barrier_nospec: Add commandline trigger Michal Suchanek

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+55aFxYOrn0XRPF8EXvizqAf3GOGmUxu-aKrqvtOsbgxwP2tg@mail.gmail.com \
    --to=torvalds@linux-foundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=andrew.donnellan@au1.ibm.com \
    --cc=bryantly@linux.vnet.ibm.com \
    --cc=clg@kaod.org \
    --cc=david@gibson.dropbear.id.au \
    --cc=dja@axtens.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=joe@perches.com \
    --cc=kstewart@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.vnet.ibm.com \
    --cc=mahesh@linux.vnet.ibm.com \
    --cc=me@tobin.cc \
    --cc=mhiramat@kernel.org \
    --cc=mikey@neuling.org \
    --cc=msuchanek@suse.de \
    --cc=naveen.n.rao@linux.vnet.ibm.com \
    --cc=npiggin@gmail.com \
    --cc=oohall@gmail.com \
    --cc=paulus@samba.org \
    --cc=pombredanne@nexb.com \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=viro@zeniv.linux.org.uk \
    /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).