arm64: consolidate rox page protection logic
authorRussell King <rmk+kernel@armlinux.org.uk>
Wed, 14 Jun 2023 16:09:35 +0000 (17:09 +0100)
committerCatalin Marinas <catalin.marinas@arm.com>
Wed, 14 Jun 2023 17:03:10 +0000 (18:03 +0100)
Consolidate the arm64 decision making for the page protections used
for executable pages, used by both the trampoline code and the kernel
text mapping code.

Acked-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Link: https://lore.kernel.org/r/E1q9T3v-00EDmW-BH@rmk-PC.armlinux.org.uk
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
arch/arm64/mm/mmu.c

index af6bc84..4829abe 100644 (file)
@@ -663,12 +663,17 @@ static void __init map_kernel_segment(pgd_t *pgdp, void *va_start, void *va_end,
        vm_area_add_early(vma);
 }
 
+static pgprot_t kernel_exec_prot(void)
+{
+       return rodata_enabled ? PAGE_KERNEL_ROX : PAGE_KERNEL_EXEC;
+}
+
 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
 static int __init map_entry_trampoline(void)
 {
        int i;
 
-       pgprot_t prot = rodata_enabled ? PAGE_KERNEL_ROX : PAGE_KERNEL_EXEC;
+       pgprot_t prot = kernel_exec_prot();
        phys_addr_t pa_start = __pa_symbol(__entry_tramp_text_start);
 
        /* The trampoline is always mapped and can therefore be global */
@@ -723,7 +728,7 @@ static void __init map_kernel(pgd_t *pgdp)
         * mapping to install SW breakpoints. Allow this (only) when
         * explicitly requested with rodata=off.
         */
-       pgprot_t text_prot = rodata_enabled ? PAGE_KERNEL_ROX : PAGE_KERNEL_EXEC;
+       pgprot_t text_prot = kernel_exec_prot();
 
        /*
         * If we have a CPU that supports BTI and a kernel built for