2009-09-16 02:50:17 -07:00
|
|
|
/* Inject a hwpoison memory failure on a arbitary pfn */
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/debugfs.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
|
2009-12-16 04:19:58 -07:00
|
|
|
static struct dentry *hwpoison_dir;
|
2009-09-16 02:50:17 -07:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-12-16 04:19:58 -07:00
|
|
|
static int hwpoison_unpoison(void *data, u64 val)
|
|
|
|
{
|
|
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
|
|
return -EPERM;
|
|
|
|
|
|
|
|
return unpoison_memory(val);
|
|
|
|
}
|
|
|
|
|
2009-09-16 02:50:17 -07:00
|
|
|
DEFINE_SIMPLE_ATTRIBUTE(hwpoison_fops, NULL, hwpoison_inject, "%lli\n");
|
2009-12-16 04:19:58 -07:00
|
|
|
DEFINE_SIMPLE_ATTRIBUTE(unpoison_fops, NULL, hwpoison_unpoison, "%lli\n");
|
2009-09-16 02:50:17 -07:00
|
|
|
|
|
|
|
static void pfn_inject_exit(void)
|
|
|
|
{
|
|
|
|
if (hwpoison_dir)
|
|
|
|
debugfs_remove_recursive(hwpoison_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pfn_inject_init(void)
|
|
|
|
{
|
2009-12-16 04:19:58 -07:00
|
|
|
struct dentry *dentry;
|
|
|
|
|
2009-09-16 02:50:17 -07:00
|
|
|
hwpoison_dir = debugfs_create_dir("hwpoison", NULL);
|
|
|
|
if (hwpoison_dir == NULL)
|
|
|
|
return -ENOMEM;
|
2009-12-16 04:19:58 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Note that the below poison/unpoison interfaces do not involve
|
|
|
|
* hardware status change, hence do not require hardware support.
|
|
|
|
* They are mainly for testing hwpoison in software level.
|
|
|
|
*/
|
|
|
|
dentry = debugfs_create_file("corrupt-pfn", 0600, hwpoison_dir,
|
2009-09-16 02:50:17 -07:00
|
|
|
NULL, &hwpoison_fops);
|
2009-12-16 04:19:58 -07:00
|
|
|
if (!dentry)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
dentry = debugfs_create_file("unpoison-pfn", 0600, hwpoison_dir,
|
|
|
|
NULL, &unpoison_fops);
|
|
|
|
if (!dentry)
|
|
|
|
goto fail;
|
|
|
|
|
2009-09-16 02:50:17 -07:00
|
|
|
return 0;
|
2009-12-16 04:19:58 -07:00
|
|
|
fail:
|
|
|
|
pfn_inject_exit();
|
|
|
|
return -ENOMEM;
|
2009-09-16 02:50:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(pfn_inject_init);
|
|
|
|
module_exit(pfn_inject_exit);
|
|
|
|
MODULE_LICENSE("GPL");
|