From: Peter Gonda <pgonda@google.com>
To: Marc Orr <marcorr@google.com>
Cc: Sean Christopherson <seanjc@google.com>,
kvm list <kvm@vger.kernel.org>,
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 1/2 V4] KVM, SEV: Add support for SEV intra host migration
Date: Mon, 23 Aug 2021 10:39:40 -0600 [thread overview]
Message-ID: <CAMkAt6rJTTojQ7Ymbywmdns-8AWNBVEde4D6cZkceL=czMaEig@mail.gmail.com> (raw)
In-Reply-To: <CAA03e5F62WEcs3PN6M9qGzW+wuufp+BjwDHcTt18yaB42RDYkA@mail.gmail.com>
On Fri, Aug 20, 2021 at 2:53 PM Marc Orr <marcorr@google.com> wrote:
>
> On Thu, Aug 19, 2021 at 3:58 PM Sean Christopherson <seanjc@google.com> wrote:
> >
> > On Thu, Aug 19, 2021, Peter Gonda wrote:
> > > > >
> > > > > +static int svm_sev_lock_for_migration(struct kvm *kvm)
> > > > > +{
> > > > > + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info;
> > > > > + int ret;
> > > > > +
> > > > > + /*
> > > > > + * Bail if this VM is already involved in a migration to avoid deadlock
> > > > > + * between two VMs trying to migrate to/from each other.
> > > > > + */
> > > > > + spin_lock(&sev->migration_lock);
> > > > > + if (sev->migration_in_progress)
> > > > > + ret = -EBUSY;
> > > > > + else {
> > > > > + /*
> > > > > + * Otherwise indicate VM is migrating and take the KVM lock.
> > > > > + */
> > > > > + sev->migration_in_progress = true;
> > > > > + mutex_lock(&kvm->lock);
> >
> > Deadlock aside, mutex_lock() can sleep, which is not allowed while holding a
> > spinlock, i.e. this patch does not work. That's my suggestion did the crazy
> > dance of "acquiring" a flag.
Ah, makes sense.
> >
> > What I don't know is why on earth I suggested a global spinlock, a simple atomic
> > should work, e.g.
> >
> > if (atomic_cmpxchg_acquire(&sev->migration_in_progress, 0, 1))
> > return -EBUSY;
> >
> > mutex_lock(&kvm->lock);
> >
> > and on the backend...
> >
> > mutex_unlock(&kvm->lock);
> >
> > atomic_set_release(&sev->migration_in_progress, 0);
>
> +1 to replacing the spin lock with an atomic flag. Correctness issues
> aside, I think it's also cleaner. Also, I'd suggest adding a comment
> to source code to explain that the `migration_in_progress` flag is to
> prevent deadlock due to the "double migration" discussed previously.
Thanks! I've updated these locks to use the atomic. It looks much cleaner now.
next prev parent 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 [this message]
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
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='CAMkAt6rJTTojQ7Ymbywmdns-8AWNBVEde4D6cZkceL=czMaEig@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).