/** * kvm_arch_init_vm - initializes a VM data structure * @kvm: pointer to the KVM struct */ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) { int ret = 0; if (type) return -EINVAL; ret = kvm_alloc_stage2_pgd(kvm); if (ret) goto out_fail_alloc; ret = create_hyp_mappings(kvm, kvm + 1); if (ret) goto out_free_stage2_pgd; kvm_vgic_early_init(kvm); kvm_timer_init(kvm); /* Mark the initial VMID generation invalid */ kvm->arch.vmid_gen = 0; /* The maximum number of VCPUs is limited by the host's GIC model */ kvm->arch.max_vcpus = kvm_vgic_get_max_vcpus(); return ret; out_free_stage2_pgd: kvm_free_stage2_pgd(kvm); out_fail_alloc: return ret; }
/** * kvm_arch_init_vm - 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); /* Mark the initial VMID generation invalid */ kvm->arch.vmid_gen = 0; /* The maximum number of VCPUs is limited by the host's GIC model */ 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; }