KVM: SEV: Add support for IBPB-on-Entry
cover KVM: SEV: Add support for IBPB-on-Entry
AMD EPYC 5th generation and above processors support IBPB-on-Entry for SNP guests. By invoking an Indirect Branch Prediction Barrier (IBPB) on VMRUN, old indirect branch predictions are prevented from influencing indirect branches within the guest.
The first patch is guest-side support which unmasks the Zen5+ feature bit to allow kernel guests to set the feature.
The second patch is host-side support that checks the CPUID and then sets the feature bit in the VMSA supported features mask.
Based on https://github.com/kvm-x86/linux kvm-x86/next (kvm-x86-next-2026.01.23, e81f7c908e16).
This series also available here:
https://github.com/AMDESE/linux/tree/ibpb-on-entry-latest
Advance qemu bits (to add ibpb-on-entry=on/off switch) available here:
https://github.com/AMDESE/qemu/tree/ibpb-on-entry-latest
Qemu bits will be posted upstream once kernel bits are merged. They depend on Naveen Rao's "target/i386: SEV: Add support for enabling VMSA SEV features":
https://lore.kernel.org/qemu-devel/[email protected]/
Kim Phillips (2):
KVM: SEV: IBPB-on-Entry guest support
KVM: SEV: Add support for IBPB-on-Entry
arch/x86/boot/compressed/sev.c | 1 + arch/x86/coco/sev/core.c | 1 + arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/msr-index.h | 5 ++++- arch/x86/include/asm/svm.h | 1 + arch/x86/kvm/svm/sev.c | 9 ++++++++- 6 files changed, 16 insertions(+), 2 deletions(-)
base-commit: e81f7c908e1664233974b9f20beead78cde6343a
Signature · 1 line
2.43.0
PATCH 1/2 KVM: SEV: IBPB-on-Entry guest support
The SEV-SNP IBPB-on-Entry feature does not require a guest-side implementation. The feature was added in Zen5 h/w, after the first SNP Zen implementation, and thus was not accounted for when the initial set of SNP features were added to the kernel.
In its abundant precaution, commit 8c29f0165405 ("x86/sev: Add SEV-SNP guest feature negotiation support") included SEV_STATUS' IBPB-on-Entry bit as a reserved bit, thereby masking guests from using the feature.
Unmask the bit, to allow guests to take advantage of the feature on hypervisor kernel versions that support it: Amend the SEV_STATUS MSR SNP_RESERVED_MASK to exclude bit 23 (IbpbOnEntry).
--- arch/x86/boot/compressed/sev.c | 1 + arch/x86/coco/sev/core.c | 1 + arch/x86/include/asm/msr-index.h | 5 ++++- 3 files changed, 6 insertions(+), 1 deletion(-)
arch/x86/boot/compressed/sev.c +1 -0
@@ -188,6 +188,7 @@ bool sev_es_check_ghcb_fault(unsigned long address)MSR_AMD64_SNP_RESERVED_BIT13 | \MSR_AMD64_SNP_RESERVED_BIT15 | \MSR_AMD64_SNP_SECURE_AVIC | \ +MSR_AMD64_SNP_RESERVED_BITS19_22 | \ MSR_AMD64_SNP_RESERVED_MASK) #ifdef CONFIG_AMD_SECURE_AVIC
arch/x86/coco/sev/core.c +1 -0
@@ -122,6 +122,7 @@ static const char * const sev_status_feat_names[] = { [MSR_AMD64_SNP_VMSA_REG_PROT_BIT] = "VMSARegProt", [MSR_AMD64_SNP_SMT_PROT_BIT] = "SMTProt", [MSR_AMD64_SNP_SECURE_AVIC_BIT] = "SecureAVIC", + [MSR_AMD64_SNP_IBPB_ON_ENTRY_BIT] = "IBPBOnEntry", };/*
arch/x86/include/asm/msr-index.h +4 -1
@@ -735,7 +735,10 @@#define MSR_AMD64_SNP_SMT_PROT BIT_ULL(MSR_AMD64_SNP_SMT_PROT_BIT)#define MSR_AMD64_SNP_SECURE_AVIC_BIT 18#define MSR_AMD64_SNP_SECURE_AVIC BIT_ULL(MSR_AMD64_SNP_SECURE_AVIC_BIT) -#define MSR_AMD64_SNP_RESV_BIT 19 +#define MSR_AMD64_SNP_RESERVED_BITS19_22 GENMASK_ULL(22, 19) +#define MSR_AMD64_SNP_IBPB_ON_ENTRY_BIT 23 +#define MSR_AMD64_SNP_IBPB_ON_ENTRY BIT_ULL(MSR_AMD64_SNP_IBPB_ON_ENTRY_BIT) +#define MSR_AMD64_SNP_RESV_BIT 24#define MSR_AMD64_SNP_RESERVED_MASK GENMASK_ULL(63, MSR_AMD64_SNP_RESV_BIT)#define MSR_AMD64_SAVIC_CONTROL 0xc0010138#define MSR_AMD64_SAVIC_EN_BIT 0
Signature · 1 line
2.43.0
PATCH 2/2 KVM: SEV: Add support for IBPB-on-Entry
In reply to Kim PhillipsAMD EPYC 5th generation and above processors support IBPB-on-Entry for SNP guests. By invoking an Indirect Branch Prediction Barrier (IBPB) on VMRUN, old indirect branch predictions are prevented from influencing indirect branches within the guest.
SNP guests may choose to enable IBPB-on-Entry by setting SEV_FEATURES bit 21 (IbpbOnEntry).
Host support for IBPB on Entry is indicated by CPUID Fn8000_001F[IbpbOnEntry], bit 31.
If supported, indicate support for IBPB on Entry in sev_supported_vmsa_features bit 23 (IbpbOnEntry).
For more info, refer to page 615, Section 15.36.17 "Side-Channel Protection", AMD64 Architecture Programmer's Manual Volume 2: System Programming Part 2, Pub. 24593 Rev. 3.42 - March 2024 (see Link).
--- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/svm.h | 1 + arch/x86/kvm/svm/sev.c | 9 ++++++++- 3 files changed, 10 insertions(+), 1 deletion(-)
arch/x86/include/asm/cpufeatures.h +1 -0
@@ -459,6 +459,7 @@#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 */ +#define X86_FEATURE_IBPB_ON_ENTRY (19*32+31)/* SEV-SNP IBPB on VM Entry */ /* AMD-defined Extended Feature 2 EAX, CPUID level 0x80000021 (EAX), word 20 */ #define X86_FEATURE_NO_NESTED_DATA_BP (20*32+ 0)/* No Nested Data Breakpoints */
arch/x86/include/asm/svm.h +1 -0
@@ -306,6 +306,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_IBPB_ON_ENTRY BIT(21)#define VMCB_ALLOWED_SEV_FEATURES_VALID BIT_ULL(63)
arch/x86/kvm/svm/sev.c +8 -1
@@ -3165,8 +3165,15 @@ void __init sev_hardware_setup(void) cpu_feature_enabled(X86_FEATURE_NO_NESTED_DATA_BP)) sev_supported_vmsa_features |=SVM_SEV_FEAT_DEBUG_SWAP ; -if (sev_snp_enabled && tsc_khz &&cpu_feature_enabled (X86_FEATURE_SNP_SECURE_TSC )) +if (!sev_snp_enabled) +return ; +/* the following feature bit checks are SNP specific */ + +if (tsc_khz &&cpu_feature_enabled (X86_FEATURE_SNP_SECURE_TSC )) sev_supported_vmsa_features |=SVM_SEV_FEAT_SECURE_TSC ; + +if (cpu_feature_enabled (X86_FEATURE_IBPB_ON_ENTRY )) + sev_supported_vmsa_features |=SVM_SEV_FEAT_IBPB_ON_ENTRY ; }void sev_hardware_unsetup (void )
Signature · 1 line
2.43.0
Re: [PATCH 1/2] KVM: SEV: IBPB-on-Entry guest support
In reply to Kim PhillipsQuoted 1 line · Kim Phillips
KVM: SEV: IBPB-on-Entry guest support
The subject line should have the prefix "x86/sev" instead of "KVM: SEV". The below subject line would be more appropriate:
x86/sev: Allow IBPB-on-Entry feature for SNP guests
Quoted 13 lines
The SEV-SNP IBPB-on-Entry feature does not require a guest-side implementation. The feature was added in Zen5 h/w, after the first SNP Zen implementation, and thus was not accounted for when the initial set of SNP features were added to the kernel.
In its abundant precaution, commit
8c29f0165405("x86/sev: Add SEV-SNP guest feature negotiation support") includedSEV_STATUS' IBPB-on-Entry bit as a reserved bit, thereby masking guests from using the feature.Unmask the bit, to allow guests to take advantage of the feature on hypervisor kernel versions that support it: Amend the
SEV_STATUSMSRSNP_RESERVED_MASKto exclude bit 23 (IbpbOnEntry).
Quoted 6 lines
Fixes 8c29f0165405 ("x86/sev: Add SEV-SNP guest feature negotiation support")> Cc: Nikunj A Dadhania <[email protected]>Cc Tom Lendacky <[email protected]>CC Borislav Petkov (AMD) <[email protected]>CC Michael Roth <[email protected]>Signed-off-by Kim Phillips <[email protected]>
Apart from the above comments:
Quoted 46 lines
--- arch/x86/boot/compressed/sev.c | 1 + arch/x86/coco/sev/core.c | 1 + arch/x86/include/asm/msr-index.h | 5 ++++- 3 files changed, 6 insertions(+), 1 deletion(-)arch/x86/boot/compressed/sev.c +1
-0@@ -188,6 +188,7 @@ bool sev_es_check_ghcb_fault(unsigned long address)MSR_AMD64_SNP_RESERVED_BIT13 | \MSR_AMD64_SNP_RESERVED_BIT15 | \MSR_AMD64_SNP_SECURE_AVIC | \ +MSR_AMD64_SNP_RESERVED_BITS19_22 | \ MSR_AMD64_SNP_RESERVED_MASK) #ifdef CONFIG_AMD_SECURE_AVICarch/x86/coco/sev/core.c +1
-0@@ -122,6 +122,7 @@ static const char * const sev_status_feat_names[] = { [MSR_AMD64_SNP_VMSA_REG_PROT_BIT] = "VMSARegProt", [MSR_AMD64_SNP_SMT_PROT_BIT] = "SMTProt", [MSR_AMD64_SNP_SECURE_AVIC_BIT] = "SecureAVIC", + [MSR_AMD64_SNP_IBPB_ON_ENTRY_BIT] = "IBPBOnEntry", };/* arch/x86/include/asm/msr-index.h +4
-1@@ -735,7 +735,10 @@#define MSR_AMD64_SNP_SMT_PROT BIT_ULL(MSR_AMD64_SNP_SMT_PROT_BIT)#define MSR_AMD64_SNP_SECURE_AVIC_BIT 18#define MSR_AMD64_SNP_SECURE_AVIC BIT_ULL(MSR_AMD64_SNP_SECURE_AVIC_BIT) -#define MSR_AMD64_SNP_RESV_BIT 19 +#define MSR_AMD64_SNP_RESERVED_BITS19_22 GENMASK_ULL(22, 19) +#define MSR_AMD64_SNP_IBPB_ON_ENTRY_BIT 23 +#define MSR_AMD64_SNP_IBPB_ON_ENTRY BIT_ULL(MSR_AMD64_SNP_IBPB_ON_ENTRY_BIT) +#define MSR_AMD64_SNP_RESV_BIT 24#define MSR_AMD64_SNP_RESERVED_MASK GENMASK_ULL(63, MSR_AMD64_SNP_RESV_BIT)#define MSR_AMD64_SAVIC_CONTROL 0xc0010138#define MSR_AMD64_SAVIC_EN_BIT 0
Quoted 55 lines · Kim Phillips
AMD EPYC 5th generation and above processors support IBPB-on-Entry for SNP guests. By invoking an Indirect Branch Prediction Barrier (IBPB) on VMRUN, old indirect branch predictions are prevented from influencing indirect branches within the guest.
SNP guests may choose to enable IBPB-on-Entry by setting
SEV_FEATURESbit 21 (IbpbOnEntry).Host support for IBPB on Entry is indicated by CPUID Fn8000_001F[IbpbOnEntry], bit 31.
If supported, indicate support for IBPB on Entry in
sev_supported_vmsa_featuresbit 23 (IbpbOnEntry).For more info, refer to page 615, Section 15.36.17 "Side-Channel Protection", AMD64 Architecture Programmer's Manual Volume 2: System Programming Part 2, Pub. 24593 Rev. 3.42 - March 2024 (see Link).
Signed-off-by Kim Phillips <[email protected]>--- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/svm.h | 1 + arch/x86/kvm/svm/sev.c | 9 ++++++++- 3 files changed, 10 insertions(+), 1 deletion(-)arch/x86/include/asm/cpufeatures.h +1
-0@@ -459,6 +459,7 @@#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 */ +#define X86_FEATURE_IBPB_ON_ENTRY (19*32+31)/* SEV-SNP IBPB on VM Entry */ /* AMD-defined Extended Feature 2 EAX, CPUID level 0x80000021 (EAX), word 20 */ #define X86_FEATURE_NO_NESTED_DATA_BP (20*32+ 0)/* No Nested Data Breakpoints */ arch/x86/include/asm/svm.h +1
-0@@ -306,6 +306,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_IBPB_ON_ENTRY BIT(21)#define VMCB_ALLOWED_SEV_FEATURES_VALID BIT_ULL(63)arch/x86/kvm/svm/sev.c +0
-0
arch/x86/kvm/svm/sev.c void __init sev_hardware_setup(void) · line 3171
Quoted 8 lines
arch/x86/kvm/svm/sev.c +4
-1@@ -3165,8 +3165,15 @@ void __init sev_hardware_setup(void) cpu_feature_enabled(X86_FEATURE_NO_NESTED_DATA_BP)) sev_supported_vmsa_features |=SVM_SEV_FEAT_DEBUG_SWAP ; -if (sev_snp_enabled && tsc_khz &&cpu_feature_enabled (X86_FEATURE_SNP_SECURE_TSC )) +if (!sev_snp_enabled) +return ; +/* the following feature bit checks are SNP specific */ +
The early return seems to split up the SNP features unnecessarily.
Keeping everything under if (sev_snp_enabled) is cleaner IMO - it's clear that these features belong together. Plus, when someone adds the next SNP feature, they won't have to think about whether it goes before or after the return. The comment about "SNP specific" features becomes redundant as well.
arch/x86/kvm/svm/sev.c void __init sev_hardware_setup(void) · line 3176
Quoted 5 lines
arch/x86/kvm/svm/sev.c +4
-0+if (tsc_khz &&cpu_feature_enabled (X86_FEATURE_SNP_SECURE_TSC )) sev_supported_vmsa_features |=SVM_SEV_FEAT_SECURE_TSC ; + +if (cpu_feature_enabled (X86_FEATURE_IBPB_ON_ENTRY )) + sev_supported_vmsa_features |=SVM_SEV_FEAT_IBPB_ON_ENTRY ;
Regards,
Nikunj
On 1/27/26 12:38 AM, Nikunj A. Dadhania wrote:
Hi Nikunj,
Quoted 17 lines · Kim Phillips
arch/x86/kvm/svm/sev.c void __init sev_hardware_setup(void) · line 3171
Quoted 13 lines
arch/x86/kvm/svm/sev.c +4
-1@@ -3165,8 +3165,15 @@ void __init sev_hardware_setup(void) cpu_feature_enabled(X86_FEATURE_NO_NESTED_DATA_BP)) sev_supported_vmsa_features |=SVM_SEV_FEAT_DEBUG_SWAP ; -if (sev_snp_enabled && tsc_khz &&cpu_feature_enabled (X86_FEATURE_SNP_SECURE_TSC )) +if (!sev_snp_enabled) +return ; +/* the following feature bit checks are SNP specific */ +The early return seems to split up the SNP features unnecessarily.
Quoted 5 lines
Keeping everything under
if (sev_snp_enabled)is cleaner IMO - it's clear that these features belong together. Plus, when someone adds the next SNP feature, they won't have to think about whether it goes before or after the return. The comment about "SNP specific" features becomes redundant as well.
The SNP 'togetherness' semantics are maintained whether under an 'if (sev_snp_enabled)' body, or after an 'if (!sev_snp_enabled) return;'.
Only SNP-specific things are being done in the trailing part of the function, so it naturally lends itself to do the early return. It makes it more readable by eliminating the unnecessary indentation created by an 'if (sev_snp_enabled)' body.
Meanwhile, I agree with your comments on the first patch in the series.
Thanks for your review,
Kim
Re: [PATCH 1/2] KVM: SEV: IBPB-on-Entry guest support
In reply to Kim PhillipsQuoted 13 lines · Kim Phillips
The SEV-SNP IBPB-on-Entry feature does not require a guest-side implementation. The feature was added in Zen5 h/w, after the first SNP Zen implementation, and thus was not accounted for when the initial set of SNP features were added to the kernel.
In its abundant precaution, commit
8c29f0165405("x86/sev: Add SEV-SNP guest feature negotiation support") includedSEV_STATUS' IBPB-on-Entry bit as a reserved bit, thereby masking guests from using the feature.Unmask the bit, to allow guests to take advantage of the feature on hypervisor kernel versions that support it: Amend the
SEV_STATUSMSRSNP_RESERVED_MASKto exclude bit 23 (IbpbOnEntry).
Quoted 7 lines
Fixes 8c29f0165405 ("x86/sev: Add SEV-SNP guest feature negotiation support")Cc Nikunj A Dadhania <[email protected]>Cc Tom Lendacky <[email protected]>CC Borislav Petkov (AMD) <[email protected]>CC Michael Roth <[email protected]>Signed-off-by Kim Phillips <[email protected]>
With the change to the subject line...
Quoted 46 lines
--- arch/x86/boot/compressed/sev.c | 1 + arch/x86/coco/sev/core.c | 1 + arch/x86/include/asm/msr-index.h | 5 ++++- 3 files changed, 6 insertions(+), 1 deletion(-)arch/x86/boot/compressed/sev.c +1
-0@@ -188,6 +188,7 @@ bool sev_es_check_ghcb_fault(unsigned long address)MSR_AMD64_SNP_RESERVED_BIT13 | \MSR_AMD64_SNP_RESERVED_BIT15 | \MSR_AMD64_SNP_SECURE_AVIC | \ +MSR_AMD64_SNP_RESERVED_BITS19_22 | \ MSR_AMD64_SNP_RESERVED_MASK) #ifdef CONFIG_AMD_SECURE_AVICarch/x86/coco/sev/core.c +1
-0@@ -122,6 +122,7 @@ static const char * const sev_status_feat_names[] = { [MSR_AMD64_SNP_VMSA_REG_PROT_BIT] = "VMSARegProt", [MSR_AMD64_SNP_SMT_PROT_BIT] = "SMTProt", [MSR_AMD64_SNP_SECURE_AVIC_BIT] = "SecureAVIC", + [MSR_AMD64_SNP_IBPB_ON_ENTRY_BIT] = "IBPBOnEntry", };/* arch/x86/include/asm/msr-index.h +4
-1@@ -735,7 +735,10 @@#define MSR_AMD64_SNP_SMT_PROT BIT_ULL(MSR_AMD64_SNP_SMT_PROT_BIT)#define MSR_AMD64_SNP_SECURE_AVIC_BIT 18#define MSR_AMD64_SNP_SECURE_AVIC BIT_ULL(MSR_AMD64_SNP_SECURE_AVIC_BIT) -#define MSR_AMD64_SNP_RESV_BIT 19 +#define MSR_AMD64_SNP_RESERVED_BITS19_22 GENMASK_ULL(22, 19) +#define MSR_AMD64_SNP_IBPB_ON_ENTRY_BIT 23 +#define MSR_AMD64_SNP_IBPB_ON_ENTRY BIT_ULL(MSR_AMD64_SNP_IBPB_ON_ENTRY_BIT) +#define MSR_AMD64_SNP_RESV_BIT 24#define MSR_AMD64_SNP_RESERVED_MASK GENMASK_ULL(63, MSR_AMD64_SNP_RESV_BIT)#define MSR_AMD64_SAVIC_CONTROL 0xc0010138#define MSR_AMD64_SAVIC_EN_BIT 0
Quoted 14 lines · Kim Phillips
AMD EPYC 5th generation and above processors support IBPB-on-Entry for SNP guests. By invoking an Indirect Branch Prediction Barrier (IBPB) on VMRUN, old indirect branch predictions are prevented from influencing indirect branches within the guest.
SNP guests may choose to enable IBPB-on-Entry by setting
SEV_FEATURESbit 21 (IbpbOnEntry).Host support for IBPB on Entry is indicated by CPUID Fn8000_001F[IbpbOnEntry], bit 31.
If supported, indicate support for IBPB on Entry in
sev_supported_vmsa_featuresbit 23 (IbpbOnEntry).
Quoted 6 lines
For more info, refer to page 615, Section 15.36.17 "Side-Channel Protection", AMD64 Architecture Programmer's Manual Volume 2: System Programming Part 2, Pub. 24593 Rev. 3.42 - March 2024 (see Link).
Quoted 51 lines
--- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/svm.h | 1 + arch/x86/kvm/svm/sev.c | 9 ++++++++- 3 files changed, 10 insertions(+), 1 deletion(-)arch/x86/include/asm/cpufeatures.h +1
-0@@ -459,6 +459,7 @@#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 */ +#define X86_FEATURE_IBPB_ON_ENTRY (19*32+31)/* SEV-SNP IBPB on VM Entry */ /* AMD-defined Extended Feature 2 EAX, CPUID level 0x80000021 (EAX), word 20 */ #define X86_FEATURE_NO_NESTED_DATA_BP (20*32+ 0)/* No Nested Data Breakpoints */ arch/x86/include/asm/svm.h +1
-0@@ -306,6 +306,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_IBPB_ON_ENTRY BIT(21)#define VMCB_ALLOWED_SEV_FEATURES_VALID BIT_ULL(63)arch/x86/kvm/svm/sev.c +8
-1@@ -3165,8 +3165,15 @@ void __init sev_hardware_setup(void) cpu_feature_enabled(X86_FEATURE_NO_NESTED_DATA_BP)) sev_supported_vmsa_features |=SVM_SEV_FEAT_DEBUG_SWAP ; -if (sev_snp_enabled && tsc_khz &&cpu_feature_enabled (X86_FEATURE_SNP_SECURE_TSC )) +if (!sev_snp_enabled) +return ; +/* the following feature bit checks are SNP specific */ + +if (tsc_khz &&cpu_feature_enabled (X86_FEATURE_SNP_SECURE_TSC )) sev_supported_vmsa_features |=SVM_SEV_FEAT_SECURE_TSC ; + +if (cpu_feature_enabled (X86_FEATURE_IBPB_ON_ENTRY )) + sev_supported_vmsa_features |=SVM_SEV_FEAT_IBPB_ON_ENTRY ; }void sev_hardware_unsetup (void )
Borislav Petkov
maintainerRe: [PATCH 1/2] KVM: SEV: IBPB-on-Entry guest support
In reply to Kim PhillipsQuoted 5 lines · Kim Phillips
The SEV-SNP IBPB-on-Entry feature does not require a guest-side implementation. The feature was added in Zen5 h/w, after the first SNP Zen implementation, and thus was not accounted for when the initial set of SNP features were added to the kernel.
Quoted 7 lines
In its abundant precaution, commit
8c29f0165405("x86/sev: Add SEV-SNP guest feature negotiation support") includedSEV_STATUS' IBPB-on-Entry bit as a reserved bit, thereby masking guests from using the feature.Unmask the bit, to allow guests to take advantage of the feature on hypervisor kernel versions that support it: Amend the
SEV_STATUSMSRSNP_RESERVED_MASKto exclude bit 23 (IbpbOnEntry).
Do not explain what the patch does.
Quoted 6 lines
Fixes 8c29f0165405 ("x86/sev: Add SEV-SNP guest feature negotiation support")Cc Nikunj A Dadhania <[email protected]>Cc Tom Lendacky <[email protected]>CC Borislav Petkov (AMD) <[email protected]>CC Michael Roth <[email protected]>
I guess...
arch/x86/include/asm/msr-index.h line 740
Quoted 12 lines
arch/x86/include/asm/msr-index.h +3
-1@@ -735,7 +735,10 @@#define MSR_AMD64_SNP_SMT_PROT BIT_ULL(MSR_AMD64_SNP_SMT_PROT_BIT)#define MSR_AMD64_SNP_SECURE_AVIC_BIT 18#define MSR_AMD64_SNP_SECURE_AVIC BIT_ULL(MSR_AMD64_SNP_SECURE_AVIC_BIT) -#define MSR_AMD64_SNP_RESV_BIT 19 +#define MSR_AMD64_SNP_RESERVED_BITS19_22 GENMASK_ULL(22, 19) +#define MSR_AMD64_SNP_IBPB_ON_ENTRY_BIT 23 +#define MSR_AMD64_SNP_IBPB_ON_ENTRY BIT_ULL(MSR_AMD64_SNP_IBPB_ON_ENTRY_BIT)
Why isn't this part of SNP_FEATURES_PRESENT?
If this feature doesn't require guest-side support, then it is trivially present, no?
arch/x86/include/asm/msr-index.h line 744
Quoted 5 lines
arch/x86/include/asm/msr-index.h +1
-0+#define MSR_AMD64_SNP_RESV_BIT 24#define MSR_AMD64_SNP_RESERVED_MASK GENMASK_ULL(63, MSR_AMD64_SNP_RESV_BIT)#define MSR_AMD64_SAVIC_CONTROL 0xc0010138#define MSR_AMD64_SAVIC_EN_BIT 0
I guess this is a fix of sorts and I could take it in now once all review comments have been addressed...
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH 1/2] KVM: SEV: IBPB-on-Entry guest support
Hi Boris,
Quoted 6 lines · Borislav Petkov
Quoted 5 lines · Kim Phillips
The SEV-SNP IBPB-on-Entry feature does not require a guest-side implementation. The feature was added in Zen5 h/w, after the first SNP Zen implementation, and thus was not accounted for when the initial set of SNP features were added to the kernel.
Quoted 8 lines
Quoted 7 lines
In its abundant precaution, commit
8c29f0165405("x86/sev: Add SEV-SNP guest feature negotiation support") includedSEV_STATUS' IBPB-on-Entry bit as a reserved bit, thereby masking guests from using the feature.Unmask the bit, to allow guests to take advantage of the feature on hypervisor kernel versions that support it: Amend the
SEV_STATUSMSRSNP_RESERVED_MASKto exclude bit 23 (IbpbOnEntry).Do not explain what the patch does.
For that last paragraph, how about:
"Allow guests to make use of IBPB-on-Entry when supported by the hypervisor, as the bit is now architecturally defined and safe to expose."
?
Quoted 7 lines
Quoted 6 lines
Fixes 8c29f0165405 ("x86/sev: Add SEV-SNP guest feature negotiation support")Cc Nikunj A Dadhania <[email protected]>Cc Tom Lendacky <[email protected]>CC Borislav Petkov (AMD) <[email protected]>CC Michael Roth <[email protected]>I guess...
Hopefully a bitfield will be carved out for these no-explicit-guest-implementation-required bits by hardware such that we won't need to do this again.
Quoted 14 lines
arch/x86/include/asm/msr-index.h line 740
Quoted 12 lines
arch/x86/include/asm/msr-index.h +3
-1@@ -735,7 +735,10 @@#define MSR_AMD64_SNP_SMT_PROT BIT_ULL(MSR_AMD64_SNP_SMT_PROT_BIT)#define MSR_AMD64_SNP_SECURE_AVIC_BIT 18#define MSR_AMD64_SNP_SECURE_AVIC BIT_ULL(MSR_AMD64_SNP_SECURE_AVIC_BIT) -#define MSR_AMD64_SNP_RESV_BIT 19 +#define MSR_AMD64_SNP_RESERVED_BITS19_22 GENMASK_ULL(22, 19) +#define MSR_AMD64_SNP_IBPB_ON_ENTRY_BIT 23 +#define MSR_AMD64_SNP_IBPB_ON_ENTRY BIT_ULL(MSR_AMD64_SNP_IBPB_ON_ENTRY_BIT)Why isn't this part of
SNP_FEATURES_PRESENT?
Quoted 2 lines
If this feature doesn't require guest-side support, then it is trivially present, no?
SNP_FEATURES_PRESENT is for the non-trivial variety: Its bits get set as part of the patchseries that add the explicit guest support *code*.
I believe 'features' like PREVENT_HOST_IBS are similar in this regard.
Quoted 7 lines
arch/x86/include/asm/msr-index.h line 744
Quoted 5 lines
arch/x86/include/asm/msr-index.h +1
-0+#define MSR_AMD64_SNP_RESV_BIT 24#define MSR_AMD64_SNP_RESERVED_MASK GENMASK_ULL(63, MSR_AMD64_SNP_RESV_BIT)#define MSR_AMD64_SAVIC_CONTROL 0xc0010138#define MSR_AMD64_SAVIC_EN_BIT 0I guess this is a fix of sorts and I could take it in now once all review comments have been addressed...
Cool, thanks.
Kim
Borislav Petkov
maintainerRe: [PATCH 1/2] KVM: SEV: IBPB-on-Entry guest support
Quoted 5 lines · Kim Phillips
For that last paragraph, how about:
"Allow guests to make use of IBPB-on-Entry when supported by the hypervisor, as the bit is now architecturally defined and safe to expose."
Better.
Quoted 2 lines
SNP_FEATURES_PRESENTis for the non-trivial variety: Its bits get set as part of the patchseries that add the explicit guest support *code*.
Yes, and I'm asking why can't SNP_FEATURES_PRESENT contain *all* SNP features?
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH 1/2] KVM: SEV: IBPB-on-Entry guest support
Quoted 4 lines · Borislav Petkov
Quoted 2 lines · Kim Phillips
SNP_FEATURES_PRESENTis for the non-trivial variety: Its bits get set as part of the patchseries that add the explicit guest support *code*.Yes, and I'm asking why can't
SNP_FEATURES_PRESENTcontain *all* SNP features?
Not *all* SNP features are implemented in all guest kernel versions, and, well, for those that don't require explicit guest code support, perhaps it's because they aren't necessarily well defined and validated in all hardware versions...
Kim
Borislav Petkov
maintainerRe: [PATCH 1/2] KVM: SEV: IBPB-on-Entry guest support
Quoted 4 lines · Kim Phillips
Not *all* SNP features are implemented in all guest kernel versions, and, well, for those that don't require explicit guest code support, perhaps it's because they aren't necessarily well defined and validated in all hardware versions...
Ok, can you add *this* feature to SNP_FEATURES_PRESENT? If not, why not?
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH 1/2] KVM: SEV: IBPB-on-Entry guest support
Quoted 7 lines · Borislav Petkov
Quoted 4 lines · Kim Phillips
Not *all* SNP features are implemented in all guest kernel versions, and, well, for those that don't require explicit guest code support, perhaps it's because they aren't necessarily well defined and validated in all hardware versions...
Ok, can you add *this* feature to
SNP_FEATURES_PRESENT? If not, why not?
It can be added. Any of the features added to SNP_FEATURES_PRESENT that aren't set in the SNP_FEATURES_IMPL_REQ bitmap are really a no-op. The SNP_FEATURES_PRESENT bitmap is meant to contain whatever bits are set in SNP_FEATURES_IMPL_REQ when an implementation has been implemented for the guest.
But, yeah, we could add all the bits that aren't set in SNP_FEATURES_IMPL_REQ to SNP_FEATURES_PRESENT if it makes it clearer.
If we do that, it should probably be a separate patch (?) that also rewords the comment above SNP_FEATURES_PRESENT
Thanks,
Tom
Quoted 1 line
Borislav Petkov
maintainerRe: [PATCH 1/2] KVM: SEV: IBPB-on-Entry guest support
Quoted 8 lines · Tom Lendacky
It can be added. Any of the features added to
SNP_FEATURES_PRESENTthat aren't set in theSNP_FEATURES_IMPL_REQbitmap are really a no-op. TheSNP_FEATURES_PRESENTbitmap is meant to contain whatever bits are set inSNP_FEATURES_IMPL_REQwhen an implementation has been implemented for the guest.But, yeah, we could add all the bits that aren't set in
SNP_FEATURES_IMPL_REQtoSNP_FEATURES_PRESENTif it makes it clearer.
Right, that's the question. SNP_FEATURES_PRESENT is used in the masking operation to get the unsupported features.
But when we say a SNP feature is present, then, even if it doesn't need guest implementation, that feature is still present nonetheless.
So our nomenclature is kinda imprecise here.
I'd say, we can always rename SNP_FEATURES_PRESENT to denote what it is there for, i.e., the narrower functionality of the masking.
Or, if we want to gather there *all* features that are present, then we can start adding them...
Quoted 2 lines
If we do that, it should probably be a separate patch (?) that also rewords the comment above
SNP_FEATURES_PRESENT
... yes, as a separate patch.
Question is, what do we really wanna do here?
Does it make sense and is it useful to have SNP_FEATURES_PRESENT contain *all* guest SNP features...
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH 1/2] KVM: SEV: IBPB-on-Entry guest support
Quoted 27 lines · Borislav Petkov
Quoted 8 lines · Tom Lendacky
It can be added. Any of the features added to
SNP_FEATURES_PRESENTthat aren't set in theSNP_FEATURES_IMPL_REQbitmap are really a no-op. TheSNP_FEATURES_PRESENTbitmap is meant to contain whatever bits are set inSNP_FEATURES_IMPL_REQwhen an implementation has been implemented for the guest.But, yeah, we could add all the bits that aren't set in
SNP_FEATURES_IMPL_REQtoSNP_FEATURES_PRESENTif it makes it clearer.Right, that's the question.
SNP_FEATURES_PRESENTis used in the masking operation to get the unsupported features.But when we say a SNP feature is present, then, even if it doesn't need guest implementation, that feature is still present nonetheless.
So our nomenclature is kinda imprecise here.
I'd say, we can always rename
SNP_FEATURES_PRESENTto denote what it is there for, i.e., the narrower functionality of the masking.Or, if we want to gather there *all* features that are present, then we can start adding them...
Quoted 2 lines
If we do that, it should probably be a separate patch (?) that also rewords the comment above
SNP_FEATURES_PRESENT
Quoted 6 lines
... yes, as a separate patch.
Question is, what do we really wanna do here?
Does it make sense and is it useful to have
SNP_FEATURES_PRESENTcontain *all* guest SNP features...
I guess it really depends on the persons point of view. I agree that renaming the SNP_FEATURES_PRESENT to SNP_FEATURES_IMPL(EMENTED) would match up nicely with SNP_FEATURES_IMPL_REQ. Maybe that's all that is needed...
Thanks,
Tom
Quoted 3 lines
Thx.
Borislav Petkov
maintainerRe: [PATCH 1/2] KVM: SEV: IBPB-on-Entry guest support
Quoted 4 lines · Tom Lendacky
I guess it really depends on the persons point of view. I agree that renaming the
SNP_FEATURES_PRESENTtoSNP_FEATURES_IMPL(EMENTED)would match up nicely withSNP_FEATURES_IMPL_REQ. Maybe that's all that is needed...
I guess...
I still think it would be useful to have a common place that says which things in SEV_STATUS are supported and present in a guest, no?
Or are we going to dump that MSR like Joerg's patch from a while ago and that'll tell us what the guest supports?
Hmm.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH 1/2] KVM: SEV: IBPB-on-Entry guest support
Quoted 10 lines · Borislav Petkov
Quoted 4 lines · Tom Lendacky
I guess it really depends on the persons point of view. I agree that renaming the
SNP_FEATURES_PRESENTtoSNP_FEATURES_IMPL(EMENTED)would match up nicely withSNP_FEATURES_IMPL_REQ. Maybe that's all that is needed...I guess...
I still think it would be useful to have a common place that says which things in
SEV_STATUSare supported and present in a guest, no?
But I can see that getting stale because it isn't required to be updated for features that don't require an implementation in order for the guest to boot successfully. Whereas the SNP_FEATURES_IMPL_REQ is set with known values that require an implementation and all the reserved bits set. So it takes actual updating to get one of those features to work that are represented in that bitmap.
Quoted 3 lines
Or are we going to dump that MSR like Joerg's patch from a while ago and that'll tell us what the guest supports?
That will tell us what the guest is running with, not what it can run with.
Thanks,
Tom
Quoted 3 lines
Hmm.
Borislav Petkov
maintainerRe: [PATCH 1/2] KVM: SEV: IBPB-on-Entry guest support
Quoted 6 lines · Tom Lendacky
But I can see that getting stale because it isn't required to be updated for features that don't require an implementation in order for the guest to boot successfully. Whereas the
SNP_FEATURES_IMPL_REQis set with known values that require an implementation and all the reserved bits set. So it takes actual updating to get one of those features to work that are represented in that bitmap.
Ok, I guess we can rename that define SNP_FEATURES_IMPL to denote is the counterpart of SNP_FEATURES_IMPL_REQ, so to speak.
@Kim, you can send a new version with the define renamed.
Due to it being too close to the merge window, it'll wait for after and then it can go to stable later but I don't think that's a problem.
Quoted 1 line
That will tell us what the guest is running with, not what it can run with.
hm, ok, let's think about this more then. I don't have a clear use case for a this-is-what-a-SNP-guest-can-run-with so let's deal with that later...
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette