Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 80730
b: refs/heads/master
c: d19a9cd
h: refs/heads/master
v: v3
  • Loading branch information
Zhang Xiantao authored and Avi Kivity committed Jan 30, 2008
1 parent c349a27 commit c189b91
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 37 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: a16b043cc96db4a01abb337bef4a51cebcfcbb1b
refs/heads/master: d19a9cd275b0fdc793d1bb8b644b7aad0517e4bc
4 changes: 4 additions & 0 deletions trunk/drivers/kvm/kvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,10 @@ int kvm_arch_hardware_setup(void);
void kvm_arch_hardware_unsetup(void);
void kvm_arch_check_processor_compat(void *rtn);

void kvm_free_physmem(struct kvm *kvm);

struct kvm *kvm_arch_create_vm(void);
void kvm_arch_destroy_vm(struct kvm *kvm);

static inline void kvm_guest_enter(void)
{
Expand Down
42 changes: 6 additions & 36 deletions trunk/drivers/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,18 @@ EXPORT_SYMBOL_GPL(kvm_vcpu_uninit);

static struct kvm *kvm_create_vm(void)
{
struct kvm *kvm = kzalloc(sizeof(struct kvm), GFP_KERNEL);
struct kvm *kvm = kvm_arch_create_vm();

if (!kvm)
return ERR_PTR(-ENOMEM);
if (IS_ERR(kvm))
goto out;

kvm_io_bus_init(&kvm->pio_bus);
mutex_init(&kvm->lock);
INIT_LIST_HEAD(&kvm->active_mmu_pages);
kvm_io_bus_init(&kvm->mmio_bus);
spin_lock(&kvm_lock);
list_add(&kvm->vm_list, &vm_list);
spin_unlock(&kvm_lock);
out:
return kvm;
}

Expand All @@ -188,52 +188,22 @@ static void kvm_free_physmem_slot(struct kvm_memory_slot *free,
free->rmap = NULL;
}

static void kvm_free_physmem(struct kvm *kvm)
void kvm_free_physmem(struct kvm *kvm)
{
int i;

for (i = 0; i < kvm->nmemslots; ++i)
kvm_free_physmem_slot(&kvm->memslots[i], NULL);
}

static void kvm_unload_vcpu_mmu(struct kvm_vcpu *vcpu)
{
vcpu_load(vcpu);
kvm_mmu_unload(vcpu);
vcpu_put(vcpu);
}

static void kvm_free_vcpus(struct kvm *kvm)
{
unsigned int i;

/*
* Unpin any mmu pages first.
*/
for (i = 0; i < KVM_MAX_VCPUS; ++i)
if (kvm->vcpus[i])
kvm_unload_vcpu_mmu(kvm->vcpus[i]);
for (i = 0; i < KVM_MAX_VCPUS; ++i) {
if (kvm->vcpus[i]) {
kvm_arch_vcpu_free(kvm->vcpus[i]);
kvm->vcpus[i] = NULL;
}
}

}

static void kvm_destroy_vm(struct kvm *kvm)
{
spin_lock(&kvm_lock);
list_del(&kvm->vm_list);
spin_unlock(&kvm_lock);
kvm_io_bus_destroy(&kvm->pio_bus);
kvm_io_bus_destroy(&kvm->mmio_bus);
kfree(kvm->vpic);
kfree(kvm->vioapic);
kvm_free_vcpus(kvm);
kvm_free_physmem(kvm);
kfree(kvm);
kvm_arch_destroy_vm(kvm);
}

static int kvm_vm_release(struct inode *inode, struct file *filp)
Expand Down
47 changes: 47 additions & 0 deletions trunk/drivers/kvm/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -2543,3 +2543,50 @@ void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu)
kvm_mmu_destroy(vcpu);
free_page((unsigned long)vcpu->pio_data);
}

struct kvm *kvm_arch_create_vm(void)
{
struct kvm *kvm = kzalloc(sizeof(struct kvm), GFP_KERNEL);

if (!kvm)
return ERR_PTR(-ENOMEM);

INIT_LIST_HEAD(&kvm->active_mmu_pages);

return kvm;
}

static void kvm_unload_vcpu_mmu(struct kvm_vcpu *vcpu)
{
vcpu_load(vcpu);
kvm_mmu_unload(vcpu);
vcpu_put(vcpu);
}

static void kvm_free_vcpus(struct kvm *kvm)
{
unsigned int i;

/*
* Unpin any mmu pages first.
*/
for (i = 0; i < KVM_MAX_VCPUS; ++i)
if (kvm->vcpus[i])
kvm_unload_vcpu_mmu(kvm->vcpus[i]);
for (i = 0; i < KVM_MAX_VCPUS; ++i) {
if (kvm->vcpus[i]) {
kvm_arch_vcpu_free(kvm->vcpus[i]);
kvm->vcpus[i] = NULL;
}
}

}

void kvm_arch_destroy_vm(struct kvm *kvm)
{
kfree(kvm->vpic);
kfree(kvm->vioapic);
kvm_free_vcpus(kvm);
kvm_free_physmem(kvm);
kfree(kvm);
}

0 comments on commit c189b91

Please sign in to comment.