Re: [PATCH v5 3/7] kvm: Make init_rmode_identity_map() return 0 on success.

tangchen
2014-09-11T10:26:00Z

On 09/11/2014 05:17 PM, Paolo Bonzini wrote:
> ......
> @@ -7645,7 +7642,7 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
> kvm->arch.ept_identity_map_addr =
> VMX_EPT_IDENTITY_PAGETABLE_ADDR;
> err = -ENOMEM;
> - if (!init_rmode_identity_map(kvm))
> + if (init_rmode_identity_map(kvm))
> Please add "< 0" here. I would also consider setting err to the return
> value of init_rmode_identity_map, and initializing it to -ENOMEM only
> after the "if".
>
I'd like to move err = -ENOMEM to the following place:

vmx_create_vcpu()
{
......
err = kvm_vcpu_init(&vmx->vcpu, kvm, id);
if (err)
goto free_vcpu;

err = -ENOMEM; ---------------------- move it here

vmx->guest_msrs = kmalloc(PAGE_SIZE, GFP_KERNEL);
....
vmx->loaded_vmcs->vmcs = alloc_vmcs();
....
}

So that it can be used to handle the next two memory allocation error.

Thanks.