KVM: SVM: relax conditions for allowing MSR_IA32_SPEC_CTRL accesses
Paolo Bonzini
maintainerPATCH 1/1 KVM: SVM: relax conditions for allowing MSR_IA32_SPEC_CTRL accesses
Userspace that does not know about the AMD_IBRS bit might still allow the guest to protect itself with MSR_IA32_SPEC_CTRL using the Intel SPEC_CTRL bit. However, svm.c disallows this and will cause a #GP in the guest when writing to the MSR. Fix this by loosening the test and allowing the Intel CPUID bit, and in fact allow the AMD_STIBP bit as well since it allows writing to MSR_IA32_SPEC_CTRL too.
--- arch/x86/kvm/svm.c | 4 ++++ 1 file changed, 4 insertions(+)
arch/x86/kvm/svm.c +4 -0
@@ -4225,6 +4225,8 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)break ;case MSR_IA32_SPEC_CTRL :if (!msr_info->host_initiated && + !guest_cpuid_has (vcpu,X86_FEATURE_SPEC_CTRL ) && + !guest_cpuid_has (vcpu,X86_FEATURE_AMD_STIBP ) && !guest_cpuid_has (vcpu,X86_FEATURE_AMD_IBRS ) && !guest_cpuid_has (vcpu,X86_FEATURE_AMD_SSBD ))return 1 ;
@@ -4310,6 +4312,8 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)break ;case MSR_IA32_SPEC_CTRL :if (!msr->host_initiated && + !guest_cpuid_has (vcpu,X86_FEATURE_SPEC_CTRL ) && + !guest_cpuid_has (vcpu,X86_FEATURE_AMD_STIBP ) && !guest_cpuid_has (vcpu,X86_FEATURE_AMD_IBRS ) && !guest_cpuid_has (vcpu,X86_FEATURE_AMD_SSBD ))return 1 ;
Signature · 1 line
1.8.3.1
Quoted 30 lines · Paolo Bonzini
Userspace that does not know about the
AMD_IBRSbit might still allow the guest to protect itself withMSR_IA32_SPEC_CTRLusing the IntelSPEC_CTRLbit. However,svm.cdisallows this and will cause a #GP in the guest when writing to the MSR. Fix this by loosening the test and allowing the Intel CPUID bit, and in fact allow theAMD_STIBPbit as well since it allows writing toMSR_IA32_SPEC_CTRLtoo.Reported-by Zhiyi Guo <[email protected]>Analyzed-by Dr. David Alan Gilbert <[email protected]>Analyzed-by Laszlo Ersek <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- arch/x86/kvm/svm.c | 4 ++++ 1 file changed, 4 insertions(+)arch/x86/kvm/svm.c +2
-0@@ -4225,6 +4225,8 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)break ;case MSR_IA32_SPEC_CTRL :if (!msr_info->host_initiated && + !guest_cpuid_has (vcpu,X86_FEATURE_SPEC_CTRL ) && + !guest_cpuid_has (vcpu,X86_FEATURE_AMD_STIBP ) && !guest_cpuid_has (vcpu,X86_FEATURE_AMD_IBRS ) && !guest_cpuid_has (vcpu,X86_FEATURE_AMD_SSBD ))return 1 ;
arch/x86/kvm/svm.c static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr) · line 4319
Quoted 8 lines
arch/x86/kvm/svm.c +2
-0@@ -4310,6 +4312,8 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)break ;case MSR_IA32_SPEC_CTRL :if (!msr->host_initiated && + !guest_cpuid_has (vcpu,X86_FEATURE_SPEC_CTRL ) && + !guest_cpuid_has (vcpu,X86_FEATURE_AMD_STIBP ) && !guest_cpuid_has (vcpu,X86_FEATURE_AMD_IBRS ) && !guest_cpuid_has (vcpu,X86_FEATURE_AMD_SSBD ))return 1 ;
but out of pure curiosity, why do we need these checks?
At least for the 'set' case right below them we have:
if (data & ~kvm_spec_ctrl_valid_bits(vcpu))
return 1;
so if guest will try using unsupported features it will #GP. So basically, these checks will only fire when reading/writing '0' and all features are missing, right? Do we care?
Signature · 1 line
Vitaly
Paolo Bonzini
maintainerQuoted 4 lines · Vitaly Kuznetsov
Reviewed-by Vitaly Kuznetsov <[email protected]>but out of pure curiosity, why do we need these checks?
Quoted 8 lines
At least for the 'set' case right below them we have:
if (data & ~kvm_spec_ctrl_valid_bits(vcpu))
return 1;so if guest will try using unsupported features it will #GP. So basically, these checks will only fire when reading/writing '0' and all features are missing, right? Do we care?
Probably not... I just wanted the smallest possible change in semantics for this patch, and the rest can be done equally on Intel and AMD.
Paolo