On 26/05/2026 19:58, Ard Biesheuvel wrote:
> From: Ard Biesheuvel <[email protected]>
>
> Now that the linear region mapping routines respect existing table
> mappings and contiguous block and page mappings, it is no longer needed
> to fiddle with the memblock tables to set and clear the NOMAP attribute
> in order to omit text and rodata when creating the linear map.
>
> Instead, map the kernel text and rodata alias first with the desired
> initial attributes and granularity, so that the loop iterating over the
> memblocks will not remap it in a manner that prevents it from being
> remapped with updated attributes later.
>
> Signed-off-by: Ard Biesheuvel <[email protected]>
> ---
> arch/arm64/mm/mmu.c | 23 ++++++--------------
> 1 file changed, 7 insertions(+), 16 deletions(-)
>
> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
> index 04cc579c7a15..b20c76b8381d 100644
> --- a/arch/arm64/mm/mmu.c
> +++ b/arch/arm64/mm/mmu.c
> @@ -1164,12 +1164,14 @@ static void __init map_mem(void)
> flags |= NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS;
>
> /*
> - * Take care not to create a writable alias for the
> - * read-only text and rodata sections of the kernel image.
> - * So temporarily mark them as NOMAP to skip mappings in
> - * the following for-loop
> + * Map the linear alias of the [_text, __init_begin) interval
> + * as non-executable now, and remove the write permission in
> + * mark_linear_text_alias_ro() above (which will be called after
> + * alternative patching has completed). This makes the contents
> + * of the region accessible to subsystems such as hibernate,
> + * but protects it from inadvertent modification or execution.
> */
> - memblock_mark_nomap(kernel_start, kernel_end - kernel_start);
> + __map_memblock(kernel_start, kernel_end, PAGE_KERNEL, flags);
Isn't the loop going to remap the range as pgprot_tagged(PAGE_KERNEL)?
Maybe better to use that here as well just to make it look more consistent.
If my understanding is correct, we should also amend the comment to
avoid implying that the permissions we're passing to __map_memblock()
here matter - the linear alias is going to be non-executable regardless
because of the loop below mapping everything RW.
- Kevin
>
> /* map all the memory banks */
> for_each_mem_range(i, &start, &end) {
> @@ -1181,17 +1183,6 @@ static void __init map_mem(void)
> __map_memblock(start, end, pgprot_tagged(PAGE_KERNEL),
> flags);
> }
> -
> - /*
> - * Map the linear alias of the [_text, __init_begin) interval
> - * as non-executable now, and remove the write permission in
> - * mark_linear_text_alias_ro() below (which will be called after
> - * alternative patching has completed). This makes the contents
> - * of the region accessible to subsystems such as hibernate,
> - * but protects it from inadvertent modification or execution.
> - */
> - __map_memblock(kernel_start, kernel_end, PAGE_KERNEL, 0);
> - memblock_clear_nomap(kernel_start, kernel_end - kernel_start);
> }
>
> void mark_rodata_ro(void)