Re: [PATCHv7 07/16] x86/mm: Return correct level from lookup_address() if pte is none

From: Kirill A. Shutemov
Date: Wed Feb 21 2024 - 09:16:55 EST


On Wed, Feb 21, 2024 at 10:37:29AM +0800, Baoquan He wrote:
> > diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
> > index 3612e3167147..425ff6e192e6 100644
> > --- a/arch/x86/mm/pat/set_memory.c
> > +++ b/arch/x86/mm/pat/set_memory.c
> > @@ -657,7 +657,8 @@ static inline pgprot_t verify_rwx(pgprot_t old, pgprot_t new, unsigned long star
> >
> > /*
> > * Lookup the page table entry for a virtual address in a specific pgd.
> > - * Return a pointer to the entry and the level of the mapping.
> > + * Return a pointer to the entry and the level of the mapping (or NULL if
> > + * the entry is none) and level of the entry.
> ^ this right parenthesis may need be moved to the end.
>
>
> =======
> * Return a pointer to the entry and the level of the mapping (or NULL if
> * the entry is none and level of the entry).
> =======

Emm.. I like my variant more. We return level regardless if the entry none
or not. I don't see a reason to repeat it twice.

> > */
> > pte_t *lookup_address_in_pgd(pgd_t *pgd, unsigned long address,
> > unsigned int *level)
> > @@ -704,9 +705,8 @@ pte_t *lookup_address_in_pgd(pgd_t *pgd, unsigned long address,
> > * Lookup the page table entry for a virtual address. Return a pointer
> > * to the entry and the level of the mapping.
> > *
> > - * Note: We return pud and pmd either when the entry is marked large
> > - * or when the present bit is not set. Otherwise we would return a
> > - * pointer to a nonexisting mapping.
> > + * Note: the function returns p4d, pud and pmd either when the entry is marked
> ~~~
> ^ s/and/or/

Fair enough.

--
Kiryl Shutsemau / Kirill A. Shutemov