2020-05-27 10:05:04

by Jiaxun Yang

[permalink] [raw]
Subject: [PATCH v2 0/3] Buggy bootloader workaround v2

v2: Fixed typo due to keyboard failure.

Jiaxun Yang (3):
MIPS: head.S: Always jump to kernel_entry at head of text
MIPS: Move kernel head into a standalone section
MIPS: Loongson64: select NO_EXCEPT_FILL

arch/mips/Kconfig | 1 +
arch/mips/kernel/head.S | 6 ++----
arch/mips/kernel/vmlinux.lds.S | 8 ++++++--
3 files changed, 9 insertions(+), 6 deletions(-)

--
2.27.0.rc0


2020-05-27 10:05:23

by Jiaxun Yang

[permalink] [raw]
Subject: [PATCH v2 2/3] MIPS: Move kernel head into a standalone section

That's what already done by Arm64 and other architectures.
That would allow us put more things like PE headers safely into
the header.

Signed-off-by: Jiaxun Yang <[email protected]>
---
arch/mips/kernel/head.S | 4 ++--
arch/mips/kernel/vmlinux.lds.S | 8 ++++++--
2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/arch/mips/kernel/head.S b/arch/mips/kernel/head.S
index c7c2795837e7..8081a905a71c 100644
--- a/arch/mips/kernel/head.S
+++ b/arch/mips/kernel/head.S
@@ -59,6 +59,8 @@
#endif
.endm

+ __HEAD
+_head:
#ifndef CONFIG_NO_EXCEPT_FILL
/*
* Reserved space for exception handlers.
@@ -67,8 +69,6 @@
.fill 0x400
#endif

-EXPORT(_stext)
-
/*
* Give us a fighting chance of running if execution beings at the
* kernel load address. This is needed because this platform does
diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
index f185a85a27c1..b9ace667b82b 100644
--- a/arch/mips/kernel/vmlinux.lds.S
+++ b/arch/mips/kernel/vmlinux.lds.S
@@ -57,8 +57,12 @@ SECTIONS
#endif
. = LINKER_LOAD_ADDRESS;
/* read-only */
- _text = .; /* Text and read-only data */
- .text : {
+ .head.text : {
+ _text = .;
+ HEAD_TEXT
+ }
+ .text : { /* Real text segment */
+ _stext = .; /* Text and read-only data */
TEXT_TEXT
SCHED_TEXT
CPUIDLE_TEXT
--
2.27.0.rc0

2020-05-27 10:05:48

by Jiaxun Yang

[permalink] [raw]
Subject: [PATCH v2 3/3] MIPS: Loongson64: select NO_EXCEPT_FILL

Loongson64 load kernel at 0x82000000 and allocate exception vectors
by ebase. So we don't need to reserve space for exception vectors
at head of kernel.

Signed-off-by: Jiaxun Yang <[email protected]>
---
arch/mips/Kconfig | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 3ca59b610a67..0e385f7b7691 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -462,6 +462,7 @@ config MACH_LOONGSON64
select IRQ_MIPS_CPU
select NR_CPUS_DEFAULT_64
select USE_GENERIC_EARLY_PRINTK_8250
+ select NO_EXCEPT_FILL
select SYS_HAS_CPU_LOONGSON64
select SYS_HAS_EARLY_PRINTK
select SYS_SUPPORTS_SMP
--
2.27.0.rc0

2020-05-27 10:20:39

by Jiaxun Yang

[permalink] [raw]
Subject: [PATCH v2 1/3] MIPS: head.S: Always jump to kernel_entry at head of text

Buggy loaders like early version of PMON2000 sometimes ignore
elf_entry and goto start of text directly.

That would help with dealing with these loaders.

Signed-off-by: Jiaxun Yang <[email protected]>
---
arch/mips/kernel/head.S | 2 --
1 file changed, 2 deletions(-)

diff --git a/arch/mips/kernel/head.S b/arch/mips/kernel/head.S
index 3b02ffe46304..c7c2795837e7 100644
--- a/arch/mips/kernel/head.S
+++ b/arch/mips/kernel/head.S
@@ -69,7 +69,6 @@

EXPORT(_stext)

-#ifdef CONFIG_BOOT_RAW
/*
* Give us a fighting chance of running if execution beings at the
* kernel load address. This is needed because this platform does
@@ -77,7 +76,6 @@ EXPORT(_stext)
*/
FEXPORT(__kernel_entry)
j kernel_entry
-#endif /* CONFIG_BOOT_RAW */

__REF

--
2.27.0.rc0

2020-05-27 15:48:34

by Thomas Bogendoerfer

[permalink] [raw]
Subject: Re: [PATCH v2 3/3] MIPS: Loongson64: select NO_EXCEPT_FILL

On Wed, May 27, 2020 at 02:34:34PM +0800, Jiaxun Yang wrote:
> Loongson64 load kernel at 0x82000000 and allocate exception vectors
> by ebase. So we don't need to reserve space for exception vectors
> at head of kernel.
>
> Signed-off-by: Jiaxun Yang <[email protected]>
> ---
> arch/mips/Kconfig | 1 +
> 1 file changed, 1 insertion(+)

applied to mips-next.

Thomas.

--
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea. [ RFC1925, 2.3 ]

2020-05-27 15:49:48

by Jiaxun Yang

[permalink] [raw]
Subject: Re: [PATCH v2 2/3] MIPS: Move kernel head into a standalone section

On Wed, 27 May 2020 13:53:54 +0200
Thomas Bogendoerfer <[email protected]> wrote:

> On Wed, May 27, 2020 at 02:34:33PM +0800, Jiaxun Yang wrote:
> > That's what already done by Arm64 and other architectures.
> > That would allow us put more things like PE headers safely into
> > the header.
> >
> > Signed-off-by: Jiaxun Yang <[email protected]>
> > ---
> > arch/mips/kernel/head.S | 4 ++--
> > arch/mips/kernel/vmlinux.lds.S | 8 ++++++--
> > 2 files changed, 8 insertions(+), 4 deletions(-)
> >
> > diff --git a/arch/mips/kernel/head.S b/arch/mips/kernel/head.S
> > index c7c2795837e7..8081a905a71c 100644
> > --- a/arch/mips/kernel/head.S
> > +++ b/arch/mips/kernel/head.S
> > @@ -59,6 +59,8 @@
> > #endif
> > .endm
> >
> > + __HEAD
> > +_head:
> > #ifndef CONFIG_NO_EXCEPT_FILL
> > /*
> > * Reserved space for exception handlers.
>
> I'm adding the missing piece, why this change ist broken:
>
> * Necessary for machines which link their kernels at KSEG0.
>
> by putting something in front of that will probably break platforms
> making use of "feature". If we can make sure, we don't need it
> anymore, we should first remove this and then add __HEAD part.

__HEAD is just marking the section of code.
It will not add anything to the binary.

Btw: I just noticed this patch may break relocatable kernel. I'll delay
it for next merge window.

Thanks.

>
> Thomas.
>

--
Jiaxun Yang

2020-05-27 15:53:26

by Thomas Bogendoerfer

[permalink] [raw]
Subject: Re: [PATCH v2 2/3] MIPS: Move kernel head into a standalone section

On Wed, May 27, 2020 at 08:05:22PM +0800, Jiaxun Yang wrote:
> On Wed, 27 May 2020 13:53:54 +0200
> Thomas Bogendoerfer <[email protected]> wrote:
>
> > On Wed, May 27, 2020 at 02:34:33PM +0800, Jiaxun Yang wrote:
> > > That's what already done by Arm64 and other architectures.
> > > That would allow us put more things like PE headers safely into
> > > the header.
> > >
> > > Signed-off-by: Jiaxun Yang <[email protected]>
> > > ---
> > > arch/mips/kernel/head.S | 4 ++--
> > > arch/mips/kernel/vmlinux.lds.S | 8 ++++++--
> > > 2 files changed, 8 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/arch/mips/kernel/head.S b/arch/mips/kernel/head.S
> > > index c7c2795837e7..8081a905a71c 100644
> > > --- a/arch/mips/kernel/head.S
> > > +++ b/arch/mips/kernel/head.S
> > > @@ -59,6 +59,8 @@
> > > #endif
> > > .endm
> > >
> > > + __HEAD
> > > +_head:
> > > #ifndef CONFIG_NO_EXCEPT_FILL
> > > /*
> > > * Reserved space for exception handlers.
> >
> > I'm adding the missing piece, why this change ist broken:
> >
> > * Necessary for machines which link their kernels at KSEG0.
> >
> > by putting something in front of that will probably break platforms
> > making use of "feature". If we can make sure, we don't need it
> > anymore, we should first remove this and then add __HEAD part.
>
> __HEAD is just marking the section of code.
> It will not add anything to the binary.

oops, should have looked it up first. You mentioned PE headers and
I thought it will be added this way.

> Btw: I just noticed this patch may break relocatable kernel. I'll delay
> it for next merge window.

ok.

Thomas.

--
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea. [ RFC1925, 2.3 ]

2020-05-27 17:27:30

by Thomas Bogendoerfer

[permalink] [raw]
Subject: Re: [PATCH v2 2/3] MIPS: Move kernel head into a standalone section

On Wed, May 27, 2020 at 02:34:33PM +0800, Jiaxun Yang wrote:
> That's what already done by Arm64 and other architectures.
> That would allow us put more things like PE headers safely into
> the header.
>
> Signed-off-by: Jiaxun Yang <[email protected]>
> ---
> arch/mips/kernel/head.S | 4 ++--
> arch/mips/kernel/vmlinux.lds.S | 8 ++++++--
> 2 files changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/arch/mips/kernel/head.S b/arch/mips/kernel/head.S
> index c7c2795837e7..8081a905a71c 100644
> --- a/arch/mips/kernel/head.S
> +++ b/arch/mips/kernel/head.S
> @@ -59,6 +59,8 @@
> #endif
> .endm
>
> + __HEAD
> +_head:
> #ifndef CONFIG_NO_EXCEPT_FILL
> /*
> * Reserved space for exception handlers.

I'm adding the missing piece, why this change ist broken:

* Necessary for machines which link their kernels at KSEG0.

by putting something in front of that will probably break platforms making
use of "feature". If we can make sure, we don't need it anymore, we should
first remove this and then add __HEAD part.

Thomas.

--
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea. [ RFC1925, 2.3 ]

2020-05-27 17:27:33

by Thomas Bogendoerfer

[permalink] [raw]
Subject: Re: [PATCH v2 1/3] MIPS: head.S: Always jump to kernel_entry at head of text

On Wed, May 27, 2020 at 02:34:32PM +0800, Jiaxun Yang wrote:
> Buggy loaders like early version of PMON2000 sometimes ignore
> elf_entry and goto start of text directly.

so select BOOT_RAW on those broken platforms, no need for this change.

Thomas.

--
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea. [ RFC1925, 2.3 ]