Re: [PATCH 02/16] mm: introduce leaf entry type and use to simplify leaf entry logic

From: Lorenzo Stoakes

Date: Wed Nov 05 2025 - 14:53:41 EST


On Wed, Nov 05, 2025 at 02:25:34PM -0500, Gregory Price wrote:
> On Wed, Nov 05, 2025 at 07:06:11PM +0000, Matthew Wilcox wrote:
> > On Mon, Nov 03, 2025 at 12:31:43PM +0000, Lorenzo Stoakes wrote:
> > > The kernel maintains leaf page table entries which contain either:
> > >
> > > - Nothing ('none' entries)
> > > - Present entries (that is stuff the hardware can navigate without fault)
> > > - Everything else that will cause a fault which the kernel handles
> >
> > The problem is that we're already using 'pmd leaf entries' to mean "this
> > is a pointer to a PMD entry rather than a table of PTEs".
>
> Having not looked at the implications of this for leafent_t prototypes
> ...
> Can't this be solved by just adding a leafent type "Pointer" which
> implies there's exactly one leaf-ent type which won't cause faults?
>
> is_present() => (table_ptr || leafent_ptr)
> else(): => !leafent_ptr
>
> if is_none()
> do the none-thing
> if is_present()
> if is_leafent(ent) (== is_leafent_ptr)
> do the pointer thing
> else
> do the table thing
> else()
> type = leafent_type(ent)
> switch(type)
> do the software things
> can't be a present entry (see above)
>
>
> A leaf is a leaf :shrug:
>
> ~Gregory

I thought about doing this but it doesn't really work as the type is
_abstracted_ from the architecture-specific value, _and_ we use what is
currently the swp_type field to identify what this is.

So we would lose the architecture-specific information that any 'hardware leaf'
entry would require and not be able to reliably identify it without losing bits.

Trying to preserve the value _and_ correctly identify it as a present entry
would be difficult.

And I _really_ didn't want to go on a deep dive through all the architectures to
see if we could encode it differently to allow for this.

Rather I think it's better to differentiate between s/w + h/w leaf entries.

Cheers, Lorenzo