Skip to content

Commit baf6ed1

Browse files
committed
KVM: SEV: Set RESET GHCB MSR value during sev_es_init_vmcb()
Set the RESET value for the GHCB "MSR" during sev_es_init_vmcb() instead of sev_es_vcpu_reset() to allow for dropping sev_es_vcpu_reset() entirely. Note, the call to sev_init_vmcb() from sev_migrate_from() also kinda sorta emulates a RESET, but sev_migrate_from() immediately overwrites ghcb_gpa with the source's current value, so whether or not stuffing the GHCB version is correct/desirable is moot. No functional change intended. Reviewed-by: Nikunj A Dadhania <nikunj@amd.com> Link: https://lore.kernel.org/r/20250819234833.3080255-7-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 3d4e882 commit baf6ed1

1 file changed

Lines changed: 11 additions & 13 deletions

File tree

arch/x86/kvm/svm/sev.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4480,7 +4480,7 @@ void sev_vcpu_after_set_cpuid(struct vcpu_svm *svm)
44804480
vcpu->arch.reserved_gpa_bits &= ~(1UL << (best->ebx & 0x3f));
44814481
}
44824482

4483-
static void sev_es_init_vmcb(struct vcpu_svm *svm)
4483+
static void sev_es_init_vmcb(struct vcpu_svm *svm, bool init_event)
44844484
{
44854485
struct kvm_sev_info *sev = to_kvm_sev_info(svm->vcpu.kvm);
44864486
struct vmcb *vmcb = svm->vmcb01.ptr;
@@ -4541,6 +4541,15 @@ static void sev_es_init_vmcb(struct vcpu_svm *svm)
45414541

45424542
/* Can't intercept XSETBV, HV can't modify XCR0 directly */
45434543
svm_clr_intercept(svm, INTERCEPT_XSETBV);
4544+
4545+
/*
4546+
* Set the GHCB MSR value as per the GHCB specification when emulating
4547+
* vCPU RESET for an SEV-ES guest.
4548+
*/
4549+
if (!init_event)
4550+
set_ghcb_msr(svm, GHCB_MSR_SEV_INFO((__u64)sev->ghcb_version,
4551+
GHCB_VERSION_MIN,
4552+
sev_enc_bit));
45444553
}
45454554

45464555
void sev_init_vmcb(struct vcpu_svm *svm, bool init_event)
@@ -4560,7 +4569,7 @@ void sev_init_vmcb(struct vcpu_svm *svm, bool init_event)
45604569
sev_snp_init_protected_guest_state(vcpu);
45614570

45624571
if (sev_es_guest(vcpu->kvm))
4563-
sev_es_init_vmcb(svm);
4572+
sev_es_init_vmcb(svm, init_event);
45644573
}
45654574

45664575
int sev_vcpu_create(struct kvm_vcpu *vcpu)
@@ -4585,17 +4594,6 @@ int sev_vcpu_create(struct kvm_vcpu *vcpu)
45854594

45864595
void sev_es_vcpu_reset(struct vcpu_svm *svm)
45874596
{
4588-
struct kvm_vcpu *vcpu = &svm->vcpu;
4589-
struct kvm_sev_info *sev = to_kvm_sev_info(vcpu->kvm);
4590-
4591-
/*
4592-
* Set the GHCB MSR value as per the GHCB specification when emulating
4593-
* vCPU RESET for an SEV-ES guest.
4594-
*/
4595-
set_ghcb_msr(svm, GHCB_MSR_SEV_INFO((__u64)sev->ghcb_version,
4596-
GHCB_VERSION_MIN,
4597-
sev_enc_bit));
4598-
45994597
mutex_init(&svm->sev_es.snp_vmsa_mutex);
46004598
}
46014599

0 commit comments

Comments
 (0)