Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1032140ybj; Thu, 7 May 2020 13:10:48 -0700 (PDT) X-Google-Smtp-Source: APiQypKNkwXOO6Fyr1hDzQvk+bch+O/QprZqJUTOKDT0mqjcj8QVnpY5OYUDlKpJIPn9QFKtfP1l X-Received: by 2002:a05:6402:30bb:: with SMTP id df27mr13159673edb.267.1588882248230; Thu, 07 May 2020 13:10:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588882248; cv=none; d=google.com; s=arc-20160816; b=TRRNM8VO7lJuXpFx1BfqihIbYVvv+MTs/mt9ZSX9nKHR3UoV8/089/3uWwd8s/BlpV XgE3fSlgXPi7Tn4grRjwejquvO/Q0rdLl7s01wMRxBRmgrYyFG3S2Tl1q6pWLQlIndJD 18LPsfdT+V7IsPi41OtoIsAw7LhYcsEXXsaMT4kJBTZfCCUY6dbkgPwLluU89s3taiFY Un+ihmGnv92nbAe2uhK2TftaW1Xrs+B62fzT6iJj4SQgz12ypkSlyBWRHt/9vhGkYaE5 gNbwGb1NqLNVA6ldi95LdQ9/fA34L9YJ2JMGzWWvbzNRp1L4wFUXFK83yMTvaDSvwsDy EjcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=KL9EzEs11mB5Vs91mETITkzWTIesusmvUGDSfeOr+zo=; b=Ghi6c20QaqZAg3bzTxBZvPg6WwwslJgXbDiUteu/OPv2/gkyDhkAapvJet85RArQtl UAxh6l8jrrh80uHIcntoBqOtrvACQoJNHCucdi1DgRPYQJsNtia/mSb+VQzBQXJoHYll xptdOQOq4qeRqrMsEpsO/wKpKbzgr8c1kutORMb4fsqDBM8/nSLm6nEUd8wJphvCtflc zN9MgTD8uz5PRw+tkwvylSbzWFHPNKQneLf8kkQOAAJsuSflS2YpLgJ4q3m6vpMbmd84 +cURE7R9pd4phMFBBkigVhXjXz7PfjW466QbnTr+yhR5AAuGD3yXIaFCwlYXeX1k2G6I UUZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=DeX7kVLO; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i12si4019168edn.103.2020.05.07.13.10.25; Thu, 07 May 2020 13:10:48 -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=@chromium.org header.s=google header.b=DeX7kVLO; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728227AbgEGUJB (ORCPT + 99 others); Thu, 7 May 2020 16:09:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726320AbgEGUJA (ORCPT ); Thu, 7 May 2020 16:09:00 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DA60C05BD09 for ; Thu, 7 May 2020 13:09:00 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id 18so3540148pfx.6 for ; Thu, 07 May 2020 13:09:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=KL9EzEs11mB5Vs91mETITkzWTIesusmvUGDSfeOr+zo=; b=DeX7kVLOVMXbc/cBjy87SIJViP8dRtLE9JYWsZFqz92vNtIdLIaHDD2So/Vd2PrSQB t2VfgSYTGbi2BX5/C9YurQA0G8IKcqvp0bzWgxKkzmna4UJNbNj9GPhX1+1zcdVDv5Rq Pg1z0yKWuhYTpeCBt87zjQyBVcfBvgtrNFwQI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=KL9EzEs11mB5Vs91mETITkzWTIesusmvUGDSfeOr+zo=; b=GZ06xo4GDxPr7x8qxAuIkEgAtHXgx4ew9WPehsrSYMC4hQ8uWPtVriL6zLnc9ONFMe a4tDAA1cmfd5IhBYpPROBpI8RI8JpTvx17vgVhqd8gW+vs44fSVxhXMjgHZiVUvYxSkB 01NKhxgHMuYgxMIjWvefveUozhyFCSNNKhclkASG06sWSen6VrxpjLKF4pbTnKGWjtUU hn8WzdK79hc8WyPHypLArBxiPnQkbmPUyJwyu6TsjZLle06ODlOL2DtWytxgFQC9Vh4Q uZ4gsTNLs2VvaMLEZDCOdkwxuXcdHcW/U3L1JprGJ6ZMfOP20QUaWlQ3v5r+XC0IL25v G/ng== X-Gm-Message-State: AGi0Pub1RzS6mPO35FnZjIwStkMqSlFyijxx7vCEyuCnhQfscP67zPtL nYQUi445NVAdZ2DEwtnoDqH7lg== X-Received: by 2002:a62:2cd7:: with SMTP id s206mr15067842pfs.183.1588882139748; Thu, 07 May 2020 13:08:59 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:24fa:e766:52c9:e3b2]) by smtp.gmail.com with ESMTPSA id d203sm5547601pfd.79.2020.05.07.13.08.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2020 13:08:59 -0700 (PDT) From: Douglas Anderson To: jason.wessel@windriver.com, daniel.thompson@linaro.org, gregkh@linuxfoundation.org Cc: 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, Douglas Anderson , Alexios Zavras , Allison Randal , Andrew Morton , Dave Martin , Enrico Weigelt , "Eric W. Biederman" , James Morse , Juergen Gross , Krzysztof Kozlowski , Mark Rutland , Masami Hiramatsu , Mauro Carvalho Chehab , Pawan Gupta , Russell King , jinho lim , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Subject: [PATCH v4 00/12] kgdb: Support late serial drivers; enable early debug w/ boot consoles Date: Thu, 7 May 2020 13:08:38 -0700 Message-Id: <20200507200850.60646-1-dianders@chromium.org> X-Mailer: git-send-email 2.26.2.645.ge9eca65c58-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This whole pile of patches was motivated by me trying to get kgdb to work properly on a platform where my serial driver ended up being hit by the -EPROBE_DEFER virus (it wasn't practicing social distancing from other drivers). Specifically my serial driver's parent device depended on a resource that wasn't available when its probe was first called. It returned -EPROBE_DEFER which meant that when "kgdboc" tried to run its setup the serial driver wasn't there. Unfortunately "kgdboc" never tried again, so that meant that kgdb was disabled until I manually enalbed it via sysfs. While I could try to figure out how to get around the -EPROBE_DEFER somehow, the above problems could happen to anyone and -EPROBE_DEFER is generally considered something you just have to live with. In any case the current "kgdboc" setup is a bit of a race waiting to happen. I _think_ I saw during early testing that even adding a msleep() in the typical serial driver's probe() is enough to trigger similar issues. I decided that for the above race the best attitude to get kgdb to register at boot was probably "if you can't beat 'em, join 'em". Thus, "kgdboc" now jumps on the -EPROBE_DEFER bandwagon (now that my driver uses it it's no longer a virus). It does so a little awkwardly because "kgdboc" hasn't normally had a "struct device" associated with it, but it's really not _that_ ugly to make a platform device and seems less ugly than alternatives. Unfortunately now on my system the debugger is one of the last things to register at boot. That's OK for debugging problems that show up significantly after boot, but isn't so hot for all the boot problems that I end up debugging. This motivated me to try to get something working a little earlier. My first attempt was to try to get the existing "ekgdboc" to work earlier. I tried that for a bit until I realized that it needed to work at the tty layer and I couldn't find any serial drivers that managed to register themselves to the tty layer super early at boot. The only documented use of "ekgdboc" is "ekgdboc=kbd" and that's a bit of a special snowflake. Trying to get my serial driver and all its dependencies to probe normally and register the tty driver super early at boot seemed like a bad way to go. In fact, all the complexity needed to do something like this is why the system already has a special concept of a "boot console" that lives only long enough to transition to the normal console. Leveraging the boot console seemed like a good way to go and that's what this series does. I found that consoles could have a read() function, though I couldn't find anyone who implemented it. I implemented it for two serial drivers for the devices I had easy access to, making the assumption that for boot consoles that we could assume read() and write() were polling-compatible (seems sane I think). Now anyone who makes a small change to their serial driver can easily enable early kgdb debugging! The devices I had for testing were: - arm32: rk3288-veyron-jerry - arm64: rk3399-gru-kevin - arm64: qcom-sc7180-trogdor (not mainline yet) These are the devices I tested this series on. I tried to test various combinations of enabling/disabling various options and I hopefully caught the corner cases, but I'd appreciate any extra testing people can do. Notably I didn't test on x86, but (I think) I didn't touch much there so I shouldn't have broken anything. When testing I found a few problems with actually dropping into the debugger super early on arm and arm64 devices. Patches in this series should help with this. For arm I just avoid dropping into the debugger until a little later and for arm64 I actually enable debugging super early. I realize that bits of this series might feel a little hacky, though I've tried to do things in the cleanest way I could without overly interferring with the rest of the kernel. If you hate the way I solved a problem I would love it if you could provide guidance on how you think I could solve the problem better. This series (and my comments / documentation / commit messages) are now long enough that my eyes glaze over when I try to read it all over to double-check. I've nontheless tried to double-check it, but I'm pretty sure I did something stupid. Thank you ahead of time for pointing it out to me so I can fix it in v5. If somehow I managed to not do anything stupid (really?) then thank you for double-checking me anyway. NOTE: v3 of the patch series tacks on support for an extra serial driver from Sumit Garg. I've piled it onto the end of my series at his request just to keep everything together. Changes in v4: - ("kgdboc: Remove useless #ifdef...") new for v4. - Add "if KGDB" to "select ARCH_HAS_EARLY_DEBUG" in Kconfig. - Add comment about why we always return 0 in kgdboc_earlycon_init(). - Major overhauls to commit message. - No more #ifdef CONFIG_KGDB_SERIAL_CONSOLE. - Now keep using bootcon even when the system stops. - Print "replacing" message before calling deinit(). - earlycon should be static. - s/The the/The/ Changes in v3: - ("kgdb: Prevent infinite recursive entries to the debugger") new for v3. - ("serial: amba-pl011: Support kgdboc_earlycon") pulled into my v3. - Add deinit() to I/O ops to know a driver can be replaced. - Added example in kgdb.rst - Change boolean weak function to KConfig. - Don't just neuter input, panic if earlycon vanishes. - No extra param to kgdb_register_io_module(). - Removed unneeded sentence in kerenel-parameters doc. - Renamed earlycon_kgdboc to kgdboc_earlycon. - Simplify earlycon_kgdb deinit by using the deinit() function. - Suggest people use kgdboc_earlycon instead of ekgdboc. - { ; } ==> { } Changes in v2: - ("Revert "kgdboc: disable the console lock when in kgdb"") new for v2. - ("kgdb: Disable WARN_CONSOLE_UNLOCKED for all kgdb") new for v2. - Assumes we have ("kgdb: Disable WARN_CONSOLE_UNLOCKED for all kgdb") - Fix kgdbts, tty/mips_ejtag_fdc, and usb/early/ehci-dbgp Douglas Anderson (11): kgdb: Disable WARN_CONSOLE_UNLOCKED for all kgdb Revert "kgdboc: disable the console lock when in kgdb" kgdboc: Use a platform device to handle tty drivers showing up late kgdb: Delay "kgdbwait" to dbg_late_init() by default arm64: Add call_break_hook() to early_brk64() for early kgdb kgdb: Prevent infinite recursive entries to the debugger kgdboc: Remove useless #ifdef CONFIG_KGDB_SERIAL_CONSOLE in kgdboc kgdboc: Add kgdboc_earlycon to support early kgdb using boot consoles Documentation: kgdboc: Document new kgdboc_earlycon parameter serial: qcom_geni_serial: Support kgdboc_earlycon serial: 8250_early: Support kgdboc_earlycon Sumit Garg (1): serial: amba-pl011: Support kgdboc_earlycon .../admin-guide/kernel-parameters.txt | 20 ++ Documentation/dev-tools/kgdb.rst | 24 ++ arch/arm64/Kconfig | 1 + arch/arm64/include/asm/debug-monitors.h | 2 + arch/arm64/kernel/debug-monitors.c | 2 +- arch/arm64/kernel/traps.c | 3 + arch/x86/Kconfig | 1 + drivers/tty/serial/8250/8250_early.c | 23 ++ drivers/tty/serial/amba-pl011.c | 32 +++ drivers/tty/serial/kgdboc.c | 268 ++++++++++++++++-- drivers/tty/serial/qcom_geni_serial.c | 32 +++ include/linux/kgdb.h | 4 + kernel/debug/debug_core.c | 52 +++- lib/Kconfig.kgdb | 18 ++ 14 files changed, 436 insertions(+), 46 deletions(-) -- 2.26.2.645.ge9eca65c58-goog