2016-10-13 11:11:09

by Paolo Bonzini

[permalink] [raw]
Subject: [PATCH] KVM: document lock orders

This is long overdue, and not really hard.

Signed-off-by: Paolo Bonzini <[email protected]>
---
Documentation/virtual/kvm/locking.txt | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/Documentation/virtual/kvm/locking.txt b/Documentation/virtual/kvm/locking.txt
index f2491a8c68b4..e5dd9f4d6100 100644
--- a/Documentation/virtual/kvm/locking.txt
+++ b/Documentation/virtual/kvm/locking.txt
@@ -4,7 +4,17 @@ KVM Lock Overview
1. Acquisition Orders
---------------------

-(to be written)
+The acquisition orders for mutexes are as follows:
+
+- kvm->lock is taken outside vcpu->mutex
+
+- kvm->lock is taken outside kvm->slots_lock and kvm->irq_lock
+
+- kvm->slots_lock is taken outside kvm->irq_lock, though acquiring
+ them together is quite rare.
+
+For spinlocks, kvm_lock is taken outside kvm->mmu_lock. Everything
+else is a leaf: no other lock is taken inside the critical sections.

2: Exception
------------
--
2.7.4


2016-10-13 12:51:14

by Radim Krčmář

[permalink] [raw]
Subject: Re: [PATCH] KVM: document lock orders

2016-10-13 13:10+0200, Paolo Bonzini:
> This is long overdue, and not really hard.
>
> Signed-off-by: Paolo Bonzini <[email protected]>
> ---

Applied to kvm/queue, thanks.

> Documentation/virtual/kvm/locking.txt | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/virtual/kvm/locking.txt b/Documentation/virtual/kvm/locking.txt
> index f2491a8c68b4..e5dd9f4d6100 100644
> --- a/Documentation/virtual/kvm/locking.txt
> +++ b/Documentation/virtual/kvm/locking.txt
> @@ -4,7 +4,17 @@ KVM Lock Overview
> 1. Acquisition Orders
> ---------------------
>
> -(to be written)
> +The acquisition orders for mutexes are as follows:
> +
> +- kvm->lock is taken outside vcpu->mutex
> +
> +- kvm->lock is taken outside kvm->slots_lock and kvm->irq_lock
> +
> +- kvm->slots_lock is taken outside kvm->irq_lock, though acquiring
> + them together is quite rare.
> +
> +For spinlocks, kvm_lock is taken outside kvm->mmu_lock. Everything
> +else is a leaf: no other lock is taken inside the critical sections.
>
> 2: Exception
> ------------
> --
> 2.7.4
>