debug_pagetables.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. #include <linux/debugfs.h>
  3. #include <linux/efi.h>
  4. #include <linux/module.h>
  5. #include <linux/seq_file.h>
  6. #include <linux/pgtable.h>
  7. static int ptdump_show(struct seq_file *m, void *v)
  8. {
  9. ptdump_walk_pgd_level_debugfs(m, &init_mm, false);
  10. return 0;
  11. }
  12. DEFINE_SHOW_ATTRIBUTE(ptdump);
  13. static int ptdump_curknl_show(struct seq_file *m, void *v)
  14. {
  15. if (current->mm->pgd)
  16. ptdump_walk_pgd_level_debugfs(m, current->mm, false);
  17. return 0;
  18. }
  19. DEFINE_SHOW_ATTRIBUTE(ptdump_curknl);
  20. #ifdef CONFIG_PAGE_TABLE_ISOLATION
  21. static int ptdump_curusr_show(struct seq_file *m, void *v)
  22. {
  23. if (current->mm->pgd)
  24. ptdump_walk_pgd_level_debugfs(m, current->mm, true);
  25. return 0;
  26. }
  27. DEFINE_SHOW_ATTRIBUTE(ptdump_curusr);
  28. #endif
  29. #if defined(CONFIG_EFI) && defined(CONFIG_X86_64)
  30. static int ptdump_efi_show(struct seq_file *m, void *v)
  31. {
  32. if (efi_mm.pgd)
  33. ptdump_walk_pgd_level_debugfs(m, &efi_mm, false);
  34. return 0;
  35. }
  36. DEFINE_SHOW_ATTRIBUTE(ptdump_efi);
  37. #endif
  38. static struct dentry *dir;
  39. static int __init pt_dump_debug_init(void)
  40. {
  41. dir = debugfs_create_dir("page_tables", NULL);
  42. debugfs_create_file("kernel", 0400, dir, NULL, &ptdump_fops);
  43. debugfs_create_file("current_kernel", 0400, dir, NULL,
  44. &ptdump_curknl_fops);
  45. #ifdef CONFIG_PAGE_TABLE_ISOLATION
  46. debugfs_create_file("current_user", 0400, dir, NULL,
  47. &ptdump_curusr_fops);
  48. #endif
  49. #if defined(CONFIG_EFI) && defined(CONFIG_X86_64)
  50. debugfs_create_file("efi", 0400, dir, NULL, &ptdump_efi_fops);
  51. #endif
  52. return 0;
  53. }
  54. static void __exit pt_dump_debug_exit(void)
  55. {
  56. debugfs_remove_recursive(dir);
  57. }
  58. module_init(pt_dump_debug_init);
  59. module_exit(pt_dump_debug_exit);
  60. MODULE_LICENSE("GPL");
  61. MODULE_AUTHOR("Arjan van de Ven <[email protected]>");
  62. MODULE_DESCRIPTION("Kernel debugging helper that dumps pagetables");