[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CABgObfa0ubOwNv2Vi9ziEjHXQMR_Sa6P-fwuXfPq76qy0N61kA@mail.gmail.com>
Date: Fri, 29 Apr 2022 19:21:33 +0200
From: Paolo Bonzini <pbonzini@...hat.com>
To: Peter Gonda <pgonda@...gle.com>
Cc: John Sperbeck <jsperbeck@...gle.com>,
kvm list <kvm@...r.kernel.org>,
David Rientjes <rientjes@...gle.com>,
Sean Christopherson <seanjc@...gle.com>,
LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v3] KVM: SEV: Mark nested locking of vcpu->lock
On Fri, Apr 29, 2022 at 7:12 PM Peter Gonda <pgonda@...gle.com> wrote:
> Sounds good. Instead of doing this prev_vcpu solution we could just
> keep the 1st vcpu for source and target. I think this could work since
> all the vcpu->mutex.dep_maps do not point to the same string.
>
> Lock:
> bool acquired = false;
> kvm_for_each_vcpu(...) {
> if (mutex_lock_killable_nested(&vcpu->mutex, role)
> goto out_unlock;
> acquired = true;
> if (acquired)
> mutex_release(&vcpu->mutex, role)
> }
Almost:
bool first = true;
kvm_for_each_vcpu(...) {
if (mutex_lock_killable_nested(&vcpu->mutex, role)
goto out_unlock;
if (first)
++role, first = false;
else
mutex_release(&vcpu->mutex, role);
}
and to unlock:
bool first = true;
kvm_for_each_vcpu(...) {
if (first)
first = false;
else
mutex_acquire(&vcpu->mutex, role);
mutex_unlock(&vcpu->mutex);
acquired = false;
}
because you cannot use the first vCPU's role again when locking.
Paolo
Powered by blists - more mailing lists