@@ -222,8 +222,9 @@ int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu,
vcpu->arch.cpuid_nent = cpuid->nent;
cpuid_fix_nx_cap(vcpu);
kvm_apic_set_version(vcpu);
- kvm_x86_ops->cpuid_update(vcpu);
r = kvm_update_cpuid(vcpu);
+ if (!r)
+ kvm_x86_ops->cpuid_update(vcpu);
out:
vfree(cpuid_entries);
@@ -245,8 +246,9 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
goto out;
vcpu->arch.cpuid_nent = cpuid->nent;
kvm_apic_set_version(vcpu);
- kvm_x86_ops->cpuid_update(vcpu);
r = kvm_update_cpuid(vcpu);
+ if (!r)
+ kvm_x86_ops->cpuid_update(vcpu);
out:
return r;
}
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 <sean.j.christopherson@intel.com> --- arch/x86/kvm/cpuid.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)