* [Patch v6 0/3] Host support for SMT and Enhanced SMT Protection
@ 2026-12-05 22:34 Pratik R. Sampat
2026-12-05 22:34 ` [Patch v6 1/3] KVM: SVM: Re-queue events that were never injected Pratik R. Sampat
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Pratik R. Sampat @ 2026-12-05 22:34 UTC (permalink / raw)
To: x86, kvm, linux-doc, linux-kernel
Cc: tglx, mingo, bp, dave.hansen, haiyangz, wei.liu, seanjc, pbonzini,
thomas.lendacky, kim.phillips, nikunj, michael.roth, ashish.kalra,
prsampat
SMT Protection (SMTP) and Enhanced SMT Protection (ESMTP) let an
SEV-SNP VM control what may run on the SMT sibling of a thread that is
executing one of its vCPUs. This mitigates the side-channel risk of
sharing core resources with untrusted host threads or with another
guest.
SMTP (Zen 4 and later) requires every sibling thread on the physical
core to be idle in host mode while the vCPU is in guest mode, which
gives up half of every core the VM runs on.
ESMTP (Zen 5 and later) relaxes that: a sibling may also run a vCPU
the guest has declared a legal sibling. A legal sibling is another
ESMTP vCPU of the same guest (matching ASID) with the same
VCPU_SIBLING_MASK and the same VCPU_ID outside that mask.
Unlike core scheduling, where co-residency is a host kernel policy
expressed with cookies, both features are enforced by hardware. For
ESMTP the policy lives in the VMSA. The host is not trusted to keep
its own kernel, userspace, or interrupt-handling work off a sibling
thread while a protected vCPU is in guest mode.
Series
----------
Patch 1 is a prerequisite. KVM has assumed that a #VMEXIT with
EVENTINJ still valid only happens on VMEXIT_INVALID, after which the
guest is torn down. With SMTP and ESMTP, VMRUN can end with an
ordinary exit code without entering guest mode, so the staged event
was never delivered. Detect that in svm_complete_interrupts() and
requeue the event instead of dropping it.
Patch 2 adds SMTP: the CPUID feature bit, IDLE_WAKEUP_ICR, retrying
VMRUN on VMEXIT_IDLE_REQUIRED, and advertising SVM_SEV_FEAT_SMTP
through KVM_X86_SEV_VMSA_FEATURES so userspace can request it with
KVM_SEV_INIT2. IDLE_WAKEUP_ICR is programmed on each CPU when
virtualization is enabled on it.
Patch 3 adds ESMTP on top: the scattered CPUID bit, the VMCB timeout
field, retrying the three new exits, populating VCPU_ID and
VCPU_SIBLING_MASK in the launch VMSAs KVM builds, KVM fully sets
VCPU_SIBLING_MASK, as the guest does for its APs, so every vCPU of the
guest may be co-resident with any other.
Merging
-------
Following the discussion on v4, guest and host support are now split
into separate series to untangle x86 and KVM. Since the guest series
from v5 is now pushed to tip, this series adds the KVM host side.
8509996df261 ("x86/sev: Add Enhanced SMT Protection fields to the VMSA")
0d4aa2a4f846 ("x86/sev: Add guest support for Enhanced SMT Protection")
SMTP needs no guest changes.
Testing
-------
It is tested with the v5 guest patches and patched OVMF [1] and
QEMU [2] builds. Launch an SEV-SNP guest with ESMTP enabled on the
sev-snp-guest object:
For SMTP:
-object sev-snp-guest,id=sev0,cbitpos=51,reduced-phys-bits=1,smtp=on
Or,
For ESMTP:
-object sev-snp-guest,id=sev0,cbitpos=51,reduced-phys-bits=1,esmtp=on
SMTP and ESMTP are mutually exclusive.
The guest reports the feature in dmesg among the SNP feature names:
# dmesg | grep -i SEV
... SEV-SNP ... SMTProt ...
Or,
... SEV-SNP ... ESMTProt ...
To check the sibling behaviour on an SMT=2 host:
* Identify a sibling pair X and Y on the host:
cat /sys/devices/system/cpu/cpuX/topology/thread_siblings_list
* Pin two of the guest's vCPUs to X and Y.
* Load both vCPUs in the guest, e.g. stress-ng --cpu 2.
* With SMTP: host CPUs should show 50% guest utilization each, since
the two vCPUs cannot run together at once and one sibling thread
must idle when the other runs.
* With ESMTP: Both host CPUs should show 100% guest utilization, since
the two vCPUs are legal siblings.
* Start a host task on one of the pair, e.g. taskset -c X stress-ng
--cpu 1. CPU X's time should now be split between host and guest.
* With SMTP: guest utilization on CPU Y should remain relatively
unchanged since it already must remain idle regardless of what runs
on CPU X.
* With ESMTP: guest utilization on CPU Y should drop, since the vCPU
on Y cannot enter guest mode while the host task runs on X.
Based on tip/master.
v6:
* Host support only. Guest support was split out in v5 and is in tip.
* New patch 2: host support for regular SMT Protection. SMTP is less
flexible than ESMTP, since it keeps the sibling idle instead of
allowing a legal sibling vCPU, but ESMTP needs Zen 5 or later while
SMTP is available from Zen 4.
* Move IDLE_WAKEUP_ICR programming which is used by both SMTP and ESMTP
to the former patch. Since functionally the patch remains the,
retaining reviewed-by's.
* Patch 1: update the commit message and comment to cover SMTP as well
as ESMTP.
* Patch 3: reject KVM_SEV_INIT2 requests that set both SMTP and ESMTP,
now that KVM can advertise both.
v5: https://lore.kernel.org/kvm/cover.1794935627.git.prsampat@amd.com/
* Split guest and host support into separate series, per Sean and
Boris [4]. This series carries guest support only.
* New patch 1: move the VCPU_ID/VCPU_SIBLING_MASK VMSA definitions out
of the KVM host patch so that the guest side builds on its own.
Retaining Tom's reviewed-by since it is functionally unchanged.
* Drop the sibling-mask comments from patches 2 and 3 - Boris
* Rebase onto tip/master.
v4: https://lore.kernel.org/all/cover.1794244450.git.prsampat@amd.com/
* Fix conflict of reserved bits introduced by PML support in
vmcb_control_area
v3: https://lore.kernel.org/kvm/cover.1792184487.git.prsampat@amd.com
* Collected Reviewed-by tags - Tom
* Use sev_status to determine SNP support for guest as well - Tom
* Not syncing the tools/ copy of msr-index.h, since several bits apart
from ESMTP differ and the perf tooling maintainers usually sync it.
Happy to add a sync patch if needed.
v2: https://lore.kernel.org/kvm/cover.1791302373.git.prsampat@amd.com/
* Populate the ESMTP VMSA fields for Hyper-V AP bring-up - Sashiko
* Add ESMTP to SNP_FEATURES_IMPL and SNP_FEATURES_IMPL_REQ - local
Sashiko instance
v1: https://lore.kernel.org/kvm/cover.1789399214.git.prsampat@amd.com
[1]: https://github.com/tianocore/edk2/pull/13128
[2]: https://lists.nongnu.org/archive/html/qemu-devel/2026-12/msg01488.html
[3]: https://lore.kernel.org/all/avc-5lkQhoR6US9o@google.com/
Pratik R. Sampat (3):
KVM: SVM: Re-queue events that were never injected
KVM: SVM: Add host support for SMT Protection
KVM: SVM: Add host support for Enhanced SMT Protection
.../admin-guide/kernel-parameters.txt | 19 ++++++
arch/x86/include/asm/cpufeatures.h | 2 +
arch/x86/include/asm/msr-index.h | 1 +
arch/x86/include/asm/svm.h | 5 +-
arch/x86/include/uapi/asm/svm.h | 11 +++-
arch/x86/kernel/cpu/scattered.c | 1 +
arch/x86/kvm/svm/sev.c | 58 ++++++++++++++++++-
arch/x86/kvm/svm/svm.c | 42 ++++++++++++--
arch/x86/kvm/svm/svm.h | 2 +
9 files changed, 134 insertions(+), 7 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Patch v6 1/3] KVM: SVM: Re-queue events that were never injected
2026-12-05 22:34 [Patch v6 0/3] Host support for SMT and Enhanced SMT Protection Pratik R. Sampat
@ 2026-12-05 22:34 ` Pratik R. Sampat
2026-12-05 22:34 ` [Patch v6 2/3] KVM: SVM: Add host support for SMT Protection Pratik R. Sampat
2026-12-05 22:35 ` [Patch v6 3/3] KVM: SVM: Add host support for Enhanced " Pratik R. Sampat
2 siblings, 0 replies; 4+ messages in thread
From: Pratik R. Sampat @ 2026-12-05 22:34 UTC (permalink / raw)
To: x86, kvm, linux-doc, linux-kernel
Cc: tglx, mingo, bp, dave.hansen, haiyangz, wei.liu, seanjc, pbonzini,
thomas.lendacky, kim.phillips, nikunj, michael.roth, ashish.kalra,
prsampat
When injecting an event into the guest via the event_inj field, a
non-zero event_inj value on #VMEXIT means that the hardware was not able
to inject the event into the guest. This used to only occur for the
VMEXIT_INVALID intercept code, which was a fatal error and resulted in
the guest being torn down.
SMT protection (SMTP) and Enhanced SMT Protection (ESMTP) invalidates
that assumption. When enabled, VMRUN doesn't enter guest mode
immediately; it stalls at a synchronization point until every sibling
thread is either idle or has executed VMRUN for a legal sibling vCPU.
If a timeout / illegal sibling exit / interrupt arrives while VMRUN is
stalled, VMRUN can now terminate with the corresponding #VMEXIT
intercept code, without entering guest mode, and thus without injecting
the event.
For example, on a 2-way SMT core running vCPU0 on thread 0 and vCPU1 on
thread 1:
Thread 0 (vCPU0) Thread 1 (vCPU1)
---------------- ----------------
Interrupt A injected to the guest in host
VMRUN |
| |
v |
Stall waiting for sibling |
| |
| host INTR arrives on thread 0 |
| while it waits |
| |
v |
#VMEXIT v
Interrupt B injected to the guest idle
VMRUN
In this case injecting interrupt B clobbers the last event. Interrupt A
is never delivered and lost forever.
Therefore, in preparation for [E]SMTP support, accommodate for
potentially lost interrupts by detecting an undelivered injected event
and re-queuing it so as not to lose the event.
svm_cancel_injection() already recovers a staged event this way and
becomes redundant, so fold it in.
Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Pratik R. Sampat <prsampat@amd.com>
---
v5..v6:
* Massage commit message to include SMT protection case
---
arch/x86/kvm/svm/svm.c | 33 +++++++++++++++++++++++++++++----
1 file changed, 29 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 47987f5ce095..8dbbc6beb74a 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -4482,6 +4482,7 @@ static void svm_complete_interrupts(struct kvm_vcpu *vcpu)
struct vcpu_svm *svm = to_svm(vcpu);
u8 vector;
int type;
+ struct vmcb_control_area *control = &svm->vmcb->control;
u32 exitintinfo = svm->vmcb->control.exit_int_info;
bool nmi_l1_to_l2 = svm->nmi_l1_to_l2;
bool soft_int_injected = svm->soft_int_injected;
@@ -4489,6 +4490,27 @@ static void svm_complete_interrupts(struct kvm_vcpu *vcpu)
svm->nmi_l1_to_l2 = false;
svm->soft_int_injected = false;
+ /*
+ * Hardware clears EVENTINJ field when it injects an event.
+ * A non-empty EVENTINJ on #VMEXIT means the vCPU never entered guest
+ * mode, and thus that the event was never delivered. Migrate the event
+ * to EXITINTINFO so that it's requeued instead of being dropped.
+ *
+ * An undelivered event doesn't imply a fatal VMEXIT_INVALID. With
+ * SMT Protection and Enhanced SMT Protection, VMRUN may exit with an
+ * ordinary #VMEXIT without having injected that event into the guest.
+ *
+ * Clobbering EXITINTINFO is safe precisely because the vCPU never
+ * entered guest mode.
+ */
+ if (control->event_inj) {
+ control->exit_int_info = control->event_inj;
+ control->exit_int_info_err = control->event_inj_err;
+ control->event_inj = 0;
+
+ exitintinfo = control->exit_int_info;
+ }
+
/*
* If we've made progress since setting awaiting_iret_completion, we've
* executed an IRET and can allow NMI injection.
@@ -4552,11 +4574,14 @@ static void svm_complete_interrupts(struct kvm_vcpu *vcpu)
static void svm_cancel_injection(struct kvm_vcpu *vcpu)
{
struct vcpu_svm *svm = to_svm(vcpu);
- struct vmcb_control_area *control = &svm->vmcb->control;
- control->exit_int_info = control->event_inj;
- control->exit_int_info_err = control->event_inj_err;
- control->event_inj = 0;
+ /*
+ * EXITINTINFO is stale as it holds the event from the previous #VMEXIT
+ * (or from the last time the current VMCB was run). Invalidate it so
+ * that svm_complete_interrupts() requeues if and only if KVM staged an
+ * event in EVENTINJ.
+ */
+ svm->vmcb->control.exit_int_info = 0;
svm_complete_interrupts(vcpu);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Patch v6 2/3] KVM: SVM: Add host support for SMT Protection
2026-12-05 22:34 [Patch v6 0/3] Host support for SMT and Enhanced SMT Protection Pratik R. Sampat
2026-12-05 22:34 ` [Patch v6 1/3] KVM: SVM: Re-queue events that were never injected Pratik R. Sampat
@ 2026-12-05 22:34 ` Pratik R. Sampat
2026-12-05 22:35 ` [Patch v6 3/3] KVM: SVM: Add host support for Enhanced " Pratik R. Sampat
2 siblings, 0 replies; 4+ messages in thread
From: Pratik R. Sampat @ 2026-12-05 22:34 UTC (permalink / raw)
To: x86, kvm, linux-doc, linux-kernel
Cc: tglx, mingo, bp, dave.hansen, haiyangz, wei.liu, seanjc, pbonzini,
thomas.lendacky, kim.phillips, nikunj, michael.roth, ashish.kalra,
prsampat
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@amd.com>
---
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Patch v6 3/3] KVM: SVM: Add host support for Enhanced SMT Protection
2026-12-05 22:34 [Patch v6 0/3] Host support for SMT and Enhanced SMT Protection Pratik R. Sampat
2026-12-05 22:34 ` [Patch v6 1/3] KVM: SVM: Re-queue events that were never injected Pratik R. Sampat
2026-12-05 22:34 ` [Patch v6 2/3] KVM: SVM: Add host support for SMT Protection Pratik R. Sampat
@ 2026-12-05 22:35 ` Pratik R. Sampat
2 siblings, 0 replies; 4+ messages in thread
From: Pratik R. Sampat @ 2026-12-05 22:35 UTC (permalink / raw)
To: x86, kvm, linux-doc, linux-kernel
Cc: tglx, mingo, bp, dave.hansen, haiyangz, wei.liu, seanjc, pbonzini,
thomas.lendacky, kim.phillips, nikunj, michael.roth, ashish.kalra,
prsampat
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@amd.com>
Acked-by: Borislav Petkov (AMD) <bp@alien8.de> # non-virtualization changes
Signed-off-by: Pratik R. Sampat <prsampat@amd.com>
---
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-05 22:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 22:34 [Patch v6 0/3] Host support for SMT and Enhanced SMT Protection Pratik R. Sampat
2026-12-05 22:34 ` [Patch v6 1/3] KVM: SVM: Re-queue events that were never injected Pratik R. Sampat
2026-12-05 22:34 ` [Patch v6 2/3] KVM: SVM: Add host support for SMT Protection Pratik R. Sampat
2026-12-05 22:35 ` [Patch v6 3/3] KVM: SVM: Add host support for Enhanced " Pratik R. Sampat
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.