Commit c2a4eadf authored by Tianyu Lan's avatar Tianyu Lan Committed by Paolo Bonzini

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: default avatarLan Tianyu <Tianyu.Lan@microsoft.com>
Reviewed-by: default avatarJunaid Shahid <junaids@google.com>
Reviewed-by: default avatarXiao Guangrong <xiaoguangrong@tencent.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 5e079c7e
...@@ -2901,6 +2901,7 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep, unsigned pte_access, ...@@ -2901,6 +2901,7 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep, unsigned pte_access,
int rmap_count; int rmap_count;
int set_spte_ret; int set_spte_ret;
int ret = RET_PF_RETRY; int ret = RET_PF_RETRY;
bool flush = false;
pgprintk("%s: spte %llx write_fault %d gfn %llx\n", __func__, pgprintk("%s: spte %llx write_fault %d gfn %llx\n", __func__,
*sptep, write_fault, gfn); *sptep, write_fault, gfn);
...@@ -2917,12 +2918,12 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep, unsigned pte_access, ...@@ -2917,12 +2918,12 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep, unsigned pte_access,
child = page_header(pte & PT64_BASE_ADDR_MASK); child = page_header(pte & PT64_BASE_ADDR_MASK);
drop_parent_pte(child, sptep); drop_parent_pte(child, sptep);
kvm_flush_remote_tlbs(vcpu->kvm); flush = true;
} else if (pfn != spte_to_pfn(*sptep)) { } else if (pfn != spte_to_pfn(*sptep)) {
pgprintk("hfn old %llx new %llx\n", pgprintk("hfn old %llx new %llx\n",
spte_to_pfn(*sptep), pfn); spte_to_pfn(*sptep), pfn);
drop_spte(vcpu->kvm, sptep); drop_spte(vcpu->kvm, sptep);
kvm_flush_remote_tlbs(vcpu->kvm); flush = true;
} else } else
was_rmapped = 1; was_rmapped = 1;
} }
...@@ -2934,7 +2935,7 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep, unsigned pte_access, ...@@ -2934,7 +2935,7 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, u64 *sptep, unsigned pte_access,
ret = RET_PF_EMULATE; ret = RET_PF_EMULATE;
kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu); kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu);
} }
if (set_spte_ret & SET_SPTE_NEED_REMOTE_TLB_FLUSH) if (set_spte_ret & SET_SPTE_NEED_REMOTE_TLB_FLUSH || flush)
kvm_flush_remote_tlbs(vcpu->kvm); kvm_flush_remote_tlbs(vcpu->kvm);
if (unlikely(is_mmio_spte(*sptep))) if (unlikely(is_mmio_spte(*sptep)))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment