| .. | .. |
|---|
| 1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
|---|
| 2 | +#include <linux/set_memory.h> |
|---|
| 3 | +#include <linux/ptdump.h> |
|---|
| 2 | 4 | #include <linux/seq_file.h> |
|---|
| 3 | 5 | #include <linux/debugfs.h> |
|---|
| 4 | | -#include <linux/sched.h> |
|---|
| 5 | 6 | #include <linux/mm.h> |
|---|
| 7 | +#include <linux/kasan.h> |
|---|
| 8 | +#include <asm/ptdump.h> |
|---|
| 9 | +#include <asm/kasan.h> |
|---|
| 6 | 10 | #include <asm/sections.h> |
|---|
| 7 | | -#include <asm/pgtable.h> |
|---|
| 8 | 11 | |
|---|
| 9 | 12 | static unsigned long max_addr; |
|---|
| 10 | 13 | |
|---|
| .. | .. |
|---|
| 14 | 17 | }; |
|---|
| 15 | 18 | |
|---|
| 16 | 19 | enum address_markers_idx { |
|---|
| 17 | | - IDENTITY_NR = 0, |
|---|
| 20 | + IDENTITY_BEFORE_NR = 0, |
|---|
| 21 | + IDENTITY_BEFORE_END_NR, |
|---|
| 18 | 22 | KERNEL_START_NR, |
|---|
| 19 | 23 | KERNEL_END_NR, |
|---|
| 24 | + IDENTITY_AFTER_NR, |
|---|
| 25 | + IDENTITY_AFTER_END_NR, |
|---|
| 26 | +#ifdef CONFIG_KASAN |
|---|
| 27 | + KASAN_SHADOW_START_NR, |
|---|
| 28 | + KASAN_SHADOW_END_NR, |
|---|
| 29 | +#endif |
|---|
| 20 | 30 | VMEMMAP_NR, |
|---|
| 31 | + VMEMMAP_END_NR, |
|---|
| 21 | 32 | VMALLOC_NR, |
|---|
| 33 | + VMALLOC_END_NR, |
|---|
| 22 | 34 | MODULES_NR, |
|---|
| 35 | + MODULES_END_NR, |
|---|
| 23 | 36 | }; |
|---|
| 24 | 37 | |
|---|
| 25 | 38 | static struct addr_marker address_markers[] = { |
|---|
| 26 | | - [IDENTITY_NR] = {0, "Identity Mapping"}, |
|---|
| 27 | | - [KERNEL_START_NR] = {(unsigned long)_stext, "Kernel Image Start"}, |
|---|
| 28 | | - [KERNEL_END_NR] = {(unsigned long)_end, "Kernel Image End"}, |
|---|
| 29 | | - [VMEMMAP_NR] = {0, "vmemmap Area"}, |
|---|
| 30 | | - [VMALLOC_NR] = {0, "vmalloc Area"}, |
|---|
| 31 | | - [MODULES_NR] = {0, "Modules Area"}, |
|---|
| 39 | + [IDENTITY_BEFORE_NR] = {0, "Identity Mapping Start"}, |
|---|
| 40 | + [IDENTITY_BEFORE_END_NR] = {(unsigned long)_stext, "Identity Mapping End"}, |
|---|
| 41 | + [KERNEL_START_NR] = {(unsigned long)_stext, "Kernel Image Start"}, |
|---|
| 42 | + [KERNEL_END_NR] = {(unsigned long)_end, "Kernel Image End"}, |
|---|
| 43 | + [IDENTITY_AFTER_NR] = {(unsigned long)_end, "Identity Mapping Start"}, |
|---|
| 44 | + [IDENTITY_AFTER_END_NR] = {0, "Identity Mapping End"}, |
|---|
| 45 | +#ifdef CONFIG_KASAN |
|---|
| 46 | + [KASAN_SHADOW_START_NR] = {KASAN_SHADOW_START, "Kasan Shadow Start"}, |
|---|
| 47 | + [KASAN_SHADOW_END_NR] = {KASAN_SHADOW_END, "Kasan Shadow End"}, |
|---|
| 48 | +#endif |
|---|
| 49 | + [VMEMMAP_NR] = {0, "vmemmap Area Start"}, |
|---|
| 50 | + [VMEMMAP_END_NR] = {0, "vmemmap Area End"}, |
|---|
| 51 | + [VMALLOC_NR] = {0, "vmalloc Area Start"}, |
|---|
| 52 | + [VMALLOC_END_NR] = {0, "vmalloc Area End"}, |
|---|
| 53 | + [MODULES_NR] = {0, "Modules Area Start"}, |
|---|
| 54 | + [MODULES_END_NR] = {0, "Modules Area End"}, |
|---|
| 32 | 55 | { -1, NULL } |
|---|
| 33 | 56 | }; |
|---|
| 34 | 57 | |
|---|
| 35 | 58 | struct pg_state { |
|---|
| 59 | + struct ptdump_state ptdump; |
|---|
| 60 | + struct seq_file *seq; |
|---|
| 36 | 61 | int level; |
|---|
| 37 | 62 | unsigned int current_prot; |
|---|
| 63 | + bool check_wx; |
|---|
| 64 | + unsigned long wx_pages; |
|---|
| 38 | 65 | unsigned long start_address; |
|---|
| 39 | | - unsigned long current_address; |
|---|
| 40 | 66 | const struct addr_marker *marker; |
|---|
| 41 | 67 | }; |
|---|
| 68 | + |
|---|
| 69 | +#define pt_dump_seq_printf(m, fmt, args...) \ |
|---|
| 70 | +({ \ |
|---|
| 71 | + struct seq_file *__m = (m); \ |
|---|
| 72 | + \ |
|---|
| 73 | + if (__m) \ |
|---|
| 74 | + seq_printf(__m, fmt, ##args); \ |
|---|
| 75 | +}) |
|---|
| 76 | + |
|---|
| 77 | +#define pt_dump_seq_puts(m, fmt) \ |
|---|
| 78 | +({ \ |
|---|
| 79 | + struct seq_file *__m = (m); \ |
|---|
| 80 | + \ |
|---|
| 81 | + if (__m) \ |
|---|
| 82 | + seq_printf(__m, fmt); \ |
|---|
| 83 | +}) |
|---|
| 42 | 84 | |
|---|
| 43 | 85 | static void print_prot(struct seq_file *m, unsigned int pr, int level) |
|---|
| 44 | 86 | { |
|---|
| 45 | 87 | static const char * const level_name[] = |
|---|
| 46 | 88 | { "ASCE", "PGD", "PUD", "PMD", "PTE" }; |
|---|
| 47 | 89 | |
|---|
| 48 | | - seq_printf(m, "%s ", level_name[level]); |
|---|
| 90 | + pt_dump_seq_printf(m, "%s ", level_name[level]); |
|---|
| 49 | 91 | if (pr & _PAGE_INVALID) { |
|---|
| 50 | | - seq_printf(m, "I\n"); |
|---|
| 92 | + pt_dump_seq_printf(m, "I\n"); |
|---|
| 51 | 93 | return; |
|---|
| 52 | 94 | } |
|---|
| 53 | | - seq_puts(m, (pr & _PAGE_PROTECT) ? "RO " : "RW "); |
|---|
| 54 | | - seq_puts(m, (pr & _PAGE_NOEXEC) ? "NX\n" : "X\n"); |
|---|
| 95 | + pt_dump_seq_puts(m, (pr & _PAGE_PROTECT) ? "RO " : "RW "); |
|---|
| 96 | + pt_dump_seq_puts(m, (pr & _PAGE_NOEXEC) ? "NX\n" : "X\n"); |
|---|
| 55 | 97 | } |
|---|
| 56 | 98 | |
|---|
| 57 | | -static void note_page(struct seq_file *m, struct pg_state *st, |
|---|
| 58 | | - unsigned int new_prot, int level) |
|---|
| 99 | +static void note_prot_wx(struct pg_state *st, unsigned long addr) |
|---|
| 59 | 100 | { |
|---|
| 60 | | - static const char units[] = "KMGTPE"; |
|---|
| 101 | +#ifdef CONFIG_DEBUG_WX |
|---|
| 102 | + if (!st->check_wx) |
|---|
| 103 | + return; |
|---|
| 104 | + if (st->current_prot & _PAGE_INVALID) |
|---|
| 105 | + return; |
|---|
| 106 | + if (st->current_prot & _PAGE_PROTECT) |
|---|
| 107 | + return; |
|---|
| 108 | + if (st->current_prot & _PAGE_NOEXEC) |
|---|
| 109 | + return; |
|---|
| 110 | + /* The first lowcore page is currently still W+X. */ |
|---|
| 111 | + if (addr == PAGE_SIZE) |
|---|
| 112 | + return; |
|---|
| 113 | + WARN_ONCE(1, "s390/mm: Found insecure W+X mapping at address %pS\n", |
|---|
| 114 | + (void *)st->start_address); |
|---|
| 115 | + st->wx_pages += (addr - st->start_address) / PAGE_SIZE; |
|---|
| 116 | +#endif /* CONFIG_DEBUG_WX */ |
|---|
| 117 | +} |
|---|
| 118 | + |
|---|
| 119 | +static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, u64 val) |
|---|
| 120 | +{ |
|---|
| 61 | 121 | int width = sizeof(unsigned long) * 2; |
|---|
| 122 | + static const char units[] = "KMGTPE"; |
|---|
| 62 | 123 | const char *unit = units; |
|---|
| 63 | | - unsigned int prot, cur; |
|---|
| 64 | 124 | unsigned long delta; |
|---|
| 125 | + struct pg_state *st; |
|---|
| 126 | + struct seq_file *m; |
|---|
| 127 | + unsigned int prot; |
|---|
| 65 | 128 | |
|---|
| 66 | | - /* |
|---|
| 67 | | - * If we have a "break" in the series, we need to flush the state |
|---|
| 68 | | - * that we have now. "break" is either changing perms, levels or |
|---|
| 69 | | - * address space marker. |
|---|
| 70 | | - */ |
|---|
| 71 | | - prot = new_prot; |
|---|
| 72 | | - cur = st->current_prot; |
|---|
| 73 | | - |
|---|
| 74 | | - if (!st->level) { |
|---|
| 75 | | - /* First entry */ |
|---|
| 76 | | - st->current_prot = new_prot; |
|---|
| 129 | + st = container_of(pt_st, struct pg_state, ptdump); |
|---|
| 130 | + m = st->seq; |
|---|
| 131 | + prot = val & (_PAGE_PROTECT | _PAGE_NOEXEC); |
|---|
| 132 | + if (level == 4 && (val & _PAGE_INVALID)) |
|---|
| 133 | + prot = _PAGE_INVALID; |
|---|
| 134 | + /* For pmd_none() & friends val gets passed as zero. */ |
|---|
| 135 | + if (level != 4 && !val) |
|---|
| 136 | + prot = _PAGE_INVALID; |
|---|
| 137 | + /* Final flush from generic code. */ |
|---|
| 138 | + if (level == -1) |
|---|
| 139 | + addr = max_addr; |
|---|
| 140 | + if (st->level == -1) { |
|---|
| 141 | + pt_dump_seq_printf(m, "---[ %s ]---\n", st->marker->name); |
|---|
| 142 | + st->start_address = addr; |
|---|
| 143 | + st->current_prot = prot; |
|---|
| 77 | 144 | st->level = level; |
|---|
| 78 | | - st->marker = address_markers; |
|---|
| 79 | | - seq_printf(m, "---[ %s ]---\n", st->marker->name); |
|---|
| 80 | | - } else if (prot != cur || level != st->level || |
|---|
| 81 | | - st->current_address >= st->marker[1].start_address) { |
|---|
| 82 | | - /* Print the actual finished series */ |
|---|
| 83 | | - seq_printf(m, "0x%0*lx-0x%0*lx", |
|---|
| 84 | | - width, st->start_address, |
|---|
| 85 | | - width, st->current_address); |
|---|
| 86 | | - delta = (st->current_address - st->start_address) >> 10; |
|---|
| 145 | + } else if (prot != st->current_prot || level != st->level || |
|---|
| 146 | + addr >= st->marker[1].start_address) { |
|---|
| 147 | + note_prot_wx(st, addr); |
|---|
| 148 | + pt_dump_seq_printf(m, "0x%0*lx-0x%0*lx ", |
|---|
| 149 | + width, st->start_address, |
|---|
| 150 | + width, addr); |
|---|
| 151 | + delta = (addr - st->start_address) >> 10; |
|---|
| 87 | 152 | while (!(delta & 0x3ff) && unit[1]) { |
|---|
| 88 | 153 | delta >>= 10; |
|---|
| 89 | 154 | unit++; |
|---|
| 90 | 155 | } |
|---|
| 91 | | - seq_printf(m, "%9lu%c ", delta, *unit); |
|---|
| 156 | + pt_dump_seq_printf(m, "%9lu%c ", delta, *unit); |
|---|
| 92 | 157 | print_prot(m, st->current_prot, st->level); |
|---|
| 93 | | - if (st->current_address >= st->marker[1].start_address) { |
|---|
| 158 | + while (addr >= st->marker[1].start_address) { |
|---|
| 94 | 159 | st->marker++; |
|---|
| 95 | | - seq_printf(m, "---[ %s ]---\n", st->marker->name); |
|---|
| 160 | + pt_dump_seq_printf(m, "---[ %s ]---\n", st->marker->name); |
|---|
| 96 | 161 | } |
|---|
| 97 | | - st->start_address = st->current_address; |
|---|
| 98 | | - st->current_prot = new_prot; |
|---|
| 162 | + st->start_address = addr; |
|---|
| 163 | + st->current_prot = prot; |
|---|
| 99 | 164 | st->level = level; |
|---|
| 100 | 165 | } |
|---|
| 101 | 166 | } |
|---|
| 102 | 167 | |
|---|
| 103 | | -/* |
|---|
| 104 | | - * The actual page table walker functions. In order to keep the |
|---|
| 105 | | - * implementation of print_prot() short, we only check and pass |
|---|
| 106 | | - * _PAGE_INVALID and _PAGE_PROTECT flags to note_page() if a region, |
|---|
| 107 | | - * segment or page table entry is invalid or read-only. |
|---|
| 108 | | - * After all it's just a hint that the current level being walked |
|---|
| 109 | | - * contains an invalid or read-only entry. |
|---|
| 110 | | - */ |
|---|
| 111 | | -static void walk_pte_level(struct seq_file *m, struct pg_state *st, |
|---|
| 112 | | - pmd_t *pmd, unsigned long addr) |
|---|
| 168 | +#ifdef CONFIG_DEBUG_WX |
|---|
| 169 | +void ptdump_check_wx(void) |
|---|
| 113 | 170 | { |
|---|
| 114 | | - unsigned int prot; |
|---|
| 115 | | - pte_t *pte; |
|---|
| 116 | | - int i; |
|---|
| 171 | + struct pg_state st = { |
|---|
| 172 | + .ptdump = { |
|---|
| 173 | + .note_page = note_page, |
|---|
| 174 | + .range = (struct ptdump_range[]) { |
|---|
| 175 | + {.start = 0, .end = max_addr}, |
|---|
| 176 | + {.start = 0, .end = 0}, |
|---|
| 177 | + } |
|---|
| 178 | + }, |
|---|
| 179 | + .seq = NULL, |
|---|
| 180 | + .level = -1, |
|---|
| 181 | + .current_prot = 0, |
|---|
| 182 | + .check_wx = true, |
|---|
| 183 | + .wx_pages = 0, |
|---|
| 184 | + .start_address = 0, |
|---|
| 185 | + .marker = (struct addr_marker[]) { |
|---|
| 186 | + { .start_address = 0, .name = NULL}, |
|---|
| 187 | + { .start_address = -1, .name = NULL}, |
|---|
| 188 | + }, |
|---|
| 189 | + }; |
|---|
| 117 | 190 | |
|---|
| 118 | | - for (i = 0; i < PTRS_PER_PTE && addr < max_addr; i++) { |
|---|
| 119 | | - st->current_address = addr; |
|---|
| 120 | | - pte = pte_offset_kernel(pmd, addr); |
|---|
| 121 | | - prot = pte_val(*pte) & |
|---|
| 122 | | - (_PAGE_PROTECT | _PAGE_INVALID | _PAGE_NOEXEC); |
|---|
| 123 | | - note_page(m, st, prot, 4); |
|---|
| 124 | | - addr += PAGE_SIZE; |
|---|
| 125 | | - } |
|---|
| 191 | + if (!MACHINE_HAS_NX) |
|---|
| 192 | + return; |
|---|
| 193 | + ptdump_walk_pgd(&st.ptdump, &init_mm, NULL); |
|---|
| 194 | + if (st.wx_pages) |
|---|
| 195 | + pr_warn("Checked W+X mappings: FAILED, %lu W+X pages found\n", st.wx_pages); |
|---|
| 196 | + else |
|---|
| 197 | + pr_info("Checked W+X mappings: passed, no unexpected W+X pages found\n"); |
|---|
| 126 | 198 | } |
|---|
| 199 | +#endif /* CONFIG_DEBUG_WX */ |
|---|
| 127 | 200 | |
|---|
| 128 | | -static void walk_pmd_level(struct seq_file *m, struct pg_state *st, |
|---|
| 129 | | - pud_t *pud, unsigned long addr) |
|---|
| 130 | | -{ |
|---|
| 131 | | - unsigned int prot; |
|---|
| 132 | | - pmd_t *pmd; |
|---|
| 133 | | - int i; |
|---|
| 134 | | - |
|---|
| 135 | | - for (i = 0; i < PTRS_PER_PMD && addr < max_addr; i++) { |
|---|
| 136 | | - st->current_address = addr; |
|---|
| 137 | | - pmd = pmd_offset(pud, addr); |
|---|
| 138 | | - if (!pmd_none(*pmd)) { |
|---|
| 139 | | - if (pmd_large(*pmd)) { |
|---|
| 140 | | - prot = pmd_val(*pmd) & |
|---|
| 141 | | - (_SEGMENT_ENTRY_PROTECT | |
|---|
| 142 | | - _SEGMENT_ENTRY_NOEXEC); |
|---|
| 143 | | - note_page(m, st, prot, 3); |
|---|
| 144 | | - } else |
|---|
| 145 | | - walk_pte_level(m, st, pmd, addr); |
|---|
| 146 | | - } else |
|---|
| 147 | | - note_page(m, st, _PAGE_INVALID, 3); |
|---|
| 148 | | - addr += PMD_SIZE; |
|---|
| 149 | | - } |
|---|
| 150 | | -} |
|---|
| 151 | | - |
|---|
| 152 | | -static void walk_pud_level(struct seq_file *m, struct pg_state *st, |
|---|
| 153 | | - p4d_t *p4d, unsigned long addr) |
|---|
| 154 | | -{ |
|---|
| 155 | | - unsigned int prot; |
|---|
| 156 | | - pud_t *pud; |
|---|
| 157 | | - int i; |
|---|
| 158 | | - |
|---|
| 159 | | - for (i = 0; i < PTRS_PER_PUD && addr < max_addr; i++) { |
|---|
| 160 | | - st->current_address = addr; |
|---|
| 161 | | - pud = pud_offset(p4d, addr); |
|---|
| 162 | | - if (!pud_none(*pud)) |
|---|
| 163 | | - if (pud_large(*pud)) { |
|---|
| 164 | | - prot = pud_val(*pud) & |
|---|
| 165 | | - (_REGION_ENTRY_PROTECT | |
|---|
| 166 | | - _REGION_ENTRY_NOEXEC); |
|---|
| 167 | | - note_page(m, st, prot, 2); |
|---|
| 168 | | - } else |
|---|
| 169 | | - walk_pmd_level(m, st, pud, addr); |
|---|
| 170 | | - else |
|---|
| 171 | | - note_page(m, st, _PAGE_INVALID, 2); |
|---|
| 172 | | - addr += PUD_SIZE; |
|---|
| 173 | | - } |
|---|
| 174 | | -} |
|---|
| 175 | | - |
|---|
| 176 | | -static void walk_p4d_level(struct seq_file *m, struct pg_state *st, |
|---|
| 177 | | - pgd_t *pgd, unsigned long addr) |
|---|
| 178 | | -{ |
|---|
| 179 | | - p4d_t *p4d; |
|---|
| 180 | | - int i; |
|---|
| 181 | | - |
|---|
| 182 | | - for (i = 0; i < PTRS_PER_P4D && addr < max_addr; i++) { |
|---|
| 183 | | - st->current_address = addr; |
|---|
| 184 | | - p4d = p4d_offset(pgd, addr); |
|---|
| 185 | | - if (!p4d_none(*p4d)) |
|---|
| 186 | | - walk_pud_level(m, st, p4d, addr); |
|---|
| 187 | | - else |
|---|
| 188 | | - note_page(m, st, _PAGE_INVALID, 2); |
|---|
| 189 | | - addr += P4D_SIZE; |
|---|
| 190 | | - } |
|---|
| 191 | | -} |
|---|
| 192 | | - |
|---|
| 193 | | -static void walk_pgd_level(struct seq_file *m) |
|---|
| 194 | | -{ |
|---|
| 195 | | - unsigned long addr = 0; |
|---|
| 196 | | - struct pg_state st; |
|---|
| 197 | | - pgd_t *pgd; |
|---|
| 198 | | - int i; |
|---|
| 199 | | - |
|---|
| 200 | | - memset(&st, 0, sizeof(st)); |
|---|
| 201 | | - for (i = 0; i < PTRS_PER_PGD && addr < max_addr; i++) { |
|---|
| 202 | | - st.current_address = addr; |
|---|
| 203 | | - pgd = pgd_offset_k(addr); |
|---|
| 204 | | - if (!pgd_none(*pgd)) |
|---|
| 205 | | - walk_p4d_level(m, &st, pgd, addr); |
|---|
| 206 | | - else |
|---|
| 207 | | - note_page(m, &st, _PAGE_INVALID, 1); |
|---|
| 208 | | - addr += PGDIR_SIZE; |
|---|
| 209 | | - cond_resched(); |
|---|
| 210 | | - } |
|---|
| 211 | | - /* Flush out the last page */ |
|---|
| 212 | | - st.current_address = max_addr; |
|---|
| 213 | | - note_page(m, &st, 0, 0); |
|---|
| 214 | | -} |
|---|
| 215 | | - |
|---|
| 201 | +#ifdef CONFIG_PTDUMP_DEBUGFS |
|---|
| 216 | 202 | static int ptdump_show(struct seq_file *m, void *v) |
|---|
| 217 | 203 | { |
|---|
| 218 | | - walk_pgd_level(m); |
|---|
| 204 | + struct pg_state st = { |
|---|
| 205 | + .ptdump = { |
|---|
| 206 | + .note_page = note_page, |
|---|
| 207 | + .range = (struct ptdump_range[]) { |
|---|
| 208 | + {.start = 0, .end = max_addr}, |
|---|
| 209 | + {.start = 0, .end = 0}, |
|---|
| 210 | + } |
|---|
| 211 | + }, |
|---|
| 212 | + .seq = m, |
|---|
| 213 | + .level = -1, |
|---|
| 214 | + .current_prot = 0, |
|---|
| 215 | + .check_wx = false, |
|---|
| 216 | + .wx_pages = 0, |
|---|
| 217 | + .start_address = 0, |
|---|
| 218 | + .marker = address_markers, |
|---|
| 219 | + }; |
|---|
| 220 | + |
|---|
| 221 | + get_online_mems(); |
|---|
| 222 | + mutex_lock(&cpa_mutex); |
|---|
| 223 | + ptdump_walk_pgd(&st.ptdump, &init_mm, NULL); |
|---|
| 224 | + mutex_unlock(&cpa_mutex); |
|---|
| 225 | + put_online_mems(); |
|---|
| 219 | 226 | return 0; |
|---|
| 220 | 227 | } |
|---|
| 228 | +DEFINE_SHOW_ATTRIBUTE(ptdump); |
|---|
| 229 | +#endif /* CONFIG_PTDUMP_DEBUGFS */ |
|---|
| 221 | 230 | |
|---|
| 222 | | -static int ptdump_open(struct inode *inode, struct file *filp) |
|---|
| 231 | +/* |
|---|
| 232 | + * Heapsort from lib/sort.c is not a stable sorting algorithm, do a simple |
|---|
| 233 | + * insertion sort to preserve the original order of markers with the same |
|---|
| 234 | + * start address. |
|---|
| 235 | + */ |
|---|
| 236 | +static void sort_address_markers(void) |
|---|
| 223 | 237 | { |
|---|
| 224 | | - return single_open(filp, ptdump_show, NULL); |
|---|
| 225 | | -} |
|---|
| 238 | + struct addr_marker tmp; |
|---|
| 239 | + int i, j; |
|---|
| 226 | 240 | |
|---|
| 227 | | -static const struct file_operations ptdump_fops = { |
|---|
| 228 | | - .open = ptdump_open, |
|---|
| 229 | | - .read = seq_read, |
|---|
| 230 | | - .llseek = seq_lseek, |
|---|
| 231 | | - .release = single_release, |
|---|
| 232 | | -}; |
|---|
| 241 | + for (i = 1; i < ARRAY_SIZE(address_markers) - 1; i++) { |
|---|
| 242 | + tmp = address_markers[i]; |
|---|
| 243 | + for (j = i - 1; j >= 0 && address_markers[j].start_address > tmp.start_address; j--) |
|---|
| 244 | + address_markers[j + 1] = address_markers[j]; |
|---|
| 245 | + address_markers[j + 1] = tmp; |
|---|
| 246 | + } |
|---|
| 247 | +} |
|---|
| 233 | 248 | |
|---|
| 234 | 249 | static int pt_dump_init(void) |
|---|
| 235 | 250 | { |
|---|
| .. | .. |
|---|
| 240 | 255 | */ |
|---|
| 241 | 256 | max_addr = (S390_lowcore.kernel_asce & _REGION_ENTRY_TYPE_MASK) >> 2; |
|---|
| 242 | 257 | max_addr = 1UL << (max_addr * 11 + 31); |
|---|
| 258 | + address_markers[IDENTITY_AFTER_END_NR].start_address = memory_end; |
|---|
| 243 | 259 | address_markers[MODULES_NR].start_address = MODULES_VADDR; |
|---|
| 260 | + address_markers[MODULES_END_NR].start_address = MODULES_END; |
|---|
| 244 | 261 | address_markers[VMEMMAP_NR].start_address = (unsigned long) vmemmap; |
|---|
| 262 | + address_markers[VMEMMAP_END_NR].start_address = (unsigned long)vmemmap + vmemmap_size; |
|---|
| 245 | 263 | address_markers[VMALLOC_NR].start_address = VMALLOC_START; |
|---|
| 264 | + address_markers[VMALLOC_END_NR].start_address = VMALLOC_END; |
|---|
| 265 | + sort_address_markers(); |
|---|
| 266 | +#ifdef CONFIG_PTDUMP_DEBUGFS |
|---|
| 246 | 267 | debugfs_create_file("kernel_page_tables", 0400, NULL, NULL, &ptdump_fops); |
|---|
| 268 | +#endif /* CONFIG_PTDUMP_DEBUGFS */ |
|---|
| 247 | 269 | return 0; |
|---|
| 248 | 270 | } |
|---|
| 249 | 271 | device_initcall(pt_dump_init); |
|---|