linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrea Arcangeli <aarcange@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	"Woodhouse, David" <dwmw@amazon.co.uk>,
	"pavel@ucw.cz" <pavel@ucw.cz>,
	"tim.c.chen@linux.intel.com" <tim.c.chen@linux.intel.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"torvalds@linux-foundation.org" <torvalds@linux-foundation.org>,
	"tglx@linutronix.de" <tglx@linutronix.de>,
	"andi@firstfloor.org" <andi@firstfloor.org>,
	"gnomes@lxorguk.ukuu.org.uk" <gnomes@lxorguk.ukuu.org.uk>,
	"dave.hansen@intel.com" <dave.hansen@intel.com>,
	"gregkh@linux-foundation.org" <gregkh@linux-foundation.org>
Subject: Re: Avoid speculative indirect calls in kernel
Date: Thu, 4 Jan 2018 17:25:41 +0100	[thread overview]
Message-ID: <20180104162541.GD13348@redhat.com> (raw)
In-Reply-To: <ad2e4bc5-26cb-c225-e869-0621fd0c9a7c@redhat.com>

Hello,

On Thu, Jan 04, 2018 at 04:32:01PM +0100, Paolo Bonzini wrote:
> On 04/01/2018 15:51, Andrew Cooper wrote:
> > Where have you got this idea from?  Using IBPB on every mode switch
> > would be an insane overhead to take, and isn't necessary.

It's only on kernel entry and vmexit.

> IIRC it started as a paranoia mode for AMD, but then we found out it was
> actually faster than IBRS on some Intel processor where IBRS performance
> was horrible.  But I don't remember the details of the performance
> testing, sorry.

Yes, it depends on the workload what is faster. ibrs 0 ibpb 2 is
possible to use on CPUs with SPEC_CTRL too in fact.

It's only where SPEC_CTRL is missing and only IBPB_SUPPORT is
available, that ibrs 0 ibpb 2 is the only option to fix variant#2 for
good.

If you run lots of syscalls ibrs 1 ibpb 1 is much faster. If you do
infrequent syscalls computing a lot in kernel like I/O with large
buffers getting copied, ibrs 0 ibpb 2 is much faster than ibrs 1 ibpb
1 (on those microcodes where ibrs 1 reduces performance a lot, not all
microcodes implementing SPEC_CTRL are inefficient like that).

If SPEC_CTRL is available ibrs 1 ibpb 1 should be preferred even if it
may not always be faster in every workload.

AMD website says
https://www.amd.com/en/corporate/speculative-execution

"Differences in AMD architecture mean there is a near zero risk of
exploitation of this variant."

ibrs 0 ibpb 2 brings the probability down to zero even when SPEC_CTRL
is missing and only IBPB_SUPPORT is available in microcode, if you
need that kind of piece of mind.

What exactly would be the point of shipping fixes for variant#2 if we
leave spectre variant#2 unfixed also in cases where we could have
fixed it?

The problem is, it's very unlikely, but if by accident somebody can
mount and setup such an attack, then spectre variant#2 becomes a
problem almost as bad as spectre variant#1 is and your hypervisor
guest/host isolation is fully compromised.

It's not up to us to decide if to leave something with "near zero
risk" unfixed by default, so for now we provided a fix that brings the
probability of such spectre variant#2 attack to zero whenever
possible so that such a spectre varaint#2 attack becomes impossible
(not just "near zero risk"").

Of course we made sure the performance comes back at runtime no matter
what after running this:

    echo 0 >/sys/kernel/debug/x86/ibpb_enabled
    echo 0 >/sys/kernel/debug/x86/ibrs_enabled

Or if you prefer at boot time with "noibrs noibpb". Not everyone
will necessarily care about that kind of variant#2 attacks of course.

NOTE: if those two tunables both read as 0 it means the fix for
variant#2 isn't activated by the running kernel and you need to
contact your CPU manufacturer for a microcode update providing
SPEC_CTRL or at least IBPB_SUPPORT (in the latter case the fix will
generally tend to perform worse and ibrs 0 ibpb 2 mode will
auto-engage).

For meltdown variant#3 same thing: if you want to disable the fix at
runtime because it's a guest kernel and it's running a single
microservice with a single app (similar to unikernel) or something
like that, you can with "nopti" or:

    echo 0 >/sys/kernel/debug/x86/pti_enabled

Same issue if it's a bare metal host and it's running a single app and
it doesn't store secure data in kernel space etc... There's always an
option to disable the fixes.

Only spectre variant#1 fix is always on, as there's no performance
overhead to it.

By default it boots in the most secure setting possible so that all
spectre variant#1 and variant2 and meltdown variant#3 are fixed.

Thanks,
Andrea

  reply	other threads:[~2018-01-04 16:25 UTC|newest]

Thread overview: 107+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-03 23:09 Avoid speculative indirect calls in kernel Andi Kleen
2018-01-03 23:09 ` [PATCH 01/11] x86/retpoline: Define retpoline indirect thunk and macros Andi Kleen
2018-01-03 23:09 ` [PATCH 02/11] x86/retpoline/crypto: Convert crypto assembler indirect jumps Andi Kleen
2018-01-03 23:09 ` [PATCH 03/11] x86/retpoline/entry: Convert entry " Andi Kleen
2018-01-03 23:09 ` [PATCH 04/11] x86/retpoline/ftrace: Convert ftrace " Andi Kleen
2018-01-03 23:09 ` [PATCH 05/11] x86/retpoline/hyperv: Convert " Andi Kleen
2018-01-03 23:09 ` [PATCH 06/11] x86/retpoline/crypto: Convert xen " Andi Kleen
2018-01-03 23:09 ` [PATCH 07/11] x86/retpoline/checksum32: Convert " Andi Kleen
2018-01-03 23:09 ` [PATCH 08/11] x86/retpoline/irq32: " Andi Kleen
2018-01-03 23:09 ` [PATCH 09/11] x86/retpoline: Finally enable retpoline for C code Andi Kleen
2018-01-04  8:28   ` Greg KH
2018-01-04  8:30     ` Dave Hansen
2018-01-03 23:09 ` [PATCH 10/11] retpoline/taint: Taint kernel for missing retpoline in compiler Andi Kleen
2018-01-04  0:29   ` Thomas Gleixner
2018-01-04  0:35     ` Randy Dunlap
2018-01-03 23:09 ` [PATCH 11/11] retpoline/objtool: Disable some objtool warnings Andi Kleen
2018-01-03 23:51 ` Avoid speculative indirect calls in kernel Linus Torvalds
2018-01-04  0:00   ` Alan Cox
2018-01-04  0:09   ` Andi Kleen
2018-01-04  0:12     ` Thomas Gleixner
2018-01-04  0:15       ` Andi Kleen
2018-01-04  0:19         ` Jiri Kosina
2018-01-05  2:01           ` james harvey
2018-01-05 10:40             ` Woodhouse, David
2018-01-05 12:29               ` james harvey
2018-01-05 12:06             ` Alan Cox
2018-01-04  0:29         ` Alan Cox
2018-01-04  0:31           ` Thomas Gleixner
2018-01-04  0:38             ` Alan Cox
2018-01-04  0:40             ` Andi Kleen
2018-01-04  8:15               ` Woodhouse, David
2018-01-04 15:53                 ` Andi Kleen
2018-01-04 15:55                   ` Woodhouse, David
2018-01-04  0:20       ` Linus Torvalds
2018-01-04  0:26         ` Thomas Gleixner
2018-01-04  0:18     ` David Lang
2018-01-04  1:00   ` Paul Turner
2018-01-04  1:41   ` Paolo Bonzini
2018-01-04  1:59     ` Alan Cox
2018-01-04  2:11       ` Paolo Bonzini
2018-01-04  8:20         ` Woodhouse, David
2018-01-04 11:42           ` Pavel Machek
2018-01-04 11:47             ` Woodhouse, David
2018-01-04 14:20               ` Paolo Bonzini
2018-01-04 14:51                 ` Andrew Cooper
2018-01-04 15:29                   ` Woodhouse, David
2018-01-04 15:32                     ` Paolo Bonzini
2018-01-04 15:37                       ` Andrew Cooper
2018-01-04 16:15                     ` David Woodhouse
2018-01-04 20:00                       ` Tom Lendacky
2018-01-04 20:05                         ` David Woodhouse
2018-01-04 23:47                           ` Tom Lendacky
2018-01-05  0:06                             ` Andrew Cooper
2018-01-05  0:26                             ` Tom Lendacky
2018-01-04 16:52                     ` Andrea Arcangeli
2018-01-04 15:32                   ` Paolo Bonzini
2018-01-04 16:25                     ` Andrea Arcangeli [this message]
2018-01-04 17:04                       ` Alan Cox
2018-01-04 17:40                         ` Andrea Arcangeli
2018-01-04 17:13                       ` Dave Hansen
2018-01-04 17:15                         ` Paolo Bonzini
2018-01-04 18:05                           ` Andrea Arcangeli
2018-01-04 14:55                 ` Woodhouse, David
2018-01-04 18:24                 ` Pavel Machek
2018-01-04 19:57           ` Jon Masters
2018-01-05  0:41             ` Jon Masters
2018-01-05  0:54               ` Thomas Gleixner
2018-01-05  4:11                 ` Jon Masters
2018-01-05  9:59                   ` Thomas Gleixner
2018-01-08 10:28                     ` Andrea Arcangeli
2018-01-08 20:42                       ` [tip:x86/pti] x86/tboot: Unbreak tboot with PTI enabled tip-bot for Dave Hansen
2018-01-08 20:53                       ` Avoid speculative indirect calls in kernel Thomas Gleixner
2018-01-08 21:32                         ` Andrea Arcangeli
2018-01-10  0:45                           ` Thomas Gleixner
2018-01-10  1:11                             ` Dave Hansen
2018-01-10 16:02                               ` Thomas Gleixner
2018-01-05  6:49                 ` Willy Tarreau
2018-01-05  6:57                   ` Dave Hansen
2018-01-05  7:13                     ` Willy Tarreau
2018-01-07 14:14                       ` Borislav Petkov
2018-01-07 17:21                         ` David Lang
2018-01-07 18:49                           ` Borislav Petkov
2018-01-07 17:44                         ` Willy Tarreau
2018-01-07 18:55                           ` Borislav Petkov
2018-01-07 22:10                             ` Willy Tarreau
2018-01-08  9:18                               ` Thomas Gleixner
2018-01-08  9:29                                 ` Willy Tarreau
2018-01-08 16:22                               ` Borislav Petkov
2018-01-08 16:53                                 ` Willy Tarreau
2018-01-05 12:12                 ` Alan Cox
2018-01-09  1:44                   ` Samir Bellabes
     [not found]                 ` <CAL9bgJ8XNJgCtxR6+M+Vm9eDBVZ4Dyi_-Lt-Q1ei9N=TE2c6cg@mail.gmail.com>
2018-01-07  5:04                   ` Fwd: " Kiernan Hager
2018-01-07  6:39                     ` Willy Tarreau
2018-01-07 14:01                     ` Alan Cox
2018-01-07 17:47                       ` Willy Tarreau
2018-01-07 18:01                         ` Ivan Ivanov
2018-01-07 18:16                           ` Woodhouse, David
2018-01-04 11:26   ` Pavel Machek
2018-01-04 11:54     ` Alan Cox
2018-01-04 18:33     ` Linus Torvalds
2018-01-04 20:08       ` Jon Masters
  -- strict thread matches above, loose matches on Subject: below --
2018-01-04  2:00 Andi Kleen
2018-01-04 11:49 ` Pavel Machek
2018-01-04 12:09   ` Alan Cox
2018-01-04 13:32     ` Pavel Machek
2018-01-12  8:20 Dr. Greg Wettstein
2018-02-23 21:10 Ywe Cærlyn

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=20180104162541.GD13348@redhat.com \
    --to=aarcange@redhat.com \
    --cc=andi@firstfloor.org \
    --cc=andrew.cooper3@citrix.com \
    --cc=dave.hansen@intel.com \
    --cc=dwmw@amazon.co.uk \
    --cc=gnomes@lxorguk.ukuu.org.uk \
    --cc=gregkh@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --cc=pbonzini@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=tim.c.chen@linux.intel.com \
    --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;
as well as URLs for NNTP newsgroup(s).