lkml.org 
[lkml]   [2018]   [Jan]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
From
Subject[PATCH 31/35] x86/ibrs: Add new helper macros to save/restore MSR_IA32_SPEC_CTRL
From: Ashok Raj <ashok.raj@intel.com>

Add some helper macros to save/restore MSR_IA32_SPEC_CTRL.

stop_indirect_branch_speculation_and_save() - saves the current
state and enables IBRS.

restore_indirect_branch_speculation() - restores the previously
saved IBRS state.

[peterz: renaming and folding of logic from the kvm patches]

Cc: Asit Mallick <asit.k.mallick@intel.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Arjan Van De Ven <arjan.van.de.ven@intel.com>
Cc: Tim Chen <tim.c.chen@linux.intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Jun Nakajima <jun.nakajima@intel.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Greg KH <gregkh@linuxfoundation.org>
Cc: David Woodhouse <dwmw@amazon.co.uk>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Ashok Raj <ashok.raj@intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
arch/x86/include/asm/nospec-branch.h | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)

--- a/arch/x86/include/asm/nospec-branch.h
+++ b/arch/x86/include/asm/nospec-branch.h
@@ -232,6 +232,24 @@ static inline void restart_indirect_bran
native_wrmsrl(MSR_IA32_SPEC_CTRL, SPEC_CTRL_DISABLE_IBRS);
}

+static inline u64 stop_indirect_branch_speculation_and_save(void)
+{
+ u64 val = 0;
+
+ if (static_cpu_has(X86_FEATURE_IBRS)) {
+ val = native_rdmsrl(MSR_IA32_SPEC_CTRL);
+ native_wrmsrl(MSR_IA32_SPEC_CTRL, SPEC_CTRL_ENABLE_IBRS);
+ }
+
+ return val;
+}
+
+static inline void restore_indirect_branch_speculation(u64 val)
+{
+ if (static_cpu_has(X86_FEATURE_IBRS))
+ native_wrmsrl(MSR_IA32_SPEC_CTRL, val);
+}
+
void specctrl_init_ibpb(void);

static inline void indirect_branch_prediction_barrier(void)

\
 
 \ /
  Last update: 2018-01-18 16:02    [W:0.548 / U:0.192 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site