Skip to contentSkip to conversation

kvm: fix usage of uninit spinlock in avic_vm_destroy()

PATCH In review Dmitry Vyukov 3 participants 3 messages Jan 24, 2017 – Mar 14, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm: fix usage of uninit spinlock in avic_vm_destroy()

If avic is not enabled, avic_vm_init() does nothing and returns early. However, avic_vm_destroy() still tries to destroy what hasn't been created. The only bad consequence of this now is that avic_vm_destroy() uses svm_vm_data_hash_lock that hasn't been initialized (and is not meant to be used at all if avic is not enabled).

Return early from avic_vm_destroy() if avic is not enabled. It has nothing to destroy.

Cc Joerg Roedel <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc "Radim Krčmář" <[email protected]>
Cc David Hildenbrand <[email protected]>
---
 arch/x86/kvm/svm.c | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/kvm/svm.c +3 -0
index 08a4d3ab3455..3aecaa13fd22 100644
@@ -1382,6 +1382,9 @@ static void avic_vm_destroy(struct kvm *kvm)
 	unsigned long flags;
 	struct kvm_arch *vm_data = &kvm->arch;
 
+	if (!avic)
+		return;
+
 	avic_free_vm_id(vm_data->avic_vm_id);
 
 	if (vm_data->avic_logical_id_table_page)
Signature · 1 line
2.11.0.483.g087da7b7c-goog
Reviewed-by on v1 1/1
#1 lore raw

Am 24.01.2017 um 14:06 schrieb Dmitry Vyukov:

Quoted 26 lines

If avic is not enabled, avic_vm_init() does nothing and returns early. However, avic_vm_destroy() still tries to destroy what hasn't been created. The only bad consequence of this now is that avic_vm_destroy() uses svm_vm_data_hash_lock that hasn't been initialized (and is not meant to be used at all if avic is not enabled).

Return early from avic_vm_destroy() if avic is not enabled. It has nothing to destroy.

Cc Joerg Roedel <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc "Radim Krčmář" <[email protected]>
Cc David Hildenbrand <[email protected]>
---
 arch/x86/kvm/svm.c | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/kvm/svm.c +0 -0
index 08a4d3ab3455..3aecaa13fd22 100644

arch/x86/kvm/svm.c static void avic_vm_destroy(struct kvm *kvm) · line 1390

Quoted 9 lines
arch/x86/kvm/svm.c +3 -0
@@ -1382,6 +1382,9 @@ static void avic_vm_destroy(struct kvm *kvm)
 	unsigned long flags;
 	struct kvm_arch *vm_data = &kvm->arch;
 
+	if (!avic)
+		return;
+
 	avic_free_vm_id(vm_data->avic_vm_id);
 
 	if (vm_data->avic_logical_id_table_page)
Signature · 1 line
David
#2 lore raw
In reply to Dmitry Vyukov

2017-01-24 14:06+0100, Dmitry Vyukov:

Quoted 9 lines

If avic is not enabled, avic_vm_init() does nothing and returns early. However, avic_vm_destroy() still tries to destroy what hasn't been created. The only bad consequence of this now is that avic_vm_destroy() uses svm_vm_data_hash_lock that hasn't been initialized (and is not meant to be used at all if avic is not enabled).

Return early from avic_vm_destroy() if avic is not enabled. It has nothing to destroy.

Quoted 8 lines
Cc Joerg Roedel <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc "Radim Krčmář" <[email protected]>
Cc David Hildenbrand <[email protected]>

---

svm_vm_data_hash_lock is initialized unconditionally now, so I've queued it for 4.12,

Thanks.

Quoted 20 lines
 arch/x86/kvm/svm.c | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/kvm/svm.c +3 -0
index 08a4d3ab3455..3aecaa13fd22 100644
@@ -1382,6 +1382,9 @@ static void avic_vm_destroy(struct kvm *kvm)
 	unsigned long flags;
 	struct kvm_arch *vm_data = &kvm->arch;
 
+	if (!avic)
+		return;
+
 	avic_free_vm_id(vm_data->avic_vm_id);
 
 	if (vm_data->avic_logical_id_table_page)
Signature · 1 line
2.11.0.483.g087da7b7c-goog