diff options
Diffstat (limited to 'drivers/kvm/kvm_main.c')
-rw-r--r-- | drivers/kvm/kvm_main.c | 42 |
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 | ||
157 | static struct kvm *kvm_create_vm(void) | 157 | static 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); |
170 | out: | ||
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 | ||
191 | static void kvm_free_physmem(struct kvm *kvm) | 191 | void 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 | ||
199 | static 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 | |||
206 | static 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 | |||
225 | static void kvm_destroy_vm(struct kvm *kvm) | 199 | static 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 | ||
239 | static int kvm_vm_release(struct inode *inode, struct file *filp) | 209 | static int kvm_vm_release(struct inode *inode, struct file *filp) |