kvm: initialize SVM spinlock
PATCH 1/1 kvm: initialize SVM spinlock
Currently svm_vm_data_hash_lock is left uninitialized. This causes lockdep warnings. Properly initialize it.
--- arch/x86/kvm/svm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/svm.c +1 -1
@@ -972,7 +972,7 @@ static void svm_disable_lbrv(struct vcpu_svm *svm)*/ #define SVM_VM_DATA_HASH_BITS 8DECLARE_HASHTABLE (svm_vm_data_hash,SVM_VM_DATA_HASH_BITS ); -static spinlock_t svm_vm_data_hash_lock; +static DEFINE_SPINLOCK (svm_vm_data_hash_lock);/* Note: * This function is called from IOMMU driver to notify
Signature · 1 line
2.11.0.483.g087da7b7c-goog
Am 22.01.2017 um 10:04 schrieb Dmitry Vyukov:
Quoted 19 lines
Currently
svm_vm_data_hash_lockis left uninitialized. This causes lockdep warnings. Properly initialize it.Signed-off-by Dmitry Vyukov <[email protected]>Cc Joerg Roedel <[email protected]>Cc Paolo Bonzini <[email protected]>Cc "Radim Krčmář" <[email protected]>--- arch/x86/kvm/svm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kvm/svm.c +0
-0
arch/x86/kvm/svm.c static void svm_disable_lbrv(struct vcpu_svm *svm) · line 978
Quoted 8 lines
arch/x86/kvm/svm.c +1
-1@@ -972,7 +972,7 @@ static void svm_disable_lbrv(struct vcpu_svm *svm)*/ #define SVM_VM_DATA_HASH_BITS 8DECLARE_HASHTABLE (svm_vm_data_hash,SVM_VM_DATA_HASH_BITS ); -static spinlock_t svm_vm_data_hash_lock; +static DEFINE_SPINLOCK (svm_vm_data_hash_lock);/* Note: * This function is called from IOMMU driver to notify
We have
spin_lock_init(&svm_vm_data_hash_lock);
in svm_hardware_setup().
If this isn't called, wouldn't the right fix be to find out why?
Signature · 1 line
David
Quoted 31 lines · David Hildenbrand
Am 22.01.2017 um 10:04 schrieb Dmitry Vyukov:
Quoted 19 lines
Currently
svm_vm_data_hash_lockis left uninitialized. This causes lockdep warnings. Properly initialize it.Signed-off-by Dmitry Vyukov <[email protected]>Cc Joerg Roedel <[email protected]>Cc Paolo Bonzini <[email protected]>Cc "Radim Krčmář" <[email protected]>--- arch/x86/kvm/svm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kvm/svm.c +0
-0arch/x86/kvm/svm.c static void svm_disable_lbrv(struct vcpu_svm *svm) · line 978
Quoted 8 lines
arch/x86/kvm/svm.c +1
-1@@ -972,7 +972,7 @@ static void svm_disable_lbrv(struct vcpu_svm *svm)*/ #define SVM_VM_DATA_HASH_BITS 8DECLARE_HASHTABLE (svm_vm_data_hash,SVM_VM_DATA_HASH_BITS ); -static spinlock_t svm_vm_data_hash_lock; +static DEFINE_SPINLOCK (svm_vm_data_hash_lock);/* Note: * This function is called from IOMMU driver to notify We have
Quoted 5 lines
spin_lock_init(&svm_vm_data_hash_lock);in
svm_hardware_setup().If this isn't called, wouldn't the right fix be to find out why?
spin_lock_init is called conditionally if avic.
Then avic_vm_init returns 0, if !avic.
But then avic_vm_destroy does not check avic and unconditionally uses the spinlock.
Perhaps the right fix then will be:
@@ -1382,6 +1383,9 @@ static void avic_vm_destroy(struct kvm *kvm)
unsigned long flags;
struct kvm_arch *vm_data = &kvm->arch;+ if (!avic)
+ return 0;
+
avic_free_vm_id(vm_data->avic_vm_id);
if (vm_data->avic_logical_id_table_page)Unfortunately I don't remember how I managed to trigger this warning because I don't have any SVM-capable hardware...
But I remember that I did not do anything special besides just enabling spinlock checks and then doing something trivial. Could somebody try to use SVM with the spinlock checks enabled? I don't feel comfortable sending a non-trivial patch without testing it...
Am 23.01.2017 um 15:52 schrieb Dmitry Vyukov:
Quoted 57 lines · David Hildenbrand
Quoted 31 lines
Am 22.01.2017 um 10:04 schrieb Dmitry Vyukov:
Quoted 19 lines
Currently
svm_vm_data_hash_lockis left uninitialized. This causes lockdep warnings. Properly initialize it.Signed-off-by Dmitry Vyukov <[email protected]>Cc Joerg Roedel <[email protected]>Cc Paolo Bonzini <[email protected]>Cc "Radim Krčmář" <[email protected]>--- arch/x86/kvm/svm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kvm/svm.c +0
-0arch/x86/kvm/svm.c static void svm_disable_lbrv(struct vcpu_svm *svm) · line 978
Quoted 8 lines
arch/x86/kvm/svm.c +1
-1@@ -972,7 +972,7 @@ static void svm_disable_lbrv(struct vcpu_svm *svm)*/ #define SVM_VM_DATA_HASH_BITS 8DECLARE_HASHTABLE (svm_vm_data_hash,SVM_VM_DATA_HASH_BITS ); -static spinlock_t svm_vm_data_hash_lock; +static DEFINE_SPINLOCK (svm_vm_data_hash_lock);/* Note: * This function is called from IOMMU driver to notify We have
Quoted 5 lines
spin_lock_init(&svm_vm_data_hash_lock);in
svm_hardware_setup().If this isn't called, wouldn't the right fix be to find out why?
spin_lock_initis called conditionally if avic.
Thenavic_vm_initreturns 0, if !avic.
But thenavic_vm_destroydoes not check avic and unconditionally uses the spinlock.
Perhaps the right fix then will be:(quoted diff) +3
-0@@ -1382,6 +1383,9 @@ static void avic_vm_destroy(struct kvm *kvm) unsigned long flags; struct kvm_arch *vm_data = &kvm->arch; + if (!avic) + return 0; + avic_free_vm_id(vm_data->avic_vm_id); if (vm_data->avic_logical_id_table_page)
Quoted 8 lines
Unfortunately I don't remember how I managed to trigger this warning because I don't have any SVM-capable hardware...
But I remember that I did not do anything special besides just enabling spinlock checks and then doing something trivial. Could somebody try to use SVM with the spinlock checks enabled? I don't feel comfortable sending a non-trivial patch without testing it...
Or stick to your initial patch and simply remove the previous initialization (sounds clean to me). But we'd better double check if that additional check in avic_vm_destroy() is also reasonable (maybe something else is touched that shouldn't be).
Signature · 1 line
David
Paolo Bonzini
maintainerReview static void avic_vm_destroy(struct kvm *kvm) · line 1391
Quoted 11 lines · Dmitry Vyukov
(quoted diff) +3
-0@@ -1382,6 +1383,9 @@ static void avic_vm_destroy(struct kvm *kvm) unsigned long flags; struct kvm_arch *vm_data = &kvm->arch; + if (!avic) + return 0; + avic_free_vm_id(vm_data->avic_vm_id); if (vm_data->avic_logical_id_table_page)
Yes, this is the right one.
Paolo
Quoted 8 lines · Paolo Bonzini
Quoted 5 lines · Dmitry Vyukov
(quoted diff) +0
-0@@ -1382,6 +1383,9 @@ static void avic_vm_destroy(struct kvm *kvm) unsigned long flags; struct kvm_arch *vm_data = &kvm->arch;
Quoted 8 lines
Review static void avic_vm_destroy(struct kvm *kvm) · line 1391
Quoted 6 lines
(quoted diff) +3
-0+ if (!avic) + return 0; + avic_free_vm_id(vm_data->avic_vm_id); if (vm_data->avic_logical_id_table_page)Yes, this is the right one.
I can mail this patch, but I can only test build.
Paolo Bonzini
maintainerQuoted 12 lines · David Hildenbrand
Quoted 12 lines
(quoted diff) +3
-0@@ -1382,6 +1383,9 @@ static void avic_vm_destroy(struct kvm *kvm) unsigned long flags; struct kvm_arch *vm_data = &kvm->arch; + if (!avic) + return 0; + avic_free_vm_id(vm_data->avic_vm_id); if (vm_data->avic_logical_id_table_page)
Quoted 12 lines
Quoted 8 lines
Unfortunately I don't remember how I managed to trigger this warning because I don't have any SVM-capable hardware...
But I remember that I did not do anything special besides just enabling spinlock checks and then doing something trivial. Could somebody try to use SVM with the spinlock checks enabled? I don't feel comfortable sending a non-trivial patch without testing it...Or stick to your initial patch and simply remove the previous initialization (sounds clean to me). But we'd better double check if that additional check in
avic_vm_destroy()is also reasonable (maybe something else is touched that shouldn't be).
Yes, that second patch is the right one. David, if you wish to submit a patch to simplify the initialization, I'll apply that too.
Thanks,
Paolo
Paolo Bonzini
maintainerQuoted 14 lines · Dmitry Vyukov
Quoted 13 lines · Paolo Bonzini
Quoted 10 lines · Dmitry Vyukov
(quoted diff) +3
-0@@ -1382,6 +1383,9 @@ static void avic_vm_destroy(struct kvm *kvm) unsigned long flags; struct kvm_arch *vm_data = &kvm->arch; + if (!avic) + return 0; + avic_free_vm_id(vm_data->avic_vm_id);
Quoted 6 lines
Quoted 3 lines
Review static void avic_vm_destroy(struct kvm *kvm) · line 1391
Quoted 1 line
(quoted diff) +0
-0if (vm_data->avic_logical_id_table_page)Yes, this is the right one.
I can mail this patch, but I can only test build.
No problem, I have applied it locally and I am testing it.
Paolo
Mailed a new patch "kvm: fix usage of uninit spinlock in avic_vm_destroy()".
Quoted 27 lines · Paolo Bonzini
Quoted 14 lines · Dmitry Vyukov
Quoted 13 lines · Paolo Bonzini
Quoted 10 lines · Dmitry Vyukov
(quoted diff) +3
-0@@ -1382,6 +1383,9 @@ static void avic_vm_destroy(struct kvm *kvm) unsigned long flags; struct kvm_arch *vm_data = &kvm->arch; + if (!avic) + return 0; + avic_free_vm_id(vm_data->avic_vm_id);Quoted 6 lines
Quoted 3 lines
Review static void avic_vm_destroy(struct kvm *kvm) · line 1391
Quoted 1 line
(quoted diff) +0
-0if (vm_data->avic_logical_id_table_page)Yes, this is the right one.
I can mail this patch, but I can only test build.
No problem, I have applied it locally and I am testing it.
Paolo