Skip to content

Commit 4ae3cb3

Browse files
Lan Tianyubonzini
Lan Tianyu
authored andcommitted
KVM: Replace smp_mb() with smp_load_acquire() in the kvm_flush_remote_tlbs()
smp_load_acquire() is enough here and it's cheaper than smp_mb(). Adding a comment about reusing memory barrier of kvm_make_all_cpus_request() here to keep order between modifications to the page tables and reading mode. Signed-off-by: Lan Tianyu <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 7bfdf21 commit 4ae3cb3

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

Diff for: virt/kvm/kvm_main.c

+16-2
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,23 @@ bool kvm_make_all_cpus_request(struct kvm *kvm, unsigned int req)
191191
#ifndef CONFIG_HAVE_KVM_ARCH_TLB_FLUSH_ALL
192192
void kvm_flush_remote_tlbs(struct kvm *kvm)
193193
{
194-
long dirty_count = kvm->tlbs_dirty;
194+
/*
195+
* Read tlbs_dirty before setting KVM_REQ_TLB_FLUSH in
196+
* kvm_make_all_cpus_request.
197+
*/
198+
long dirty_count = smp_load_acquire(&kvm->tlbs_dirty);
195199

196-
smp_mb();
200+
/*
201+
* We want to publish modifications to the page tables before reading
202+
* mode. Pairs with a memory barrier in arch-specific code.
203+
* - x86: smp_mb__after_srcu_read_unlock in vcpu_enter_guest
204+
* and smp_mb in walk_shadow_page_lockless_begin/end.
205+
* - powerpc: smp_mb in kvmppc_prepare_to_enter.
206+
*
207+
* There is already an smp_mb__after_atomic() before
208+
* kvm_make_all_cpus_request() reads vcpu->mode. We reuse that
209+
* barrier here.
210+
*/
197211
if (kvm_make_all_cpus_request(kvm, KVM_REQ_TLB_FLUSH))
198212
++kvm->stat.remote_tlb_flush;
199213
cmpxchg(&kvm->tlbs_dirty, dirty_count, 0);

0 commit comments

Comments
 (0)