[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAA03e5F62WEcs3PN6M9qGzW+wuufp+BjwDHcTt18yaB42RDYkA@mail.gmail.com>
Date: Fri, 20 Aug 2021 13:53:36 -0700
From: Marc Orr <marcorr@...gle.com>
To: Sean Christopherson <seanjc@...gle.com>
Cc: Peter Gonda <pgonda@...gle.com>, kvm list <kvm@...r.kernel.org>,
Paolo Bonzini <pbonzini@...hat.com>,
David Rientjes <rientjes@...gle.com>,
"Dr . David Alan Gilbert" <dgilbert@...hat.com>,
Brijesh Singh <brijesh.singh@....com>,
Vitaly Kuznetsov <vkuznets@...hat.com>,
Wanpeng Li <wanpengli@...cent.com>,
Jim Mattson <jmattson@...gle.com>,
Joerg Roedel <joro@...tes.org>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
"H. Peter Anvin" <hpa@...or.com>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/2 V4] KVM, SEV: Add support for SEV intra host migration
On Thu, Aug 19, 2021 at 3:58 PM Sean Christopherson <seanjc@...gle.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.
>
> 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.
Powered by blists - more mailing lists