blob: 092ea436c7e62223bd3042a6a68607c992b5f7be [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001// SPDX-License-Identifier: GPL-2.0-only
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002#include <linux/debugfs.h>
3#include <linux/efi.h>
4#include <linux/module.h>
5#include <linux/seq_file.h>
Olivier Deprez157378f2022-04-04 15:47:50 +02006#include <linux/pgtable.h>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00007
8static int ptdump_show(struct seq_file *m, void *v)
9{
Olivier Deprez157378f2022-04-04 15:47:50 +020010 ptdump_walk_pgd_level_debugfs(m, &init_mm, false);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000011 return 0;
12}
13
David Brazdil0f672f62019-12-10 10:32:29 +000014DEFINE_SHOW_ATTRIBUTE(ptdump);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000015
David Brazdil0f672f62019-12-10 10:32:29 +000016static int ptdump_curknl_show(struct seq_file *m, void *v)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000017{
Olivier Deprez157378f2022-04-04 15:47:50 +020018 if (current->mm->pgd)
19 ptdump_walk_pgd_level_debugfs(m, current->mm, false);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000020 return 0;
21}
22
David Brazdil0f672f62019-12-10 10:32:29 +000023DEFINE_SHOW_ATTRIBUTE(ptdump_curknl);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000024
25#ifdef CONFIG_PAGE_TABLE_ISOLATION
David Brazdil0f672f62019-12-10 10:32:29 +000026static int ptdump_curusr_show(struct seq_file *m, void *v)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000027{
Olivier Deprez157378f2022-04-04 15:47:50 +020028 if (current->mm->pgd)
29 ptdump_walk_pgd_level_debugfs(m, current->mm, true);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000030 return 0;
31}
32
David Brazdil0f672f62019-12-10 10:32:29 +000033DEFINE_SHOW_ATTRIBUTE(ptdump_curusr);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000034#endif
35
36#if defined(CONFIG_EFI) && defined(CONFIG_X86_64)
David Brazdil0f672f62019-12-10 10:32:29 +000037static int ptdump_efi_show(struct seq_file *m, void *v)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000038{
39 if (efi_mm.pgd)
Olivier Deprez157378f2022-04-04 15:47:50 +020040 ptdump_walk_pgd_level_debugfs(m, &efi_mm, false);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000041 return 0;
42}
43
David Brazdil0f672f62019-12-10 10:32:29 +000044DEFINE_SHOW_ATTRIBUTE(ptdump_efi);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000045#endif
46
David Brazdil0f672f62019-12-10 10:32:29 +000047static struct dentry *dir;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000048
49static int __init pt_dump_debug_init(void)
50{
51 dir = debugfs_create_dir("page_tables", NULL);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000052
David Brazdil0f672f62019-12-10 10:32:29 +000053 debugfs_create_file("kernel", 0400, dir, NULL, &ptdump_fops);
54 debugfs_create_file("current_kernel", 0400, dir, NULL,
55 &ptdump_curknl_fops);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000056
57#ifdef CONFIG_PAGE_TABLE_ISOLATION
David Brazdil0f672f62019-12-10 10:32:29 +000058 debugfs_create_file("current_user", 0400, dir, NULL,
59 &ptdump_curusr_fops);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000060#endif
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000061#if defined(CONFIG_EFI) && defined(CONFIG_X86_64)
David Brazdil0f672f62019-12-10 10:32:29 +000062 debugfs_create_file("efi", 0400, dir, NULL, &ptdump_efi_fops);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000063#endif
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000064 return 0;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000065}
66
67static void __exit pt_dump_debug_exit(void)
68{
69 debugfs_remove_recursive(dir);
70}
71
72module_init(pt_dump_debug_init);
73module_exit(pt_dump_debug_exit);
74MODULE_LICENSE("GPL");
75MODULE_AUTHOR("Arjan van de Ven <arjan@linux.intel.com>");
76MODULE_DESCRIPTION("Kernel debugging helper that dumps pagetables");