From patchwork Mon Aug 20 14:47:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 10805 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 88D3323E56 for ; Mon, 20 Aug 2012 14:50:06 +0000 (UTC) Received: from mail-gg0-f180.google.com (mail-gg0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id 4652EA18B4E for ; Mon, 20 Aug 2012 14:50:00 +0000 (UTC) Received: by ggmi2 with SMTP id i2so5358432ggm.11 for ; Mon, 20 Aug 2012 07:50:05 -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=BknSGtQ+81uGSA23KpN1nbsJd/A5FxbXQfpL6/yShVJBeV3Zb2JPY7KqkM1JXQpgb4 2DsjZR3vgrFGCTmDr39nU8ODrAsqgLOvoJeaSgg651xVp/bdQAv9zXzJQwM4YEuLKTi9 SY6J0oFDPtltdvuFJbFZAbMpixMJUxo0m19Jmd/BaptBUK7zziNrRMX8okIrOwe6ctUF XIbdV2a4wQBPAzcXSPYO5+YpmTL86RQ07sJ5bvHh8nSDK72DngHrEeHckfvYyE1xnu2e eGJWOk6nMHNRk9kD7y9wbvR4vJgPIU/iDPMI2IHbo8EyTWwLWFvzoi9xxN1UxgihXESb wOsQ== Received: by 10.50.187.138 with SMTP id fs10mr9953565igc.43.1345474205181; Mon, 20 Aug 2012 07:50:05 -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 ex8csp87694igc; Mon, 20 Aug 2012 07:50:04 -0700 (PDT) Received: by 10.68.125.133 with SMTP id mq5mr35468920pbb.42.1345474204574; Mon, 20 Aug 2012 07:50: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 ip5si26175824pbc.348.2012.08.20.07.50.04 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 20 Aug 2012 07:50: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 pbcmd12 with SMTP id md12so7851964pbc.37 for ; Mon, 20 Aug 2012 07:50:04 -0700 (PDT) Received: by 10.66.74.100 with SMTP id s4mr30265285pav.27.1345474204103; Mon, 20 Aug 2012 07:50:04 -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 hr9sm11235374pbc.36.2012.08.20.07.50.03 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 20 Aug 2012 07:50:03 -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 02/12] kdb: Implement disable_nmi command Date: Mon, 20 Aug 2012 07:47:20 -0700 Message-Id: <1345474050-8339-2-git-send-email-anton.vorontsov@linaro.org> X-Mailer: git-send-email 1.7.11.5 In-Reply-To: <20120820144449.GA32560@lizard> References: <20120820144449.GA32560@lizard> X-Gm-Message-State: ALoCoQnhCV9EHFJTdsq5tnuYKz/ki7I8vuUdTK1vcsMWZOg6KKqQOudOVDTmmqrT3eNmKw2coBDB 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> ",