Skip to contentSkip to conversation

x86: prevent call to xfree() in dump_irqs() while in an irq context

PATCH In review Jan Beulich 3 participants 5 messages May 21, 2012 – May 22, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: prevent call to xfree() in dump_irqs() while in an irq context

Because of c/s 24707:96987c324a4f, dump_irqs() can now be called in an irq context when a bug condition is encountered. If this is the case, ignore the call to xsm_show_irq_ssid() and the subsequent call to xfree().

This prevents an assertion failure in xfree(), and should allow all the debug information to be dumped, before failing with a BUG() because of the underlying race condition we are attempting to reproduce.

Rather than using the non-obvious conditional around an xfree() that would be passed NULL only in the inverse case (which could easily get removed by a future change on the basis that calling xfree(NULL) is benign), switch the order of checks in xfree() itself and only suppress the call to XSM that could potentially call xmalloc().

xen/arch/x86/irq.c +1 -1
@@ -2060,7 +2060,7 @@ static void dump_irqs(unsigned char key)
         if ( !irq_desc_initialized(desc) || desc->handler == &no_irq_type )
             continue;
 
-        ssid = xsm_show_irq_sid(irq);
+        ssid = in_irq() ? NULL : xsm_show_irq_sid(irq);
 
         spin_lock_irqsave(&desc->lock, flags);
 
xen/common/xmalloc_tlsf.c +2 -2
@@ -604,11 +604,11 @@ void xfree(void *p)
 {
     struct bhdr *b;
 
-    ASSERT(!in_irq());
-
     if ( p == NULL )
         return;
 
+    ASSERT(!in_irq());
+
     /* Strip alignment padding. */
     b = (struct bhdr *)((char *) p - BHDR_OVERHEAD);
     if ( b->size & 1 )

x86: prevent call to xfree() in dump_irqs() while in an irq context

Because of c/s 24707:96987c324a4f, dump_irqs() can now be called in an irq context when a bug condition is encountered. If this is the case, ignore the call to xsm_show_irq_ssid() and the subsequent call to xfree().

This prevents an assertion failure in xfree(), and should allow all the debug information to be dumped, before failing with a BUG() because of the underlying race condition we are attempting to reproduce.

Rather than using the non-obvious conditional around an xfree() that would be passed NULL only in the inverse case (which could easily get removed by a future change on the basis that calling xfree(NULL) is benign), switch the order of checks in xfree() itself and only suppress the call to XSM that could potentially call xmalloc().

xen/arch/x86/irq.c +1 -1
@@ -2060,7 +2060,7 @@ static void dump_irqs(unsigned char key)
         if ( !irq_desc_initialized(desc) || desc->handler == &no_irq_type )
             continue;
 
-        ssid = xsm_show_irq_sid(irq);
+        ssid = in_irq() ? NULL : xsm_show_irq_sid(irq);
 
         spin_lock_irqsave(&desc->lock, flags);
 
xen/common/xmalloc_tlsf.c +2 -2
@@ -604,11 +604,11 @@ void xfree(void *p)
 {
     struct bhdr *b;
 
-    ASSERT(!in_irq());
-
     if ( p == NULL )
         return;
 
+    ASSERT(!in_irq());
+
     /* Strip alignment padding. */
     b = (struct bhdr *)((char *) p - BHDR_OVERHEAD);
     if ( b->size & 1 )

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

Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Jan Beulich

Because of c/s 24707:96987c324a4f, dump_irqs() can now be called in an irq context when a bug condition is encountered. If this is the case, ignore the call to xsm_show_irq_ssid() and the subsequent call to xfree().

This prevents an assertion failure in xfree(), and should allow all the debug information to be dumped, before failing with a BUG() because of the underlying race condition we are attempting to reproduce.

Quoted 7 lines

Rather than using the non-obvious conditional around an xfree() that would be passed NULL only in the inverse case (which could easily get removed by a future change on the basis that calling xfree(NULL) is benign), switch the order of checks in xfree() itself and only suppress the call to XSM that could potentially call xmalloc().

Quoted 31 lines
xen/arch/x86/irq.c +1 -1
@@ -2060,7 +2060,7 @@ static void dump_irqs(unsigned char key)
         if ( !irq_desc_initialized(desc) || desc->handler == &no_irq_type )
             continue;
 
-        ssid = xsm_show_irq_sid(irq);
+        ssid = in_irq() ? NULL : xsm_show_irq_sid(irq);
 
         spin_lock_irqsave(&desc->lock, flags);
 
xen/common/xmalloc_tlsf.c +2 -2
@@ -604,11 +604,11 @@ void xfree(void *p)
 {
     struct bhdr *b;
 
-    ASSERT(!in_irq());
-
     if ( p == NULL )
         return;
 
+    ASSERT(!in_irq());
+
     /* Strip alignment padding. */
     b = (struct bhdr *)((char *) p - BHDR_OVERHEAD);
     if ( b->size & 1 )
Signature · 2 lines
Andrew Cooper - Dom0 Kernel Engineer, Citrix XenServer
T: +44 (0)1223 225 900, http://www.citrix.com
#2 lore raw
Quoted 18 lines · Andrew Cooper
Quoted 17 lines · Jan Beulich

Because of c/s 24707:96987c324a4f, dump_irqs() can now be called in an irq context when a bug condition is encountered. If this is the case, ignore the call to xsm_show_irq_ssid() and the subsequent call to xfree().

This prevents an assertion failure in xfree(), and should allow all the debug information to be dumped, before failing with a BUG() because of the underlying race condition we are attempting to reproduce.

Rather than using the non-obvious conditional around an xfree() that would be passed NULL only in the inverse case (which could easily get removed by a future change on the basis that calling xfree(NULL) is benign), switch the order of checks in xfree() itself and only suppress the call to XSM that could potentially call xmalloc().

Quoted 3 lines
Quoted 1 line

I'm a bit dubious about having a function that can be called in irq context for some input values but not others. I suppose this trivial case for xfree() is obvious enough, so I'm okay with it. If it was anything more subtle, I would probably nack.

-- Keir

Quoted 31 lines
Quoted 31 lines
xen/arch/x86/irq.c 2012-05-21 15:38:01.000000000 +0200 renamed from xen/arch/x86/irq.c 2012-05-14 17:43:58.000000000 +0200 +5 -4
@@ -2060,7 +2060,7 @@ static void dump_irqs(unsigned char key)
         if ( !irq_desc_initialized(desc) || desc->handler == &no_irq_type )
             continue;
 
-        ssid = xsm_show_irq_sid(irq);
+        ssid = in_irq() ? NULL : xsm_show_irq_sid(irq);
 
         spin_lock_irqsave(&desc->lock, flags);
 
--- 2012-04-23.orig/xen/common/xmalloc_tlsf.c 2011-10-17 08:35:00.000000000
+0200
+++ 2012-04-23/xen/common/xmalloc_tlsf.c 2012-05-21 15:38:31.000000000 +0200
@@ -604,11 +604,11 @@ void xfree(void *p)
 {
     struct bhdr *b;
 
-    ASSERT(!in_irq());
-
     if ( p == NULL )
         return;
 
+    ASSERT(!in_irq());
+
     /* Strip alignment padding. */
     b = (struct bhdr *)((char *) p - BHDR_OVERHEAD);
     if ( b->size & 1 )
#3 lore raw
Quoted 21 lines
Quoted 1 line
Quoted 1 line · Keir Fraser
Quoted 18 lines · Andrew Cooper
Quoted 17 lines · Jan Beulich

Because of c/s 24707:96987c324a4f, dump_irqs() can now be called in an irq context when a bug condition is encountered. If this is the case, ignore the call to xsm_show_irq_ssid() and the subsequent call to xfree().

This prevents an assertion failure in xfree(), and should allow all the debug information to be dumped, before failing with a BUG() because of the underlying race condition we are attempting to reproduce.

Rather than using the non-obvious conditional around an xfree() that would be passed NULL only in the inverse case (which could easily get removed by a future change on the basis that calling xfree(NULL) is benign), switch the order of checks in xfree() itself and only suppress the call to XSM that could potentially call xmalloc().

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

I'm a bit dubious about having a function that can be called in irq context for some input values but not others. I suppose this trivial case for xfree() is obvious enough, so I'm okay with it. If it was anything more subtle, I would probably nack.

I did ask that in the original thread, but you never responded either way. Is your above reply an ack then, or should I commit Andy's original patch instead?

Jan

#4 lore raw
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 9 lines
Quoted 7 lines

Rather than using the non-obvious conditional around an xfree() that would be passed NULL only in the inverse case (which could easily get removed by a future change on the basis that calling xfree(NULL) is benign), switch the order of checks in xfree() itself and only suppress the call to XSM that could potentially call xmalloc().

Quoted 8 lines
Quoted 4 lines

I'm a bit dubious about having a function that can be called in irq context for some input values but not others. I suppose this trivial case for xfree() is obvious enough, so I'm okay with it. If it was anything more subtle, I would probably nack.

I did ask that in the original thread, but you never responded either way. Is your above reply an ack then, or should I commit Andy's original patch instead?

It's an Ack :)