diff mbox series

[v1,3/6] arm: Prepare linker scripts for memory permissions

Message ID 20250205071714.635518-4-ilias.apalodimas@linaro.org
State New
Headers show
Series Fix page permission on arm64 architectures | expand

Commit Message

Ilias Apalodimas Feb. 5, 2025, 7:16 a.m. UTC
Upcoming patches are switching the memory mappings to RW, RO, RX
after the U-Boot binary and its data are relocated. Add
annotations in the linker scripts to and mark text, data, rodata
sections and align them to a page boundary.

It's worth noting that efi_runtime relocations are left untouched for
now. The efi runtime regions can be relocated by the OS when the latter
is calling SetVirtualAddressMap. Which means we have to configure the
pages as RX for U-Boot but convert them to RWX just before
ExitBootServices. It also needs extra code in efi_tuntime relocation
code since R_AARCH64_NONE are emitted as well if we page align the
section. Keep it out for now and we can fix it in future patches.

Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
---
 arch/arm/cpu/armv8/u-boot.lds  | 29 +++++++++++++++++------------
 include/asm-generic/sections.h |  2 ++
 2 files changed, 19 insertions(+), 12 deletions(-)

Comments

Ilias Apalodimas Feb. 5, 2025, 8:22 a.m. UTC | #1
I'm just replying to myself here but I'll send a v2 when the patches
are reviewed.

I can add the linker under an ifdef, so u-boot size won't change
unless a Kconfig options is selected

/Ilias

On Wed, 5 Feb 2025 at 09:17, Ilias Apalodimas
<ilias.apalodimas@linaro.org> wrote:
>
> Upcoming patches are switching the memory mappings to RW, RO, RX
> after the U-Boot binary and its data are relocated. Add
> annotations in the linker scripts to and mark text, data, rodata
> sections and align them to a page boundary.
>
> It's worth noting that efi_runtime relocations are left untouched for
> now. The efi runtime regions can be relocated by the OS when the latter
> is calling SetVirtualAddressMap. Which means we have to configure the
> pages as RX for U-Boot but convert them to RWX just before
> ExitBootServices. It also needs extra code in efi_tuntime relocation
> code since R_AARCH64_NONE are emitted as well if we page align the
> section. Keep it out for now and we can fix it in future patches.
>
> Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> ---
>  arch/arm/cpu/armv8/u-boot.lds  | 29 +++++++++++++++++------------
>  include/asm-generic/sections.h |  2 ++
>  2 files changed, 19 insertions(+), 12 deletions(-)
>
> diff --git a/arch/arm/cpu/armv8/u-boot.lds b/arch/arm/cpu/armv8/u-boot.lds
> index 857f44412e07..35afc3cbe7ec 100644
> --- a/arch/arm/cpu/armv8/u-boot.lds
> +++ b/arch/arm/cpu/armv8/u-boot.lds
> @@ -22,7 +22,7 @@ SECTIONS
>
>         . = ALIGN(8);
>         __image_copy_start = ADDR(.text);
> -       .text :
> +       .text ALIGN(4096):
>         {
>                 CPUDIR/start.o (.text*)
>         }
> @@ -36,9 +36,12 @@ SECTIONS
>                  __efi_runtime_stop = .;
>         }
>
> -       .text_rest :
> +       .text_rest ALIGN(4096) :
>         {
> +               __text_start = .;
>                 *(.text*)
> +               . = ALIGN(4096);
> +               __text_end = .;
>         }
>
>  #ifdef CONFIG_ARMV8_PSCI
> @@ -98,18 +101,20 @@ SECTIONS
>         }
>  #endif
>
> -       . = ALIGN(8);
> -       .rodata : { *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*))) }
> +       .rodata ALIGN(4096): {
> +           __start_rodata = .;
> +           *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*)))
> +           . = ALIGN(4096);
> +           __end_rodata = .;
> +       }
>
> -       . = ALIGN(8);
> -       .data : {
> +       .data ALIGN(4096) : {
> +           __start_data = .;
>                 *(.data*)
> +           . = ALIGN(4096);
> +           __end_data = .;
>         }
>
> -       . = ALIGN(8);
> -
> -       . = .;
> -
>         . = ALIGN(8);
>         __u_boot_list : {
>                 KEEP(*(SORT(__u_boot_list*)));
> @@ -136,10 +141,10 @@ SECTIONS
>         /*
>          * arch/arm/lib/crt0_64.S assumes __bss_start - __bss_end % 8 == 0
>          */
> -       .bss ALIGN(8) : {
> +       .bss ALIGN(4096) : {
>                 __bss_start = .;
>                 *(.bss*)
> -               . = ALIGN(8);
> +               . = ALIGN(4096);
>                 __bss_end = .;
>         }
>
> diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
> index 3fd5c772a1af..024b1adde270 100644
> --- a/include/asm-generic/sections.h
> +++ b/include/asm-generic/sections.h
> @@ -23,6 +23,7 @@ extern char __kprobes_text_start[], __kprobes_text_end[];
>  extern char __entry_text_start[], __entry_text_end[];
>  extern char __initdata_begin[], __initdata_end[];
>  extern char __start_rodata[], __end_rodata[];
> +extern char __start_data[], __end_data[];
>  extern char __efi_helloworld_begin[];
>  extern char __efi_helloworld_end[];
>  extern char __efi_var_file_begin[];
> @@ -63,6 +64,7 @@ static inline int arch_is_kernel_data(unsigned long addr)
>
>  /* Start of U-Boot text region */
>  extern char __text_start[];
> +extern char __text_end[];
>
>  /* This marks the text region which must be relocated */
>  extern char __image_copy_start[], __image_copy_end[];
> --
> 2.47.2
>
Michal Simek Feb. 5, 2025, 12:41 p.m. UTC | #2
Hi,

On 2/5/25 09:22, Ilias Apalodimas wrote:
> I'm just replying to myself here but I'll send a v2 when the patches
> are reviewed.
> 
> I can add the linker under an ifdef, so u-boot size won't change
> unless a Kconfig options is selected

I think you can just do it for alignment not really big ifdef in the file.
Definitely this will be needed for our mini configurations which are running out 
of OCM.
Feel free to look at xilinx_*_mini* configurations.

Thanks,
Michal
Ilias Apalodimas Feb. 5, 2025, 1:11 p.m. UTC | #3
On Wed, 5 Feb 2025 at 14:42, Michal Simek <michal.simek@amd.com> wrote:
>
> Hi,
>
> On 2/5/25 09:22, Ilias Apalodimas wrote:
> > I'm just replying to myself here but I'll send a v2 when the patches
> > are reviewed.
> >
> > I can add the linker under an ifdef, so u-boot size won't change
> > unless a Kconfig options is selected
>
> I think you can just do it for alignment not really big ifdef in the file.

Yes that's what I meant, I can have all the ALIGN(4096) stuff in an ifdef.

Cheers
/Ilias
> Definitely this will be needed for our mini configurations which are running out
> of OCM.
> Feel free to look at xilinx_*_mini* configurations.
>
> Thanks,
> Michal
Richard Henderson Feb. 5, 2025, 5:23 p.m. UTC | #4
On 2/4/25 23:16, Ilias Apalodimas wrote:
> @@ -98,18 +101,20 @@ SECTIONS
>   	}
>   #endif
>   
> -	. = ALIGN(8);
> -	.rodata : { *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*))) }
> +	.rodata ALIGN(4096): {
> +	    __start_rodata = .;
> +	    *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*)))
> +	    . = ALIGN(4096);
> +	    __end_rodata = .;
> +	}
>   
> -	. = ALIGN(8);
> -	.data : {
> +	.data ALIGN(4096) : {
> +	    __start_data = .;
>   		*(.data*)
> +	    . = ALIGN(4096);
> +	    __end_data = .;
>   	}
>   
> -	. = ALIGN(8);
> -
> -	. = .;
> -
>   	. = ALIGN(8);
>   	__u_boot_list : {
>   		KEEP(*(SORT(__u_boot_list*)));
> @@ -136,10 +141,10 @@ SECTIONS
>   	/*
>   	 * arch/arm/lib/crt0_64.S assumes __bss_start - __bss_end % 8 == 0
>   	 */
> -	.bss ALIGN(8) : {
> +	.bss ALIGN(4096) : {
>   		__bss_start = .;
>   		*(.bss*)
> -		. = ALIGN(8);
> +		. = ALIGN(4096);
>   		__bss_end = .;
>   	}

You don't need to align .bss because it normally immediately follows .data, and they have 
the same page permissions.

You've got __u_boot_list, .efi_runtime_rel and .rela.dyn in between.  Consider if any of 
that ought to be moved around to become read-only.


r~
Tom Rini Feb. 5, 2025, 5:33 p.m. UTC | #5
On Wed, Feb 05, 2025 at 09:16:47AM +0200, Ilias Apalodimas wrote:

> Upcoming patches are switching the memory mappings to RW, RO, RX
> after the U-Boot binary and its data are relocated. Add
> annotations in the linker scripts to and mark text, data, rodata
> sections and align them to a page boundary.
> 
> It's worth noting that efi_runtime relocations are left untouched for
> now. The efi runtime regions can be relocated by the OS when the latter
> is calling SetVirtualAddressMap. Which means we have to configure the
> pages as RX for U-Boot but convert them to RWX just before
> ExitBootServices. It also needs extra code in efi_tuntime relocation
> code since R_AARCH64_NONE are emitted as well if we page align the
> section. Keep it out for now and we can fix it in future patches.
> 
> Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> ---
>  arch/arm/cpu/armv8/u-boot.lds  | 29 +++++++++++++++++------------
>  include/asm-generic/sections.h |  2 ++
>  2 files changed, 19 insertions(+), 12 deletions(-)
> 
> diff --git a/arch/arm/cpu/armv8/u-boot.lds b/arch/arm/cpu/armv8/u-boot.lds
> index 857f44412e07..35afc3cbe7ec 100644
> --- a/arch/arm/cpu/armv8/u-boot.lds
> +++ b/arch/arm/cpu/armv8/u-boot.lds
> @@ -22,7 +22,7 @@ SECTIONS
>  
>  	. = ALIGN(8);
>  	__image_copy_start = ADDR(.text);
> -	.text :
> +	.text ALIGN(4096):
>  	{
>  		CPUDIR/start.o (.text*)
>  	}

Shouldn't this be:
-	. = ALIGN(8);
-	__image_copy_start = ADDR(.text);
-	.text :
+	.text ALIGN(4096):
 	{
+		__image_copy_start = ADDR(.text); // Or even just '= .;' ?
		CPUDIR/start.o (.text*)
 	}
Or so? Something like that would also make it easier in v2 to have a
Kconfig about page align / min align for sections in the linker script
and then ALIGN(CONFIG_FOO) or #ifdef CONFIG_FOO #define MINALIGN 8 #else
4096 #endif, or so. Also I guess today we're not going to worry about
bigger than 4KiB pages?

> @@ -36,9 +36,12 @@ SECTIONS
>                  __efi_runtime_stop = .;
>  	}
>  
> -	.text_rest :
> +	.text_rest ALIGN(4096) :
>  	{
> +		__text_start = .;
>  		*(.text*)
> +		. = ALIGN(4096);
> +		__text_end = .;
>  	}

Here and elsewhere in the patch, does that really need two ALIGN(4096)
lines? Or am I totally misremembering how these symbols work in a linker
script?
Ilias Apalodimas Feb. 5, 2025, 5:34 p.m. UTC | #6
Hi Richard,

On Wed, 5 Feb 2025 at 19:23, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> On 2/4/25 23:16, Ilias Apalodimas wrote:
> > @@ -98,18 +101,20 @@ SECTIONS
> >       }
> >   #endif
> >
> > -     . = ALIGN(8);
> > -     .rodata : { *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*))) }
> > +     .rodata ALIGN(4096): {
> > +         __start_rodata = .;
> > +         *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*)))
> > +         . = ALIGN(4096);
> > +         __end_rodata = .;
> > +     }
> >
> > -     . = ALIGN(8);
> > -     .data : {
> > +     .data ALIGN(4096) : {
> > +         __start_data = .;
> >               *(.data*)
> > +         . = ALIGN(4096);
> > +         __end_data = .;
> >       }
> >
> > -     . = ALIGN(8);
> > -
> > -     . = .;
> > -
> >       . = ALIGN(8);
> >       __u_boot_list : {
> >               KEEP(*(SORT(__u_boot_list*)));
> > @@ -136,10 +141,10 @@ SECTIONS
> >       /*
> >        * arch/arm/lib/crt0_64.S assumes __bss_start - __bss_end % 8 == 0
> >        */
> > -     .bss ALIGN(8) : {
> > +     .bss ALIGN(4096) : {
> >               __bss_start = .;
> >               *(.bss*)
> > -             . = ALIGN(8);
> > +             . = ALIGN(4096);
> >               __bss_end = .;
> >       }
>
> You don't need to align .bss because it normally immediately follows .data, and they have
> the same page permissions.
>
> You've got __u_boot_list, .efi_runtime_rel and .rela.dyn in between.  Consider if any of
> that ought to be moved around to become read-only.

That's a good idea and I just realized I am not setting the .bss to RW
in later patches.
I can move .bss right after data and rela.dyn after .rodata. That will
probably same me ~2 pages due to alignment. I am not sure about
__u_boot_list, but if that's read-only I can group it as well.

The .efi_runtime_rel is a bit weird. This is where the UEFI runtime
services live and it contains executable code. However, when an OS
boots up it can call SetVirtualAddressMap. That call relocates the
runtime code to the new VA mapping the OS choose. This means I have to
initially set it to RX and later when we leave the firmware land
switch it RWX so the OS can relocate it... I've left that part out on
purpose but I can move the runtime services as the last segment and
fix up weird logic on relocation in later patches

Thanks!
/Ilias
>
>
> r~
Tom Rini Feb. 5, 2025, 7:03 p.m. UTC | #7
On Wed, Feb 05, 2025 at 01:41:46PM +0100, Michal Simek wrote:
> Hi,
> 
> On 2/5/25 09:22, Ilias Apalodimas wrote:
> > I'm just replying to myself here but I'll send a v2 when the patches
> > are reviewed.
> > 
> > I can add the linker under an ifdef, so u-boot size won't change
> > unless a Kconfig options is selected
> 
> I think you can just do it for alignment not really big ifdef in the file.
> Definitely this will be needed for our mini configurations which are running
> out of OCM.
> Feel free to look at xilinx_*_mini* configurations.

Does the existing SPL_SIZE_LIMIT on the mini configs catch problems?
This series doesn't trip it there, but maybe we're only close? Thanks.
Ilias Apalodimas Feb. 5, 2025, 7:18 p.m. UTC | #8
Hi Tom,

On Wed, 5 Feb 2025 at 19:33, Tom Rini <trini@konsulko.com> wrote:
>
> On Wed, Feb 05, 2025 at 09:16:47AM +0200, Ilias Apalodimas wrote:
>
> > Upcoming patches are switching the memory mappings to RW, RO, RX
> > after the U-Boot binary and its data are relocated. Add
> > annotations in the linker scripts to and mark text, data, rodata
> > sections and align them to a page boundary.
> >
> > It's worth noting that efi_runtime relocations are left untouched for
> > now. The efi runtime regions can be relocated by the OS when the latter
> > is calling SetVirtualAddressMap. Which means we have to configure the
> > pages as RX for U-Boot but convert them to RWX just before
> > ExitBootServices. It also needs extra code in efi_tuntime relocation
> > code since R_AARCH64_NONE are emitted as well if we page align the
> > section. Keep it out for now and we can fix it in future patches.
> >
> > Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
> > Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> > ---
> >  arch/arm/cpu/armv8/u-boot.lds  | 29 +++++++++++++++++------------
> >  include/asm-generic/sections.h |  2 ++
> >  2 files changed, 19 insertions(+), 12 deletions(-)
> >
> > diff --git a/arch/arm/cpu/armv8/u-boot.lds b/arch/arm/cpu/armv8/u-boot.lds
> > index 857f44412e07..35afc3cbe7ec 100644
> > --- a/arch/arm/cpu/armv8/u-boot.lds
> > +++ b/arch/arm/cpu/armv8/u-boot.lds
> > @@ -22,7 +22,7 @@ SECTIONS
> >
> >       . = ALIGN(8);
> >       __image_copy_start = ADDR(.text);
> > -     .text :
> > +     .text ALIGN(4096):
> >       {
> >               CPUDIR/start.o (.text*)
> >       }
>
> Shouldn't this be:
> -       . = ALIGN(8);
> -       __image_copy_start = ADDR(.text);
> -       .text :
> +       .text ALIGN(4096):
>         {
> +               __image_copy_start = ADDR(.text); // Or even just '= .;' ?
>                 CPUDIR/start.o (.text*)

IIRC this will produce the exact same output.
Given Richards's idea, I'll move the sections around a bit and define
rw_start_end, ro_start/end and rx_start/end symbols.
It would make other architectures life easier if they ever want to
replicate this. So with those new symbols, adding ifdefs around the
alignment should be more readable.

>         }
> Or so? Something like that would also make it easier in v2 to have a
> Kconfig about page align / min align for sections in the linker script
> and then ALIGN(CONFIG_FOO) or #ifdef CONFIG_FOO #define MINALIGN 8 #else
> 4096 #endif, or so. Also I guess today we're not going to worry about
> bigger than 4KiB pages?
>
> > @@ -36,9 +36,12 @@ SECTIONS
> >                  __efi_runtime_stop = .;
> >       }
> >
> > -     .text_rest :
> > +     .text_rest ALIGN(4096) :
> >       {
> > +             __text_start = .;
> >               *(.text*)
> > +             . = ALIGN(4096);
> > +             __text_end = .;
> >       }
>
> Here and elsewhere in the patch, does that really need two ALIGN(4096)
> lines? Or am I totally misremembering how these symbols work in a linker
> script?

Yes it does, the first one guarantees the start of the section and the
latter the end. IOW if I commit the second align, there's no guarantee
we'll end up page aliged. Our mmu code assumes that it's operating in
page boundaries.

Thanks
/Ilias


>
> --
> Tom
Tom Rini Feb. 5, 2025, 7:25 p.m. UTC | #9
On Wed, Feb 05, 2025 at 09:18:50PM +0200, Ilias Apalodimas wrote:
> Hi Tom,
> 
> On Wed, 5 Feb 2025 at 19:33, Tom Rini <trini@konsulko.com> wrote:
> >
> > On Wed, Feb 05, 2025 at 09:16:47AM +0200, Ilias Apalodimas wrote:
> >
> > > Upcoming patches are switching the memory mappings to RW, RO, RX
> > > after the U-Boot binary and its data are relocated. Add
> > > annotations in the linker scripts to and mark text, data, rodata
> > > sections and align them to a page boundary.
> > >
> > > It's worth noting that efi_runtime relocations are left untouched for
> > > now. The efi runtime regions can be relocated by the OS when the latter
> > > is calling SetVirtualAddressMap. Which means we have to configure the
> > > pages as RX for U-Boot but convert them to RWX just before
> > > ExitBootServices. It also needs extra code in efi_tuntime relocation
> > > code since R_AARCH64_NONE are emitted as well if we page align the
> > > section. Keep it out for now and we can fix it in future patches.
> > >
> > > Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
> > > Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> > > ---
> > >  arch/arm/cpu/armv8/u-boot.lds  | 29 +++++++++++++++++------------
> > >  include/asm-generic/sections.h |  2 ++
> > >  2 files changed, 19 insertions(+), 12 deletions(-)
> > >
> > > diff --git a/arch/arm/cpu/armv8/u-boot.lds b/arch/arm/cpu/armv8/u-boot.lds
> > > index 857f44412e07..35afc3cbe7ec 100644
> > > --- a/arch/arm/cpu/armv8/u-boot.lds
> > > +++ b/arch/arm/cpu/armv8/u-boot.lds
> > > @@ -22,7 +22,7 @@ SECTIONS
> > >
> > >       . = ALIGN(8);
> > >       __image_copy_start = ADDR(.text);
> > > -     .text :
> > > +     .text ALIGN(4096):
> > >       {
> > >               CPUDIR/start.o (.text*)
> > >       }
> >
> > Shouldn't this be:
> > -       . = ALIGN(8);
> > -       __image_copy_start = ADDR(.text);
> > -       .text :
> > +       .text ALIGN(4096):
> >         {
> > +               __image_copy_start = ADDR(.text); // Or even just '= .;' ?
> >                 CPUDIR/start.o (.text*)
> 
> IIRC this will produce the exact same output.

OK, so we don't end up with 8192 worth of alignment here.

> Given Richards's idea, I'll move the sections around a bit and define
> rw_start_end, ro_start/end and rx_start/end symbols.
> It would make other architectures life easier if they ever want to
> replicate this. So with those new symbols, adding ifdefs around the
> alignment should be more readable.

Yes, re-organizing things will help too, I agree.

> > Or so? Something like that would also make it easier in v2 to have a
> > Kconfig about page align / min align for sections in the linker script
> > and then ALIGN(CONFIG_FOO) or #ifdef CONFIG_FOO #define MINALIGN 8 #else
> > 4096 #endif, or so. Also I guess today we're not going to worry about
> > bigger than 4KiB pages?
> >
> > > @@ -36,9 +36,12 @@ SECTIONS
> > >                  __efi_runtime_stop = .;
> > >       }
> > >
> > > -     .text_rest :
> > > +     .text_rest ALIGN(4096) :
> > >       {
> > > +             __text_start = .;
> > >               *(.text*)
> > > +             . = ALIGN(4096);
> > > +             __text_end = .;
> > >       }
> >
> > Here and elsewhere in the patch, does that really need two ALIGN(4096)
> > lines? Or am I totally misremembering how these symbols work in a linker
> > script?
> 
> Yes it does, the first one guarantees the start of the section and the
> latter the end. IOW if I commit the second align, there's no guarantee
> we'll end up page aliged. Our mmu code assumes that it's operating in
> page boundaries.

And I had mis-read the context. Yes, we need to make sure the end is
aligned so that we don't have incorrect permissions for the next
section. And with re-organization of the areas we'll have less extra
padding too.
Ilias Apalodimas Feb. 5, 2025, 9:35 p.m. UTC | #10
On Wed, 5 Feb 2025 at 21:25, Tom Rini <trini@konsulko.com> wrote:
>
> On Wed, Feb 05, 2025 at 09:18:50PM +0200, Ilias Apalodimas wrote:
> > Hi Tom,
> >
> > On Wed, 5 Feb 2025 at 19:33, Tom Rini <trini@konsulko.com> wrote:
> > >
> > > On Wed, Feb 05, 2025 at 09:16:47AM +0200, Ilias Apalodimas wrote:
> > >
> > > > Upcoming patches are switching the memory mappings to RW, RO, RX
> > > > after the U-Boot binary and its data are relocated. Add
> > > > annotations in the linker scripts to and mark text, data, rodata
> > > > sections and align them to a page boundary.
> > > >
> > > > It's worth noting that efi_runtime relocations are left untouched for
> > > > now. The efi runtime regions can be relocated by the OS when the latter
> > > > is calling SetVirtualAddressMap. Which means we have to configure the
> > > > pages as RX for U-Boot but convert them to RWX just before
> > > > ExitBootServices. It also needs extra code in efi_tuntime relocation
> > > > code since R_AARCH64_NONE are emitted as well if we page align the
> > > > section. Keep it out for now and we can fix it in future patches.
> > > >
> > > > Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
> > > > Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> > > > ---
> > > >  arch/arm/cpu/armv8/u-boot.lds  | 29 +++++++++++++++++------------
> > > >  include/asm-generic/sections.h |  2 ++
> > > >  2 files changed, 19 insertions(+), 12 deletions(-)
> > > >
> > > > diff --git a/arch/arm/cpu/armv8/u-boot.lds b/arch/arm/cpu/armv8/u-boot.lds
> > > > index 857f44412e07..35afc3cbe7ec 100644
> > > > --- a/arch/arm/cpu/armv8/u-boot.lds
> > > > +++ b/arch/arm/cpu/armv8/u-boot.lds
> > > > @@ -22,7 +22,7 @@ SECTIONS
> > > >
> > > >       . = ALIGN(8);
> > > >       __image_copy_start = ADDR(.text);
> > > > -     .text :
> > > > +     .text ALIGN(4096):
> > > >       {
> > > >               CPUDIR/start.o (.text*)
> > > >       }
> > >
> > > Shouldn't this be:
> > > -       . = ALIGN(8);
> > > -       __image_copy_start = ADDR(.text);
> > > -       .text :
> > > +       .text ALIGN(4096):
> > >         {
> > > +               __image_copy_start = ADDR(.text); // Or even just '= .;' ?
> > >                 CPUDIR/start.o (.text*)
> >
> > IIRC this will produce the exact same output.
>
> OK, so we don't end up with 8192 worth of alignment here.

We do, but that's because I added an ALIGN(4096) in .text. The change
above won't change that.

But looking at it again, I don't have to do that now. I can remove the
alignment from .text since some efi_runtime services are between that
and .text_start.
Since my current patch ignores efi_runtime, I can skip the .text
alignment, save ~4k and fix the rest when I deal with EFI.

>
> > Given Richards's idea, I'll move the sections around a bit and define
> > rw_start_end, ro_start/end and rx_start/end symbols.
> > It would make other architectures life easier if they ever want to
> > replicate this. So with those new symbols, adding ifdefs around the
> > alignment should be more readable.
>
> Yes, re-organizing things will help too, I agree.
>
[...]

Regards
/Ilias
diff mbox series

Patch

diff --git a/arch/arm/cpu/armv8/u-boot.lds b/arch/arm/cpu/armv8/u-boot.lds
index 857f44412e07..35afc3cbe7ec 100644
--- a/arch/arm/cpu/armv8/u-boot.lds
+++ b/arch/arm/cpu/armv8/u-boot.lds
@@ -22,7 +22,7 @@  SECTIONS
 
 	. = ALIGN(8);
 	__image_copy_start = ADDR(.text);
-	.text :
+	.text ALIGN(4096):
 	{
 		CPUDIR/start.o (.text*)
 	}
@@ -36,9 +36,12 @@  SECTIONS
                 __efi_runtime_stop = .;
 	}
 
-	.text_rest :
+	.text_rest ALIGN(4096) :
 	{
+		__text_start = .;
 		*(.text*)
+		. = ALIGN(4096);
+		__text_end = .;
 	}
 
 #ifdef CONFIG_ARMV8_PSCI
@@ -98,18 +101,20 @@  SECTIONS
 	}
 #endif
 
-	. = ALIGN(8);
-	.rodata : { *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*))) }
+	.rodata ALIGN(4096): {
+	    __start_rodata = .;
+	    *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*)))
+	    . = ALIGN(4096);
+	    __end_rodata = .;
+	}
 
-	. = ALIGN(8);
-	.data : {
+	.data ALIGN(4096) : {
+	    __start_data = .;
 		*(.data*)
+	    . = ALIGN(4096);
+	    __end_data = .;
 	}
 
-	. = ALIGN(8);
-
-	. = .;
-
 	. = ALIGN(8);
 	__u_boot_list : {
 		KEEP(*(SORT(__u_boot_list*)));
@@ -136,10 +141,10 @@  SECTIONS
 	/*
 	 * arch/arm/lib/crt0_64.S assumes __bss_start - __bss_end % 8 == 0
 	 */
-	.bss ALIGN(8) : {
+	.bss ALIGN(4096) : {
 		__bss_start = .;
 		*(.bss*)
-		. = ALIGN(8);
+		. = ALIGN(4096);
 		__bss_end = .;
 	}
 
diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index 3fd5c772a1af..024b1adde270 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -23,6 +23,7 @@  extern char __kprobes_text_start[], __kprobes_text_end[];
 extern char __entry_text_start[], __entry_text_end[];
 extern char __initdata_begin[], __initdata_end[];
 extern char __start_rodata[], __end_rodata[];
+extern char __start_data[], __end_data[];
 extern char __efi_helloworld_begin[];
 extern char __efi_helloworld_end[];
 extern char __efi_var_file_begin[];
@@ -63,6 +64,7 @@  static inline int arch_is_kernel_data(unsigned long addr)
 
 /* Start of U-Boot text region */
 extern char __text_start[];
+extern char __text_end[];
 
 /* This marks the text region which must be relocated */
 extern char __image_copy_start[], __image_copy_end[];