From patchwork Mon Jul 30 11:58:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 10366 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 591DE23E02 for ; Mon, 30 Jul 2012 12:01:58 +0000 (UTC) Received: from mail-yw0-f52.google.com (mail-yw0-f52.google.com [209.85.213.52]) by fiordland.canonical.com (Postfix) with ESMTP id 28EE2A18AD4 for ; Mon, 30 Jul 2012 12:01:58 +0000 (UTC) Received: by mail-yw0-f52.google.com with SMTP id p61so4596899yhp.11 for ; Mon, 30 Jul 2012 05:01:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=QpNi8X5KnO/rG8S0RRSR3s4AqUWgiBKbMlhEuYFl2So=; b=ZxDLHtvWW7VEhVJqmKESaXwHE1BwTBP8BxkAGHoKtrj9IF9v3xyEUIpC5BazKRjOnJ Buwe5H5LhnjyIV2+qAE3YrYejYQLz6aD8ne6pkcignU5sFON8IH4jTYrCM1x6l2XIwUy jvBZMf1nJ56zwZ9wKodB/ME+hzLAjUie+CxQ9tP9KqHK/IjyM9ZQ/XrM8mZXqv9jWId+ YdIOJbsyy6d4HT8XJCiHnsYCwIVzbFTI52UDT2PpKpKkdisk93P8p3RW0CJMribwkeMf ohL9ckcjYz586tr7D6y9j7InFhwEhd5GbLTveRPagH0sdakreiEbR06XvM0Z8WFFC6ml 6qxA== Received: by 10.42.54.133 with SMTP id r5mr6613874icg.9.1343649717699; Mon, 30 Jul 2012 05:01:57 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.87.40 with SMTP id u8csp84601igz; Mon, 30 Jul 2012 05:01:57 -0700 (PDT) Received: by 10.68.235.236 with SMTP id up12mr34539913pbc.79.1343649717109; Mon, 30 Jul 2012 05:01:57 -0700 (PDT) Received: from mail-pb0-f50.google.com (mail-pb0-f50.google.com [209.85.160.50]) by mx.google.com with ESMTPS id tv8si17383013pbc.32.2012.07.30.05.01.56 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 30 Jul 2012 05:01:57 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of anton.vorontsov@linaro.org) client-ip=209.85.160.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of anton.vorontsov@linaro.org) smtp.mail=anton.vorontsov@linaro.org Received: by mail-pb0-f50.google.com with SMTP id rr4so11040174pbb.37 for ; Mon, 30 Jul 2012 05:01:56 -0700 (PDT) Received: by 10.68.194.168 with SMTP id hx8mr34722982pbc.36.1343649716783; Mon, 30 Jul 2012 05:01:56 -0700 (PDT) Received: from localhost (c-71-204-165-222.hsd1.ca.comcast.net. [71.204.165.222]) by mx.google.com with ESMTPS id wf7sm7815496pbc.34.2012.07.30.05.01.55 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 30 Jul 2012 05:01:56 -0700 (PDT) From: Anton Vorontsov To: Russell King , Jason Wessel , Greg Kroah-Hartman , Alan Cox Cc: =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Colin Cross , John Stultz , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linaro-kernel@lists.linaro.org, patches@linaro.org, kernel-team@android.com, kgdb-bugreport@lists.sourceforge.net Subject: [PATCH 08/11] ARM: kgdb_fiq: Implement knocking into KDB via escape command Date: Mon, 30 Jul 2012 04:58:17 -0700 Message-Id: <1343649500-18491-8-git-send-email-anton.vorontsov@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <20120730115719.GA5742@lizard> References: <20120730115719.GA5742@lizard> X-Gm-Message-State: ALoCoQmwY6npJ93acEchztP9AQtj5yeoGIRrtsA6IMyO/Z8DAdO+mXFOoGDca4oAPrDk2eINyzx6 As Colin Cross noticed, serial ports could be noisy, so occasional characters once in a while are possible. So, considering the noise possibility, entering the debugger on any received byte is unacceptable for production devices. This changes KGDB FIQ behaviour in a such way so that we have to type the GDB-protocol "$3#33" command to actually enter the debugger, the kernel will print the following prompt: Type $3#33 to enter the debugger> This is the exactly the same command we use to escape from KGDB to KDB, so it should be all pretty familiar. For convenience, there is a kgdb_fiq.knock kernel command line option, when set to 0, this turns the special command to just a return key press, so the kernel will be printing this: Hit to enter the debugger> And for the cases when NMI connected to a dedicated button, the knocking can be disabled altogether by setting kgdb_fiq.knock to -1. Suggested-by: Colin Cross Signed-off-by: Anton Vorontsov --- arch/arm/kernel/kgdb_fiq.c | 58 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/arch/arm/kernel/kgdb_fiq.c b/arch/arm/kernel/kgdb_fiq.c index 72a62c7..2bf4467 100644 --- a/arch/arm/kernel/kgdb_fiq.c +++ b/arch/arm/kernel/kgdb_fiq.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -26,6 +27,60 @@ static int kgdb_fiq_enabled; module_param_named(enable, kgdb_fiq_enabled, int, 0600); MODULE_PARM_DESC(enable, "set to 1 to enable FIQ KGDB"); +static int kgdb_fiq_knock = 1; +module_param_named(knock, kgdb_fiq_knock, int, 0600); +MODULE_PARM_DESC(knock, "if set to 1 (default), the special '$3#33' command " + "must be used to enter the debugger; when set to 0, " + "hitting return key is enough to enter the debugger; " + "when set to -1, the debugger is entered immediately " + "upon NMI"); + +/* + * "Serial ports are often noisy, especially when muxed over another port (we + * often use serial over the headset connector). Noise on the async command + * line just causes characters that are ignored, on a command line that blocked + * execution noise would be catastrophic." -- Colin Cross + * + * So, this small function implements KGDB/KDB knocking on the serial line: we + * won't enter the debugger until we receive a known magic phrase (which is + * actually "$3#33", known as "escape to KDB" command. If knocking is disabled, + * just pressing the return key is enough to enter the debugger. + */ +static bool kgdb_fiq_poll_knock(void) +{ + static int n; + int c = -1; + get_char_func *getc; + char magic[] = "$3#33"; + size_t m = strlen(magic); + + if (kgdb_fiq_knock < 0) + return 1; + + for (getc = &kdb_poll_funcs[0]; *getc; ++getc) { + c = (*getc)(); + if (c >= 0) + break; + } + + if (!kgdb_fiq_knock && (c == '\r' || c == '\n')) { + return 1; + } else if (c == magic[n]) { + kdb_printf("%c", c); + n = (n + 1) % m; + if (!n) + return 1; + } else { + n = 0; + kdb_printf("\r%s %s to enter the debugger> %*s", + kgdb_fiq_knock ? "Type" : "Hit", + kgdb_fiq_knock ? magic : "", m, ""); + memset(magic, '\b', m); + kdb_printf("%s", magic); + } + return 0; +} + static unsigned int kgdb_fiq; static void (*kgdb_enable_fiq)(unsigned int irq, bool on); static bool (*is_kgdb_fiq)(unsigned int irq); @@ -36,6 +91,9 @@ asmlinkage void __exception_irq_entry kgdb_fiq_do_handle(struct pt_regs *regs) return; dbg_io_ops->clear_irqs(); + if (!kgdb_fiq_poll_knock()) + return; + nmi_enter(); kgdb_handle_exception(1, 0, 0, regs); nmi_exit();