linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sumit Garg <sumit.garg@linaro.org>
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 <sumit.garg@linaro.org>
Subject: [PATCH 1/7] serial: kgdb_nmi: Allow NMI console to replace kgdb IO console
Date: Mon, 22 Jun 2020 19:56:18 +0530	[thread overview]
Message-ID: <1592835984-28613-2-git-send-email-sumit.garg@linaro.org> (raw)
In-Reply-To: <1592835984-28613-1-git-send-email-sumit.garg@linaro.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 <sumit.garg@linaro.org>
---
 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


  reply	other threads:[~2020-06-22 14:27 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-22 14:26 [PATCH 0/7] Enable support for kgdb NMI console feature Sumit Garg
2020-06-22 14:26 ` Sumit Garg [this message]
2020-06-22 14:26 ` [PATCH 2/7] tty: serial: Add poll_get_irq() to the polling interface Sumit Garg
2020-06-22 15:56   ` Daniel Thompson
2020-06-23  7:48     ` Sumit Garg
2020-06-23 10:52       ` Daniel Thompson
2020-06-22 14:26 ` [PATCH 3/7] kgdb: Add request_nmi() to the io ops table for kgdboc Sumit Garg
2020-06-22 16:03   ` Daniel Thompson
2020-06-23  8:37     ` Sumit Garg
2020-06-23 10:59       ` Daniel Thompson
2020-06-26 19:44         ` Doug Anderson
2020-06-29 11:45           ` Daniel Thompson
2020-06-30  6:09             ` Sumit Garg
2020-06-22 14:26 ` [PATCH 4/7] serial: kgdb_nmi: Add support for interrupt based fallback Sumit Garg
2020-06-22 16:36   ` Daniel Thompson
2020-06-23  9:59     ` Sumit Garg
2020-06-22 14:26 ` [PATCH 5/7] serial: 8250: Implement poll_get_irq() interface Sumit Garg
2020-06-22 14:26 ` [PATCH 6/7] serial: amba-pl011: " Sumit Garg
2020-06-22 14:26 ` [PATCH 7/7] serial: kgdb_nmi: Replace hrtimer with irq_work ping Sumit Garg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1592835984-28613-2-git-send-email-sumit.garg@linaro.org \
    --to=sumit.garg@linaro.org \
    --cc=daniel.thompson@linaro.org \
    --cc=dianders@chromium.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jason.wessel@windriver.com \
    --cc=jslaby@suse.com \
    --cc=kgdb-bugreport@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).