1 /* Inject a hwpoison memory failure on a arbitary pfn */
2 #include <linux/module.h>
3 #include <linux/debugfs.h>
4 #include <linux/kernel.h>
8 static struct dentry *hwpoison_dir;
10 static int hwpoison_inject(void *data, u64 val)
12 if (!capable(CAP_SYS_ADMIN))
14 printk(KERN_INFO "Injecting memory failure at pfn %Lx\n", val);
15 return __memory_failure(val, 18, 0);
18 static int hwpoison_unpoison(void *data, u64 val)
20 if (!capable(CAP_SYS_ADMIN))
23 return unpoison_memory(val);
26 DEFINE_SIMPLE_ATTRIBUTE(hwpoison_fops, NULL, hwpoison_inject, "%lli\n");
27 DEFINE_SIMPLE_ATTRIBUTE(unpoison_fops, NULL, hwpoison_unpoison, "%lli\n");
29 static void pfn_inject_exit(void)
32 debugfs_remove_recursive(hwpoison_dir);
35 static int pfn_inject_init(void)
37 struct dentry *dentry;
39 hwpoison_dir = debugfs_create_dir("hwpoison", NULL);
40 if (hwpoison_dir == NULL)
44 * Note that the below poison/unpoison interfaces do not involve
45 * hardware status change, hence do not require hardware support.
46 * They are mainly for testing hwpoison in software level.
48 dentry = debugfs_create_file("corrupt-pfn", 0600, hwpoison_dir,
49 NULL, &hwpoison_fops);
53 dentry = debugfs_create_file("unpoison-pfn", 0600, hwpoison_dir,
54 NULL, &unpoison_fops);
58 dentry = debugfs_create_u32("corrupt-filter-dev-major", 0600,
59 hwpoison_dir, &hwpoison_filter_dev_major);
63 dentry = debugfs_create_u32("corrupt-filter-dev-minor", 0600,
64 hwpoison_dir, &hwpoison_filter_dev_minor);
74 module_init(pfn_inject_init);
75 module_exit(pfn_inject_exit);
76 MODULE_LICENSE("GPL");