From 00f71b23c29885639511a94a05ee74a029ccd022 Mon Sep 17 00:00:00 2001 From: Andi Kleen Date: Wed, 16 Sep 2009 11:50:17 +0200 Subject: [PATCH] --- yaml --- r: 165741 b: refs/heads/master c: cae681fc12a824631337906d6ba1dbd498e751a5 h: refs/heads/master i: 165739: 440db130971faa053f3468232e31c1eeada3ab05 v: v3 --- [refs] | 2 +- trunk/mm/Kconfig | 4 ++++ trunk/mm/Makefile | 1 + trunk/mm/hwpoison-inject.c | 41 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 trunk/mm/hwpoison-inject.c diff --git a/[refs] b/[refs] index 00559d0e44af..715f287405b0 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 9893e49d64a4874ea67849ee2cfbf3f3d6817573 +refs/heads/master: cae681fc12a824631337906d6ba1dbd498e751a5 diff --git a/trunk/mm/Kconfig b/trunk/mm/Kconfig index ea2d8b61c631..4b4e57a9643e 100644 --- a/trunk/mm/Kconfig +++ b/trunk/mm/Kconfig @@ -243,6 +243,10 @@ config MEMORY_FAILURE even when some of its memory has uncorrected errors. This requires special hardware support and typically ECC memory. +config HWPOISON_INJECT + tristate "Poison pages injector" + depends on MEMORY_FAILURE && DEBUG_KERNEL + config NOMMU_INITIAL_TRIM_EXCESS int "Turn on mmap() excess space trimming before booting" depends on !MMU diff --git a/trunk/mm/Makefile b/trunk/mm/Makefile index dc2551e7d006..713c9f82d5ab 100644 --- a/trunk/mm/Makefile +++ b/trunk/mm/Makefile @@ -41,5 +41,6 @@ endif obj-$(CONFIG_QUICKLIST) += quicklist.o obj-$(CONFIG_CGROUP_MEM_RES_CTLR) += memcontrol.o page_cgroup.o obj-$(CONFIG_MEMORY_FAILURE) += memory-failure.o +obj-$(CONFIG_HWPOISON_INJECT) += hwpoison-inject.o obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o diff --git a/trunk/mm/hwpoison-inject.c b/trunk/mm/hwpoison-inject.c new file mode 100644 index 000000000000..e1d85137f086 --- /dev/null +++ b/trunk/mm/hwpoison-inject.c @@ -0,0 +1,41 @@ +/* Inject a hwpoison memory failure on a arbitary pfn */ +#include +#include +#include +#include + +static struct dentry *hwpoison_dir, *corrupt_pfn; + +static int hwpoison_inject(void *data, u64 val) +{ + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + printk(KERN_INFO "Injecting memory failure at pfn %Lx\n", val); + return __memory_failure(val, 18, 0); +} + +DEFINE_SIMPLE_ATTRIBUTE(hwpoison_fops, NULL, hwpoison_inject, "%lli\n"); + +static void pfn_inject_exit(void) +{ + if (hwpoison_dir) + debugfs_remove_recursive(hwpoison_dir); +} + +static int pfn_inject_init(void) +{ + hwpoison_dir = debugfs_create_dir("hwpoison", NULL); + if (hwpoison_dir == NULL) + return -ENOMEM; + corrupt_pfn = debugfs_create_file("corrupt-pfn", 0600, hwpoison_dir, + NULL, &hwpoison_fops); + if (corrupt_pfn == NULL) { + pfn_inject_exit(); + return -ENOMEM; + } + return 0; +} + +module_init(pfn_inject_init); +module_exit(pfn_inject_exit); +MODULE_LICENSE("GPL");