Re: [PATCH] x86/mm: fix lookup_address() to handle physical memory holes in direct mapping

From: Edgecombe, Rick P
Date: Fri Jun 28 2024 - 17:33:39 EST


On Fri, 2024-06-28 at 16:22 -0500, Kalra, Ashish wrote:
> > > @@ -717,7 +718,11 @@ pte_t *lookup_address_in_pgd_attr(pgd_t *pgd,
> > > unsigned
> > > long address,
> > >         *nx |= pmd_flags(*pmd) & _PAGE_NX;
> > >         *rw &= pmd_flags(*pmd) & _PAGE_RW;
> > >  
> > > -       return pte_offset_kernel(pmd, address);
> > > +       pte = pte_offset_kernel(pmd, address);
> > > +       if (pte_none(*pte))
> > > +               return NULL;
> > > +
> > > +       return pte;
> > The other levels check for pXX_none() before adjusting *level. Not sure what
> > the
> > effect would be, but I think it should be the same behavior for all.
>
> If we are returning NULL, why should adjusting *level matter.

Well, I think symmetry is enough of a reason, but actually it should be ok.

I was looking at this diff compared to my working tree, but this tip commit
(which is about that scenario) makes it set *level before checking none for all
of them:
https://lore.kernel.org/lkml/171871930159.10875.16081839197437299007.tip-bot2@tip-bot2/

So sorry, nevermind.