KVM: make make_all_cpus_request() lockless
[platform/adaptation/renesas_rcar/renesas_kernel.git] / virt / kvm / kvm_main.c
index f29abeb..4856a7d 100644 (file)
@@ -165,13 +165,16 @@ static bool make_all_cpus_request(struct kvm *kvm, unsigned int req)
 
        zalloc_cpumask_var(&cpus, GFP_ATOMIC);
 
-       raw_spin_lock(&kvm->requests_lock);
-       me = smp_processor_id();
+       me = get_cpu();
        kvm_for_each_vcpu(i, vcpu, kvm) {
-               if (kvm_make_check_request(req, vcpu))
-                       continue;
+               kvm_make_request(req, vcpu);
                cpu = vcpu->cpu;
-               if (cpus != NULL && cpu != -1 && cpu != me)
+
+               /* Set ->requests bit before we read ->mode */
+               smp_mb();
+
+               if (cpus != NULL && cpu != -1 && cpu != me &&
+                     kvm_vcpu_exiting_guest_mode(vcpu) != OUTSIDE_GUEST_MODE)
                        cpumask_set_cpu(cpu, cpus);
        }
        if (unlikely(cpus == NULL))
@@ -180,7 +183,7 @@ static bool make_all_cpus_request(struct kvm *kvm, unsigned int req)
                smp_call_function_many(cpus, ack_flush, NULL, 1);
        else
                called = false;
-       raw_spin_unlock(&kvm->requests_lock);
+       put_cpu();
        free_cpumask_var(cpus);
        return called;
 }
@@ -463,7 +466,6 @@ static struct kvm *kvm_create_vm(void)
        kvm->mm = current->mm;
        atomic_inc(&kvm->mm->mm_count);
        spin_lock_init(&kvm->mmu_lock);
-       raw_spin_lock_init(&kvm->requests_lock);
        kvm_eventfd_init(kvm);
        mutex_init(&kvm->lock);
        mutex_init(&kvm->irq_lock);
@@ -588,6 +590,7 @@ static int kvm_vm_release(struct inode *inode, struct file *filp)
        return 0;
 }
 
+#ifndef CONFIG_S390
 /*
  * Allocation size is twice as large as the actual dirty bitmap size.
  * This makes it possible to do double buffering: see x86's
@@ -608,6 +611,7 @@ static int kvm_create_dirty_bitmap(struct kvm_memory_slot *memslot)
        memslot->dirty_bitmap_head = memslot->dirty_bitmap;
        return 0;
 }
+#endif /* !CONFIG_S390 */
 
 /*
  * Allocate some memory and give it an address in the guest physical address
@@ -621,7 +625,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
                            struct kvm_userspace_memory_region *mem,
                            int user_alloc)
 {
-       int r, flush_shadow = 0;
+       int r;
        gfn_t base_gfn;
        unsigned long npages;
        unsigned long i;
@@ -741,8 +745,6 @@ skip_lpage:
                if (kvm_create_dirty_bitmap(&new) < 0)
                        goto out_free;
                /* destroy any largepage mappings for dirty tracking */
-               if (old.npages)
-                       flush_shadow = 1;
        }
 #else  /* not defined CONFIG_S390 */
        new.user_alloc = user_alloc;
@@ -813,9 +815,6 @@ skip_lpage:
        kvm_free_physmem_slot(&old, &new);
        kfree(old_memslots);
 
-       if (flush_shadow)
-               kvm_arch_flush_shadow(kvm);
-
        return 0;
 
 out_free: