Re: [PATCH v1 3/4] arm64: mm: Introduce linear_map_needs_set() helper

From: Vincent Donnefort

Date: Mon Nov 30 2026 - 13:42:16 EST


[...]

> > +/*
> > + * True if the linear map needs to be modified for one of the following
> > + * features:
> > + *
> > + * rodata_full and DEBUG_PAGEALLOC need to protect/unprotect pages in
> > + * the linear map.
> > + *
> > + * KFENCE pool needs to protect/unprotect pages in the linear map if
> > + * initialized late.
> > + *
> > + * Realms need to mark pages shared/protected in the linear map.
> > + */
> > +bool linear_map_needs_set(void)
> > +{
>
> nit: I'm not a big fan of this function name, but see below.
>
> > + return rodata_full || debug_pagealloc_enabled() ||
> > + arm64_kfence_can_set_direct_map() || is_realm_world();
> > +}
> > +
> > static inline bool force_pte_mapping(void)
> > {
> > const bool bbml3 = system_capabilities_finalized() ?
> > @@ -785,7 +803,7 @@ static inline bool force_pte_mapping(void)
> > return true;
>
> This 'return true' above is part of a check for debug_pagealloc_enabled(),
> which is now redundant because you've added that to linear_map_needs_set().

The redundant debug_pagealloc_enabled() is the one in linear_map_needs_set(). I
believe this one is necessary because we must force PTE regardless of bbml3.

>
> > if (bbml3)
> > return false;
> > - return rodata_full || arm64_kfence_can_set_direct_map() || is_realm_world();
> > + return linear_map_needs_set();
> > }
> >
> > static DEFINE_MUTEX(pgtable_split_lock);
> > @@ -1203,7 +1221,7 @@ static void __init map_mem(void)
> >
> > arm64_kfence_map_pool();
> >
> > - linear_map_requires_bbml3 = !force_pte_mapping() && can_set_direct_map();
> > + linear_map_requires_bbml3 = !force_pte_mapping() && linear_map_needs_set();
>
> That looks pretty odd now that force_pte_mapping() calls
> linear_map_needs_set() under the hood.
>
> I wonder if you should avoid introducing the new function and just put
> the logic in force_pte_mapping() instead? You could rename it to
> linear_map_force_pte_mapping().
>
> Then map_mem() just needs to check force_pte_mapping() whereas
> can_set_direct_map() is force_pte_mapping() || has_bbml3().
>
> Will

I am not sure we can get by with just linear_map_force_pte_mapping(). When
false, we still need to distinguish if this is because we have no feature that
requires PTE level mappings or if it is because we might be BBML3.

How about something like:

static inline bool linear_map_needs_split_or_ptes(void)
{
return rodata_full || arm64_kfence_can_set_direct_map() || is_realm_world();
}

bool linear_map_force_pte_mapping(void)
{
...
return linear_map_needs_split_or_pte();
}

And then perhaps this map_mem() snippet is easier to reason about?

void map_mem()
{
...

if (linear_map_force_pte_mapping())
flags = NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS;
else if (linear_map_needs_split_or_pte())
linear_map_requires_bbml3 = true;

...
}

--
Vincent