Skip to content

Commit af9d544

Browse files
vittyvksean-jc
authored andcommitted
KVM: x86: Introduce helper to handle Hyper-V paravirt TLB flush requests
As a preparation to making Hyper-V emulation optional, introduce a helper to handle pending KVM_REQ_HV_TLB_FLUSH requests. No functional change intended. Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> Tested-by: Jeremi Piotrowski <jpiotrowski@linux.microsoft.com> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com> Link: https://lore.kernel.org/r/20231205103630.1391318-8-vkuznets@redhat.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent e7ad84d commit af9d544

3 files changed

Lines changed: 17 additions & 16 deletions

File tree

arch/x86/kvm/hyperv.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,19 @@ static inline int kvm_hv_verify_vp_assist(struct kvm_vcpu *vcpu)
247247
return kvm_hv_get_assist_page(vcpu);
248248
}
249249

250+
static inline void kvm_hv_nested_transtion_tlb_flush(struct kvm_vcpu *vcpu,
251+
bool tdp_enabled)
252+
{
253+
/*
254+
* KVM_REQ_HV_TLB_FLUSH flushes entries from either L1's VP_ID or
255+
* L2's VP_ID upon request from the guest. Make sure we check for
256+
* pending entries in the right FIFO upon L1/L2 transition as these
257+
* requests are put by other vCPUs asynchronously.
258+
*/
259+
if (to_hv_vcpu(vcpu) && tdp_enabled)
260+
kvm_make_request(KVM_REQ_HV_TLB_FLUSH, vcpu);
261+
}
262+
250263
int kvm_hv_vcpu_flush_tlb(struct kvm_vcpu *vcpu);
251264

252265
#endif

arch/x86/kvm/svm/nested.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -487,14 +487,8 @@ static void nested_save_pending_event_to_vmcb12(struct vcpu_svm *svm,
487487

488488
static void nested_svm_transition_tlb_flush(struct kvm_vcpu *vcpu)
489489
{
490-
/*
491-
* KVM_REQ_HV_TLB_FLUSH flushes entries from either L1's VP_ID or
492-
* L2's VP_ID upon request from the guest. Make sure we check for
493-
* pending entries in the right FIFO upon L1/L2 transition as these
494-
* requests are put by other vCPUs asynchronously.
495-
*/
496-
if (to_hv_vcpu(vcpu) && npt_enabled)
497-
kvm_make_request(KVM_REQ_HV_TLB_FLUSH, vcpu);
490+
/* Handle pending Hyper-V TLB flush requests */
491+
kvm_hv_nested_transtion_tlb_flush(vcpu, npt_enabled);
498492

499493
/*
500494
* TODO: optimize unconditional TLB flush/MMU sync. A partial list of

arch/x86/kvm/vmx/nested.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,14 +1139,8 @@ static void nested_vmx_transition_tlb_flush(struct kvm_vcpu *vcpu,
11391139
{
11401140
struct vcpu_vmx *vmx = to_vmx(vcpu);
11411141

1142-
/*
1143-
* KVM_REQ_HV_TLB_FLUSH flushes entries from either L1's VP_ID or
1144-
* L2's VP_ID upon request from the guest. Make sure we check for
1145-
* pending entries in the right FIFO upon L1/L2 transition as these
1146-
* requests are put by other vCPUs asynchronously.
1147-
*/
1148-
if (to_hv_vcpu(vcpu) && enable_ept)
1149-
kvm_make_request(KVM_REQ_HV_TLB_FLUSH, vcpu);
1142+
/* Handle pending Hyper-V TLB flush requests */
1143+
kvm_hv_nested_transtion_tlb_flush(vcpu, enable_ept);
11501144

11511145
/*
11521146
* If vmcs12 doesn't use VPID, L1 expects linear and combined mappings

0 commit comments

Comments
 (0)