[RFC PATCH 10/34] x86: mm: carve out the generic compile-time folded pgtable case in effective_prot()
Yeoreum Yun
yeoreum.yun at arm.com
Thu Jul 16 00:49:47 PDT 2026
On Wed, Jul 15, 2026 at 12:34:29PM +0200, Geert Uytterhoeven wrote:
> Hi Yeoreum,
>
> On Wed, 15 Jul 2026 at 11:42, Yeoreum Yun <yeoreum.yun at arm.com> wrote:
> > > On Tue, 14 Jul 2026 at 18:51, Yeoreum Yun <yeoreum.yun at arm.com> wrote:
> > > > --- a/mm/ptdump.c
> > > > +++ b/mm/ptdump.c
> > > > @@ -190,6 +190,23 @@ void ptdump_walk_pgd(struct ptdump_state *st, struct mm_struct *mm, pgd_t *pgd)
> > > > st->note_page_flush(st);
> > > > }
> > > >
> > > > +bool pdtump_pt_level_first(struct mm_struct *mm, int level)
> > > > +{
> > > > + if (!mm || level > CONFIG_PGTABLE_LEVELS)
> > > > + return false;
> > > > +
> > > > + if (mm_pmd_folded(mm) && level == 3)
> > > > + return true;
> > > > + if (mm_pud_folded(mm) && level == 2)
> > > > + return true;
> > > > + if (mm_p4d_folded(mm) && level == 1)
> > > > + return true;
> > >
> > > Is this order (... && level == ...) the optimal order?
> > > On arm64, mm_pud_folded() and mm_p4d_folded() perform several checks.
> > >
> > > > + if (level == 0)
> > > > + return true;
> > > > +
> > > > + return false;
> > > > +}
> >
> > It is. since the purpose of ptdump_pt_level_first is designed to be used
> > in the *callback* of pXd_entry(). IOW, if we check level 0 first,
> > it always returns wrong return in folded case.
>
> I meant the order inside the if () conditions.
> E.g.
> "if (mm_pud_folded(mm) && level == 2)" does the expensive check first.
> "if (level == 2 && mm_pud_folded(mm))" does the cheap check first.
Ah. Yeap that would be better. Thanks!
--
Sincerely,
Yeoreum Yun
More information about the kvm-riscv
mailing list