diff options
author | Zhang Xiantao <xiantao@vtsmp-build32.los-vmm.org> | 2007-11-18 05:43:45 -0500 |
---|---|---|
committer | Avi Kivity <avi@qumranet.com> | 2008-01-30 10:53:04 -0500 |
commit | d19a9cd275b0fdc793d1bb8b644b7aad0517e4bc (patch) | |
tree | 5dba36f58295f165e4fd3380742875d1867266f5 | |
parent | a16b043cc96db4a01abb337bef4a51cebcfcbb1b (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>
-rw-r--r-- | drivers/kvm/kvm.h | 4 | ||||
-rw-r--r-- | drivers/kvm/kvm_main.c | 42 | ||||
-rw-r--r-- | drivers/kvm/x86.c | 47 |
3 files changed, 57 insertions, 36 deletions
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h index c4ad66bb5e08..59e001c3ff09 100644 --- a/drivers/kvm/kvm.h +++ b/drivers/kvm/kvm.h | |||
@@ -674,6 +674,10 @@ int kvm_arch_hardware_setup(void); | |||
674 | void kvm_arch_hardware_unsetup(void); | 674 | void kvm_arch_hardware_unsetup(void); |
675 | void kvm_arch_check_processor_compat(void *rtn); | 675 | void kvm_arch_check_processor_compat(void *rtn); |
676 | 676 | ||
677 | void kvm_free_physmem(struct kvm *kvm); | ||
678 | |||
679 | struct kvm *kvm_arch_create_vm(void); | ||
680 | void kvm_arch_destroy_vm(struct kvm *kvm); | ||
677 | 681 | ||
678 | static inline void kvm_guest_enter(void) | 682 | static inline void kvm_guest_enter(void) |
679 | { | 683 | { |
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) |
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c index abb7beeb8f54..b7c72ac36735 100644 --- a/drivers/kvm/x86.c +++ b/drivers/kvm/x86.c | |||
@@ -2543,3 +2543,50 @@ void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu) | |||
2543 | kvm_mmu_destroy(vcpu); | 2543 | kvm_mmu_destroy(vcpu); |
2544 | free_page((unsigned long)vcpu->pio_data); | 2544 | free_page((unsigned long)vcpu->pio_data); |
2545 | } | 2545 | } |
2546 | |||
2547 | struct kvm *kvm_arch_create_vm(void) | ||
2548 | { | ||
2549 | struct kvm *kvm = kzalloc(sizeof(struct kvm), GFP_KERNEL); | ||
2550 | |||
2551 | if (!kvm) | ||
2552 | return ERR_PTR(-ENOMEM); | ||
2553 | |||
2554 | INIT_LIST_HEAD(&kvm->active_mmu_pages); | ||
2555 | |||
2556 | return kvm; | ||
2557 | } | ||
2558 | |||
2559 | static void kvm_unload_vcpu_mmu(struct kvm_vcpu *vcpu) | ||
2560 | { | ||
2561 | vcpu_load(vcpu); | ||
2562 | kvm_mmu_unload(vcpu); | ||
2563 | vcpu_put(vcpu); | ||
2564 | } | ||
2565 | |||
2566 | static void kvm_free_vcpus(struct kvm *kvm) | ||
2567 | { | ||
2568 | unsigned int i; | ||
2569 | |||
2570 | /* | ||
2571 | * Unpin any mmu pages first. | ||
2572 | */ | ||
2573 | for (i = 0; i < KVM_MAX_VCPUS; ++i) | ||
2574 | if (kvm->vcpus[i]) | ||
2575 | kvm_unload_vcpu_mmu(kvm->vcpus[i]); | ||
2576 | for (i = 0; i < KVM_MAX_VCPUS; ++i) { | ||
2577 | if (kvm->vcpus[i]) { | ||
2578 | kvm_arch_vcpu_free(kvm->vcpus[i]); | ||
2579 | kvm->vcpus[i] = NULL; | ||
2580 | } | ||
2581 | } | ||
2582 | |||
2583 | } | ||
2584 | |||
2585 | void kvm_arch_destroy_vm(struct kvm *kvm) | ||
2586 | { | ||
2587 | kfree(kvm->vpic); | ||
2588 | kfree(kvm->vioapic); | ||
2589 | kvm_free_vcpus(kvm); | ||
2590 | kvm_free_physmem(kvm); | ||
2591 | kfree(kvm); | ||
2592 | } | ||