]> git.karo-electronics.de Git - karo-tx-linux.git/commit
KVM: add explicit barrier to kvm_vcpu_kick
authorAndrew Jones <drjones@redhat.com>
Wed, 26 Apr 2017 20:32:24 +0000 (22:32 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 27 Apr 2017 12:16:17 +0000 (14:16 +0200)
commitcde9af6e79046e12cd08d161139b1d5e57e9fbac
tree2192140fe822f0805d3b766f3e277798e12445b0
parent6c6e8360b34d59d2f687a1649e61173742dbc891
KVM: add explicit barrier to kvm_vcpu_kick

kvm_vcpu_kick() must issue a general memory barrier prior to reading
vcpu->mode in order to ensure correctness of the mutual-exclusion
memory barrier pattern used with vcpu->requests.  While the cmpxchg
called from kvm_vcpu_kick():

 kvm_vcpu_kick
   kvm_arch_vcpu_should_kick
     kvm_vcpu_exiting_guest_mode
       cmpxchg

implies general memory barriers before and after the operation, that
implication is only valid when cmpxchg succeeds.  We need an explicit
barrier for when it fails, otherwise a VCPU thread on its entry path
that reads zero for vcpu->requests does not exclude the possibility
the requesting thread sees !IN_GUEST_MODE when it reads vcpu->mode.

kvm_make_all_cpus_request already had a barrier, so we remove it, as
now it would be redundant.

Signed-off-by: Andrew Jones <drjones@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/x86.c
include/linux/kvm_host.h
virt/kvm/kvm_main.c