Skip to contentSkip to conversation

xen: make CONFIG_DEBUG_LOCKS usable without CONFIG_DEBUG

PATCH In review Juergen Gross 3 participants 8 messages Jan 9, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen: make CONFIG_DEBUG_LOCKS usable without CONFIG_DEBUG

In expert mode it is possible to enable CONFIG_DEBUG_LOCKS without having enabled CONFIG_DEBUG. The coding is depending on CONFIG_DEBUG as it is using ASSERT(), however.

Fix that by introducing assert() doing the same as ASSERT(), but being available in non-debug builds, too, and use that in spinlock debug code.

---
 xen/common/spinlock.c | 2 +-
 xen/include/xen/lib.h | 6 ++++--
 2 files changed, 5 insertions(+), 3 deletions(-)
xen/common/spinlock.c +1 -1
index 286f916bca..8f54580d24 100644
@@ -86,7 +86,7 @@ static void got_lock(union lock_debug *debug)
 static void rel_lock(union lock_debug *debug)
 {
     if ( atomic_read(&spin_debug) > 0 )
-        ASSERT(debug->cpu == smp_processor_id());
+        assert(debug->cpu == smp_processor_id());
     debug->cpu = SPINLOCK_NO_CPU;
 }
 
xen/include/xen/lib.h +4 -2
index 8fbe84032d..000ea677d0 100644
@@ -32,9 +32,11 @@
 #define gcov_string ""
 #endif
 
-#ifndef NDEBUG
-#define ASSERT(p) \
+#define assert(p) \
     do { if ( unlikely(!(p)) ) assert_failed(#p); } while (0)
+
+#ifndef NDEBUG
+#define ASSERT(p) assert(p)
 #define ASSERT_UNREACHABLE() assert_failed("unreachable")
 #define debug_build() 1
 #else
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw
Quoted 3 lines · Juergen Gross

In expert mode it is possible to enable CONFIG_DEBUG_LOCKS without having enabled CONFIG_DEBUG. The coding is depending on CONFIG_DEBUG as it is using ASSERT(), however.

Any reason not to use BUG_ON() in that case?

Having two different asserts is almost certainly going to cause bugs.

-George

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

#2 lore raw
Quoted 6 lines · George Dunlap
Quoted 3 lines · Juergen Gross

In expert mode it is possible to enable CONFIG_DEBUG_LOCKS without having enabled CONFIG_DEBUG. The coding is depending on CONFIG_DEBUG as it is using ASSERT(), however.

Any reason not to use BUG_ON() in that case?

The main reason is the missing message which condition failed.

A rename ("BUG_ASSERT"?) could be an alternative to just dropping the message. Both would be fine with me.

Quoted 2 lines

Having two different asserts is almost certainly going to cause bugs.

Obviously having only one is enough for bugs already. ;-)

Juergen

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

#3 lore raw
Quoted 6 lines · Jürgen Groß
Quoted 5 lines · George Dunlap
Quoted 3 lines · Juergen Gross

In expert mode it is possible to enable CONFIG_DEBUG_LOCKS without having enabled CONFIG_DEBUG. The coding is depending on CONFIG_DEBUG as it is using ASSERT(), however.

Quoted 6 lines
Quoted 1 line

Any reason not to use BUG_ON() in that case?

The main reason is the missing message which condition failed.

A rename ("BUG_ASSERT"?) could be an alternative to just dropping the message. Both would be fine with me.

How about

    if ( ... )
    {
        printk(...);
        BUG();
    }

?

Jan

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

#4 lore raw
Quoted 14 lines · Jan Beulich
Quoted 6 lines · Jürgen Groß
Quoted 5 lines · George Dunlap
Quoted 3 lines · Juergen Gross

In expert mode it is possible to enable CONFIG_DEBUG_LOCKS without having enabled CONFIG_DEBUG. The coding is depending on CONFIG_DEBUG as it is using ASSERT(), however.

Quoted 6 lines
Quoted 1 line

Any reason not to use BUG_ON() in that case?

The main reason is the missing message which condition failed.

A rename ("BUG_ASSERT"?) could be an alternative to just dropping the message. Both would be fine with me.

Quoted 7 lines

How about

    if ( ... )
    {
        printk(...);
        BUG();
    }

Is there a reason we can't make BUG_ON() print the condition?

-George

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

#5 lore raw
Quoted 17 lines · George Dunlap
Quoted 16 lines · Jan Beulich
Quoted 6 lines · Jürgen Groß
Quoted 5 lines · George Dunlap
Quoted 3 lines · Juergen Gross

In expert mode it is possible to enable CONFIG_DEBUG_LOCKS without having enabled CONFIG_DEBUG. The coding is depending on CONFIG_DEBUG as it is using ASSERT(), however.

Quoted 6 lines
Quoted 1 line

Any reason not to use BUG_ON() in that case?

The main reason is the missing message which condition failed.

A rename ("BUG_ASSERT"?) could be an alternative to just dropping the message. Both would be fine with me.

How about

Quoted 7 lines
Quoted 5 lines
    if ( ... )
    {
        printk(...);
        BUG();
    }

Is there a reason we can't make BUG_ON() print the condition?

Of course we could, in principle, at the price of a meaningful growth of the .rodata section. If we do this, perhaps we'd want something like Linux'es CONFIG_DEBUG_BUGVERBOSE to control this.

Jan

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

#6 lore raw
Quoted 24 lines · Jan Beulich
Quoted 23 lines · George Dunlap
Quoted 21 lines · Jan Beulich
Quoted 6 lines · Jürgen Groß
Quoted 5 lines · George Dunlap
Quoted 3 lines · Juergen Gross

In expert mode it is possible to enable CONFIG_DEBUG_LOCKS without having enabled CONFIG_DEBUG. The coding is depending on CONFIG_DEBUG as it is using ASSERT(), however.

Quoted 6 lines
Quoted 1 line

Any reason not to use BUG_ON() in that case?

The main reason is the missing message which condition failed.

A rename ("BUG_ASSERT"?) could be an alternative to just dropping the message. Both would be fine with me.

How about

     if ( ... )
     {
         printk(...);
         BUG();
     }
Quoted 5 lines
Quoted 1 line

Is there a reason we can't make BUG_ON() print the condition?

Of course we could, in principle, at the price of a meaningful growth of the .rodata section. If we do this, perhaps we'd want something like Linux'es CONFIG_DEBUG_BUGVERBOSE to control this.

In case nobody objects I'll modify my patch to do that (well, split it to introduce that option and then use it).

Juergen

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

#7 lore raw
In reply to George Dunlap
Quoted 8 lines · George Dunlap
Quoted 3 lines · Juergen Gross

In expert mode it is possible to enable CONFIG_DEBUG_LOCKS without having enabled CONFIG_DEBUG. The coding is depending on CONFIG_DEBUG as it is using ASSERT(), however.

Any reason not to use BUG_ON() in that case?

Having two different asserts is almost certainly going to cause bugs.

Furthermore, assert() is a C standard library construct, mandated to be controlled by NDEBUG. I.e. if anything at all, ASSERT() could be made behave differently, but of course this would be quite big a change to the code base. +1 to (continue) using BUG_ON() anywhere we want more than just debug build checking.

Jan

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