Skip to contentSkip to conversation

kvm: initialize SVM spinlock

PATCH In review Dmitry Vyukov 3 participants 9 messages Jan 22, 2017 – Jan 24, 2017

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

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
index 08a4d3ab3455..b928a9c34987 100644
@@ -972,7 +972,7 @@ static void svm_disable_lbrv(struct vcpu_svm *svm)
  */
 #define SVM_VM_DATA_HASH_BITS	8
 DECLARE_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
#1 lore raw

Am 22.01.2017 um 10:04 schrieb Dmitry Vyukov:

Quoted 19 lines

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 +0 -0
index 08a4d3ab3455..b928a9c34987 100644

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	8
 DECLARE_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
#2 lore raw
Quoted 31 lines · David Hildenbrand

Am 22.01.2017 um 10:04 schrieb Dmitry Vyukov:

Quoted 19 lines

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 +0 -0
index 08a4d3ab3455..b928a9c34987 100644

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        8
 DECLARE_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...

#3 lore raw

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_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 +0 -0
index 08a4d3ab3455..b928a9c34987 100644

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        8
 DECLARE_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:

(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
maintainer
#4 lore raw
Quoted 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

maintainer
#5 lore raw
In reply to Dmitry Vyukov

Review 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

#6 lore raw
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.

maintainer
#7 lore raw
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 -0
        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.

No problem, I have applied it locally and I am testing it.

Paolo

#8 lore raw

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 -0
        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.

No problem, I have applied it locally and I am testing it.

Paolo