Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 93860
b: refs/heads/master
c: d39f13b
h: refs/heads/master
v: v3
  • Loading branch information
Izik Eidus authored and Avi Kivity committed Apr 27, 2008
1 parent 1d04720 commit c41cd00
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 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: 9c20456a32ce9e82ccda55e12c10016b181d85e5
refs/heads/master: d39f13b0da7fa7f705fbe6c80995205d0380bc7a
4 changes: 4 additions & 0 deletions trunk/include/linux/kvm_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ struct kvm {
struct kvm_io_bus pio_bus;
struct kvm_vm_stat stat;
struct kvm_arch arch;
atomic_t users_count;
};

/* The guest did something we don't support. */
Expand All @@ -140,6 +141,9 @@ int kvm_init(void *opaque, unsigned int vcpu_size,
struct module *module);
void kvm_exit(void);

void kvm_get_kvm(struct kvm *kvm);
void kvm_put_kvm(struct kvm *kvm);

#define HPA_MSB ((sizeof(hpa_t) * 8) - 1)
#define HPA_ERR_MASK ((hpa_t)1 << HPA_MSB)
static inline int is_error_hpa(hpa_t hpa) { return hpa >> HPA_MSB; }
Expand Down
17 changes: 16 additions & 1 deletion trunk/virt/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ static struct kvm *kvm_create_vm(void)
mutex_init(&kvm->lock);
kvm_io_bus_init(&kvm->mmio_bus);
init_rwsem(&kvm->slots_lock);
atomic_set(&kvm->users_count, 1);
spin_lock(&kvm_lock);
list_add(&kvm->vm_list, &vm_list);
spin_unlock(&kvm_lock);
Expand Down Expand Up @@ -242,11 +243,25 @@ static void kvm_destroy_vm(struct kvm *kvm)
mmdrop(mm);
}

void kvm_get_kvm(struct kvm *kvm)
{
atomic_inc(&kvm->users_count);
}
EXPORT_SYMBOL_GPL(kvm_get_kvm);

void kvm_put_kvm(struct kvm *kvm)
{
if (atomic_dec_and_test(&kvm->users_count))
kvm_destroy_vm(kvm);
}
EXPORT_SYMBOL_GPL(kvm_put_kvm);


static int kvm_vm_release(struct inode *inode, struct file *filp)
{
struct kvm *kvm = filp->private_data;

kvm_destroy_vm(kvm);
kvm_put_kvm(kvm);
return 0;
}

Expand Down

0 comments on commit c41cd00

Please sign in to comment.