KVM: x86: Introduce vcpu->arch.xsaves_enabled
authorAaron Lewis <aaronlewis@google.com>
Mon, 21 Oct 2019 23:30:20 +0000 (16:30 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 22 Oct 2019 13:42:48 +0000 (15:42 +0200)
Cache whether XSAVES is enabled in the guest by adding xsaves_enabled to
vcpu->arch.

Reviewed-by: Jim Mattson <jmattson@google.com>
Signed-off-by: Aaron Lewis <aaronlewis@google.com>
Change-Id: If4638e0901c28a4494dad2e103e2c075e8ab5d68
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/svm.c
arch/x86/kvm/vmx/vmx.c

index 62f32a61c250dd2cd26318424e46520b4514aa0c..6f6b8886a8ebca9e8a53de12a51fb786fa0eea56 100644 (file)
@@ -560,6 +560,7 @@ struct kvm_vcpu_arch {
        u64 smbase;
        u64 smi_count;
        bool tpr_access_reporting;
+       bool xsaves_enabled;
        u64 ia32_xss;
        u64 microcode_version;
        u64 arch_capabilities;
index e479ea9bc9da25801a03805a8b3d0552b386ba9c..cf224963e7d1b57377635075dd82a650416f836d 100644 (file)
@@ -5895,6 +5895,9 @@ static void svm_cpuid_update(struct kvm_vcpu *vcpu)
 {
        struct vcpu_svm *svm = to_svm(vcpu);
 
+       vcpu->arch.xsaves_enabled = guest_cpuid_has(vcpu, X86_FEATURE_XSAVE) &&
+                                   boot_cpu_has(X86_FEATURE_XSAVES);
+
        /* Update nrips enabled cache */
        svm->nrips_enabled = !!guest_cpuid_has(&svm->vcpu, X86_FEATURE_NRIPS);
 
index 4211f72a1a01effa4813455886c7432611652128..751765532305efc160118ce3fe3a3bd63dd9ce47 100644 (file)
@@ -4050,6 +4050,8 @@ static void vmx_compute_secondary_exec_control(struct vcpu_vmx *vmx)
                        guest_cpuid_has(vcpu, X86_FEATURE_XSAVE) &&
                        guest_cpuid_has(vcpu, X86_FEATURE_XSAVES);
 
+               vcpu->arch.xsaves_enabled = xsaves_enabled;
+
                if (!xsaves_enabled)
                        exec_control &= ~SECONDARY_EXEC_XSAVES;
 
@@ -7089,6 +7091,9 @@ static void vmx_cpuid_update(struct kvm_vcpu *vcpu)
 {
        struct vcpu_vmx *vmx = to_vmx(vcpu);
 
+       /* xsaves_enabled is recomputed in vmx_compute_secondary_exec_control(). */
+       vcpu->arch.xsaves_enabled = false;
+
        if (cpu_has_secondary_exec_ctrls()) {
                vmx_compute_secondary_exec_control(vmx);
                vmcs_set_secondary_exec_control(vmx);