From patchwork Mon Sep 24 21:27:51 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 11685 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 C03F223E41 for ; Mon, 24 Sep 2012 21:31:35 +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 75102A18111 for ; Mon, 24 Sep 2012 21:31:35 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so11249367iej.11 for ; Mon, 24 Sep 2012 14:31:35 -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=N5tYpALku55svUewv7NTNUL7ASdkqZTEE8xPj1bP8c0=; b=Nk1kYANewkUhIusqQi97Ner5TqV9iInQQOkTq8krQBgbr5PlE4izU2kdtqlQJysJOT vJfuQORnWoggQOQzqpdxtSVlufdzIxivnXWbJrAEfG4Wn3lNBMKxKvfwV334E6ZpMyIw s4rs71xSaLd4FmTj9OApcJ7iYh8/kIO2s3JKg0O7ArEF0jGZyn64ASEVRAZcFaZn0vYp TZLSkvCE7pvcj9Ef1eMFgyZU5UCZY/bFx+itB5nN/4ijae+ROWCci3SjT2pYwoDnhHkB pv4C0JgpqsiJxL7IbG19htwg+rVefOHassWac/taZN9ZSNen8ee90rftZ8KSf3nmkaV0 88Xg== Received: by 10.42.84.69 with SMTP id k5mr10708153icl.5.1348522295205; Mon, 24 Sep 2012 14:31:35 -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 ex8csp263597igc; Mon, 24 Sep 2012 14:31:34 -0700 (PDT) Received: by 10.66.74.74 with SMTP id r10mr35553344pav.57.1348522294368; Mon, 24 Sep 2012 14:31:34 -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 j9si6686665paw.67.2012.09.24.14.31.34 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 24 Sep 2012 14:31:34 -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 md12so13998041pbc.37 for ; Mon, 24 Sep 2012 14:31:34 -0700 (PDT) Received: by 10.66.74.196 with SMTP id w4mr35589735pav.32.1348522294117; Mon, 24 Sep 2012 14:31:34 -0700 (PDT) Received: from localhost (ip-64-134-232-154.public.wayport.net. [64.134.232.154]) by mx.google.com with ESMTPS id kj10sm10165345pbc.72.2012.09.24.14.31.19 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 24 Sep 2012 14:31:33 -0700 (PDT) From: Anton Vorontsov To: Greg Kroah-Hartman , Russell King Cc: Alan Cox , Jason Wessel , =?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/11] kdb: Implement disable_nmi command Date: Mon, 24 Sep 2012 14:27:51 -0700 Message-Id: <1348522080-32629-2-git-send-email-anton.vorontsov@linaro.org> X-Mailer: git-send-email 1.7.12 In-Reply-To: <20120924212648.GA27605@lizard> References: <20120924212648.GA27605@lizard> X-Gm-Message-State: ALoCoQnTkUAI6IvCgs0D7Ms+MRLnxWb/sPEBRXtB+rwaBd3RkXugQuVGWI7EXKZoVwKKBwJYpnmr 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 Acked-by: Jason Wessel --- 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> ",