Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2807757ybt; Mon, 22 Jun 2020 07:32:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwu2FNjXC7qsajIr9VXqDHqVQSUX1Zn1Yg+jRasx8eBqIFKRuMaa+8ghkYPg0NGmw1iuQzw X-Received: by 2002:a17:906:f88a:: with SMTP id lg10mr11777083ejb.317.1592836349201; Mon, 22 Jun 2020 07:32:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592836349; cv=none; d=google.com; s=arc-20160816; b=j9OR9IqlRNHQyK2y9nSu2sKVj+QyA7g3a01pcIDLrHlkWaPwJ/bJLyAAjDQC2PFRxI ubMQEBRNl6BQj6/dQT5ffjQxLrHYhAJayvE9oVMesNXglKdL0KxkT67P90yz5IZDZkwM F+7NM5yrPdXsw/cnRHIb1TAz/6q5T6m958L4dWPt4YZ83erEKb9/J3TD4VWwBa5/GjwN PqtVg1aOp8damPdVo+hweoKEQmgyuISHmaj8RqVeCCxjzNKbm35hG7ICM3mIdUYRvM/K XotHWMxYzxR2lg3sKQZ9Gl+5px6YxiBSuWn3wjhGjMingPZyQPYgr4Q73gsci16+w0Wb jj5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=8IF9E1gKHyjaeJfo2rxkpn7RVtFle/sJ4XKWmX86Q3Q=; b=A/IUC48eYpRJWqHmh5kJI2ymhnAeAd8dS1i0oTKhwqCO3frgbJ+kZSaHIeG0gNZlnh 6YlLHqc9XdKKITbrnBANDjWd0iV7xLC9Z2LnGFLbCnWzXHk+aKTc5imeIDotCBJka0dv lewZZyfx7Rap2LnY6x+IWI3HwPgOaJy3mBJGvrke36k6QdJaJbhIrp2yUgl0akL6dsb6 RhB3ZTb0V+7EpBwNo8rRAe+zMZ+O+/ZHG1R1A/C2Xgwygd8guZb6aQI8xlUFysVEHdKr qWEBvQu4f6lABqrfCb3QwX4+QTq13CCSqNKFS4L1FFwK82gCOfAb5bmGwvk/LYXOJ0/P KZTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vnopgcIu; 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 ss4si8990006ejb.645.2020.06.22.07.32.06; Mon, 22 Jun 2020 07:32:29 -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=vnopgcIu; 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 S1729522AbgFVO1a (ORCPT + 99 others); Mon, 22 Jun 2020 10:27:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729753AbgFVO1Z (ORCPT ); Mon, 22 Jun 2020 10:27:25 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27404C061795 for ; Mon, 22 Jun 2020 07:27:25 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id e8so2983266pgc.5 for ; Mon, 22 Jun 2020 07:27:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8IF9E1gKHyjaeJfo2rxkpn7RVtFle/sJ4XKWmX86Q3Q=; b=vnopgcIuuGUomYyixYh3vmsH/ZEfcTlDpC9WbItwt2rL5Q/fAjVXnBvbwwOoml4Xop A4WCt4YiyvLALgP7spO6E9WpjRI5FqApFXfKm/XTeM4GWsztkl57XMdB59ib9gjLR7zk akE2I/kgqYJMQGP/cAXVUxx+4PC8BFLzoLMLkQIel8iaYCBE1KVlxO0ohMYj+qR5KTbP yhbnqOiI0guRk7dVDMuLikFBsjozadCgYhD4WJLJCy6/RaZjdIMFrniappbpl3733COV /XvsPO/au4Ik/ONpHzsmRCiDPYfMGMVlJL7MFHhfFFf4iSSPJwedCqKzyzuVDR8ocHV8 Dovw== 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:in-reply-to :references; bh=8IF9E1gKHyjaeJfo2rxkpn7RVtFle/sJ4XKWmX86Q3Q=; b=E8GL/jwqeVE+v2V09/wyMJO5EYUceaIvRM4nsHb/RYClEvI9hd+GqPB+cG3oF2cDF+ rGixrmchF+SOdi8Rwo1gMZy4d/ZiC9U0iDJLIcbNfyBZH3SC7b0GxNfHIFKXbSJLy4LH NGTADbHa2w8OxznOxZLtgrvY6vO7vAL6pwEO2mG42Oz0IUAA+AwpHPgP74YiqeRqthxx e3j1+tfUvEIkjx7z/Np+bvBfqpLchKmSrXAlFZEWC4Ga3Y5LY1oQU8xUHfOH1797HFfa MGw+FxGtDicDxJorBV7y7g6Cb1K1vyYhsk9GZjbiM0S19o4rbX4NuTsVn08BmNAWngK0 g8oA== X-Gm-Message-State: AOAM531s00n5h5rzhhqmH73sHNCCzNTf6GeGmG8GUujCf5RJRAyUkSlk BoNmmzwW/aGrP08fc8IVRmrTQbhATLk= X-Received: by 2002:aa7:9818:: with SMTP id e24mr21368063pfl.30.1592836044694; Mon, 22 Jun 2020 07:27:24 -0700 (PDT) Received: from localhost.localdomain ([117.252.67.186]) by smtp.gmail.com with ESMTPSA id d6sm14547939pjh.5.2020.06.22.07.27.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Jun 2020 07:27:23 -0700 (PDT) From: Sumit Garg To: kgdb-bugreport@lists.sourceforge.net, linux-serial@vger.kernel.org Cc: gregkh@linuxfoundation.org, daniel.thompson@linaro.org, jason.wessel@windriver.com, dianders@chromium.org, jslaby@suse.com, linux@armlinux.org.uk, linux-kernel@vger.kernel.org, Sumit Garg Subject: [PATCH 1/7] serial: kgdb_nmi: Allow NMI console to replace kgdb IO console Date: Mon, 22 Jun 2020 19:56:18 +0530 Message-Id: <1592835984-28613-2-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1592835984-28613-1-git-send-email-sumit.garg@linaro.org> References: <1592835984-28613-1-git-send-email-sumit.garg@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Traditionally, kgdb NMI console relied on cmdline option "console=" to enable/disable consoles. But it didn't took into account DT/ACPI modes which can also provide default preferred console that can be enabled prior to kgdb NMI console. And if that default preferred console is used for debug IO operations as well then it will lead to duplicate consoles representing same physical serial device which in turn leads to duplicate printk messages. In order to avoid this duplication, we need to disable/unregister debug IO console in case the NMI console is enabled successfully. Also, we wouldn't like to see beginning boot messages twice, so we need to remove flag: CON_PRINTBUFFER prior to NMI console registration. Signed-off-by: Sumit Garg --- drivers/tty/serial/kgdb_nmi.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c index 6004c0c..b32c6b1 100644 --- a/drivers/tty/serial/kgdb_nmi.c +++ b/drivers/tty/serial/kgdb_nmi.c @@ -40,6 +40,7 @@ module_param_named(magic, kgdb_nmi_magic, charp, 0600); MODULE_PARM_DESC(magic, "magic sequence to enter NMI debugger (default $3#33)"); static atomic_t kgdb_nmi_num_readers = ATOMIC_INIT(0); +static struct console *orig_dbg_cons; static int kgdb_nmi_console_setup(struct console *co, char *options) { @@ -352,8 +353,22 @@ int kgdb_register_nmi_console(void) goto err_drv_reg; } + /* + * If we already have an active debug IO console, and are switching + * to a NMI console, don't print everything out again, since debug IO + * console, and the NMI console are the same physical device, it's + * annoying to see the beginning boot messages twice. + */ + if (dbg_io_ops->cons && (dbg_io_ops->cons->flags & CON_ENABLED)) { + orig_dbg_cons = dbg_io_ops->cons; + kgdb_nmi_console.flags &= ~CON_PRINTBUFFER; + } + register_console(&kgdb_nmi_console); + if (orig_dbg_cons && (kgdb_nmi_console.flags & CON_ENABLED)) + unregister_console(orig_dbg_cons); + return 0; err_drv_reg: put_tty_driver(kgdb_nmi_tty_driver); @@ -373,6 +388,9 @@ int kgdb_unregister_nmi_console(void) if (ret) return ret; + if (orig_dbg_cons) + register_console(orig_dbg_cons); + ret = tty_unregister_driver(kgdb_nmi_tty_driver); if (ret) return ret; -- 2.7.4