From patchwork Thu Sep 13 15:03:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 11392 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 F216623EB4 for ; Thu, 13 Sep 2012 15:06:33 +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 7A3BCA2675D for ; Thu, 13 Sep 2012 15:06:32 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id k11so4928223iea.11 for ; Thu, 13 Sep 2012 08:06:32 -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=Y2j2AzG2cP8jdh2bOQPhPQZVCIJ25PJnsSsj5ZZUrJ4=; b=ITlV3uaqzWF2X7bZN3g2JM90rjweFUjiPt401oKsLpPuF+nqI9uMZS8SXyQNWBixiN fl31E9KYVndvczzx7FxD6N9mwwT5Qnbm26AJ3hRZYHYfbaM+BeYEx8D6Pyb/6IRykEP/ Yb1UjkLpSZEkOkTvCe7vQOmj9KLpS7vsmmK9XVLy3G1E8xG5rIkejt5Mb2kKvyouY/W+ Z0j24b9sRN06VvvJs04T/4EENyX1q0vrBZdP9MoR7nNTOKXdH2DTeD5mT8c5bp06hi08 +jZ3F5nV6P/XQ/zesSx5YdLz1UqRQ2/E49tHk7BwnAa84geJgs+Wdw4zk+/T9D3sn/UL y8Mg== Received: by 10.50.191.227 with SMTP id hb3mr17374417igc.43.1347548792265; Thu, 13 Sep 2012 08:06:32 -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 ex8csp137322igc; Thu, 13 Sep 2012 08:06:30 -0700 (PDT) Received: by 10.68.225.199 with SMTP id rm7mr5097189pbc.150.1347548789543; Thu, 13 Sep 2012 08:06:29 -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 nr4si28815712pbc.156.2012.09.13.08.06.29 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 13 Sep 2012 08:06:29 -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 md12so4678732pbc.37 for ; Thu, 13 Sep 2012 08:06:29 -0700 (PDT) Received: by 10.68.116.232 with SMTP id jz8mr5124619pbb.77.1347548789037; Thu, 13 Sep 2012 08:06:29 -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 jz10sm13219172pbc.8.2012.09.13.08.06.27 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 13 Sep 2012 08:06:28 -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: Thu, 13 Sep 2012 08:03:26 -0700 Message-Id: <1347548615-18227-2-git-send-email-anton.vorontsov@linaro.org> X-Mailer: git-send-email 1.7.11.5 In-Reply-To: <20120913150133.GA16238@lizard> References: <20120913150133.GA16238@lizard> X-Gm-Message-State: ALoCoQklGJeCLSzUGR3BdfcQERDSn4nhWBF6SeUDp2w92mmxOq8TgjJwY4Vzmn8OesVF1sTTolGW 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 | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c index 31df170..9fadff1 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); + kgdb_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; + kgdb_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,8 @@ static void __init kdb_inittab(void) kdb_register_repeat("dmesg", kdb_dmesg, "[lines]", "Display syslog buffer", 0, KDB_REPEAT_NONE); #endif + 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> ",