From nobody Thu Apr 13 15:18:51 2023 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Py3Bm41hfz45GDb for ; Thu, 13 Apr 2023 15:18:56 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-qt1-x833.google.com (mail-qt1-x833.google.com [IPv6:2607:f8b0:4864:20::833]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Py3Bm10kbz4bKh; Thu, 13 Apr 2023 15:18:56 +0000 (UTC) (envelope-from markjdb@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-qt1-x833.google.com with SMTP id l16so3649618qtv.1; Thu, 13 Apr 2023 08:18:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681399134; x=1683991134; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:sender :from:to:cc:subject:date:message-id:reply-to; bh=cXjtt2fUtoQ9Kxr2xpE89qU6ZlyZDLaFXW3xDYps9qE=; b=fAUodTfCKs/t7+yaelkZZuvHLchN4iYoYqP9y0eVUC/MehO8ZRzgHStCNrsMkC998/ CnDbXDN0RMwIWfOQInImFxPK00S3SKOk6t7k2BtGOyHF/X/x3umGJESkc+vP9NDUR/m+ QhpLckmi//Y0Df6CIDNPo6X6E07UbkaHNoVUOSZbO5k3Oy8k1bXc4ikHJkevOI8OaOUb 3PBrHqBYH+nZY2trPnyFsf12pMKnATfjXEhVJWRII76N82BRRbMT6pwXY3zeHktph+iU zpucNzlGmanR/YXSG+Ibtziel5QShavshDBjXmqAEjCXXPj/ajERScQHIrXHmFZsHQsg 8+VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681399134; x=1683991134; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:sender :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cXjtt2fUtoQ9Kxr2xpE89qU6ZlyZDLaFXW3xDYps9qE=; b=ROhpMdBzb7ZZS0J5ns3yJFxu3U5lZ73KKf11E2eVYBSduyr6WQVwj5VM37l7usO1VI 6fJWiSfaHJ72RA942Eau0RMz/CGOowGqfcFN0tPJUC10cXJl1AnlCv1bvXEsRlM/hr2W OtbBSIZmcb6FD0+ZwKCkm9eRRX26U9iPYpPH1Lq/vC9dPth1Uw72nw5kGo/GyEp/96us 36M5Ry0XqaLSC5n3QVvRqMKNFnW1z2zAwHE2WMEvYElednavFmiiBLVKlfOT7HDWah+I wH8UVg4SJo1BBfrJq6HvDdg3nyyygNxsoXwUylC0EuV8yvSv2NLSeMlXoSrZw364/CWb Zyjg== X-Gm-Message-State: AAQBX9d2oX/zUxcDUduy3jcfItFaguezX9COCZh0YnzCl4aODqufmcm4 sp8dgUank4k14/d8b0Mpm5paxREt7js= X-Google-Smtp-Source: AKy350aXVNQLITmWgGCni7wXqDeBFmFk4MreQiTAO3D6rCvacdm3kwTCw5LkmX2EXCj0C7964GqsYg== X-Received: by 2002:ac8:5b53:0:b0:3db:786f:d91a with SMTP id n19-20020ac85b53000000b003db786fd91amr2655672qtw.57.1681399134611; Thu, 13 Apr 2023 08:18:54 -0700 (PDT) Received: from nuc (192-0-220-237.cpe.teksavvy.com. [192.0.220.237]) by smtp.gmail.com with ESMTPSA id dw20-20020a05620a601400b0074269db4699sm541833qkb.46.2023.04.13.08.18.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 08:18:53 -0700 (PDT) Date: Thu, 13 Apr 2023 11:18:51 -0400 From: Mark Johnston To: =?iso-8859-1?Q?Jean-S=E9bastien_P=E9dron?= Cc: freebsd-hackers@freebsd.org Subject: Re: Handling panics inside vt(4) callbacks Message-ID: References: <4ed85151-09e8-db3e-0e0b-d0a8f3bb937c@FreeBSD.org> List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4ed85151-09e8-db3e-0e0b-d0a8f3bb937c@FreeBSD.org> X-Rspamd-Queue-Id: 4Py3Bm10kbz4bKh X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N On Wed, Apr 12, 2023 at 10:45:27PM +0200, Jean-Sébastien Pédron wrote: > Hi! > > While working on the DRM drivers, I don't always get a kernel core dump > in case of a panic. > > My hypothesis is that if the DRM driver code called by vt(4) panics, > then the panic code might not go through successfully. The reason is > because panic(9) prints the reason, a stacktrace and possibly some > progress to the console, which calls vt(4) and the DRM driver code again. > > I played with the following patch: > https://gist.github.com/dumbbell/88d77789bfeb38869268c84c40575f49 > > The idea is that before calling "vt_flush()" in "vtterm_done()", I set a > global flag to true to indicate that vt(4) is called as part of kdb or a > panic. If another panic occurs inside vt_flush(), typically the > underlying DRM driver code, "vtterm_done()" is called recursively and > "vt_flush()" might trigger the same panic again. If the flag is set, the > entire function is skipped instead. > > I test the patch by adding a panic(9) just before "vt_flush()" and I > trigger the initial panic with debug.kdb.panic=1. I don't even load a > DRM driver. My problem is that in this case, the laptop reboots > immediately. However, if I replace panic(9) with a simple printf(9), it > works as expected and I get a kernel dump. > > I could not find something in panic(9) code that would reboot the > computer in case of a nested panic. In the case of a nested panic, vpanic() will not set RB_DUMP when it calls kern_reboot(), so it won't write a kernel dump. And, if debug.debugger_on_recursive_panic is not set, the kernel will not try to re-enter the debugger. So the kernel will simply reboot. > Previous versions of the patch called doadump() and rebooted the > computer explicitly if the flag was set, but it didn't work either and I > thought I could simplify that patch and let panic(9) handle recursion. > In other words, I just want to skip most of vt(4) code if vt(4) or DRM > crash. Perhaps we should set RB_DUMP in the case of a recursive panic so long as dumping == 0, i.e., we did not panic again while trying to dump core. In fact, kern_reboot() already checks this. > Does someone spot something wrong in my hypothesis or methodology? > > -- > Jean-Sébastien Pédron > The FreeBSD Project >