Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp625389ybk; Fri, 15 May 2020 09:20:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhtGpjRfCCI5UaUbSplrgkOSq8hDk4KGUWtk5ECjQguvuvPk5XiQAEPki/wJK6R4yW/HII X-Received: by 2002:a05:6402:1766:: with SMTP id da6mr3517135edb.119.1589559628222; Fri, 15 May 2020 09:20:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589559628; cv=none; d=google.com; s=arc-20160816; b=WE5Smy9AgQ4kAGN4jXPXxVGB0df+aHfriaTOTsA+/My3RRPUTC6WtWte6IBeIRk3AZ 4ny7HioTI/2wZrShABpOwHBSx7Uo3m5+1sk0k+Cdsa3RMZumJOZnJ38fdvzm8nPjjY6D 7nSGUda/1EsnbV1SUopym2K1E25hMudXzpDIKIwlf4RQKqBa54ytRJ6dbJTDKuggNLbl UC3x6bA5nCrdw2Y+lA3aJrZtBK9jNfaGz+42VMo1YpzVuBGDq/h3o8UyQgYtSZgu4smt BuIl9Id6Wo6gO/X2eOjNdY1eCVtlJInQAXkfwN9GftMgCBYXFKwflurj1ZCqi6N28gka RnyA== 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=dzQ9ZWRTK7rD/i+H1Fdnru9+VEPfr4nmpUnSitdS5yc=; b=UP5Qz3atBxX+Gb/HFueqXNTLpJAvY49dxrQCA3ZB+L1USBY5tNGQjXg7QRkX0XF5lH 5+0IhC96AdgnFJVBIUFiLxPZPNEShojsGr9L9wWssoB+QLDeyGPZFSGfrVilcXLxIVGQ L6YPq3CSuJ/r7N+1UhT1w0FXt1hzA66Nzut4JfMug4b4sBy0MvtZfugXCUW0RHtz3Ahu efW3rJtClvHt26tRERaTef7nE4mE+m2bf74KQz2S9U7FgnIOR/cpQGxpHXsaQ+cBl141 YFWJD+60NPHPTW4Y+emv75YAsb8PVldSYlKnULQ4IEoIRycKh9Z5OtIidDoMZLwp0b25 UxYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qeXeGnfR; 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 yc1si1148852ejb.16.2020.05.15.09.20.02; Fri, 15 May 2020 09:20:28 -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=qeXeGnfR; 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 S1726233AbgEOQSS (ORCPT + 99 others); Fri, 15 May 2020 12:18:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726170AbgEOQSR (ORCPT ); Fri, 15 May 2020 12:18:17 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50B82C05BD09 for ; Fri, 15 May 2020 09:18:16 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id h4so2892195wmb.4 for ; Fri, 15 May 2020 09:18:16 -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=dzQ9ZWRTK7rD/i+H1Fdnru9+VEPfr4nmpUnSitdS5yc=; b=qeXeGnfRgM72ebjuFUB6ERbL/h88bKA9mwClRvT0KfI4TXNsMYUMlqBYktfQqXjRZL 0ighIUR4ASoO9pFh2zujdCDnCUNdLe8G3Xbip+Md8UTLMZlZAWSFElhZjjJZtjfCo8IP yA8H9lYeH4KP0RlH9R0bRro0VDoUhPSqPI83cpa1t1auVVtF5KyNQVDJrhi2ZR+fuiM8 MNlH1B/3cKl8pLyl/T/qSBR6e6e0KcrYUucZsfnE7QV0H1DCojgKOT4FVS8MODPJ8CbS tQRLiRfDXqF852Lsj/2NmZOCZYqmHOembRHZtCpZcghpvqvUm5Zf/ciL6nT7qFRQeZz0 jF5Q== 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=dzQ9ZWRTK7rD/i+H1Fdnru9+VEPfr4nmpUnSitdS5yc=; b=ffFwJMdCFbSu43rLSlUcn5gv4rnO9gBO9prvzVadAdfnbbXIxMMm5shRWaZ83694t8 pOFg1byV8i0P1JWjWx46djvHx/dEtiwuHiYAL8fsuiat6lH+aIJ4uO1ugvR6PRkMdC5h 3UTpfLEsC9TkgO9YrhRy2Rqc0CtZcpcqMaiaiv4Nfie12KP3rNVk8jFoiNIT3IICkiDT vSR/UsAiDQrhJkop+thX0+GORJVh1FmEmh2D8nOWiEC5B9N4ANPc3AbLqFGObnd3HQYI GOShZgy9HSsdLeGFscJDVOydcX2BI7pAzo8AJPx//h4DxOGBiiEIstiuWjKthIjzQKOi sadg== X-Gm-Message-State: AOAM532kPkEiHnN0WmHpsxcz+80BOUoTHfML2vpPmkYpHmBDHlKZTf/M CeyPyW4Sx3KIQJnwoHA7OI3ylA== X-Received: by 2002:a05:600c:4147:: with SMTP id h7mr4710092wmm.178.1589559494828; Fri, 15 May 2020 09:18:14 -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 z124sm2931929wmg.20.2020.05.15.09.18.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2020 09:18:14 -0700 (PDT) Date: Fri, 15 May 2020 17:18:12 +0100 From: Daniel Thompson To: Douglas Anderson Cc: jason.wessel@windriver.com, gregkh@linuxfoundation.org, corbet@lwn.net, frowand.list@gmail.com, bjorn.andersson@linaro.org, linux-serial@vger.kernel.org, mingo@redhat.com, hpa@zytor.com, jslaby@suse.com, kgdb-bugreport@lists.sourceforge.net, sumit.garg@linaro.org, will@kernel.org, tglx@linutronix.de, agross@kernel.org, catalin.marinas@arm.com, bp@alien8.de, Andrew Morton , Krzysztof Kozlowski , linux-kernel@vger.kernel.org, x86@kernel.org Subject: Re: [PATCH v4 04/12] kgdb: Delay "kgdbwait" to dbg_late_init() by default Message-ID: <20200515161812.vs3ry35qcatgf7ut@holly.lan> References: <20200507200850.60646-1-dianders@chromium.org> <20200507130644.v4.4.I3113aea1b08d8ce36dc3720209392ae8b815201b@changeid> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200507130644.v4.4.I3113aea1b08d8ce36dc3720209392ae8b815201b@changeid> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 07, 2020 at 01:08: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 select the > ARCH_HAS_EARLY_DEBUG KConfig option. 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_param'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 > Reviewed-by: Greg Kroah-Hartman I hope to pull this set into the kgdb tree shortly. Any objections to the arch/x86 changes this would bring? Daniel. > --- > > Changes in v4: > - Add "if KGDB" to "select ARCH_HAS_EARLY_DEBUG" in Kconfig. > > Changes in v3: > - Change boolean weak function to KConfig. > > Changes in v2: None > > arch/x86/Kconfig | 1 + > kernel/debug/debug_core.c | 25 +++++++++++++++---------- > lib/Kconfig.kgdb | 18 ++++++++++++++++++ > 3 files changed, 34 insertions(+), 10 deletions(-) > > diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig > index 1197b5596d5a..5f44955ee21c 100644 > --- a/arch/x86/Kconfig > +++ b/arch/x86/Kconfig > @@ -60,6 +60,7 @@ config X86 > select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI > select ARCH_HAS_DEBUG_VIRTUAL > select ARCH_HAS_DEVMEM_IS_ALLOWED > + select ARCH_HAS_EARLY_DEBUG if KGDB > select ARCH_HAS_ELF_RANDOMIZE > select ARCH_HAS_FAST_MULTIPLIER > select ARCH_HAS_FILTER_PGPROT > diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c > index 950dc667c823..503c1630ca76 100644 > --- a/kernel/debug/debug_core.c > +++ b/kernel/debug/debug_core.c > @@ -950,6 +950,14 @@ void kgdb_panic(const char *msg) > kgdb_breakpoint(); > } > > +static void kgdb_initial_breakpoint(void) > +{ > + kgdb_break_asap = 0; > + > + pr_crit("Waiting for connection from remote gdb...\n"); > + kgdb_breakpoint(); > +} > + > void __weak kgdb_arch_late(void) > { > } > @@ -960,6 +968,9 @@ void __init dbg_late_init(void) > if (kgdb_io_module_registered) > kgdb_arch_late(); > kdb_init(KDB_INIT_FULL); > + > + if (kgdb_io_module_registered && kgdb_break_asap) > + kgdb_initial_breakpoint(); > } > > static int > @@ -1055,14 +1066,6 @@ void kgdb_schedule_breakpoint(void) > } > EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint); > > -static void kgdb_initial_breakpoint(void) > -{ > - kgdb_break_asap = 0; > - > - pr_crit("Waiting for connection from remote gdb...\n"); > - kgdb_breakpoint(); > -} > - > /** > * kgdb_register_io_module - register KGDB IO module > * @new_dbg_io_ops: the io ops vector > @@ -1099,7 +1102,8 @@ int kgdb_register_io_module(struct kgdb_io *new_dbg_io_ops) > /* Arm KGDB now. */ > kgdb_register_callbacks(); > > - if (kgdb_break_asap) > + if (kgdb_break_asap && > + (!dbg_is_early || IS_ENABLED(CONFIG_ARCH_HAS_EARLY_DEBUG))) > kgdb_initial_breakpoint(); > > return 0; > @@ -1169,7 +1173,8 @@ static int __init opt_kgdb_wait(char *str) > kgdb_break_asap = 1; > > kdb_init(KDB_INIT_EARLY); > - if (kgdb_io_module_registered) > + if (kgdb_io_module_registered && > + IS_ENABLED(CONFIG_ARCH_HAS_EARLY_DEBUG)) > kgdb_initial_breakpoint(); > > return 0; > diff --git a/lib/Kconfig.kgdb b/lib/Kconfig.kgdb > index 933680b59e2d..ffa7a76de086 100644 > --- a/lib/Kconfig.kgdb > +++ b/lib/Kconfig.kgdb > @@ -124,4 +124,22 @@ config KDB_CONTINUE_CATASTROPHIC > CONFIG_KDB_CONTINUE_CATASTROPHIC == 2. KDB forces a reboot. > If you are not sure, say 0. > > +config ARCH_HAS_EARLY_DEBUG > + bool > + default n > + help > + If an architecture can definitely handle entering the debugger > + when early_param's are parsed then it select this config. > + 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 isn't selected by an architecture we will > + still try to register kgdb to handle breakpoints and crashes > + when early_param'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. > + > endif # KGDB > -- > 2.26.2.645.ge9eca65c58-goog >