Commit 446f7f11 authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: VMX: Do Hyper-V TLB flush iff vCPU's EPTP hasn't been flushed

Combine the for-loops for Hyper-V TLB EPTP checking and flushing, and in
doing so skip flushes for vCPUs whose EPTP matches the target EPTP.
Reviewed-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: default avatarSean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Message-Id: <20210305183123.3978098-6-seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 288bee28
...@@ -505,33 +505,26 @@ static int hv_remote_flush_tlb_with_range(struct kvm *kvm, ...@@ -505,33 +505,26 @@ static int hv_remote_flush_tlb_with_range(struct kvm *kvm,
spin_lock(&kvm_vmx->ept_pointer_lock); spin_lock(&kvm_vmx->ept_pointer_lock);
if (kvm_vmx->ept_pointers_match == EPT_POINTERS_CHECK) { if (kvm_vmx->ept_pointers_match != EPT_POINTERS_MATCH) {
kvm_vmx->ept_pointers_match = EPT_POINTERS_MATCH; kvm_vmx->ept_pointers_match = EPT_POINTERS_MATCH;
kvm_vmx->hv_tlb_eptp = INVALID_PAGE; kvm_vmx->hv_tlb_eptp = INVALID_PAGE;
kvm_for_each_vcpu(i, vcpu, kvm) { kvm_for_each_vcpu(i, vcpu, kvm) {
tmp_eptp = to_vmx(vcpu)->ept_pointer; tmp_eptp = to_vmx(vcpu)->ept_pointer;
if (!VALID_PAGE(tmp_eptp)) if (!VALID_PAGE(tmp_eptp) ||
tmp_eptp == kvm_vmx->hv_tlb_eptp)
continue; continue;
if (!VALID_PAGE(kvm_vmx->hv_tlb_eptp)) { if (!VALID_PAGE(kvm_vmx->hv_tlb_eptp))
kvm_vmx->hv_tlb_eptp = tmp_eptp; kvm_vmx->hv_tlb_eptp = tmp_eptp;
} else if (kvm_vmx->hv_tlb_eptp != tmp_eptp) { else
kvm_vmx->hv_tlb_eptp = INVALID_PAGE;
kvm_vmx->ept_pointers_match kvm_vmx->ept_pointers_match
= EPT_POINTERS_MISMATCH; = EPT_POINTERS_MISMATCH;
break;
}
}
}
if (kvm_vmx->ept_pointers_match != EPT_POINTERS_MATCH) { ret |= hv_remote_flush_eptp(tmp_eptp, range);
kvm_for_each_vcpu(i, vcpu, kvm) {
/* If ept_pointer is invalid pointer, bypass flush request. */
if (VALID_PAGE(to_vmx(vcpu)->ept_pointer))
ret |= hv_remote_flush_eptp(to_vmx(vcpu)->ept_pointer,
range);
} }
if (kvm_vmx->ept_pointers_match == EPT_POINTERS_MISMATCH)
kvm_vmx->hv_tlb_eptp = INVALID_PAGE;
} else if (VALID_PAGE(kvm_vmx->hv_tlb_eptp)) { } else if (VALID_PAGE(kvm_vmx->hv_tlb_eptp)) {
ret = hv_remote_flush_eptp(kvm_vmx->hv_tlb_eptp, range); ret = hv_remote_flush_eptp(kvm_vmx->hv_tlb_eptp, range);
} }
......
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