| From 941dc4a1c5506fa1694337d6cf0cec9749982c95 Mon Sep 17 00:00:00 2001 |
| From: Aaron Lewis <aaronlewis@google.com> |
| Date: Mon, 21 Oct 2019 16:30:20 -0700 |
| Subject: [PATCH] KVM: x86: Introduce vcpu->arch.xsaves_enabled |
| |
| commit 7204160eb7809345d10c983d9d1dfbd98060a56d upstream. |
| |
| 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> |
| Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com> |
| |
| diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h |
| index 83350f210be9..a5a4e460bad5 100644 |
| --- a/arch/x86/include/asm/kvm_host.h |
| +++ b/arch/x86/include/asm/kvm_host.h |
| @@ -570,6 +570,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; |
| diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c |
| index 68f63d9684a6..450a72bbf231 100644 |
| --- a/arch/x86/kvm/svm.c |
| +++ b/arch/x86/kvm/svm.c |
| @@ -5905,6 +5905,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); |
| |
| diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c |
| index e56451e20768..8d5f275295f3 100644 |
| --- a/arch/x86/kvm/vmx/vmx.c |
| +++ b/arch/x86/kvm/vmx/vmx.c |
| @@ -3908,6 +3908,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; |
| |
| @@ -6953,6 +6955,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->secondary_exec_control); |
| -- |
| 2.7.4 |
| |