From: Sean Christopherson <seanjc@google.com>
To: Peter Gonda <pgonda@google.com>
Cc: kvm@vger.kernel.org, Marc Orr <marcorr@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
David Rientjes <rientjes@google.com>,
"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
Brijesh Singh <brijesh.singh@amd.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
"H. Peter Anvin" <hpa@zytor.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3 V7] KVM, SEV: Add support for SEV-ES intra host migration
Date: Fri, 10 Sep 2021 00:50:42 +0000 [thread overview]
Message-ID: <YTqr4nuXYVFz81kD@google.com> (raw)
In-Reply-To: <20210902181751.252227-3-pgonda@google.com>
On Thu, Sep 02, 2021, Peter Gonda wrote:
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index 8db666a362d4..fac21a82e4de 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -1545,6 +1545,59 @@ static void migrate_info_from(struct kvm_sev_info *dst,
> list_replace_init(&src->regions_list, &dst->regions_list);
> }
>
> +static int migrate_vmsa_from(struct kvm *dst, struct kvm *src)
> +{
> + int i, num_vcpus;
> + struct kvm_vcpu *dst_vcpu, *src_vcpu;
> + struct vcpu_svm *dst_svm, *src_svm;
> +
> + num_vcpus = atomic_read(&dst->online_vcpus);
> + if (num_vcpus != atomic_read(&src->online_vcpus)) {
> + pr_warn_ratelimited(
> + "Source and target VMs must have same number of vCPUs.\n");
Same comments about not logging the why.
> + return -EINVAL;
> + }
> +
> + for (i = 0; i < num_vcpus; ++i)
> + src_vcpu = src->vcpus[i];
This can be:
kvm_for_each_vcpu(i, src_vcpu, src) {
if (!src_vcpu->arch.guest_state_protected)
return -EINVAL;
}
> + if (!src_vcpu->arch.guest_state_protected) {
> + pr_warn_ratelimited(
> + "Source ES VM vCPUs must have protected state.\n");
> + return -EINVAL;
> + }
> + }
> +
> + for (i = 0; i < num_vcpus; ++i) {
And again here,
kvm_for_each_vcpu(i, src_vcpu, src) {
src_svm = to_svm(src_vcpu);
> + src_vcpu = src->vcpus[i];
> + src_svm = to_svm(src_vcpu);
> + dst_vcpu = dst->vcpus[i];
Probably a good idea to use kvm_get_vcpu(), even though dst->lock is held. If
nothing else, using kvm_get_vcpu() may save some merge pain as there's a proposal
to switch vcpus to an xarray.
> + dst_svm = to_svm(dst_vcpu);
> +
> + /*
> + * Copy VMSA and GHCB fields from the source to the destination.
> + * Clear them on the source to prevent the VM running and
As brought up in the prior patch, clearing the fields might ensure future KVM_RUNs
fail, but it doesn't prevent the VM from running _now_. And with vcpu->mutext
held, I think a more appropriate comment would be:
/*
* Transfer VMSA and GHCB state to the destination. Nullify and
* clear source fields as appropriate, the state now belongs to
* the destination.
*/
> + * changing the state of the VMSA/GHCB unexpectedly.
> + */
> + dst_vcpu->vcpu_id = src_vcpu->vcpu_id;
> + dst_svm->vmsa = src_svm->vmsa;
> + src_svm->vmsa = NULL;
> + dst_svm->ghcb = src_svm->ghcb;
> + src_svm->ghcb = NULL;
> + dst_svm->vmcb->control.ghcb_gpa =
> + src_svm->vmcb->control.ghcb_gpa;
Let this poke out, an 83 char line isn't the end of the world, and not having
the interrupt makes the code more readable overall.
> + src_svm->vmcb->control.ghcb_gpa = 0;
Nit, '0' isn't an invalid GPA. The reset value would be more appropriate, though
I would just leave this alone.
> + dst_svm->ghcb_sa = src_svm->ghcb_sa;
> + src_svm->ghcb_sa = NULL;
> + dst_svm->ghcb_sa_len = src_svm->ghcb_sa_len;
> + src_svm->ghcb_sa_len = 0;
> + dst_svm->ghcb_sa_sync = src_svm->ghcb_sa_sync;
> + src_svm->ghcb_sa_sync = false;
> + dst_svm->ghcb_sa_free = src_svm->ghcb_sa_free;
> + src_svm->ghcb_sa_free = false;
> + }
> + return 0;
> +}
next prev parent reply other threads:[~2021-09-10 1:15 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-02 18:17 [PATCH 0/2 V7] Add AMD SEV and SEV-ES intra host migration support Peter Gonda
2021-09-02 18:17 ` [PATCH 1/3 V7] KVM, SEV: Add support for SEV intra host migration Peter Gonda
2021-09-10 0:11 ` Sean Christopherson
2021-09-10 1:12 ` Sean Christopherson
2021-09-13 16:21 ` Peter Gonda
2021-09-10 1:15 ` Marc Orr
2021-09-10 1:40 ` Sean Christopherson
2021-09-10 3:41 ` Marc Orr
2021-09-10 21:54 ` Peter Gonda
2021-09-10 22:03 ` Sean Christopherson
2021-09-10 22:07 ` Peter Gonda
2021-09-02 18:17 ` [PATCH 2/3 V7] KVM, SEV: Add support for SEV-ES " Peter Gonda
2021-09-10 0:50 ` Sean Christopherson [this message]
2021-09-10 1:20 ` Sean Christopherson
2021-09-02 18:17 ` [PATCH 3/3 V7] selftest: KVM: Add intra host migration tests Peter Gonda
2021-09-10 17:16 ` Sean Christopherson
2021-09-10 22:14 ` Peter Gonda
2021-09-02 18:45 ` [PATCH 0/2 V7] Add AMD SEV and SEV-ES intra host migration support Sean Christopherson
2021-09-02 18:53 ` Peter Gonda
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YTqr4nuXYVFz81kD@google.com \
--to=seanjc@google.com \
--cc=bp@alien8.de \
--cc=brijesh.singh@amd.com \
--cc=dgilbert@redhat.com \
--cc=hpa@zytor.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcorr@google.com \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=pgonda@google.com \
--cc=rientjes@google.com \
--cc=tglx@linutronix.de \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.