From patchwork Tue Sep 11 09:34:56 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 11292 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 CC48823EFE for ; Tue, 11 Sep 2012 09:38:05 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id 65598A1866A for ; Tue, 11 Sep 2012 09:38:05 +0000 (UTC) Received: by iafj25 with SMTP id j25so234780iaf.11 for ; Tue, 11 Sep 2012 02:38:04 -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=lYQ0hV6DgyDkt6dxXOwmdLv8KBCJD3XlzMuOfaRM7nBJFDBwOm0SKNFDNDTJ3n6uuL B9rbpN+xHza4vqbwLYENcJZ5vJp1ZF0dhsyvT+sliZuWCmC48M08CGCzImaErnihCPkI DGs/HFD7Yp/p00qt7twg2Zy5z3LcrkBL6/Er9bIDvuACvliovzkbYSgV77odnJz6ThDl OWEtjL6q38xoYXLXSgqS91NB9HkbvfHd/zMpn+T4fM1cMaIQhN5kMuTxg1GSq3dgy88L D/0FW7T+o/IKWcJgPPB3dUQ4OIGYCWMcGpWNQgJrM+BI2ZJvSioSW7zLGhsW1EyREXty 8F8A== Received: by 10.50.7.212 with SMTP id l20mr15630970iga.43.1347356284794; Tue, 11 Sep 2012 02:38:04 -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 ex8csp4768igc; Tue, 11 Sep 2012 02:38:04 -0700 (PDT) Received: by 10.68.202.193 with SMTP id kk1mr10532721pbc.136.1347356284089; Tue, 11 Sep 2012 02:38:04 -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 pn6si24191257pbb.160.2012.09.11.02.38.03 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 11 Sep 2012 02:38:04 -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 md12so636245pbc.37 for ; Tue, 11 Sep 2012 02:38:03 -0700 (PDT) Received: by 10.66.73.9 with SMTP id h9mr25898538pav.76.1347356283756; Tue, 11 Sep 2012 02:38:03 -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 rz10sm9496011pbc.32.2012.09.11.02.38.01 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 11 Sep 2012 02:38:03 -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 , 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/12] kdb: Implement disable_nmi command Date: Tue, 11 Sep 2012 02:34:56 -0700 Message-Id: <1347356106-25368-2-git-send-email-anton.vorontsov@linaro.org> X-Mailer: git-send-email 1.7.11.5 In-Reply-To: <20120911093042.GA12471@lizard> References: <20120911093042.GA12471@lizard> X-Gm-Message-State: ALoCoQmnG8zYlsqb0VWAqCzXTNiAnK7etzz4N/v9G7RSKWJ5p58Ckhd7pX2V+CPIFB9IV60/sL8q 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> ",