diff options
author | Tianyu Lan <Tianyu.Lan@microsoft.com> | 2018-07-24 04:17:07 -0400 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2018-08-06 11:59:18 -0400 |
commit | c2a4eadf7747a1359a80ede64e4ae0e0ba64ca08 (patch) | |
tree | 51601589f99be2c26d1d2e4e5b0cf64831456fcc | |
parent | 5e079c7ece1060491ef4a45414823162cce91b3d (diff) |
KVM/MMU: Combine flushing remote tlb in mmu_set_spte()
mmu_set_spte() flushes remote tlbs for drop_parent_pte/drop_spte()
and set_spte() separately. This may introduce redundant flush. This
patch is to combine these flushes and check flush request after
calling set_spte().
Signed-off-by: Lan Tianyu <Tianyu.Lan@microsoft.com>
Reviewed-by: Junaid Shahid <junaids@google.com>
Reviewed-by: Xiao Guangrong <xiaoguangrong@tencent.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r-- | arch/x86/kvm/mmu.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 22a7984c68a5..8f216321d33b 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c | |||
@@ -2901,6 +2901,7 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep, unsigned pte_access, | |||
2901 | int rmap_count; | 2901 | int rmap_count; |
2902 | int set_spte_ret; | 2902 | int set_spte_ret; |
2903 | int ret = RET_PF_RETRY; | 2903 | int ret = RET_PF_RETRY; |
2904 | bool flush = false; | ||
2904 | 2905 | ||
2905 | pgprintk("%s: spte %llx write_fault %d gfn %llx\n", __func__, | 2906 | pgprintk("%s: spte %llx write_fault %d gfn %llx\n", __func__, |
2906 | *sptep, write_fault, gfn); | 2907 | *sptep, write_fault, gfn); |
@@ -2917,12 +2918,12 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep, unsigned pte_access, | |||
2917 | 2918 | ||
2918 | child = page_header(pte & PT64_BASE_ADDR_MASK); | 2919 | child = page_header(pte & PT64_BASE_ADDR_MASK); |
2919 | drop_parent_pte(child, sptep); | 2920 | drop_parent_pte(child, sptep); |
2920 | kvm_flush_remote_tlbs(vcpu->kvm); | 2921 | flush = true; |
2921 | } else if (pfn != spte_to_pfn(*sptep)) { | 2922 | } else if (pfn != spte_to_pfn(*sptep)) { |
2922 | pgprintk("hfn old %llx new %llx\n", | 2923 | pgprintk("hfn old %llx new %llx\n", |
2923 | spte_to_pfn(*sptep), pfn); | 2924 | spte_to_pfn(*sptep), pfn); |
2924 | drop_spte(vcpu->kvm, sptep); | 2925 | drop_spte(vcpu->kvm, sptep); |
2925 | kvm_flush_remote_tlbs(vcpu->kvm); | 2926 | flush = true; |
2926 | } else | 2927 | } else |
2927 | was_rmapped = 1; | 2928 | was_rmapped = 1; |
2928 | } | 2929 | } |
@@ -2934,7 +2935,7 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep, unsigned pte_access, | |||
2934 | ret = RET_PF_EMULATE; | 2935 | ret = RET_PF_EMULATE; |
2935 | kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu); | 2936 | kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu); |
2936 | } | 2937 | } |
2937 | if (set_spte_ret & SET_SPTE_NEED_REMOTE_TLB_FLUSH) | 2938 | if (set_spte_ret & SET_SPTE_NEED_REMOTE_TLB_FLUSH || flush) |
2938 | kvm_flush_remote_tlbs(vcpu->kvm); | 2939 | kvm_flush_remote_tlbs(vcpu->kvm); |
2939 | 2940 | ||
2940 | if (unlikely(is_mmio_spte(*sptep))) | 2941 | if (unlikely(is_mmio_spte(*sptep))) |