powerpc: move __end_rodata to cover arch read-only sections
authorNicholas Piggin <npiggin@gmail.com>
Fri, 16 Sep 2022 04:07:49 +0000 (14:07 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Mon, 26 Sep 2022 10:58:16 +0000 (20:58 +1000)
powerpc has a number of read-only sections and tables that are put after
RO_DATA(). Move the __end_rodata symbol to cover these as well.

Setting memory to read-only at boot is done using __init_begin, change
that to use __end_rodata.

This makes is_kernel_rodata() exactly cover the read-only region, as
well as other things using __end_rodata (e.g., kernel/dma/debug.c).
Boot dmesg also prints the rodata size more accurately.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20220916040755.2398112-2-npiggin@gmail.com
arch/powerpc/kernel/vmlinux.lds.S
arch/powerpc/mm/book3s32/mmu.c
arch/powerpc/mm/book3s64/hash_pgtable.c
arch/powerpc/mm/book3s64/radix_pgtable.c
arch/powerpc/mm/pgtable_32.c

index 29d8913..5fe33a6 100644 (file)
@@ -219,6 +219,7 @@ SECTIONS
         */
        . = ALIGN(STRICT_ALIGN_SIZE);
        __srwx_boundary = .;
+       __end_rodata = .;
        __init_begin = .;
 
 /*
index 250d174..e5ee05c 100644 (file)
@@ -240,7 +240,7 @@ void mmu_mark_rodata_ro(void)
        for (i = 0; i < nb; i++) {
                struct ppc_bat *bat = BATS[i];
 
-               if (bat_addrs[i].start < (unsigned long)__init_begin)
+               if (bat_addrs[i].start < (unsigned long)__end_rodata)
                        bat[1].batl = (bat[1].batl & ~BPP_RW) | BPP_RX;
        }
 
index ae008b9..2833200 100644 (file)
@@ -541,7 +541,7 @@ void hash__mark_rodata_ro(void)
        unsigned long start, end, pp;
 
        start = (unsigned long)_stext;
-       end = (unsigned long)__init_begin;
+       end = (unsigned long)__end_rodata;
 
        pp = htab_convert_pte_flags(pgprot_val(PAGE_KERNEL_ROX), HPTE_USE_KERNEL_KEY);
 
index 9f880f9..60c277a 100644 (file)
@@ -228,7 +228,7 @@ void radix__mark_rodata_ro(void)
        unsigned long start, end;
 
        start = (unsigned long)_stext;
-       end = (unsigned long)__init_begin;
+       end = (unsigned long)__end_rodata;
 
        radix__change_memory_range(start, end, _PAGE_WRITE);
 }
index 3ac73f9..5c02fd0 100644 (file)
@@ -158,10 +158,11 @@ void mark_rodata_ro(void)
        }
 
        /*
-        * mark .text and .rodata as read only. Use __init_begin rather than
-        * __end_rodata to cover NOTES and EXCEPTION_TABLE.
+        * mark text and rodata as read only. __end_rodata is set by
+        * powerpc's linker script and includes tables and data
+        * requiring relocation which are not put in RO_DATA.
         */
-       numpages = PFN_UP((unsigned long)__init_begin) -
+       numpages = PFN_UP((unsigned long)__end_rodata) -
                   PFN_DOWN((unsigned long)_stext);
 
        set_memory_ro((unsigned long)_stext, numpages);