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

From: Li Zhong
Date: Mon Feb 20 2012 - 01:05:26 EST


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@xxxxxxxxxxxxxxxxxx>
---
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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/