2018-11-11 20:24:40

by Paul E. McKenney

[permalink] [raw]
Subject: [PATCH tip/core/rcu 0/7] Use lockdep instead of asserting spin_is_locked() for v4.21/v5.0

Hello!

This series converts assertions of spin_is_locked() into
lockdep_assert_held(), all courtesy of Lance Roy.

Thanx, Paul

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

arch/x86/pci/i386.c | 2 +-
drivers/net/ethernet/sfc/efx.c | 2 +-
drivers/net/ethernet/smsc/smsc911x.h | 2 +-
fs/userfaultfd.c | 2 +-
kernel/locking/mutex-debug.c | 4 ++--
mm/khugepaged.c | 4 ++--
mm/swap.c | 3 +--
virt/kvm/arm/vgic/vgic.c | 12 ++++++------
8 files changed, 15 insertions(+), 16 deletions(-)



2018-11-11 20:05:47

by Paul E. McKenney

[permalink] [raw]
Subject: [PATCH tip/core/rcu 2/7] sfc: Replace spin_is_locked() with lockdep

From: Lance Roy <[email protected]>

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().

Signed-off-by: Lance Roy <[email protected]>
Cc: Solarflare linux maintainers <[email protected]>
Cc: Edward Cree <[email protected]>
Cc: Bert Kenward <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: <[email protected]>
Signed-off-by: Paul E. McKenney <[email protected]>
---
drivers/net/ethernet/sfc/efx.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/sfc/efx.c b/drivers/net/ethernet/sfc/efx.c
index 98fe7e762e17..3643015a55cf 100644
--- a/drivers/net/ethernet/sfc/efx.c
+++ b/drivers/net/ethernet/sfc/efx.c
@@ -3167,7 +3167,7 @@ struct hlist_head *efx_rps_hash_bucket(struct efx_nic *efx,
{
u32 hash = efx_filter_spec_hash(spec);

- WARN_ON(!spin_is_locked(&efx->rps_hash_lock));
+ lockdep_assert_held(&efx->rps_hash_lock);
if (!efx->rps_hash_table)
return NULL;
return &efx->rps_hash_table[hash % EFX_ARFS_HASH_TABLE_SIZE];
--
2.17.1


2018-11-11 20:05:48

by Paul E. McKenney

[permalink] [raw]
Subject: [PATCH tip/core/rcu 3/7] smsc: Replace spin_is_locked() with lockdep

From: Lance Roy <[email protected]>

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().

Signed-off-by: Lance Roy <[email protected]>
Cc: Steve Glendinning <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: <[email protected]>
Signed-off-by: Paul E. McKenney <[email protected]>
---
drivers/net/ethernet/smsc/smsc911x.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/smsc/smsc911x.h b/drivers/net/ethernet/smsc/smsc911x.h
index 8d75508acd2b..51b2fc1a395f 100644
--- a/drivers/net/ethernet/smsc/smsc911x.h
+++ b/drivers/net/ethernet/smsc/smsc911x.h
@@ -67,7 +67,7 @@

#ifdef CONFIG_DEBUG_SPINLOCK
#define SMSC_ASSERT_MAC_LOCK(pdata) \
- WARN_ON_SMP(!spin_is_locked(&pdata->mac_lock))
+ lockdep_assert_held(&pdata->mac_lock)
#else
#define SMSC_ASSERT_MAC_LOCK(pdata) do {} while (0)
#endif /* CONFIG_DEBUG_SPINLOCK */
--
2.17.1


2018-11-11 20:05:58

by Paul E. McKenney

[permalink] [raw]
Subject: [PATCH tip/core/rcu 1/7] x86/PCI: Replace spin_is_locked() with lockdep

From: Lance Roy <[email protected]>

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().

Signed-off-by: Lance Roy <[email protected]>
Cc: Bjorn Helgaas <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: <[email protected]>
Cc: <[email protected]>
Signed-off-by: Paul E. McKenney <[email protected]>
---
arch/x86/pci/i386.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/pci/i386.c b/arch/x86/pci/i386.c
index 8cd66152cdb0..9df652d3d927 100644
--- a/arch/x86/pci/i386.c
+++ b/arch/x86/pci/i386.c
@@ -59,7 +59,7 @@ static struct pcibios_fwaddrmap *pcibios_fwaddrmap_lookup(struct pci_dev *dev)
{
struct pcibios_fwaddrmap *map;

- WARN_ON_SMP(!spin_is_locked(&pcibios_fwaddrmap_lock));
+ lockdep_assert_held(&pcibios_fwaddrmap_lock);

list_for_each_entry(map, &pcibios_fwaddrmappings, list)
if (map->dev == dev)
--
2.17.1


2018-11-11 20:23:54

by Paul E. McKenney

[permalink] [raw]
Subject: [PATCH tip/core/rcu 7/7] KVM: arm/arm64: vgic: Replace spin_is_locked() with lockdep

From: Lance Roy <[email protected]>

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().

Signed-off-by: Lance Roy <[email protected]>
Cc: Marc Zyngier <[email protected]>
Cc: Eric Auger <[email protected]>
Cc: [email protected]
Cc: <[email protected]>
Signed-off-by: Paul E. McKenney <[email protected]>
Acked-by: Christoffer Dall <[email protected]>
---
virt/kvm/arm/vgic/vgic.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c
index 7cfdfbc910e0..50e25438fb3c 100644
--- a/virt/kvm/arm/vgic/vgic.c
+++ b/virt/kvm/arm/vgic/vgic.c
@@ -196,7 +196,7 @@ void vgic_irq_set_phys_active(struct vgic_irq *irq, bool active)
*/
static struct kvm_vcpu *vgic_target_oracle(struct vgic_irq *irq)
{
- DEBUG_SPINLOCK_BUG_ON(!spin_is_locked(&irq->irq_lock));
+ lockdep_assert_held(&irq->irq_lock);

/* If the interrupt is active, it must stay on the current vcpu */
if (irq->active)
@@ -273,7 +273,7 @@ static void vgic_sort_ap_list(struct kvm_vcpu *vcpu)
{
struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;

- DEBUG_SPINLOCK_BUG_ON(!spin_is_locked(&vgic_cpu->ap_list_lock));
+ lockdep_assert_held(&vgic_cpu->ap_list_lock);

list_sort(NULL, &vgic_cpu->ap_list_head, vgic_irq_cmp);
}
@@ -311,7 +311,7 @@ bool vgic_queue_irq_unlock(struct kvm *kvm, struct vgic_irq *irq,
{
struct kvm_vcpu *vcpu;

- DEBUG_SPINLOCK_BUG_ON(!spin_is_locked(&irq->irq_lock));
+ lockdep_assert_held(&irq->irq_lock);

retry:
vcpu = vgic_target_oracle(irq);
@@ -702,7 +702,7 @@ static inline void vgic_fold_lr_state(struct kvm_vcpu *vcpu)
static inline void vgic_populate_lr(struct kvm_vcpu *vcpu,
struct vgic_irq *irq, int lr)
{
- DEBUG_SPINLOCK_BUG_ON(!spin_is_locked(&irq->irq_lock));
+ lockdep_assert_held(&irq->irq_lock);

if (kvm_vgic_global_state.type == VGIC_V2)
vgic_v2_populate_lr(vcpu, irq, lr);
@@ -736,7 +736,7 @@ static int compute_ap_list_depth(struct kvm_vcpu *vcpu,

*multi_sgi = false;

- DEBUG_SPINLOCK_BUG_ON(!spin_is_locked(&vgic_cpu->ap_list_lock));
+ lockdep_assert_held(&vgic_cpu->ap_list_lock);

list_for_each_entry(irq, &vgic_cpu->ap_list_head, ap_list) {
int w;
@@ -761,7 +761,7 @@ static void vgic_flush_lr_state(struct kvm_vcpu *vcpu)
bool multi_sgi;
u8 prio = 0xff;

- DEBUG_SPINLOCK_BUG_ON(!spin_is_locked(&vgic_cpu->ap_list_lock));
+ lockdep_assert_held(&vgic_cpu->ap_list_lock);

count = compute_ap_list_depth(vcpu, &multi_sgi);
if (count > kvm_vgic_global_state.nr_lr || multi_sgi)
--
2.17.1


2018-11-11 20:24:04

by Paul E. McKenney

[permalink] [raw]
Subject: [PATCH tip/core/rcu 6/7] mm: Replace spin_is_locked() with lockdep

From: Lance Roy <[email protected]>

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().

Signed-off-by: Lance Roy <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: "Kirill A. Shutemov" <[email protected]>
Cc: Yang Shi <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: Mel Gorman <[email protected]>
Acked-by: Vlastimil Babka <[email protected]>
Cc: Jan Kara <[email protected]>
Cc: Shakeel Butt <[email protected]>
Cc: <[email protected]>
Signed-off-by: Paul E. McKenney <[email protected]>
---
mm/khugepaged.c | 4 ++--
mm/swap.c | 3 +--
2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index c13625c1ad5e..7b86600a47c9 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -1225,7 +1225,7 @@ static void collect_mm_slot(struct mm_slot *mm_slot)
{
struct mm_struct *mm = mm_slot->mm;

- VM_BUG_ON(NR_CPUS != 1 && !spin_is_locked(&khugepaged_mm_lock));
+ lockdep_assert_held(&khugepaged_mm_lock);

if (khugepaged_test_exit(mm)) {
/* free mm_slot */
@@ -1631,7 +1631,7 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages,
int progress = 0;

VM_BUG_ON(!pages);
- VM_BUG_ON(NR_CPUS != 1 && !spin_is_locked(&khugepaged_mm_lock));
+ lockdep_assert_held(&khugepaged_mm_lock);

if (khugepaged_scan.mm_slot)
mm_slot = khugepaged_scan.mm_slot;
diff --git a/mm/swap.c b/mm/swap.c
index aa483719922e..5d786019eab9 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -823,8 +823,7 @@ void lru_add_page_tail(struct page *page, struct page *page_tail,
VM_BUG_ON_PAGE(!PageHead(page), page);
VM_BUG_ON_PAGE(PageCompound(page_tail), page);
VM_BUG_ON_PAGE(PageLRU(page_tail), page);
- VM_BUG_ON(NR_CPUS != 1 &&
- !spin_is_locked(&lruvec_pgdat(lruvec)->lru_lock));
+ lockdep_assert_held(&lruvec_pgdat(lruvec)->lru_lock);

if (!list)
SetPageLRU(page_tail);
--
2.17.1


2018-11-11 20:24:11

by Paul E. McKenney

[permalink] [raw]
Subject: [PATCH tip/core/rcu 5/7] locking/mutex: Replace spin_is_locked() with lockdep

From: Lance Roy <[email protected]>

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().

Signed-off-by: Lance Roy <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Will Deacon <[email protected]>
Signed-off-by: Paul E. McKenney <[email protected]>
---
kernel/locking/mutex-debug.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
index 9aa713629387..771d4ca96dda 100644
--- a/kernel/locking/mutex-debug.c
+++ b/kernel/locking/mutex-debug.c
@@ -36,7 +36,7 @@ void debug_mutex_lock_common(struct mutex *lock, struct mutex_waiter *waiter)

void debug_mutex_wake_waiter(struct mutex *lock, struct mutex_waiter *waiter)
{
- SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
+ lockdep_assert_held(&lock->wait_lock);
DEBUG_LOCKS_WARN_ON(list_empty(&lock->wait_list));
DEBUG_LOCKS_WARN_ON(waiter->magic != waiter);
DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
@@ -51,7 +51,7 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
struct task_struct *task)
{
- SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
+ lockdep_assert_held(&lock->wait_lock);

/* Mark the current thread as blocked on the lock: */
task->blocked_on = waiter;
--
2.17.1


2018-11-11 20:25:17

by Paul E. McKenney

[permalink] [raw]
Subject: [PATCH tip/core/rcu 4/7] userfaultfd: Replace spin_is_locked() with lockdep

From: Lance Roy <[email protected]>

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().

Signed-off-by: Lance Roy <[email protected]>
Cc: Alexander Viro <[email protected]>
Cc: <[email protected]>
Signed-off-by: Paul E. McKenney <[email protected]>
---
fs/userfaultfd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
index 356d2b8568c1..681881dc8a9d 100644
--- a/fs/userfaultfd.c
+++ b/fs/userfaultfd.c
@@ -926,7 +926,7 @@ static inline struct userfaultfd_wait_queue *find_userfault_in(
wait_queue_entry_t *wq;
struct userfaultfd_wait_queue *uwq;

- VM_BUG_ON(!spin_is_locked(&wqh->lock));
+ lockdep_assert_held(&wqh->lock);

uwq = NULL;
if (!waitqueue_active(wqh))
--
2.17.1


2018-11-12 13:03:20

by Edward Cree

[permalink] [raw]
Subject: Re: [PATCH tip/core/rcu 2/7] sfc: Replace spin_is_locked() with lockdep

On 11/11/18 20:04, Paul E. McKenney wrote:
> From: Lance Roy <[email protected]>
>
> 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().
>
> Signed-off-by: Lance Roy <[email protected]>
> Cc: Solarflare linux maintainers <[email protected]>
> Cc: Edward Cree <[email protected]>
> Cc: Bert Kenward <[email protected]>
> Cc: "David S. Miller" <[email protected]>
> Cc: <[email protected]>
> Signed-off-by: Paul E. McKenney <[email protected]>
> ---
Acked-by: Edward Cree <[email protected]>
> drivers/net/ethernet/sfc/efx.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/sfc/efx.c b/drivers/net/ethernet/sfc/efx.c
> index 98fe7e762e17..3643015a55cf 100644
> --- a/drivers/net/ethernet/sfc/efx.c
> +++ b/drivers/net/ethernet/sfc/efx.c
> @@ -3167,7 +3167,7 @@ struct hlist_head *efx_rps_hash_bucket(struct efx_nic *efx,
> {
> u32 hash = efx_filter_spec_hash(spec);
>
> - WARN_ON(!spin_is_locked(&efx->rps_hash_lock));
> + lockdep_assert_held(&efx->rps_hash_lock);
> if (!efx->rps_hash_table)
> return NULL;
> return &efx->rps_hash_table[hash % EFX_ARFS_HASH_TABLE_SIZE];



2018-11-12 17:08:48

by Paul E. McKenney

[permalink] [raw]
Subject: Re: [PATCH tip/core/rcu 2/7] sfc: Replace spin_is_locked() with lockdep

On Mon, Nov 12, 2018 at 01:02:32PM +0000, Edward Cree wrote:
> On 11/11/18 20:04, Paul E. McKenney wrote:
> > From: Lance Roy <[email protected]>
> >
> > 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().
> >
> > Signed-off-by: Lance Roy <[email protected]>
> > Cc: Solarflare linux maintainers <[email protected]>
> > Cc: Edward Cree <[email protected]>
> > Cc: Bert Kenward <[email protected]>
> > Cc: "David S. Miller" <[email protected]>
> > Cc: <[email protected]>
> > Signed-off-by: Paul E. McKenney <[email protected]>
> > ---
> Acked-by: Edward Cree <[email protected]>

Applied, thank you!

Thanx, Paul

> > drivers/net/ethernet/sfc/efx.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/ethernet/sfc/efx.c b/drivers/net/ethernet/sfc/efx.c
> > index 98fe7e762e17..3643015a55cf 100644
> > --- a/drivers/net/ethernet/sfc/efx.c
> > +++ b/drivers/net/ethernet/sfc/efx.c
> > @@ -3167,7 +3167,7 @@ struct hlist_head *efx_rps_hash_bucket(struct efx_nic *efx,
> > {
> > u32 hash = efx_filter_spec_hash(spec);
> >
> > - WARN_ON(!spin_is_locked(&efx->rps_hash_lock));
> > + lockdep_assert_held(&efx->rps_hash_lock);
> > if (!efx->rps_hash_table)
> > return NULL;
> > return &efx->rps_hash_table[hash % EFX_ARFS_HASH_TABLE_SIZE];
>
>


2018-11-15 18:51:44

by Davidlohr Bueso

[permalink] [raw]
Subject: Re: [PATCH tip/core/rcu 6/7] mm: Replace spin_is_locked() with lockdep

On Sun, 11 Nov 2018, Paul E. McKenney wrote:

>From: Lance Roy <[email protected]>
>
>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().

So fyi I'm not crazy about these kind of patches simply because lockdep
is a lot less used out of anything that's not a lab, and we can be missing
potential offenders. There's obviously nothing wrong about what you describe
above perse, just my two cents.

Thansk,
Davidlohr

2018-11-16 07:07:01

by Paul E. McKenney

[permalink] [raw]
Subject: Re: [PATCH tip/core/rcu 6/7] mm: Replace spin_is_locked() with lockdep

On Thu, Nov 15, 2018 at 10:49:17AM -0800, Davidlohr Bueso wrote:
> On Sun, 11 Nov 2018, Paul E. McKenney wrote:
>
> >From: Lance Roy <[email protected]>
> >
> >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().
>
> So fyi I'm not crazy about these kind of patches simply because lockdep
> is a lot less used out of anything that's not a lab, and we can be missing
> potential offenders. There's obviously nothing wrong about what you describe
> above perse, just my two cents.

Fair point!

One countervailing advantage of lockdep is that it is not subject to the
false negatives that can happen if someone else happens to be currently
holding the lock. But what would you suggest instead?

Thanx, Paul