Re: [PATCH 02/16] mm: introduce leaf entry type and use to simplify leaf entry logic
From: Lorenzo Stoakes
Date: Wed Nov 05 2025 - 16:48:36 EST
On Wed, Nov 05, 2025 at 10:29:14PM +0100, David Hildenbrand (Red Hat) wrote:
> On 05.11.25 22:24, Lorenzo Stoakes wrote:
> > On Wed, Nov 05, 2025 at 10:15:51PM +0100, David Hildenbrand (Red Hat) wrote:
> > > On 05.11.25 22:08, Lorenzo Stoakes wrote:
> > > > On Wed, Nov 05, 2025 at 09:11:45PM +0100, David Hildenbrand (Red Hat) wrote:
> > > > > On 05.11.25 21:05, Lorenzo Stoakes wrote:
> > > > > > On Wed, Nov 05, 2025 at 03:01:00PM -0500, Gregory Price wrote:
> > > > > > > On Wed, Nov 05, 2025 at 07:52:36PM +0000, Lorenzo Stoakes wrote:
> > > > > > > > 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:
> > > > > > > > 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.
> > > > > > > >
> > > > > > >
> > > > > > > Reasonable - names are hard, but just about anything will be better than swp_entry.
> > > > > > >
> > > > > > > SWE / sw_entry seems perfectly reasonable.
> > > > > >
> > > > > > I'm not a lover of 'sw' in there it's just... eye-stabby. Is that a word?
> > > > > >
> > > > > > I am quite fond of my suggested soft_leaf_t, softleaf_xxx()
> > > > >
> > > > > We do have soft_dirty.
> > > > >
> > > > > It will get interesting with pte_swp_soft_dirty() :)
> > > >
> > > > Hmm but that's literally a swap entry, and is used against an actual PTE entry
> > > > not an abstracted s/w leaf entry so I doubt that'd require renaming on any
> > > > level.
> > >
> > > It's used on migration entries as well. Just like pte_swp_uffd_wp().
> > >
> > > So, it's ... tricky :)
> > >
> > > But maybe I am missing your point (my brain is exhausted from uffd code)
> >
> > We'd either not rename it or rename it to something like pte_is_uffd_wp(). So
> > it's not even so relevant.
>
> We do have pte_uffd_wp() for present ptes.
Of course we do :) fun.
I mean we can always invert it with pte_is_present_uffd_wp() or something.
>
> >
> > We'd probably call that something like pte_is_soft_dirty() in the soft dirty
> > case. The 'swp' part of that is pretty redundant.
>
> We do have pte_soft_dirty() for present ptes.
>
> So we'd need some indication that these are for softleaf entries (where the
> bit positions will differ).
>
> >
> > If people were insistent on having softleaf in there we could call it
> > pte_softleaf_is_soft_dirty() which isn't qutie so bad. But I'd not want to put
> > softleaf in there anyway.
> >
> > sw_entry or sw_leaf or sw_leaf_entry would all have the same weirdness.
> >
> > I want it to be something that is readable + not hideous to look at but still
> > clear as to what it's referring too. Softleaf covers all of that off... :)
>
> I think you misunderstood me: I have nothing against softleaf, I was rather
> saying that we already use the "soft" terminology elsewhere (soft_dirt), so
> it's not too crazy.
>
OK we can fix this mess in a number of ways, and mitigate any weird naming I
think.
For instance, we could invert and reference hardware in the non-softleaf case,
or we could have a function that detects whether present or not, or find a way
to not reference softleaf, or just live with pte_is_softleaf_soft_dirty()
(really not that bad, given softleaf is one word etc.)
Given these are niche cases I don't think it's a big issue.
Any reference to software will cause a possible slightly weird sounding name wrt
soft-dirty, but it's right to reference software as that's the key difference
between these leaf entries and present ones.
So yeah I think we're still good to go :)
Cheers, Lorenzo