Skip to contentSkip to conversation

spin_is_locked() conversions for v5.1

PATCH In review Paul E. McKenney 2 participants 5 messages Jan 9, 2019 – Jan 10, 2019

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

cover spin_is_locked() conversions for v5.1

Hello!

This series further de-emphasizes use spin_is_locked()-based warnings in favor of lockdep_assert_held().

1. Remove spin_is_locked() comment from include/asm-generic.

2. Replace spin_is_locked() with lockdep in virt/kvm.

Thanx, Paul

------------------------------------------------------------------------

 include/asm-generic/bug.h |    3 ---
 virt/kvm/kvm_main.c       |    2 +-
 2 files changed, 1 insertion(+), 4 deletions(-)
#1 lore raw

PATCH 1/2 include/asm-generic: Remove spin_is_locked() comment

The WARN_ON_SMP() comment header suggests using spin_is_locked() to check for locks being held. But these days we prefer lockdep_assert_held(), so this commit removes that suggestion.

---
 include/asm-generic/bug.h | 3 ---
 1 file changed, 3 deletions(-)
include/asm-generic/bug.h +0 -3
index 20561a60db9c..0e9bd9c83870 100644
@@ -211,9 +211,6 @@ void __warn(const char *file, int line, void *caller, unsigned taint,
 /*
  * WARN_ON_SMP() is for cases that the warning is either
  * meaningless for !SMP or may even cause failures.
- * This is usually used for cases that we have
- * WARN_ON(!spin_is_locked(&lock)) checks, as spin_is_locked()
- * returns 0 for uniprocessor settings.
  * It can also be used with values that are only defined
  * on SMP:
  *
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/2 virt/kvm: Replace spin_is_locked() with lockdep

In reply to Paul E. McKenney

lockdep_assert_held() is better suited to checking locking requirements, since it only checks if the current thread holds the lock regardless of whether someone else does. This is also a step towards possibly removing spin_is_locked().

Cc Paolo Bonzini <[email protected]>
Cc "Radim Krčmář" <[email protected]>
---
 virt/kvm/kvm_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/kvm_main.c +1 -1
index 1f888a103f78..ec758bb7eeba 100644
@@ -4078,7 +4078,7 @@ static int kvm_suspend(void)
 static void kvm_resume(void)
 {
 	if (kvm_usage_count) {
-		WARN_ON(raw_spin_is_locked(&kvm_count_lock));
+		lockdep_assert_held(&kvm_count_lock);
 		hardware_enable_nolock(NULL);
 	}
 }
Signature · 1 line
2.17.1
maintainer Acked-by on v1 2/2
#3 lore raw

Re: [PATCH tip/core/rcu 2/2] virt/kvm: Replace spin_is_locked() with lockdep

Quoted 19 lines · Paul E. McKenney

lockdep_assert_held() is better suited to checking locking requirements, since it only checks if the current thread holds the lock regardless of whether someone else does. This is also a step towards possibly removing spin_is_locked().

Cc Paolo Bonzini <[email protected]>
Cc "Radim Krčmář" <[email protected]>
---
 virt/kvm/kvm_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/kvm_main.c +0 -0
index 1f888a103f78..ec758bb7eeba 100644

virt/kvm/kvm_main.c static int kvm_suspend(void) · line 4084

Quoted 8 lines
virt/kvm/kvm_main.c +1 -1
@@ -4078,7 +4078,7 @@ static int kvm_suspend(void)
 static void kvm_resume(void)
 {
 	if (kvm_usage_count) {
-		WARN_ON(raw_spin_is_locked(&kvm_count_lock));
+		lockdep_assert_held(&kvm_count_lock);
 		hardware_enable_nolock(NULL);
 	}
 }
author Applied
#4 lore raw

Re: [PATCH tip/core/rcu 2/2] virt/kvm: Replace spin_is_locked() with lockdep

Quoted 14 lines · Paolo Bonzini
Quoted 13 lines · Paul E. McKenney

lockdep_assert_held() is better suited to checking locking requirements, since it only checks if the current thread holds the lock regardless of whether someone else does. This is also a step towards possibly removing spin_is_locked().

Cc Paolo Bonzini <[email protected]>
Cc "Radim Krčmář" <[email protected]>
---
 virt/kvm/kvm_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

virt/kvm/kvm_main.c static int kvm_suspend(void) · line 4084

Quoted 13 lines
virt/kvm/kvm_main.c +1 -1
index 1f888a103f78..ec758bb7eeba 100644
@@ -4078,7 +4078,7 @@ static int kvm_suspend(void)
 static void kvm_resume(void)
 {
 	if (kvm_usage_count) {
-		WARN_ON(raw_spin_is_locked(&kvm_count_lock));
+		lockdep_assert_held(&kvm_count_lock);
 		hardware_enable_nolock(NULL);
 	}
 }

Applied, thank you!

Thanx, Paul