// SPDX-License-Identifier: GPL-2.0-only /* * Copyright 2016, Rashmica Gupta, IBM Corp. * * This traverses the kernel virtual memory and dumps the pages that are in * the hash pagetable, along with their flags to * /sys/kernel/debug/kernel_hash_pagetable. * * If radix is enabled then there is no hash page table and so no debugfs file * is generated.
*/ #include <linux/debugfs.h> #include <linux/fs.h> #include <linux/io.h> #include <linux/mm.h> #include <linux/sched.h> #include <linux/seq_file.h> #include <linux/const.h> #include <asm/page.h> #include <asm/plpar_wrappers.h> #include <linux/memblock.h> #include <asm/firmware.h> #include <asm/pgalloc.h>
for (i = 0; i < num; i++, flag++) { constchar *s = NULL;
u64 val;
/* flag not defined so don't check it */ if (flag->mask == 0) continue; /* Some 'flags' are actually values */ if (flag->is_val) {
val = pte & flag->val; if (flag->shift)
val = val >> flag->shift;
seq_printf(st->seq, " %s:%llx", flag->set, val);
} else { if ((pte & flag->mask) == flag->val)
s = flag->set; else
s = flag->clear; if (s)
seq_printf(st->seq, " %s", s);
}
}
}
staticvoid dump_hpte_info(struct pg_state *st, unsignedlong ea, u64 v, u64 r, unsignedlong rpn, int bps, int aps, unsignedlong lp)
{ int aps_index;
/* to check in the secondary hash table, we invert the hash */ if (!primary)
hash = ~hash;
hpte_group = (hash & htab_hash_mask) * HPTES_PER_GROUP; for (i = 0; i < HPTES_PER_GROUP; i++) {
hptep = htab_address + hpte_group;
hpte_v = be64_to_cpu(hptep->v);
/* to check in the secondary hash table, we invert the hash */ if (!primary)
hash = ~hash;
hpte_group = (hash & htab_hash_mask) * HPTES_PER_GROUP; /* see if we can find an entry in the hpte with this hash */ for (i = 0; i < HPTES_PER_GROUP; i += 4, hpte_group += 4) {
lpar_rc = plpar_pte_read_4(0, hpte_group, (void *)ptes);
/*. * The LP field has 8 bits. Depending on the actual page size, some of * these bits are concatenated with the APRN to get the RPN. The rest * of the bits in the LP field is the LP value and is an encoding for * the base page size and the actual page size. * * - find the mmu entry for our base page size * - go through all page encodings and use the associated mask to * find an encoding that matches our encoding in the LP field.
*/
arpn = (r & HPTE_R_RPN) >> HPTE_R_RPN_SHIFT;
lp = arpn & 0xff;
/* Look in secondary table */ if (slot == -1)
slot = base_hpte_find(ea, psize, false, &v, &r);
/* No entry found */ if (slot == -1) return -1;
/* * We found an entry in the hash page table: * - check that this has the same base page * - find the actual page size * - find the RPN
*/
base_psize = mmu_psize_to_shift(psize);
if ((v & HPTE_V_LARGE) == HPTE_V_LARGE) {
decode_r(psize, r, &rpn, &actual_psize, &lp_bits);
} else { /* 4K actual page size */
actual_psize = 12;
rpn = (r & HPTE_R_RPN) >> HPTE_R_RPN_SHIFT; /* In this case there are no LP bits */
lp_bits = -1;
} /* * We didn't find a matching encoding, so the PTE we found isn't for * this address.
*/ if (actual_psize == -1) return -1;
/* check for hashpte */
status = hpte_find(st, addr, psize);
if (((pteval & H_PAGE_HASHPTE) != H_PAGE_HASHPTE)
&& (status != -1)) { /* found a hpte that is not in the linux page tables */
seq_printf(st->seq, "page probably bolted before linux" " pagetables were set: addr:%lx, pteval:%lx\n",
addr, pteval);
}
}
}
/* * Traverse the linux pagetable structure and dump pages that are in * the hash pagetable.
*/ for (i = 0; i < PTRS_PER_PGD; i++, pgd++) {
addr = KERN_VIRT_START + i * PGDIR_SIZE; if (!pgd_none(*pgd)) /* pgd exists */
walk_p4d(st, pgd, addr);
}
}
/* * Traverse the linear mapping section of virtual memory and dump pages * that are in the hash pagetable.
*/ unsignedlong psize = 1 << mmu_psize_defs[mmu_linear_psize].shift;
if (!IS_ENABLED(CONFIG_SPARSEMEM_VMEMMAP)) return; /* * Traverse the vmemmaped memory and dump pages that are in the hash * pagetable.
*/ while (ptr) {
hpte_find(st, ptr->virt_addr, mmu_vmemmap_psize);
ptr = ptr->list;
}
seq_puts(st->seq, "---[ vmemmap end ]---\n");
}
staticint ptdump_show(struct seq_file *m, void *v)
{ struct pg_state st = {
.seq = m,
.start_address = PAGE_OFFSET,
.marker = address_markers,
}; /* * Traverse the 0xc, 0xd and 0xf areas of the kernel virtual memory and * dump pages that are in the hash pagetable.
*/
walk_linearmapping(&st);
walk_pagetables(&st);
walk_vmemmap(&st); return 0;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.