Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM/MMU: Move tlb flush in kvm_set_pte_rmapp() to kvm_mmu_notifier_change_pte()

This patch is to move tlb flush in kvm_set_pte_rmapp() to
kvm_mmu_notifier_change_pte() in order to avoid redundant tlb flush.

Signed-off-by: Lan Tianyu <Tianyu.Lan@microsoft.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

authored by

Lan Tianyu and committed by
Paolo Bonzini
0cf853c5 748c0e31

+6 -7
+2 -6
arch/x86/kvm/mmu.c
··· 1776 1776 } 1777 1777 } 1778 1778 1779 - if (need_flush) 1780 - kvm_flush_remote_tlbs(kvm); 1781 - 1782 - return 0; 1779 + return need_flush; 1783 1780 } 1784 1781 1785 1782 struct slot_rmap_walk_iterator { ··· 1912 1915 1913 1916 int kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte) 1914 1917 { 1915 - kvm_handle_hva(kvm, hva, (unsigned long)&pte, kvm_set_pte_rmapp); 1916 - return 0; 1918 + return kvm_handle_hva(kvm, hva, (unsigned long)&pte, kvm_set_pte_rmapp); 1917 1919 } 1918 1920 1919 1921 static int kvm_age_rmapp(struct kvm *kvm, struct kvm_rmap_head *rmap_head,
+4 -1
virt/kvm/kvm_main.c
··· 354 354 idx = srcu_read_lock(&kvm->srcu); 355 355 spin_lock(&kvm->mmu_lock); 356 356 kvm->mmu_notifier_seq++; 357 - kvm_set_spte_hva(kvm, address, pte); 357 + 358 + if (kvm_set_spte_hva(kvm, address, pte)) 359 + kvm_flush_remote_tlbs(kvm); 360 + 358 361 spin_unlock(&kvm->mmu_lock); 359 362 srcu_read_unlock(&kvm->srcu, idx); 360 363 }