Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3029564ybz; Mon, 27 Apr 2020 08:45:39 -0700 (PDT) X-Google-Smtp-Source: APiQypINmcxTxcjc7h7tQgVgqVqz7qbXjjfLB4G1eG6xMuB4IYdod8HohlXExRGeARnGaOIDTdaS X-Received: by 2002:a17:906:4e8f:: with SMTP id v15mr20832160eju.321.1588002339519; Mon, 27 Apr 2020 08:45:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588002339; cv=none; d=google.com; s=arc-20160816; b=Ao3m5AXn42L7jv4DuQkTQv2b29GtW8EDU4ynRNFOkGIIUtrdF61/BuIP9xjzG1qoLZ D3ygYeheMzpGgFBn5PN7TFhNbR3V8vhxJQOLgusEx+LQbmC0fAOU/8CdDZS71zET7Gtb Vl/VWal2waD9FhWzlMr8fNpVd9KJVdtF49Bj+mcH3dQL8Qlb6rGHRg1OKMGXAwDz57hb sZZqBk3XCtGpyHwnSkMeMAx8rU/LyV6IYOFTWKyBLX8nkUWiGfof4Dqu90/iPKnwCJ3m 5xr59YXROR+LCwroMV5iPp62Y9qjUJWbRht037UyDUdWmId5b6QjkhPQJzBn7kBYVh7/ LKFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=lLZ7XRRaI1Gpl8c1cQLS2hZAOx8Bn/MZHFlY/EiF3y4=; b=xHhXIE/yvWtAxXcrCDwFNvnDmeA9gNSq7vA7o4h2A0obtUpQ8ivi39rBfzz2Yf7+kF y6YBPZ7Oo9+ZLCdmw+uqwxznhiHP6UqvXmseb70shcTNw7WwYRdgeNzFd+HA2VpJmG2Z yJNSCMs4AfW5ucz/LlDn+OxtseBCrl7FFBNwzMcTM9LGquTrluJRYePlMcG72SuEPOjF ntsPNogwBSKc88u+I8qGPMp/9gn+wr81G6KPuUt7fK08el2VoXEqh2J8TQysuVjuGg0r 0ITY1838uNG+CQfq2ZlyACus4bV+TNgE3m1mJJtoZsV8jMRW1jBVCGu0zYrgOqxY6uAq zCGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zVyMRiMl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u22si3437786edd.207.2020.04.27.08.45.11; Mon, 27 Apr 2020 08:45:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zVyMRiMl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728121AbgD0PmG (ORCPT + 99 others); Mon, 27 Apr 2020 11:42:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1728032AbgD0PmF (ORCPT ); Mon, 27 Apr 2020 11:42:05 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C308C03C1A7 for ; Mon, 27 Apr 2020 08:42:05 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id x4so133459wmj.1 for ; Mon, 27 Apr 2020 08:42:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=lLZ7XRRaI1Gpl8c1cQLS2hZAOx8Bn/MZHFlY/EiF3y4=; b=zVyMRiMlwP+4cneNlBaaoQ92zIOVybC9w7sTqGp6acGraFBBzMNx47ZgVM0VG2/3EG NEPiBNjfdPgG4SDKj+0hZXH+JyVsqJmkXwHbH2YpKeWHODUK0z6FvTCLldhQr293Uflb v4gpmbFCPThW6+4w69f4HLq/2UwEkekOwNsS7TSBvs+QcpQtPe9usGuV5mRmPQGJthFY l2R0uRiURvPiQYByEuK2PWbtckwm3lDBYJPbjAHVmyfrI47bGJOozdGn8vxxHkK72v98 SUV2DbWN4hTXtML0aeXUJ2ebaeinIsvIAqYBBhocdaABi06WiZ7LFXLH1YH7itElAiXH k5aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=lLZ7XRRaI1Gpl8c1cQLS2hZAOx8Bn/MZHFlY/EiF3y4=; b=F3aaG0l0pj9IH7sUVgvO+P4Fmnta+g+2iT+f5C2CL4s7iAnEq97zmQQP2O3amDQQqr 6NmxmWDpHYmh2JNtryMXxX+DiAfj1fGlkUCicA7ZVquK3uxoC+9dsyzvj360ZGiT7goS o87Wgj+nDiPckUnJj9yWWLZ1Zj/TB8Urzb2EGawF2it/P1e0l9g4xQmzsct/yaINLquA 3AtLFYY14xndC9Nuf42QilEEcmg82zXK0SR5S9GPNjKzwuUx9IfNLBPtkbX2IhVB6cTc Fai5ZJbq0OX6wP9EluZWGUxHgIsFMGF+WjfMsy6hAsQvciF0TIToj5VDZyqY523RkmZV b9XA== X-Gm-Message-State: AGi0PuajI2FgQnUEhMNMutB/QX3Zb6tgqFVeZg510tlv9VK3xK1nD1mQ t2gekcLXgg6ZjCxgzgCDqt+jzgHcXpnpzw== X-Received: by 2002:a1c:9a81:: with SMTP id c123mr52891wme.115.1588002123816; Mon, 27 Apr 2020 08:42:03 -0700 (PDT) Received: from holly.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id w10sm22463339wrg.52.2020.04.27.08.42.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Apr 2020 08:42:03 -0700 (PDT) Date: Mon, 27 Apr 2020 16:42:01 +0100 From: Daniel Thompson To: Douglas Anderson Cc: jason.wessel@windriver.com, gregkh@linuxfoundation.org, kgdb-bugreport@lists.sourceforge.net, mingo@redhat.com, hpa@zytor.com, bp@alien8.de, linux-serial@vger.kernel.org, agross@kernel.org, tglx@linutronix.de, frowand.list@gmail.com, bjorn.andersson@linaro.org, jslaby@suse.com, catalin.marinas@arm.com, corbet@lwn.net, will@kernel.org, Matt Mullins , Nadav Amit , Peter Zijlstra , Rick Edgecombe , linux-kernel@vger.kernel.org, x86@kernel.org Subject: Re: [PATCH v2 4/9] kgdb: Delay "kgdbwait" to dbg_late_init() by default Message-ID: <20200427154201.dxkoctjxta22u7hz@holly.lan> References: <20200421211447.193860-1-dianders@chromium.org> <20200421141234.v2.4.I3113aea1b08d8ce36dc3720209392ae8b815201b@changeid> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200421141234.v2.4.I3113aea1b08d8ce36dc3720209392ae8b815201b@changeid> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 21, 2020 at 02:14:42PM -0700, Douglas Anderson wrote: > Using kgdb requires at least some level of architecture-level > initialization. If nothing else, it relies on the architecture to > pass breakpoints / crashes onto kgdb. > > On some architectures this all works super early, specifically it > starts working at some point in time before Linux parses > early_params's. On other architectures it doesn't. A survey of a few > platforms: > > a) x86: Presumably it all works early since "ekgdboc" is documented to > work here. > b) arm64: Catching crashes works; with a simple patch breakpoints can > also be made to work. > c) arm: Nothing in kgdb works until > paging_init() -> devicemaps_init() -> early_trap_init() > > Let's be conservative and, by default, process "kgdbwait" (which tells > the kernel to drop into the debugger ASAP at boot) a bit later at > dbg_late_init() time. If an architecture has tested it and wants to > re-enable super early debugging, they can implement the weak function > kgdb_arch_can_debug_early() to return true. We'll do this for x86 to > start. It should be noted that dbg_late_init() is still called quite > early in the system. > > Note that this patch doesn't affect when kgdb runs its init. If kgdb > is set to initialize early it will still initialize when parsing > early_params's. This patch _only_ inhibits the initial breakpoint > from "kgdbwait". This means: > > * Without any extra patches arm64 platforms will at least catch > crashes after kgdb inits. > * arm platforms will catch crashes (and could handle a hardcoded > kgdb_breakpoint()) any time after early_trap_init() runs, even > before dbg_late_init(). > > Signed-off-by: Douglas Anderson > Cc: Thomas Gleixner > Cc: Ingo Molnar > Cc: Borislav Petkov Overall this looks good but there is a small quibble below... > diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h > index b072aeb1fd78..7371517aeacc 100644 > --- a/include/linux/kgdb.h > +++ b/include/linux/kgdb.h > @@ -226,6 +226,28 @@ extern int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt); > */ > extern void kgdb_arch_late(void); > > +/** > + * kgdb_arch_can_debug_early - Check if OK to break before dbg_late_init() > + * > + * If an architecture can definitely handle entering the debugger when > + * early_param's are parsed then it can override this function to return > + * true. Otherwise if "kgdbwait" is passed on the kernel command line it > + * won't actually be processed until dbg_late_init() just after the call > + * to kgdb_arch_late() is made. > + * > + * NOTE: Even if this returns false we will still try to register kgdb to > + * handle breakpoints and crashes when early_params's are parsed, we just > + * won't act on the "kgdbwait" parameter until dbg_late_init(). If you > + * get a crash and try to drop into kgdb somewhere between these two > + * places you might or might not end up being able to use kgdb depending > + * on exactly how far along the architecture has initted. > + * > + * ALSO: dbg_late_init() is actually still fairly early in the system > + * boot process. > + * > + * Return: true if platform can handle kgdb early. > + */ > +extern bool kgdb_arch_can_debug_early(void); Does this need to be a function? It looks like all implementations are either return true or return false (e.g. CONFIG_ARCH_HAVE_EARLY_DEBUG would do the same thing). Daniel.