KVM: Move kvm_vm_ioctl_create_vcpu() around

In preparation of some hacking.

Signed-off-by: Avi Kivity <avi@qumranet.com>

+51 -51
+51 -51
drivers/kvm/kvm_main.c
··· 599 599 EXPORT_SYMBOL_GPL(fx_init); 600 600 601 601 /* 602 - * Creates some virtual cpus. Good luck creating more than one. 603 - */ 604 - static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, int n) 605 - { 606 - int r; 607 - struct kvm_vcpu *vcpu; 608 - 609 - r = -EINVAL; 610 - if (!valid_vcpu(n)) 611 - goto out; 612 - 613 - vcpu = &kvm->vcpus[n]; 614 - 615 - mutex_lock(&vcpu->mutex); 616 - 617 - if (vcpu->vmcs) { 618 - mutex_unlock(&vcpu->mutex); 619 - return -EEXIST; 620 - } 621 - 622 - vcpu->host_fx_image = (char*)ALIGN((hva_t)vcpu->fx_buf, 623 - FX_IMAGE_ALIGN); 624 - vcpu->guest_fx_image = vcpu->host_fx_image + FX_IMAGE_SIZE; 625 - 626 - r = kvm_arch_ops->vcpu_create(vcpu); 627 - if (r < 0) 628 - goto out_free_vcpus; 629 - 630 - r = kvm_mmu_create(vcpu); 631 - if (r < 0) 632 - goto out_free_vcpus; 633 - 634 - kvm_arch_ops->vcpu_load(vcpu); 635 - r = kvm_mmu_setup(vcpu); 636 - if (r >= 0) 637 - r = kvm_arch_ops->vcpu_setup(vcpu); 638 - vcpu_put(vcpu); 639 - 640 - if (r < 0) 641 - goto out_free_vcpus; 642 - 643 - return 0; 644 - 645 - out_free_vcpus: 646 - kvm_free_vcpu(vcpu); 647 - mutex_unlock(&vcpu->mutex); 648 - out: 649 - return r; 650 - } 651 - 652 - /* 653 602 * Allocate some memory and give it an address in the guest physical address 654 603 * space. 655 604 * ··· 1910 1961 1911 1962 vcpu_put(vcpu); 1912 1963 1964 + return r; 1965 + } 1966 + 1967 + /* 1968 + * Creates some virtual cpus. Good luck creating more than one. 1969 + */ 1970 + static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, int n) 1971 + { 1972 + int r; 1973 + struct kvm_vcpu *vcpu; 1974 + 1975 + r = -EINVAL; 1976 + if (!valid_vcpu(n)) 1977 + goto out; 1978 + 1979 + vcpu = &kvm->vcpus[n]; 1980 + 1981 + mutex_lock(&vcpu->mutex); 1982 + 1983 + if (vcpu->vmcs) { 1984 + mutex_unlock(&vcpu->mutex); 1985 + return -EEXIST; 1986 + } 1987 + 1988 + vcpu->host_fx_image = (char*)ALIGN((hva_t)vcpu->fx_buf, 1989 + FX_IMAGE_ALIGN); 1990 + vcpu->guest_fx_image = vcpu->host_fx_image + FX_IMAGE_SIZE; 1991 + 1992 + r = kvm_arch_ops->vcpu_create(vcpu); 1993 + if (r < 0) 1994 + goto out_free_vcpus; 1995 + 1996 + r = kvm_mmu_create(vcpu); 1997 + if (r < 0) 1998 + goto out_free_vcpus; 1999 + 2000 + kvm_arch_ops->vcpu_load(vcpu); 2001 + r = kvm_mmu_setup(vcpu); 2002 + if (r >= 0) 2003 + r = kvm_arch_ops->vcpu_setup(vcpu); 2004 + vcpu_put(vcpu); 2005 + 2006 + if (r < 0) 2007 + goto out_free_vcpus; 2008 + 2009 + return 0; 2010 + 2011 + out_free_vcpus: 2012 + kvm_free_vcpu(vcpu); 2013 + mutex_unlock(&vcpu->mutex); 2014 + out: 1913 2015 return r; 1914 2016 } 1915 2017