KVM: x86: More cleanups for Hyper-V range flushing
Subsystems (4)
Sean Christopherson
maintainercover KVM: x86: More cleanups for Hyper-V range flushing
More cleanups of the code related to Hyper-V's range-based TLB flushing. David's series got most of the names, but there are a few more that can be converted (patch 1). On top of that, having Hyper-V fill its struct provides a decent improvement to code generation, and IMO yields a better API (patch 2).
Sean Christopherson (2):
KVM: x86: Rename Hyper-V remote TLB hooks to match established scheme
KVM: x86/mmu: Move filling of Hyper-V's TLB range struct into Hyper-V
code
arch/x86/include/asm/kvm-x86-ops.h | 4 ++-- arch/x86/include/asm/kvm_host.h | 15 +++++--------- arch/x86/kvm/kvm_onhyperv.c | 33 ++++++++++++++++++++++-------- arch/x86/kvm/kvm_onhyperv.h | 5 ++--- arch/x86/kvm/mmu/mmu.c | 18 +++++++--------- arch/x86/kvm/svm/svm_onhyperv.h | 5 ++--- arch/x86/kvm/vmx/vmx.c | 5 ++--- 7 files changed, 44 insertions(+), 41 deletions(-)
base-commit: 50f13998451effea5c5fdc70fe576f8b435d6224
Signature · 1 line
2.40.0.348.gf938b09366-goog
Sean Christopherson
maintainerPATCH 1/2 KVM: x86: Rename Hyper-V remote TLB hooks to match established scheme
Rename the Hyper-V hooks for TLB flushing to match the naming scheme used by all the other TLB flushing hooks, e.g. in kvm_x86_ops, vendor code, arch hooks from common code, etc.
--- arch/x86/include/asm/kvm-x86-ops.h | 4 ++-- arch/x86/include/asm/kvm_host.h | 10 +++++----- arch/x86/kvm/kvm_onhyperv.c | 13 ++++++------- arch/x86/kvm/kvm_onhyperv.h | 5 ++--- arch/x86/kvm/mmu/mmu.c | 12 ++++++------ arch/x86/kvm/svm/svm_onhyperv.h | 5 ++--- arch/x86/kvm/vmx/vmx.c | 5 ++--- 7 files changed, 25 insertions(+), 29 deletions(-)
arch/x86/include/asm/kvm-x86-ops.h +2 -2
@@ -54,8 +54,8 @@ KVM_X86_OP(set_rflags) KVM_X86_OP(get_if_flag) KVM_X86_OP(flush_tlb_all) KVM_X86_OP(flush_tlb_current) -KVM_X86_OP_OPTIONAL(tlb_remote_flush) -KVM_X86_OP_OPTIONAL(tlb_remote_flush_with_range) +KVM_X86_OP_OPTIONAL(flush_remote_tlbs) +KVM_X86_OP_OPTIONAL(flush_remote_tlbs_range) KVM_X86_OP(flush_tlb_gva) KVM_X86_OP(flush_tlb_guest) KVM_X86_OP(vcpu_pre_run)
arch/x86/include/asm/kvm_host.h +5 -5
@@ -1588,9 +1588,9 @@ struct kvm_x86_ops {void (*flush_tlb_all)(struct kvm_vcpu *vcpu);void (*flush_tlb_current)(struct kvm_vcpu *vcpu); -int (*tlb_remote_flush)(struct kvm *kvm); -int (*tlb_remote_flush_with_range)(struct kvm *kvm, -struct kvm_tlb_range *range); +int (*flush_remote_tlbs)(struct kvm *kvm); +int (*flush_remote_tlbs_range)(struct kvm *kvm, +struct kvm_tlb_range *range);/* * Flush any TLB entries associated with the given GVA.
@@ -1794,8 +1794,8 @@ void kvm_arch_free_vm(struct kvm *kvm);#define __KVM_HAVE_ARCH_FLUSH_REMOTE_TLBstatic inline int kvm_arch_flush_remote_tlb (struct kvm *kvm) { -if (kvm_x86_ops.tlb_remote_flush && - !static_call (kvm_x86_tlb_remote_flush)(kvm)) +if (kvm_x86_ops.flush_remote_tlbs && + !static_call (kvm_x86_flush_remote_tlbs)(kvm))return 0 ;else return -ENOTSUPP ;
arch/x86/kvm/kvm_onhyperv.c +6 -7
@@ -29,8 +29,7 @@ static inline int hv_remote_flush_root_tdp(hpa_t root_tdp,return hyperv_flush_guest_mapping (root_tdp); } -int hv_remote_flush_tlb_with_range (struct kvm *kvm, -struct kvm_tlb_range *range) +int hv_flush_remote_tlbs_range (struct kvm *kvm,struct kvm_tlb_range *range) {struct kvm_arch *kvm_arch = &kvm->arch;struct kvm_vcpu *vcpu;
@@ -86,19 +85,19 @@ int hv_remote_flush_tlb_with_range(struct kvm *kvm,spin_unlock (&kvm_arch->hv_root_tdp_lock);return ret; } -EXPORT_SYMBOL_GPL (hv_remote_flush_tlb_with_range); +EXPORT_SYMBOL_GPL (hv_flush_remote_tlbs_range); -int hv_remote_flush_tlb (struct kvm *kvm) +int hv_flush_remote_tlbs (struct kvm *kvm) { -return hv_remote_flush_tlb_with_range (kvm,NULL ); +return hv_flush_remote_tlbs_range (kvm,NULL ); } -EXPORT_SYMBOL_GPL (hv_remote_flush_tlb); +EXPORT_SYMBOL_GPL (hv_flush_remote_tlbs);void hv_track_root_tdp (struct kvm_vcpu *vcpu,hpa_t root_tdp) {struct kvm_arch *kvm_arch = &vcpu->kvm->arch; -if (kvm_x86_ops.tlb_remote_flush == hv_remote_flush_tlb) { +if (kvm_x86_ops.flush_remote_tlbs == hv_flush_remote_tlbs) {spin_lock (&kvm_arch->hv_root_tdp_lock); vcpu->arch.hv_root_tdp = root_tdp;if (root_tdp != kvm_arch->hv_root_tdp)
arch/x86/kvm/kvm_onhyperv.h +2 -3
@@ -7,9 +7,8 @@#define __ARCH_X86_KVM_KVM_ONHYPERV_H__#if IS_ENABLED (CONFIG_HYPERV ) -int hv_remote_flush_tlb_with_range (struct kvm *kvm, -struct kvm_tlb_range *range); -int hv_remote_flush_tlb (struct kvm *kvm); +int hv_flush_remote_tlbs_range (struct kvm *kvm,struct kvm_tlb_range *range); +int hv_flush_remote_tlbs (struct kvm *kvm);void hv_track_root_tdp (struct kvm_vcpu *vcpu,hpa_t root_tdp);#else /* !CONFIG_HYPERV */ static inline void hv_track_root_tdp (struct kvm_vcpu *vcpu,hpa_t root_tdp)
arch/x86/kvm/mmu/mmu.c +6 -6
@@ -270,9 +270,9 @@ static inline unsigned long kvm_mmu_get_guest_pgd(struct kvm_vcpu *vcpu,return mmu->get_guest_pgd (vcpu); } -static inline bool kvm_available_flush_tlb_with_range (void ) +static inline bool kvm_available_flush_remote_tlbs_range (void ) { -return kvm_x86_ops.tlb_remote_flush_with_range; +return kvm_x86_ops.flush_remote_tlbs_range; } void kvm_flush_remote_tlbs_range(struct kvm *kvm, gfn_t start_gfn,
@@ -284,8 +284,8 @@ void kvm_flush_remote_tlbs_range(struct kvm *kvm, gfn_t start_gfn, range.start_gfn = start_gfn; range.pages = nr_pages; -if (kvm_x86_ops.tlb_remote_flush_with_range) - ret =static_call (kvm_x86_tlb_remote_flush_with_range)(kvm, &range); +if (kvm_x86_ops.flush_remote_tlbs_range) + ret =static_call (kvm_x86_flush_remote_tlbs_range)(kvm, &range);if (ret)kvm_flush_remote_tlbs (kvm);
@@ -1498,7 +1498,7 @@ static bool kvm_set_pte_rmap(struct kvm *kvm, struct kvm_rmap_head *rmap_head, } } -if (need_flush &&kvm_available_flush_tlb_with_range ()) { +if (need_flush &&kvm_available_flush_remote_tlbs_range ()) {kvm_flush_remote_tlbs_gfn (kvm, gfn, level);return false; }
@@ -6623,7 +6623,7 @@ static bool kvm_mmu_zap_collapsible_spte(struct kvm *kvm, PG_LEVEL_NUM)) {kvm_zap_one_rmap_spte (kvm, rmap_head, sptep); -if (kvm_available_flush_tlb_with_range ()) +if (kvm_available_flush_remote_tlbs_range ())kvm_flush_remote_tlbs_sptep (kvm, sptep);else need_tlb_flush =1 ;
arch/x86/kvm/svm/svm_onhyperv.h +2 -3
@@ -35,9 +35,8 @@ static inline __init void svm_hv_hardware_setup(void)if (npt_enabled && ms_hyperv.nested_features &HV_X64_NESTED_ENLIGHTENED_TLB ) {pr_info (KBUILD_MODNAME ": Hyper-V enlightened NPT TLB flush enabled\n" ); - svm_x86_ops.tlb_remote_flush = hv_remote_flush_tlb; - svm_x86_ops.tlb_remote_flush_with_range = - hv_remote_flush_tlb_with_range; + svm_x86_ops.flush_remote_tlbs = hv_flush_remote_tlbs; + svm_x86_ops.flush_remote_tlbs_range = hv_flush_remote_tlbs_range; }if (ms_hyperv.nested_features &HV_X64_NESTED_DIRECT_FLUSH ) {
arch/x86/kvm/vmx/vmx.c +2 -3
@@ -8432,9 +8432,8 @@ static __init int hardware_setup(void)#if IS_ENABLED (CONFIG_HYPERV )if (ms_hyperv.nested_features &HV_X64_NESTED_GUEST_MAPPING_FLUSH && enable_ept) { - vmx_x86_ops.tlb_remote_flush = hv_remote_flush_tlb; - vmx_x86_ops.tlb_remote_flush_with_range = - hv_remote_flush_tlb_with_range; + vmx_x86_ops.flush_remote_tlbs = hv_flush_remote_tlbs; + vmx_x86_ops.flush_remote_tlbs_range = hv_flush_remote_tlbs_range; }#endif
Signature · 1 line
2.40.0.348.gf938b09366-goog
Sean Christopherson
maintainerPATCH 2/2 KVM: x86/mmu: Move filling of Hyper-V's TLB range struct into Hyper-V code
In reply to Sean ChristophersonRefactor Hyper-V's range-based TLB flushing API to take a gfn+nr_pages pair instead of a struct, and bury said struct in Hyper-V specific code.
Passing along two params generates much better code for the common case where KVM is _not_ running on Hyper-V, as forwarding the flush on to Hyper-V's hv_flush_remote_tlbs_range() from kvm_flush_remote_tlbs_range() becomes a tail call.
--- arch/x86/include/asm/kvm_host.h | 9 ++------- arch/x86/kvm/kvm_onhyperv.c | 24 ++++++++++++++++++++---- arch/x86/kvm/kvm_onhyperv.h | 2 +- arch/x86/kvm/mmu/mmu.c | 8 ++------ 4 files changed, 25 insertions(+), 18 deletions(-)
arch/x86/include/asm/kvm_host.h +2 -7
@@ -482,11 +482,6 @@ struct kvm_mmu {u64 pdptrs[4 ];/* pae */ }; -struct kvm_tlb_range { -u64 start_gfn; -u64 pages; -}; -enum pmc_type {KVM_PMC_GP =0 ,KVM_PMC_FIXED ,
@@ -1589,8 +1584,8 @@ struct kvm_x86_ops {void (*flush_tlb_all)(struct kvm_vcpu *vcpu);void (*flush_tlb_current)(struct kvm_vcpu *vcpu);int (*flush_remote_tlbs)(struct kvm *kvm); -int (*flush_remote_tlbs_range)(struct kvm *kvm, -struct kvm_tlb_range *range); +int (*flush_remote_tlbs_range)(struct kvm *kvm,gfn_t gfn, +gfn_t nr_pages);/* * Flush any TLB entries associated with the given GVA.
arch/x86/kvm/kvm_onhyperv.c +20 -4
@@ -10,17 +10,22 @@#include "hyperv.h" #include "kvm_onhyperv.h" +struct kvm_hv_tlb_range { +u64 start_gfn; +u64 pages; +}; +static int kvm_fill_hv_flush_list_func (struct hv_guest_mapping_flush_list *flush,void *data) { -struct kvm_tlb_range *range = data; +struct kvm_hv_tlb_range *range = data;return hyperv_fill_flush_guest_mapping_list (flush, range->start_gfn, range->pages); }static inline int hv_remote_flush_root_tdp (hpa_t root_tdp, -struct kvm_tlb_range *range) +struct kvm_hv_tlb_range *range) {if (range) return hyperv_flush_guest_mapping_range(root_tdp,
@@ -29,7 +34,8 @@ static inline int hv_remote_flush_root_tdp(hpa_t root_tdp,return hyperv_flush_guest_mapping (root_tdp); } -int hv_flush_remote_tlbs_range (struct kvm *kvm,struct kvm_tlb_range *range) +static int __hv_flush_remote_tlbs_range (struct kvm *kvm, +struct kvm_hv_tlb_range *range) {struct kvm_arch *kvm_arch = &kvm->arch;struct kvm_vcpu *vcpu;
@@ -85,11 +91,21 @@ int hv_flush_remote_tlbs_range(struct kvm *kvm, struct kvm_tlb_range *range)spin_unlock (&kvm_arch->hv_root_tdp_lock);return ret; } + +int hv_flush_remote_tlbs_range (struct kvm *kvm,gfn_t start_gfn,gfn_t nr_pages) +{ +struct kvm_hv_tlb_range range = { + .start_gfn = start_gfn, + .pages = nr_pages, + }; + +return __hv_flush_remote_tlbs_range (kvm, &range); +}EXPORT_SYMBOL_GPL (hv_flush_remote_tlbs_range);int hv_flush_remote_tlbs (struct kvm *kvm) { -return hv_flush_remote_tlbs_range (kvm,NULL ); +return __hv_flush_remote_tlbs_range (kvm,NULL ); }EXPORT_SYMBOL_GPL (hv_flush_remote_tlbs);
arch/x86/kvm/kvm_onhyperv.h +1 -1
@@ -7,7 +7,7 @@#define __ARCH_X86_KVM_KVM_ONHYPERV_H__#if IS_ENABLED (CONFIG_HYPERV ) -int hv_flush_remote_tlbs_range (struct kvm *kvm,struct kvm_tlb_range *range); +int hv_flush_remote_tlbs_range (struct kvm *kvm,gfn_t gfn,gfn_t nr_pages);int hv_flush_remote_tlbs (struct kvm *kvm);void hv_track_root_tdp (struct kvm_vcpu *vcpu,hpa_t root_tdp);#else /* !CONFIG_HYPERV */
arch/x86/kvm/mmu/mmu.c +2 -6
@@ -278,15 +278,11 @@ static inline bool kvm_available_flush_remote_tlbs_range(void)void kvm_flush_remote_tlbs_range (struct kvm *kvm,gfn_t start_gfn,gfn_t nr_pages) { -struct kvm_tlb_range range;int ret = -EOPNOTSUPP ; - range.start_gfn = start_gfn; - range.pages = nr_pages; -if (kvm_x86_ops.flush_remote_tlbs_range) - ret =static_call (kvm_x86_flush_remote_tlbs_range)(kvm, &range); - + ret =static_call (kvm_x86_flush_remote_tlbs_range)(kvm, start_gfn, + nr_pages);if (ret)kvm_flush_remote_tlbs (kvm); }
Signature · 1 line
2.40.0.348.gf938b09366-goog
Quoted 11 lines · Sean Christopherson
More cleanups of the code related to Hyper-V's range-based TLB flushing. David's series got most of the names, but there are a few more that can be converted (patch 1). On top of that, having Hyper-V fill its struct provides a decent improvement to code generation, and IMO yields a better API (patch 2).
Sean Christopherson (2):
KVM: x86: Rename Hyper-V remote TLB hooks to match established scheme
KVM: x86/mmu: Move filling of Hyper-V's TLB range struct into Hyper-V
code
For the series:
Signature · 1 line
Vitaly
Quoted 5 lines · Sean Christopherson
More cleanups of the code related to Hyper-V's range-based TLB flushing. David's series got most of the names, but there are a few more that can be converted (patch 1). On top of that, having Hyper-V fill its struct provides a decent improvement to code generation, and IMO yields a better API (patch 2).
Quoted 6 lines · Sean Christopherson
More cleanups of the code related to Hyper-V's range-based TLB flushing. David's series got most of the names, but there are a few more that can be converted (patch 1). On top of that, having Hyper-V fill its struct provides a decent improvement to code generation, and IMO yields a better API (patch 2).
Quoted 6 lines
Sean Christopherson (2):
KVM: x86: Rename Hyper-V remote TLB hooks to match established scheme
KVM: x86/mmu: Move filling of Hyper-V's TLB range struct into Hyper-V
code[...]
Applied to kvm-x86 mmu, thanks!
[1/2] KVM: x86: Rename Hyper-V remote TLB hooks to match established scheme
https://github.com/kvm-x86/linux/commit/8a1300ff9518 [2/2] KVM: x86/mmu: Move filling of Hyper-V's TLB range struct into Hyper-V code https://github.com/kvm-x86/linux/commit/9ed3bf411226
--
https://github.com/kvm-x86/linux/tree/next
https://github.com/kvm-x86/linux/tree/fixes