[PATCH v1 06/28] KVM: SVM: Fallback to flush everything if FLUSHBYASID is not available

From: Yosry Ahmed

Date: Mon Jul 27 2026 - 20:37:22 EST


Currently, if FLUSHBYASID is not available when performing a TLB flush,
the fallback is decrementing the ASID generation to trigger allocating a
new ASID. In preparation for using a static ASID per vCPU (like VMX),
just fallback to flushing everything if FLUSHBYASID is not available.
This is probably worse from a performance perspective, but FLUSHBYASID
has been around for ~15 years and it's not worth carrying the
complexity.

Move the fallback logic into vmcb_set_flush_asid(), as more callers will
be added and will need the fallback as well. The only other current
caller is from SEV code, and no CPUs support SEV but not FLUSHBYASID (at
least according to AI).

Suggested-by: Sean Christopherson <seanjc@xxxxxxxxxx>
Signed-off-by: Yosry Ahmed <yosry@xxxxxxxxxx>
---
arch/x86/kvm/svm/svm.c | 5 +----
arch/x86/kvm/svm/svm.h | 5 ++++-
2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index de90320a2e669..aff1aae5a5a32 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -4198,10 +4198,7 @@ static void svm_flush_tlb_asid(struct kvm_vcpu *vcpu)
* unconditionally does a TLB flush on both nested VM-Enter and nested
* VM-Exit (via kvm_mmu_reset_context()).
*/
- if (static_cpu_has(X86_FEATURE_FLUSHBYASID))
- vmcb_set_flush_asid(svm->vmcb);
- else
- svm->current_vmcb->asid_generation--;
+ vmcb_set_flush_asid(svm->vmcb);
}

static void svm_flush_tlb_current(struct kvm_vcpu *vcpu)
diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h
index e3cce839573d9..2f18dff023bc5 100644
--- a/arch/x86/kvm/svm/svm.h
+++ b/arch/x86/kvm/svm/svm.h
@@ -479,7 +479,10 @@ static inline void vmcb_set_gpat(struct vmcb *vmcb, u64 data)

static inline void vmcb_set_flush_asid(struct vmcb *vmcb)
{
- vmcb->control.tlb_ctl = TLB_CONTROL_FLUSH_ASID;
+ if (static_cpu_has(X86_FEATURE_FLUSHBYASID))
+ vmcb->control.tlb_ctl = TLB_CONTROL_FLUSH_ASID;
+ else
+ vmcb->control.tlb_ctl = TLB_CONTROL_FLUSH_ALL_ASID;
}

static inline void vmcb_clr_flush_asid(struct vmcb *vmcb)
--
2.55.0.229.g6434b31f56-goog