]> 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 3416f8a31f63c978f59c2a5ac22d70baea12f860..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)
@@ -408,7 +410,7 @@ static void kvm_mmu_notifier_release(struct mmu_notifier *mn,
        int idx;
 
        idx = srcu_read_lock(&kvm->srcu);
-       kvm_arch_flush_shadow(kvm);
+       kvm_arch_flush_shadow_all(kvm);
        srcu_read_unlock(&kvm->srcu, idx);
 }
 
@@ -582,7 +584,7 @@ static void kvm_destroy_vm(struct kvm *kvm)
 #if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER)
        mmu_notifier_unregister(&kvm->mmu_notifier, kvm->mm);
 #else
-       kvm_arch_flush_shadow(kvm);
+       kvm_arch_flush_shadow_all(kvm);
 #endif
        kvm_arch_destroy_vm(kvm);
        kvm_free_physmem(kvm);
@@ -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,14 +809,14 @@ 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)
                 *      - kvm_is_visible_gfn (mmu_check_roots)
                 */
-               kvm_arch_flush_shadow(kvm);
+               kvm_arch_flush_shadow_memslot(kvm, slot);
                kfree(old_memslots);
        }
 
@@ -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(kvm);
-
        kvm_free_physmem_slot(&old, &new);
        kfree(old_memslots);
 
@@ -984,12 +979,6 @@ static bool memslot_is_readonly(struct kvm_memory_slot *slot)
        return slot->flags & KVM_MEM_READONLY;
 }
 
-static unsigned long __gfn_to_hva_memslot(struct kvm_memory_slot *slot,
-                                         gfn_t gfn)
-{
-       return slot->userspace_addr + (gfn - slot->base_gfn) * PAGE_SIZE;
-}
-
 static unsigned long __gfn_to_hva_many(struct kvm_memory_slot *slot, gfn_t gfn,
                                       gfn_t *nr_pages, bool write)
 {
@@ -1904,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;