Skip to contentSkip to conversation

common/spinlock: Improve the output from check_lock() if it trips

PATCH In review Andrew Cooper 5 participants 6 messages Oct 31, 2017 – Nov 13, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common/spinlock: Improve the output from check_lock() if it trips

If check_lock() triggers, a crash will occur. Instead of simply identifying "the irq context was different", indicate the expected and current irq context.

---
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Tim Deegan <[email protected]>
CC: Wei Liu <[email protected]>
CC: Julien Grall <[email protected]>

check_lock() only exists in debug builds, which makes this a low risk change for 4.10.

---
 xen/common/spinlock.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
xen/common/spinlock.c +7 -1
index 44b07b7..8f2ba08 100644
@@ -44,7 +44,13 @@ static void check_lock(struct lock_debug *debug)
     if ( unlikely(debug->irq_safe != irq_safe) )
     {
         int seen = cmpxchg(&debug->irq_safe, -1, irq_safe);
-        BUG_ON(seen == !irq_safe);
+
+        if ( seen == !irq_safe )
+        {
+            printk("CHECKLOCK FAILURE: prev irqsafe: %d, curr irqsafe %d\n",
+                   seen, irq_safe);
+            BUG();
+        }
     }
 }
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#3 lore raw
In reply to Andrew Cooper

Hi Andrew,

Quoted 5 lines · Andrew Cooper

If check_lock() triggers, a crash will occur. Instead of simply identifying "the irq context was different", indicate the expected and current irq context.

Cheers,

Quoted 35 lines

---
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Tim Deegan <[email protected]>
CC: Wei Liu <[email protected]>
CC: Julien Grall <[email protected]>

check_lock() only exists in debug builds, which makes this a low risk change for 4.10.

---
  xen/common/spinlock.c | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)
xen/common/spinlock.c +7 -1
index 44b07b7..8f2ba08 100644
@@ -44,7 +44,13 @@ static void check_lock(struct lock_debug *debug)
      if ( unlikely(debug->irq_safe != irq_safe) )
      {
          int seen = cmpxchg(&debug->irq_safe, -1, irq_safe);
-        BUG_ON(seen == !irq_safe);
+
+        if ( seen == !irq_safe )
+        {
+            printk("CHECKLOCK FAILURE: prev irqsafe: %d, curr irqsafe %d\n",
+                   seen, irq_safe);
+            BUG();
+        }
      }
  }
 
Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#4 lore raw
In reply to Andrew Cooper
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 31.10.17 at 11:49, <[email protected]> wrote:

xen/common/spinlock.c static void check_lock(struct lock_debug *debug) · line 52

Quoted 10 lines
xen/common/spinlock.c +6 -1
@@ -44,7 +44,13 @@ static void check_lock(struct lock_debug *debug)
     if ( unlikely(debug->irq_safe != irq_safe) )
     {
         int seen = cmpxchg(&debug->irq_safe, -1, irq_safe);
-        BUG_ON(seen == !irq_safe);
+
+        if ( seen == !irq_safe )
+        {
+            printk("CHECKLOCK FAILURE: prev irqsafe: %d, curr irqsafe %d\n",
+                   seen, irq_safe);
+            BUG();

This really should use XENLOG_ERR imo, so that the message won't be lost if warnings are rate limited.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw

Hi Jan,

Quoted 17 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 31.10.17 at 11:49, <[email protected]> wrote:

xen/common/spinlock.c static void check_lock(struct lock_debug *debug) · line 52

Quoted 10 lines
xen/common/spinlock.c +6 -1
@@ -44,7 +44,13 @@ static void check_lock(struct lock_debug *debug)
      if ( unlikely(debug->irq_safe != irq_safe) )
      {
          int seen = cmpxchg(&debug->irq_safe, -1, irq_safe);
-        BUG_ON(seen == !irq_safe);
+
+        if ( seen == !irq_safe )
+        {
+            printk("CHECKLOCK FAILURE: prev irqsafe: %d, curr irqsafe %d\n",
+                   seen, irq_safe);
+            BUG();

This really should use XENLOG_ERR imo, so that the message won't be lost if warnings are rate limited.

The patch was already merged. I guess a follow-up could be done for Xen 4.10.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel