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] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 29 Apr 2022 01:59:15 +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 4/28/22 23:28, Peter Gonda wrote:
> 
> So when actually trying this out I noticed that we are releasing the
> current vcpu iterator but really we haven't actually taken that lock
> yet. So we'd need to maintain a prev_* pointer and release that one.

Not entirely true because all vcpu->mutex.dep_maps will be for the same 
lock.  The dep_map is essentially a fancy string, in this case 
"&vcpu->mutex".

See the definition of mutex_init:

#define mutex_init(mutex)                                              \
do {                                                                   \
         static struct lock_class_key __key;                            \
                                                                        \
         __mutex_init((mutex), #mutex, &__key);                         \
} while (0)

and the dep_map field is initialized with

         lockdep_init_map_wait(&lock->dep_map, name, key, 0, LD_WAIT_SLEEP);

(i.e. all vcpu->mutexes share the same name and key because they have a 
single mutex_init-ialization site).  Lockdep is as crude in theory as it 
is effective in practice!

> 
>           bool acquired = false;
>           kvm_for_each_vcpu(...) {
>                   if (!acquired) {
>                      if (mutex_lock_killable_nested(&vcpu->mutex, role)
>                          goto out_unlock;
>                      acquired = true;
>                   } else {
>                      if (mutex_lock_killable(&vcpu->mutex, role)
>                          goto out_unlock;

This will cause a lockdep splat because it uses subclass 0.  All the 
*_nested functions is allow you to specify a subclass other than zero.

Paolo

>                   }
>           }
> 
> To unlock:
> 
>           kvm_for_each_vcpu(...) {
>              mutex_unlock(&vcpu->mutex);
>           }
> 
> This way instead of mocking and releasing the lock_dep we just lock
> the fist vcpu with mutex_lock_killable_nested(). I think this
> maintains the property you suggested of "coalesces all the mutexes for
> a vm in a single subclass".  Thoughts?

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ