Skip to content

Commit 02d9a04

Browse files
committed
Documentation: kvm: clarify SRCU locking order
Currently only the locking order of SRCU vs kvm->slots_arch_lock and kvm->slots_lock is documented. Extend this to kvm->lock since Xen emulation got it terribly wrong. Signed-off-by: Paolo Bonzini <[email protected]>
1 parent a79b53a commit 02d9a04

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

Documentation/virt/kvm/locking.rst

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,26 @@ The acquisition orders for mutexes are as follows:
1616
- kvm->slots_lock is taken outside kvm->irq_lock, though acquiring
1717
them together is quite rare.
1818

19-
- Unlike kvm->slots_lock, kvm->slots_arch_lock is released before
20-
synchronize_srcu(&kvm->srcu). Therefore kvm->slots_arch_lock
21-
can be taken inside a kvm->srcu read-side critical section,
22-
while kvm->slots_lock cannot.
23-
2419
- kvm->mn_active_invalidate_count ensures that pairs of
2520
invalidate_range_start() and invalidate_range_end() callbacks
2621
use the same memslots array. kvm->slots_lock and kvm->slots_arch_lock
2722
are taken on the waiting side in install_new_memslots, so MMU notifiers
2823
must not take either kvm->slots_lock or kvm->slots_arch_lock.
2924

25+
For SRCU:
26+
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``.
38+
3039
On x86:
3140

3241
- vcpu->mutex is taken outside kvm->arch.hyperv.hv_lock

0 commit comments

Comments
 (0)