From owner-freebsd-current@FreeBSD.ORG Thu Nov 3 18:39:07 2005 Return-Path: X-Original-To: freebsd-current@freebsd.org Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4460516A41F; Thu, 3 Nov 2005 18:39:07 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from speedfactory.net (mail5.speedfactory.net [66.23.216.218]) by mx1.FreeBSD.org (Postfix) with ESMTP id AE68943D46; Thu, 3 Nov 2005 18:39:06 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from server.baldwin.cx (unverified [66.23.211.162]) by speedfactory.net (SurgeMail 3.5b3) with ESMTP id 1316624 for multiple; Thu, 03 Nov 2005 13:37:05 -0500 Received: from localhost (john@localhost [127.0.0.1]) by server.baldwin.cx (8.13.1/8.13.1) with ESMTP id jA3Id2Lq066865; Thu, 3 Nov 2005 13:39:02 -0500 (EST) (envelope-from jhb@freebsd.org) From: John Baldwin To: freebsd-current@freebsd.org, lonnie.vanzandt@ngc.com Date: Thu, 3 Nov 2005 13:27:13 -0500 User-Agent: KMail/1.8.2 References: <200509220742.10364.lonnie.vanzandt@ngc.com> In-Reply-To: <200509220742.10364.lonnie.vanzandt@ngc.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-6" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200511031327.18011.jhb@freebsd.org> X-Spam-Status: No, score=-2.8 required=4.2 tests=ALL_TRUSTED autolearn=failed version=3.0.2 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on server.baldwin.cx X-Server: High Performance Mail Server - http://surgemail.com r=100 Cc: marcel@freebsd.org Subject: Re: Cdiff patch for kernel gdb and mi_switch panic in freebsd 5.4 STABLE X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Nov 2005 18:39:07 -0000 On Sunday 09 October 2005 05:49 pm, Lonnie VanZandt wrote: > Attached is the patch for the revised subr_kdb.c from FreeBSD 5.4 STABLE. > (the rcsid is __FBSDID("$FreeBSD: src/sys/kern/subr_kdb.c,v 1.5.2.2.2.1 > 2005/05/01 05:38:14 dwhite Exp $"); ) I've looked at this, but I think t could maybe be done slightly differently. Here's a suggested patch that would close the race you are seeing I think while allowing semantics such that if two CPUs try to enter KDB at the same time, they would serialize and the second CPU would enter kdb after the first had exited. Could you at least test it to see if it addresses your race condition? --- //depot/projects/smpng/sys/kern/subr_kdb.c 2005/10/27 19:51:50 +++ //depot/user/jhb/ktrace/kern/subr_kdb.c 2005/11/03 18:24:38 @@ -39,6 +39,7 @@ #include #include +#include #include #include @@ -462,12 +463,21 @@ return (0); /* We reenter the debugger through kdb_reenter(). */ - if (kdb_active) + if (kdb_active == PCPU_GET(cpuid) + 1) return (0); critical_enter(); - kdb_active++; + /* + * If more than one CPU tries to enter KDB at the same time + * then force them to serialize and go one at a time. + */ + while (!atomic_cmpset_int(&kdb_active, 0, PCPU_GET(cpuid) + 1)) { + critical_exit(); + while (kdb_active) + cpu_spinwait(); + critical_enter(); + } #ifdef SMP if ((did_stop_cpus = kdb_stop_cpus) != 0) @@ -484,13 +494,17 @@ handled = kdb_dbbe->dbbe_trap(type, code); + /* + * We have to exit KDB before resuming the other CPUs so that they + * may run in a debugger-less context. + */ + kdb_active = 0; + #ifdef SMP if (did_stop_cpus) restart_cpus(stopped_cpus); #endif - kdb_active--; - critical_exit(); return (handled); -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org