lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAMkAt6rJTTojQ7Ymbywmdns-8AWNBVEde4D6cZkceL=czMaEig@mail.gmail.com>
Date:   Mon, 23 Aug 2021 10:39:40 -0600
From:   Peter Gonda <pgonda@...gle.com>
To:     Marc Orr <marcorr@...gle.com>
Cc:     Sean Christopherson <seanjc@...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 Fri, Aug 20, 2021 at 2:53 PM Marc Orr <marcorr@...gle.com> wrote:
>
> 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.

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.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ