From patchwork Wed Sep 19 23:41:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 11512 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 25D0E23E41 for ; Wed, 19 Sep 2012 23:46:02 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 9BBC6A18B08 for ; Wed, 19 Sep 2012 23:46:01 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so2020369iej.11 for ; Wed, 19 Sep 2012 16:46:01 -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=JaJgbmqFCQvohdgvRErRlG4ZBIdoY1hlvMWaOxFqBik=; b=Etg755nA9CRw1AyrMDPxSdxxQOkr0D3kKaXuNAU7eaLIN8FdpKtI4rPlFByHraEc36 APmo+nw7Bud9GdzSvuUKajBAPKUjfK9MULEFk2Uxoc3LlrrjGo6XmbNUFIdVzwpNPYqk 799NqX1SZWrZle7LP2hNqqASEnovhDafJq2vT/eIkMXLzv/EQgBoFApkMUCYr71s5rF8 P8Kkl+/Tb+uZjvmgR+NJ6lmXzXIuXY3IXPvLoNXBIVO99FX6TjhnbaHz4VzqHS/Y6vAz NLMvSgIehCTwEfq3cH/Eg9gZZj+YsOzgEUncsTCuqqQpwNipzh4QTG9h3pbBlRagxBGx eUCA== Received: by 10.42.84.69 with SMTP id k5mr123080icl.5.1348098361343; Wed, 19 Sep 2012 16:46:01 -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.184.232 with SMTP id ex8csp49676igc; Wed, 19 Sep 2012 16:46:00 -0700 (PDT) Received: by 10.68.189.161 with SMTP id gj1mr2097441pbc.21.1348098360537; Wed, 19 Sep 2012 16:46:00 -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 s7si2186373pax.74.2012.09.19.16.46.00 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 19 Sep 2012 16:46:00 -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 md12so3888025pbc.37 for ; Wed, 19 Sep 2012 16:46:00 -0700 (PDT) Received: by 10.66.90.67 with SMTP id bu3mr1009727pab.26.1348098360233; Wed, 19 Sep 2012 16:46:00 -0700 (PDT) Received: from localhost (ip-64-134-220-225.public.wayport.net. [64.134.220.225]) by mx.google.com with ESMTPS id w4sm1440071paz.38.2012.09.19.16.45.45 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 19 Sep 2012 16:45:59 -0700 (PDT) From: Anton Vorontsov To: Andrew Morton , Russell King , Jason Wessel , Greg Kroah-Hartman , Alan Cox Cc: =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Colin Cross , Brian Swetland , John Stultz , Thomas Gleixner , 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, linux-serial@vger.kernel.org Subject: [PATCH 02/11] kdb: Implement disable_nmi command Date: Wed, 19 Sep 2012 16:41:53 -0700 Message-Id: <1348098122-11041-2-git-send-email-anton.vorontsov@linaro.org> X-Mailer: git-send-email 1.7.11.5 In-Reply-To: <20120919234003.GA24143@lizard> References: <20120919234003.GA24143@lizard> X-Gm-Message-State: ALoCoQlDRTiixw7ChqxbWpawDAubW9+qN/XwSWXTsZ9k0Rf73CRWQN2IUtN9cILWdGPou43xGOwG This command disables NMI-entry. If NMI source has been previously shared with a serial console ("debug port"), this effectively releases the port from KDB exclusive use, and makes the console available for normal use. Of course, NMI can be reenabled, enable_nmi modparam is used for that: echo 1 > /sys/module/kdb/parameters/enable_nmi Signed-off-by: Anton Vorontsov --- kernel/debug/kdb/kdb_main.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c index 31df170..1261dc7 100644 --- a/kernel/debug/kdb/kdb_main.c +++ b/kernel/debug/kdb/kdb_main.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -2107,6 +2108,32 @@ static int kdb_dmesg(int argc, const char **argv) return 0; } #endif /* CONFIG_PRINTK */ + +/* Make sure we balance enable/disable calls, must disable first. */ +static atomic_t kdb_nmi_disabled; + +static int kdb_disable_nmi(int argc, const char *argv[]) +{ + if (atomic_read(&kdb_nmi_disabled)) + return 0; + atomic_set(&kdb_nmi_disabled, 1); + arch_kgdb_ops.enable_nmi(0); + return 0; +} + +static int kdb_param_enable_nmi(const char *val, const struct kernel_param *kp) +{ + if (!atomic_add_unless(&kdb_nmi_disabled, -1, 0)) + return -EINVAL; + arch_kgdb_ops.enable_nmi(1); + return 0; +} + +static const struct kernel_param_ops kdb_param_ops_enable_nmi = { + .set = kdb_param_enable_nmi, +}; +module_param_cb(enable_nmi, &kdb_param_ops_enable_nmi, NULL, 0600); + /* * kdb_cpu - This function implements the 'cpu' command. * cpu [] @@ -2851,6 +2878,10 @@ static void __init kdb_inittab(void) kdb_register_repeat("dmesg", kdb_dmesg, "[lines]", "Display syslog buffer", 0, KDB_REPEAT_NONE); #endif + if (arch_kgdb_ops.enable_nmi) { + kdb_register_repeat("disable_nmi", kdb_disable_nmi, "", + "Disable NMI entry to KDB", 0, KDB_REPEAT_NONE); + } kdb_register_repeat("defcmd", kdb_defcmd, "name \"usage\" \"help\"", "Define a set of commands, down to endefcmd", 0, KDB_REPEAT_NONE); kdb_register_repeat("kill", kdb_kill, "<-signal> ",