[lkml]   [2019]   [Jul]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[RFC PATCH 18/21] KVM: x86: Invoke kvm_x86_ops->cpuid_update() after kvm_update_cpuid()
VMX's virtualization of SGX adds a lovely dependency on the guest's
supported xcr0, which is calculated in kvm_update_cpuid(). VMX must
toggled its interception of SGX instructions based on the supported
xcr0, i.e. kvm_x86_ops->cpuid_update() is certainly the correct
location for the dependent code.

kvm_update_cpuid() was originally added by commit 2acf923e38fb ("KVM:
VMX: Enable XSAVE/XRSTOR for guest"). There is no indication that its
placement after kvm_x86_ops->cpuid_update() was anything more than a
"new function at the end" decision.

Inspection of the current code reveals no dependency on kvm_x86_ops's
cpuid_update() in kvm_update_cpuid() or any of its helpers.

- SVM's sole update is to conditionally clear X86_FEATURE_X2APIC.
X86_FEATURE_X2APIC is only consumed by kvm_apic_set_state(), which
is already called immediately prior to kvm_x86_ops->cpuid_update().

- VMX updates only nested VMX MSRs, allowed FEATURE_CONTROL bits,
and VMCS fields, e.g. secondary execution controls, none of which
should bleed back into kvm_update_cpuid() barring an egregious
dependency bug somewhere else.

Signed-off-by: Sean Christopherson <>
arch/x86/kvm/cpuid.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 70e488951f25..4c235af5318c 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -222,8 +222,9 @@ int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu,
vcpu->arch.cpuid_nent = cpuid->nent;
- kvm_x86_ops->cpuid_update(vcpu);
r = kvm_update_cpuid(vcpu);
+ if (!r)
+ kvm_x86_ops->cpuid_update(vcpu);

@@ -245,8 +246,9 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
goto out;
vcpu->arch.cpuid_nent = cpuid->nent;
- kvm_x86_ops->cpuid_update(vcpu);
r = kvm_update_cpuid(vcpu);
+ if (!r)
+ kvm_x86_ops->cpuid_update(vcpu);
return r;
 \ /
  Last update: 2019-07-27 07:54    [W:0.131 / U:2.484 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site