Re: [PATCH v2 08/13] KVM: x86: Dynamically allocate per-vCPU emulation context

From: Sean Christopherson
Date: Tue Mar 03 2020 - 11:52:06 EST


On Wed, Feb 26, 2020 at 06:29:56PM +0100, Vitaly Kuznetsov wrote:
> Sean Christopherson <sean.j.christopherson@xxxxxxxxx> writes:
> > @@ -9409,6 +9451,9 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
> >
> > kvm_x86_ops->vcpu_free(vcpu);
> >
> > + if (vcpu->arch.emulate_ctxt)
> > + kmem_cache_free(x86_emulator_cache, vcpu->arch.emulate_ctxt);
>
> Checking for NULL here seems superfluous as we create the context in
> kvm_arch_vcpu_create() unconditionally. I'd suggest we move the check to
> "[PATCH v2 12/13] KVM: x86: Add variable to control existence of
> emulator" where 'enable_emulator' global is added.

Ya, checking here is premature.

> > +
> > free_cpumask_var(vcpu->arch.wbinvd_dirty_mask);
> > kmem_cache_free(x86_fpu_cache, vcpu->arch.user_fpu);
> > kmem_cache_free(x86_fpu_cache, vcpu->arch.guest_fpu);
>
> --
> Vitaly
>