aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/kvm/kvm_main.c
diff options
context:
space:
mode:
authorZhang Xiantao <xiantao@vtsmp-build32.los-vmm.org>2007-11-18 05:43:45 -0500
committerAvi Kivity <avi@qumranet.com>2008-01-30 10:53:04 -0500
commitd19a9cd275b0fdc793d1bb8b644b7aad0517e4bc (patch)
tree5dba36f58295f165e4fd3380742875d1867266f5 /drivers/kvm/kvm_main.c
parenta16b043cc96db4a01abb337bef4a51cebcfcbb1b (diff)
KVM: Portability: Add two hooks to handle kvm_create and destroy vm
Add two arch hooks to handle kvm_create_vm and kvm destroy_vm. Now, just put io_bus init and destory in common. Signed-off-by: Zhang Xiantao <xiantao.zhang@intel.com> Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'drivers/kvm/kvm_main.c')
-rw-r--r--drivers/kvm/kvm_main.c42
1 files changed, 6 insertions, 36 deletions
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index e24489b409cf..bde3cf741892 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -156,18 +156,18 @@ EXPORT_SYMBOL_GPL(kvm_vcpu_uninit);
156 156
157static struct kvm *kvm_create_vm(void) 157static struct kvm *kvm_create_vm(void)
158{ 158{
159 struct kvm *kvm = kzalloc(sizeof(struct kvm), GFP_KERNEL); 159 struct kvm *kvm = kvm_arch_create_vm();
160 160
161 if (!kvm) 161 if (IS_ERR(kvm))
162 return ERR_PTR(-ENOMEM); 162 goto out;
163 163
164 kvm_io_bus_init(&kvm->pio_bus); 164 kvm_io_bus_init(&kvm->pio_bus);
165 mutex_init(&kvm->lock); 165 mutex_init(&kvm->lock);
166 INIT_LIST_HEAD(&kvm->active_mmu_pages);
167 kvm_io_bus_init(&kvm->mmio_bus); 166 kvm_io_bus_init(&kvm->mmio_bus);
168 spin_lock(&kvm_lock); 167 spin_lock(&kvm_lock);
169 list_add(&kvm->vm_list, &vm_list); 168 list_add(&kvm->vm_list, &vm_list);
170 spin_unlock(&kvm_lock); 169 spin_unlock(&kvm_lock);
170out:
171 return kvm; 171 return kvm;
172} 172}
173 173
@@ -188,7 +188,7 @@ static void kvm_free_physmem_slot(struct kvm_memory_slot *free,
188 free->rmap = NULL; 188 free->rmap = NULL;
189} 189}
190 190
191static void kvm_free_physmem(struct kvm *kvm) 191void kvm_free_physmem(struct kvm *kvm)
192{ 192{
193 int i; 193 int i;
194 194
@@ -196,32 +196,6 @@ static void kvm_free_physmem(struct kvm *kvm)
196 kvm_free_physmem_slot(&kvm->memslots[i], NULL); 196 kvm_free_physmem_slot(&kvm->memslots[i], NULL);
197} 197}
198 198
199static void kvm_unload_vcpu_mmu(struct kvm_vcpu *vcpu)
200{
201 vcpu_load(vcpu);
202 kvm_mmu_unload(vcpu);
203 vcpu_put(vcpu);
204}
205
206static void kvm_free_vcpus(struct kvm *kvm)
207{
208 unsigned int i;
209
210 /*
211 * Unpin any mmu pages first.
212 */
213 for (i = 0; i < KVM_MAX_VCPUS; ++i)
214 if (kvm->vcpus[i])
215 kvm_unload_vcpu_mmu(kvm->vcpus[i]);
216 for (i = 0; i < KVM_MAX_VCPUS; ++i) {
217 if (kvm->vcpus[i]) {
218 kvm_arch_vcpu_free(kvm->vcpus[i]);
219 kvm->vcpus[i] = NULL;
220 }
221 }
222
223}
224
225static void kvm_destroy_vm(struct kvm *kvm) 199static void kvm_destroy_vm(struct kvm *kvm)
226{ 200{
227 spin_lock(&kvm_lock); 201 spin_lock(&kvm_lock);
@@ -229,11 +203,7 @@ static void kvm_destroy_vm(struct kvm *kvm)
229 spin_unlock(&kvm_lock); 203 spin_unlock(&kvm_lock);
230 kvm_io_bus_destroy(&kvm->pio_bus); 204 kvm_io_bus_destroy(&kvm->pio_bus);
231 kvm_io_bus_destroy(&kvm->mmio_bus); 205 kvm_io_bus_destroy(&kvm->mmio_bus);
232 kfree(kvm->vpic); 206 kvm_arch_destroy_vm(kvm);
233 kfree(kvm->vioapic);
234 kvm_free_vcpus(kvm);
235 kvm_free_physmem(kvm);
236 kfree(kvm);
237} 207}
238 208
239static int kvm_vm_release(struct inode *inode, struct file *filp) 209static int kvm_vm_release(struct inode *inode, struct file *filp)