* [RFC 0/2] MIPS: fix code relocation routine @ 2019-06-18 9:38 Antony Pavlov 2019-06-18 9:38 ` [RFC 1/2] MIPS: lib/Makefile: fix whitespaces Antony Pavlov ` (2 more replies) 0 siblings, 3 replies; 5+ messages in thread From: Antony Pavlov @ 2019-06-18 9:38 UTC (permalink / raw) To: barebox; +Cc: Oleksij Rempel At the moment MIPS relocation code routine has at least two problems: 1. the first problem is fixed in the 'MIPS: relocate_code: fix barebox image size' patch from this patchseries. 2. relocate_code() calls flush_cache_all(). flush_cache_all() uses 'struct cpuinfo_mips current_cpu_data' data fields. These data fields are initialized in r4k_cache_init(). However in the current implementation the r4k_cache_init() function is called __AFTER__ relocate_code(). This cache problem can't be discovered via qemu. Antony Pavlov (2): MIPS: lib/Makefile: fix whitespaces MIPS: relocate_code: fix barebox image memcpy() size arch/mips/lib/Makefile | 4 ++-- arch/mips/lib/reloc.c | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) -- 2.20.1 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 5+ messages in thread
* [RFC 1/2] MIPS: lib/Makefile: fix whitespaces 2019-06-18 9:38 [RFC 0/2] MIPS: fix code relocation routine Antony Pavlov @ 2019-06-18 9:38 ` Antony Pavlov 2019-06-18 9:38 ` [RFC 2/2] MIPS: relocate_code: fix barebox image memcpy() size Antony Pavlov 2019-06-20 14:34 ` [RFC 0/2] MIPS: fix code relocation routine Sascha Hauer 2 siblings, 0 replies; 5+ messages in thread From: Antony Pavlov @ 2019-06-18 9:38 UTC (permalink / raw) To: barebox; +Cc: Oleksij Rempel Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> --- arch/mips/lib/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/mips/lib/Makefile b/arch/mips/lib/Makefile index c600f4b533..bdcaef91a7 100644 --- a/arch/mips/lib/Makefile +++ b/arch/mips/lib/Makefile @@ -4,8 +4,8 @@ obj-y += cpu-probe.o lwl-y += end.o obj-y += traps.o obj-y += genex.o -obj-y += reloc.o -obj-y += sections.o +obj-y += reloc.o +obj-y += sections.o obj-y += shutdown.o obj-y += dma-default.o -- 2.20.1 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 5+ messages in thread
* [RFC 2/2] MIPS: relocate_code: fix barebox image memcpy() size 2019-06-18 9:38 [RFC 0/2] MIPS: fix code relocation routine Antony Pavlov 2019-06-18 9:38 ` [RFC 1/2] MIPS: lib/Makefile: fix whitespaces Antony Pavlov @ 2019-06-18 9:38 ` Antony Pavlov 2019-06-18 11:05 ` Oleksij Rempel 2019-06-20 14:34 ` [RFC 0/2] MIPS: fix code relocation routine Sascha Hauer 2 siblings, 1 reply; 5+ messages in thread From: Antony Pavlov @ 2019-06-18 9:38 UTC (permalink / raw) To: barebox; +Cc: Oleksij Rempel In this relocate_code() piece 'length' is greater than 'barebox_image_size': #define MAX_BSS_SIZE SZ_1M ... length = barebox_image_size + MAX_BSS_SIZE; relocaddr = ALIGN_DOWN(ram_size - barebox_image_size, SZ_64K); ... memcpy((void *)relocaddr, __image_start, length); so 'ram_size' overflow occurs during memcpy(). Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> --- arch/mips/lib/reloc.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/arch/mips/lib/reloc.c b/arch/mips/lib/reloc.c index 9756d61666..14ba6167dd 100644 --- a/arch/mips/lib/reloc.c +++ b/arch/mips/lib/reloc.c @@ -40,8 +40,6 @@ #include <linux/sizes.h> #include <asm-generic/memory_layout.h> -#define MAX_BSS_SIZE SZ_1M - void main_entry(void *fdt, u32 fdt_size); void relocate_code(void *fdt, u32 fdt_size, u32 relocaddr); @@ -127,8 +125,10 @@ void relocate_code(void *fdt, u32 fdt_size, u32 ram_size) unsigned int type; long off; - length = barebox_image_size + MAX_BSS_SIZE; - relocaddr = ALIGN_DOWN(ram_size - barebox_image_size, SZ_64K); + bss_len = (unsigned long)&__bss_stop - (unsigned long)__bss_start; + + length = barebox_image_size + bss_len; + relocaddr = ALIGN_DOWN(ram_size - length, SZ_64K); relocaddr = KSEG0ADDR(relocaddr); new_stack = relocaddr - MALLOC_SIZE - 16; @@ -143,7 +143,7 @@ void relocate_code(void *fdt, u32 fdt_size, u32 ram_size) panic("Mis-aligned relocation\n"); /* Copy Barebox to RAM */ - memcpy((void *)relocaddr, __image_start, length); + memcpy((void *)relocaddr, __image_start, barebox_image_size); /* Now apply relocations to the copy in RAM */ buf = __rel_start; @@ -162,7 +162,6 @@ void relocate_code(void *fdt, u32 fdt_size, u32 ram_size) /* Clear the .bss section */ bss_start = (uint8_t *)((unsigned long)__bss_start + off); - bss_len = (unsigned long)&__bss_stop - (unsigned long)__bss_start; memset(bss_start, 0, bss_len); __asm__ __volatile__ ( -- 2.20.1 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC 2/2] MIPS: relocate_code: fix barebox image memcpy() size 2019-06-18 9:38 ` [RFC 2/2] MIPS: relocate_code: fix barebox image memcpy() size Antony Pavlov @ 2019-06-18 11:05 ` Oleksij Rempel 0 siblings, 0 replies; 5+ messages in thread From: Oleksij Rempel @ 2019-06-18 11:05 UTC (permalink / raw) To: Antony Pavlov, barebox; +Cc: Oleksij Rempel Am 18.06.19 um 11:38 schrieb Antony Pavlov: > In this relocate_code() piece 'length' is greater than 'barebox_image_size': > > #define MAX_BSS_SIZE SZ_1M > ... > length = barebox_image_size + MAX_BSS_SIZE; > relocaddr = ALIGN_DOWN(ram_size - barebox_image_size, SZ_64K); > ... > memcpy((void *)relocaddr, __image_start, length); > > so 'ram_size' overflow occurs during memcpy(). > > Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Thenk you! This patch is fixing relocatable barebox for malta-qemu and ihas no regressions on ar9331 DPT-Module! Tested-by: Oleksij Rempel <o.rempel@pengutronix.de> > --- > arch/mips/lib/reloc.c | 11 +++++------ > 1 file changed, 5 insertions(+), 6 deletions(-) > > diff --git a/arch/mips/lib/reloc.c b/arch/mips/lib/reloc.c > index 9756d61666..14ba6167dd 100644 > --- a/arch/mips/lib/reloc.c > +++ b/arch/mips/lib/reloc.c > @@ -40,8 +40,6 @@ > #include <linux/sizes.h> > #include <asm-generic/memory_layout.h> > > -#define MAX_BSS_SIZE SZ_1M > - > void main_entry(void *fdt, u32 fdt_size); > void relocate_code(void *fdt, u32 fdt_size, u32 relocaddr); > > @@ -127,8 +125,10 @@ void relocate_code(void *fdt, u32 fdt_size, u32 ram_size) > unsigned int type; > long off; > > - length = barebox_image_size + MAX_BSS_SIZE; > - relocaddr = ALIGN_DOWN(ram_size - barebox_image_size, SZ_64K); > + bss_len = (unsigned long)&__bss_stop - (unsigned long)__bss_start; > + > + length = barebox_image_size + bss_len; > + relocaddr = ALIGN_DOWN(ram_size - length, SZ_64K); > relocaddr = KSEG0ADDR(relocaddr); > new_stack = relocaddr - MALLOC_SIZE - 16; > > @@ -143,7 +143,7 @@ void relocate_code(void *fdt, u32 fdt_size, u32 ram_size) > panic("Mis-aligned relocation\n"); > > /* Copy Barebox to RAM */ > - memcpy((void *)relocaddr, __image_start, length); > + memcpy((void *)relocaddr, __image_start, barebox_image_size); > > /* Now apply relocations to the copy in RAM */ > buf = __rel_start; > @@ -162,7 +162,6 @@ void relocate_code(void *fdt, u32 fdt_size, u32 ram_size) > > /* Clear the .bss section */ > bss_start = (uint8_t *)((unsigned long)__bss_start + off); > - bss_len = (unsigned long)&__bss_stop - (unsigned long)__bss_start; > memset(bss_start, 0, bss_len); > > __asm__ __volatile__ ( > -- Regards, Oleksij _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC 0/2] MIPS: fix code relocation routine 2019-06-18 9:38 [RFC 0/2] MIPS: fix code relocation routine Antony Pavlov 2019-06-18 9:38 ` [RFC 1/2] MIPS: lib/Makefile: fix whitespaces Antony Pavlov 2019-06-18 9:38 ` [RFC 2/2] MIPS: relocate_code: fix barebox image memcpy() size Antony Pavlov @ 2019-06-20 14:34 ` Sascha Hauer 2 siblings, 0 replies; 5+ messages in thread From: Sascha Hauer @ 2019-06-20 14:34 UTC (permalink / raw) To: Antony Pavlov; +Cc: barebox, Oleksij Rempel On Tue, Jun 18, 2019 at 12:38:31PM +0300, Antony Pavlov wrote: > At the moment MIPS relocation code routine has at least two problems: > > 1. the first problem is fixed in the 'MIPS: relocate_code: fix barebox image size' > patch from this patchseries. > > 2. relocate_code() calls flush_cache_all(). > flush_cache_all() uses 'struct cpuinfo_mips current_cpu_data' data fields. > These data fields are initialized in r4k_cache_init(). > > However in the current implementation the r4k_cache_init() function > is called __AFTER__ relocate_code(). > > This cache problem can't be discovered via qemu. > > Antony Pavlov (2): > MIPS: lib/Makefile: fix whitespaces > MIPS: relocate_code: fix barebox image memcpy() size Applied, thanks Sascha -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 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] 5+ messages in thread
end of thread, other threads:[~2019-06-20 14:34 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2019-06-18 9:38 [RFC 0/2] MIPS: fix code relocation routine Antony Pavlov 2019-06-18 9:38 ` [RFC 1/2] MIPS: lib/Makefile: fix whitespaces Antony Pavlov 2019-06-18 9:38 ` [RFC 2/2] MIPS: relocate_code: fix barebox image memcpy() size Antony Pavlov 2019-06-18 11:05 ` Oleksij Rempel 2019-06-20 14:34 ` [RFC 0/2] MIPS: fix code relocation routine Sascha Hauer
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox