riscv: Align section markers with other archs
cover riscv: Align section markers with other archs
From: Ard Biesheuvel <[email protected]>
Patch #3 of this series was sent out as part of a EFI series [0] that implements generic support for carrying image info data inside the stub, and after Sashiko found another related issue, I decided to break it out into this series. IOW, patch #3 is a resend.
The point of these changes is to harmonize all architectures that support EFI in terms of the section markers, so that generic zboot code can refer to them without arch specific #ifdefs. Other generic tools probably benefit from this too.
If the maintainers are onboard with this, kindly put it on a stable topic branch so I can refer to it from the EFI tree.
[0] https://lore.kernel.org/all/[email protected]/
Ard Biesheuvel (3):
riscv: Use _stext not _text to denote the start of kernel code
riscv: Make _text point to the start of the kernel image
riscv: Rename __init_text_end to __inittext_end like other archs
arch/riscv/include/asm/sections.h | 2 +- arch/riscv/kernel/image-vars.h | 2 +- arch/riscv/kernel/setup.c | 2 +- arch/riscv/kernel/vmlinux.lds.S | 6 +++--- drivers/firmware/efi/libstub/riscv-stub.c | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-)
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
Signature · 1 line
2.56.0.611.g1030f0b940-goog
PATCH 1/3 riscv: Use _stext not _text to denote the start of kernel code
From: Ard Biesheuvel <[email protected]>
On RISC-V, _text and _stext currently refer to the same location, i.e., the start of the .text output section, which follows the image header (.head.text) emitted by HEAD_TEXT_SECTION. _start is the symbol that refers to the actual start of the image.
On most other architectures, _text refers to the start of the image, and _stext to the start of the kernel code, and generic code (such as the EFI stub) may start relying on this distinction.
So switch the only user of _text in arch/riscv, i.e., the "Kernel code" resource that is exposed via /proc/iomem (and from which the "Kernel image" resource inherits its start address), over to _stext. This is a no-op given that both symbols currently resolve to the same address, but it permits _text to be moved to the start of the image, making it an alias of _start.
--- arch/riscv/kernel/setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/setup.c +1 -1
@@ -91,7 +91,7 @@ static int __init add_kernel_resources(void)* child nodes. */ - code_res.start =__pa_symbol (_text); + code_res.start =__pa_symbol (_stext); code_res.end =__pa_symbol (_etext) -1 ; code_res.flags =IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY ;
Signature · 1 line
2.56.0.611.g1030f0b940-goog
PATCH 2/3 riscv: Make _text point to the start of the kernel image
In reply to Ard BiesheuvelFrom: Ard Biesheuvel <[email protected]>
On RISC-V, _text currently refers to the start of the .text output section, which is placed after the image header (.head.text), and is therefore equal to _stext. On most other architectures such, _text refers to the start of the image, and is used as such by generic code, e.g., to describe the kernel mapping in /proc/kcore and in the ELF headers of the vmcore, and by the EFI stub.
Now that arch/riscv no longer uses _text to refer to the start of the kernel code, move it to the start of the image so that it is equal to _start, and the distinction between _text and _stext is the same as on other architectures.
This also means that the image header is no longer omitted from the /proc/kcore and vmcore kernel text mappings. Other users of _text, such as kallsyms and ftrace, only use it as a reference point to calculate relative offsets, and are not affected by this change.
Note that, as on arm64, _text will no longer appear in /proc/kallsyms unless CONFIG_KALLSYMS_ALL=y, given that it now lives outside of the [_stext, _etext) range. User space tools such as perf already fall back to _stext in this case.
--- arch/riscv/kernel/vmlinux.lds.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/vmlinux.lds.S +1 -1
@@ -28,11 +28,11 @@ SECTIONS /* Beginning of code and text segment */ . = LOAD_OFFSET; _start = .; + _text = .; HEAD_TEXT_SECTION . = ALIGN(PAGE_SIZE); .text : { - _text = .; _stext = .; TEXT_TEXT SCHED_TEXT
Signature · 1 line
2.56.0.611.g1030f0b940-goog
PATCH 3/3 riscv: Rename __init_text_end to __inittext_end like other archs
In reply to Ard BiesheuvelFrom: Ard Biesheuvel <[email protected]>
Align RISC-V with arm64, LoongArch and x86, and drop the underscore between 'init' and 'text' in the section markers. This allows the value to be captured by generic EFI stub code that can be shared between all those architectures.
--- arch/riscv/include/asm/sections.h | 2 +- arch/riscv/kernel/image-vars.h | 2 +- arch/riscv/kernel/vmlinux.lds.S | 4 ++-- drivers/firmware/efi/libstub/riscv-stub.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-)
arch/riscv/include/asm/sections.h +1 -1
@@ -11,7 +11,7 @@extern char _start[];extern char _start_kernel[];extern char __init_data_begin[], __init_data_end[]; -extern char __init_text_begin[], __init_text_end[]; +extern char __inittext_begin[], __inittext_end[];extern char __alt_start[], __alt_end[];extern char __exittext_begin[], __exittext_end[];
arch/riscv/kernel/image-vars.h +1 -1
@@ -27,7 +27,7 @@ __efistub__start = _start; __efistub__start_kernel = _start_kernel; __efistub__end = _end; __efistub__edata = _edata; -__efistub___init_text_end = __init_text_end; +__efistub___inittext_end = __inittext_end;#if defined(CONFIG_EFI_EARLYCON ) || defined(CONFIG_SYSFB ) __efistub_sysfb_primary_display = sysfb_primary_display;#endif
arch/riscv/kernel/vmlinux.lds.S +2 -2
@@ -46,7 +46,7 @@ SECTIONS . = ALIGN(SECTION_ALIGN); __init_begin = .; - __init_text_begin = .; + __inittext_begin = .; .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) ALIGN(SECTION_ALIGN) { \ _sinittext = .; \ INIT_TEXT \
@@ -72,7 +72,7 @@ SECTIONS } __exittext_end = .; - __init_text_end = .; + __inittext_end = .; . = ALIGN(SECTION_ALIGN); #ifdef CONFIG_EFI . = ALIGN(PECOFF_SECTION_ALIGNMENT);
drivers/firmware/efi/libstub/riscv-stub.c +1 -1
@@ -34,7 +34,7 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,efi_status_t status; kernel_size = _edata - _start; - kernel_codesize = __init_text_end - _start; + kernel_codesize = __inittext_end - _start; kernel_memsize = kernel_size + (_end - _edata); *image_addr = (unsigned long )_start; *reserve_size = kernel_memsize;
Signature · 1 line
2.56.0.611.g1030f0b940-goog
Quoted 15 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
Patch #3 of this series was sent out as part of a EFI series [0] that implements generic support for carrying image info data inside the stub, and after Sashiko found another related issue, I decided to break it out into this series. IOW, patch #3 is a resend.
The point of these changes is to harmonize all architectures that support EFI in terms of the section markers, so that generic zboot code can refer to them without arch specific #ifdefs. Other generic tools probably benefit from this too.
If the maintainers are onboard with this, kindly put it on a stable topic branch so I can refer to it from the EFI tree.
Quoted 7 lines
[0] https://lore.kernel.org/all/[email protected]/
Cc Paul Walmsley <[email protected]>Cc Palmer Dabbelt <[email protected]>Cc Albert Ou <[email protected]>Cc Alexandre Ghiti <[email protected]>
For the series:
Quoted 23 lines
Ard Biesheuvel (3):
riscv: Use_stextnot_textto denote the start of kernel code
riscv: Make_textpoint to the start of the kernel image
riscv: Rename__init_text_endto__inittext_endlike other archsarch/riscv/include/asm/sections.h | 2 +- arch/riscv/kernel/image-vars.h | 2 +- arch/riscv/kernel/setup.c | 2 +- arch/riscv/kernel/vmlinux.lds.S | 6 +++--- drivers/firmware/efi/libstub/riscv-stub.c | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-)base-commit:
6628e7d4c6b25c8d18f1345e3a20d21829aae7e4Signature · 7 lines
2.56.0.611.g1030f0b940-goog _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv