hwpoison-inject.c 988 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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>
  5. #include <linux/mm.h>
  6. static struct dentry *hwpoison_dir, *corrupt_pfn;
  7. static int hwpoison_inject(void *data, u64 val)
  8. {
  9. if (!capable(CAP_SYS_ADMIN))
  10. return -EPERM;
  11. printk(KERN_INFO "Injecting memory failure at pfn %Lx\n", val);
  12. return __memory_failure(val, 18, 0);
  13. }
  14. DEFINE_SIMPLE_ATTRIBUTE(hwpoison_fops, NULL, hwpoison_inject, "%lli\n");
  15. static void pfn_inject_exit(void)
  16. {
  17. if (hwpoison_dir)
  18. debugfs_remove_recursive(hwpoison_dir);
  19. }
  20. static int pfn_inject_init(void)
  21. {
  22. hwpoison_dir = debugfs_create_dir("hwpoison", NULL);
  23. if (hwpoison_dir == NULL)
  24. return -ENOMEM;
  25. corrupt_pfn = debugfs_create_file("corrupt-pfn", 0600, hwpoison_dir,
  26. NULL, &hwpoison_fops);
  27. if (corrupt_pfn == NULL) {
  28. pfn_inject_exit();
  29. return -ENOMEM;
  30. }
  31. return 0;
  32. }
  33. module_init(pfn_inject_init);
  34. module_exit(pfn_inject_exit);
  35. MODULE_LICENSE("GPL");