@@ -175,8 +175,7 @@ struct pg_level {
};
static struct pg_level pg_level[] = {
- {
- }, { /* pgd */
+ { /* pgd */
.name = "PGD",
.bits = pte_bits,
.num = ARRAY_SIZE(pte_bits),
@@ -256,7 +255,7 @@ static void note_page(struct ptdump_stat
if (level >= 0)
prot = val & pg_level[level].mask;
- if (!st->level) {
+ if (st->level == -1) {
st->level = level;
st->current_prot = prot;
st->start_address = addr;
@@ -350,6 +349,7 @@ void ptdump_check_wx(void)
{ 0, NULL},
{ -1, NULL},
},
+ .level = -1,
.check_wx = true,
.ptdump = {
.note_page = note_page,
@@ -176,7 +176,7 @@ static struct addr_marker address_marker
static void printk_prot(struct seq_file *m, pgprotval_t pr, int level, bool dmsg)
{
static const char * const level_name[] =
- { "cr3", "pgd", "p4d", "pud", "pmd", "pte" };
+ { "pgd", "p4d", "pud", "pmd", "pte" };
if (!(pr & _PAGE_PRESENT)) {
/* Not present */
@@ -200,12 +200,12 @@ static void printk_prot(struct seq_file
pt_dump_cont_printf(m, dmsg, " ");
/* 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 ");
else
pt_dump_cont_printf(m, dmsg, " ");
- if ((level == 5 && pr & _PAGE_PAT) ||
- ((level == 4 || level == 3) && pr & _PAGE_PAT_LARGE))
+ if ((level == 4 && pr & _PAGE_PAT) ||
+ ((level == 3 || level == 2) && pr & _PAGE_PAT_LARGE))
pt_dump_cont_printf(m, dmsg, "PAT ");
else
pt_dump_cont_printf(m, dmsg, " ");
@@ -267,15 +267,15 @@ static void note_page(struct ptdump_stat
new_prot = val & PTE_FLAGS_MASK;
- if (level > 1) {
- new_eff = effective_prot(st->prot_levels[level - 2],
+ if (level > 0) {
+ new_eff = effective_prot(st->prot_levels[level - 1],
new_prot);
} else {
new_eff = new_prot;
}
- if (level > 0)
- st->prot_levels[level - 1] = new_eff;
+ if (level >= 0)
+ st->prot_levels[level] = new_eff;
/*
* If we have a "break" in the series, we need to flush the state that
@@ -285,7 +285,7 @@ static void note_page(struct ptdump_stat
cur = st->current_prot;
eff = st->effective_prot;
- if (!st->level) {
+ if (st->level == -1) {
/* First entry */
st->current_prot = new_prot;
st->effective_prot = new_eff;
@@ -376,6 +376,7 @@ static void ptdump_walk_pgd_level_core(s
.note_page = note_page,
.range = ptdump_ranges
},
+ .level = -1,
.to_dmesg = dmesg,
.check_wx = checkwx,
.seq = m
@@ -11,6 +11,7 @@ struct ptdump_range {
};
struct ptdump_state {
+ /* level is 0:PGD to 4:PTE, or -1 if unknown */
void (*note_page)(struct ptdump_state *st, unsigned long addr,
int level, unsigned long val);
const struct ptdump_range *range;
@@ -11,7 +11,7 @@ static int ptdump_pgd_entry(pgd_t *pgd,
pgd_t val = READ_ONCE(*pgd);
if (pgd_leaf(val))
- st->note_page(st, addr, 1, pgd_val(val));
+ st->note_page(st, addr, 0, pgd_val(val));
return 0;
}
@@ -23,7 +23,7 @@ static int ptdump_p4d_entry(p4d_t *p4d,
p4d_t val = READ_ONCE(*p4d);
if (p4d_leaf(val))
- st->note_page(st, addr, 2, p4d_val(val));
+ st->note_page(st, addr, 1, p4d_val(val));
return 0;
}
@@ -35,7 +35,7 @@ static int ptdump_pud_entry(pud_t *pud,
pud_t val = READ_ONCE(*pud);
if (pud_leaf(val))
- st->note_page(st, addr, 3, pud_val(val));
+ st->note_page(st, addr, 2, pud_val(val));
return 0;
}
@@ -47,7 +47,7 @@ static int ptdump_pmd_entry(pmd_t *pmd,
pmd_t val = READ_ONCE(*pmd);
if (pmd_leaf(val))
- st->note_page(st, addr, 4, pmd_val(val));
+ st->note_page(st, addr, 3, pmd_val(val));
return 0;
}
@@ -57,7 +57,7 @@ static int ptdump_pte_entry(pte_t *pte,
{
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;
}
@@ -75,7 +75,7 @@ static inline int note_kasan_page_table(
{
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]));
return 1;
}
@@ -115,7 +115,7 @@ static int ptdump_hole(unsigned long add
{
struct ptdump_state *st = walk->private;
- st->note_page(st, addr, depth + 1, 0);
+ st->note_page(st, addr, depth, 0);
return 0;
}
@@ -147,5 +147,5 @@ void ptdump_walk_pgd(struct ptdump_state
up_read(&mm->mmap_sem);
/* Flush out the last page */
- st->note_page(st, 0, 0, 0);
+ st->note_page(st, 0, -1, 0);
}