[RFC PATCH 9/9] KVM: SVM: Enable Alternate Injection for an SEV-SNP guest
From: Melody Wang
Date: Tue Nov 10 2026 - 03:45:48 EST
When the SVSM detects that the hypervisor supports Alternate Injection,
it can configure Alternate Injection and create APs with it enabled in
sev_features.
Add Alternate Injection support to the hypervisor advertised features
Signed-off-by: Melody Wang <huibo.wang@xxxxxxx>
---
arch/x86/include/asm/cpufeatures.h | 1 +
arch/x86/include/asm/sev-common.h | 1 +
arch/x86/kvm/svm/sev.c | 12 +++++++++++-
3 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
index 41af7bd2473c..b2746a4d926a 100644
--- a/arch/x86/include/asm/cpufeatures.h
+++ b/arch/x86/include/asm/cpufeatures.h
@@ -454,6 +454,7 @@
#define X86_FEATURE_V_TSC_AUX (19*32+ 9) /* Virtual TSC_AUX */
#define X86_FEATURE_SME_COHERENT (19*32+10) /* hardware-enforced cache coherency */
#define X86_FEATURE_RESTRICTED_INJECTION (19*32+12) /* Restricted Injection */
+#define X86_FEATURE_ALTERNATE_INJECTION (19*32+13) /* Alternate Injection */
#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 */
diff --git a/arch/x86/include/asm/sev-common.h b/arch/x86/include/asm/sev-common.h
index a09cf5690aba..62f0c3aa7549 100644
--- a/arch/x86/include/asm/sev-common.h
+++ b/arch/x86/include/asm/sev-common.h
@@ -145,6 +145,7 @@ enum psc_op {
#define GHCB_HV_FT_SNP_RINJ (BIT_ULL(2) | GHCB_HV_FT_SNP_AP_CREATION)
#define GHCB_HV_FT_APIC_ID_LIST BIT_ULL(4)
#define GHCB_HV_FT_SNP_MULTI_VMPL BIT_ULL(5)
+#define GHCB_HV_FT_SNP_ALT_INJ BIT_ULL(9)
/*
* SNP Page State Change NAE event
diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 7846d4ebb278..fd0212abc3af 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -44,6 +44,7 @@
GHCB_HV_FT_SNP_AP_CREATION | \
GHCB_HV_FT_SNP_RINJ | \
GHCB_HV_FT_APIC_ID_LIST | \
+ GHCB_HV_FT_SNP_ALT_INJ | \
GHCB_HV_FT_SNP_MULTI_VMPL)
/*
@@ -72,6 +73,10 @@ module_param_named(sev_snp, sev_snp_enabled, bool, 0444);
static bool sev_snp_restricted_injection_enabled = true;
module_param_named(restricted_injection, sev_snp_restricted_injection_enabled, bool, 0444);
+/* enable/disable SEV-SNP Alternate Injection support */
+static bool sev_snp_alternate_injection_enabled = true;
+module_param_named(alternate_injection, sev_snp_alternate_injection_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);
@@ -3242,9 +3247,14 @@ void __init sev_hardware_setup(void)
if (!sev_snp_enabled || !cpu_feature_enabled(X86_FEATURE_RESTRICTED_INJECTION))
sev_snp_restricted_injection_enabled = false;
+ if (!sev_snp_enabled || !cpu_feature_enabled(X86_FEATURE_ALTERNATE_INJECTION))
+ sev_snp_alternate_injection_enabled = false;
- if (sev_snp_restricted_injection_enabled)
+ if (sev_snp_restricted_injection_enabled) {
sev_supported_vmsa_features |= SVM_SEV_FEAT_RESTRICTED_INJECTION;
+ if (sev_snp_alternate_injection_enabled)
+ sev_supported_vmsa_features |= SVM_SEV_FEAT_ALTERNATE_INJECTION;
+ }
}
void sev_hardware_unsetup(void)
--
2.43.0