[PATCH 1/2 x86] fix page faults by nmi handler in nmi if kmemcheck is enabled

Li Zhong
2012-02-20T06:05:28Z

This patch tries to
change the nmi handler name from a pointer to an array.
use __get_free_pages instead of kzalloc if CONFIG_KMEMCHECK is
enabled.

Signed-off-by: Li Zhong <zhong@linux.vnet.ibm.com>
---
arch/x86/kernel/nmi.c | 23 +++++++++++++++--------
1 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
index 47acaf3..84aa03a 100644
--- a/arch/x86/kernel/nmi.c
+++ b/arch/x86/kernel/nmi.c
@@ -36,7 +36,7 @@ struct nmiaction {
struct list_head list;
nmi_handler_t handler;
unsigned int flags;
- char *name;
+ char name[NMI_MAX_NAMELEN];
};

struct nmi_desc {
@@ -169,16 +169,18 @@ int register_nmi_handler(unsigned int type,
nmi_handler_t handler,
if (!handler)
return -EINVAL;

+#ifdef CONFIG_KMEMCHECK
+ action = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
+ get_order(sizeof(*action)));
+#else
action = kzalloc(sizeof(struct nmiaction), GFP_KERNEL);
+#endif
if (!action)
goto fail_action;

action->handler = handler;
action->flags = nmiflags;
- action->name = kstrndup(devname, NMI_MAX_NAMELEN, GFP_KERNEL);
- if (!action->name)
- goto fail_action_name;
-
+ strncpy(action->name, devname, sizeof(action->name));
retval = __setup_nmi(type, action);

if (retval)
@@ -187,9 +189,11 @@ int register_nmi_handler(unsigned int type,
nmi_handler_t handler,
return retval;

fail_setup_nmi:
- kfree(action->name);
-fail_action_name:
+#ifdef CONFIG_KMEMCHECK
+ free_pages((unsigned long)action, get_order(sizeof(*action)));
+#else
kfree(action);
+#endif
fail_action:

return retval;
@@ -202,8 +206,11 @@ void unregister_nmi_handler(unsigned int type,
const char *name)

a = __free_nmi(type, name);
if (a) {
- kfree(a->name);
+#ifdef CONFIG_KMEMCHECK
+ free_pages((unsigned long)a, get_order(sizeof(*a)));
+#else
kfree(a);
+#endif
}
}

--
1.7.5.4