From patchwork Mon Sep 10 04:13:08 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 11270 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 59FD423F26 for ; Mon, 10 Sep 2012 04:15:47 +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 0AC50A1831C for ; Mon, 10 Sep 2012 04:15:46 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id k11so2310032iea.11 for ; Sun, 09 Sep 2012 21:15:46 -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:date:from :to:cc:subject:message-id:references:mime-version:content-type :content-disposition:in-reply-to:user-agent:x-gm-message-state; bh=Y2j2AzG2cP8jdh2bOQPhPQZVCIJ25PJnsSsj5ZZUrJ4=; b=HX/G0njXrreUCDqUcKk/B3E5UnrJdc0km8hRSt+OiGDb8hlRIuryqr098dhGGFZYtY UP769Y6i2kbfDutjuNWf85xF/HuBtZFbjq35aM7WiEwb2TC1hmGiJPzX4Z86J6G62nYe MRZHvfYDSBXHYUnyTGn/FY2rW/B7qa80VZs00Ps/TuDeuPTiQdaWwLOZ4exMLilII6Nf UmST7AzCUxE/AWaxh1V2h19d3nmN4kqrCMavPcYkmy7kSH1rKh7LZIs9x41FABDXJjq0 bpHFnBDw6+1NM9fx8JOYsTjKu8lva0yg+C20vctp4NERp+tFQcB68QhDZtJd6atYZzaH jApQ== Received: by 10.42.109.194 with SMTP id m2mr15413445icp.48.1347250546804; Sun, 09 Sep 2012 21:15:46 -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 ex8csp72923igc; Sun, 9 Sep 2012 21:15:46 -0700 (PDT) Received: by 10.68.229.73 with SMTP id so9mr3921011pbc.66.1347250546259; Sun, 09 Sep 2012 21:15:46 -0700 (PDT) Received: from mail-pz0-f50.google.com (mail-pz0-f50.google.com [209.85.210.50]) by mx.google.com with ESMTPS id rr1si2743009pbc.248.2012.09.09.21.15.46 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 09 Sep 2012 21:15:46 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.210.50 is neither permitted nor denied by best guess record for domain of anton.vorontsov@linaro.org) client-ip=209.85.210.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.210.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-pz0-f50.google.com with SMTP id e7so1311691dad.37 for ; Sun, 09 Sep 2012 21:15:46 -0700 (PDT) Received: by 10.68.237.38 with SMTP id uz6mr3923877pbc.23.1347250545947; Sun, 09 Sep 2012 21:15:45 -0700 (PDT) Received: from localhost (ip-64-134-230-8.public.wayport.net. [64.134.230.8]) by mx.google.com with ESMTPS id gj9sm1259117pbc.16.2012.09.09.21.15.44 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 09 Sep 2012 21:15:45 -0700 (PDT) Date: Sun, 9 Sep 2012 21:13:08 -0700 From: Anton Vorontsov To: Andrew Morton , Russell King , Jason Wessel , Greg Kroah-Hartman , Alan Cox Cc: Arve =?utf-8?B?SGrDuG5uZXbDpWc=?= , 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 04/14] kdb: Implement disable_nmi command Message-ID: <20120910041308.GD29537@lizard> References: <20120910040802.GA1261@lizard> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20120910040802.GA1261@lizard> User-Agent: Mutt/1.5.21 (2010-09-15) X-Gm-Message-State: ALoCoQmedDJ1bqvC2DPvss+q33ucSThmg5x7GfpsoTMbyBJtHUQK51D61j+B1/jdgX0wlX5rw4eR 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> ",