[Patch v6 3/3] KVM: SVM: Add host support for Enhanced SMT Protection
From: Pratik R. Sampat
Date: Sat Dec 05 2026 - 17:35:54 EST
Enhanced SMT Protection (ESMTP) protects an SEV-SNP guest for ZEN 5+
systems from SMT side channels by requiring that, while a vCPU is in
guest mode, its SMT sibling thread is either idle in host mode or
executing a vCPU the guest has declared to be a legal sibling. A legal
sibling is another ESMTP vCPU of the same guest that carries the same
VCPU_SIBLING_MASK and agrees on VCPU_ID outside that mask.
Hardware enforces this at VMRUN, which no longer enters guest mode right
away but stalls until the condition holds. Three new exits report that it
could not be met, all of them non-fatal:
ESMTP_ILLSIB: a sibling thread is running a vCPU that is not a legal
sibling of this one.
ESMTP_TIMEOUT: the stall exceeded the timeout programmed in the VMCB. The
timer bounds how long VMRUN waits for the core to settle. A module
parameter exposes an interface to program this timer.
ESMTP_RETRY: If DBREQ is detected, VMRUN exits. ESMTP_RETRY indicates an
internal event and the hypervisor should execute a VMRUN.
ESMTP synchronizes exits as well: when one thread leaves guest mode,
hardware kicks any sibling that is still running guest code by writing
the IDLE_WAKEUP_ICR MSR value to the APIC ICR. Program IDLE_WAKEUP_ICR
when ESMTP is supported, as is already done for SMT Protection.
ESMTP and SMT Protection are mutually exclusive, and VMRUN fails with
VMEXIT_INVALID if both are set, so reject KVM_SEV_INIT2 requests that
ask for both.
Refer to the AMD64 APM Vol 2, section "AMD64 Enhanced SMT Protection".
Reviewed-by: Tom Lendacky <thomas.lendacky@xxxxxxx>
Acked-by: Borislav Petkov (AMD) <bp@xxxxxxxxx> # non-virtualization changes
Signed-off-by: Pratik R. Sampat <prsampat@xxxxxxx>
---
v5..v6:
* Move IDLE_WAKEUP_ICR programming to patch 2 since SMT protection also
depends on it
---
.../admin-guide/kernel-parameters.txt | 19 +++++++++++
arch/x86/include/asm/cpufeatures.h | 1 +
arch/x86/include/asm/svm.h | 4 ++-
arch/x86/include/uapi/asm/svm.h | 9 +++++-
arch/x86/kernel/cpu/scattered.c | 1 +
arch/x86/kvm/svm/sev.c | 32 +++++++++++++++++--
arch/x86/kvm/svm/svm.c | 6 +++-
7 files changed, 67 insertions(+), 5 deletions(-)
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 515028e4ac46..2d9b3cbe32b9 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -3260,6 +3260,25 @@ Kernel parameters
max_snp_asid == min_sev_asid-1, will effectively make
SEV-ES unusable.
+ kvm-amd.esmtp_timeout_ns=
+ [KVM,AMD] Enhanced SMT Protection (ESMTP) VMRUN
+ timeout, in nanoseconds, for SEV-SNP guests that enable
+ ESMTP. When an ESMTP vCPU executes VMRUN, hardware
+ waits for every sibling thread to either be idle or
+ run a legal sibling vCPU of the same guest before
+ entering guest mode. If the wait exceeds this timeout,
+ VMRUN exits with VMEXIT_ESMTP_TIMEOUT and KVM retries
+ the VMRUN.
+
+ The value is converted to TSC cycles and programmed
+ into the VMCB when a vCPU is initialized, so changing
+ it at runtime only affects vCPUs that are created or
+ reset afterwards.
+
+ Default is 0, which disables the timeout, i.e. VMRUN
+ waits until the sibling condition is met or a physical
+ interrupt arrives.
+
kvm-arm.mode=
[KVM,ARM,EARLY] Select one of KVM/arm64's modes of
operation.
diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
index 4840e90ba3c4..359bbcf3b61e 100644
--- a/arch/x86/include/asm/cpufeatures.h
+++ b/arch/x86/include/asm/cpufeatures.h
@@ -537,6 +537,7 @@
* and purposes if CLEAR_CPU_BUF_VM is set).
*/
#define X86_FEATURE_X2AVIC_EXT (21*32+20) /* AMD SVM x2AVIC support for 4k vCPUs */
+#define X86_FEATURE_AMD_ESMTP (21*32+21) /* AMD Enhanced SMT Protection */
/*
* BUG word(s)
diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h
index a2331f5e533c..84122c7e7c50 100644
--- a/arch/x86/include/asm/svm.h
+++ b/arch/x86/include/asm/svm.h
@@ -165,7 +165,8 @@ struct __attribute__ ((__packed__)) vmcb_control_area {
u8 reserved_9[22];
u64 allowed_sev_features; /* Offset 0x138 */
u64 guest_sev_features; /* Offset 0x140 */
- u8 reserved_10[128];
+ u64 esmtp_timeout; /* Offset 0x148 */
+ u8 reserved_10[120];
u64 pml_addr; /* Offset 0x1c8 */
u16 pml_index; /* Offset 0x1d0 */
u8 reserved_11[526];
@@ -315,6 +316,7 @@ static_assert((X2AVIC_4K_MAX_PHYSICAL_ID & AVIC_PHYSICAL_MAX_INDEX_MASK) == X2AV
#define SVM_SEV_FEAT_DEBUG_SWAP BIT(5)
#define SVM_SEV_FEAT_SECURE_TSC BIT(9)
#define SVM_SEV_FEAT_SMTP BIT(15)
+#define SVM_SEV_FEAT_ESMTP BIT(17)
#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 f9f972177b08..66faf87fb5c2 100644
--- a/arch/x86/include/uapi/asm/svm.h
+++ b/arch/x86/include/uapi/asm/svm.h
@@ -137,6 +137,10 @@
#define SVM_EXIT_ERR -1ull
#define SVM_EXIT_IDLE_REQUIRED -3ull /* SMT Protection: sibling not idle */
+/* Enhanced SMT Protection VM exits taken during VMRUN sibling sync */
+#define SVM_EXIT_ESMTP_ILLSIB -5ull /* Illegal ESMTP sibling */
+#define SVM_EXIT_ESMTP_TIMEOUT -6ull /* ESMTP_TIMEOUT expired */
+#define SVM_EXIT_ESMTP_RETRY -7ull /* Internal event; retry VMRUN */
#define SVM_EXIT_REASONS \
{ SVM_EXIT_READ_CR0, "read_cr0" }, \
@@ -250,7 +254,10 @@
{ SVM_VMGEXIT_AP_CREATION, "vmgexit_ap_creation" }, \
{ SVM_VMGEXIT_HV_FEATURES, "vmgexit_hypervisor_feature" }, \
{ SVM_EXIT_ERR, "invalid_guest_state" }, \
- { SVM_EXIT_IDLE_REQUIRED, "idle_required" }
+ { SVM_EXIT_IDLE_REQUIRED, "idle_required" }, \
+ { SVM_EXIT_ESMTP_ILLSIB, "esmtp_illsib" }, \
+ { SVM_EXIT_ESMTP_TIMEOUT, "esmtp_timeout" }, \
+ { SVM_EXIT_ESMTP_RETRY, "esmtp_retry" }
#endif /* _UAPI__SVM_H */
diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattered.c
index c990245d29d6..6d0cf3bee31b 100644
--- a/arch/x86/kernel/cpu/scattered.c
+++ b/arch/x86/kernel/cpu/scattered.c
@@ -71,6 +71,7 @@ static const struct cpuid_bit cpuid_bits[] = {
{ X86_FEATURE_AMD_LBR_V2, CPUID_EAX, 1, 0x80000022, 0 },
{ X86_FEATURE_AMD_LBR_PMC_FREEZE, CPUID_EAX, 2, 0x80000022, 0 },
{ X86_FEATURE_RMPOPT, CPUID_EDX, 0, 0x80000025, 0 },
+ { X86_FEATURE_AMD_ESMTP, CPUID_EDX, 1, 0x80000025, 0 },
{ X86_FEATURE_AMD_HTR_CORES, CPUID_EAX, 30, 0x80000026, 0 },
{ 0, 0, 0, 0, 0 }
};
diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index ad802211ec4f..915acb2c973e 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -67,6 +67,11 @@ module_param_named(sev_snp, sev_snp_enabled, bool, 0444);
static unsigned int __ro_after_init nr_ciphertext_hiding_asids;
module_param_named(ciphertext_hiding_asids, nr_ciphertext_hiding_asids, uint, 0444);
+static unsigned int esmtp_timeout_ns;
+module_param(esmtp_timeout_ns, uint, 0644);
+MODULE_PARM_DESC(esmtp_timeout_ns,
+ "ESMTP VMRUN sibling-wait timeout in nanoseconds (default: 0, timer disabled)");
+
#define AP_RESET_HOLD_NONE 0
#define AP_RESET_HOLD_NAE_EVENT 1
#define AP_RESET_HOLD_MSR_PROTO 2
@@ -520,11 +525,17 @@ 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 | SVM_SEV_FEAT_SMTP);
+ valid_vmsa_features &= ~(SVM_SEV_FEAT_SECURE_TSC |
+ SVM_SEV_FEAT_ESMTP | SVM_SEV_FEAT_SMTP);
if (data->vmsa_features & ~valid_vmsa_features)
return -EINVAL;
+ /* VMRUN fails with VMEXIT_INVALID if both are set. */
+ if ((data->vmsa_features & SVM_SEV_FEAT_SMTP) &&
+ (data->vmsa_features & SVM_SEV_FEAT_ESMTP))
+ return -EINVAL;
+
if (data->ghcb_version > GHCB_VERSION_MAX || (!es_active && data->ghcb_version))
return -EINVAL;
@@ -1035,6 +1046,15 @@ static int sev_es_sync_vmsa(struct vcpu_svm *svm)
save->sev_features = sev->vmsa_features;
+ if (sev->vmsa_features & SVM_SEV_FEAT_ESMTP) {
+ save->vcpu_id = vcpu->vcpu_id;
+ /*
+ * All vCPUs of a guest are put into one group and can be run
+ * co-resident on the sibling thread of the same core.
+ */
+ save->vcpu_sibling_mask = U32_MAX;
+ }
+
/*
* Skip FPU and AVX setup with KVM_SEV_ES_INIT to avoid
* breaking older measurements.
@@ -3286,6 +3306,9 @@ void __init sev_hardware_setup(void)
if (sev_snp_enabled && cpu_feature_enabled(X86_FEATURE_SMT_PROT))
sev_supported_vmsa_features |= SVM_SEV_FEAT_SMTP;
+
+ if (sev_snp_enabled && cpu_feature_enabled(X86_FEATURE_AMD_ESMTP))
+ sev_supported_vmsa_features |= SVM_SEV_FEAT_ESMTP;
}
void sev_hardware_unsetup(void)
@@ -3322,7 +3345,8 @@ void sev_enable_idle_wakeup_icr(void)
unsigned int cpu, sibling, shift;
u32 core;
- if (!(sev_supported_vmsa_features & SVM_SEV_FEAT_SMTP))
+ if (!(sev_supported_vmsa_features &
+ (SVM_SEV_FEAT_SMTP | SVM_SEV_FEAT_ESMTP)))
return;
cpu = raw_smp_processor_id();
@@ -4865,6 +4889,10 @@ static void sev_es_init_vmcb(struct vcpu_svm *svm, bool init_event)
svm->vmcb->control.allowed_sev_features = sev->vmsa_features |
VMCB_ALLOWED_SEV_FEATURES_VALID;
+ if (sev->vmsa_features & SVM_SEV_FEAT_ESMTP)
+ svm->vmcb->control.esmtp_timeout = mul_u64_u32_div(esmtp_timeout_ns,
+ tsc_khz, 1000000);
+
/* Can't intercept CR register access, HV can't modify CR registers */
svm_clr_intercept(svm, INTERCEPT_CR0_READ);
svm_clr_intercept(svm, INTERCEPT_CR4_READ);
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 7183c33a51ed..2556dd4b961f 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -3872,8 +3872,12 @@ 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)
+ if (svm->vmcb->control.exit_code == SVM_EXIT_IDLE_REQUIRED ||
+ svm->vmcb->control.exit_code == SVM_EXIT_ESMTP_RETRY ||
+ svm->vmcb->control.exit_code == SVM_EXIT_ESMTP_ILLSIB ||
+ svm->vmcb->control.exit_code == SVM_EXIT_ESMTP_TIMEOUT) {
return 1;
+ }
if (exit_fastpath != EXIT_FASTPATH_NONE)
return 1;
--
2.43.0