From owner-freebsd-bugs@FreeBSD.ORG Wed Oct 26 04:40:19 2005 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6928216A41F for ; Wed, 26 Oct 2005 04:40:19 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 175AB43D48 for ; Wed, 26 Oct 2005 04:40:19 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.3/8.13.3) with ESMTP id j9Q4eJZq026393 for ; Wed, 26 Oct 2005 04:40:19 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.3/8.13.1/Submit) id j9Q4eIYC026392; Wed, 26 Oct 2005 04:40:18 GMT (envelope-from gnats) Date: Wed, 26 Oct 2005 04:40:18 GMT Message-Id: <200510260440.j9Q4eIYC026392@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: "Lonnie VanZandt" Cc: Subject: Re: kern/87990: [kernel] [patch] SMP Race Condition in kdb_enter/kdb_exit code X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Lonnie VanZandt List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Oct 2005 04:40:19 -0000 The following reply was made to PR kern/87990; it has been noted by GNATS. From: "Lonnie VanZandt" To: Cc: Subject: Re: kern/87990: [kernel] [patch] SMP Race Condition in kdb_enter/kdb_exit code Date: Tue, 25 Oct 2005 22:35:48 -0600 This is a multi-part message in MIME format. ------=_NextPart_000_0185_01C5D9B4.761893B0 Content-Type: multipart/alternative; boundary="----=_NextPart_001_0186_01C5D9B4.761893B0" ------=_NextPart_001_0186_01C5D9B4.761893B0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable The context diff as plaintext and not as an attachment. =20 *** subr_kdb.c.orig Wed Sep 21 15:27:16 2005 --- /tmp/subr_kdb.c Wed Sep 21 15:23:23 2005 *************** *** 444,455 **** =20 makectx(tf, &kdb_pcb); =20 critical_enter(); =20 ! kdb_active++; ! kdb_frame =3D tf; ! kdb_thr_select(curthread); !=20 #ifdef SMP if ((did_stop_cpus =3D kdb_stop_cpus) !=3D 0) { --- 444,454 ---- =20 makectx(tf, &kdb_pcb); =20 + // disable interrupts to our own CPU critical_enter(); =20 ! // halt any other CPUs who might trip over our ! // traps and try to rush into KDB before us #ifdef SMP if ((did_stop_cpus =3D kdb_stop_cpus) !=3D 0) { *************** *** 462,479 **** } #endif =20 /* Let MD code do its thing first... */ kdb_cpu_trap(type, code); =20 handled =3D kdb_dbbe->dbbe_trap(type, code); =20 #ifdef SMP if (did_stop_cpus) restart_cpus(stopped_cpus); #endif =20 ! kdb_active--; !=20 critical_exit(); =20 return (handled); --- 461,497 ---- } #endif =20 + // we can't be interrupted now and we must be + // the only running CPU. So, if kdb_active remains 0 + // then we have won the race to enter KDB, otherwise + // some other CPU beat us through the gate... + if ( 0 !=3D kdb_active ) + { + return 0; + } +=20 + // claim the prize + kdb_active++; +=20 + // set the kdb context + kdb_frame =3D tf; + kdb_thr_select( curthread ); +=20 /* Let MD code do its thing first... */ kdb_cpu_trap(type, code); =20 handled =3D kdb_dbbe->dbbe_trap(type, code); =20 + // release the prize + kdb_active--; +=20 + // let other CPUs have a chance to run #ifdef SMP if (did_stop_cpus) restart_cpus(stopped_cpus); #endif =20 ! // let our own ISRs to run critical_exit(); =20 return (handled); =20 Engineering Reliable Software Solutions...=09 =09 Lonnie VanZandt Consulting Systems Engineer Predictable Response Consulting 637 Witter Gulch Road =20 Evergreen, CO 80439 =09 lonniev@predictableresponse.com IM: lonnievanzandt@yahoo.com =09 tel:=20 fax:=20 mobile: 303 679-6035 303 679-8119 720 201-1349 =09 =09 = Add me to your address book... Want a signature like this?=09 =20 ------=_NextPart_001_0186_01C5D9B4.761893B0 Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable Message
The = context diff as=20 plaintext and not as an attachment.
 
*** subr_kdb.c.orig Wed Sep 21 = 15:27:16=20 2005
--- /tmp/subr_kdb.c Wed Sep 21 15:23:23=20 2005
***************
*** 444,455 ****
 
 =20  makectx(tf, &kdb_pcb);
 
 =20  critical_enter();
 
!  kdb_active++;
! =  kdb_frame=20 =3D tf;
!  kdb_thr_select(curthread);
!
  #ifdef = SMP
 =20  if ((did_stop_cpus =3D kdb_stop_cpus) !=3D 0)
  =    {
---=20 444,454 ----
 
   makectx(tf, = &kdb_pcb);
 =20
+  // disable interrupts to our own CPU
 =20  critical_enter();
 
!  // halt any other CPUs who = might=20 trip over our
!  // traps and try to rush into KDB before = us
 =20 #ifdef SMP
   if ((did_stop_cpus =3D kdb_stop_cpus) !=3D = 0)
 =20    {
***************
*** 462,479 ****
  =   =20 }
  #endif
 
   /* Let MD code do its = thing=20 first... */
   kdb_cpu_trap(type, code);
  =
 =20  handled =3D kdb_dbbe->dbbe_trap(type, code);
  =
  #ifdef=20 SMP
   if (did_stop_cpus)
 =20   restart_cpus(stopped_cpus);
  #endif
 
! =  kdb_active--;
!
   critical_exit();
  =
 =20  return (handled);
--- 461,497 ----
     = }
 =20 #endif
 
+  // we can't be interrupted now and we must = be
+=20  // the only running CPU. So, if kdb_active remains 0
+  // = then we=20 have won the race to enter KDB, otherwise
+  // some other CPU = beat us=20 through the gate...
+  if ( 0 !=3D kdb_active )
+ =  {
+=20   return 0;
+  }
+
+  // claim the = prize
+=20  kdb_active++;
+
+  // set the kdb context
+ =  kdb_frame=20 =3D tf;
+  kdb_thr_select( curthread );
+
   /* = Let MD=20 code do its thing first... */
   kdb_cpu_trap(type,=20 code);
 
   handled =3D = kdb_dbbe->dbbe_trap(type,=20 code);
 
+  // release the prize
+ =  kdb_active--;
+=20
+  // let other CPUs have a chance to run
  #ifdef=20 SMP
   if (did_stop_cpus)
 =20   restart_cpus(stopped_cpus);
  #endif
 
! =  // let our own ISRs to run
  =  critical_exit();
 =20
   return (handled);
 
Engineering Reliable Software=20 Solutions...
Lonnie = VanZandt
Consulting=20 Systems Engineer
Predictable Response = Consulting
637 Witter Gulch = Road
Evergreen, CO=20 80439
lonniev@predictableresponse.com
IM:=20 lonnievanzandt@yahoo.com
tel: =
fax:=20
mobile:
303 679-6035
303 = 679-8119
720=20 201-1349=20 =
Add me to your address = book... Want a signature like=20 this?
 
------=_NextPart_001_0186_01C5D9B4.761893B0-- ------=_NextPart_000_0185_01C5D9B4.761893B0 Content-Type: image/gif; name="Predictable Logo as GIF.gif" Content-Transfer-Encoding: base64 Content-ID: <260253404@26102005-0B99> R0lGODdheQBOAHcAACH+GlNvZnR3YXJlOiBNaWNyb3NvZnQgT2ZmaWNlACwAAAAAeQBOAIcAAAAA ADMAAGYAAJkAAMwAAP8AMwAAMzMAM2YAM5kAM8wAM/8AZgAAZjMAZmYAZpkAZswAZv8AmQAAmTMA mWYAmZkAmcwAmf8AzAAAzDMAzGYAzJkAzMwAzP8A/wAA/zMA/2YA/5kA/8wA//8zAAAzADMzAGYz AJkzAMwzAP8zMwAzMzMzM2YzM5kzM8wzM/8zZgAzZjMzZmYzZpkzZswzZv8zmQAzmTMzmWYzmZkz mcwzmf8zzAAzzDMzzGYzzJkzzMwzzP8z/wAz/zMz/2Yz/5kz/8wz//9mAABmADNmAGZmAJlmAMxm AP9mMwBmMzNmM2ZmM5lmM8xmM/9mZgBmZjNmZmZmZplmZsxmZv9mmQBmmTNmmWZmmZlmmcxmmf9m zABmzDNmzGZmzJlmzMxmzP9m/wBm/zNm/2Zm/5lm/8xm//+ZAACZADOZAGaZAJmZAMyZAP+ZMwCZ MzOZM2aZM5mZM8yZM/+ZZgCZZjOZZmaZZpmZZsyZZv+ZmQCZmTOZmWaZmZ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