Skip to content

Commit 00f0b95

Browse files
nikunjadsean-jc
authored andcommitted
KVM: SEV: Enforce minimum GHCB version requirement for SEV-SNP guests
Require a minimum GHCB version of 2 when starting SEV-SNP guests through KVM_SEV_INIT2. When a VMM attempts to start an SEV-SNP guest with an incompatible GHCB version (less than 2), reject the request early rather than allowing the guest kernel to start with an incorrect protocol version and fail later with GHCB_SNP_UNSUPPORTED guest termination. Not enforcing the minimum version typically causes the guest to request termination with GHCB_SNP_UNSUPPORTED error code: kvm_amd: SEV-ES guest requested termination: 0x0:0x2 Fixes: 4af663c ("KVM: SEV: Allow per-guest configuration of GHCB protocol version") Cc: Thomas Lendacky <thomas.lendacky@amd.com> Cc: Sean Christopherson <seanjc@google.com> Cc: Michael Roth <michael.roth@amd.com> Signed-off-by: Nikunj A Dadhania <nikunj@amd.com> Link: https://lore.kernel.org/r/20250819234833.3080255-3-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent c78af20 commit 00f0b95

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

arch/x86/kvm/svm/sev.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ static int __sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp,
405405
struct kvm_sev_info *sev = to_kvm_sev_info(kvm);
406406
struct sev_platform_init_args init_args = {0};
407407
bool es_active = vm_type != KVM_X86_SEV_VM;
408+
bool snp_active = vm_type == KVM_X86_SNP_VM;
408409
u64 valid_vmsa_features = es_active ? sev_supported_vmsa_features : 0;
409410
int ret;
410411

@@ -428,6 +429,9 @@ static int __sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp,
428429
if (es_active && !data->ghcb_version)
429430
data->ghcb_version = 2;
430431

432+
if (snp_active && data->ghcb_version < 2)
433+
return -EINVAL;
434+
431435
if (unlikely(sev->active))
432436
return -EINVAL;
433437

@@ -436,7 +440,7 @@ static int __sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp,
436440
sev->vmsa_features = data->vmsa_features;
437441
sev->ghcb_version = data->ghcb_version;
438442

439-
if (vm_type == KVM_X86_SNP_VM)
443+
if (snp_active)
440444
sev->vmsa_features |= SVM_SEV_FEAT_SNP_ACTIVE;
441445

442446
ret = sev_asid_new(sev);
@@ -454,7 +458,7 @@ static int __sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp,
454458
}
455459

456460
/* This needs to happen after SEV/SNP firmware initialization. */
457-
if (vm_type == KVM_X86_SNP_VM) {
461+
if (snp_active) {
458462
ret = snp_guest_req_init(kvm);
459463
if (ret)
460464
goto e_free;

0 commit comments

Comments
 (0)