All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH 9/8] KVM: x86: limit MSR_IA32_SPEC_CTRL access based on CPUID availability
@ 2018-01-09 15:58 Liran Alon
  2018-01-09 16:11 ` Paolo Bonzini
  0 siblings, 1 reply; 6+ messages in thread
From: Liran Alon @ 2018-01-09 15:58 UTC (permalink / raw)
  To: pbonzini
  Cc: jmattson, x86, dwmw, bp, aliguori, thomas.lendacky, rkrcmar,
	linux-kernel, kvm


----- pbonzini@redhat.com wrote:

> MSR_IA32_SPEC_CTRL is not available unless CPU[7,0].EDX[26] is 1.
> Check that against host CPUID or guest CPUID, respectively for
> host-initiated and guest-initiated accesses.
> 
> Suggested-by: Jim Mattson <jmattson@google.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> 	This is for after X86_FEATURE_SPEC_CTRL is added to Linux, but
> 	I still wanted to ack Jim's improvement.
> 
>  arch/x86/kvm/svm.c | 8 ++++++++
>  arch/x86/kvm/vmx.c | 8 ++++++++
>  2 files changed, 16 insertions(+)
> 
> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> index 97126c2bd663..3a646580d7c5 100644
> --- a/arch/x86/kvm/svm.c
> +++ b/arch/x86/kvm/svm.c
> @@ -3648,6 +3648,10 @@ static int svm_get_msr(struct kvm_vcpu *vcpu,
> struct msr_data *msr_info)
>  		msr_info->data = svm->nested.vm_cr_msr;
>  		break;
>  	case MSR_IA32_SPEC_CTRL:
> +		if (!static_cpu_has(X86_FEATURE_SPEC_CTRL) ||
> +	    	    (!msr_info->host_initiated &&
> +       		     !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL)))
> +			return 1;
>  		msr_info->data = svm->spec_ctrl;
>  		break;
>  	case MSR_IA32_UCODE_REV:
> @@ -3806,6 +3810,10 @@ static int svm_set_msr(struct kvm_vcpu *vcpu,
> struct msr_data *msr)
>  		vcpu_unimpl(vcpu, "unimplemented wrmsr: 0x%x data 0x%llx\n", ecx,
> data);
>  		break;
>  	case MSR_IA32_SPEC_CTRL:
> +		if (!static_cpu_has(X86_FEATURE_SPEC_CTRL) ||
> +	    	    (!msr_info->host_initiated &&
> +       		     !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL)))
> +			return 1;
>  		svm->spec_ctrl = data;
>  		break;
>  	case MSR_IA32_APICBASE:
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 49b4a2d61603..42bc7ee293e4 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -3368,6 +3368,10 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu,
> struct msr_data *msr_info)
>  		msr_info->data = guest_read_tsc(vcpu);
>  		break;
>  	case MSR_IA32_SPEC_CTRL:
> +		if (!static_cpu_has(X86_FEATURE_SPEC_CTRL) ||
> +		    (!msr_info->host_initiated &&
> +		     !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL)))
> +			return 1;
>  		msr_info->data = to_vmx(vcpu)->spec_ctrl;
>  		break;
>  	case MSR_IA32_SYSENTER_CS:
> @@ -3510,6 +3514,10 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu,
> struct msr_data *msr_info)
>  		kvm_write_tsc(vcpu, msr_info);
>  		break;
>  	case MSR_IA32_SPEC_CTRL:
> +		if (!static_cpu_has(X86_FEATURE_SPEC_CTRL) ||
> +		    (!msr_info->host_initiated &&
> +		     !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL)))
> +			return 1;
>  		to_vmx(vcpu)->spec_ctrl = data;
>  		break;
>  	case MSR_IA32_CR_PAT:
> -- 
> 1.8.3.1

Reviewed-by: Liran Alon <liran.alon@oracle.com>

The only thing I a bit dislike is that currently these MSRs are always pass-through to guest and therefore
there is no case vmx_set_msr() is called with !msr_info->host_initiated.
Don't you think we should BUG_ON(!msr_info->host_initiated)?

-Liran

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 9/8] KVM: x86: limit MSR_IA32_SPEC_CTRL access based on CPUID availability
  2018-01-09 15:58 [PATCH 9/8] KVM: x86: limit MSR_IA32_SPEC_CTRL access based on CPUID availability Liran Alon
@ 2018-01-09 16:11 ` Paolo Bonzini
  2018-01-09 16:40   ` Jim Mattson
  0 siblings, 1 reply; 6+ messages in thread
From: Paolo Bonzini @ 2018-01-09 16:11 UTC (permalink / raw)
  To: Liran Alon
  Cc: jmattson, x86, dwmw, bp, aliguori, thomas.lendacky, rkrcmar,
	linux-kernel, kvm

On 09/01/2018 16:58, Liran Alon wrote:
> 
> The only thing I a bit dislike is that currently these MSRs are always pass-through to guest and therefore
> there is no case vmx_set_msr() is called with !msr_info->host_initiated.
> Don't you think we should BUG_ON(!msr_info->host_initiated)?

All this is in flux.  We'll probably get per-VCPU MSR bitmaps anyway
before this patch (which is not part of the initial, minimal fix) is
committed.

Paolo

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 9/8] KVM: x86: limit MSR_IA32_SPEC_CTRL access based on CPUID availability
  2018-01-09 16:11 ` Paolo Bonzini
@ 2018-01-09 16:40   ` Jim Mattson
  0 siblings, 0 replies; 6+ messages in thread
From: Jim Mattson @ 2018-01-09 16:40 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Liran Alon, the arch/x86 maintainers, dwmw, bp, aliguori,
	Tom Lendacky, Radim Krčmář,
	LKML, kvm list

I'm going to try to get per-vCPU MSR bitmaps out today or tomorrow.

On Tue, Jan 9, 2018 at 8:11 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> On 09/01/2018 16:58, Liran Alon wrote:
>>
>> The only thing I a bit dislike is that currently these MSRs are always pass-through to guest and therefore
>> there is no case vmx_set_msr() is called with !msr_info->host_initiated.
>> Don't you think we should BUG_ON(!msr_info->host_initiated)?
>
> All this is in flux.  We'll probably get per-VCPU MSR bitmaps anyway
> before this patch (which is not part of the initial, minimal fix) is
> committed.
>
> Paolo
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 9/8] KVM: x86: limit MSR_IA32_SPEC_CTRL access based on CPUID availability
  2018-01-16  0:55   ` Eric Wheeler
@ 2018-01-16 12:59     ` Paolo Bonzini
  0 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2018-01-16 12:59 UTC (permalink / raw)
  To: Eric Wheeler
  Cc: linux-kernel, kvm, rkrcmar, liran.alon, jmattson, aliguori,
	thomas.lendacky, dwmw, bp, x86

On 16/01/2018 01:55, Eric Wheeler wrote:
> On Tue, 9 Jan 2018, Paolo Bonzini wrote:
>> MSR_IA32_SPEC_CTRL is not available unless CPU[7,0].EDX[26] is 1.
>> Check that against host CPUID or guest CPUID, respectively for
>> host-initiated and guest-initiated accesses.
> 
> Hi Radim, Paolo:
> 
> In porting this patch series to v4.14

Just don't apply this patch.

Paolo

> In file included from arch/x86/kvm/vmx.c:21:0:
> In function 'x86_feature_cpuid',
>     inlined from 'guest_cpuid_get_register' at arch/x86/kvm/cpuid.h:72:25,
>     inlined from 'vmx_get_msr' at arch/x86/kvm/cpuid.h:101:6:
> arch/x86/kvm/cpuid.h:64:232: error: call to '__compiletime_assert_64' 
> declared with attribute error: BUILD_BUG_ON failed: 
> reverse_cpuid[x86_leaf].function == 0
>   BUILD_BUG_ON(reverse_cpuid[x86_leaf].function == 0);
>                                                                                                                                                                                                                                         
> ^
> In function 'x86_feature_cpuid',
>     inlined from 'guest_cpuid_get_register' at arch/x86/kvm/cpuid.h:72:25,
>     inlined from 'vmx_set_msr' at arch/x86/kvm/cpuid.h:101:6:
> arch/x86/kvm/cpuid.h:64:232: error: call to '__compiletime_assert_64' 
> declared with attribute error: BUILD_BUG_ON failed: 
> reverse_cpuid[x86_leaf].function == 0
>   BUILD_BUG_ON(reverse_cpuid[x86_leaf].function == 0);
>                                                                                                                                                                                                                                         
> 
> I think this is caused by the following call stack for 
> X86_FEATURE_SPEC_CTRL, but if not please correct me here:
> 
> arch/x86/kvm/vmx.c:
> vmx_get_msr/vmx_set_msr()
> 	guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL)
> 		guest_cpuid_get_register(vcpu, x86_feature); 
> 			x86_feature_cpuid(x86_feature);
> 				x86_feature_cpuid(unsigned x86_feature)
> 					BUILD_BUG_ON(reverse_cpuid[x86_leaf].function == 0);
> 
> 
> It looks like I need to add something to reverse_cpuid[] but I'm not sure 
> what.  
> 
> Do you know what needs to be added here?
> 
> -Eric
> 
> --
> Eric Wheeler
> 
> 
> 
>>
>> Suggested-by: Jim Mattson <jmattson@google.com>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> ---
>> 	This is for after X86_FEATURE_SPEC_CTRL is added to Linux, but
>> 	I still wanted to ack Jim's improvement.
>>
>>  arch/x86/kvm/svm.c | 8 ++++++++
>>  arch/x86/kvm/vmx.c | 8 ++++++++
>>  2 files changed, 16 insertions(+)
>>
>> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
>> index 97126c2bd663..3a646580d7c5 100644
>> --- a/arch/x86/kvm/svm.c
>> +++ b/arch/x86/kvm/svm.c
>> @@ -3648,6 +3648,10 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
>>  		msr_info->data = svm->nested.vm_cr_msr;
>>  		break;
>>  	case MSR_IA32_SPEC_CTRL:
>> +		if (!static_cpu_has(X86_FEATURE_SPEC_CTRL) ||
>> +	    	    (!msr_info->host_initiated &&
>> +       		     !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL)))
>> +			return 1;
>>  		msr_info->data = svm->spec_ctrl;
>>  		break;
>>  	case MSR_IA32_UCODE_REV:
>> @@ -3806,6 +3810,10 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
>>  		vcpu_unimpl(vcpu, "unimplemented wrmsr: 0x%x data 0x%llx\n", ecx, data);
>>  		break;
>>  	case MSR_IA32_SPEC_CTRL:
>> +		if (!static_cpu_has(X86_FEATURE_SPEC_CTRL) ||
>> +	    	    (!msr_info->host_initiated &&
>> +       		     !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL)))
>> +			return 1;
>>  		svm->spec_ctrl = data;
>>  		break;
>>  	case MSR_IA32_APICBASE:
>> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
>> index 49b4a2d61603..42bc7ee293e4 100644
>> --- a/arch/x86/kvm/vmx.c
>> +++ b/arch/x86/kvm/vmx.c
>> @@ -3368,6 +3368,10 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
>>  		msr_info->data = guest_read_tsc(vcpu);
>>  		break;
>>  	case MSR_IA32_SPEC_CTRL:
>> +		if (!static_cpu_has(X86_FEATURE_SPEC_CTRL) ||
>> +		    (!msr_info->host_initiated &&
>> +		     !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL)))
>> +			return 1;
>>  		msr_info->data = to_vmx(vcpu)->spec_ctrl;
>>  		break;
>>  	case MSR_IA32_SYSENTER_CS:
>> @@ -3510,6 +3514,10 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
>>  		kvm_write_tsc(vcpu, msr_info);
>>  		break;
>>  	case MSR_IA32_SPEC_CTRL:
>> +		if (!static_cpu_has(X86_FEATURE_SPEC_CTRL) ||
>> +		    (!msr_info->host_initiated &&
>> +		     !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL)))
>> +			return 1;
>>  		to_vmx(vcpu)->spec_ctrl = data;
>>  		break;
>>  	case MSR_IA32_CR_PAT:
>> -- 
>> 1.8.3.1
>>
>>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 9/8] KVM: x86: limit MSR_IA32_SPEC_CTRL access based on CPUID availability
  2018-01-09 12:03 ` [PATCH 9/8] KVM: x86: limit MSR_IA32_SPEC_CTRL access based on CPUID availability Paolo Bonzini
@ 2018-01-16  0:55   ` Eric Wheeler
  2018-01-16 12:59     ` Paolo Bonzini
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Wheeler @ 2018-01-16  0:55 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: linux-kernel, kvm, rkrcmar, liran.alon, jmattson, aliguori,
	thomas.lendacky, dwmw, bp, x86

On Tue, 9 Jan 2018, Paolo Bonzini wrote:
> MSR_IA32_SPEC_CTRL is not available unless CPU[7,0].EDX[26] is 1.
> Check that against host CPUID or guest CPUID, respectively for
> host-initiated and guest-initiated accesses.

Hi Radim, Paolo:

In porting this patch series to v4.14, I'm getting this BUILD_BUG_ON:

In file included from arch/x86/kvm/vmx.c:21:0:
In function 'x86_feature_cpuid',
    inlined from 'guest_cpuid_get_register' at arch/x86/kvm/cpuid.h:72:25,
    inlined from 'vmx_get_msr' at arch/x86/kvm/cpuid.h:101:6:
arch/x86/kvm/cpuid.h:64:232: error: call to '__compiletime_assert_64' 
declared with attribute error: BUILD_BUG_ON failed: 
reverse_cpuid[x86_leaf].function == 0
  BUILD_BUG_ON(reverse_cpuid[x86_leaf].function == 0);
                                                                                                                                                                                                                                        
^
In function 'x86_feature_cpuid',
    inlined from 'guest_cpuid_get_register' at arch/x86/kvm/cpuid.h:72:25,
    inlined from 'vmx_set_msr' at arch/x86/kvm/cpuid.h:101:6:
arch/x86/kvm/cpuid.h:64:232: error: call to '__compiletime_assert_64' 
declared with attribute error: BUILD_BUG_ON failed: 
reverse_cpuid[x86_leaf].function == 0
  BUILD_BUG_ON(reverse_cpuid[x86_leaf].function == 0);
                                                                                                                                                                                                                                        

I think this is caused by the following call stack for 
X86_FEATURE_SPEC_CTRL, but if not please correct me here:

arch/x86/kvm/vmx.c:
vmx_get_msr/vmx_set_msr()
	guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL)
		guest_cpuid_get_register(vcpu, x86_feature); 
			x86_feature_cpuid(x86_feature);
				x86_feature_cpuid(unsigned x86_feature)
					BUILD_BUG_ON(reverse_cpuid[x86_leaf].function == 0);


It looks like I need to add something to reverse_cpuid[] but I'm not sure 
what.  

Do you know what needs to be added here?

-Eric

--
Eric Wheeler



> 
> Suggested-by: Jim Mattson <jmattson@google.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> 	This is for after X86_FEATURE_SPEC_CTRL is added to Linux, but
> 	I still wanted to ack Jim's improvement.
> 
>  arch/x86/kvm/svm.c | 8 ++++++++
>  arch/x86/kvm/vmx.c | 8 ++++++++
>  2 files changed, 16 insertions(+)
> 
> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> index 97126c2bd663..3a646580d7c5 100644
> --- a/arch/x86/kvm/svm.c
> +++ b/arch/x86/kvm/svm.c
> @@ -3648,6 +3648,10 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
>  		msr_info->data = svm->nested.vm_cr_msr;
>  		break;
>  	case MSR_IA32_SPEC_CTRL:
> +		if (!static_cpu_has(X86_FEATURE_SPEC_CTRL) ||
> +	    	    (!msr_info->host_initiated &&
> +       		     !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL)))
> +			return 1;
>  		msr_info->data = svm->spec_ctrl;
>  		break;
>  	case MSR_IA32_UCODE_REV:
> @@ -3806,6 +3810,10 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
>  		vcpu_unimpl(vcpu, "unimplemented wrmsr: 0x%x data 0x%llx\n", ecx, data);
>  		break;
>  	case MSR_IA32_SPEC_CTRL:
> +		if (!static_cpu_has(X86_FEATURE_SPEC_CTRL) ||
> +	    	    (!msr_info->host_initiated &&
> +       		     !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL)))
> +			return 1;
>  		svm->spec_ctrl = data;
>  		break;
>  	case MSR_IA32_APICBASE:
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 49b4a2d61603..42bc7ee293e4 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -3368,6 +3368,10 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
>  		msr_info->data = guest_read_tsc(vcpu);
>  		break;
>  	case MSR_IA32_SPEC_CTRL:
> +		if (!static_cpu_has(X86_FEATURE_SPEC_CTRL) ||
> +		    (!msr_info->host_initiated &&
> +		     !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL)))
> +			return 1;
>  		msr_info->data = to_vmx(vcpu)->spec_ctrl;
>  		break;
>  	case MSR_IA32_SYSENTER_CS:
> @@ -3510,6 +3514,10 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
>  		kvm_write_tsc(vcpu, msr_info);
>  		break;
>  	case MSR_IA32_SPEC_CTRL:
> +		if (!static_cpu_has(X86_FEATURE_SPEC_CTRL) ||
> +		    (!msr_info->host_initiated &&
> +		     !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL)))
> +			return 1;
>  		to_vmx(vcpu)->spec_ctrl = data;
>  		break;
>  	case MSR_IA32_CR_PAT:
> -- 
> 1.8.3.1
> 
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 9/8] KVM: x86: limit MSR_IA32_SPEC_CTRL access based on CPUID availability
  2018-01-09 12:03 [PATCH v2 0/8] KVM: x86: expose CVE-2017-5715 ("Spectre variant 2") mitigations to guest Paolo Bonzini
@ 2018-01-09 12:03 ` Paolo Bonzini
  2018-01-16  0:55   ` Eric Wheeler
  0 siblings, 1 reply; 6+ messages in thread
From: Paolo Bonzini @ 2018-01-09 12:03 UTC (permalink / raw)
  To: linux-kernel, kvm
  Cc: rkrcmar, liran.alon, jmattson, aliguori, thomas.lendacky, dwmw, bp, x86

MSR_IA32_SPEC_CTRL is not available unless CPU[7,0].EDX[26] is 1.
Check that against host CPUID or guest CPUID, respectively for
host-initiated and guest-initiated accesses.

Suggested-by: Jim Mattson <jmattson@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
	This is for after X86_FEATURE_SPEC_CTRL is added to Linux, but
	I still wanted to ack Jim's improvement.

 arch/x86/kvm/svm.c | 8 ++++++++
 arch/x86/kvm/vmx.c | 8 ++++++++
 2 files changed, 16 insertions(+)

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 97126c2bd663..3a646580d7c5 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -3648,6 +3648,10 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
 		msr_info->data = svm->nested.vm_cr_msr;
 		break;
 	case MSR_IA32_SPEC_CTRL:
+		if (!static_cpu_has(X86_FEATURE_SPEC_CTRL) ||
+	    	    (!msr_info->host_initiated &&
+       		     !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL)))
+			return 1;
 		msr_info->data = svm->spec_ctrl;
 		break;
 	case MSR_IA32_UCODE_REV:
@@ -3806,6 +3810,10 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
 		vcpu_unimpl(vcpu, "unimplemented wrmsr: 0x%x data 0x%llx\n", ecx, data);
 		break;
 	case MSR_IA32_SPEC_CTRL:
+		if (!static_cpu_has(X86_FEATURE_SPEC_CTRL) ||
+	    	    (!msr_info->host_initiated &&
+       		     !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL)))
+			return 1;
 		svm->spec_ctrl = data;
 		break;
 	case MSR_IA32_APICBASE:
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 49b4a2d61603..42bc7ee293e4 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -3368,6 +3368,10 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
 		msr_info->data = guest_read_tsc(vcpu);
 		break;
 	case MSR_IA32_SPEC_CTRL:
+		if (!static_cpu_has(X86_FEATURE_SPEC_CTRL) ||
+		    (!msr_info->host_initiated &&
+		     !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL)))
+			return 1;
 		msr_info->data = to_vmx(vcpu)->spec_ctrl;
 		break;
 	case MSR_IA32_SYSENTER_CS:
@@ -3510,6 +3514,10 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
 		kvm_write_tsc(vcpu, msr_info);
 		break;
 	case MSR_IA32_SPEC_CTRL:
+		if (!static_cpu_has(X86_FEATURE_SPEC_CTRL) ||
+		    (!msr_info->host_initiated &&
+		     !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL)))
+			return 1;
 		to_vmx(vcpu)->spec_ctrl = data;
 		break;
 	case MSR_IA32_CR_PAT:
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-01-16 13:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-09 15:58 [PATCH 9/8] KVM: x86: limit MSR_IA32_SPEC_CTRL access based on CPUID availability Liran Alon
2018-01-09 16:11 ` Paolo Bonzini
2018-01-09 16:40   ` Jim Mattson
  -- strict thread matches above, loose matches on Subject: below --
2018-01-09 12:03 [PATCH v2 0/8] KVM: x86: expose CVE-2017-5715 ("Spectre variant 2") mitigations to guest Paolo Bonzini
2018-01-09 12:03 ` [PATCH 9/8] KVM: x86: limit MSR_IA32_SPEC_CTRL access based on CPUID availability Paolo Bonzini
2018-01-16  0:55   ` Eric Wheeler
2018-01-16 12:59     ` Paolo Bonzini

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.