From: "David Hildenbrand (Arm)" <[email protected]> We want to change how pXdp_get() works with generic compile-time folded page tables. To prepare for that, rework effective_prot() to ignore any folded page tables entries, as it will unconditionally get called by ptdump core with pXd_val(pXdp_get()), and we really should be ignoring that value for folded entries.
For this, identify the first real page-table level and update effective_prot only when the current entry is not folded. There should be no functional change. Signed-off-by: Yeoreum Yun <[email protected]> --- arch/x86/mm/dump_pagetables.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c index 2afa7a23340e9..e32848c7f26d4 100644 --- a/arch/x86/mm/dump_pagetables.c +++ b/arch/x86/mm/dump_pagetables.c @@ -27,6 +27,7 @@ */ struct pg_state { struct ptdump_state ptdump; + struct mm_struct *mm; int level; pgprotval_t current_prot; pgprotval_t effective_prot; @@ -253,8 +254,22 @@ static void effective_prot(struct ptdump_state *pt_st, int level, u64 val) struct pg_state *st = container_of(pt_st, struct pg_state, ptdump); pgprotval_t prot = val & PTE_FLAGS_MASK; pgprotval_t effective; + bool first_level = false; - if (level > 0) { + /* Ignore folded levels ... */ + if (((level == 0) && mm_p4d_folded(st->mm)) || + ((level == 1) && mm_pud_folded(st->mm)) || + ((level == 2) && mm_pmd_folded(st->mm))) + return; + + /* ... and make the actual first level remember the protection. */ + if (((level == 0)) || + ((level == 1) && mm_p4d_folded(st->mm)) || + ((level == 2) && mm_pud_folded(st->mm)) || + ((level == 3) && mm_pmd_folded(st->mm))) + first_level = true; + + if (!first_level) { pgprotval_t higher_prot = st->prot_levels[level - 1]; effective = (higher_prot & prot & (_PAGE_USER | _PAGE_RW)) | @@ -449,6 +464,7 @@ bool ptdump_walk_pgd_level_core(struct seq_file *m, .effective_prot_pgd = effective_prot_pgd, .range = ptdump_ranges }, + .mm = mm, .level = -1, .to_dmesg = dmesg, .check_wx = checkwx, -- LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}
