Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Debug helper to dump the current kernel pagetables of the system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * so that we can see what the various memory ranges are set to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * (C) Copyright 2008 Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Author: Arjan van de Ven <arjan@linux.intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/kasan.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/highmem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/ptdump.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <asm/e820/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * The dumper groups pagetable entries of the same type into one, and for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * that it needs to keep some state when walking, and flush this state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * when a "break" in the continuity is found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) struct pg_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	struct ptdump_state ptdump;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	int level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	pgprotval_t current_prot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	pgprotval_t effective_prot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	pgprotval_t prot_levels[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	unsigned long start_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	const struct addr_marker *marker;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	unsigned long lines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	bool to_dmesg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	bool check_wx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	unsigned long wx_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct seq_file *seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) struct addr_marker {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	unsigned long start_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	unsigned long max_lines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) /* Address space markers hints */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #ifdef CONFIG_X86_64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) enum address_markers_idx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	USER_SPACE_NR = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	KERNEL_SPACE_NR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #ifdef CONFIG_MODIFY_LDT_SYSCALL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	LDT_NR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	LOW_KERNEL_NR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	VMALLOC_START_NR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	VMEMMAP_START_NR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #ifdef CONFIG_KASAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	KASAN_SHADOW_START_NR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	KASAN_SHADOW_END_NR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	CPU_ENTRY_AREA_NR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) #ifdef CONFIG_X86_ESPFIX64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	ESPFIX_START_NR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) #ifdef CONFIG_EFI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	EFI_END_NR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	HIGH_KERNEL_NR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	MODULES_VADDR_NR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	MODULES_END_NR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	FIXADDR_START_NR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	END_OF_SPACE_NR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) static struct addr_marker address_markers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	[USER_SPACE_NR]		= { 0,			"User Space" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	[KERNEL_SPACE_NR]	= { (1UL << 63),	"Kernel Space" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	[LOW_KERNEL_NR]		= { 0UL,		"Low Kernel Mapping" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	[VMALLOC_START_NR]	= { 0UL,		"vmalloc() Area" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	[VMEMMAP_START_NR]	= { 0UL,		"Vmemmap" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) #ifdef CONFIG_KASAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	 * These fields get initialized with the (dynamic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	 * KASAN_SHADOW_{START,END} values in pt_dump_init().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	[KASAN_SHADOW_START_NR]	= { 0UL,		"KASAN shadow" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	[KASAN_SHADOW_END_NR]	= { 0UL,		"KASAN shadow end" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) #ifdef CONFIG_MODIFY_LDT_SYSCALL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	[LDT_NR]		= { 0UL,		"LDT remap" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	[CPU_ENTRY_AREA_NR]	= { CPU_ENTRY_AREA_BASE,"CPU entry Area" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) #ifdef CONFIG_X86_ESPFIX64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	[ESPFIX_START_NR]	= { ESPFIX_BASE_ADDR,	"ESPfix Area", 16 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #ifdef CONFIG_EFI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	[EFI_END_NR]		= { EFI_VA_END,		"EFI Runtime Services" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	[HIGH_KERNEL_NR]	= { __START_KERNEL_map,	"High Kernel Mapping" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	[MODULES_VADDR_NR]	= { MODULES_VADDR,	"Modules" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	[MODULES_END_NR]	= { MODULES_END,	"End Modules" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	[FIXADDR_START_NR]	= { FIXADDR_START,	"Fixmap Area" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	[END_OF_SPACE_NR]	= { -1,			NULL }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define INIT_PGD	((pgd_t *) &init_top_pgt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #else /* CONFIG_X86_64 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) enum address_markers_idx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	USER_SPACE_NR = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	KERNEL_SPACE_NR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	VMALLOC_START_NR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	VMALLOC_END_NR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #ifdef CONFIG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	PKMAP_BASE_NR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #ifdef CONFIG_MODIFY_LDT_SYSCALL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	LDT_NR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	CPU_ENTRY_AREA_NR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	FIXADDR_START_NR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	END_OF_SPACE_NR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static struct addr_marker address_markers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	[USER_SPACE_NR]		= { 0,			"User Space" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	[KERNEL_SPACE_NR]	= { PAGE_OFFSET,	"Kernel Mapping" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	[VMALLOC_START_NR]	= { 0UL,		"vmalloc() Area" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	[VMALLOC_END_NR]	= { 0UL,		"vmalloc() End" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) #ifdef CONFIG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	[PKMAP_BASE_NR]		= { 0UL,		"Persistent kmap() Area" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) #ifdef CONFIG_MODIFY_LDT_SYSCALL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	[LDT_NR]		= { 0UL,		"LDT remap" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	[CPU_ENTRY_AREA_NR]	= { 0UL,		"CPU entry area" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	[FIXADDR_START_NR]	= { 0UL,		"Fixmap area" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	[END_OF_SPACE_NR]	= { -1,			NULL }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) #define INIT_PGD	(swapper_pg_dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) #endif /* !CONFIG_X86_64 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) /* Multipliers for offsets within the PTEs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) #define PTE_LEVEL_MULT (PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) #define PMD_LEVEL_MULT (PTRS_PER_PTE * PTE_LEVEL_MULT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) #define PUD_LEVEL_MULT (PTRS_PER_PMD * PMD_LEVEL_MULT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) #define P4D_LEVEL_MULT (PTRS_PER_PUD * PUD_LEVEL_MULT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) #define PGD_LEVEL_MULT (PTRS_PER_P4D * P4D_LEVEL_MULT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) #define pt_dump_seq_printf(m, to_dmesg, fmt, args...)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) ({								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	if (to_dmesg)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		printk(KERN_INFO fmt, ##args);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	else							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		if (m)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			seq_printf(m, fmt, ##args);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) #define pt_dump_cont_printf(m, to_dmesg, fmt, args...)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) ({								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	if (to_dmesg)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		printk(KERN_CONT fmt, ##args);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	else							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		if (m)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			seq_printf(m, fmt, ##args);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  * Print a readable form of a pgprot_t to the seq_file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static void printk_prot(struct seq_file *m, pgprotval_t pr, int level, bool dmsg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	static const char * const level_name[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		{ "pgd", "p4d", "pud", "pmd", "pte" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (!(pr & _PAGE_PRESENT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		/* Not present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		pt_dump_cont_printf(m, dmsg, "                              ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		if (pr & _PAGE_USER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			pt_dump_cont_printf(m, dmsg, "USR ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			pt_dump_cont_printf(m, dmsg, "    ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		if (pr & _PAGE_RW)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			pt_dump_cont_printf(m, dmsg, "RW ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			pt_dump_cont_printf(m, dmsg, "ro ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		if (pr & _PAGE_PWT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			pt_dump_cont_printf(m, dmsg, "PWT ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			pt_dump_cont_printf(m, dmsg, "    ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		if (pr & _PAGE_PCD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			pt_dump_cont_printf(m, dmsg, "PCD ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			pt_dump_cont_printf(m, dmsg, "    ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		/* Bit 7 has a different meaning on level 3 vs 4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		if (level <= 3 && pr & _PAGE_PSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			pt_dump_cont_printf(m, dmsg, "PSE ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			pt_dump_cont_printf(m, dmsg, "    ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		if ((level == 4 && pr & _PAGE_PAT) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		    ((level == 3 || level == 2) && pr & _PAGE_PAT_LARGE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			pt_dump_cont_printf(m, dmsg, "PAT ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			pt_dump_cont_printf(m, dmsg, "    ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		if (pr & _PAGE_GLOBAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			pt_dump_cont_printf(m, dmsg, "GLB ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			pt_dump_cont_printf(m, dmsg, "    ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		if (pr & _PAGE_NX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 			pt_dump_cont_printf(m, dmsg, "NX ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			pt_dump_cont_printf(m, dmsg, "x  ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	pt_dump_cont_printf(m, dmsg, "%s\n", level_name[level]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static void note_wx(struct pg_state *st, unsigned long addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	unsigned long npages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	npages = (addr - st->start_address) / PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) #ifdef CONFIG_PCI_BIOS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	 * If PCI BIOS is enabled, the PCI BIOS area is forced to WX.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	 * Inform about it, but avoid the warning.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	if (pcibios_enabled && st->start_address >= PAGE_OFFSET + BIOS_BEGIN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	    addr <= PAGE_OFFSET + BIOS_END) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		pr_warn_once("x86/mm: PCI BIOS W+X mapping %lu pages\n", npages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	/* Account the WX pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	st->wx_pages += npages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	WARN_ONCE(__supported_pte_mask & _PAGE_NX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		  "x86/mm: Found insecure W+X mapping at address %pS\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		  (void *)st->start_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static void effective_prot(struct ptdump_state *pt_st, int level, u64 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	struct pg_state *st = container_of(pt_st, struct pg_state, ptdump);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	pgprotval_t prot = val & PTE_FLAGS_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	pgprotval_t effective;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	if (level > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		pgprotval_t higher_prot = st->prot_levels[level - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		effective = (higher_prot & prot & (_PAGE_USER | _PAGE_RW)) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 			    ((higher_prot | prot) & _PAGE_NX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		effective = prot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	st->prot_levels[level] = effective;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)  * This function gets called on a break in a continuous series
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)  * of PTE entries; the next one is different so we need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)  * print what we collected so far.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		      u64 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	struct pg_state *st = container_of(pt_st, struct pg_state, ptdump);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	pgprotval_t new_prot, new_eff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	pgprotval_t cur, eff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	static const char units[] = "BKMGTPE";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	struct seq_file *m = st->seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	new_prot = val & PTE_FLAGS_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	if (!val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		new_eff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		new_eff = st->prot_levels[level];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	 * If we have a "break" in the series, we need to flush the state that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	 * we have now. "break" is either changing perms, levels or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	 * address space marker.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	cur = st->current_prot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	eff = st->effective_prot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	if (st->level == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		/* First entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		st->current_prot = new_prot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		st->effective_prot = new_eff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		st->level = level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		st->marker = address_markers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		st->lines = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		pt_dump_seq_printf(m, st->to_dmesg, "---[ %s ]---\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 				   st->marker->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	} else if (new_prot != cur || new_eff != eff || level != st->level ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		   addr >= st->marker[1].start_address) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		const char *unit = units;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		unsigned long delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		int width = sizeof(unsigned long) * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		if (st->check_wx && (eff & _PAGE_RW) && !(eff & _PAGE_NX))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 			note_wx(st, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		 * Now print the actual finished series
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		if (!st->marker->max_lines ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		    st->lines < st->marker->max_lines) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 			pt_dump_seq_printf(m, st->to_dmesg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 					   "0x%0*lx-0x%0*lx   ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 					   width, st->start_address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 					   width, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 			delta = addr - st->start_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 			while (!(delta & 1023) && unit[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 				delta >>= 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 				unit++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 			pt_dump_cont_printf(m, st->to_dmesg, "%9lu%c ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 					    delta, *unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 			printk_prot(m, st->current_prot, st->level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 				    st->to_dmesg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		st->lines++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		 * We print markers for special areas of address space,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		 * such as the start of vmalloc space etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		 * This helps in the interpretation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		if (addr >= st->marker[1].start_address) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 			if (st->marker->max_lines &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 			    st->lines > st->marker->max_lines) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 				unsigned long nskip =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 					st->lines - st->marker->max_lines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 				pt_dump_seq_printf(m, st->to_dmesg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 						   "... %lu entr%s skipped ... \n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 						   nskip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 						   nskip == 1 ? "y" : "ies");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 			st->marker++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 			st->lines = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 			pt_dump_seq_printf(m, st->to_dmesg, "---[ %s ]---\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 					   st->marker->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		st->start_address = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		st->current_prot = new_prot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		st->effective_prot = new_eff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		st->level = level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) static void ptdump_walk_pgd_level_core(struct seq_file *m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 				       struct mm_struct *mm, pgd_t *pgd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 				       bool checkwx, bool dmesg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	const struct ptdump_range ptdump_ranges[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) #ifdef CONFIG_X86_64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	{0, PTRS_PER_PGD * PGD_LEVEL_MULT / 2},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	{GUARD_HOLE_END_ADDR, ~0UL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	{0, ~0UL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	{0, 0}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	struct pg_state st = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		.ptdump = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 			.note_page	= note_page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 			.effective_prot = effective_prot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 			.range		= ptdump_ranges
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		.level = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		.to_dmesg	= dmesg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		.check_wx	= checkwx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		.seq		= m
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	ptdump_walk_pgd(&st.ptdump, mm, pgd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	if (!checkwx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	if (st.wx_pages)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		pr_info("x86/mm: Checked W+X mappings: FAILED, %lu W+X pages found.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 			st.wx_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		pr_info("x86/mm: Checked W+X mappings: passed, no W+X pages found.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) void ptdump_walk_pgd_level(struct seq_file *m, struct mm_struct *mm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	ptdump_walk_pgd_level_core(m, mm, mm->pgd, false, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) void ptdump_walk_pgd_level_debugfs(struct seq_file *m, struct mm_struct *mm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 				   bool user)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	pgd_t *pgd = mm->pgd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) #ifdef CONFIG_PAGE_TABLE_ISOLATION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	if (user && boot_cpu_has(X86_FEATURE_PTI))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		pgd = kernel_to_user_pgdp(pgd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	ptdump_walk_pgd_level_core(m, mm, pgd, false, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) EXPORT_SYMBOL_GPL(ptdump_walk_pgd_level_debugfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) void ptdump_walk_user_pgd_level_checkwx(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) #ifdef CONFIG_PAGE_TABLE_ISOLATION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	pgd_t *pgd = INIT_PGD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	if (!(__supported_pte_mask & _PAGE_NX) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	    !boot_cpu_has(X86_FEATURE_PTI))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	pr_info("x86/mm: Checking user space page tables\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	pgd = kernel_to_user_pgdp(pgd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	ptdump_walk_pgd_level_core(NULL, &init_mm, pgd, true, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) void ptdump_walk_pgd_level_checkwx(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	ptdump_walk_pgd_level_core(NULL, &init_mm, INIT_PGD, true, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) static int __init pt_dump_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	 * Various markers are not compile-time constants, so assign them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	 * here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) #ifdef CONFIG_X86_64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	address_markers[LOW_KERNEL_NR].start_address = PAGE_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	address_markers[VMALLOC_START_NR].start_address = VMALLOC_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	address_markers[VMEMMAP_START_NR].start_address = VMEMMAP_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) #ifdef CONFIG_MODIFY_LDT_SYSCALL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	address_markers[LDT_NR].start_address = LDT_BASE_ADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) #ifdef CONFIG_KASAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	address_markers[KASAN_SHADOW_START_NR].start_address = KASAN_SHADOW_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	address_markers[KASAN_SHADOW_END_NR].start_address = KASAN_SHADOW_END;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) #ifdef CONFIG_X86_32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	address_markers[VMALLOC_START_NR].start_address = VMALLOC_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	address_markers[VMALLOC_END_NR].start_address = VMALLOC_END;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) # ifdef CONFIG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	address_markers[PKMAP_BASE_NR].start_address = PKMAP_BASE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) # endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	address_markers[FIXADDR_START_NR].start_address = FIXADDR_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	address_markers[CPU_ENTRY_AREA_NR].start_address = CPU_ENTRY_AREA_BASE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) # ifdef CONFIG_MODIFY_LDT_SYSCALL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	address_markers[LDT_NR].start_address = LDT_BASE_ADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) # endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) __initcall(pt_dump_init);