Re: [PATCH v3 2/8] arm64: Add support for MEMBLOCK_PTEMAP

From: Mike Rapoport

Date: Sun Nov 15 2026 - 14:20:35 EST


On Wed, Nov 11, 2026 at 11:07:32AM +0000, Vincent Donnefort wrote:
> With the MEMBLOCK_PTEMAP flag, force a PTE-level mapping. This also

I'd expand this to "Force a PTE-level mapping for memblock regions with
MEMBLOCK_PTEMAP flag set".

> disables contiguous PTEs to make sure any page from the memblock can be

and memblock region here ^

> safely unmapped from the linear map.
>
> Signed-off-by: Vincent Donnefort <vdonnefort@xxxxxxxxxx>
> ---
> arch/arm64/mm/mmu.c | 22 +++++++++++++++-------
> 1 file changed, 15 insertions(+), 7 deletions(-)
>
> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
> index 140520b351e2..a4cafafa1d82 100644
> --- a/arch/arm64/mm/mmu.c
> +++ b/arch/arm64/mm/mmu.c
> @@ -1184,9 +1184,8 @@ static void __init map_mem(void)
> phys_addr_t init_begin = __pa_symbol(__init_begin);
> phys_addr_t init_end = __pa_symbol(__init_end);
> phys_addr_t kernel_end = __pa_symbol(__bss_stop);
> - phys_addr_t start, end;
> int flags = NO_EXEC_MAPPINGS;
> - u64 i;
> + struct memblock_region *r;
>
> /*
> * Setting hierarchical PXNTable attributes on table entries covering
> @@ -1226,9 +1225,14 @@ static void __init map_mem(void)
> flags);
>
> /* map all the memory banks */
> - for_each_mem_range(i, &start, &end) {
> + for_each_mem_region(r) {
> + phys_addr_t start, end;
> + int rflags = flags;
> +
> + if (memblock_is_nomap(r))
> + continue;
> /*
> - * for_each_mem_range may return sub-page-aligned boundaries
> + * for_each_mem_region may return sub-page-aligned boundaries
> * after memblock_mark_nomap() splits regions at byte precision.
> * __create_pgd_mapping_locked aligns phys down to PAGE_MASK,
> * which could accidentally map no-map memory on the boundary.
> @@ -1237,17 +1241,21 @@ static void __init map_mem(void)
> * regions. The cost is at most one page of unmapped gap at
> * each boundary.
> */
> - start = PAGE_ALIGN(start);
> - end = end & PAGE_MASK;
> + start = PAGE_ALIGN(r->base);
> + end = (r->base + r->size) & PAGE_MASK;

Nit: as we anyway change the assignment to end, PAGE_ALIGN_DOWN() is
slightly more explicit.

> if (start >= end)
> continue;
> +
> + if (memblock_is_ptemap(r))
> + rflags |= NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS;
> +
> /*
> * The linear map must allow allocation tags reading/writing
> * if MTE is present. Otherwise, it has the same attributes as
> * PAGE_KERNEL.
> */
> __map_memblock(start, end, pgprot_tagged(PAGE_KERNEL),
> - flags);
> + rflags);
> }
> }
>
> --
> 2.56.0.542.g3ef89b7020-goog
>

--
Sincerely yours,
Mike.