KVM: x86: Fold fx_init() into kvm_arch_vcpu_create()
authorSean Christopherson <seanjc@google.com>
Tue, 21 Sep 2021 00:02:59 +0000 (17:02 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 30 Sep 2021 08:27:06 +0000 (04:27 -0400)
Move the few bits of relevant fx_init() code into kvm_arch_vcpu_create(),
dropping the superfluous check on vcpu->arch.guest_fpu that was blindly
and wrongly added by commit ed02b213098a ("KVM: SVM: Guest FPU state
save/restore not needed for SEV-ES guest").

Note, KVM currently allocates and then frees FPU state for SEV-ES guests,
rather than avoid the allocation in the first place.  While that approach
is inarguably inefficient and unnecessary, it's a cleanup for the future.

No functional change intended.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20210921000303.400537-7-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/x86.c

index da0d48d..1ab0caa 100644 (file)
@@ -10597,17 +10597,6 @@ static int sync_regs(struct kvm_vcpu *vcpu)
        return 0;
 }
 
-static void fx_init(struct kvm_vcpu *vcpu)
-{
-       if (!vcpu->arch.guest_fpu)
-               return;
-
-       fpstate_init(&vcpu->arch.guest_fpu->state);
-       if (boot_cpu_has(X86_FEATURE_XSAVES))
-               vcpu->arch.guest_fpu->state.xsave.header.xcomp_bv =
-                       host_xcr0 | XSTATE_COMPACTION_ENABLED;
-}
-
 void kvm_free_guest_fpu(struct kvm_vcpu *vcpu)
 {
        if (vcpu->arch.guest_fpu) {
@@ -10686,7 +10675,10 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
                pr_err("kvm: failed to allocate vcpu's fpu\n");
                goto free_user_fpu;
        }
-       fx_init(vcpu);
+       fpstate_init(&vcpu->arch.guest_fpu->state);
+       if (boot_cpu_has(X86_FEATURE_XSAVES))
+               vcpu->arch.guest_fpu->state.xsave.header.xcomp_bv =
+                       host_xcr0 | XSTATE_COMPACTION_ENABLED;
 
        vcpu->arch.maxphyaddr = cpuid_query_maxphyaddr(vcpu);
        vcpu->arch.reserved_gpa_bits = kvm_vcpu_reserved_gpa_bits_raw(vcpu);