All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Tim Chen <tim.c.chen@linux.intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Andy Lutomirski <luto@kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Greg KH <gregkh@linuxfoundation.org>,
	Dave Hansen <dave.hansen@intel.com>,
	Andrea Arcangeli <aarcange@redhat.com>,
	Andi Kleen <ak@linux.intel.com>,
	Arjan Van De Ven <arjan.van.de.ven@intel.com>,
	David Woodhouse <dwmw@amazon.co.uk>,
	Dan Williams <dan.j.williams@intel.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Ashok Raj <ashok.raj@intel.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 3/5] x86/enter: Use IBRS on syscall and interrupts
Date: Wed, 10 Jan 2018 11:04:57 +0100	[thread overview]
Message-ID: <20180110100457.GA29822@worktop.programming.kicks-ass.net> (raw)
In-Reply-To: <d5e4c03ec290c61dfbe5a769f7287817283fa6b7.1515542293.git.tim.c.chen@linux.intel.com>

On Tue, Jan 09, 2018 at 06:26:47PM -0800, Tim Chen wrote:
> Set IBRS upon kernel entrance via syscall and interrupts. Clear it
> upon exit.  IBRS protects against unsafe indirect branching predictions
> in the kernel.
> 
> The NMI interrupt save/restore of IBRS state was based on Andrea
> Arcangeli's implementation.
> Here's an explanation by Dave Hansen on why we save IBRS state for NMI.
> 
> The normal interrupt code uses the 'error_entry' path which uses the
> Code Segment (CS) of the instruction that was interrupted to tell
> whether it interrupted the kernel or userspace and thus has to switch
> IBRS, or leave it alone.
> 
> The NMI code is different.  It uses 'paranoid_entry' because it can
> interrupt the kernel while it is running with a userspace IBRS (and %GS
> and CR3) value, but has a kernel CS.  If we used the same approach as
> the normal interrupt code, we might do the following;
> 
> 	SYSENTER_entry
> <-------------- NMI HERE
> 	IBRS=1
> 		do_something()
> 	IBRS=0
> 	SYSRET
> 
> The NMI code might notice that we are running in the kernel and decide
> that it is OK to skip the IBRS=1.  This would leave it running
> unprotected with IBRS=0, which is bad.
> 
> However, if we unconditionally set IBRS=1, in the NMI, we might get the
> following case:
> 
> 	SYSENTER_entry
> 	IBRS=1
> 		do_something()
> 	IBRS=0
> <-------------- NMI HERE (set IBRS=1)
> 	SYSRET
> 
> and we would return to userspace with IBRS=1.  Userspace would run
> slowly until we entered and exited the kernel again.
> 
> Instead of those two approaches, we chose a third one where we simply
> save the IBRS value in a scratch register (%r13) and then restore that
> value, verbatim.
> 

What this Changelog fails to address is _WHY_ we need this. What does
this provide that retpoline does not.

  reply	other threads:[~2018-01-10 10:05 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-10  2:26 [PATCH v3 0/5] IBRS patch series Tim Chen
2018-01-10  2:26 ` [PATCH v3 1/5] x86/feature: Detect the x86 IBRS feature to control Speculation Tim Chen
2018-01-10  2:26 ` [PATCH v3 2/5] x86/enter: Create macros to set/clear IBRS Tim Chen
2018-01-11 16:04   ` Thomas Gleixner
2018-01-11 21:05     ` Tim Chen
2018-01-11 21:24       ` Tim Chen
2018-01-10  2:26 ` [PATCH v3 3/5] x86/enter: Use IBRS on syscall and interrupts Tim Chen
2018-01-10 10:04   ` Peter Zijlstra [this message]
2018-01-10 11:27     ` Paolo Bonzini
2018-01-10 18:16     ` Tim Chen
2018-01-10 18:28       ` Peter Zijlstra
2018-01-10 18:44         ` Tim Chen
2018-01-10 18:47         ` Van De Ven, Arjan
2018-01-11 12:45   ` Woodhouse, David
2018-01-10  2:26 ` [PATCH v3 4/5] x86/ibrs: Create boot option for IBRS Tim Chen
2018-01-10  2:26 ` [PATCH v3 5/5] x86/idle: Disable IBRS entering idle and enable it on wakeup Tim Chen

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=20180110100457.GA29822@worktop.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=aarcange@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=arjan.van.de.ven@intel.com \
    --cc=ashok.raj@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.hansen@intel.com \
    --cc=dwmw@amazon.co.uk \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.