Skip to contentSkip to conversation

watchdog, hpwdt: Remove priority option for NMI callback

PATCH In review Don Zickus 3 participants 8 messages Mar 9, 2012 – Mar 12, 2012

Subsystems (3)
lore
Share & tools
lore
author
#1 lore raw

PATCH 2/2 x86,nmi: Fix page faults by nmiaction if kmemcheck is enabled

In reply to Don Zickus

From: Li Zhong <[email protected]>

This patch tries to fix the problem of page fault exception caused by accessing nmiaction structure in nmi if kmemcheck is enabled.

If kmemcheck is enabled, the memory allocated through slab are in pages that are marked non-present, so that some checks could be done in the page fault handling code ( e.g. whether the memory is read before written to ).
As nmiaction is allocated in this way, so it resides in a non-present page. Then there is a page fault while the nmi code accessing the nmiaction structure, which would then cause a warning by WARN_ON_ONCE(in_nmi()) in kmemcheck_fault(), called by do_page_fault().

v2: as Peter suggested, changed the nmiaction to use static storage.

v3: as Peter suggested, use macro to shorten the codes. Also keep the original usage of register_nmi_handler, so users of this call doesn't need change.

[simplified wrappers -dcz]

---
 arch/x86/include/asm/nmi.h |   20 ++++++++++++-
 arch/x86/kernel/nmi.c      |   65 ++++---------------------------------------
 2 files changed, 24 insertions(+), 61 deletions(-)
arch/x86/include/asm/nmi.h +18 -2
index fd3f9f1..2a17e57 100644
@@ -35,8 +35,24 @@ enum {
 
 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
 
-int register_nmi_handler(unsigned int, nmi_handler_t, unsigned long,
-			 const char *);
+struct nmiaction {
+	struct list_head list;
+	nmi_handler_t handler;
+	unsigned int flags;
+	const char *name;
+};
+
+#define register_nmi_handler(t, fn, fg, n)		\
+({							\
+	static struct nmiaction fn##_na = {		\
+		.handler = (fn),			\
+		.name = (n),				\
+		.flags = (fg),				\
+	};						\
+	__register_nmi_handler((t), &fn##_na);	\
+})
+
+int __register_nmi_handler(unsigned int, struct nmiaction *);
 
 void unregister_nmi_handler(unsigned int, const char *);
 
arch/x86/kernel/nmi.c +6 -59

95 lines not on this page · raw message

Signature · 1 line
1.7.7.6

Don Zickus

author
#0 lore raw

PATCH 1/2 watchdog, hpwdt: Remove priority option for NMI callback

The NMI_UNKNOWN bucket only allows for one function to register to it. The reason for that is because only functions which can not determine if the NMI belongs to them or not should register and would like to assume/swallow any NMI they see.

As a result it doesn't make sense to let more than one function like this register. In fact, letting a second function fail allows us to know that more than one function is going to swallow NMIs on the current system. This is better than silently being ignored.

Therefore hpwdt's priority mechanism doesn't make sense any more. They will be always first on the NMI_UNKNOWN queue, if they register.

Removing this parameter cleans up the code and simplifies things for the next patch which changes how nmis are registered.

Cc Thomas Mingarelli <[email protected]>
Cc Wim Van Sebroeck <[email protected]>
---
 drivers/watchdog/hpwdt.c |   19 ++++---------------
 1 files changed, 4 insertions(+), 15 deletions(-)
drivers/watchdog/hpwdt.c +4 -15
index 3c166d3..deee02c8 100644
@@ -145,7 +145,6 @@ struct cmn_registers {
 
 static unsigned int hpwdt_nmi_decoding;
 static unsigned int allow_kdump;
-static unsigned int priority;		/* hpwdt at end of die_notify list */
 static unsigned int is_icru;
 static DEFINE_SPINLOCK(rom_lock);
 static void *cru_rom_addr;
@@ -730,13 +729,9 @@ static int __devinit hpwdt_init_nmi_decoding(struct pci_dev *dev)
 	}
 
 	/*
-	 * If the priority is set to 1, then we will be put first on the
-	 * die notify list to handle a critical NMI. The default is to
-	 * be last so other users of the NMI signal can function.
+	 * Only one function can register for NMI_UNKNOWN
 	 */
-	retval = register_nmi_handler(NMI_UNKNOWN, hpwdt_pretimeout,
-					(priority) ? NMI_FLAG_FIRST : 0,
-					"hpwdt");
+	retval = register_nmi_handler(NMI_UNKNOWN, hpwdt_pretimeout, 0, "hpwdt");
 	if (retval != 0) {
 		dev_warn(&dev->dev,
 			"Unable to register a die notifier (err=%d).\n",
@@ -747,10 +742,8 @@ static int __devinit hpwdt_init_nmi_decoding(struct pci_dev *dev)
 
 	dev_info(&dev->dev,
 			"HP Watchdog Timer Driver: NMI decoding initialized"
-			", allow kernel dump: %s (default = 0/OFF)"
-			", priority: %s (default = 0/LAST).\n",
-			(allow_kdump == 0) ? "OFF" : "ON",
-			(priority == 0) ? "LAST" : "FIRST");
+			", allow kernel dump: %s (default = 0/OFF)\n",
+			(allow_kdump == 0) ? "OFF" : "ON");
 	return 0;
 }
 
@@ -888,10 +881,6 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
 #ifdef CONFIG_HPWDT_NMI_DECODING
 module_param(allow_kdump, int, 0);
 MODULE_PARM_DESC(allow_kdump, "Start a kernel dump after NMI occurs");
-
-module_param(priority, int, 0);
-MODULE_PARM_DESC(priority, "The hpwdt driver handles NMIs first or last"
-		" (default = 0/Last)\n");
 #endif /* !CONFIG_HPWDT_NMI_DECODING */
 
 module_init(hpwdt_init);
Signature · 1 line
1.7.7.6
#2 lore raw

Has this been tested with echo c > /proc/sysrg-trigger and the virtual NMI button via iLO?

-----Original Message-----
From: Don Zickus [mailto:[email protected]]
Sent: Friday, March 09, 2012 10:37 AM
To: [email protected]
Cc: Peter Zijlstra; LKML; Don Zickus; Mingarelli, Thomas; Wim Van Sebroeck
Subject: [PATCH 1/2] watchdog, hpwdt: Remove priority option for NMI callback

The NMI_UNKNOWN bucket only allows for one function to register to it. The reason for that is because only functions which can not determine if the NMI belongs to them or not should register and would like to assume/swallow any NMI they see.

As a result it doesn't make sense to let more than one function like this register. In fact, letting a second function fail allows us to know that more than one function is going to swallow NMIs on the current system. This is better than silently being ignored.

Therefore hpwdt's priority mechanism doesn't make sense any more. They will be always first on the NMI_UNKNOWN queue, if they register.

Removing this parameter cleans up the code and simplifies things for the next patch which changes how nmis are registered.

Cc Thomas Mingarelli <[email protected]>
Cc Wim Van Sebroeck <[email protected]>
---
 drivers/watchdog/hpwdt.c |   19 ++++---------------
 1 files changed, 4 insertions(+), 15 deletions(-)
drivers/watchdog/hpwdt.c +4 -15
index 3c166d3..deee02c8 100644
@@ -145,7 +145,6 @@ struct cmn_registers {
 
 static unsigned int hpwdt_nmi_decoding;
 static unsigned int allow_kdump;
-static unsigned int priority;		/* hpwdt at end of die_notify list */
 static unsigned int is_icru;
 static DEFINE_SPINLOCK(rom_lock);
 static void *cru_rom_addr;
@@ -730,13 +729,9 @@ static int __devinit hpwdt_init_nmi_decoding(struct pci_dev *dev)
 	}
 
 	/*
-	 * If the priority is set to 1, then we will be put first on the
-	 * die notify list to handle a critical NMI. The default is to
-	 * be last so other users of the NMI signal can function.
+	 * Only one function can register for NMI_UNKNOWN
 	 */
-	retval = register_nmi_handler(NMI_UNKNOWN, hpwdt_pretimeout,
-					(priority) ? NMI_FLAG_FIRST : 0,
-					"hpwdt");
+	retval = register_nmi_handler(NMI_UNKNOWN, hpwdt_pretimeout, 0, "hpwdt");
 	if (retval != 0) {
 		dev_warn(&dev->dev,
 			"Unable to register a die notifier (err=%d).\n",
@@ -747,10 +742,8 @@ static int __devinit hpwdt_init_nmi_decoding(struct pci_dev *dev)
 
 	dev_info(&dev->dev,
 			"HP Watchdog Timer Driver: NMI decoding initialized"
-			", allow kernel dump: %s (default = 0/OFF)"
-			", priority: %s (default = 0/LAST).\n",
-			(allow_kdump == 0) ? "OFF" : "ON",
-			(priority == 0) ? "LAST" : "FIRST");
+			", allow kernel dump: %s (default = 0/OFF)\n",
+			(allow_kdump == 0) ? "OFF" : "ON");
 	return 0;
 }
 
@@ -888,10 +881,6 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
 #ifdef CONFIG_HPWDT_NMI_DECODING
 module_param(allow_kdump, int, 0);
 MODULE_PARM_DESC(allow_kdump, "Start a kernel dump after NMI occurs");
-
-module_param(priority, int, 0);
-MODULE_PARM_DESC(priority, "The hpwdt driver handles NMIs first or last"
-		" (default = 0/Last)\n");
 #endif /* !CONFIG_HPWDT_NMI_DECODING */
 
 module_init(hpwdt_init);
Signature · 1 line
1.7.7.6
author
#3 lore raw
Quoted 1 line · Thomas

Has this been tested with echo c > /proc/sysrg-trigger and the virtual NMI button via iLO?

No, because I don't know how to do that. Though I can probably ping Tony over here to show me how. But for the most part the functionality hasn't changed (the priority is always a '0' now). Looking in arch/x86/kernel/nmi.c shows that it will spit out a warning if two functions register against NMI_UNKNOWN.

Cheers,
Don

#4 lore raw

Ok I will run some tests asap. I may not get to it today.

Tom

-----Original Message-----
From: Don Zickus [mailto:[email protected]]
Sent: Friday, March 09, 2012 11:17 AM
To: Mingarelli, Thomas
Cc: [email protected]; Peter Zijlstra; LKML; Wim Van Sebroeck
Subject: Re: [PATCH 1/2] watchdog, hpwdt: Remove priority option for NMI callback

Quoted 1 line · Thomas

Has this been tested with echo c > /proc/sysrg-trigger and the virtual NMI button via iLO?

No, because I don't know how to do that. Though I can probably ping Tony over here to show me how. But for the most part the functionality hasn't changed (the priority is always a '0' now). Looking in arch/x86/kernel/nmi.c shows that it will spit out a warning if two functions register against NMI_UNKNOWN.

Cheers,
Don

#5 lore raw
In reply to Don Zickus

Can I register for more than one type? Like NMI_UNKNOWN | NMI_DIE (or something like that)?

-----Original Message-----
From: Don Zickus [mailto:[email protected]]
Sent: Friday, March 09, 2012 11:17 AM
To: Mingarelli, Thomas
Cc: [email protected]; Peter Zijlstra; LKML; Wim Van Sebroeck
Subject: Re: [PATCH 1/2] watchdog, hpwdt: Remove priority option for NMI callback

Quoted 1 line · Thomas

Has this been tested with echo c > /proc/sysrg-trigger and the virtual NMI button via iLO?

No, because I don't know how to do that. Though I can probably ping Tony over here to show me how. But for the most part the functionality hasn't changed (the priority is always a '0' now). Looking in arch/x86/kernel/nmi.c shows that it will spit out a warning if two functions register against NMI_UNKNOWN.

Cheers,
Don

author
#6 lore raw
Quoted 1 line · Thomas

Can I register for more than one type? Like NMI_UNKNOWN | NMI_DIE (or something like that)?

There are only two queues, NMI_LOCAL and NMI_UNKNOWN. The difference is NMI_LOCAL has handlers that can determine if they are the NMI source, which is needed because _every_ handler is executed on every NMI. NMI_UNKNOWN is reserved for handlers that just assume the NMI is theirs.

Cheers,
Don

#7 lore raw
In reply to Mingarelli, Thomas
Quoted 2 lines · Thomas

Can I register for more than one type? Like NMI_UNKNOWN | NMI_DIE (or something like that)?

There's only NMI_LOCAL and NMI_UNKNOWN, and you can only use NMI_LOCAL if you can tell you generated the NMI. See it as one massively shared interrupt line.

The NMI_UNKNOWN handler is basically the handler of last resort for those that cannot multiplex the line, hence the restriction of only having one.