KVM: Keep an upper bound of initialized vcpus
authorAvi Kivity <avi@qumranet.com>
Thu, 7 Jun 2007 16:11:53 +0000 (19:11 +0300)
committerAvi Kivity <avi@qumranet.com>
Mon, 16 Jul 2007 09:05:46 +0000 (12:05 +0300)
That way, we don't need to loop for KVM_MAX_VCPUS for a single vcpu
vm.

Signed-off-by: Avi Kivity <avi@qumranet.com>
drivers/kvm/kvm.h
drivers/kvm/kvm_main.c

index d49b16cae27aa18939b196ce41e46d19dfc1dc82..528a56b1790e1d20836cc196ee6b169044e0c60f 100644 (file)
@@ -379,6 +379,7 @@ struct kvm {
        struct list_head active_mmu_pages;
        int n_free_mmu_pages;
        struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES];
+       int nvcpus;
        struct kvm_vcpu vcpus[KVM_MAX_VCPUS];
        int memory_config_version;
        int busy;
index 556416962541e50a141cbab85dc932a379d6e5c4..4e1a017f3db7245e0e2e050c13cfa36bcc070a07 100644 (file)
@@ -2391,6 +2391,11 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, int n)
        if (r < 0)
                goto out_free_vcpus;
 
+       spin_lock(&kvm_lock);
+       if (n >= kvm->nvcpus)
+               kvm->nvcpus = n + 1;
+       spin_unlock(&kvm_lock);
+
        return r;
 
 out_free_vcpus: