linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mike Travis <travis@sgi.com>
To: Ingo Molnar <mingo@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	"H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
	Dimitri Sivanich <sivanich@hpe.com>
Subject: [PATCH 6/8] x86/platform/UV: Verify NMI action is valid, default is standard
Date: Fri, 13 Jan 2017 09:21:16 -0600	[thread overview]
Message-ID: <20170113152112.051569679@asylum.americas.sgi.com> (raw)
In-Reply-To: 20170113152110.831599361@asylum.americas.sgi.com

[-- Attachment #1: uv4_add-check-action --]
[-- Type: text/plain, Size: 2989 bytes --]

Verify that the NMI action being set is valid.  The default NMI action
changes from the non-standard 'kdb' to the more standard 'dump'.

Signed-off-by: Mike Travis <travis@sgi.com>
Acked-by: Dimitri Sivanich <sivanich@hpe.com>
Reviewed-by: Russ Anderson <rja@hpe.com>
Reviewed-by: Alex Thorlton <athorlton@sgi.com>
---
Note: this patch fails checkpatch with the following error:
WARNING: do not add new typedefs
#44: FILE: arch/x86/platform/uv/uv_nmi.c:186:
+typedef char action_t[ACTION_LEN];

But I do not know another way to create the correct parameter for this check:
+#define param_check_action(name, p) __param_check(name, p, action_t)
---
 arch/x86/platform/uv/uv_nmi.c |   69 +++++++++++++++++++++++++++++++++++-------
 1 file changed, 58 insertions(+), 11 deletions(-)

--- linux.orig/arch/x86/platform/uv/uv_nmi.c
+++ linux/arch/x86/platform/uv/uv_nmi.c
@@ -170,17 +170,64 @@ module_param_named(debug, uv_nmi_debug,
 			pr_info(fmt, ##__VA_ARGS__);	\
 	} while (0)
 
-/*
- * Valid NMI Actions:
- *  "dump"	- dump process stack for each cpu
- *  "ips"	- dump IP info for each cpu
- *  "kdump"	- do crash dump
- *  "kdb"	- enter KDB (default)
- *  "kgdb"	- enter KGDB
- *  "health"	- check if CPUs respond to NMI
- */
-static char uv_nmi_action[8] = "kdb";
-module_param_string(action, uv_nmi_action, sizeof(uv_nmi_action), 0644);
+/* Valid NMI Actions */
+#define	ACTION_LEN	16
+static struct nmi_action {
+	char	*action;
+	char	*desc;
+} valid_acts[] = {
+	{	"kdump",	"do kernel crash dump"			},
+	{	"dump",		"dump process stack for each cpu"	},
+	{	"ips",		"dump Inst Ptr info for each cpu"	},
+	{	"kdb",		"enter KDB (needs kgdboc= assignment)"	},
+	{	"kgdb",		"enter KGDB (needs gdb target remote)"	},
+	{	"health",	"check if CPUs respond to NMI"		},
+};
+typedef char action_t[ACTION_LEN];
+static action_t uv_nmi_action = { "dump" };
+
+static int param_get_action(char *buffer, const struct kernel_param *kp)
+{
+	return sprintf(buffer, "%s\n", uv_nmi_action);
+}
+
+static int param_set_action(const char *val, const struct kernel_param *kp)
+{
+	int i;
+	int n = ARRAY_SIZE(valid_acts);
+	char arg[ACTION_LEN], *p;
+
+	/* (remove possible '\n') */
+	strncpy(arg, val, ACTION_LEN - 1);
+	arg[ACTION_LEN - 1] = '\0';
+	p = strchr(arg, '\n');
+	if (p)
+		*p = '\0';
+
+	for (i = 0; i < n; i++)
+		if (!strcmp(arg, valid_acts[i].action))
+			break;
+
+	if (i < n) {
+		strcpy(uv_nmi_action, arg);
+		pr_info("UV: New NMI action:%s\n", uv_nmi_action);
+		return 0;
+	}
+
+	pr_err("UV: Invalid NMI action:%s, valid actions are:\n", arg);
+	for (i = 0; i < n; i++)
+		pr_err("UV: %-8s - %s\n",
+			valid_acts[i].action, valid_acts[i].desc);
+	return -EINVAL;
+}
+
+static const struct kernel_param_ops param_ops_action = {
+	.get = param_get_action,
+	.set = param_set_action,
+};
+#define param_check_action(name, p) __param_check(name, p, action_t)
+
+module_param_named(action, uv_nmi_action, action, 0644);
 
 static inline bool uv_nmi_action_is(const char *action)
 {

-- 

  parent reply	other threads:[~2017-01-13 15:21 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-13 15:21 [PATCH 0/8] x86/platform/UV: UV Update PatchSet 2 Mike Travis
2017-01-13 15:21 ` [PATCH 1/8] x86/platform/UV: Fix panic with missing UVsystab support Mike Travis
2017-01-14  9:57   ` [tip:x86/platform] " tip-bot for Mike Travis
2017-01-13 15:21 ` [PATCH 2/8] x86/platform/UV: Fix 2 socket config problem Mike Travis
2017-01-14  9:58   ` [tip:x86/platform] " tip-bot for Mike Travis
2017-01-13 15:21 ` [PATCH 3/8] x86/platform/UV: Add Support for UV4 Hubless systems Mike Travis
2017-01-13 15:21 ` [PATCH 4/8] x86/platform/UV: Add Support for UV4 Hubless NMIs Mike Travis
2017-01-14  7:52   ` Ingo Molnar
2017-01-14  8:26     ` [PATCH] x86/platform/UV: Clean up the UV APIC code Ingo Molnar
2017-01-14 13:11       ` Joe Perches
2017-02-01 10:09       ` [tip:x86/platform] " tip-bot for Ingo Molnar
2017-01-13 15:21 ` [PATCH 5/8] x86/platform/UV: Add basic CPU NMI health check Mike Travis
2017-01-13 15:21 ` Mike Travis [this message]
2017-01-13 15:21 ` [PATCH 7/8] x86/platform/UV: Initialize PCH GPP_D_0 NMI Pin to be NMI source Mike Travis
2017-01-13 15:21 ` [PATCH 8/8] x86/platform/UV: Insure uv_system_init is called when necessary Mike Travis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170113152112.051569679@asylum.americas.sgi.com \
    --to=travis@sgi.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=sivanich@hpe.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).