linux/virt/kvm/arm/arm.c
/**
 * kvm_arch_init_vm - initializes a VM data structure
 * @kvm:	pointer to the KVM struct
 */
initializes a VM data structure
@kvm:        pointer to the KVM struct
initializes a VM data structure @kvm : pointer to the KVM struct
int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
{
	int ret, cpu;
	if (type)
		return -EINVAL;
	kvm->arch.last_vcpu_ran = alloc_percpu(typeof(*kvm->arch.last_vcpu_ran));
	if (!kvm->arch.last_vcpu_ran)
		return -ENOMEM;
	for_each_possible_cpu(cpu)
		*per_cpu_ptr(kvm->arch.last_vcpu_ran, cpu) = -1;
	ret = kvm_alloc_stage2_pgd(kvm);
	if (ret)
		goto out_fail_alloc;
	ret = create_hyp_mappings(kvm, kvm + 1, PAGE_HYP);
	if (ret)
		goto out_free_stage2_pgd;
	kvm_vgic_early_init(kvm);
	kvm->arch.vmid_gen = 0;
	kvm->arch.max_vcpus = vgic_present ?
				kvm_vgic_get_max_vcpus() : KVM_MAX_VCPUS;
	return ret;
out_free_stage2_pgd:
	kvm_free_stage2_pgd(kvm);
out_fail_alloc:
	free_percpu(kvm->arch.last_vcpu_ran);
	kvm->arch.last_vcpu_ran = NULL;
	return ret;
}
int kvm_arch_init_vm ( struct kvm * kvm , unsigned long type ) { int ret , cpu ; if ( type ) return - EINVAL ; kvm -> arch . last_vcpu_ran = alloc_percpu ( typeof ( * kvm -> arch . last_vcpu_ran ) ) ; if ( ! kvm -> arch . last_vcpu_ran ) return - ENOMEM ; for_each_possible_cpu ( cpu ) * per_cpu_ptr ( kvm -> arch . last_vcpu_ran , cpu ) = -1 ; ret = kvm_alloc_stage2_pgd ( kvm ) ; if ( ret ) goto out_fail_alloc ; ret = create_hyp_mappings ( kvm , kvm + 1 , PAGE_HYP ) ; if ( ret ) goto out_free_stage2_pgd ; kvm_vgic_early_init ( kvm ) ; kvm -> arch . vmid_gen = 0 ; kvm -> arch . max_vcpus = vgic_present ? kvm_vgic_get_max_vcpus ( ) : KVM_MAX_VCPUS ; return ret ; out_free_stage2_pgd : kvm_free_stage2_pgd ( kvm ) ; out_fail_alloc : free_percpu ( kvm -> arch . last_vcpu_ran ) ; kvm -> arch . last_vcpu_ran = NULL ; return ret ; }
kvm_arch_init_vm - initializes a VM data structure
 @kvm:        pointer to the KVM struct
kvm_arch_init_vm - initializes a VM data structure @kvm : pointer to the KVM struct
/* Mark the initial VMID generation invalid */ /* The maximum number of VCPUs is limited by the host's GIC model */