From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932417AbeARPJz (ORCPT ); Thu, 18 Jan 2018 10:09:55 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:57519 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754736AbeARO56 (ORCPT ); Thu, 18 Jan 2018 09:57:58 -0500 Message-Id: <20180118140153.438995817@infradead.org> User-Agent: quilt/0.63-1 Date: Thu, 18 Jan 2018 14:48:33 +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 33/35] x86/svm: Direct access to MSR_IA32_SPEC_CTRL References: <20180118134800.711245485@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline; filename=paolo_bonzini-x86_svm-direct_access_to_msr_ia32_spec_ctrl.patch Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paolo Bonzini Direct access to MSR_IA32_SPEC_CTRL is important for performance. Allow load/store of MSR_IA32_SPEC_CTRL, restore guest IBRS on VM entry and set restore host values on VM exit. it yet). TBD: need to check msr's can be passed through even if feature is not emuerated by the CPU. [peterz: rebased, folded feedback from Tom] Cc: Asit Mallick Cc: Arjan Van De Ven Cc: Dave Hansen Cc: Andi Kleen Cc: Andrea Arcangeli Cc: Linus Torvalds Cc: Tim Chen Cc: Thomas Gleixner Cc: Dan Williams Cc: Jun Nakajima Cc: David Woodhouse Cc: Greg KH Cc: Andy Lutomirski Signed-off-by: Paolo Bonzini Signed-off-by: Ashok Raj Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/kvm/svm.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -184,6 +184,8 @@ struct vcpu_svm { u64 gs_base; } host; + u64 spec_ctrl; + u32 *msrpm; ulong nmi_iret_rip; @@ -249,6 +251,7 @@ static const struct svm_direct_access_ms { .index = MSR_CSTAR, .always = true }, { .index = MSR_SYSCALL_MASK, .always = true }, #endif + { .index = MSR_IA32_SPEC_CTRL, .always = true }, { .index = MSR_IA32_LASTBRANCHFROMIP, .always = false }, { .index = MSR_IA32_LASTBRANCHTOIP, .always = false }, { .index = MSR_IA32_LASTINTFROMIP, .always = false }, @@ -3577,6 +3580,9 @@ static int svm_get_msr(struct kvm_vcpu * case MSR_VM_CR: msr_info->data = svm->nested.vm_cr_msr; break; + case MSR_IA32_SPEC_CTRL: + msr_info->data = svm->spec_ctrl; + break; case MSR_IA32_UCODE_REV: msr_info->data = 0x01000065; break; @@ -3725,6 +3731,9 @@ static int svm_set_msr(struct kvm_vcpu * case MSR_VM_IGNNE: vcpu_unimpl(vcpu, "unimplemented wrmsr: 0x%x data 0x%llx\n", ecx, data); break; + case MSR_IA32_SPEC_CTRL: + svm->spec_ctrl = data; + break; case MSR_IA32_APICBASE: if (kvm_vcpu_apicv_active(vcpu)) avic_update_vapic_bar(to_svm(vcpu), data); @@ -4911,6 +4920,8 @@ static void svm_vcpu_run(struct kvm_vcpu clgi(); + restore_indirect_branch_speculation(svm->spec_ctrl); + local_irq_enable(); asm volatile ( @@ -4989,6 +5000,8 @@ static void svm_vcpu_run(struct kvm_vcpu /* Eliminate branch target predictions from guest mode */ vmexit_fill_RSB(); + svm->spec_ctrl = stop_indirect_branch_speculation_and_save(); + #ifdef CONFIG_X86_64 wrmsrl(MSR_GS_BASE, svm->host.gs_base); #else