Message ID | 20220414132013.1588929-16-vkuznets@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | KVM: x86: hyper-v: Fine-grained TLB flush + L2 TLB flush feature | expand |
On Thu, 2022-04-14 at 15:19 +0200, Vitaly Kuznetsov wrote: > The newly introduced helper checks whether vCPU is performing a > Hyper-V TLB flush hypercall. This is required to filter out L2 TLB > flush hypercalls for processing. > > Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com> > --- > arch/x86/kvm/hyperv.h | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) > > diff --git a/arch/x86/kvm/hyperv.h b/arch/x86/kvm/hyperv.h > index d59f96700104..ca67c18cef2c 100644 > --- a/arch/x86/kvm/hyperv.h > +++ b/arch/x86/kvm/hyperv.h > @@ -170,6 +170,24 @@ static inline void kvm_hv_vcpu_empty_flush_tlb(struct kvm_vcpu *vcpu) > tlb_flush_ring = kvm_hv_get_tlb_flush_ring(vcpu); > tlb_flush_ring->read_idx = tlb_flush_ring->write_idx; > } > + > +static inline bool kvm_hv_is_tlb_flush_hcall(struct kvm_vcpu *vcpu) > +{ > + struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(vcpu); > + u16 code; > + > + if (!hv_vcpu) > + return false; > + > + code = is_64_bit_hypercall(vcpu) ? kvm_rcx_read(vcpu) : > + kvm_rax_read(vcpu); > + > + return (code == HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE || > + code == HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST || > + code == HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX || > + code == HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX); > +} > + > void kvm_hv_vcpu_flush_tlb(struct kvm_vcpu *vcpu); > > Looks Ok, but my knowelege of HV spec is limited so I might have missed something. Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> Best regards, Maxim Levitsky
On Thu, Apr 14, 2022, Vitaly Kuznetsov wrote: > The newly introduced helper checks whether vCPU is performing a > Hyper-V TLB flush hypercall. This is required to filter out L2 TLB > flush hypercalls for processing. > > Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com> > --- > arch/x86/kvm/hyperv.h | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) > > diff --git a/arch/x86/kvm/hyperv.h b/arch/x86/kvm/hyperv.h > index d59f96700104..ca67c18cef2c 100644 > --- a/arch/x86/kvm/hyperv.h > +++ b/arch/x86/kvm/hyperv.h > @@ -170,6 +170,24 @@ static inline void kvm_hv_vcpu_empty_flush_tlb(struct kvm_vcpu *vcpu) > tlb_flush_ring = kvm_hv_get_tlb_flush_ring(vcpu); > tlb_flush_ring->read_idx = tlb_flush_ring->write_idx; > } > + > +static inline bool kvm_hv_is_tlb_flush_hcall(struct kvm_vcpu *vcpu) > +{ > + struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(vcpu); > + u16 code; > + > + if (!hv_vcpu) > + return false; > + > + code = is_64_bit_hypercall(vcpu) ? kvm_rcx_read(vcpu) : > + kvm_rax_read(vcpu); Nit, can you align the two expressions? code = is_64_bit_hypercall(vcpu) ? kvm_rcx_read(vcpu) : kvm_rax_read(vcpu); > + > + return (code == HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE || > + code == HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST || > + code == HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX || > + code == HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX); > +} > + > void kvm_hv_vcpu_flush_tlb(struct kvm_vcpu *vcpu); > > > -- > 2.35.1 >
diff --git a/arch/x86/kvm/hyperv.h b/arch/x86/kvm/hyperv.h index d59f96700104..ca67c18cef2c 100644 --- a/arch/x86/kvm/hyperv.h +++ b/arch/x86/kvm/hyperv.h @@ -170,6 +170,24 @@ static inline void kvm_hv_vcpu_empty_flush_tlb(struct kvm_vcpu *vcpu) tlb_flush_ring = kvm_hv_get_tlb_flush_ring(vcpu); tlb_flush_ring->read_idx = tlb_flush_ring->write_idx; } + +static inline bool kvm_hv_is_tlb_flush_hcall(struct kvm_vcpu *vcpu) +{ + struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(vcpu); + u16 code; + + if (!hv_vcpu) + return false; + + code = is_64_bit_hypercall(vcpu) ? kvm_rcx_read(vcpu) : + kvm_rax_read(vcpu); + + return (code == HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE || + code == HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST || + code == HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX || + code == HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX); +} + void kvm_hv_vcpu_flush_tlb(struct kvm_vcpu *vcpu);
The newly introduced helper checks whether vCPU is performing a Hyper-V TLB flush hypercall. This is required to filter out L2 TLB flush hypercalls for processing. Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com> --- arch/x86/kvm/hyperv.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)