From owner-freebsd-current@FreeBSD.ORG Fri Nov 18 12:21:59 2011 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E5C451065670 for ; Fri, 18 Nov 2011 12:21:59 +0000 (UTC) (envelope-from freebsd-listen@fabiankeil.de) Received: from smtprelay05.ispgateway.de (smtprelay05.ispgateway.de [80.67.31.98]) by mx1.freebsd.org (Postfix) with ESMTP id 76B8B8FC15 for ; Fri, 18 Nov 2011 12:21:59 +0000 (UTC) Received: from [78.35.81.42] (helo=fabiankeil.de) by smtprelay05.ispgateway.de with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.68) (envelope-from ) id 1RRNS9-0000Bc-Lb for freebsd-current@freebsd.org; Fri, 18 Nov 2011 13:21:57 +0100 Date: Fri, 18 Nov 2011 13:21:54 +0100 From: Fabian Keil To: freebsd-current@freebsd.org Message-ID: <20111118132154.6111dfc3@fabiankeil.de> In-Reply-To: <4EC500CD.6040305@FreeBSD.org> References: <20111113083215.GV50300@deviant.kiev.zoral.com.ua> <20111116202714.5ee4bd53@fabiankeil.de> <4EC43764.1020202@FreeBSD.org> <4EC4423A.3020904@FreeBSD.org> <20111117081533.GP50300@deviant.kiev.zoral.com.ua> <4EC4C89A.2040208@FreeBSD.org> <20111117090653.GR50300@deviant.kiev.zoral.com.ua> <4EC4D3DE.8080103@FreeBSD.org> <20111117111405.GT50300@deviant.kiev.zoral.com.ua> <4EC500CD.6040305@FreeBSD.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=PGP-SHA1; boundary="Sig_/bbrVtMXU2KCXmKRPHha6=ZC"; protocol="application/pgp-signature" X-Df-Sender: Nzc1MDY3 Subject: Re: Stop scheduler on panic 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: Fri, 18 Nov 2011 12:22:00 -0000 --Sig_/bbrVtMXU2KCXmKRPHha6=ZC Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Alexander Motin wrote: > On 11/17/11 13:14, Kostik Belousov wrote: > > On Thu, Nov 17, 2011 at 11:29:02AM +0200, Alexander Motin wrote: > >> On 11/17/11 11:06, Kostik Belousov wrote: > >>> On Thu, Nov 17, 2011 at 10:40:58AM +0200, Alexander Motin wrote: > >>>> On 11/17/11 10:15, Kostik Belousov wrote: > >>>>> On Thu, Nov 17, 2011 at 01:07:38AM +0200, Alexander Motin wrote: > >>>>>> On 17.11.2011 00:21, Andriy Gapon wrote: > >>>>>>> on 16/11/2011 21:27 Fabian Keil said the following: > >>>>>>>> Kostik Belousov wrote: > >>>>>>>> > >>>>>>>>> I was tricked into finishing the work by Andrey Gapon, who deve= loped > >>>>>>>>> the patch to reliably stop other processors on panic. The patch > >>>>>>>>> greatly improves the chances of getting dump on panic on SMP ho= st. > >>>>>>>> > >>>>>>>> I tested the patch trying to get a dump (from the debugger) for > >>>>>>>> kern/162036, which currently results in the double fault reporte= d in: > >>>>>>>> http://lists.freebsd.org/pipermail/freebsd-current/2011-Septembe= r/027766.html > >>>>>>>> > >>>>>>>> It didn't help, but also didn't make anything worse. > >>>>>>> The mi_switch recursion looks very familiar to me: > >>>>>>> mi_switch() at mi_switch+0x270 > >>>>>>> critical_exit() at critical_exit+0x9b > >>>>>>> spinlock_exit() at spinlock_exit+0x17 > >>>>>>> mi_switch() at mi_switch+0x275 > >>>>>>> critical_exit() at critical_exit+0x9b > >>>>>>> spinlock_exit() at spinlock_exit+0x17 > >>>>>>> [several pages of the previous three lines skipped] > >>>>>>> mi_switch() at mi_switch+0x275 > >>>>>>> critical_exit() at critical_exit+0x9b > >>>>>>> spinlock_exit() at spinlock_exit+0x17 > >>>>>>> intr_even_schedule_thread() at intr_event_schedule_thread+0xbb > >>>>>>> ahci_end_transaction() at ahci_end_transaction+0x398 > >>>>>>> ahci_ch_intr() at ahci_ch_intr+0x2b5 > >>>>>>> ahcipoll() at ahcipoll+0x15 > >>>>>>> xpt_polled_action() at xpt_polled_action+0xf7 > >>>>>>> > >>>>>>> In fact I once discussed with jhb this recursion triggered from a= different > >>>>>>> place. To quote myself: > >>>>>>> spinlock_exit -> critical_exit -> mi_switch -> kdb_sw= itch -> > >>>>>>> thread_unlock -> spinlock_exit -> critical_exit -> mi_switch -= > ... > >>>>>>> in the kdb context > >>>>>>> this issue seems to be triggered by td_owepreempt being = true at=20 > >>>>>>> the time > >>>>>>> kdb is entered > >>>>>>> and there of course has to be an initial spinlock_exit c= all=20 > >>>>>>> somewhere > >>>>>>> in my case it's because of usb keyboard > >>>>>>> I wonder if it would make sense to clear td_owepreempt r= ight=20 > >>>>>>> before > >>>>>>> calling kdb_switch in mi_switch > >>>>>>> instead of in sched_switch() > >>>>>>> clearing td_owepreempt seems like a scheduler-independen= t=20 > >>>>>>> operation to me > >>>>>>> or is it better to just skip locking in usb when kdb_act= ive is set > >>>>>>> ? > >>>>>>> > >>>>>>> The workaround described above should work in this case. > >>>>>>> Another possibility is to pessimize mtx_unlock_spin() implementat= ions to=20 > >>>>>>> check > >>>>>>> SCHEDULER_STOPPED() and to bypass any further actions in that cas= e. But=20 > >>>>>>> that > >>>>>>> would add unnecessary overhead to the sunny day code paths. > >>>>>>> > >>>>>>> Going further up the stack one can come up with the following pro= posals: > >>>>>>> - check SCHEDULER_STOPPED() swi_sched() and return early > >>>>>>> - do not call swi_sched() from xpt_done() if we somehow know that= we are=20 > >>>>>>> in a > >>>>>>> polling mode > >>>>>> > >>>>>> There is no flag in CAM now to indicate polling mode, but if neede= d, it=20 > >>>>>> should not be difficult to add one and not call swi_sched(). > >>>>> > >>>>> I have the following change for eons on my test boxes. Without it, > >>>>> I simply cannot get _any_ dump. > >>>> That should be OK for kernel dumping. I was thinking about CAM abusi= ng > >>>> polling not only for dumping. But looking on cases where it does it = now, > >>>> may be it is better to rewrite them instead. > >>> > >>> So, should I interpret your response as 'Reviewed by" ? > >> > >> It feels somehow dirty to me. I don't like these global variables. If > >> you consider it is fine, proceed, I see no much harm. But if not, I can > >> add polling flag to the CAM. Flip a coin for me. :) > > You promised to add the polling at summer' meeting in Kiev. Will you do > > it now ? >=20 > Sorry, I've probably forgot. The patch is attached. After rebasing on r227637 dumping core from the debugger works and the backtrace is at least partly usable. PR updated. Thanks a lot. Fabian --Sig_/bbrVtMXU2KCXmKRPHha6=ZC Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.18 (FreeBSD) iEYEARECAAYFAk7GTecACgkQBYqIVf93VJ1DVACfQYJGodBgUcqaf2XykzMfO8QI oUUAoM54oBHFdNYIi+KOCGvQ7M8MlUNq =eIDt -----END PGP SIGNATURE----- --Sig_/bbrVtMXU2KCXmKRPHha6=ZC--