From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756052AbeARPB2 (ORCPT ); Thu, 18 Jan 2018 10:01:28 -0500 Received: from merlin.infradead.org ([205.233.59.134]:46780 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755170AbeARO6F (ORCPT ); Thu, 18 Jan 2018 09:58:05 -0500 Message-Id: <20180118140153.318015981@infradead.org> User-Agent: quilt/0.63-1 Date: Thu, 18 Jan 2018 14:48:31 +0100 From: Peter Zijlstra From: Peter Zijlstra To: David Woodhouse , Thomas Gleixner , Josh Poimboeuf Cc: linux-kernel@vger.kernel.org, Dave Hansen , Ashok Raj , Tim Chen , Andy Lutomirski , Linus Torvalds , Greg KH , Andrea Arcangeli , Andi Kleen , Arjan Van De Ven , Dan Williams , Paolo Bonzini , Jun Nakajima , Asit Mallick , Jason Baron , Peter Zijlstra , David Woodhouse Subject: [PATCH 31/35] x86/ibrs: Add new helper macros to save/restore MSR_IA32_SPEC_CTRL References: <20180118134800.711245485@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline; filename=ashok_raj-x86_ibrs-add_new_helper_macros_to_save_restore_msr_ia32_spec_ctrl.patch Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ashok Raj 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 Cc: Dave Hansen Cc: Arjan Van De Ven Cc: Tim Chen Cc: Linus Torvalds Cc: Andrea Arcangeli Cc: Andi Kleen Cc: Thomas Gleixner Cc: Dan Williams Cc: Jun Nakajima Cc: Andy Lutomirski Cc: Greg KH Cc: David Woodhouse Cc: Paolo Bonzini Signed-off-by: Ashok Raj Signed-off-by: Peter Zijlstra (Intel) --- 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)