Skip to content

Commit d672a4b

Browse files
ardbiesheuvelwilldeacon
authored andcommitted
arm64: mm: Don't abuse memblock NOMAP to check for overlaps
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 <ardb@kernel.org> Reviewed-by: Kevin Brodsky <kevin.brodsky@arm.com> Signed-off-by: Will Deacon <will@kernel.org>
1 parent 382a03e commit d672a4b

1 file changed

Lines changed: 10 additions & 16 deletions

File tree

arch/arm64/mm/mmu.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,12 +1164,17 @@ static void __init map_mem(void)
11641164
flags |= NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS;
11651165

11661166
/*
1167-
* Take care not to create a writable alias for the
1168-
* read-only text and rodata sections of the kernel image.
1169-
* So temporarily mark them as NOMAP to skip mappings in
1170-
* the following for-loop
1167+
* Map the linear alias of the [_text, __init_begin) interval first
1168+
* so that its write permissions can be removed later without the need
1169+
* to split any block mappings created by the loop below.
1170+
*
1171+
* Write permissions are needed for alternatives patching, and will be
1172+
* removed later by mark_linear_text_alias_ro() above. This makes the
1173+
* contents of the region accessible to subsystems such as hibernate,
1174+
* but protects it from inadvertent modification or execution.
11711175
*/
1172-
memblock_mark_nomap(kernel_start, kernel_end - kernel_start);
1176+
__map_memblock(kernel_start, kernel_end, pgprot_tagged(PAGE_KERNEL),
1177+
flags);
11731178

11741179
/* map all the memory banks */
11751180
for_each_mem_range(i, &start, &end) {
@@ -1181,17 +1186,6 @@ static void __init map_mem(void)
11811186
__map_memblock(start, end, pgprot_tagged(PAGE_KERNEL),
11821187
flags);
11831188
}
1184-
1185-
/*
1186-
* Map the linear alias of the [_text, __init_begin) interval
1187-
* as non-executable now, and remove the write permission in
1188-
* mark_linear_text_alias_ro() below (which will be called after
1189-
* alternative patching has completed). This makes the contents
1190-
* of the region accessible to subsystems such as hibernate,
1191-
* but protects it from inadvertent modification or execution.
1192-
*/
1193-
__map_memblock(kernel_start, kernel_end, PAGE_KERNEL, 0);
1194-
memblock_clear_nomap(kernel_start, kernel_end - kernel_start);
11951189
}
11961190

11971191
void mark_rodata_ro(void)

0 commit comments

Comments
 (0)