From: Nicholas Piggin <npiggin@gmail.com> Date: 2022-09-16 04:08:46
This series is mainly about moving more things out of writable and
executable memory, and slightly moving the linker script in the
direction of the binutils ld internal linker script as we do.
Thanks,
Nick
Since v1:
- Move sys_call_table data.rel.ro patch to the end.
- And fix the changelog in that patch, the relocations were a red herring.
- Update the changelog in the __end_rodata patch.
- Align __end_rodata to strict align size.
Nicholas Piggin (7):
powerpc: move __end_rodata to cover arch read-only sections
powerpc/32/build: move got1/got2 sections out of text
powerpc/build: move got, toc, plt, branch_lt sections to read-only
powerpc/build: move .data.rel.ro, .sdata2 to read-only
powerpc/64/build: only include .opd with ELFv1
powerpc/64/build: merge .got and .toc input sections
powerpc/build: put sys_call_table in .data.rel.ro if RELOCATABLE
arch/powerpc/kernel/systbl.S | 4 ++
arch/powerpc/kernel/vmlinux.lds.S | 85 +++++++++++++++---------
arch/powerpc/mm/book3s32/mmu.c | 2 +-
arch/powerpc/mm/book3s64/hash_pgtable.c | 2 +-
arch/powerpc/mm/book3s64/radix_pgtable.c | 6 +-
arch/powerpc/mm/pgtable_32.c | 7 +-
6 files changed, 66 insertions(+), 40 deletions(-)
--
2.37.2
From: Nicholas Piggin <npiggin@gmail.com> Date: 2022-09-16 04:09:21
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 that to use __end_rodata. This removes the requirement for the init
section to follow read-only data.
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>
---
arch/powerpc/kernel/vmlinux.lds.S | 3 +++
arch/powerpc/mm/book3s32/mmu.c | 2 +-
arch/powerpc/mm/book3s64/hash_pgtable.c | 2 +-
arch/powerpc/mm/book3s64/radix_pgtable.c | 6 +++---
arch/powerpc/mm/pgtable_32.c | 7 ++++---
5 files changed, 12 insertions(+), 8 deletions(-)
From: Nicholas Piggin <npiggin@gmail.com> Date: 2022-09-16 04:09:56
Following the example from the binutils default linker script, move
.got1 and .got2 out of .text, to just after RO_DATA.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
arch/powerpc/kernel/vmlinux.lds.S | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
From: Nicholas Piggin <npiggin@gmail.com> Date: 2022-09-16 04:10:30
This moves linker-related tables from .data to read-only area.
Relocations are performed at early boot time before memory is protected,
after which there should be no modifications required.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
arch/powerpc/kernel/vmlinux.lds.S | 42 ++++++++++++++++++++-----------
1 file changed, 27 insertions(+), 15 deletions(-)
I guess SPECIAL is a binutils ld ism?
I can't find it documented anywhere.
Presumably we can just not use it, given we never did before?
Yeah that's what it is, oops I just took it from the linker script.
I think we can drop it, I think it selects either old or new plt
sections that are created with --secure-plt, I guess depending on
some link options and copmatibility concerns. Doesn't look like
ppc32 uses --secure-plt.
Thanks,
Nick
From: Nicholas Piggin <npiggin@gmail.com> Date: 2022-09-16 04:11:04
.sdata2 is a readonly small data section for ppc32, and .data.rel.ro
is data that needs relocating but is read-only after that so these
can both be moved to the read only memory region.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
arch/powerpc/kernel/vmlinux.lds.S | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
From: Nicholas Piggin <npiggin@gmail.com> Date: 2022-09-16 04:11:45
ELFv2 does not use function descriptors so .opd is not required.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
arch/powerpc/kernel/vmlinux.lds.S | 2 ++
1 file changed, 2 insertions(+)
At the begining I was thinking that this change would jeopardise the
below, but in fact the #ifdef below is pointless, because prom_init.o is
built only when CONFIG_PPC_OF_BOOT_TRAMPOLINE is selected but
CONFIG_PPC_OF_BOOT_TRAMPOLINE selects CONFIG_RELOCATABLE
So all __prom_init_toc_ stuff can go away :
arch/powerpc/include/asm/sections.h:extern char __prom_init_toc_start[];
arch/powerpc/include/asm/sections.h:extern char __prom_init_toc_end[];
arch/powerpc/kernel/prom_init_check.sh:__prom_init_toc_start
__prom_init_toc_end btext_setup_display TOC.
arch/powerpc/kernel/vmlinux.lds.S: __prom_init_toc_start = .;
arch/powerpc/kernel/vmlinux.lds.S: __prom_init_toc_end = .;
At the begining I was thinking that this change would jeopardise the
below, but in fact the #ifdef below is pointless, because prom_init.o is
built only when CONFIG_PPC_OF_BOOT_TRAMPOLINE is selected but
CONFIG_PPC_OF_BOOT_TRAMPOLINE selects CONFIG_RELOCATABLE
So all __prom_init_toc_ stuff can go away :
arch/powerpc/include/asm/sections.h:extern char __prom_init_toc_start[];
arch/powerpc/include/asm/sections.h:extern char __prom_init_toc_end[];
arch/powerpc/kernel/prom_init_check.sh:__prom_init_toc_start
__prom_init_toc_end btext_setup_display TOC.
arch/powerpc/kernel/vmlinux.lds.S: __prom_init_toc_start = .;
arch/powerpc/kernel/vmlinux.lds.S: __prom_init_toc_end = .;
Yes you're right.
Missed cleanup by me in 24d33ac5b8ff ("powerpc/64s: Make prom_init require RELOCATABLE").
I'll send a patch tomorrow.
cheers
From: Nicholas Piggin <npiggin@gmail.com> Date: 2022-09-16 04:12:55
Const function pointers by convention live in .data.rel.ro if they need
to be relocated. Now that .data.rel.ro is linked into the read-only
region, put them in the right section. This doesn't make much practical
difference, but it will make the C conversion of sys_call_table a
smaller change as far as linking goes.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
arch/powerpc/kernel/systbl.S | 4 ++++
1 file changed, 4 insertions(+)
From: Michael Ellerman <hidden> Date: 2022-10-04 13:59:56
On Fri, 16 Sep 2022 14:07:48 +1000, Nicholas Piggin wrote:
This series is mainly about moving more things out of writable and
executable memory, and slightly moving the linker script in the
direction of the binutils ld internal linker script as we do.
Thanks,
Nick
[...]