From: "Jan Beulich" Subject: [PATCH] x86: prevent call to xfree() in dump_irqs() while in an irq context Date: Mon, 21 May 2012 14:50:26 +0100 Message-ID: <4FBA64420200007800084D93@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartE7C91F32.1__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: andrew.cooper3@citrix.com List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartE7C91F32.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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. Signed-off-by: Andrew Cooper 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(). Signed-off-by: Jan Beulich --- 2012-04-23.orig/xen/arch/x86/irq.c 2012-05-14 17:43:58.000000000 = +0200 +++ 2012-04-23/xen/arch/x86/irq.c 2012-05-21 15:38:01.000000000 = +0200 @@ -2060,7 +2060,7 @@ static void dump_irqs(unsigned char key) if ( !irq_desc_initialized(desc) || desc->handler =3D=3D = &no_irq_type ) continue; =20 - ssid =3D xsm_show_irq_sid(irq); + ssid =3D in_irq() ? NULL : xsm_show_irq_sid(irq); =20 spin_lock_irqsave(&desc->lock, flags); =20 --- 2012-04-23.orig/xen/common/xmalloc_tlsf.c 2011-10-17 08:35:00.0000000= 00 +0200 +++ 2012-04-23/xen/common/xmalloc_tlsf.c 2012-05-21 15:38:31.0000000= 00 +0200 @@ -604,11 +604,11 @@ void xfree(void *p) { struct bhdr *b; =20 - ASSERT(!in_irq()); - if ( p =3D=3D NULL ) return; =20 + ASSERT(!in_irq()); + /* Strip alignment padding. */ b =3D (struct bhdr *)((char *) p - BHDR_OVERHEAD); if ( b->size & 1 ) --=__PartE7C91F32.1__= Content-Type: text/plain; name="x86-irq-fix-dump.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-irq-fix-dump.patch" x86: prevent call to xfree() in dump_irqs() while in an irq context=0A=0ABe= cause of c/s 24707:96987c324a4f, dump_irqs() can now be called in an=0Airq = context when a bug condition is encountered. If this is the case,=0Aignore = the call to xsm_show_irq_ssid() and the subsequent call to=0Axfree().=0A=0A= This prevents an assertion failure in xfree(), and should allow all = the=0Adebug information to be dumped, before failing with a BUG() because = of=0Athe underlying race condition we are attempting to reproduce.=0A=0ASig= ned-off-by: Andrew Cooper =0A=0ARather than = using the non-obvious conditional around an xfree() that=0Awould be passed = NULL only in the inverse case (which could easily get=0Aremoved by a = future change on the basis that calling xfree(NULL) is=0Abenign), switch = the order of checks in xfree() itself and only suppress=0Athe call to XSM = that could potentially call xmalloc().=0A=0ASigned-off-by: Jan Beulich = =0A=0A--- 2012-04-23.orig/xen/arch/x86/irq.c 2012-05-14 = 17:43:58.000000000 +0200=0A+++ 2012-04-23/xen/arch/x86/irq.c 2012-05-21 = 15:38:01.000000000 +0200=0A@@ -2060,7 +2060,7 @@ static void dump_irqs(unsi= gned char key)=0A if ( !irq_desc_initialized(desc) || desc->handler= =3D=3D &no_irq_type )=0A continue;=0A =0A- ssid =3D = xsm_show_irq_sid(irq);=0A+ ssid =3D in_irq() ? NULL : xsm_show_irq_s= id(irq);=0A =0A spin_lock_irqsave(&desc->lock, flags);=0A =0A--- = 2012-04-23.orig/xen/common/xmalloc_tlsf.c 2011-10-17 08:35:00.0000000= 00 +0200=0A+++ 2012-04-23/xen/common/xmalloc_tlsf.c 2012-05-21 = 15:38:31.000000000 +0200=0A@@ -604,11 +604,11 @@ void xfree(void *p)=0A = {=0A struct bhdr *b;=0A =0A- ASSERT(!in_irq());=0A-=0A if ( p = =3D=3D NULL )=0A return;=0A =0A+ ASSERT(!in_irq());=0A+=0A = /* Strip alignment padding. */=0A b =3D (struct bhdr *)((char *) p - = BHDR_OVERHEAD);=0A if ( b->size & 1 )=0A --=__PartE7C91F32.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__PartE7C91F32.1__=--