Re: [PATCH v1 05/10] MIPS: add kexec ELF loading support
On Thu, May 17, 2018 at 12:07:29PM +0200, Oleksij Rempel wrote: > Am 17.05.2018 um 11:56 schrieb Sascha Hauer: > > On Wed, May 16, 2018 at 06:42:28PM +0200, Oleksij Rempel wrote: > >> From: Antony Pavlov> >> > >> Signed-off-by: Antony Pavlov > >> Signed-off-by: Peter Mamonov > >> --- > >> arch/mips/include/asm/elf.h| 8 +- > >> arch/mips/lib/Makefile | 4 + > >> arch/mips/lib/kexec-mach-generic.c | 21 +++ > >> arch/mips/lib/kexec-mips.c | 307 > >> + > >> arch/mips/lib/machine_kexec.h | 21 +++ > >> arch/mips/lib/relocate_kernel.S| 108 + > >> 6 files changed, 468 insertions(+), 1 deletion(-) > >> create mode 100644 arch/mips/lib/kexec-mach-generic.c > >> create mode 100644 arch/mips/lib/kexec-mips.c > >> create mode 100644 arch/mips/lib/machine_kexec.h > >> create mode 100644 arch/mips/lib/relocate_kernel.S > >> > >> +int kexec_load(struct image_data *data, void *entry, > >> + unsigned long nr_segments, > >> + struct kexec_segment *segments) > >> +{ > >> + int i; > >> + struct resource *elf; > >> + resource_size_t start; > >> + LIST_HEAD(elf_segments); > >> + > >> + for (i = 0; i < nr_segments; i++) { > >> + resource_size_t mem = (resource_size_t)segments[i].mem; > >> + > >> + elf = create_resource("elf segment", > >> + mem, mem + segments[i].memsz - 1); > >> + > >> + list_add_used_region(>sibling, _segments); > >> + } > >> + > >> + if (check_room_for_elf(_segments)) { > >> + pr_err("ELF can't be loaded!\n"); > >> + return -ENOSPC; > >> + } > >> + > >> + start = dcheck_res(_segments); > >> + > >> + /* relocate_new_kernel() copy by register (4 or 8 bytes) > >> + so start address must be aligned to 4/8 */ > >> + start = (start + 15) & 0xfff0; > >> + > >> + for (i = 0; i < nr_segments; i++) { > >> + segments[i].mem = (void *)(phys_to_virt((unsigned > >> long)segments[i].mem)); > >> + memcpy(phys_to_virt(start), segments[i].buf, segments[i].bufsz); > >> + request_sdram_region("kexec relocatable segment", > >> + (unsigned long)phys_to_virt(start), > >> + (unsigned long)segments[i].bufsz); > > > > The return value of request_sdram_region should be checked and of course > > the resource should be used after having checked the return value, not > > before. Same for the other calls to request_sdram_region. > > Will it be enough for initial inclusion? No, to merge it I need the feeling that this code is understood, not in the works-for-me state. 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- | ___ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH v1 05/10] MIPS: add kexec ELF loading support
Am 17.05.2018 um 11:56 schrieb Sascha Hauer: > On Wed, May 16, 2018 at 06:42:28PM +0200, Oleksij Rempel wrote: >> From: Antony Pavlov>> >> Signed-off-by: Antony Pavlov >> Signed-off-by: Peter Mamonov >> --- >> arch/mips/include/asm/elf.h| 8 +- >> arch/mips/lib/Makefile | 4 + >> arch/mips/lib/kexec-mach-generic.c | 21 +++ >> arch/mips/lib/kexec-mips.c | 307 >> + >> arch/mips/lib/machine_kexec.h | 21 +++ >> arch/mips/lib/relocate_kernel.S| 108 + >> 6 files changed, 468 insertions(+), 1 deletion(-) >> create mode 100644 arch/mips/lib/kexec-mach-generic.c >> create mode 100644 arch/mips/lib/kexec-mips.c >> create mode 100644 arch/mips/lib/machine_kexec.h >> create mode 100644 arch/mips/lib/relocate_kernel.S >> >> +int kexec_load(struct image_data *data, void *entry, >> + unsigned long nr_segments, >> + struct kexec_segment *segments) >> +{ >> +int i; >> +struct resource *elf; >> +resource_size_t start; >> +LIST_HEAD(elf_segments); >> + >> +for (i = 0; i < nr_segments; i++) { >> +resource_size_t mem = (resource_size_t)segments[i].mem; >> + >> +elf = create_resource("elf segment", >> +mem, mem + segments[i].memsz - 1); >> + >> +list_add_used_region(>sibling, _segments); >> +} >> + >> +if (check_room_for_elf(_segments)) { >> +pr_err("ELF can't be loaded!\n"); >> +return -ENOSPC; >> +} >> + >> +start = dcheck_res(_segments); >> + >> +/* relocate_new_kernel() copy by register (4 or 8 bytes) >> + so start address must be aligned to 4/8 */ >> +start = (start + 15) & 0xfff0; >> + >> +for (i = 0; i < nr_segments; i++) { >> +segments[i].mem = (void *)(phys_to_virt((unsigned >> long)segments[i].mem)); >> +memcpy(phys_to_virt(start), segments[i].buf, segments[i].bufsz); >> +request_sdram_region("kexec relocatable segment", >> +(unsigned long)phys_to_virt(start), >> +(unsigned long)segments[i].bufsz); > > The return value of request_sdram_region should be checked and of course > the resource should be used after having checked the return value, not > before. Same for the other calls to request_sdram_region. Will it be enough for initial inclusion? -- Regards, Oleksij signature.asc Description: OpenPGP digital signature ___ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH v1 05/10] MIPS: add kexec ELF loading support
On Wed, May 16, 2018 at 06:42:28PM +0200, Oleksij Rempel wrote: > From: Antony Pavlov> > Signed-off-by: Antony Pavlov > Signed-off-by: Peter Mamonov > --- > arch/mips/include/asm/elf.h| 8 +- > arch/mips/lib/Makefile | 4 + > arch/mips/lib/kexec-mach-generic.c | 21 +++ > arch/mips/lib/kexec-mips.c | 307 > + > arch/mips/lib/machine_kexec.h | 21 +++ > arch/mips/lib/relocate_kernel.S| 108 + > 6 files changed, 468 insertions(+), 1 deletion(-) > create mode 100644 arch/mips/lib/kexec-mach-generic.c > create mode 100644 arch/mips/lib/kexec-mips.c > create mode 100644 arch/mips/lib/machine_kexec.h > create mode 100644 arch/mips/lib/relocate_kernel.S > > +int kexec_load(struct image_data *data, void *entry, > +unsigned long nr_segments, > +struct kexec_segment *segments) > +{ > + int i; > + struct resource *elf; > + resource_size_t start; > + LIST_HEAD(elf_segments); > + > + for (i = 0; i < nr_segments; i++) { > + resource_size_t mem = (resource_size_t)segments[i].mem; > + > + elf = create_resource("elf segment", > + mem, mem + segments[i].memsz - 1); > + > + list_add_used_region(>sibling, _segments); > + } > + > + if (check_room_for_elf(_segments)) { > + pr_err("ELF can't be loaded!\n"); > + return -ENOSPC; > + } > + > + start = dcheck_res(_segments); > + > + /* relocate_new_kernel() copy by register (4 or 8 bytes) > +so start address must be aligned to 4/8 */ > + start = (start + 15) & 0xfff0; > + > + for (i = 0; i < nr_segments; i++) { > + segments[i].mem = (void *)(phys_to_virt((unsigned > long)segments[i].mem)); > + memcpy(phys_to_virt(start), segments[i].buf, segments[i].bufsz); > + request_sdram_region("kexec relocatable segment", > + (unsigned long)phys_to_virt(start), > + (unsigned long)segments[i].bufsz); The return value of request_sdram_region should be checked and of course the resource should be used after having checked the return value, not before. Same for the other calls to request_sdram_region. 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- | ___ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox