Skip to contentSkip to conversation

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

PATCH Superseded Don Zickus 2 participants 2 messages Mar 8, 2012 x86

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Don Zickus

author
#0 lore raw

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

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.

---
 arch/x86/include/asm/nmi.h |   19 ++++++++++++++-
 arch/x86/kernel/nmi.c      |   52 ++++++--------------------------------------
 2 files changed, 24 insertions(+), 47 deletions(-)
arch/x86/include/asm/nmi.h +17 -2
index fd3f9f1..5a2b2c6 100644
@@ -35,8 +35,23 @@ 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),				\
+	};						\
+	__register_nmi_handler((t), (fg), &fn##_na);	\
+})
+
+int __register_nmi_handler(unsigned int, unsigned int, struct nmiaction *);
 
 void unregister_nmi_handler(unsigned int, const char *);
 
arch/x86/kernel/nmi.c +7 -45

72 lines not on this page · raw message

Signature · 1 line
1.7.7.6
#1 lore raw

arch/x86/kernel/nmi.c static struct nmiaction *__free_nmi(unsigned int type, const char *name) · line 165

Quoted 11 lines · Don Zickus
arch/x86/kernel/nmi.c +6 -0
+int __register_nmi_handler(unsigned int type, unsigned int nmiflags,
+                                               struct nmiaction *na)
 {
+       if (!na->handler)
                return -EINVAL;
 
+       na->flags = nmiflags;
 
+       return __setup_nmi(type, na);
 }
+EXPORT_SYMBOL_GPL(__register_nmi_handler);

Put the na->flags thing in the CPP bit, put the !handler check in __setup_nmi() and loose the pointless wrappery?

Quoted 6 lines

void unregister_nmi_handler(unsigned int type, const char *name) {
+ __free_nmi(type, name);
}

EXPORT_SYMBOL_GPL(unregister_nmi_handler);

That's another quite pointless wrapper there..