KVM: document memory barriers for kvm->vcpus/kvm->online_vcpus
authorPaolo Bonzini <pbonzini@redhat.com>
Wed, 29 Jul 2015 09:32:20 +0000 (11:32 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 30 Jul 2015 14:02:54 +0000 (16:02 +0200)
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
include/linux/kvm_host.h
virt/kvm/kvm_main.c

index bd1097a95704f9bd36eb9f9930093bfaaa7e6a8a..81089cf1f0c11c025b6f448d20ddcc1117ab5367 100644 (file)
@@ -427,6 +427,10 @@ struct kvm {
 
 static inline struct kvm_vcpu *kvm_get_vcpu(struct kvm *kvm, int i)
 {
+       /* Pairs with smp_wmb() in kvm_vm_ioctl_create_vcpu, in case
+        * the caller has read kvm->online_vcpus before (as is the case
+        * for kvm_for_each_vcpu, for example).
+        */
        smp_rmb();
        return kvm->vcpus[i];
 }
index 8dc4828f623f15259c95bf9c745c37566358fe58..d8db2f8fce9c7ab727fb5dfa957d5f7ba828fa42 100644 (file)
@@ -2206,6 +2206,11 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
        }
 
        kvm->vcpus[atomic_read(&kvm->online_vcpus)] = vcpu;
+
+       /*
+        * Pairs with smp_rmb() in kvm_get_vcpu.  Write kvm->vcpus
+        * before kvm->online_vcpu's incremented value.
+        */
        smp_wmb();
        atomic_inc(&kvm->online_vcpus);