Re: [PATCH 06/12] KVM: SEV: initialize regions_list of a mirror VM
From: Sean Christopherson
Date: Mon Nov 29 2021 - 18:14:04 EST
On Mon, Nov 22, 2021, Paolo Bonzini wrote:
> This was broken before the introduction of KVM_CAP_VM_MOVE_ENC_CONTEXT_FROM,
> but technically harmless because the region list was unused for a mirror
> VM. However, it is untidy and it now causes a NULL pointer access when
> attempting to move the encryption context of a mirror VM.
>
> Fixes: 54526d1fd593 ("KVM: x86: Support KVM VMs sharing SEV context")
> Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
> ---
> arch/x86/kvm/svm/sev.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index 23a4877d7bdf..dc974c1728b6 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -2004,6 +2004,7 @@ int svm_vm_copy_asid_from(struct kvm *kvm, unsigned int source_fd)
> mirror_sev->fd = source_sev.fd;
> mirror_sev->es_active = source_sev.es_active;
> mirror_sev->handle = source_sev.handle;
> + INIT_LIST_HEAD(&mirror_sev->regions_list);
Heh, I still think the list should be initialized when the VM is created.
On Wed, Feb 24, 2021 at 9:37 AM Sean Christopherson <seanjc@xxxxxxxxxx> wrote:
> > + mutex_unlock(&kvm->lock);
> > + mutex_lock(&mirror_kvm->lock);
> > +
> > + /* Set enc_context_owner and copy its encryption context over */
> > + mirror_kvm_sev = &to_kvm_svm(mirror_kvm)->sev_info;
> > + mirror_kvm_sev->enc_context_owner = kvm;
> > + mirror_kvm_sev->asid = asid;
> > + mirror_kvm_sev->active = true;
>
> I would prefer a prep patch to move "INIT_LIST_HEAD(&sev->regions_list);" from
> sev_guest_init() to when the VM is instantiated. Shaving a few cycles in that
> flow is meaningless, and not initializing the list of regions is odd, and will
> cause problems if mirrors are allowed to pin memory (or do PSP commands).