aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/kvm/kvm_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/kvm/kvm_main.c')
-rw-r--r--drivers/kvm/kvm_main.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index aec6b67cfebb..0efd759e585f 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -165,6 +165,8 @@ static struct kvm *kvm_create_vm(void)
165 if (IS_ERR(kvm)) 165 if (IS_ERR(kvm))
166 goto out; 166 goto out;
167 167
168 kvm->mm = current->mm;
169 atomic_inc(&kvm->mm->mm_count);
168 kvm_io_bus_init(&kvm->pio_bus); 170 kvm_io_bus_init(&kvm->pio_bus);
169 mutex_init(&kvm->lock); 171 mutex_init(&kvm->lock);
170 kvm_io_bus_init(&kvm->mmio_bus); 172 kvm_io_bus_init(&kvm->mmio_bus);
@@ -202,12 +204,15 @@ void kvm_free_physmem(struct kvm *kvm)
202 204
203static void kvm_destroy_vm(struct kvm *kvm) 205static void kvm_destroy_vm(struct kvm *kvm)
204{ 206{
207 struct mm_struct *mm = kvm->mm;
208
205 spin_lock(&kvm_lock); 209 spin_lock(&kvm_lock);
206 list_del(&kvm->vm_list); 210 list_del(&kvm->vm_list);
207 spin_unlock(&kvm_lock); 211 spin_unlock(&kvm_lock);
208 kvm_io_bus_destroy(&kvm->pio_bus); 212 kvm_io_bus_destroy(&kvm->pio_bus);
209 kvm_io_bus_destroy(&kvm->mmio_bus); 213 kvm_io_bus_destroy(&kvm->mmio_bus);
210 kvm_arch_destroy_vm(kvm); 214 kvm_arch_destroy_vm(kvm);
215 mmdrop(mm);
211} 216}
212 217
213static int kvm_vm_release(struct inode *inode, struct file *filp) 218static int kvm_vm_release(struct inode *inode, struct file *filp)
@@ -818,6 +823,8 @@ static long kvm_vcpu_ioctl(struct file *filp,
818 void __user *argp = (void __user *)arg; 823 void __user *argp = (void __user *)arg;
819 int r; 824 int r;
820 825
826 if (vcpu->kvm->mm != current->mm)
827 return -EIO;
821 switch (ioctl) { 828 switch (ioctl) {
822 case KVM_RUN: 829 case KVM_RUN:
823 r = -EINVAL; 830 r = -EINVAL;
@@ -976,6 +983,8 @@ static long kvm_vm_ioctl(struct file *filp,
976 void __user *argp = (void __user *)arg; 983 void __user *argp = (void __user *)arg;
977 int r; 984 int r;
978 985
986 if (kvm->mm != current->mm)
987 return -EIO;
979 switch (ioctl) { 988 switch (ioctl) {
980 case KVM_CREATE_VCPU: 989 case KVM_CREATE_VCPU:
981 r = kvm_vm_ioctl_create_vcpu(kvm, arg); 990 r = kvm_vm_ioctl_create_vcpu(kvm, arg);