diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2013-09-10 06:58:35 -0400 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2013-09-30 03:21:46 -0400 |
commit | 4a937f96f3a29c58b7edd349d2e4dfac371efdf2 (patch) | |
tree | 67471522814264ea197e724a1ca09a424bdbba6c /virt | |
parent | 4fa92fb25ae5a2d79d872ab54df511c831b1f363 (diff) |
KVM: protect kvm_usage_count with its own spinlock
The VM list need not be protected by a raw spinlock. Separate the
two so that kvm_lock can be made non-raw.
Cc: kvm@vger.kernel.org
Cc: gleb@redhat.com
Cc: jan.kiszka@siemens.com
Reviewed-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'virt')
-rw-r--r-- | virt/kvm/kvm_main.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 426051d66173..eb94343c2ed2 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c | |||
@@ -71,6 +71,7 @@ MODULE_LICENSE("GPL"); | |||
71 | */ | 71 | */ |
72 | 72 | ||
73 | DEFINE_RAW_SPINLOCK(kvm_lock); | 73 | DEFINE_RAW_SPINLOCK(kvm_lock); |
74 | static DEFINE_RAW_SPINLOCK(kvm_count_lock); | ||
74 | LIST_HEAD(vm_list); | 75 | LIST_HEAD(vm_list); |
75 | 76 | ||
76 | static cpumask_var_t cpus_hardware_enabled; | 77 | static cpumask_var_t cpus_hardware_enabled; |
@@ -2683,10 +2684,10 @@ static void hardware_enable_nolock(void *junk) | |||
2683 | 2684 | ||
2684 | static void hardware_enable(void) | 2685 | static void hardware_enable(void) |
2685 | { | 2686 | { |
2686 | raw_spin_lock(&kvm_lock); | 2687 | raw_spin_lock(&kvm_count_lock); |
2687 | if (kvm_usage_count) | 2688 | if (kvm_usage_count) |
2688 | hardware_enable_nolock(NULL); | 2689 | hardware_enable_nolock(NULL); |
2689 | raw_spin_unlock(&kvm_lock); | 2690 | raw_spin_unlock(&kvm_count_lock); |
2690 | } | 2691 | } |
2691 | 2692 | ||
2692 | static void hardware_disable_nolock(void *junk) | 2693 | static void hardware_disable_nolock(void *junk) |
@@ -2701,10 +2702,10 @@ static void hardware_disable_nolock(void *junk) | |||
2701 | 2702 | ||
2702 | static void hardware_disable(void) | 2703 | static void hardware_disable(void) |
2703 | { | 2704 | { |
2704 | raw_spin_lock(&kvm_lock); | 2705 | raw_spin_lock(&kvm_count_lock); |
2705 | if (kvm_usage_count) | 2706 | if (kvm_usage_count) |
2706 | hardware_disable_nolock(NULL); | 2707 | hardware_disable_nolock(NULL); |
2707 | raw_spin_unlock(&kvm_lock); | 2708 | raw_spin_unlock(&kvm_count_lock); |
2708 | } | 2709 | } |
2709 | 2710 | ||
2710 | static void hardware_disable_all_nolock(void) | 2711 | static void hardware_disable_all_nolock(void) |
@@ -2718,16 +2719,16 @@ static void hardware_disable_all_nolock(void) | |||
2718 | 2719 | ||
2719 | static void hardware_disable_all(void) | 2720 | static void hardware_disable_all(void) |
2720 | { | 2721 | { |
2721 | raw_spin_lock(&kvm_lock); | 2722 | raw_spin_lock(&kvm_count_lock); |
2722 | hardware_disable_all_nolock(); | 2723 | hardware_disable_all_nolock(); |
2723 | raw_spin_unlock(&kvm_lock); | 2724 | raw_spin_unlock(&kvm_count_lock); |
2724 | } | 2725 | } |
2725 | 2726 | ||
2726 | static int hardware_enable_all(void) | 2727 | static int hardware_enable_all(void) |
2727 | { | 2728 | { |
2728 | int r = 0; | 2729 | int r = 0; |
2729 | 2730 | ||
2730 | raw_spin_lock(&kvm_lock); | 2731 | raw_spin_lock(&kvm_count_lock); |
2731 | 2732 | ||
2732 | kvm_usage_count++; | 2733 | kvm_usage_count++; |
2733 | if (kvm_usage_count == 1) { | 2734 | if (kvm_usage_count == 1) { |
@@ -2740,7 +2741,7 @@ static int hardware_enable_all(void) | |||
2740 | } | 2741 | } |
2741 | } | 2742 | } |
2742 | 2743 | ||
2743 | raw_spin_unlock(&kvm_lock); | 2744 | raw_spin_unlock(&kvm_count_lock); |
2744 | 2745 | ||
2745 | return r; | 2746 | return r; |
2746 | } | 2747 | } |
@@ -3130,7 +3131,7 @@ static int kvm_suspend(void) | |||
3130 | static void kvm_resume(void) | 3131 | static void kvm_resume(void) |
3131 | { | 3132 | { |
3132 | if (kvm_usage_count) { | 3133 | if (kvm_usage_count) { |
3133 | WARN_ON(raw_spin_is_locked(&kvm_lock)); | 3134 | WARN_ON(raw_spin_is_locked(&kvm_count_lock)); |
3134 | hardware_enable_nolock(NULL); | 3135 | hardware_enable_nolock(NULL); |
3135 | } | 3136 | } |
3136 | } | 3137 | } |