Commit b00ff6d8 authored by Christophe Leroy's avatar Christophe Leroy Committed by Michael Ellerman

powerpc/ptdump: Properly handle non standard page size

In order to properly display information regardless of the page size,
it is necessary to take into account real page size.

Fixes: cabe8138 ("powerpc: dump as a single line areas mapping a single physical page.")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/a53b2a0ffd042a8d85464bf90d55bc5b970e00a1.1589866984.git.christophe.leroy@csgroup.eu
parent 8961a2a5
...@@ -60,6 +60,7 @@ struct pg_state { ...@@ -60,6 +60,7 @@ struct pg_state {
unsigned long start_address; unsigned long start_address;
unsigned long start_pa; unsigned long start_pa;
unsigned long last_pa; unsigned long last_pa;
unsigned long page_size;
unsigned int level; unsigned int level;
u64 current_flags; u64 current_flags;
bool check_wx; bool check_wx;
...@@ -168,9 +169,9 @@ static void dump_addr(struct pg_state *st, unsigned long addr) ...@@ -168,9 +169,9 @@ static void dump_addr(struct pg_state *st, unsigned long addr)
#endif #endif
pt_dump_seq_printf(st->seq, REG "-" REG " ", st->start_address, addr - 1); pt_dump_seq_printf(st->seq, REG "-" REG " ", st->start_address, addr - 1);
if (st->start_pa == st->last_pa && st->start_address + PAGE_SIZE != addr) { if (st->start_pa == st->last_pa && st->start_address + st->page_size != addr) {
pt_dump_seq_printf(st->seq, "[" REG "]", st->start_pa); pt_dump_seq_printf(st->seq, "[" REG "]", st->start_pa);
delta = PAGE_SIZE >> 10; delta = st->page_size >> 10;
} else { } else {
pt_dump_seq_printf(st->seq, " " REG " ", st->start_pa); pt_dump_seq_printf(st->seq, " " REG " ", st->start_pa);
delta = (addr - st->start_address) >> 10; delta = (addr - st->start_address) >> 10;
...@@ -195,7 +196,7 @@ static void note_prot_wx(struct pg_state *st, unsigned long addr) ...@@ -195,7 +196,7 @@ static void note_prot_wx(struct pg_state *st, unsigned long addr)
} }
static void note_page(struct pg_state *st, unsigned long addr, static void note_page(struct pg_state *st, unsigned long addr,
unsigned int level, u64 val) unsigned int level, u64 val, unsigned long page_size)
{ {
u64 flag = val & pg_level[level].mask; u64 flag = val & pg_level[level].mask;
u64 pa = val & PTE_RPN_MASK; u64 pa = val & PTE_RPN_MASK;
...@@ -207,6 +208,7 @@ static void note_page(struct pg_state *st, unsigned long addr, ...@@ -207,6 +208,7 @@ static void note_page(struct pg_state *st, unsigned long addr,
st->start_address = addr; st->start_address = addr;
st->start_pa = pa; st->start_pa = pa;
st->last_pa = pa; st->last_pa = pa;
st->page_size = page_size;
pt_dump_seq_printf(st->seq, "---[ %s ]---\n", st->marker->name); pt_dump_seq_printf(st->seq, "---[ %s ]---\n", st->marker->name);
/* /*
* Dump the section of virtual memory when: * Dump the section of virtual memory when:
...@@ -218,7 +220,7 @@ static void note_page(struct pg_state *st, unsigned long addr, ...@@ -218,7 +220,7 @@ static void note_page(struct pg_state *st, unsigned long addr,
*/ */
} else if (flag != st->current_flags || level != st->level || } else if (flag != st->current_flags || level != st->level ||
addr >= st->marker[1].start_address || addr >= st->marker[1].start_address ||
(pa != st->last_pa + PAGE_SIZE && (pa != st->last_pa + st->page_size &&
(pa != st->start_pa || st->start_pa != st->last_pa))) { (pa != st->start_pa || st->start_pa != st->last_pa))) {
/* Check the PTE flags */ /* Check the PTE flags */
...@@ -246,6 +248,7 @@ static void note_page(struct pg_state *st, unsigned long addr, ...@@ -246,6 +248,7 @@ static void note_page(struct pg_state *st, unsigned long addr,
st->start_address = addr; st->start_address = addr;
st->start_pa = pa; st->start_pa = pa;
st->last_pa = pa; st->last_pa = pa;
st->page_size = page_size;
st->current_flags = flag; st->current_flags = flag;
st->level = level; st->level = level;
} else { } else {
...@@ -261,7 +264,7 @@ static void walk_pte(struct pg_state *st, pmd_t *pmd, unsigned long start) ...@@ -261,7 +264,7 @@ static void walk_pte(struct pg_state *st, pmd_t *pmd, unsigned long start)
for (i = 0; i < PTRS_PER_PTE; i++, pte++) { for (i = 0; i < PTRS_PER_PTE; i++, pte++) {
addr = start + i * PAGE_SIZE; addr = start + i * PAGE_SIZE;
note_page(st, addr, 4, pte_val(*pte)); note_page(st, addr, 4, pte_val(*pte), PAGE_SIZE);
} }
} }
...@@ -278,7 +281,7 @@ static void walk_pmd(struct pg_state *st, pud_t *pud, unsigned long start) ...@@ -278,7 +281,7 @@ static void walk_pmd(struct pg_state *st, pud_t *pud, unsigned long start)
/* pmd exists */ /* pmd exists */
walk_pte(st, pmd, addr); walk_pte(st, pmd, addr);
else else
note_page(st, addr, 3, pmd_val(*pmd)); note_page(st, addr, 3, pmd_val(*pmd), PMD_SIZE);
} }
} }
...@@ -294,7 +297,7 @@ static void walk_pud(struct pg_state *st, pgd_t *pgd, unsigned long start) ...@@ -294,7 +297,7 @@ static void walk_pud(struct pg_state *st, pgd_t *pgd, unsigned long start)
/* pud exists */ /* pud exists */
walk_pmd(st, pud, addr); walk_pmd(st, pud, addr);
else else
note_page(st, addr, 2, pud_val(*pud)); note_page(st, addr, 2, pud_val(*pud), PUD_SIZE);
} }
} }
...@@ -313,7 +316,7 @@ static void walk_pagetables(struct pg_state *st) ...@@ -313,7 +316,7 @@ static void walk_pagetables(struct pg_state *st)
/* pgd exists */ /* pgd exists */
walk_pud(st, pgd, addr); walk_pud(st, pgd, addr);
else else
note_page(st, addr, 1, pgd_val(*pgd)); note_page(st, addr, 1, pgd_val(*pgd), PGDIR_SIZE);
} }
} }
...@@ -368,7 +371,7 @@ static int ptdump_show(struct seq_file *m, void *v) ...@@ -368,7 +371,7 @@ static int ptdump_show(struct seq_file *m, void *v)
/* Traverse kernel page tables */ /* Traverse kernel page tables */
walk_pagetables(&st); walk_pagetables(&st);
note_page(&st, 0, 0, 0); note_page(&st, 0, 0, 0, 0);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment