Skip to contentSkip to conversation

KVM: SVM: Explicitly require FLUSHBYASID to enable SEV support

PATCH Applied Sean Christopherson 1 participant 2 messages Oct 18, 2023 – Dec 1, 2023

Subsystems (3)
lore
Share & tools
lore

Sean Christopherson

author maintainer
#0 lore raw

PATCH 1/1 KVM: SVM: Explicitly require FLUSHBYASID to enable SEV support

Add a sanity check that FLUSHBYASID is available if SEV is supported in hardware, as SEV (and beyond) guests are bound to a single ASID, i.e. KVM can't "flush" by assigning a new, fresh ASID to the guest. If FLUSHBYASID isn't supported for some bizarre reason, KVM would completely fail to do TLB flushes for SEV+ guests (see pre_svm_run() and pre_sev_run()).

---
 arch/x86/kvm/svm/sev.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
arch/x86/kvm/svm/sev.c +5 -2
index 4900c078045a..d0c580607f00 100644
@@ -2191,10 +2191,13 @@ void __init sev_hardware_setup(void)
 	/*
 	 * SEV must obviously be supported in hardware.  Sanity check that the
 	 * CPU supports decode assists, which is mandatory for SEV guests to
-	 * support instruction emulation.
+	 * support instruction emulation.  Ditto for flushing by ASID, as SEV
+	 * guests are bound to a single ASID, i.e. KVM can't rotate to a new
+	 * ASID to effect a TLB flush.
 	 */
 	if (!boot_cpu_has(X86_FEATURE_SEV) ||
-	    WARN_ON_ONCE(!boot_cpu_has(X86_FEATURE_DECODEASSISTS)))
+	    WARN_ON_ONCE(!boot_cpu_has(X86_FEATURE_DECODEASSISTS)) ||
+	    WARN_ON_ONCE(!boot_cpu_has(X86_FEATURE_FLUSHBYASID)))
 		goto out;
 
 	/* Retrieve SEV CPUID information */

base-commit: 437bba5ad2bba00c2056c896753a32edf80860cc

Signature · 1 line
2.42.0.655.g421f12c284-goog
author maintainer Applied
#1 lore raw
Quoted 8 lines · Sean Christopherson

Add a sanity check that FLUSHBYASID is available if SEV is supported in hardware, as SEV (and beyond) guests are bound to a single ASID, i.e. KVM can't "flush" by assigning a new, fresh ASID to the guest. If FLUSHBYASID isn't supported for some bizarre reason, KVM would completely fail to do TLB flushes for SEV+ guests (see pre_svm_run() and pre_sev_run()).

[...]

Applied to kvm-x86 svm, thanks!

[1/1] KVM: SVM: Explicitly require FLUSHBYASID to enable SEV support

      https://github.com/kvm-x86/linux/commit/770d6aa2e416

--
https://github.com/kvm-x86/linux/tree/next