kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Gonda <pgonda@google.com>
To: Marc Orr <marcorr@google.com>
Cc: kvm list <kvm@vger.kernel.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Sean Christopherson <seanjc@google.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/2 V4] KVM, SEV: Add support for SEV-ES intra host migration
Date: Mon, 23 Aug 2021 10:38:48 -0600	[thread overview]
Message-ID: <CAMkAt6oJVC=2X_9u4+g0vRhFPL3GV3GZT02bLBkoU4R39+cucQ@mail.gmail.com> (raw)
In-Reply-To: <CAA03e5Hx_BW806LRnsm7jL6tH2YdwVZ2x49UsNe3M93_Kz0WXg@mail.gmail.com>

On Fri, Aug 20, 2021 at 3:01 PM Marc Orr <marcorr@google.com> wrote:
>
> On Thu, Aug 19, 2021 at 8:49 AM Peter Gonda <pgonda@google.com> wrote:
> >
> > For SEV-ES to work with intra host migration the VMSAs, GHCB metadata,
> > and other SEV-ES info needs to be preserved along with the guest's
> > memory.
> >
> > Signed-off-by: Peter Gonda <pgonda@google.com>
> > Cc: Marc Orr <marcorr@google.com>
> > Cc: Paolo Bonzini <pbonzini@redhat.com>
> > Cc: Sean Christopherson <seanjc@google.com>
> > Cc: David Rientjes <rientjes@google.com>
> > Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
> > Cc: Brijesh Singh <brijesh.singh@amd.com>
> > Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
> > Cc: Wanpeng Li <wanpengli@tencent.com>
> > Cc: Jim Mattson <jmattson@google.com>
> > Cc: Joerg Roedel <joro@8bytes.org>
> > Cc: Thomas Gleixner <tglx@linutronix.de>
> > Cc: Ingo Molnar <mingo@redhat.com>
> > Cc: Borislav Petkov <bp@alien8.de>
> > Cc: "H. Peter Anvin" <hpa@zytor.com>
> > Cc: kvm@vger.kernel.org
> > Cc: linux-kernel@vger.kernel.org
> > ---
> >  arch/x86/kvm/svm/sev.c | 58 +++++++++++++++++++++++++++++++++++++++---
> >  1 file changed, 55 insertions(+), 3 deletions(-)
> >
> > diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> > index 2d98b56b6f8c..970d75c34e9a 100644
> > --- a/arch/x86/kvm/svm/sev.c
> > +++ b/arch/x86/kvm/svm/sev.c
> > @@ -1554,6 +1554,53 @@ 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");
> > +               return -EINVAL;
> > +       }
> > +
> > +       for (i = 0; i < num_vcpus; ++i) {
> > +               src_vcpu = src->vcpus[i];
> > +               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) {
> > +               src_vcpu = src->vcpus[i];
> > +               src_svm = to_svm(src_vcpu);
> > +               dst_vcpu = dst->vcpus[i];
> > +               dst_svm = to_svm(dst_vcpu);
> > +
> > +               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;
>
> Should we clear `src_svm->vmcb->control.ghcb_gpa`? (All the other
> fields in `srv_svm` that are copied are then cleared, except for this
> one.) Aside: Do we really need to clear all of the fields in `src_svm`
> after they're copied over? It might be worth adding a comment to
> explain why we're clearing them. It's not immediately obvious to me
> why we're doing that.

Cleared in the next version and added a comment. We don't want to
leave references for the source VM to edit the VMSA or GHCB after the
migration.

>
> > +               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;
> > +}
> > +
> >  int svm_vm_migrate_from(struct kvm *kvm, unsigned int source_fd)
> >  {
> >         struct kvm_sev_info *dst_sev = &to_kvm_svm(kvm)->sev_info;
> > @@ -1565,7 +1612,7 @@ int svm_vm_migrate_from(struct kvm *kvm, unsigned int source_fd)
> >         if (ret)
> >                 return ret;
> >
> > -       if (!sev_guest(kvm) || sev_es_guest(kvm)) {
> > +       if (!sev_guest(kvm)) {
> >                 ret = -EINVAL;
> >                 pr_warn_ratelimited("VM must be SEV enabled to migrate to.\n");
> >                 goto out_unlock;
> > @@ -1589,15 +1636,20 @@ int svm_vm_migrate_from(struct kvm *kvm, unsigned int source_fd)
> >         if (ret)
> >                 goto out_fput;
> >
> > -       if (!sev_guest(source_kvm) || sev_es_guest(source_kvm)) {
> > +       if (!sev_guest(source_kvm)) {
> >                 ret = -EINVAL;
> >                 pr_warn_ratelimited(
> >                         "Source VM must be SEV enabled to migrate from.\n");
> >                 goto out_source;
> >         }
> >
> > +       if (sev_es_guest(kvm)) {
> > +               ret = migrate_vmsa_from(kvm, source_kvm);
> > +               if (ret)
> > +                       goto out_source;
> > +       }
> >         migrate_info_from(dst_sev, &to_kvm_svm(source_kvm)->sev_info);
> > -        ret = 0;
> > +       ret = 0;
>
> nit: looks like there's some space issue on this line. Since I believe
> this line was introduced in the previous patch, I wouldn't expect it
> to show up with a diff in patch #2.

Fixed thanks.

>
> >  out_source:
> >         svm_unlock_after_migration(source_kvm);
> > --
> > 2.33.0.rc1.237.g0d66db33f3-goog
>
> This patch looks good overall to me.
>
> Reviewed-by: Marc Orr <marcorr@google.com>

      reply	other threads:[~2021-08-23 16:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-19 15:49 [PATCH 0/2 V4] Add AMD SEV and SEV-ES intra host migration support Peter Gonda
2021-08-19 15:49 ` [PATCH 1/2 V4] KVM, SEV: Add support for SEV intra host migration Peter Gonda
2021-08-19 16:23   ` Marc Orr
2021-08-19 21:00     ` Peter Gonda
2021-08-19 22:58       ` Sean Christopherson
2021-08-20  6:35         ` Marc Orr
2021-08-20 14:50           ` Sean Christopherson
2021-08-20 20:53         ` Marc Orr
2021-08-23 16:39           ` Peter Gonda
2021-08-19 15:49 ` [PATCH 2/2 V4] KVM, SEV: Add support for SEV-ES " Peter Gonda
2021-08-20 21:00   ` Marc Orr
2021-08-23 16:38     ` Peter Gonda [this message]

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='CAMkAt6oJVC=2X_9u4+g0vRhFPL3GV3GZT02bLBkoU4R39+cucQ@mail.gmail.com' \
    --to=pgonda@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=rientjes@google.com \
    --cc=seanjc@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).