^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) * Copyright 2016, Rashmica Gupta, IBM Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * This traverses the kernel pagetables and dumps the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * information about the used sections of memory to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * /sys/kernel/debug/kernel_pagetables.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Derived from the arm64 implementation:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Copyright (c) 2014, The Linux Foundation, Laura Abbott.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * (C) Copyright 2008 Intel Corporation, Arjan van de Ven.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/hugetlb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/highmem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <asm/fixmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/const.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <asm/hugetlb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <mm/mmu_decl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include "ptdump.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * To visualise what is happening,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * - PTRS_PER_P** = how many entries there are in the corresponding P**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * - P**_SHIFT = how many bits of the address we use to index into the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * corresponding P**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * - P**_SIZE is how much memory we can access through the table - not the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * size of the table itself.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * P**={PGD, PUD, PMD, PTE}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * Each entry of the PGD points to a PUD. Each entry of a PUD points to a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * PMD. Each entry of a PMD points to a PTE. And every PTE entry points to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * a page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * In the case where there are only 3 levels, the PUD is folded into the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * PGD: every PUD has only one entry which points to the PMD.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * The page dumper groups page table entries of the same type into a single
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * description. It uses pg_state to track the range information while
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * iterating over the PTE entries. When the continuity is broken it then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * dumps out a description of the range - ie PTEs that are virtually contiguous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * with the same PTE flags are chunked together. This is to make it clear how
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * different areas of the kernel virtual memory are used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) struct pg_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct seq_file *seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) const struct addr_marker *marker;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) unsigned long start_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) unsigned long start_pa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) unsigned long last_pa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) unsigned long page_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) unsigned int level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) u64 current_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) bool check_wx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) unsigned long wx_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct addr_marker {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) unsigned long start_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static struct addr_marker address_markers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) { 0, "Start of kernel VM" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #ifdef MODULES_VADDR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) { 0, "modules start" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) { 0, "modules end" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) { 0, "vmalloc() Area" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) { 0, "vmalloc() End" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #ifdef CONFIG_PPC64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) { 0, "isa I/O start" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) { 0, "isa I/O end" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) { 0, "phb I/O start" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) { 0, "phb I/O end" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) { 0, "I/O remap start" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) { 0, "I/O remap end" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) { 0, "vmemmap start" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) { 0, "Early I/O remap start" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) { 0, "Early I/O remap end" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #ifdef CONFIG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) { 0, "Highmem PTEs start" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) { 0, "Highmem PTEs end" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) { 0, "Fixmap start" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) { 0, "Fixmap end" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #ifdef CONFIG_KASAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) { 0, "kasan shadow mem start" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) { 0, "kasan shadow mem end" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) { -1, NULL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #define pt_dump_seq_printf(m, fmt, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) if (m) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) seq_printf(m, fmt, ##args); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #define pt_dump_seq_putc(m, c) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) if (m) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) seq_putc(m, c); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) void pt_dump_size(struct seq_file *m, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static const char units[] = "KMGTPE";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) const char *unit = units;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /* Work out what appropriate unit to use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) while (!(size & 1023) && unit[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) size >>= 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) unit++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) pt_dump_seq_printf(m, "%9lu%c ", size, *unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static void dump_flag_info(struct pg_state *st, const struct flag_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) *flag, u64 pte, int num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) for (i = 0; i < num; i++, flag++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) const char *s = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) u64 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) /* flag not defined so don't check it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (flag->mask == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /* Some 'flags' are actually values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (flag->is_val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) val = pte & flag->val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (flag->shift)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) val = val >> flag->shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) pt_dump_seq_printf(st->seq, " %s:%llx", flag->set, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if ((pte & flag->mask) == flag->val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) s = flag->set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) s = flag->clear;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) pt_dump_seq_printf(st->seq, " %s", s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) st->current_flags &= ~flag->mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (st->current_flags != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) pt_dump_seq_printf(st->seq, " unknown flags:%llx", st->current_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static void dump_addr(struct pg_state *st, unsigned long addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) unsigned long delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) #ifdef CONFIG_PPC64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) #define REG "0x%016lx"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) #define REG "0x%08lx"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) pt_dump_seq_printf(st->seq, REG "-" REG " ", st->start_address, addr - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (st->start_pa == st->last_pa && st->start_address + st->page_size != addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) pt_dump_seq_printf(st->seq, "[" REG "]", st->start_pa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) delta = st->page_size >> 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) pt_dump_seq_printf(st->seq, " " REG " ", st->start_pa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) delta = (addr - st->start_address) >> 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) pt_dump_size(st->seq, delta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static void note_prot_wx(struct pg_state *st, unsigned long addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) pte_t pte = __pte(st->current_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (!IS_ENABLED(CONFIG_PPC_DEBUG_WX) || !st->check_wx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (!pte_write(pte) || !pte_exec(pte))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) WARN_ONCE(1, "powerpc/mm: Found insecure W+X mapping at address %p/%pS\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) (void *)st->start_address, (void *)st->start_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) st->wx_pages += (addr - st->start_address) / PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) static void note_page_update_state(struct pg_state *st, unsigned long addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) unsigned int level, u64 val, unsigned long page_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) u64 flag = val & pg_level[level].mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) u64 pa = val & PTE_RPN_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) st->level = level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) st->current_flags = flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) st->start_address = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) st->start_pa = pa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) st->page_size = page_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) while (addr >= st->marker[1].start_address) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) st->marker++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) pt_dump_seq_printf(st->seq, "---[ %s ]---\n", st->marker->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) static void note_page(struct pg_state *st, unsigned long addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) unsigned int level, u64 val, unsigned long page_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) u64 flag = val & pg_level[level].mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) u64 pa = val & PTE_RPN_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) /* At first no level is set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (!st->level) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) pt_dump_seq_printf(st->seq, "---[ %s ]---\n", st->marker->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) note_page_update_state(st, addr, level, val, page_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) * Dump the section of virtual memory when:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * - the PTE flags from one entry to the next differs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) * - we change levels in the tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * - the address is in a different section of memory and is thus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * used for a different purpose, regardless of the flags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * - the pa of this page is not adjacent to the last inspected page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) } else if (flag != st->current_flags || level != st->level ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) addr >= st->marker[1].start_address ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) (pa != st->last_pa + st->page_size &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) (pa != st->start_pa || st->start_pa != st->last_pa))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) /* Check the PTE flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (st->current_flags) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) note_prot_wx(st, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) dump_addr(st, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) /* Dump all the flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) if (pg_level[st->level].flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) dump_flag_info(st, pg_level[st->level].flag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) st->current_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) pg_level[st->level].num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) pt_dump_seq_putc(st->seq, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) * Address indicates we have passed the end of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) * current section of virtual memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) note_page_update_state(st, addr, level, val, page_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) st->last_pa = pa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static void walk_pte(struct pg_state *st, pmd_t *pmd, unsigned long start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) pte_t *pte = pte_offset_kernel(pmd, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) unsigned long addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) for (i = 0; i < PTRS_PER_PTE; i++, pte++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) addr = start + i * PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) note_page(st, addr, 4, pte_val(*pte), PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) static void walk_hugepd(struct pg_state *st, hugepd_t *phpd, unsigned long start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) int pdshift, int level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) #ifdef CONFIG_ARCH_HAS_HUGEPD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) int shift = hugepd_shift(*phpd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) int ptrs_per_hpd = pdshift - shift > 0 ? 1 << (pdshift - shift) : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) if (start & ((1 << shift) - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) for (i = 0; i < ptrs_per_hpd; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) unsigned long addr = start + (i << shift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) pte_t *pte = hugepte_offset(*phpd, addr, pdshift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) note_page(st, addr, level + 1, pte_val(*pte), 1 << shift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) static void walk_pmd(struct pg_state *st, pud_t *pud, unsigned long start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) pmd_t *pmd = pmd_offset(pud, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) unsigned long addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) for (i = 0; i < PTRS_PER_PMD; i++, pmd++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) addr = start + i * PMD_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) if (!pmd_none(*pmd) && !pmd_is_leaf(*pmd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) /* pmd exists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) walk_pte(st, pmd, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) note_page(st, addr, 3, pmd_val(*pmd), PMD_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static void walk_pud(struct pg_state *st, p4d_t *p4d, unsigned long start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) pud_t *pud = pud_offset(p4d, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) unsigned long addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) for (i = 0; i < PTRS_PER_PUD; i++, pud++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) addr = start + i * PUD_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) if (!pud_none(*pud) && !pud_is_leaf(*pud))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) /* pud exists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) walk_pmd(st, pud, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) note_page(st, addr, 2, pud_val(*pud), PUD_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) static void walk_pagetables(struct pg_state *st)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) unsigned long addr = st->start_address & PGDIR_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) pgd_t *pgd = pgd_offset_k(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) * Traverse the linux pagetable structure and dump pages that are in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) * the hash pagetable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) for (i = pgd_index(addr); i < PTRS_PER_PGD; i++, pgd++, addr += PGDIR_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) p4d_t *p4d = p4d_offset(pgd, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) if (p4d_none(*p4d) || p4d_is_leaf(*p4d))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) note_page(st, addr, 1, p4d_val(*p4d), PGDIR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) else if (is_hugepd(__hugepd(p4d_val(*p4d))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) walk_hugepd(st, (hugepd_t *)p4d, addr, PGDIR_SHIFT, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) /* p4d exists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) walk_pud(st, p4d, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) static void populate_markers(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) #ifdef CONFIG_PPC64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) address_markers[i++].start_address = PAGE_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) address_markers[i++].start_address = TASK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) #ifdef MODULES_VADDR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) address_markers[i++].start_address = MODULES_VADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) address_markers[i++].start_address = MODULES_END;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) address_markers[i++].start_address = VMALLOC_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) address_markers[i++].start_address = VMALLOC_END;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) #ifdef CONFIG_PPC64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) address_markers[i++].start_address = ISA_IO_BASE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) address_markers[i++].start_address = ISA_IO_END;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) address_markers[i++].start_address = PHB_IO_BASE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) address_markers[i++].start_address = PHB_IO_END;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) address_markers[i++].start_address = IOREMAP_BASE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) address_markers[i++].start_address = IOREMAP_END;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) /* What is the ifdef about? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) #ifdef CONFIG_PPC_BOOK3S_64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) address_markers[i++].start_address = H_VMEMMAP_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) address_markers[i++].start_address = VMEMMAP_BASE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) #else /* !CONFIG_PPC64 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) address_markers[i++].start_address = ioremap_bot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) address_markers[i++].start_address = IOREMAP_TOP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) #ifdef CONFIG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) address_markers[i++].start_address = PKMAP_BASE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) address_markers[i++].start_address = PKMAP_ADDR(LAST_PKMAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) address_markers[i++].start_address = FIXADDR_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) address_markers[i++].start_address = FIXADDR_TOP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) #ifdef CONFIG_KASAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) address_markers[i++].start_address = KASAN_SHADOW_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) address_markers[i++].start_address = KASAN_SHADOW_END;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) #endif /* CONFIG_PPC64 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) static int ptdump_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) struct pg_state st = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) .seq = m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) .marker = address_markers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) .start_address = IS_ENABLED(CONFIG_PPC64) ? PAGE_OFFSET : TASK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) #ifdef CONFIG_PPC64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) if (!radix_enabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) st.start_address = KERN_VIRT_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) /* Traverse kernel page tables */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) walk_pagetables(&st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) note_page(&st, 0, 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) static int ptdump_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) return single_open(file, ptdump_show, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) static const struct file_operations ptdump_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) .open = ptdump_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) .read = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) .llseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) .release = single_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) static void build_pgtable_complete_mask(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) unsigned int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) for (i = 0; i < ARRAY_SIZE(pg_level); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) if (pg_level[i].flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) for (j = 0; j < pg_level[i].num; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) pg_level[i].mask |= pg_level[i].flag[j].mask;
^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) #ifdef CONFIG_PPC_DEBUG_WX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) void ptdump_check_wx(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) struct pg_state st = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) .seq = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) .marker = address_markers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) .check_wx = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) .start_address = IS_ENABLED(CONFIG_PPC64) ? PAGE_OFFSET : TASK_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) #ifdef CONFIG_PPC64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) if (!radix_enabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) st.start_address = KERN_VIRT_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) walk_pagetables(&st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) if (st.wx_pages)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) pr_warn("Checked W+X mappings: FAILED, %lu W+X pages found\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) st.wx_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) pr_info("Checked W+X mappings: passed, no W+X pages found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) static int ptdump_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) populate_markers();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) build_pgtable_complete_mask();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) debugfs_create_file("kernel_page_tables", 0400, NULL, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) &ptdump_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) device_initcall(ptdump_init);