Skip to content

Commit 3a9ae31

Browse files
committed
Documentation: kvm: fix SRCU locking order docs
kvm->srcu is taken in KVM_RUN and several other vCPU ioctls, therefore vcpu->mutex is susceptible to the same deadlock that is documented for kvm->slots_lock. The same holds for kvm->lock, since kvm->lock is held outside vcpu->mutex. Fix the documentation and rearrange it to highlight the difference between these locks and kvm->slots_arch_lock, and how kvm->slots_arch_lock can be useful while processing a vmexit. Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 45e966f commit 3a9ae31

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

Documentation/virt/kvm/locking.rst

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,18 @@ The acquisition orders for mutexes are as follows:
2424

2525
For SRCU:
2626

27-
- ``synchronize_srcu(&kvm->srcu)`` is called _inside_
28-
the kvm->slots_lock critical section, therefore kvm->slots_lock
29-
cannot be taken inside a kvm->srcu read-side critical section.
30-
Instead, kvm->slots_arch_lock is released before the call
31-
to ``synchronize_srcu()`` and _can_ be taken inside a
32-
kvm->srcu read-side critical section.
33-
34-
- kvm->lock is taken inside kvm->srcu, therefore
35-
``synchronize_srcu(&kvm->srcu)`` cannot be called inside
36-
a kvm->lock critical section. If you cannot delay the
37-
call until after kvm->lock is released, use ``call_srcu``.
27+
- ``synchronize_srcu(&kvm->srcu)`` is called inside critical sections
28+
for kvm->lock, vcpu->mutex and kvm->slots_lock. These locks _cannot_
29+
be taken inside a kvm->srcu read-side critical section; that is, the
30+
following is broken::
31+
32+
srcu_read_lock(&kvm->srcu);
33+
mutex_lock(&kvm->slots_lock);
34+
35+
- kvm->slots_arch_lock instead is released before the call to
36+
``synchronize_srcu()``. It _can_ therefore be taken inside a
37+
kvm->srcu read-side critical section, for example while processing
38+
a vmexit.
3839

3940
On x86:
4041

0 commit comments

Comments
 (0)