mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] MIPS: relocate_code: fix relocation area size
@ 2020-01-28 17:53 Peter Mamonov
  2020-01-28 18:29 ` Oleksij Rempel
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Mamonov @ 2020-01-28 17:53 UTC (permalink / raw)
  To: o.rempel; +Cc: barebox, Peter Mamonov

relocate_code() calculates relocation area size as a sum (barebox_image_size +
bss_len). barebox_image_size and bss_len are calculated as (__image_end -
__image_start) and (__bss_stop - __bss_start) respectively. This doesn't take
into account relocation data placed between  __image_end and __bss_start.
However relocation preserves BSS position relative to image start, as if
relocation data is still there. This causes RAM overflow during BSS
initialization in main_entry(). This problem may be hidden due to the alignment
of the `relocaddr`.

Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
---
 arch/mips/lib/reloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/mips/lib/reloc.c b/arch/mips/lib/reloc.c
index 32d776a6a6..41e2d5c75f 100644
--- a/arch/mips/lib/reloc.c
+++ b/arch/mips/lib/reloc.c
@@ -121,7 +121,7 @@ void relocate_code(void *fdt, u32 fdt_size, u32 ram_size)
 	memset(__bss_start, 0, bss_len);
 	cpu_probe();
 
-	length = barebox_image_size + bss_len;
+	length = __bss_stop - __image_start;
 	relocaddr = ALIGN_DOWN(ram_size - length, SZ_64K);
 	relocaddr = KSEG0ADDR(relocaddr);
 	new_stack = relocaddr - MALLOC_SIZE - 16;
-- 
2.24.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] MIPS: relocate_code: fix relocation area size
  2020-01-28 17:53 [PATCH] MIPS: relocate_code: fix relocation area size Peter Mamonov
@ 2020-01-28 18:29 ` Oleksij Rempel
  2020-01-28 20:31   ` Peter Mamonov
  0 siblings, 1 reply; 4+ messages in thread
From: Oleksij Rempel @ 2020-01-28 18:29 UTC (permalink / raw)
  To: Peter Mamonov; +Cc: barebox


[-- Attachment #1.1: Type: text/plain, Size: 1896 bytes --]

On Tue, Jan 28, 2020 at 08:53:07PM +0300, Peter Mamonov wrote:
> relocate_code() calculates relocation area size as a sum (barebox_image_size +
> bss_len). barebox_image_size and bss_len are calculated as (__image_end -
> __image_start) and (__bss_stop - __bss_start) respectively. This doesn't take
> into account relocation data placed between  __image_end and __bss_start.
> However relocation preserves BSS position relative to image start, as if
> relocation data is still there. This causes RAM overflow during BSS
> initialization in main_entry(). This problem may be hidden due to the alignment
> of the `relocaddr`.

Thx! Works on ar9331

Tested-by: Oleksij Rempel <o.rempel@pengutronix.de>

> Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
> ---
>  arch/mips/lib/reloc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/mips/lib/reloc.c b/arch/mips/lib/reloc.c
> index 32d776a6a6..41e2d5c75f 100644
> --- a/arch/mips/lib/reloc.c
> +++ b/arch/mips/lib/reloc.c
> @@ -121,7 +121,7 @@ void relocate_code(void *fdt, u32 fdt_size, u32 ram_size)
>  	memset(__bss_start, 0, bss_len);
>  	cpu_probe();
>  
> -	length = barebox_image_size + bss_len;
> +	length = __bss_stop - __image_start;
>  	relocaddr = ALIGN_DOWN(ram_size - length, SZ_64K);
>  	relocaddr = KSEG0ADDR(relocaddr);
>  	new_stack = relocaddr - MALLOC_SIZE - 16;
> -- 
> 2.24.0
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 149 bytes --]

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] MIPS: relocate_code: fix relocation area size
  2020-01-28 18:29 ` Oleksij Rempel
@ 2020-01-28 20:31   ` Peter Mamonov
  2020-01-29  5:20     ` Oleksij Rempel
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Mamonov @ 2020-01-28 20:31 UTC (permalink / raw)
  To: Oleksij Rempel; +Cc: barebox

On Tue, Jan 28, 2020 at 07:29:51PM +0100, Oleksij Rempel wrote:
> On Tue, Jan 28, 2020 at 08:53:07PM +0300, Peter Mamonov wrote:
> > relocate_code() calculates relocation area size as a sum (barebox_image_size +
> > bss_len). barebox_image_size and bss_len are calculated as (__image_end -
> > __image_start) and (__bss_stop - __bss_start) respectively. This doesn't take
> > into account relocation data placed between  __image_end and __bss_start.
> > However relocation preserves BSS position relative to image start, as if
> > relocation data is still there. This causes RAM overflow during BSS
> > initialization in main_entry(). This problem may be hidden due to the alignment
> > of the `relocaddr`.
> 
> Thx! Works on ar9331

Guess you should squash this patch into "MIPS: remove .bss to __rel_start 
overlay", since it fixes the issue caused by the latter.

Regards,
Peter

> 
> Tested-by: Oleksij Rempel <o.rempel@pengutronix.de>
> 
> > Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
> > ---
> >  arch/mips/lib/reloc.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/arch/mips/lib/reloc.c b/arch/mips/lib/reloc.c
> > index 32d776a6a6..41e2d5c75f 100644
> > --- a/arch/mips/lib/reloc.c
> > +++ b/arch/mips/lib/reloc.c
> > @@ -121,7 +121,7 @@ void relocate_code(void *fdt, u32 fdt_size, u32 ram_size)
> >  	memset(__bss_start, 0, bss_len);
> >  	cpu_probe();
> >  
> > -	length = barebox_image_size + bss_len;
> > +	length = __bss_stop - __image_start;
> >  	relocaddr = ALIGN_DOWN(ram_size - length, SZ_64K);
> >  	relocaddr = KSEG0ADDR(relocaddr);
> >  	new_stack = relocaddr - MALLOC_SIZE - 16;
> > -- 
> > 2.24.0
> > 
> > 
> > _______________________________________________
> > barebox mailing list
> > barebox@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/barebox
> > 
> 
> -- 
> Pengutronix e.K.                           |                             |
> Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] MIPS: relocate_code: fix relocation area size
  2020-01-28 20:31   ` Peter Mamonov
@ 2020-01-29  5:20     ` Oleksij Rempel
  0 siblings, 0 replies; 4+ messages in thread
From: Oleksij Rempel @ 2020-01-29  5:20 UTC (permalink / raw)
  To: Peter Mamonov; +Cc: barebox


[-- Attachment #1.1: Type: text/plain, Size: 2879 bytes --]

On Tue, Jan 28, 2020 at 11:31:06PM +0300, Peter Mamonov wrote:
> On Tue, Jan 28, 2020 at 07:29:51PM +0100, Oleksij Rempel wrote:
> > On Tue, Jan 28, 2020 at 08:53:07PM +0300, Peter Mamonov wrote:
> > > relocate_code() calculates relocation area size as a sum (barebox_image_size +
> > > bss_len). barebox_image_size and bss_len are calculated as (__image_end -
> > > __image_start) and (__bss_stop - __bss_start) respectively. This doesn't take
> > > into account relocation data placed between  __image_end and __bss_start.
> > > However relocation preserves BSS position relative to image start, as if
> > > relocation data is still there. This causes RAM overflow during BSS
> > > initialization in main_entry(). This problem may be hidden due to the alignment
> > > of the `relocaddr`.
> > 
> > Thx! Works on ar9331
> 
> Guess you should squash this patch into "MIPS: remove .bss to __rel_start 
> overlay", since it fixes the issue caused by the latter.

ACK

> Regards,
> Peter
> 
> > 
> > Tested-by: Oleksij Rempel <o.rempel@pengutronix.de>
> > 
> > > Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
> > > ---
> > >  arch/mips/lib/reloc.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/arch/mips/lib/reloc.c b/arch/mips/lib/reloc.c
> > > index 32d776a6a6..41e2d5c75f 100644
> > > --- a/arch/mips/lib/reloc.c
> > > +++ b/arch/mips/lib/reloc.c
> > > @@ -121,7 +121,7 @@ void relocate_code(void *fdt, u32 fdt_size, u32 ram_size)
> > >  	memset(__bss_start, 0, bss_len);
> > >  	cpu_probe();
> > >  
> > > -	length = barebox_image_size + bss_len;
> > > +	length = __bss_stop - __image_start;
> > >  	relocaddr = ALIGN_DOWN(ram_size - length, SZ_64K);
> > >  	relocaddr = KSEG0ADDR(relocaddr);
> > >  	new_stack = relocaddr - MALLOC_SIZE - 16;
> > > -- 
> > > 2.24.0
> > > 
> > > 
> > > _______________________________________________
> > > barebox mailing list
> > > barebox@lists.infradead.org
> > > http://lists.infradead.org/mailman/listinfo/barebox
> > > 
> > 
> > -- 
> > Pengutronix e.K.                           |                             |
> > Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
> > 31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
> > Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
> 
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 149 bytes --]

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-01-29  5:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-28 17:53 [PATCH] MIPS: relocate_code: fix relocation area size Peter Mamonov
2020-01-28 18:29 ` Oleksij Rempel
2020-01-28 20:31   ` Peter Mamonov
2020-01-29  5:20     ` Oleksij Rempel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox