diff mbox series

[MIPS] Place __kernel_entry at the beginning of text section

Message ID 20241125230953.3090508-1-xur@google.com (mailing list archive)
State Superseded
Headers show
Series [MIPS] Place __kernel_entry at the beginning of text section | expand

Commit Message

Rong Xu Nov. 25, 2024, 11:09 p.m. UTC
Mark __kernel_entry as ".head.text" and place HEAD_TEXT before
TEXT_TEXT in the linker script. This ensures that __kernel_entry
will be placed at the beginning of text section.

Drop mips from scripts/head-object-list.txt.

Signed-off-by: Rong Xu <xur@google.com>
Reported-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
 arch/mips/kernel/head.S        | 1 +
 arch/mips/kernel/vmlinux.lds.S | 1 +
 scripts/head-object-list.txt   | 1 -
 3 files changed, 2 insertions(+), 1 deletion(-)


base-commit: 3596c721c4348b2a964e43f9296a0c01509ba927

Comments

Chris Packham Nov. 25, 2024, 11:42 p.m. UTC | #1
On 26/11/24 12:09, Rong Xu wrote:
> Mark __kernel_entry as ".head.text" and place HEAD_TEXT before
> TEXT_TEXT in the linker script. This ensures that __kernel_entry
> will be placed at the beginning of text section.
>
> Drop mips from scripts/head-object-list.txt.
>
> Signed-off-by: Rong Xu <xur@google.com>
> Reported-by: Chris Packham <chris.packham@alliedtelesis.co.nz>

Works for me on my RTL9302C based board

Tested-by: Chris Packham <chris.packham@alliedtelesis.co.nz>

> ---
>   arch/mips/kernel/head.S        | 1 +
>   arch/mips/kernel/vmlinux.lds.S | 1 +
>   scripts/head-object-list.txt   | 1 -
>   3 files changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/mips/kernel/head.S b/arch/mips/kernel/head.S
> index e90695b2b60e..6d5fc498c6f9 100644
> --- a/arch/mips/kernel/head.S
> +++ b/arch/mips/kernel/head.S
> @@ -26,6 +26,7 @@
>   
>   #include <kernel-entry-init.h>
>   
> +	__HEAD

I'm not and expert on any of this but... should this go below the 
setup_c0_status_* macros (just before the CONFIG_NO_EXCEPT_FILL) line? I 
don't think it makes any actual difference but as a reader it feels more 
logical that the __HEAD annotation is applying to the .fill and 
__kernel_entry.

>   	/*
>   	 * For the moment disable interrupts, mark the kernel mode and
>   	 * set ST0_KX so that the CPU does not spit fire when using
> diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
> index d575f945d422..c9c1ba85ac7b 100644
> --- a/arch/mips/kernel/vmlinux.lds.S
> +++ b/arch/mips/kernel/vmlinux.lds.S
> @@ -62,6 +62,7 @@ SECTIONS
>   	_text = .;	/* Text and read-only data */
>   	_stext = .;
>   	.text : {
> +		HEAD_TEXT
>   		TEXT_TEXT
>   		SCHED_TEXT
>   		LOCK_TEXT
> diff --git a/scripts/head-object-list.txt b/scripts/head-object-list.txt
> index fd5d00bac447..f12b4a7b8406 100644
> --- a/scripts/head-object-list.txt
> +++ b/scripts/head-object-list.txt
> @@ -23,7 +23,6 @@ arch/m68k/coldfire/head.o
>   arch/m68k/kernel/head.o
>   arch/m68k/kernel/sun3-head.o
>   arch/microblaze/kernel/head.o
> -arch/mips/kernel/head.o
>   arch/nios2/kernel/head.o
>   arch/openrisc/kernel/head.o
>   arch/parisc/kernel/head.o
>
> base-commit: 3596c721c4348b2a964e43f9296a0c01509ba927
Masahiro Yamada Nov. 26, 2024, 3:42 a.m. UTC | #2
On Tue, Nov 26, 2024 at 8:42 AM Chris Packham
<chris.packham@alliedtelesis.co.nz> wrote:
>
>
> On 26/11/24 12:09, Rong Xu wrote:
> > Mark __kernel_entry as ".head.text" and place HEAD_TEXT before
> > TEXT_TEXT in the linker script. This ensures that __kernel_entry
> > will be placed at the beginning of text section.
> >
> > Drop mips from scripts/head-object-list.txt.
> >
> > Signed-off-by: Rong Xu <xur@google.com>
> > Reported-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
>
> Works for me on my RTL9302C based board
>
> Tested-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
>
> > ---
> >   arch/mips/kernel/head.S        | 1 +
> >   arch/mips/kernel/vmlinux.lds.S | 1 +
> >   scripts/head-object-list.txt   | 1 -
> >   3 files changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/mips/kernel/head.S b/arch/mips/kernel/head.S
> > index e90695b2b60e..6d5fc498c6f9 100644
> > --- a/arch/mips/kernel/head.S
> > +++ b/arch/mips/kernel/head.S
> > @@ -26,6 +26,7 @@
> >
> >   #include <kernel-entry-init.h>
> >
> > +     __HEAD
>
> I'm not and expert on any of this but... should this go below the
> setup_c0_status_* macros (just before the CONFIG_NO_EXCEPT_FILL) line? I
> don't think it makes any actual difference but as a reader it feels more
> logical that the __HEAD annotation is applying to the .fill and
> __kernel_entry.


Agree.

Having __HEAD right before the allocated code would be better.


We have one more section marker, __REF, some lines below.
This is placed right before the affected code.


Rong, could please send v2 as Chris suggested?

Then, I will insert this to my tree to avoid regression.

I will drop the previous commit
(MIPS: move _stext definition to vmlinux.lds.S).
It changed the location of _stext when
CONFIG_NO_EXCEPT_FILL is disabled.

Thanks.




>
> >       /*
> >        * For the moment disable interrupts, mark the kernel mode and
> >        * set ST0_KX so that the CPU does not spit fire when using
> > diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
> > index d575f945d422..c9c1ba85ac7b 100644
> > --- a/arch/mips/kernel/vmlinux.lds.S
> > +++ b/arch/mips/kernel/vmlinux.lds.S
> > @@ -62,6 +62,7 @@ SECTIONS
> >       _text = .;      /* Text and read-only data */
> >       _stext = .;
> >       .text : {
> > +             HEAD_TEXT
> >               TEXT_TEXT
> >               SCHED_TEXT
> >               LOCK_TEXT
> > diff --git a/scripts/head-object-list.txt b/scripts/head-object-list.txt
> > index fd5d00bac447..f12b4a7b8406 100644
> > --- a/scripts/head-object-list.txt
> > +++ b/scripts/head-object-list.txt
> > @@ -23,7 +23,6 @@ arch/m68k/coldfire/head.o
> >   arch/m68k/kernel/head.o
> >   arch/m68k/kernel/sun3-head.o
> >   arch/microblaze/kernel/head.o
> > -arch/mips/kernel/head.o
> >   arch/nios2/kernel/head.o
> >   arch/openrisc/kernel/head.o
> >   arch/parisc/kernel/head.o
> >
> > base-commit: 3596c721c4348b2a964e43f9296a0c01509ba927
Rong Xu Nov. 26, 2024, 5:36 p.m. UTC | #3
Thanks Masahiro and Chris for the review!

I just sent out patch v2. I verified that v2 has pretty much the same
layout (except for
some debug info caused layout changes).

-Rong

On Mon, Nov 25, 2024 at 7:43 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> On Tue, Nov 26, 2024 at 8:42 AM Chris Packham
> <chris.packham@alliedtelesis.co.nz> wrote:
> >
> >
> > On 26/11/24 12:09, Rong Xu wrote:
> > > Mark __kernel_entry as ".head.text" and place HEAD_TEXT before
> > > TEXT_TEXT in the linker script. This ensures that __kernel_entry
> > > will be placed at the beginning of text section.
> > >
> > > Drop mips from scripts/head-object-list.txt.
> > >
> > > Signed-off-by: Rong Xu <xur@google.com>
> > > Reported-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
> >
> > Works for me on my RTL9302C based board
> >
> > Tested-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
> >
> > > ---
> > >   arch/mips/kernel/head.S        | 1 +
> > >   arch/mips/kernel/vmlinux.lds.S | 1 +
> > >   scripts/head-object-list.txt   | 1 -
> > >   3 files changed, 2 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/arch/mips/kernel/head.S b/arch/mips/kernel/head.S
> > > index e90695b2b60e..6d5fc498c6f9 100644
> > > --- a/arch/mips/kernel/head.S
> > > +++ b/arch/mips/kernel/head.S
> > > @@ -26,6 +26,7 @@
> > >
> > >   #include <kernel-entry-init.h>
> > >
> > > +     __HEAD
> >
> > I'm not and expert on any of this but... should this go below the
> > setup_c0_status_* macros (just before the CONFIG_NO_EXCEPT_FILL) line? I
> > don't think it makes any actual difference but as a reader it feels more
> > logical that the __HEAD annotation is applying to the .fill and
> > __kernel_entry.
>
>
> Agree.
>
> Having __HEAD right before the allocated code would be better.
>
>
> We have one more section marker, __REF, some lines below.
> This is placed right before the affected code.
>
>
> Rong, could please send v2 as Chris suggested?
>
> Then, I will insert this to my tree to avoid regression.
>
> I will drop the previous commit
> (MIPS: move _stext definition to vmlinux.lds.S).
> It changed the location of _stext when
> CONFIG_NO_EXCEPT_FILL is disabled.
>
> Thanks.
>
>
>
>
> >
> > >       /*
> > >        * For the moment disable interrupts, mark the kernel mode and
> > >        * set ST0_KX so that the CPU does not spit fire when using
> > > diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
> > > index d575f945d422..c9c1ba85ac7b 100644
> > > --- a/arch/mips/kernel/vmlinux.lds.S
> > > +++ b/arch/mips/kernel/vmlinux.lds.S
> > > @@ -62,6 +62,7 @@ SECTIONS
> > >       _text = .;      /* Text and read-only data */
> > >       _stext = .;
> > >       .text : {
> > > +             HEAD_TEXT
> > >               TEXT_TEXT
> > >               SCHED_TEXT
> > >               LOCK_TEXT
> > > diff --git a/scripts/head-object-list.txt b/scripts/head-object-list.txt
> > > index fd5d00bac447..f12b4a7b8406 100644
> > > --- a/scripts/head-object-list.txt
> > > +++ b/scripts/head-object-list.txt
> > > @@ -23,7 +23,6 @@ arch/m68k/coldfire/head.o
> > >   arch/m68k/kernel/head.o
> > >   arch/m68k/kernel/sun3-head.o
> > >   arch/microblaze/kernel/head.o
> > > -arch/mips/kernel/head.o
> > >   arch/nios2/kernel/head.o
> > >   arch/openrisc/kernel/head.o
> > >   arch/parisc/kernel/head.o
> > >
> > > base-commit: 3596c721c4348b2a964e43f9296a0c01509ba927
>
>
>
> --
> Best Regards
> Masahiro Yamada
diff mbox series

Patch

diff --git a/arch/mips/kernel/head.S b/arch/mips/kernel/head.S
index e90695b2b60e..6d5fc498c6f9 100644
--- a/arch/mips/kernel/head.S
+++ b/arch/mips/kernel/head.S
@@ -26,6 +26,7 @@ 
 
 #include <kernel-entry-init.h>
 
+	__HEAD
 	/*
 	 * For the moment disable interrupts, mark the kernel mode and
 	 * set ST0_KX so that the CPU does not spit fire when using
diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
index d575f945d422..c9c1ba85ac7b 100644
--- a/arch/mips/kernel/vmlinux.lds.S
+++ b/arch/mips/kernel/vmlinux.lds.S
@@ -62,6 +62,7 @@  SECTIONS
 	_text = .;	/* Text and read-only data */
 	_stext = .;
 	.text : {
+		HEAD_TEXT
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
diff --git a/scripts/head-object-list.txt b/scripts/head-object-list.txt
index fd5d00bac447..f12b4a7b8406 100644
--- a/scripts/head-object-list.txt
+++ b/scripts/head-object-list.txt
@@ -23,7 +23,6 @@  arch/m68k/coldfire/head.o
 arch/m68k/kernel/head.o
 arch/m68k/kernel/sun3-head.o
 arch/microblaze/kernel/head.o
-arch/mips/kernel/head.o
 arch/nios2/kernel/head.o
 arch/openrisc/kernel/head.o
 arch/parisc/kernel/head.o