KVM: x86: remove "full" out-argument from flush_tlb_gva
Subsystems (4)
Paolo Bonzini
maintainerPATCH 1/1 KVM: x86: remove "full" out-argument from flush_tlb_gva
The "full" out-argument in flush_tlb_gva is only ever set on AMD processors, where the TLB flush is little more than a memory write and thus extremely cheap anyway.
Simplify the code by letting the implementation of Hyper-V TLB flush hypercalls always go through all the addresses queued in tlb_flush_fifo; there are no performance concerns since that is already the case on VMX, and also was on SVM prior to commit 26505e1b5b54 ("KVM: SVM: make svm_flush_tlb_gva do a full asid flush if NPT enabled", 2026-08-06).
--- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/hyperv.c | 7 +++---- arch/x86/kvm/mmu/mmu.c | 2 +- arch/x86/kvm/svm/svm.c | 4 +--- arch/x86/kvm/vmx/main.c | 4 ++-- arch/x86/kvm/vmx/vmx.c | 2 +- arch/x86/kvm/vmx/x86_ops.h | 2 +- 7 files changed, 10 insertions(+), 13 deletions(-)
arch/x86/include/asm/kvm_host.h +1 -1
@@ -1578,7 +1578,7 @@ struct kvm_x86_ops {* Can potentially get non-canonical addresses through INVLPGs, which * the implementation may choose to ignore if appropriate. */ -void (*flush_tlb_gva)(struct kvm_vcpu *vcpu,gva_t addr,bool *full); +void (*flush_tlb_gva)(struct kvm_vcpu *vcpu,gva_t addr);/* * Flush any TLB entries created by the guest. Like tlb_flush_gva(),
arch/x86/kvm/hyperv.c +3 -4
@@ -1995,7 +1995,6 @@ int kvm_hv_vcpu_flush_tlb(struct kvm_vcpu *vcpu)u64 entries[KVM_HV_TLB_FLUSH_FIFO_SIZE ];int i, j, count;gva_t gva; -bool full = false;if (!tdp_enabled)return -EINVAL ;
@@ -2006,7 +2005,7 @@ int kvm_hv_vcpu_flush_tlb(struct kvm_vcpu *vcpu) count =kfifo_out (&tlb_flush_fifo->entries, entries,KVM_HV_TLB_FLUSH_FIFO_SIZE ); -for (i =0 ; i < count && !full; i++) { +for (i =0 ; i < count; i++) {if (entries[i] ==KVM_HV_TLB_FLUSHALL_ENTRY ) goto out_flush_all;
@@ -2015,11 +2014,11 @@ int kvm_hv_vcpu_flush_tlb(struct kvm_vcpu *vcpu)* pages to flush. */ gva = entries[i] &PAGE_MASK ; -for (j =0 ; j < (entries[i] & ~PAGE_MASK ) +1 && !full; j++) { +for (j =0 ; j < (entries[i] & ~PAGE_MASK ) +1 ; j++) {if (is_noncanonical_invlpg_address (gva + j *PAGE_SIZE , vcpu))continue ; -kvm_x86_call (flush_tlb_gva)(vcpu, gva + j *PAGE_SIZE , &full); +kvm_x86_call (flush_tlb_gva)(vcpu, gva + j *PAGE_SIZE ); } ++vcpu->stat.tlb_flush;
arch/x86/kvm/mmu/mmu.c +1 -1
@@ -6704,7 +6704,7 @@ void kvm_mmu_invalidate_addr(struct kvm_vcpu *vcpu, struct kvm_pagewalk *w,if (is_noncanonical_invlpg_address (addr, vcpu))return ; -kvm_x86_call (flush_tlb_gva)(vcpu, addr,NULL ); +kvm_x86_call (flush_tlb_gva)(vcpu, addr);if (tdp_enabled)return ;
arch/x86/kvm/svm/svm.c +1 -3
@@ -4245,7 +4245,7 @@ static void svm_flush_tlb_guest(struct kvm_vcpu *vcpu)svm_flush_tlb_asid (vcpu); } -static void svm_flush_tlb_gva (struct kvm_vcpu *vcpu,gva_t gva,bool *full) +static void svm_flush_tlb_gva (struct kvm_vcpu *vcpu,gva_t gva) {struct vcpu_svm *svm =to_svm (vcpu);
@@ -4261,8 +4261,6 @@ static void svm_flush_tlb_gva(struct kvm_vcpu *vcpu, gva_t gva, bool *full) }svm_flush_tlb_guest (vcpu); -if (full) - *full = true; }static inline void sync_cr8_to_lapic (struct kvm_vcpu *vcpu)
arch/x86/kvm/vmx/main.c +2 -2
@@ -543,12 +543,12 @@ static void vt_flush_tlb_current(struct kvm_vcpu *vcpu)vmx_flush_tlb_current (vcpu); } -static void vt_flush_tlb_gva (struct kvm_vcpu *vcpu,gva_t addr,bool *full) +static void vt_flush_tlb_gva (struct kvm_vcpu *vcpu,gva_t addr) {if (is_td_vcpu (vcpu))return ; -vmx_flush_tlb_gva (vcpu, addr, full); +vmx_flush_tlb_gva (vcpu, addr); }static void vt_flush_tlb_guest (struct kvm_vcpu *vcpu)
arch/x86/kvm/vmx/vmx.c +1 -1
@@ -3377,7 +3377,7 @@ void vmx_flush_tlb_current(struct kvm_vcpu *vcpu)vpid_sync_context (vmx_get_current_vpid (vcpu)); } -void vmx_flush_tlb_gva (struct kvm_vcpu *vcpu,gva_t addr,bool *full) +void vmx_flush_tlb_gva (struct kvm_vcpu *vcpu,gva_t addr) {/* * vpid_sync_vcpu_addr() is a nop if vpid==0, see the comment in
arch/x86/kvm/vmx/x86_ops.h +1 -1
@@ -82,7 +82,7 @@ void vmx_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags);bool vmx_get_if_flag (struct kvm_vcpu *vcpu);void vmx_flush_tlb_all (struct kvm_vcpu *vcpu);void vmx_flush_tlb_current (struct kvm_vcpu *vcpu); -void vmx_flush_tlb_gva (struct kvm_vcpu *vcpu,gva_t addr,bool *full); +void vmx_flush_tlb_gva (struct kvm_vcpu *vcpu,gva_t addr);void vmx_flush_tlb_guest (struct kvm_vcpu *vcpu);void vmx_set_interrupt_shadow (struct kvm_vcpu *vcpu,int mask);u32 vmx_get_interrupt_shadow (struct kvm_vcpu *vcpu);
Signature · 1 line
2.52.0
Quoted 11 lines · Paolo Bonzini
The "full" out-argument in
flush_tlb_gvais only ever set on AMD processors, where the TLB flush is little more than a memory write and thus extremely cheap anyway.Simplify the code by letting the implementation of Hyper-V TLB flush hypercalls always go through all the addresses queued in
tlb_flush_fifo; there are no performance concerns since that is already the case on VMX, and also was on SVM prior to commit26505e1b5b54("KVM: SVM: makesvm_flush_tlb_gvado a full asid flush if NPT enabled", 2026-08-06).[...]
Applied to kvm-x86 misc, thanks!
[1/1] KVM: x86: remove "full" out-argument from flush_tlb_gva
https://github.com/kvm-x86/linux/commit/ba70065fec49