Re: [PATCH v2 09/11] KVM: SEV: define VM types for SEV and SEV-ES

From: Sean Christopherson
Date: Fri Feb 23 2024 - 11:55:46 EST


On Fri, Feb 23, 2024, Paolo Bonzini wrote:

Changelog...

> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index 392b9c2e2ce1..87541c84d07e 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -4087,6 +4087,11 @@ static void svm_cancel_injection(struct kvm_vcpu *vcpu)
>
> static int svm_vcpu_pre_run(struct kvm_vcpu *vcpu)
> {
> + struct kvm_sev_info *sev = &to_kvm_svm(vcpu->kvm)->sev_info;

Ugh, we really should have

static inline struct kvm_sev_info *to_kvm_sev(struct kvm *kvm)
{
return &to_kvm_svm(vcpu->kvm)->sev_info;
}

> +
> + if (sev->need_init)

And then this can be:

if (to_kvm_sev(vcpu->kvm)->need_init)

> + return -EINVAL;
> +
> return 1;
> }
>
> @@ -4888,6 +4893,11 @@ static void svm_vm_destroy(struct kvm *kvm)
>
> static int svm_vm_init(struct kvm *kvm)
> {
> + if (kvm->arch.vm_type) {
> + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info;
> + sev->need_init = true;

And

if (kvm->arch.vm_type)
to_kvm_sev(vcpu->kvm)->need_init = true;