linux-toolchains.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>,
	<linux-toolchains@vger.kernel.org>,
	clang-built-linux <clang-built-linux@googlegroups.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	"Jose E. Marchesi" <jemarch@gnu.org>,
	Kees Cook <keescook@chromium.org>,
	Florian Weimer <fweimer@redhat.com>,
	Christian Brauner <christian.brauner@canonical.com>,
	<nick.alcock@oracle.com>,
	Segher Boessenkool <segher@kernel.crashing.org>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Will Deacon <will@kernel.org>
Subject: Re: Plumbers CF MCs
Date: Tue, 23 Mar 2021 22:23:10 +0000	[thread overview]
Message-ID: <00891d85-ef0f-b8bf-6d0e-47ecd4b650ff@citrix.com> (raw)
In-Reply-To: <20210323195358.GB4746@worktop.programming.kicks-ass.net>

On 23/03/2021 19:53, Peter Zijlstra wrote:
> On Tue, Mar 23, 2021 at 07:29:01PM +0000, Andrew Cooper wrote:
>> For the compiler folk here, the tl;dr is that indirect CALL/JMP (i.e.
>> function pointers, jump tables) and RET instructions may speculatively
>> execute the next sequential instruction(s) before taking the control
>> flow change into account. 
> So JMP and RET can trivially have INT3 following in such a way that that
> instruction is never in the actual execution path. This is obviously not
> possible for CALL.
>
> For CALL we can follow with LFENCE (hurts), or if we can get a limit
> on how many instructions deep the speculation gap is, a bunch of NOPs.
> Or possibly nothing at all.
>
> As such it might make sense to have these two cases separated out.

Agreed.

There is architectural execution following an indirect CALL, so we will
only be speculating what we will execute non-speculatively later.  I
can't see any situation where this would be speculatively dangerous.

For indirect JMP, whether you care about stopping speculation depends on
how likely it is that you'll enter case 0 of a switch statement.  That
said, for profile optimised code, the chances are that the hotpath(s)
are in an if/else chain, so I don't think it is worth attempting to do
anything interesting here.

Both the Intel and AMD documents on the matter say to use LFENCE, but
that is a simplified set of instruction to cover all 3 cases.  Given
that we probably want to split CALL away from JMP/RET, then INT3 is the
shortest speculation block at a single byte, and thus has least .text
size impact.

~Andrew


  parent reply	other threads:[~2021-03-23 22:34 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-22 20:23 Plumbers CF MCs Nick Desaulniers
2021-03-22 20:39 ` Jose E. Marchesi
2021-03-31 19:34   ` Elena Zannoni
2021-03-31 20:36     ` Nick Desaulniers
2021-04-01  7:59       ` Jose E. Marchesi
2021-04-01 20:01         ` Nick Desaulniers
2021-04-01 13:29       ` Steven Rostedt
2021-04-01 13:31         ` Steven Rostedt
2021-04-01 13:49         ` Elena Zannoni
2021-04-01 15:11           ` Miguel Ojeda
2021-04-01 20:11           ` Nick Desaulniers
2021-04-01 13:25     ` Steven Rostedt
2021-04-01 13:25       ` Steven Rostedt
2021-03-23  8:35 ` Peter Zijlstra
2021-03-23  8:45   ` Peter Zijlstra
2021-03-23 19:29   ` Andrew Cooper
2021-03-23 19:53     ` Peter Zijlstra
2021-03-23 22:12       ` Peter Zijlstra
2021-03-24  0:36         ` Steven Rostedt
2021-03-24  8:15           ` Peter Zijlstra
2021-03-23 22:23       ` Andrew Cooper [this message]
2021-03-24  8:08         ` Peter Zijlstra
2021-03-24 11:30           ` Andrew Cooper
2021-04-02 12:40       ` Segher Boessenkool
2021-03-23 22:26     ` Nick Desaulniers
2021-03-24  7:52       ` Peter Zijlstra
2021-03-24  8:47   ` Christian Brauner
2021-03-30 14:13   ` Will Deacon
2021-04-01  7:17     ` Kees Cook
2021-04-02 12:33   ` Segher Boessenkool

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=00891d85-ef0f-b8bf-6d0e-47ecd4b650ff@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=christian.brauner@canonical.com \
    --cc=clang-built-linux@googlegroups.com \
    --cc=fweimer@redhat.com \
    --cc=jemarch@gnu.org \
    --cc=jpoimboe@redhat.com \
    --cc=keescook@chromium.org \
    --cc=linux-toolchains@vger.kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=nick.alcock@oracle.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=segher@kernel.crashing.org \
    --cc=will@kernel.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;
as well as URLs for NNTP newsgroup(s).