xref: /linux/arch/riscv/mm/ptdump.c (revision 6cdc82db0c044d36137dd98f33e8aa0b8742987f)
159c4da86SZong Li // SPDX-License-Identifier: GPL-2.0-only
259c4da86SZong Li /*
359c4da86SZong Li  * Copyright (C) 2019 SiFive
459c4da86SZong Li  */
559c4da86SZong Li 
6de22d210SAtish Patra #include <linux/efi.h>
759c4da86SZong Li #include <linux/init.h>
859c4da86SZong Li #include <linux/debugfs.h>
959c4da86SZong Li #include <linux/seq_file.h>
1059c4da86SZong Li #include <linux/ptdump.h>
1159c4da86SZong Li 
12ca5999fdSMike Rapoport #include <linux/pgtable.h>
1359c4da86SZong Li #include <asm/kasan.h>
1459c4da86SZong Li 
1559c4da86SZong Li #define pt_dump_seq_printf(m, fmt, args...)	\
1659c4da86SZong Li ({						\
1759c4da86SZong Li 	if (m)					\
1859c4da86SZong Li 		seq_printf(m, fmt, ##args);	\
1959c4da86SZong Li })
2059c4da86SZong Li 
2159c4da86SZong Li #define pt_dump_seq_puts(m, fmt)	\
2259c4da86SZong Li ({					\
2359c4da86SZong Li 	if (m)				\
2459c4da86SZong Li 		seq_printf(m, fmt);	\
2559c4da86SZong Li })
2659c4da86SZong Li 
2759c4da86SZong Li /*
2859c4da86SZong Li  * The page dumper groups page table entries of the same type into a single
2959c4da86SZong Li  * description. It uses pg_state to track the range information while
3059c4da86SZong Li  * iterating over the pte entries. When the continuity is broken it then
3159c4da86SZong Li  * dumps out a description of the range.
3259c4da86SZong Li  */
3359c4da86SZong Li struct pg_state {
3459c4da86SZong Li 	struct ptdump_state ptdump;
3559c4da86SZong Li 	struct seq_file *seq;
3659c4da86SZong Li 	const struct addr_marker *marker;
3759c4da86SZong Li 	unsigned long start_address;
3859c4da86SZong Li 	unsigned long start_pa;
3959c4da86SZong Li 	unsigned long last_pa;
4059c4da86SZong Li 	int level;
4159c4da86SZong Li 	u64 current_prot;
4259c4da86SZong Li 	bool check_wx;
4359c4da86SZong Li 	unsigned long wx_pages;
4459c4da86SZong Li };
4559c4da86SZong Li 
4659c4da86SZong Li /* Address marker */
4759c4da86SZong Li struct addr_marker {
4859c4da86SZong Li 	unsigned long start_address;
4959c4da86SZong Li 	const char *name;
5059c4da86SZong Li };
5159c4da86SZong Li 
52de22d210SAtish Patra /* Private information for debugfs */
53de22d210SAtish Patra struct ptd_mm_info {
54de22d210SAtish Patra 	struct mm_struct		*mm;
55de22d210SAtish Patra 	const struct addr_marker	*markers;
56de22d210SAtish Patra 	unsigned long base_addr;
57de22d210SAtish Patra 	unsigned long end;
58de22d210SAtish Patra };
59de22d210SAtish Patra 
600df68ce4SAlexandre Ghiti enum address_markers_idx {
610df68ce4SAlexandre Ghiti 	FIXMAP_START_NR,
620df68ce4SAlexandre Ghiti 	FIXMAP_END_NR,
630df68ce4SAlexandre Ghiti 	PCI_IO_START_NR,
640df68ce4SAlexandre Ghiti 	PCI_IO_END_NR,
650df68ce4SAlexandre Ghiti #ifdef CONFIG_SPARSEMEM_VMEMMAP
660df68ce4SAlexandre Ghiti 	VMEMMAP_START_NR,
670df68ce4SAlexandre Ghiti 	VMEMMAP_END_NR,
680df68ce4SAlexandre Ghiti #endif
690df68ce4SAlexandre Ghiti 	VMALLOC_START_NR,
700df68ce4SAlexandre Ghiti 	VMALLOC_END_NR,
710df68ce4SAlexandre Ghiti 	PAGE_OFFSET_NR,
72ecd7ebafSAlexandre Ghiti #ifdef CONFIG_KASAN
73ecd7ebafSAlexandre Ghiti 	KASAN_SHADOW_START_NR,
74ecd7ebafSAlexandre Ghiti 	KASAN_SHADOW_END_NR,
75ecd7ebafSAlexandre Ghiti #endif
760df68ce4SAlexandre Ghiti #ifdef CONFIG_64BIT
770df68ce4SAlexandre Ghiti 	MODULES_MAPPING_NR,
780df68ce4SAlexandre Ghiti 	KERNEL_MAPPING_NR,
7928252e08SAlexandre Ghiti #endif
800df68ce4SAlexandre Ghiti 	END_OF_SPACE_NR
810df68ce4SAlexandre Ghiti };
820df68ce4SAlexandre Ghiti 
8359c4da86SZong Li static struct addr_marker address_markers[] = {
840df68ce4SAlexandre Ghiti 	{0, "Fixmap start"},
850df68ce4SAlexandre Ghiti 	{0, "Fixmap end"},
860df68ce4SAlexandre Ghiti 	{0, "PCI I/O start"},
870df68ce4SAlexandre Ghiti 	{0, "PCI I/O end"},
8859c4da86SZong Li #ifdef CONFIG_SPARSEMEM_VMEMMAP
890df68ce4SAlexandre Ghiti 	{0, "vmemmap start"},
900df68ce4SAlexandre Ghiti 	{0, "vmemmap end"},
9159c4da86SZong Li #endif
920df68ce4SAlexandre Ghiti 	{0, "vmalloc() area"},
930df68ce4SAlexandre Ghiti 	{0, "vmalloc() end"},
940df68ce4SAlexandre Ghiti 	{0, "Linear mapping"},
95ecd7ebafSAlexandre Ghiti #ifdef CONFIG_KASAN
96ecd7ebafSAlexandre Ghiti 	{0, "Kasan shadow start"},
97ecd7ebafSAlexandre Ghiti 	{0, "Kasan shadow end"},
98ecd7ebafSAlexandre Ghiti #endif
990df68ce4SAlexandre Ghiti #ifdef CONFIG_64BIT
1007761e36bSAlexandre Ghiti 	{0, "Modules/BPF mapping"},
1017761e36bSAlexandre Ghiti 	{0, "Kernel mapping"},
10228252e08SAlexandre Ghiti #endif
10359c4da86SZong Li 	{-1, NULL},
10459c4da86SZong Li };
10559c4da86SZong Li 
106de22d210SAtish Patra static struct ptd_mm_info kernel_ptd_info = {
107de22d210SAtish Patra 	.mm		= &init_mm,
108de22d210SAtish Patra 	.markers	= address_markers,
1090df68ce4SAlexandre Ghiti 	.base_addr	= 0,
110de22d210SAtish Patra 	.end		= ULONG_MAX,
111de22d210SAtish Patra };
112de22d210SAtish Patra 
113de22d210SAtish Patra #ifdef CONFIG_EFI
114de22d210SAtish Patra static struct addr_marker efi_addr_markers[] = {
115de22d210SAtish Patra 		{ 0,		"UEFI runtime start" },
116de22d210SAtish Patra 		{ SZ_1G,	"UEFI runtime end" },
117de22d210SAtish Patra 		{ -1,		NULL }
118de22d210SAtish Patra };
119de22d210SAtish Patra 
120de22d210SAtish Patra static struct ptd_mm_info efi_ptd_info = {
121de22d210SAtish Patra 	.mm		= &efi_mm,
122de22d210SAtish Patra 	.markers	= efi_addr_markers,
123de22d210SAtish Patra 	.base_addr	= 0,
124de22d210SAtish Patra 	.end		= SZ_2G,
125de22d210SAtish Patra };
126de22d210SAtish Patra #endif
127de22d210SAtish Patra 
12859c4da86SZong Li /* Page Table Entry */
12959c4da86SZong Li struct prot_bits {
13059c4da86SZong Li 	u64 mask;
13159c4da86SZong Li 	const char *set;
13259c4da86SZong Li 	const char *clear;
13359c4da86SZong Li };
13459c4da86SZong Li 
13559c4da86SZong Li static const struct prot_bits pte_bits[] = {
13659c4da86SZong Li 	{
1370713ff33SYu Chien Peter Lin #ifdef CONFIG_64BIT
138015c3c37SYu Chien Peter Lin 		.mask = _PAGE_NAPOT,
139015c3c37SYu Chien Peter Lin 		.set = "N",
140015c3c37SYu Chien Peter Lin 		.clear = ".",
141015c3c37SYu Chien Peter Lin 	}, {
1420713ff33SYu Chien Peter Lin 		.mask = _PAGE_MTMASK_SVPBMT,
1430713ff33SYu Chien Peter Lin 		.set = "MT(%s)",
1440713ff33SYu Chien Peter Lin 		.clear = "  ..  ",
1450713ff33SYu Chien Peter Lin 	}, {
1460713ff33SYu Chien Peter Lin #endif
14759c4da86SZong Li 		.mask = _PAGE_SOFT,
148d5d2c264SYu Chien Peter Lin 		.set = "RSW(%d)",
149d5d2c264SYu Chien Peter Lin 		.clear = "  ..  ",
15059c4da86SZong Li 	}, {
15159c4da86SZong Li 		.mask = _PAGE_DIRTY,
15259c4da86SZong Li 		.set = "D",
15359c4da86SZong Li 		.clear = ".",
15459c4da86SZong Li 	}, {
15559c4da86SZong Li 		.mask = _PAGE_ACCESSED,
15659c4da86SZong Li 		.set = "A",
15759c4da86SZong Li 		.clear = ".",
15859c4da86SZong Li 	}, {
15959c4da86SZong Li 		.mask = _PAGE_GLOBAL,
16059c4da86SZong Li 		.set = "G",
16159c4da86SZong Li 		.clear = ".",
16259c4da86SZong Li 	}, {
16359c4da86SZong Li 		.mask = _PAGE_USER,
16459c4da86SZong Li 		.set = "U",
16559c4da86SZong Li 		.clear = ".",
16659c4da86SZong Li 	}, {
16759c4da86SZong Li 		.mask = _PAGE_EXEC,
16859c4da86SZong Li 		.set = "X",
16959c4da86SZong Li 		.clear = ".",
17059c4da86SZong Li 	}, {
17159c4da86SZong Li 		.mask = _PAGE_WRITE,
17259c4da86SZong Li 		.set = "W",
17359c4da86SZong Li 		.clear = ".",
17459c4da86SZong Li 	}, {
17559c4da86SZong Li 		.mask = _PAGE_READ,
17659c4da86SZong Li 		.set = "R",
17759c4da86SZong Li 		.clear = ".",
17859c4da86SZong Li 	}, {
17959c4da86SZong Li 		.mask = _PAGE_PRESENT,
18059c4da86SZong Li 		.set = "V",
18159c4da86SZong Li 		.clear = ".",
18259c4da86SZong Li 	}
18359c4da86SZong Li };
18459c4da86SZong Li 
18559c4da86SZong Li /* Page Level */
18659c4da86SZong Li struct pg_level {
18759c4da86SZong Li 	const char *name;
18859c4da86SZong Li 	u64 mask;
18959c4da86SZong Li };
19059c4da86SZong Li 
19159c4da86SZong Li static struct pg_level pg_level[] = {
19259c4da86SZong Li 	{ /* pgd */
19359c4da86SZong Li 		.name = "PGD",
19459c4da86SZong Li 	}, { /* p4d */
19559c4da86SZong Li 		.name = (CONFIG_PGTABLE_LEVELS > 4) ? "P4D" : "PGD",
19659c4da86SZong Li 	}, { /* pud */
19759c4da86SZong Li 		.name = (CONFIG_PGTABLE_LEVELS > 3) ? "PUD" : "PGD",
19859c4da86SZong Li 	}, { /* pmd */
19959c4da86SZong Li 		.name = (CONFIG_PGTABLE_LEVELS > 2) ? "PMD" : "PGD",
20059c4da86SZong Li 	}, { /* pte */
20159c4da86SZong Li 		.name = "PTE",
20259c4da86SZong Li 	},
20359c4da86SZong Li };
20459c4da86SZong Li 
20559c4da86SZong Li static void dump_prot(struct pg_state *st)
20659c4da86SZong Li {
20759c4da86SZong Li 	unsigned int i;
20859c4da86SZong Li 
20959c4da86SZong Li 	for (i = 0; i < ARRAY_SIZE(pte_bits); i++) {
210d5d2c264SYu Chien Peter Lin 		char s[7];
211d5d2c264SYu Chien Peter Lin 		unsigned long val;
21259c4da86SZong Li 
213d5d2c264SYu Chien Peter Lin 		val = st->current_prot & pte_bits[i].mask;
214d5d2c264SYu Chien Peter Lin 		if (val) {
215d5d2c264SYu Chien Peter Lin 			if (pte_bits[i].mask == _PAGE_SOFT)
216d5d2c264SYu Chien Peter Lin 				sprintf(s, pte_bits[i].set, val >> 8);
2170713ff33SYu Chien Peter Lin #ifdef CONFIG_64BIT
2180713ff33SYu Chien Peter Lin 			else if (pte_bits[i].mask == _PAGE_MTMASK_SVPBMT) {
2190713ff33SYu Chien Peter Lin 				if (val == _PAGE_NOCACHE_SVPBMT)
2200713ff33SYu Chien Peter Lin 					sprintf(s, pte_bits[i].set, "NC");
2210713ff33SYu Chien Peter Lin 				else if (val == _PAGE_IO_SVPBMT)
2220713ff33SYu Chien Peter Lin 					sprintf(s, pte_bits[i].set, "IO");
22359c4da86SZong Li 				else
2240713ff33SYu Chien Peter Lin 					sprintf(s, pte_bits[i].set, "??");
2250713ff33SYu Chien Peter Lin 			}
2260713ff33SYu Chien Peter Lin #endif
22759c4da86SZong Li 			else
228d5d2c264SYu Chien Peter Lin 				sprintf(s, "%s", pte_bits[i].set);
229d5d2c264SYu Chien Peter Lin 		} else {
230d5d2c264SYu Chien Peter Lin 			sprintf(s, "%s", pte_bits[i].clear);
231d5d2c264SYu Chien Peter Lin 		}
23259c4da86SZong Li 
23359c4da86SZong Li 		pt_dump_seq_printf(st->seq, " %s", s);
23459c4da86SZong Li 	}
23559c4da86SZong Li }
23659c4da86SZong Li 
23759c4da86SZong Li #ifdef CONFIG_64BIT
23859c4da86SZong Li #define ADDR_FORMAT	"0x%016lx"
23959c4da86SZong Li #else
24059c4da86SZong Li #define ADDR_FORMAT	"0x%08lx"
24159c4da86SZong Li #endif
24259c4da86SZong Li static void dump_addr(struct pg_state *st, unsigned long addr)
24359c4da86SZong Li {
24459c4da86SZong Li 	static const char units[] = "KMGTPE";
24559c4da86SZong Li 	const char *unit = units;
24659c4da86SZong Li 	unsigned long delta;
24759c4da86SZong Li 
24859c4da86SZong Li 	pt_dump_seq_printf(st->seq, ADDR_FORMAT "-" ADDR_FORMAT "   ",
24959c4da86SZong Li 			   st->start_address, addr);
25059c4da86SZong Li 
25159c4da86SZong Li 	pt_dump_seq_printf(st->seq, " " ADDR_FORMAT " ", st->start_pa);
25259c4da86SZong Li 	delta = (addr - st->start_address) >> 10;
25359c4da86SZong Li 
25459c4da86SZong Li 	while (!(delta & 1023) && unit[1]) {
25559c4da86SZong Li 		delta >>= 10;
25659c4da86SZong Li 		unit++;
25759c4da86SZong Li 	}
25859c4da86SZong Li 
25959c4da86SZong Li 	pt_dump_seq_printf(st->seq, "%9lu%c %s", delta, *unit,
26059c4da86SZong Li 			   pg_level[st->level].name);
26159c4da86SZong Li }
26259c4da86SZong Li 
26359c4da86SZong Li static void note_prot_wx(struct pg_state *st, unsigned long addr)
26459c4da86SZong Li {
26559c4da86SZong Li 	if (!st->check_wx)
26659c4da86SZong Li 		return;
26759c4da86SZong Li 
26859c4da86SZong Li 	if ((st->current_prot & (_PAGE_WRITE | _PAGE_EXEC)) !=
26959c4da86SZong Li 	    (_PAGE_WRITE | _PAGE_EXEC))
27059c4da86SZong Li 		return;
27159c4da86SZong Li 
27259c4da86SZong Li 	WARN_ONCE(1, "riscv/mm: Found insecure W+X mapping at address %p/%pS\n",
27359c4da86SZong Li 		  (void *)st->start_address, (void *)st->start_address);
27459c4da86SZong Li 
27559c4da86SZong Li 	st->wx_pages += (addr - st->start_address) / PAGE_SIZE;
27659c4da86SZong Li }
27759c4da86SZong Li 
27859c4da86SZong Li static void note_page(struct ptdump_state *pt_st, unsigned long addr,
27999395ee3SSteven Price 		      int level, u64 val)
28059c4da86SZong Li {
28159c4da86SZong Li 	struct pg_state *st = container_of(pt_st, struct pg_state, ptdump);
28259c4da86SZong Li 	u64 pa = PFN_PHYS(pte_pfn(__pte(val)));
28359c4da86SZong Li 	u64 prot = 0;
28459c4da86SZong Li 
28559c4da86SZong Li 	if (level >= 0)
28659c4da86SZong Li 		prot = val & pg_level[level].mask;
28759c4da86SZong Li 
28859c4da86SZong Li 	if (st->level == -1) {
28959c4da86SZong Li 		st->level = level;
29059c4da86SZong Li 		st->current_prot = prot;
29159c4da86SZong Li 		st->start_address = addr;
29259c4da86SZong Li 		st->start_pa = pa;
29359c4da86SZong Li 		st->last_pa = pa;
29459c4da86SZong Li 		pt_dump_seq_printf(st->seq, "---[ %s ]---\n", st->marker->name);
29559c4da86SZong Li 	} else if (prot != st->current_prot ||
29659c4da86SZong Li 		   level != st->level || addr >= st->marker[1].start_address) {
29759c4da86SZong Li 		if (st->current_prot) {
29859c4da86SZong Li 			note_prot_wx(st, addr);
29959c4da86SZong Li 			dump_addr(st, addr);
30059c4da86SZong Li 			dump_prot(st);
30159c4da86SZong Li 			pt_dump_seq_puts(st->seq, "\n");
30259c4da86SZong Li 		}
30359c4da86SZong Li 
30459c4da86SZong Li 		while (addr >= st->marker[1].start_address) {
30559c4da86SZong Li 			st->marker++;
30659c4da86SZong Li 			pt_dump_seq_printf(st->seq, "---[ %s ]---\n",
30759c4da86SZong Li 					   st->marker->name);
30859c4da86SZong Li 		}
30959c4da86SZong Li 
31059c4da86SZong Li 		st->start_address = addr;
31159c4da86SZong Li 		st->start_pa = pa;
31259c4da86SZong Li 		st->last_pa = pa;
31359c4da86SZong Li 		st->current_prot = prot;
31459c4da86SZong Li 		st->level = level;
31559c4da86SZong Li 	} else {
31659c4da86SZong Li 		st->last_pa = pa;
31759c4da86SZong Li 	}
31859c4da86SZong Li }
31959c4da86SZong Li 
320de22d210SAtish Patra static void ptdump_walk(struct seq_file *s, struct ptd_mm_info *pinfo)
32159c4da86SZong Li {
32259c4da86SZong Li 	struct pg_state st = {
32359c4da86SZong Li 		.seq = s,
324de22d210SAtish Patra 		.marker = pinfo->markers,
32559c4da86SZong Li 		.level = -1,
32659c4da86SZong Li 		.ptdump = {
32759c4da86SZong Li 			.note_page = note_page,
32859c4da86SZong Li 			.range = (struct ptdump_range[]) {
329de22d210SAtish Patra 				{pinfo->base_addr, pinfo->end},
33059c4da86SZong Li 				{0, 0}
33159c4da86SZong Li 			}
33259c4da86SZong Li 		}
33359c4da86SZong Li 	};
33459c4da86SZong Li 
335de22d210SAtish Patra 	ptdump_walk_pgd(&st.ptdump, pinfo->mm, NULL);
33659c4da86SZong Li }
33759c4da86SZong Li 
338*6cdc82dbSChristophe Leroy bool ptdump_check_wx(void)
33959c4da86SZong Li {
34059c4da86SZong Li 	struct pg_state st = {
34159c4da86SZong Li 		.seq = NULL,
34259c4da86SZong Li 		.marker = (struct addr_marker[]) {
34359c4da86SZong Li 			{0, NULL},
34459c4da86SZong Li 			{-1, NULL},
34559c4da86SZong Li 		},
34659c4da86SZong Li 		.level = -1,
34759c4da86SZong Li 		.check_wx = true,
34859c4da86SZong Li 		.ptdump = {
34959c4da86SZong Li 			.note_page = note_page,
35059c4da86SZong Li 			.range = (struct ptdump_range[]) {
35159c4da86SZong Li 				{KERN_VIRT_START, ULONG_MAX},
35259c4da86SZong Li 				{0, 0}
35359c4da86SZong Li 			}
35459c4da86SZong Li 		}
35559c4da86SZong Li 	};
35659c4da86SZong Li 
35759c4da86SZong Li 	ptdump_walk_pgd(&st.ptdump, &init_mm, NULL);
35859c4da86SZong Li 
359*6cdc82dbSChristophe Leroy 	if (st.wx_pages) {
36059c4da86SZong Li 		pr_warn("Checked W+X mappings: failed, %lu W+X pages found\n",
36159c4da86SZong Li 			st.wx_pages);
362*6cdc82dbSChristophe Leroy 
363*6cdc82dbSChristophe Leroy 		return false;
364*6cdc82dbSChristophe Leroy 	} else {
36559c4da86SZong Li 		pr_info("Checked W+X mappings: passed, no W+X pages found\n");
366*6cdc82dbSChristophe Leroy 
367*6cdc82dbSChristophe Leroy 		return true;
368*6cdc82dbSChristophe Leroy 	}
36959c4da86SZong Li }
37059c4da86SZong Li 
37159c4da86SZong Li static int ptdump_show(struct seq_file *m, void *v)
37259c4da86SZong Li {
373de22d210SAtish Patra 	ptdump_walk(m, m->private);
37459c4da86SZong Li 
37559c4da86SZong Li 	return 0;
37659c4da86SZong Li }
37759c4da86SZong Li 
37859c4da86SZong Li DEFINE_SHOW_ATTRIBUTE(ptdump);
37959c4da86SZong Li 
3801987501bSJisheng Zhang static int __init ptdump_init(void)
38159c4da86SZong Li {
38259c4da86SZong Li 	unsigned int i, j;
38359c4da86SZong Li 
3840df68ce4SAlexandre Ghiti 	address_markers[FIXMAP_START_NR].start_address = FIXADDR_START;
3850df68ce4SAlexandre Ghiti 	address_markers[FIXMAP_END_NR].start_address = FIXADDR_TOP;
3860df68ce4SAlexandre Ghiti 	address_markers[PCI_IO_START_NR].start_address = PCI_IO_START;
3870df68ce4SAlexandre Ghiti 	address_markers[PCI_IO_END_NR].start_address = PCI_IO_END;
3880df68ce4SAlexandre Ghiti #ifdef CONFIG_SPARSEMEM_VMEMMAP
3890df68ce4SAlexandre Ghiti 	address_markers[VMEMMAP_START_NR].start_address = VMEMMAP_START;
3900df68ce4SAlexandre Ghiti 	address_markers[VMEMMAP_END_NR].start_address = VMEMMAP_END;
3910df68ce4SAlexandre Ghiti #endif
3920df68ce4SAlexandre Ghiti 	address_markers[VMALLOC_START_NR].start_address = VMALLOC_START;
3930df68ce4SAlexandre Ghiti 	address_markers[VMALLOC_END_NR].start_address = VMALLOC_END;
3940df68ce4SAlexandre Ghiti 	address_markers[PAGE_OFFSET_NR].start_address = PAGE_OFFSET;
395ecd7ebafSAlexandre Ghiti #ifdef CONFIG_KASAN
396ecd7ebafSAlexandre Ghiti 	address_markers[KASAN_SHADOW_START_NR].start_address = KASAN_SHADOW_START;
397ecd7ebafSAlexandre Ghiti 	address_markers[KASAN_SHADOW_END_NR].start_address = KASAN_SHADOW_END;
398ecd7ebafSAlexandre Ghiti #endif
3990df68ce4SAlexandre Ghiti #ifdef CONFIG_64BIT
4000df68ce4SAlexandre Ghiti 	address_markers[MODULES_MAPPING_NR].start_address = MODULES_VADDR;
401658e2c51SAlexandre Ghiti 	address_markers[KERNEL_MAPPING_NR].start_address = kernel_map.virt_addr;
40228252e08SAlexandre Ghiti #endif
4030df68ce4SAlexandre Ghiti 
4040df68ce4SAlexandre Ghiti 	kernel_ptd_info.base_addr = KERN_VIRT_START;
4050df68ce4SAlexandre Ghiti 
406e59e5e27SSong Shuai 	pg_level[1].name = pgtable_l5_enabled ? "P4D" : "PGD";
407e59e5e27SSong Shuai 	pg_level[2].name = pgtable_l4_enabled ? "PUD" : "PGD";
408e59e5e27SSong Shuai 
40959c4da86SZong Li 	for (i = 0; i < ARRAY_SIZE(pg_level); i++)
41059c4da86SZong Li 		for (j = 0; j < ARRAY_SIZE(pte_bits); j++)
41159c4da86SZong Li 			pg_level[i].mask |= pte_bits[j].mask;
41259c4da86SZong Li 
413de22d210SAtish Patra 	debugfs_create_file("kernel_page_tables", 0400, NULL, &kernel_ptd_info,
41459c4da86SZong Li 			    &ptdump_fops);
415de22d210SAtish Patra #ifdef CONFIG_EFI
416de22d210SAtish Patra 	if (efi_enabled(EFI_RUNTIME_SERVICES))
417de22d210SAtish Patra 		debugfs_create_file("efi_page_tables", 0400, NULL, &efi_ptd_info,
418de22d210SAtish Patra 				    &ptdump_fops);
419de22d210SAtish Patra #endif
42059c4da86SZong Li 
42159c4da86SZong Li 	return 0;
42259c4da86SZong Li }
42359c4da86SZong Li 
42459c4da86SZong Li device_initcall(ptdump_init);
425