Received: by 10.223.176.5 with SMTP id f5csp2071990wra; Wed, 31 Jan 2018 16:25:53 -0800 (PST) X-Google-Smtp-Source: AH8x227lsuTppE04J+Q1VyPf2op9osquVnqQjp/L8asZ4QfTrRK3ii2d4c5XSVe4NHGd0arOqbAS X-Received: by 2002:a17:902:6683:: with SMTP id e3-v6mr29718181plk.22.1517444753577; Wed, 31 Jan 2018 16:25:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517444753; cv=none; d=google.com; s=arc-20160816; b=h1weeT+r30BjN3pP8HhQCeE45iX9lEYYDFAvA7RPPM4wcJgaGJFtfXsrUmiKSEftck kaojsYs4MyTZkd5VPVhq/0Oy8w7sjLoZCHirIq86rPdAGl4wtdYDdEI8xK3xa3vwnavX ymStAxLE7M06n2QkQlXJhEGno+PmCNnbD7J7jYCbvDqIxAVavtxYL5mh1gZGBzTbNLni HYJt8q/fs/NqKrlT3HlhSf/0hJQIoxs/l8LTS9iHzDhDd8w2F0cd0ReHRnw6ckbIvToM R9372erydB2PlpUrS2SMXnLhpQrcw7vW5ripX06SmNWd7wEzTqQevCpAb2Yljb0f65AS TyxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:cc:to:from:subject :dkim-signature:arc-authentication-results; bh=snER60efwfxmdCsTIuGRhTxuoQ0Y7bqWkPJGaSAfjdY=; b=MmrR5cVaenOe+OuJpFZuHVUW6TaPOJOhhki+ubqCqkEHHWy8mSjTEbNTnZAMHamn99 si8IC/Aq3zPfzIS/sz9IDEMJza1RS9SreKkZEWVKGSk6c9Az50Mmv0h+XiirB302xvj6 odao4d8tj8AcMTUqRIrmUn7bWLBijlDHZX3sTgG3vrCb4v7o6wls6eUE/K4TdQEncaKi uStPAPgMXY9KfXTWNTrD0XPXZTvv8PtB7FlQUmBs2jvuY8nFvSeqXOf6Ol8Zjy4t5bot eAhr1yIMeGFiKBFKGX/OvsYGTjShjCPLk83nkAmNretPYtBOl5Dktkr2vUmbib+tX7ub vOAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=OFmc83hi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z9si5092115pfk.333.2018.01.31.16.25.39; Wed, 31 Jan 2018 16:25:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=OFmc83hi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932160AbeBAAZS (ORCPT + 99 others); Wed, 31 Jan 2018 19:25:18 -0500 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:54335 "EHLO smtp-fw-9102.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753846AbeBAAZO (ORCPT ); Wed, 31 Jan 2018 19:25:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1517444714; x=1548980714; h=subject:from:to:cc:references:message-id:date: mime-version:in-reply-to; bh=snER60efwfxmdCsTIuGRhTxuoQ0Y7bqWkPJGaSAfjdY=; b=OFmc83higrXo1Vn9upaybL9fqOWmYzvou5GVne58Nf9FjhpebcB52YSy xWD6nVd9dySy9M/rp2x2HOv4/0tsTbG3ruykCYypJszC1vRvCC1xKcfPY eGTzH2WNFYR5A4oyaUoUGx1/zHzVlzytFfNlG91BpMzGIeYJYWG4nwQVB U=; X-Amazon-filename: 0004-KVM-VMX-Allow-direct-access-to-MSR_IA32_SPEC_CTRL.patch X-IronPort-AV: E=Sophos;i="5.46,442,1511827200"; d="scan'208,223";a="591878803" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-1d-74cf8b49.us-east-1.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 01 Feb 2018 00:25:11 +0000 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1d-74cf8b49.us-east-1.amazon.com (8.14.7/8.14.7) with ESMTP id w110P4Mn094063 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Thu, 1 Feb 2018 00:25:05 GMT Received: from EX13D01EUB003.ant.amazon.com (10.43.166.248) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Thu, 1 Feb 2018 00:25:04 +0000 Received: from [10.85.102.109] (10.43.160.237) by EX13D01EUB003.ant.amazon.com (10.43.166.248) with Microsoft SMTP Server (TLS) id 15.0.1236.3; Thu, 1 Feb 2018 00:24:54 +0000 Subject: Re: [PATCH v5 4/5] KVM: VMX: Allow direct access to MSR_IA32_SPEC_CTRL From: KarimAllah Ahmed To: Jim Mattson CC: KarimAllah Ahmed , kvm list , LKML , the arch/x86 maintainers , Asit Mallick , Arjan Van De Ven , Dave Hansen , Andi Kleen , Andrea Arcangeli , Linus Torvalds , Tim Chen , Thomas Gleixner , Dan Williams , Jun Nakajima , "Paolo Bonzini" , David Woodhouse , Greg KH , Andy Lutomirski , Ashok Raj References: <1517427467-28567-1-git-send-email-karahmed@amazon.de> <1517427467-28567-5-git-send-email-karahmed@amazon.de> <06cb88da-f355-41ed-380f-7daa8ddf6159@amazon.com> Message-ID: Date: Thu, 1 Feb 2018 01:24:49 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------E06A5B468C37FA90DF9CFCD3" Content-Language: en-US X-Originating-IP: [10.43.160.237] X-ClientProxiedBy: EX13D01UWA001.ant.amazon.com (10.43.160.60) To EX13D01EUB003.ant.amazon.com (10.43.166.248) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --------------E06A5B468C37FA90DF9CFCD3 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: base64 T24gMDEvMzEvMjAxOCAxMTo1MiBQTSwgS2FyaW1BbGxhaCBBaG1lZCB3cm90ZToKPiBPbiAwMS8z MS8yMDE4IDA5OjE4IFBNLCBKaW0gTWF0dHNvbiB3cm90ZToKPj4gT24gV2VkLCBKYW4gMzEsIDIw MTggYXQgMTI6MDEgUE0sIEthcmltQWxsYWggQWhtZWQgCj4+IDxrYXJhaG1lZEBhbWF6b24uY29t PiB3cm90ZToKPj4KPj4+IGJ1dCBzYXZlX3NwZWNfY3RybF9vbl9leGl0IGlzIGFsc28gc2V0IGZv ciBMMiB3cml0ZS4gU28gb25jZSBMMiB3cml0ZXMKPj4+IHRvIGl0LCB0aGlzIGNvbmRpdGlvbiB3 aWxsIGJlIHRydWUgYW5kIHRoZW4gdGhlIGJpdG1hcCB3aWxsIGJlIHVwZGF0ZWQuCj4+Cj4+IFNv IGlmIEwxIG9yIGFueSBMMiB3cml0ZXMgdG8gdGhlIE1TUiwgdGhlbiBzYXZlX3NwZWNfY3RybF9v bl9leGl0IGlzCj4+IHNldCB0byB0cnVlLCBldmVuIGlmIHRoZSBNU1IgcGVybWlzc2lvbiBiaXRt YXAgZm9yIGEgcGFydGljdWxhciBWTUNTCj4+ICpkb2Vzbid0KiBhbGxvdyB0aGUgTVNSIHRvIGJl IHdyaXR0ZW4gd2l0aG91dCBhbiBpbnRlcmNlcHQuIFRoYXQncwo+PiBmdW5jdGlvbmFsbHkgY29y cmVjdCwgYnV0IGluZWZmaWNpZW50LiBJdCBzZWVtcyB0byBtZSB0aGF0Cj4+IHNhdmVfc3BlY19j dHJsX29uX2V4aXQgc2hvdWxkIGluZGljYXRlIHdoZXRoZXIgb3Igbm90IHRoZSAqY3VycmVudCoK Pj4gTVNSIHBlcm1pc3Npb24gYml0bWFwIGFsbG93cyB1bmludGVyY2VwdGVkIHdyaXRlcyB0byBJ QTMyX1NQRUNfQ1RSTC4KPj4gVG8gdGhhdCBlbmQsIHBlcmhhcHMgc2F2ZV9zcGVjX2N0cmxfb25f ZXhpdCByaWdodGZ1bGx5IGJlbG9uZ3MgaW4gdGhlCj4+IGxvYWRlZF92bWNzIHN0cnVjdHVyZSwg YWxvbmdzaWRlIHRoZSBtc3JfYml0bWFwIHBvaW50ZXIgdGhhdCBpdCBpcwo+PiBhc3NvY2lhdGVk IHdpdGguIEZvciB2bWNzMDIsIG5lc3RlZF92bXhfbWVyZ2VfbXNyX2JpdG1hcCgpIHNob3VsZCBz ZXQKPj4gdGhlIHZtY3MwMiBzYXZlX3NwZWNfY3RybF9vbl9leGl0IGJhc2VkIG9uIChhKSB3aGV0 aGVyIEwwIGlzIHdpbGxpbmcKPj4gdG8geWllbGQgdGhlIE1TUiB0byBMMSwgYW5kIChiKSB3aGV0 aGVyIEwxIGlzIHdpbGxpbmcgdG8geWllbGQgdGhlIE1TUgo+PiB0byBMMi4KPiAKPiBJIGFjdHVh bGx5IGdvdCByaWQgb2YgdGhpcyBzYXZlX3NwZWNfY3RybF9vbl9leGl0IHZhcmlhYmxlIGFuZCBy ZXBsYWNlZAo+IGl0IHdpdGggYW5vdGhlciB2YXJpYWJsZSBsaWtlIHRoZSBvbmUgc3VnZ2VzdGVk IGZvciBJQlBCLiBKdXN0IHRvIGF2b2lkCj4gZG9pbmcgYW4gZXhwZW5zaXZlIGd1ZXN0X2NwdWlk X2hhcy4gTm93IEkgcGVhayBpbnN0ZWFkIGluIHRoZSBNU1IgYml0bWFwCj4gdG8gZmlndXJlIG91 dCBpZiB0aGlzIE1TUiB3YXMgc3VwcG9zZWQgdG8gYmUgaW50ZXJjZXB0ZWQgb3Igbm90LiBUaGlz Cj4gdGVzdCBzaG91bGQgcHJvdmlkZSBhIHNpbWlsYXIgc2VtYW50aWNzIHRvIHNhdmVfc3BlY19j dHJsX29uX2V4aXQuCj4gCj4gQW55d2F5LCBjbGVhbmluZyB1cC90ZXN0aW5nIG5vdyBhbmQgd2ls bCBwb3N0IGEgbmV3IHZlcnNpb24uCgpJIHRoaW5rIHRoaXMgcGF0Y2ggc2hvdWxkIGFkZHJlc3Mg YWxsIHlvdXIgY29uY2VybnMuCkFtYXpvbiBEZXZlbG9wbWVudCBDZW50ZXIgR2VybWFueSBHbWJI CkJlcmxpbiAtIERyZXNkZW4gLSBBYWNoZW4KbWFpbiBvZmZpY2U6IEtyYXVzZW5zdHIuIDM4LCAx MDExNyBCZXJsaW4KR2VzY2hhZWZ0c2Z1ZWhyZXI6IERyLiBSYWxmIEhlcmJyaWNoLCBDaHJpc3Rp YW4gU2NobGFlZ2VyClVzdC1JRDogREUyODkyMzc4NzkKRWluZ2V0cmFnZW4gYW0gQW10c2dlcmlj aHQgQ2hhcmxvdHRlbmJ1cmcgSFJCIDE0OTE3MyBCCg== --------------E06A5B468C37FA90DF9CFCD3 Content-Type: text/x-patch; name="0004-KVM-VMX-Allow-direct-access-to-MSR_IA32_SPEC_CTRL.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0004-KVM-VMX-Allow-direct-access-to-MSR_IA32_SPEC_CTRL.patch" From 9c19a8ac3f021efba6f70ad7e28f7ad06bb97e43 Mon Sep 17 00:00:00 2001 From: KarimAllah Ahmed Date: Mon, 29 Jan 2018 19:58:10 +0000 Subject: [PATCH] KVM: VMX: Allow direct access to MSR_IA32_SPEC_CTRL [ Based on a patch from Ashok Raj ] Add direct access to MSR_IA32_SPEC_CTRL for guests. This is needed for guests that will only mitigate Spectre V2 through IBRS+IBPB and will not be using a retpoline+IBPB based approach. To avoid the overhead of atomically saving and restoring the MSR_IA32_SPEC_CTRL for guests that do not actually use the MSR, only add_atomic_switch_msr when a non-zero is written to it. No attempt is made to handle STIBP here, intentionally. Filtering STIBP may be added in a future patch, which may require trapping all writes if we don't want to pass it through directly to the guest. [dwmw2: Clean up CPUID bits, save/restore manually, handle reset] 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: Paolo Bonzini Cc: David Woodhouse Cc: Greg KH Cc: Andy Lutomirski Cc: Ashok Raj Signed-off-by: KarimAllah Ahmed Signed-off-by: David Woodhouse --- v6: - got rid of save_spec_ctrl_on_exit - introduce spec_ctrl_intercepted - introduce spec_ctrl_used v5: - Also check for X86_FEATURE_SPEC_CTRL for the msr reads/writes v4: - Add IBRS to kvm_cpuid_8000_0008_ebx_x86_features - Handling nested guests v3: - Save/restore manually - Fix CPUID handling - Fix a copy & paste error in the name of SPEC_CTRL MSR in disable_intercept. - support !cpu_has_vmx_msr_bitmap() v2: - remove 'host_spec_ctrl' in favor of only a comment (dwmw@). - special case writing '0' in SPEC_CTRL to avoid confusing live-migration when the instance never used the MSR (dwmw@). - depend on X86_FEATURE_IBRS instead of X86_FEATURE_SPEC_CTRL (dwmw@). - add MSR_IA32_SPEC_CTRL to the list of MSRs to save (dropped it by accident). --- arch/x86/kvm/cpuid.c | 9 +++-- arch/x86/kvm/vmx.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++- arch/x86/kvm/x86.c | 2 +- 3 files changed, 100 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 1909635..13f5d42 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -367,7 +367,7 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, /* cpuid 0x80000008.ebx */ const u32 kvm_cpuid_8000_0008_ebx_x86_features = - F(IBPB); + F(IBPB) | F(IBRS); /* cpuid 0xC0000001.edx */ const u32 kvm_cpuid_C000_0001_edx_x86_features = @@ -394,7 +394,8 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, /* cpuid 7.0.edx*/ const u32 kvm_cpuid_7_0_edx_x86_features = - F(AVX512_4VNNIW) | F(AVX512_4FMAPS) | F(ARCH_CAPABILITIES); + F(AVX512_4VNNIW) | F(AVX512_4FMAPS) | F(SPEC_CTRL) | + F(ARCH_CAPABILITIES); /* all calls to cpuid_count() should be made on the same cpu */ get_cpu(); @@ -630,9 +631,11 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, g_phys_as = phys_as; entry->eax = g_phys_as | (virt_as << 8); entry->edx = 0; - /* IBPB isn't necessarily present in hardware cpuid */ + /* IBRS and IBPB aren't necessarily present in hardware cpuid */ if (boot_cpu_has(X86_FEATURE_IBPB)) entry->ebx |= F(IBPB); + if (boot_cpu_has(X86_FEATURE_IBRS)) + entry->ebx |= F(IBRS); entry->ebx &= kvm_cpuid_8000_0008_ebx_x86_features; cpuid_mask(&entry->ebx, CPUID_8000_0008_EBX); break; diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 6a9f4ec..bfc80ff 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -594,6 +594,14 @@ struct vcpu_vmx { #endif u64 arch_capabilities; + u64 spec_ctrl; + + /* + * This indicates that: + * 1) guest_cpuid_has(X86_FEATURE_IBRS) == true && + * 2) The guest has actually initiated a write against the MSR. + */ + bool spec_ctrl_used; /* * This indicates that: @@ -946,6 +954,8 @@ static void vmx_set_nmi_mask(struct kvm_vcpu *vcpu, bool masked); static bool nested_vmx_is_page_fault_vmexit(struct vmcs12 *vmcs12, u16 error_code); static void vmx_update_msr_bitmap(struct kvm_vcpu *vcpu); +static void __always_inline vmx_disable_intercept_for_msr(unsigned long *msr_bitmap, + u32 msr, int type); static DEFINE_PER_CPU(struct vmcs *, vmxarea); static DEFINE_PER_CPU(struct vmcs *, current_vmcs); @@ -1917,6 +1927,22 @@ static void update_exception_bitmap(struct kvm_vcpu *vcpu) vmcs_write32(EXCEPTION_BITMAP, eb); } +/* Is SPEC_CTRL intercepted for the currently running vCPU? */ +static bool spec_ctrl_intercepted(struct kvm_vcpu *vcpu) +{ + unsigned long *msr_bitmap; + int f = sizeof(unsigned long); + + if (!cpu_has_vmx_msr_bitmap()) + return true; + + msr_bitmap = is_guest_mode(vcpu) ? + to_vmx(vcpu)->nested.vmcs02.msr_bitmap : + to_vmx(vcpu)->vmcs01.msr_bitmap; + + return !!test_bit(MSR_IA32_SPEC_CTRL, msr_bitmap + 0x800 / f); +} + static void clear_atomic_switch_msr_special(struct vcpu_vmx *vmx, unsigned long entry, unsigned long exit) { @@ -3246,6 +3272,14 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) case MSR_IA32_TSC: msr_info->data = guest_read_tsc(vcpu); break; + case MSR_IA32_SPEC_CTRL: + if (!msr_info->host_initiated && + !guest_cpuid_has(vcpu, X86_FEATURE_IBRS) && + !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL)) + return 1; + + msr_info->data = to_vmx(vcpu)->spec_ctrl; + break; case MSR_IA32_ARCH_CAPABILITIES: if (!msr_info->host_initiated && !guest_cpuid_has(vcpu, X86_FEATURE_ARCH_CAPABILITIES)) @@ -3359,6 +3393,34 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) case MSR_IA32_TSC: kvm_write_tsc(vcpu, msr_info); break; + case MSR_IA32_SPEC_CTRL: + if (!msr_info->host_initiated && + !guest_cpuid_has(vcpu, X86_FEATURE_IBRS) && + !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL)) + return 1; + + vmx->spec_ctrl_used = true; + + /* The STIBP bit doesn't fault even if it's not advertised */ + if (data & ~(SPEC_CTRL_IBRS | SPEC_CTRL_STIBP)) + return 1; + + vmx->spec_ctrl = data; + + /* + * When it's written (to non-zero) for the first time, pass + * it through. This means we don't have to take the perf + * hit of saving it on vmexit for the common case of guests + * that don't use it. + */ + if (cpu_has_vmx_msr_bitmap() && data && + spec_ctrl_intercepted(vcpu) && + is_guest_mode(vcpu)) + vmx_disable_intercept_for_msr( + vmx->vmcs01.msr_bitmap, + MSR_IA32_SPEC_CTRL, + MSR_TYPE_RW); + break; case MSR_IA32_PRED_CMD: if (!msr_info->host_initiated && !guest_cpuid_has(vcpu, X86_FEATURE_IBPB) && @@ -5678,6 +5740,7 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) u64 cr0; vmx->rmode.vm86_active = 0; + vmx->spec_ctrl = 0; vmx->vcpu.arch.regs[VCPU_REGS_RDX] = get_rdx_init_val(); kvm_set_cr8(vcpu, 0); @@ -9349,6 +9412,15 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu) vmx_arm_hv_timer(vcpu); + /* + * If this vCPU has touched SPEC_CTRL, restore the guest's value if + * it's non-zero. Since vmentry is serialising on affected CPUs, there + * is no need to worry about the conditional branch over the wrmsr + * being speculatively taken. + */ + if (vmx->spec_ctrl) + wrmsrl(MSR_IA32_SPEC_CTRL, vmx->spec_ctrl); + vmx->__launched = vmx->loaded_vmcs->launched; asm( /* Store host registers */ @@ -9467,6 +9539,19 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu) #endif ); + /* + * We do not use IBRS in the kernel. If this vCPU has used the + * SPEC_CTRL MSR it may have left it on; save the value and + * turn it off. This is much more efficient than blindly adding + * it to the atomic save/restore list. Especially as the former + * (Saving guest MSRs on vmexit) doesn't even exist in KVM. + */ + if (!spec_ctrl_intercepted(vcpu)) + rdmsrl(MSR_IA32_SPEC_CTRL, vmx->spec_ctrl); + + if (vmx->spec_ctrl) + wrmsrl(MSR_IA32_SPEC_CTRL, 0); + /* Eliminate branch target predictions from guest mode */ vmexit_fill_RSB(); @@ -10092,7 +10177,8 @@ static inline bool nested_vmx_merge_msr_bitmap(struct kvm_vcpu *vcpu, unsigned long *msr_bitmap_l0 = to_vmx(vcpu)->nested.vmcs02.msr_bitmap; if (!nested_cpu_has_virt_x2apic_mode(vmcs12) && - !to_vmx(vcpu)->pred_cmd_used) + !to_vmx(vcpu)->pred_cmd_used && + !to_vmx(vcpu)->spec_ctrl_used) return false; page = kvm_vcpu_gpa_to_page(vcpu, vmcs12->msr_bitmap); @@ -10126,6 +10212,12 @@ static inline bool nested_vmx_merge_msr_bitmap(struct kvm_vcpu *vcpu, } } + if (to_vmx(vcpu)->spec_ctrl_used) + nested_vmx_disable_intercept_for_msr( + msr_bitmap_l1, msr_bitmap_l0, + MSR_IA32_SPEC_CTRL, + MSR_TYPE_R | MSR_TYPE_W); + if (to_vmx(vcpu)->pred_cmd_used) nested_vmx_disable_intercept_for_msr( msr_bitmap_l1, msr_bitmap_l0, diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 4ec142e..ac38143 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1009,7 +1009,7 @@ static u32 msrs_to_save[] = { #endif MSR_IA32_TSC, MSR_IA32_CR_PAT, MSR_VM_HSAVE_PA, MSR_IA32_FEATURE_CONTROL, MSR_IA32_BNDCFGS, MSR_TSC_AUX, - MSR_IA32_ARCH_CAPABILITIES + MSR_IA32_SPEC_CTRL, MSR_IA32_ARCH_CAPABILITIES }; static unsigned num_msrs_to_save; -- 2.7.4 --------------E06A5B468C37FA90DF9CFCD3--