]> Pileus Git - ~andy/linux/blobdiff - virt/kvm/kvm_main.c
KVM: make processes waiting on vcpu mutex killable
[~andy/linux] / virt / kvm / kvm_main.c
index a4bf05be5fea7fd23b6843ed0746c6fd0a9ef738..cc3f6dc506e43fea81b79e7c5fcb427c8be083da 100644 (file)
@@ -131,11 +131,12 @@ bool kvm_is_mmio_pfn(pfn_t pfn)
 /*
  * Switches to specified vcpu, until a matching vcpu_put()
  */
-void vcpu_load(struct kvm_vcpu *vcpu)
+int vcpu_load(struct kvm_vcpu *vcpu)
 {
        int cpu;
 
-       mutex_lock(&vcpu->mutex);
+       if (mutex_lock_killable(&vcpu->mutex))
+               return -EINTR;
        if (unlikely(vcpu->pid != current->pids[PIDTYPE_PID].pid)) {
                /* The thread running this VCPU changed. */
                struct pid *oldpid = vcpu->pid;
@@ -148,6 +149,7 @@ void vcpu_load(struct kvm_vcpu *vcpu)
        preempt_notifier_register(&vcpu->preempt_notifier);
        kvm_arch_vcpu_load(vcpu, cpu);
        put_cpu();
+       return 0;
 }
 
 void vcpu_put(struct kvm_vcpu *vcpu)
@@ -791,7 +793,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
                /* destroy any largepage mappings for dirty tracking */
        }
 
-       if (!npages) {
+       if (!npages || base_gfn != old.base_gfn) {
                struct kvm_memory_slot *slot;
 
                r = -ENOMEM;
@@ -807,8 +809,8 @@ int __kvm_set_memory_region(struct kvm *kvm,
                old_memslots = kvm->memslots;
                rcu_assign_pointer(kvm->memslots, slots);
                synchronize_srcu_expedited(&kvm->srcu);
-               /* From this point no new shadow pages pointing to a deleted
-                * memslot will be created.
+               /* From this point no new shadow pages pointing to a deleted,
+                * or moved, memslot will be created.
                 *
                 * validation of sp->gfn happens in:
                 *      - gfn_to_hva (kvm_read_guest, gfn_to_pfn)
@@ -849,13 +851,6 @@ int __kvm_set_memory_region(struct kvm *kvm,
 
        kvm_arch_commit_memory_region(kvm, mem, old, user_alloc);
 
-       /*
-        * If the new memory slot is created, we need to clear all
-        * mmio sptes.
-        */
-       if (npages && old.base_gfn != mem->guest_phys_addr >> PAGE_SHIFT)
-               kvm_arch_flush_shadow_all(kvm);
-
        kvm_free_physmem_slot(&old, &new);
        kfree(old_memslots);
 
@@ -1898,7 +1893,9 @@ static long kvm_vcpu_ioctl(struct file *filp,
 #endif
 
 
-       vcpu_load(vcpu);
+       r = vcpu_load(vcpu);
+       if (r)
+               return r;
        switch (ioctl) {
        case KVM_RUN:
                r = -EINVAL;