Skip to contentSkip to conversation

drm: Do not use BUG_ON(!spin_is_locked())

PATCH In review Guenter Roeck 6 participants 13 messages Aug 11, 2014 – Sep 1, 2014

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

PATCH 1/1 drm: Do not use BUG_ON(!spin_is_locked())

spin_is_locked() always returns false in uniprocessor configurations and can therefore not be used with BUG_ON. Replace it with assert_spin_locked(), which exists for that very purpose.

---
 drivers/gpu/drm/msm/mdp/mdp_kms.c          | 2 +-
 drivers/gpu/drm/nouveau/core/core/event.c  | 4 ++--
 drivers/gpu/drm/nouveau/core/core/notify.c | 2 +-
 drivers/gpu/drm/omapdrm/omap_irq.c         | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/msm/mdp/mdp_kms.c +1 -1
index 03455b6..92a1531 100644
@@ -34,7 +34,7 @@ static void update_irq(struct mdp_kms *mdp_kms)
 	struct mdp_irq *irq;
 	uint32_t irqmask = mdp_kms->vblank_mask;
 
-	BUG_ON(!spin_is_locked(&list_lock));
+	assert_spin_locked(&list_lock);
 
 	list_for_each_entry(irq, &mdp_kms->irq_list, node)
 		irqmask |= irq->irqmask;
drivers/gpu/drm/nouveau/core/core/event.c +2 -2
index 0540a48..9327117 100644
@@ -26,7 +26,7 @@
 void
 nvkm_event_put(struct nvkm_event *event, u32 types, int index)
 {
-	BUG_ON(!spin_is_locked(&event->refs_lock));
+	assert_spin_locked(&event->refs_lock);
 	while (types) {
 		int type = __ffs(types); types &= ~(1 << type);
 		if (--event->refs[index * event->types_nr + type] == 0) {
@@ -39,7 +39,7 @@ nvkm_event_put(struct nvkm_event *event, u32 types, int index)
 void
 nvkm_event_get(struct nvkm_event *event, u32 types, int index)
 {
-	BUG_ON(!spin_is_locked(&event->refs_lock));
+	assert_spin_locked(&event->refs_lock);
 	while (types) {
 		int type = __ffs(types); types &= ~(1 << type);
 		if (++event->refs[index * event->types_nr + type] == 1) {
drivers/gpu/drm/nouveau/core/core/notify.c +1 -1
index 76adb81..f70dbc4 100644
@@ -98,7 +98,7 @@ nvkm_notify_send(struct nvkm_notify *notify, void *data, u32 size)
 	struct nvkm_event *event = notify->event;
 	unsigned long flags;
 
-	BUG_ON(!spin_is_locked(&event->list_lock));
+	assert_spin_locked(&event->list_lock);
 	BUG_ON(size != notify->size);
 
 	spin_lock_irqsave(&event->refs_lock, flags);
drivers/gpu/drm/omapdrm/omap_irq.c +1 -1
index f035d2b..3eb097e 100644
@@ -34,7 +34,7 @@ static void omap_irq_update(struct drm_device *dev)
 	struct omap_drm_irq *irq;
 	uint32_t irqmask = priv->vblank_mask;
 
-	BUG_ON(!spin_is_locked(&list_lock));
+	assert_spin_locked(&list_lock);
 
 	list_for_each_entry(irq, &priv->irq_list, node)
 		irqmask |= irq->irqmask;
Signature · 1 line
1.9.1
#1 lore raw

Hello Roeck,

This should be replaced everywhere in driver.what do you say ?

Regards
Sanjeev Sharma

Quoted 82 lines · Guenter Roeck

spin_is_locked() always returns false in uniprocessor configurations and can therefore not be used with BUG_ON. Replace it with assert_spin_locked(), which exists for that very purpose.

---
 drivers/gpu/drm/msm/mdp/mdp_kms.c          | 2 +-
 drivers/gpu/drm/nouveau/core/core/event.c  | 4 ++--
 drivers/gpu/drm/nouveau/core/core/notify.c | 2 +-
 drivers/gpu/drm/omapdrm/omap_irq.c         | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/msm/mdp/mdp_kms.c +1 -1
index 03455b6..92a1531 100644
@@ -34,7 +34,7 @@ static void update_irq(struct mdp_kms *mdp_kms)
        struct mdp_irq *irq;
        uint32_t irqmask = mdp_kms->vblank_mask;
 
-       BUG_ON(!spin_is_locked(&list_lock));
+       assert_spin_locked(&list_lock);
 
        list_for_each_entry(irq, &mdp_kms->irq_list, node)
                irqmask |= irq->irqmask;
drivers/gpu/drm/nouveau/core/core/event.c +2 -2
index 0540a48..9327117 100644
@@ -26,7 +26,7 @@
 void
 nvkm_event_put(struct nvkm_event *event, u32 types, int index)
 {
-       BUG_ON(!spin_is_locked(&event->refs_lock));
+       assert_spin_locked(&event->refs_lock);
        while (types) {
                int type = __ffs(types); types &= ~(1 << type);
                if (--event->refs[index * event->types_nr + type] == 0) {
@@ -39,7 +39,7 @@ nvkm_event_put(struct nvkm_event *event, u32 types, int
 index)
 void
 nvkm_event_get(struct nvkm_event *event, u32 types, int index)
 {
-       BUG_ON(!spin_is_locked(&event->refs_lock));
+       assert_spin_locked(&event->refs_lock);
        while (types) {
                int type = __ffs(types); types &= ~(1 << type);
                if (++event->refs[index * event->types_nr + type] == 1) {
drivers/gpu/drm/nouveau/core/core/notify.c +1 -1
index 76adb81..f70dbc4 100644
@@ -98,7 +98,7 @@ nvkm_notify_send(struct nvkm_notify *notify, void *data,
 u32 size)
        struct nvkm_event *event = notify->event;
        unsigned long flags;
 
-       BUG_ON(!spin_is_locked(&event->list_lock));
+       assert_spin_locked(&event->list_lock);
        BUG_ON(size != notify->size);
 
        spin_lock_irqsave(&event->refs_lock, flags);
drivers/gpu/drm/omapdrm/omap_irq.c +1 -2
index f035d2b..3eb097e 100644
@@ -34,7 +34,7 @@ static void omap_irq_update(struct drm_device *dev)
        struct omap_drm_irq *irq;
        uint32_t irqmask = priv->vblank_mask;
 
-       BUG_ON(!spin_is_locked(&list_lock));
+       assert_spin_locked(&list_lock);
 
        list_for_each_entry(irq, &priv->irq_list, node)
                irqmask |= irq->irqmask;
--

1.9.1

Quoted 6 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#2 lore raw
In reply to Guenter Roeck
Quoted 4 lines · Guenter Roeck

spin_is_locked() always returns false in uniprocessor configurations and can therefore not be used with BUG_ON. Replace it with assert_spin_locked(), which exists for that very purpose.

It may be helpful to assess whether any of these sites should be converted to lockdep_assert_held() so they have no cost when lockdep isn't enabled but still reveal problems when debugging.

#3 lore raw

Hello David,

Do you see any problem in replacing with assert_spin_locked() and here is old discusion around the

Quoted 7 lines · David Rientjes
Quoted 4 lines · Guenter Roeck

spin_is_locked() always returns false in uniprocessor configurations and can therefore not be used with BUG_ON. Replace it with assert_spin_locked(), which exists for that very purpose.

Quoted 9 lines

It may be helpful to assess whether any of these sites should be converted to lockdep_assert_held() so they have no cost when lockdep isn't enabled but still reveal problems when debugging.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw

Hello David,

Here is the old discussion carried out on this.

http://linux-kernel.2935.n7.nabble.com/Is-spin-is-locked-safe-to-use-with-BUG-ON-WARN-ON-td654800.html#a921802

Regards
Sanjeev Sharma

On Mon, Aug 11, 2014 at 5:31 PM, sanjeev sharma <[email protected]

Quoted 4 lines

wrote:

Hello David,

Quoted 26 lines

Do you see any problem in replacing with assert_spin_locked() and here is old discusion around the

Quoted 16 lines · David Rientjes
Quoted 4 lines · Guenter Roeck

spin_is_locked() always returns false in uniprocessor configurations and can therefore not be used with BUG_ON. Replace it with assert_spin_locked(), which exists for that very purpose.

It may be helpful to assess whether any of these sites should be converted to lockdep_assert_held() so they have no cost when lockdep isn't enabled but still reveal problems when debugging.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw
Quoted 6 lines · sanjeev sharma

Hello David,

Here is the old discussion carried out on this.

http://linux-kernel.2935.n7.nabble.com/Is-spin-is-locked-safe-to-use-with-BUG-ON-WARN-ON-td654800.html#a921802

I'm suggesting that if you don't want to incur the cost of the conditional everytime you call a certain function with assert_spin_locked() that you could covert these to lockdep_assert_held() so the check is only done when lockdep is enabled for debugging.

#6 lore raw
Quoted 6 lines · David Rientjes
Quoted 4 lines · sanjeev sharma

Hello David,

Here is the old discussion carried out on this.

Quoted 7 lines
Quoted 2 lines

http://linux-kernel.2935.n7.nabble.com/Is-spin-is-locked-safe-to-use-with-BUG-ON-WARN-ON-td654800.html#a921802

I'm suggesting that if you don't want to incur the cost of the conditional everytime you call a certain function with assert_spin_locked() that you could covert these to lockdep_assert_held() so the check is only done when lockdep is enabled for debugging.

not sure about the nouveau parts, but for the omap and msm hunks, this code getting called at potentially vblank rate (so maybe once or twice per ~16ms).. and lockdep has considerable overhead (for a gpu driver) so I don't always have it enabled. So it sounds like for those two at least assert_spin_locked() is a better option.

BR,
-R

Quoted 4 lines

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#7 lore raw
Quoted 11 lines · Rob Clark
Quoted 4 lines

I'm suggesting that if you don't want to incur the cost of the conditional everytime you call a certain function with assert_spin_locked() that you could covert these to lockdep_assert_held() so the check is only done when lockdep is enabled for debugging.

not sure about the nouveau parts, but for the omap and msm hunks, this code getting called at potentially vblank rate (so maybe once or twice per ~16ms).. and lockdep has considerable overhead (for a gpu driver) so I don't always have it enabled. So it sounds like for those two at least assert_spin_locked() is a better option.

Unless there's a bug, assert_spin_locked() is just going to incur an unnecessary cost every time it is called at runtime. My suggestion was to limit that check only to debugging kernels that include enabling lockdep when tracking down problems rather than needlessly evaluating the conditional every time when there are no bugs.

#8 lore raw

Thanks all and I replaced with lockdep_assert_held() which seems less overhead.

Regards
Sanjeev Sharma

Quoted 17 lines · David Rientjes
Quoted 1 line · Rob Clark
Quoted 1 line

I'm suggesting that if you don't want to incur the cost of the

conditional

Quoted 1 line
Quoted 1 line

everytime you call a certain function with assert_spin_locked() that

you

Quoted 1 line
Quoted 1 line

could covert these to lockdep_assert_held() so the check is only done

when

Quoted 8 lines
Quoted 1 line

lockdep is enabled for debugging.

not sure about the nouveau parts, but for the omap and msm hunks, this code getting called at potentially vblank rate (so maybe once or twice per ~16ms).. and lockdep has considerable overhead (for a gpu driver) so I don't always have it enabled. So it sounds like for those two at least assert_spin_locked() is a better option.

Quoted 6 lines

Unless there's a bug, assert_spin_locked() is just going to incur an unnecessary cost every time it is called at runtime. My suggestion was to limit that check only to debugging kernels that include enabling lockdep when tracking down problems rather than needlessly evaluating the conditional every time when there are no bugs.

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#9 lore raw
In reply to David Rientjes
Quoted 14 lines · David Rientjes
Quoted 11 lines · Rob Clark
Quoted 4 lines

I'm suggesting that if you don't want to incur the cost of the conditional everytime you call a certain function with assert_spin_locked() that you could covert these to lockdep_assert_held() so the check is only done when lockdep is enabled for debugging.

not sure about the nouveau parts, but for the omap and msm hunks, this code getting called at potentially vblank rate (so maybe once or twice per ~16ms).. and lockdep has considerable overhead (for a gpu driver) so I don't always have it enabled. So it sounds like for those two at least assert_spin_locked() is a better option.

Quoted 5 lines

Unless there's a bug, assert_spin_locked() is just going to incur an unnecessary cost every time it is called at runtime. My suggestion was to limit that check only to debugging kernels that include enabling lockdep when tracking down problems rather than needlessly evaluating the conditional every time when there are no bugs.

My experience with gpu drivers (i915) has been that hw and the software running it is varied enough that almost always it's better to unconditionally enable this stuff. I much prefer assert_spin_locked and friends over the lockdep versions since enabling full lockdep is not something you usually do. Especially not normal users, and we rely upon them for testing the old stuff. Furthermore for the modeset code the overhead is totally irrelevant since we're doing metric piles of register reads and writes in there anyway.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#10 lore raw

yes you are absolutely correct and the change I have done in other area i.e drivers/usb/storage/uas.c.In gpu drivers assert_spin_locked() make more sense.

Regards
Sanjeev Sharma

Quoted 25 lines · Daniel Vetter
Quoted 3 lines · David Rientjes
Quoted 1 line · Rob Clark
Quoted 1 line

I'm suggesting that if you don't want to incur the cost of the

conditional

Quoted 1 line
Quoted 1 line
Quoted 1 line

everytime you call a certain function with assert_spin_locked() that

you

Quoted 1 line
Quoted 1 line
Quoted 1 line

could covert these to lockdep_assert_held() so the check is only

done when

Quoted 11 lines
Quoted 8 lines
Quoted 1 line

lockdep is enabled for debugging.

not sure about the nouveau parts, but for the omap and msm hunks, this code getting called at potentially vblank rate (so maybe once or twice per ~16ms).. and lockdep has considerable overhead (for a gpu driver) so I don't always have it enabled. So it sounds like for those two at least assert_spin_locked() is a better option.

Unless there's a bug, assert_spin_locked() is just going to incur an unnecessary cost every time it is called at runtime. My suggestion was

to

Quoted 3 lines

limit that check only to debugging kernels that include enabling lockdep when tracking down problems rather than needlessly evaluating the conditional every time when there are no bugs.

Quoted 14 lines

My experience with gpu drivers (i915) has been that hw and the software running it is varied enough that almost always it's better to unconditionally enable this stuff. I much prefer assert_spin_locked and friends over the lockdep versions since enabling full lockdep is not something you usually do. Especially not normal users, and we rely upon them for testing the old stuff. Furthermore for the modeset code the overhead is totally irrelevant since we're doing metric piles of register reads and writes in there anyway.
-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer
#11 lore raw
Quoted 18 lines

ssert_spin_locked() is a better option.

Quoted 17 lines
Quoted 8 lines
Quoted 1 line

Unless there's a bug, assert_spin_locked() is just going to incur an unnecessary cost every time it is called at runtime. My suggestion was to
limit that check only to debugging kernels that include enabling lockdep when tracking down problems rather than needlessly evaluating the conditional every time when there are no bugs.

My experience with gpu drivers (i915) has been that hw and the software running it is varied enough that almost always it's better to unconditionally enable this stuff. I much prefer assert_spin_locked and friends over the lockdep versions since enabling full lockdep is not something you usually do. Especially not normal users, and we rely upon them for testing the old stuff. Furthermore for the modeset code the overhead is totally irrelevant since we're doing metric piles of register reads and writes in there anyway.

Did anything translate into an R-b here?

Dave.

#12 lore raw
In reply to David Rientjes
Quoted 12 lines · David Rientjes
Quoted 4 lines · Guenter Roeck

spin_is_locked() always returns false in uniprocessor configurations and can therefore not be used with BUG_ON. Replace it with assert_spin_locked(), which exists for that very purpose.

It may be helpful to assess whether any of these sites should be converted to lockdep_assert_held() so they have no cost when lockdep isn't enabled but still reveal problems when debugging.

Possibly, but that would need to be done by someone with better knowledge about locking and the code than me.

Guenter