[Patch v6 2/3] KVM: SVM: Add host support for SMT Protection
From: Pratik R. Sampat
Date: Sat Dec 05 2026 - 17:35:45 EST
SMT Protection (SMTP) protects an SEV-SNP guest for ZEN 4+ systems from
SMT side channels by requiring that, while one of its vCPUs is in guest
mode, every SMT sibling thread on that physical core is HLT idle in host
mode.
Hardware enforces this at VMRUN. If a sibling thread is not idle, VMRUN
does not enter guest mode and exits with the new VMEXIT_IDLE_REQUIRED
(exit code -3). The exit is not fatal: resume the vCPU and let VMRUN be
retried. Any event staged in EVENTINJ was not delivered in that case,
and svm_complete_interrupts() requeues it.
While the vCPU runs, its sibling is held in the idle state. If the idle
sibling receives an interrupt, hardware first kicks the vCPU's thread
out of guest mode by writing the value of the IDLE_WAKEUP_ICR MSR to the
APIC ICR, and only then lets the sibling leave the idle state to service
the interrupt. Program IDLE_WAKEUP_ICR on each CPU with an IPI to its
SMT sibling when virtualization is enabled on that CPU.
Refer to the AMD64 APM Vol 2, section "Side-Channel Protection".
Signed-off-by: Pratik R. Sampat <prsampat@xxxxxxx>
---
v5..v6:
* New patch - Introduce SMT protection
---
arch/x86/include/asm/cpufeatures.h | 1 +
arch/x86/include/asm/msr-index.h | 1 +
arch/x86/include/asm/svm.h | 1 +
arch/x86/include/uapi/asm/svm.h | 4 +++-
arch/x86/kvm/svm/sev.c | 30 +++++++++++++++++++++++++++++-
arch/x86/kvm/svm/svm.c | 5 +++++
arch/x86/kvm/svm/svm.h | 2 ++
7 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
index 303467a498b8..4840e90ba3c4 100644
--- a/arch/x86/include/asm/cpufeatures.h
+++ b/arch/x86/include/asm/cpufeatures.h
@@ -472,6 +472,7 @@
#define X86_FEATURE_DEBUG_SWAP (19*32+14) /* "debug_swap" SEV-ES full debug state swap support */
#define X86_FEATURE_RMPREAD (19*32+21) /* RMPREAD instruction */
#define X86_FEATURE_SEGMENTED_RMP (19*32+23) /* Segmented RMP support */
+#define X86_FEATURE_SMT_PROT (19*32+25) /* SMT Protection */
#define X86_FEATURE_ALLOWED_SEV_FEATURES (19*32+27) /* Allowed SEV Features */
#define X86_FEATURE_SVSM (19*32+28) /* "svsm" SVSM present */
#define X86_FEATURE_HV_INUSE_WR_ALLOWED (19*32+30) /* Allow Write to in-use hypervisor-owned pages */
diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
index 82182af9140f..1980f6d29788 100644
--- a/arch/x86/include/asm/msr-index.h
+++ b/arch/x86/include/asm/msr-index.h
@@ -772,6 +772,7 @@
#define MSR_AMD64_SEG_RMP_ENABLED_BIT 0
#define MSR_AMD64_SEG_RMP_ENABLED BIT_ULL(MSR_AMD64_SEG_RMP_ENABLED_BIT)
#define MSR_AMD64_RMP_SEGMENT_SHIFT(x) (((x) & GENMASK_ULL(13, 8)) >> 8)
+#define MSR_AMD64_IDLE_WAKEUP_ICR 0xc0010137
#define MSR_AMD64_RMPOPT_BASE 0xc0010139
#define MSR_AMD64_RMPOPT_ENABLE_BIT 0
#define MSR_AMD64_RMPOPT_ENABLE BIT_ULL(MSR_AMD64_RMPOPT_ENABLE_BIT)
diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h
index aceb405449a5..a2331f5e533c 100644
--- a/arch/x86/include/asm/svm.h
+++ b/arch/x86/include/asm/svm.h
@@ -314,6 +314,7 @@ static_assert((X2AVIC_4K_MAX_PHYSICAL_ID & AVIC_PHYSICAL_MAX_INDEX_MASK) == X2AV
#define SVM_SEV_FEAT_ALTERNATE_INJECTION BIT(4)
#define SVM_SEV_FEAT_DEBUG_SWAP BIT(5)
#define SVM_SEV_FEAT_SECURE_TSC BIT(9)
+#define SVM_SEV_FEAT_SMTP BIT(15)
#define VMCB_ALLOWED_SEV_FEATURES_VALID BIT_ULL(63)
diff --git a/arch/x86/include/uapi/asm/svm.h b/arch/x86/include/uapi/asm/svm.h
index e80676185092..f9f972177b08 100644
--- a/arch/x86/include/uapi/asm/svm.h
+++ b/arch/x86/include/uapi/asm/svm.h
@@ -136,6 +136,7 @@
#define SVM_EXIT_SW 0xf0000000ull
#define SVM_EXIT_ERR -1ull
+#define SVM_EXIT_IDLE_REQUIRED -3ull /* SMT Protection: sibling not idle */
#define SVM_EXIT_REASONS \
{ SVM_EXIT_READ_CR0, "read_cr0" }, \
@@ -248,7 +249,8 @@
{ SVM_VMGEXIT_EXT_GUEST_REQUEST, "vmgexit_ext_guest_request" }, \
{ SVM_VMGEXIT_AP_CREATION, "vmgexit_ap_creation" }, \
{ SVM_VMGEXIT_HV_FEATURES, "vmgexit_hypervisor_feature" }, \
- { SVM_EXIT_ERR, "invalid_guest_state" }
+ { SVM_EXIT_ERR, "invalid_guest_state" }, \
+ { SVM_EXIT_IDLE_REQUIRED, "idle_required" }
#endif /* _UAPI__SVM_H */
diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index b90c5f14c1ac..ad802211ec4f 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -520,7 +520,7 @@ static int __sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp,
return -EINVAL;
if (!snp_active)
- valid_vmsa_features &= ~SVM_SEV_FEAT_SECURE_TSC;
+ valid_vmsa_features &= ~(SVM_SEV_FEAT_SECURE_TSC | SVM_SEV_FEAT_SMTP);
if (data->vmsa_features & ~valid_vmsa_features)
return -EINVAL;
@@ -3283,6 +3283,9 @@ void __init sev_hardware_setup(void)
if (sev_snp_enabled && tsc_khz && cpu_feature_enabled(X86_FEATURE_SNP_SECURE_TSC))
sev_supported_vmsa_features |= SVM_SEV_FEAT_SECURE_TSC;
+
+ if (sev_snp_enabled && cpu_feature_enabled(X86_FEATURE_SMT_PROT))
+ sev_supported_vmsa_features |= SVM_SEV_FEAT_SMTP;
}
void sev_hardware_unsetup(void)
@@ -3314,6 +3317,31 @@ int sev_cpu_init(struct svm_cpu_data *sd)
return 0;
}
+void sev_enable_idle_wakeup_icr(void)
+{
+ unsigned int cpu, sibling, shift;
+ u32 core;
+
+ if (!(sev_supported_vmsa_features & SVM_SEV_FEAT_SMTP))
+ return;
+
+ cpu = raw_smp_processor_id();
+ shift = topology_get_domain_shift(TOPO_CORE_DOMAIN);
+ core = per_cpu(x86_cpu_to_apicid, cpu) >> shift;
+
+ for_each_present_cpu(sibling) {
+ u32 apicid = per_cpu(x86_cpu_to_apicid, sibling);
+ u64 icr;
+
+ if (sibling == cpu || (apicid >> shift) != core)
+ continue;
+
+ icr = (u64)apicid << 32;
+ icr |= LOCAL_TIMER_VECTOR;
+ WARN_ON_ONCE(wrmsrq_safe(MSR_AMD64_IDLE_WAKEUP_ICR, icr));
+ }
+}
+
/*
* Pages used by hardware to hold guest encrypted state must be flushed before
* returning them to the system.
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 8dbbc6beb74a..7183c33a51ed 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -603,6 +603,8 @@ static int svm_enable_virtualization_cpu(void)
__svm_write_tsc_multiplier(SVM_TSC_RATIO_DEFAULT);
}
+ sev_enable_idle_wakeup_icr();
+
svm_init_os_visible_workarounds();
svm_init_erratum_383();
@@ -3870,6 +3872,9 @@ static int svm_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
return 0;
}
+ if (svm->vmcb->control.exit_code == SVM_EXIT_IDLE_REQUIRED)
+ return 1;
+
if (exit_fastpath != EXIT_FASTPATH_NONE)
return 1;
diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h
index cd3242811e43..62139f49c2d1 100644
--- a/arch/x86/kvm/svm/svm.h
+++ b/arch/x86/kvm/svm/svm.h
@@ -1021,6 +1021,7 @@ void __init sev_set_cpu_caps(void);
void __init sev_hardware_setup(void);
void sev_hardware_unsetup(void);
int sev_cpu_init(struct svm_cpu_data *sd);
+void sev_enable_idle_wakeup_icr(void);
int sev_dev_get_attr(u32 group, u64 attr, u64 *val);
extern unsigned int max_sev_asid;
void sev_handle_rmp_fault(struct kvm_vcpu *vcpu, gpa_t gpa, u64 error_code);
@@ -1049,6 +1050,7 @@ static inline void __init sev_set_cpu_caps(void) {}
static inline void __init sev_hardware_setup(void) {}
static inline void sev_hardware_unsetup(void) {}
static inline int sev_cpu_init(struct svm_cpu_data *sd) { return 0; }
+static inline void sev_enable_idle_wakeup_icr(void) {}
static inline int sev_dev_get_attr(u32 group, u64 attr, u64 *val) { return -ENXIO; }
#define max_sev_asid 0
static inline void sev_handle_rmp_fault(struct kvm_vcpu *vcpu, gpa_t gpa, u64 error_code) {}
--
2.43.0