Skip to content

Commit c78af20

Browse files
nikunjadsean-jc
authored andcommitted
KVM: SEV: Drop GHCB_VERSION_DEFAULT and open code it
Remove the GHCB_VERSION_DEFAULT macro and open code it with '2'. The macro is used conditionally and is not a true default. KVM ABI does not advertise/emumerates the default GHCB version. Any future change to this macro would silently alter the ABI and potentially break existing deployments that rely on the current behavior. Additionally, move the GHCB version assignment earlier in the code flow and update the comment to clarify that KVM_SEV_INIT2 defaults to version 2, while KVM_SEV_INIT forces version 1. No functional change intended. Cc: Thomas Lendacky <thomas.lendacky@amd.com> Cc: Michael Roth <michael.roth@amd.com> Suggested-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Nikunj A Dadhania <nikunj@amd.com> Link: https://lore.kernel.org/r/20250819234833.3080255-2-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent c17b750 commit c78af20

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

arch/x86/kvm/svm/sev.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#include "trace.h"
3838

3939
#define GHCB_VERSION_MAX 2ULL
40-
#define GHCB_VERSION_DEFAULT 2ULL
4140
#define GHCB_VERSION_MIN 1ULL
4241

4342
#define GHCB_HV_FT_SUPPORTED (GHCB_HV_FT_SNP | GHCB_HV_FT_SNP_AP_CREATION)
@@ -421,6 +420,14 @@ static int __sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp,
421420
if (data->ghcb_version > GHCB_VERSION_MAX || (!es_active && data->ghcb_version))
422421
return -EINVAL;
423422

423+
/*
424+
* KVM supports the full range of mandatory features defined by version
425+
* 2 of the GHCB protocol, so default to that for SEV-ES guests created
426+
* via KVM_SEV_INIT2 (KVM_SEV_INIT forces version 1).
427+
*/
428+
if (es_active && !data->ghcb_version)
429+
data->ghcb_version = 2;
430+
424431
if (unlikely(sev->active))
425432
return -EINVAL;
426433

@@ -429,14 +436,6 @@ static int __sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp,
429436
sev->vmsa_features = data->vmsa_features;
430437
sev->ghcb_version = data->ghcb_version;
431438

432-
/*
433-
* Currently KVM supports the full range of mandatory features defined
434-
* by version 2 of the GHCB protocol, so default to that for SEV-ES
435-
* guests created via KVM_SEV_INIT2.
436-
*/
437-
if (sev->es_active && !sev->ghcb_version)
438-
sev->ghcb_version = GHCB_VERSION_DEFAULT;
439-
440439
if (vm_type == KVM_X86_SNP_VM)
441440
sev->vmsa_features |= SVM_SEV_FEAT_SNP_ACTIVE;
442441

0 commit comments

Comments
 (0)