Commit f8f0d0b6 authored by Steven Price's avatar Steven Price Committed by Linus Torvalds

mm: ptdump: reduce level numbers by 1 in note_page()

Rather than having to increment the 'depth' number by 1 in ptdump_hole(),
let's change the meaning of 'level' in note_page() since that makes the
code simplier.

Note that for x86, the level numbers were previously increased by 1 in
commit 45dcd209 ("x86/mm/dump_pagetables: Fix printout of p4d level")
and the comment "Bit 7 has a different meaning" was not updated, so this
change also makes the code match the comment again.

Link: http://lkml.kernel.org/r/20191218162402.45610-24-steven.price@arm.comSigned-off-by: default avatarSteven Price <steven.price@arm.com>
Reviewed-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Alexandre Ghiti <alex@ghiti.fr>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Hogan <jhogan@kernel.org>
Cc: James Morse <james.morse@arm.com>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: "Liang, Kan" <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Paul Burton <paul.burton@mips.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vineet Gupta <vgupta@synopsys.com>
Cc: Will Deacon <will@kernel.org>
Cc: Zong Li <zong.li@sifive.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 9c7869c7
...@@ -176,8 +176,7 @@ struct pg_level { ...@@ -176,8 +176,7 @@ struct pg_level {
}; };
static struct pg_level pg_level[] = { static struct pg_level pg_level[] = {
{ { /* pgd */
}, { /* pgd */
.name = "PGD", .name = "PGD",
.bits = pte_bits, .bits = pte_bits,
.num = ARRAY_SIZE(pte_bits), .num = ARRAY_SIZE(pte_bits),
...@@ -257,7 +256,7 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, ...@@ -257,7 +256,7 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level,
if (level >= 0) if (level >= 0)
prot = val & pg_level[level].mask; prot = val & pg_level[level].mask;
if (!st->level) { if (st->level == -1) {
st->level = level; st->level = level;
st->current_prot = prot; st->current_prot = prot;
st->start_address = addr; st->start_address = addr;
...@@ -351,6 +350,7 @@ void ptdump_check_wx(void) ...@@ -351,6 +350,7 @@ void ptdump_check_wx(void)
{ 0, NULL}, { 0, NULL},
{ -1, NULL}, { -1, NULL},
}, },
.level = -1,
.check_wx = true, .check_wx = true,
.ptdump = { .ptdump = {
.note_page = note_page, .note_page = note_page,
......
...@@ -180,7 +180,7 @@ static struct addr_marker address_markers[] = { ...@@ -180,7 +180,7 @@ static struct addr_marker address_markers[] = {
static void printk_prot(struct seq_file *m, pgprotval_t pr, int level, bool dmsg) static void printk_prot(struct seq_file *m, pgprotval_t pr, int level, bool dmsg)
{ {
static const char * const level_name[] = static const char * const level_name[] =
{ "cr3", "pgd", "p4d", "pud", "pmd", "pte" }; { "pgd", "p4d", "pud", "pmd", "pte" };
if (!(pr & _PAGE_PRESENT)) { if (!(pr & _PAGE_PRESENT)) {
/* Not present */ /* Not present */
...@@ -204,12 +204,12 @@ static void printk_prot(struct seq_file *m, pgprotval_t pr, int level, bool dmsg ...@@ -204,12 +204,12 @@ static void printk_prot(struct seq_file *m, pgprotval_t pr, int level, bool dmsg
pt_dump_cont_printf(m, dmsg, " "); pt_dump_cont_printf(m, dmsg, " ");
/* Bit 7 has a different meaning on level 3 vs 4 */ /* Bit 7 has a different meaning on level 3 vs 4 */
if (level <= 4 && pr & _PAGE_PSE) if (level <= 3 && pr & _PAGE_PSE)
pt_dump_cont_printf(m, dmsg, "PSE "); pt_dump_cont_printf(m, dmsg, "PSE ");
else else
pt_dump_cont_printf(m, dmsg, " "); pt_dump_cont_printf(m, dmsg, " ");
if ((level == 5 && pr & _PAGE_PAT) || if ((level == 4 && pr & _PAGE_PAT) ||
((level == 4 || level == 3) && pr & _PAGE_PAT_LARGE)) ((level == 3 || level == 2) && pr & _PAGE_PAT_LARGE))
pt_dump_cont_printf(m, dmsg, "PAT "); pt_dump_cont_printf(m, dmsg, "PAT ");
else else
pt_dump_cont_printf(m, dmsg, " "); pt_dump_cont_printf(m, dmsg, " ");
...@@ -271,15 +271,15 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, ...@@ -271,15 +271,15 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level,
new_prot = val & PTE_FLAGS_MASK; new_prot = val & PTE_FLAGS_MASK;
if (level > 1) { if (level > 0) {
new_eff = effective_prot(st->prot_levels[level - 2], new_eff = effective_prot(st->prot_levels[level - 1],
new_prot); new_prot);
} else { } else {
new_eff = new_prot; new_eff = new_prot;
} }
if (level > 0) if (level >= 0)
st->prot_levels[level - 1] = new_eff; st->prot_levels[level] = new_eff;
/* /*
* If we have a "break" in the series, we need to flush the state that * If we have a "break" in the series, we need to flush the state that
...@@ -289,7 +289,7 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, ...@@ -289,7 +289,7 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level,
cur = st->current_prot; cur = st->current_prot;
eff = st->effective_prot; eff = st->effective_prot;
if (!st->level) { if (st->level == -1) {
/* First entry */ /* First entry */
st->current_prot = new_prot; st->current_prot = new_prot;
st->effective_prot = new_eff; st->effective_prot = new_eff;
...@@ -380,6 +380,7 @@ static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd, ...@@ -380,6 +380,7 @@ static void ptdump_walk_pgd_level_core(struct seq_file *m, pgd_t *pgd,
.note_page = note_page, .note_page = note_page,
.range = ptdump_ranges .range = ptdump_ranges
}, },
.level = -1,
.to_dmesg = dmesg, .to_dmesg = dmesg,
.check_wx = checkwx, .check_wx = checkwx,
.seq = m .seq = m
......
...@@ -11,6 +11,7 @@ struct ptdump_range { ...@@ -11,6 +11,7 @@ struct ptdump_range {
}; };
struct ptdump_state { struct ptdump_state {
/* level is 0:PGD to 4:PTE, or -1 if unknown */
void (*note_page)(struct ptdump_state *st, unsigned long addr, void (*note_page)(struct ptdump_state *st, unsigned long addr,
int level, unsigned long val); int level, unsigned long val);
const struct ptdump_range *range; const struct ptdump_range *range;
......
...@@ -17,7 +17,7 @@ static inline int note_kasan_page_table(struct mm_walk *walk, ...@@ -17,7 +17,7 @@ static inline int note_kasan_page_table(struct mm_walk *walk,
{ {
struct ptdump_state *st = walk->private; struct ptdump_state *st = walk->private;
st->note_page(st, addr, 5, pte_val(kasan_early_shadow_pte[0])); st->note_page(st, addr, 4, pte_val(kasan_early_shadow_pte[0]));
walk->action = ACTION_CONTINUE; walk->action = ACTION_CONTINUE;
...@@ -37,7 +37,7 @@ static int ptdump_pgd_entry(pgd_t *pgd, unsigned long addr, ...@@ -37,7 +37,7 @@ static int ptdump_pgd_entry(pgd_t *pgd, unsigned long addr,
#endif #endif
if (pgd_leaf(val)) if (pgd_leaf(val))
st->note_page(st, addr, 1, pgd_val(val)); st->note_page(st, addr, 0, pgd_val(val));
return 0; return 0;
} }
...@@ -54,7 +54,7 @@ static int ptdump_p4d_entry(p4d_t *p4d, unsigned long addr, ...@@ -54,7 +54,7 @@ static int ptdump_p4d_entry(p4d_t *p4d, unsigned long addr,
#endif #endif
if (p4d_leaf(val)) if (p4d_leaf(val))
st->note_page(st, addr, 2, p4d_val(val)); st->note_page(st, addr, 1, p4d_val(val));
return 0; return 0;
} }
...@@ -71,7 +71,7 @@ static int ptdump_pud_entry(pud_t *pud, unsigned long addr, ...@@ -71,7 +71,7 @@ static int ptdump_pud_entry(pud_t *pud, unsigned long addr,
#endif #endif
if (pud_leaf(val)) if (pud_leaf(val))
st->note_page(st, addr, 3, pud_val(val)); st->note_page(st, addr, 2, pud_val(val));
return 0; return 0;
} }
...@@ -88,7 +88,7 @@ static int ptdump_pmd_entry(pmd_t *pmd, unsigned long addr, ...@@ -88,7 +88,7 @@ static int ptdump_pmd_entry(pmd_t *pmd, unsigned long addr,
#endif #endif
if (pmd_leaf(val)) if (pmd_leaf(val))
st->note_page(st, addr, 4, pmd_val(val)); st->note_page(st, addr, 3, pmd_val(val));
return 0; return 0;
} }
...@@ -98,7 +98,7 @@ static int ptdump_pte_entry(pte_t *pte, unsigned long addr, ...@@ -98,7 +98,7 @@ static int ptdump_pte_entry(pte_t *pte, unsigned long addr,
{ {
struct ptdump_state *st = walk->private; struct ptdump_state *st = walk->private;
st->note_page(st, addr, 5, pte_val(READ_ONCE(*pte))); st->note_page(st, addr, 4, pte_val(READ_ONCE(*pte)));
return 0; return 0;
} }
...@@ -108,7 +108,7 @@ static int ptdump_hole(unsigned long addr, unsigned long next, ...@@ -108,7 +108,7 @@ static int ptdump_hole(unsigned long addr, unsigned long next,
{ {
struct ptdump_state *st = walk->private; struct ptdump_state *st = walk->private;
st->note_page(st, addr, depth + 1, 0); st->note_page(st, addr, depth, 0);
return 0; return 0;
} }
...@@ -135,5 +135,5 @@ void ptdump_walk_pgd(struct ptdump_state *st, struct mm_struct *mm) ...@@ -135,5 +135,5 @@ void ptdump_walk_pgd(struct ptdump_state *st, struct mm_struct *mm)
up_read(&mm->mmap_sem); up_read(&mm->mmap_sem);
/* Flush out the last page */ /* Flush out the last page */
st->note_page(st, 0, 0, 0); st->note_page(st, 0, -1, 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