kexec_file_load implementation for PowerPC
Subsystems (4)
cover kexec_file_load implementation for PowerPC
Hello,
This patch series implements the kexec_file_load system call on PowerPC.
It starts by removing an x86 assumption from kexec_file: kexec_add_buffer uses iomem to find reserved memory ranges, but PowerPC uses the memblock subsystem. Hooks are added so that each arch can specify how memory ranges can be found.
Also, the memory-walking logic in kexec_add_buffer is useful in this implementation to find a free area for the purgatory's stack, so that same patch moves that logic to kexec_locate_mem_hole.
The kexec_file_load system call needs to apply relocations to the purgatory but adding code for that would duplicate functionality with the module loading mechanism, which also needs to apply relocations to the kernel modules. Therefore, this patch series factors out the module relocation code so that it can be shared.
One thing that is still missing is crashkernel support, which I intend to submit shortly.
This code is based on kexec-tools, but with many modifications to adapt it to the kernel environment and facilities. Except the purgatory, which only has minimal changes.
Thiago Jung Bauermann (8):
kexec_file: Remove unused members from struct kexec_buf.
kexec_file: Generalize kexec_add_buffer.
powerpc: Factor out relocation code from module_64.c to elf_util_64.c.
powerpc: Generalize elf64_apply_relocate_add.
powerpc: Add functions to read ELF files of any endianness.
powerpc: Implement kexec_file_load.
powerpc: Add support for loading ELF kernels with kexec_file_load.
powerpc: Add purgatory for kexec_file_load implementation.
arch/powerpc/Kconfig | 13 + arch/powerpc/Makefile | 4 + arch/powerpc/include/asm/elf_util.h | 92 +++++ arch/powerpc/include/asm/kexec_elf_64.h | 10 + arch/powerpc/include/asm/module.h | 14 +- arch/powerpc/include/asm/systbl.h | 1 + arch/powerpc/include/asm/unistd.h | 2 +- arch/powerpc/include/uapi/asm/unistd.h | 1 + arch/powerpc/kernel/Makefile | 7 + arch/powerpc/kernel/elf_util.c | 476 +++++++++++++++++++++++++ arch/powerpc/kernel/elf_util_64.c | 373 ++++++++++++++++++++ arch/powerpc/kernel/kexec_elf_64.c | 564 ++++++++++++++++++++++++++++++ arch/powerpc/kernel/machine_kexec_64.c | 142 ++++++++ arch/powerpc/kernel/module_64.c | 328 +++-------------- arch/powerpc/purgatory/.gitignore | 2 + arch/powerpc/purgatory/Makefile | 36 ++ arch/powerpc/purgatory/console-ppc64.c | 43 +++ arch/powerpc/purgatory/crashdump-ppc64.h | 42 +++ arch/powerpc/purgatory/crashdump_backup.c | 40 +++ arch/powerpc/purgatory/crtsavres.S | 5 + arch/powerpc/purgatory/hvCall.S | 27 ++ arch/powerpc/purgatory/hvCall.h | 8 + arch/powerpc/purgatory/kexec-sha256.h | 11 + arch/powerpc/purgatory/ppc64_asm.h | 18 + arch/powerpc/purgatory/printf.c | 171 +++++++++ arch/powerpc/purgatory/purgatory-ppc64.c | 46 +++ arch/powerpc/purgatory/purgatory-ppc64.h | 6 + arch/powerpc/purgatory/purgatory.c | 66 ++++ arch/powerpc/purgatory/purgatory.h | 11 + arch/powerpc/purgatory/sha256.c | 6 + arch/powerpc/purgatory/sha256.h | 1 + arch/powerpc/purgatory/string.S | 1 + arch/powerpc/purgatory/v2wrap.S | 139 ++++++++ include/linux/kexec.h | 10 + kernel/kexec_file.c | 102 ++++-- kernel/kexec_internal.h | 2 - 36 files changed, 2504 insertions(+), 316 deletions(-) create mode 100644 arch/powerpc/include/asm/elf_util.h create mode 100644 arch/powerpc/include/asm/kexec_elf_64.h create mode 100644 arch/powerpc/kernel/elf_util.c create mode 100644 arch/powerpc/kernel/elf_util_64.c create mode 100644 arch/powerpc/kernel/kexec_elf_64.c create mode 100644 arch/powerpc/purgatory/.gitignore create mode 100644 arch/powerpc/purgatory/Makefile create mode 100644 arch/powerpc/purgatory/console-ppc64.c create mode 100644 arch/powerpc/purgatory/crashdump-ppc64.h create mode 100644 arch/powerpc/purgatory/crashdump_backup.c create mode 100644 arch/powerpc/purgatory/crtsavres.S create mode 100644 arch/powerpc/purgatory/hvCall.S create mode 100644 arch/powerpc/purgatory/hvCall.h create mode 100644 arch/powerpc/purgatory/kexec-sha256.h create mode 100644 arch/powerpc/purgatory/ppc64_asm.h create mode 100644 arch/powerpc/purgatory/printf.c create mode 100644 arch/powerpc/purgatory/purgatory-ppc64.c create mode 100644 arch/powerpc/purgatory/purgatory-ppc64.h create mode 100644 arch/powerpc/purgatory/purgatory.c create mode 100644 arch/powerpc/purgatory/purgatory.h create mode 100644 arch/powerpc/purgatory/sha256.c create mode 100644 arch/powerpc/purgatory/sha256.h create mode 100644 arch/powerpc/purgatory/string.S create mode 100644 arch/powerpc/purgatory/v2wrap.S
Signature · 1 line
1.9.1
PATCH 1/8 kexec_file: Remove unused members from struct kexec_buf.
kexec_add_buffer uses kexec_buf.buffer and kexec_buf.bufsz to pass along its own arguments buffer and bufsz, but since they aren't used anywhere else, it's pointless.
--- kernel/kexec_file.c | 6 ++---- kernel/kexec_internal.h | 2 -- 2 files changed, 2 insertions(+), 6 deletions(-)
kernel/kexec_file.c +2 -4
@@ -464,8 +464,6 @@ int kexec_add_buffer(struct kimage *image, char *buffer, unsigned long bufsz,memset (&buf,0 ,sizeof (struct kexec_buf )); kbuf = &buf; kbuf->image = image; - kbuf->buffer = buffer; - kbuf->bufsz = bufsz; kbuf->memsz =ALIGN (memsz,PAGE_SIZE ); kbuf->buf_align =max (buf_align,PAGE_SIZE );
@@ -489,8 +487,8 @@ int kexec_add_buffer(struct kimage *image, char *buffer, unsigned long bufsz,/* Found a suitable memory range */ ksegment = &image->segment[image->nr_segments]; - ksegment->kbuf = kbuf->buffer; - ksegment->bufsz = kbuf->bufsz; + ksegment->kbuf = buffer; + ksegment->bufsz = bufsz; ksegment->mem = kbuf->mem; ksegment->memsz = kbuf->memsz; image->nr_segments++;
kernel/kexec_internal.h +0 -2
@@ -26,8 +26,6 @@ struct kexec_sha_region {*/ struct kexec_buf {struct kimage *image; -char *buffer; -unsigned long bufsz;unsigned long mem;unsigned long memsz;unsigned long buf_align;
Signature · 1 line
1.9.1
Re: [PATCH 1/8] kexec_file: Remove unused members from struct kexec_buf.
Quoted 57 lines · Thiago Jung Bauermann
kexec_add_bufferuses kexec_buf.buffer and kexec_buf.bufsz to pass along its own arguments buffer and bufsz, but since they aren't used anywhere else, it's pointless.--- kernel/kexec_file.c | 6 ++---- kernel/kexec_internal.h | 2 -- 2 files changed, 2 insertions(+), 6 deletions(-)kernel/kexec_file.c +2
-4@@ -464,8 +464,6 @@ int kexec_add_buffer(struct kimage *image, char *buffer, unsigned long bufsz,memset (&buf,0 ,sizeof (struct kexec_buf )); kbuf = &buf; kbuf->image = image; - kbuf->buffer = buffer; - kbuf->bufsz = bufsz; kbuf->memsz =ALIGN (memsz,PAGE_SIZE ); kbuf->buf_align =max (buf_align,PAGE_SIZE );@@ -489,8 +487,8 @@ int kexec_add_buffer(struct kimage *image, char *buffer, unsigned long bufsz,/* Found a suitable memory range */ ksegment = &image->segment[image->nr_segments]; - ksegment->kbuf = kbuf->buffer; - ksegment->bufsz = kbuf->bufsz; + ksegment->kbuf = buffer; + ksegment->bufsz = bufsz; ksegment->mem = kbuf->mem; ksegment->memsz = kbuf->memsz; image->nr_segments++;kernel/kexec_internal.h +0
-2@@ -26,8 +26,6 @@ struct kexec_sha_region {*/ struct kexec_buf {struct kimage *image; -char *buffer; -unsigned long bufsz;unsigned long mem;unsigned long memsz;unsigned long buf_align;Signature · 7 lines
1.9.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Thanks
Dave
PATCH 2/8 kexec_file: Generalize kexec_add_buffer.
In reply to Thiago Jung BauermannAllow architectures to specify different memory walking functions for kexec_add_buffer. Intel uses iomem to track reserved memory ranges, but PowerPC uses the memblock subsystem.
Also, factor kexec_locate_mem_hole out of kexec_add_buffer. It will be used by the PowerPC kexec_file_load implementation to find free memory for the purgatory stack.
--- include/linux/kexec.h | 10 ++++++ kernel/kexec_file.c | 96 +++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 81 insertions(+), 25 deletions(-)
include/linux/kexec.h +10 -0
@@ -210,6 +210,10 @@ extern asmlinkage long sys_kexec_load(unsigned long entry,struct kexec_segment __user *segments, unsigned long flags);extern int kernel_kexec (void ); +int kexec_locate_mem_hole (struct kimage *image,unsigned long size, +unsigned long align,unsigned long start, +unsigned long end,bool top_down, +unsigned long *addr); extern int kexec_add_buffer(struct kimage *image, char *buffer, unsigned long bufsz, unsigned long memsz, unsigned long buf_align, unsigned long buf_min,
@@ -315,6 +319,12 @@ int __weak arch_kexec_apply_relocations_add(const Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, unsigned int relsec);int __weak arch_kexec_apply_relocations (const Elf_Ehdr *ehdr,Elf_Shdr *sechdrs,unsigned int relsec); +int __weak arch_walk_iomem (unsigned long desc,unsigned long start, +unsigned long end,bool top_down,void *data, +int (*func)(u64 ,u64 ,void *)); +int __weak arch_walk_system_ram (unsigned long start,unsigned long end, +bool top_down,void *data, +int (*func)(u64 ,u64 ,void *));void arch_kexec_protect_crashkres (void );void arch_kexec_unprotect_crashkres (void );
kernel/kexec_file.c +71 -25
121 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [PATCH 2/8] kexec_file: Generalize kexec_add_buffer.
Quoted 7 lines · Thiago Jung Bauermann
Allow architectures to specify different memory walking functions for
kexec_add_buffer. Intel uses iomem to track reserved memory ranges, but PowerPC uses the memblock subsystem.Also, factor
kexec_locate_mem_holeout ofkexec_add_buffer. It will be used by the PowerPCkexec_file_loadimplementation to find free memory for the purgatory stack.
Split factoring locate hole function to another patch will be clearer.
Quoted 173 lines
--- include/linux/kexec.h | 10 ++++++ kernel/kexec_file.c | 96 +++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 81 insertions(+), 25 deletions(-)include/linux/kexec.h +10
-0@@ -210,6 +210,10 @@ extern asmlinkage long sys_kexec_load(unsigned long entry,struct kexec_segment __user *segments, unsigned long flags);extern int kernel_kexec (void ); +int kexec_locate_mem_hole (struct kimage *image,unsigned long size, +unsigned long align,unsigned long start, +unsigned long end,bool top_down, +unsigned long *addr); extern int kexec_add_buffer(struct kimage *image, char *buffer, unsigned long bufsz, unsigned long memsz, unsigned long buf_align, unsigned long buf_min,@@ -315,6 +319,12 @@ int __weak arch_kexec_apply_relocations_add(const Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, unsigned int relsec);int __weak arch_kexec_apply_relocations (const Elf_Ehdr *ehdr,Elf_Shdr *sechdrs,unsigned int relsec); +int __weak arch_walk_iomem (unsigned long desc,unsigned long start, +unsigned long end,bool top_down,void *data, +int (*func)(u64 ,u64 ,void *)); +int __weak arch_walk_system_ram (unsigned long start,unsigned long end, +bool top_down,void *data, +int (*func)(u64 ,u64 ,void *));void arch_kexec_protect_crashkres (void );void arch_kexec_unprotect_crashkres (void );kernel/kexec_file.c +71
-25@@ -428,6 +428,68 @@ static int locate_mem_hole_callback(u64 start, u64 end, void *arg)return locate_mem_hole_bottom_up (start, end, kbuf); } +int __weak arch_walk_iomem (unsigned long desc,unsigned long start, +unsigned long end,bool top_down,void *data, +int (*func)(u64 ,u64 ,void *)) +{ +return walk_iomem_res_desc (desc, +IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY , + start, end, data, func); +} + +int __weak arch_walk_system_ram (unsigned long start,unsigned long end, +bool top_down,void *data, +int (*func)(u64 ,u64 ,void *)) +{ +return walk_system_ram_res (start, end, data, func); +} + +/** +* kexec_locate_mem_hole - find free memory to load segment or use in purgatory +* @image: kexec image being updated. +* @size: Memory size. +* @align: Minimum alignment needed. +* @start: Minimum starting address. +* @end: Maximum end address. +* @top_down Find the highest free memory region? +* @addr On success, will have start address of the memory region found. +* +* Return: 0 on success, negative erro on failure. +*/ +int kexec_locate_mem_hole (struct kimage *image,unsigned long size, +unsigned long align,unsigned long start, +unsigned long end,bool top_down,unsigned long *addr) +{ +int ret; +struct kexec_buf buf; + +memset (&buf,0 ,sizeof (struct kexec_buf )); + buf.image = image; + + buf.memsz = size; + buf.buf_align = align; + buf.buf_min = start; + buf.buf_max = end; + buf.top_down = top_down; + +/* Walk the RAM ranges and allocate a suitable range for the buffer */ +if (image->type ==KEXEC_TYPE_CRASH ) + ret =arch_walk_iomem (crashk_res.desc, crashk_res.start, + crashk_res.end, top_down, &buf, + locate_mem_hole_callback); +else + ret =arch_walk_system_ram (0 ,-1 , top_down, &buf, + locate_mem_hole_callback); +if (ret !=1 ) { +/* A suitable memory range could not be found for buffer */ +return -EADDRNOTAVAIL ; + } + + *addr = buf.mem; + +return 0 ; +} +/* * Helper function for placing a buffer in a kexec segment. This assumes * that kexec_mutex is held. @@ -439,8 +501,8 @@ int kexec_add_buffer(struct kimage *image, char *buffer, unsigned long bufsz, {struct kexec_segment *ksegment; -struct kexec_buf buf, *kbuf;int ret; +unsigned long addr, align, size;/* Currently adding segment this way is allowed only in file mode */ if (!image->file_mode)@@ -461,36 +523,20 @@ int kexec_add_buffer(struct kimage *image, char *buffer, unsigned long bufsz,return -EINVAL ; } -memset (&buf,0 ,sizeof (struct kexec_buf )); - kbuf = &buf; - kbuf->image = image; - - kbuf->memsz =ALIGN (memsz,PAGE_SIZE ); - kbuf->buf_align =max (buf_align,PAGE_SIZE ); - kbuf->buf_min = buf_min; - kbuf->buf_max = buf_max; - kbuf->top_down = top_down; + size =ALIGN (memsz,PAGE_SIZE ); + align =max (buf_align,PAGE_SIZE ); -/* Walk the RAM ranges and allocate a suitable range for the buffer */ -if (image->type ==KEXEC_TYPE_CRASH ) - ret =walk_iomem_res_desc (crashk_res.desc, -IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY , - crashk_res.start, crashk_res.end, kbuf, - locate_mem_hole_callback); -else - ret =walk_system_ram_res (0 ,-1 , kbuf, - locate_mem_hole_callback); -if (ret !=1 ) { -/* A suitable memory range could not be found for buffer */ -return -EADDRNOTAVAIL ; - } + ret =kexec_locate_mem_hole (image, size, align, buf_min, buf_max, + top_down, &addr); +if (ret) +return ret;/* Found a suitable memory range */ ksegment = &image->segment[image->nr_segments]; ksegment->kbuf = buffer; ksegment->bufsz = bufsz; - ksegment->mem = kbuf->mem; - ksegment->memsz = kbuf->memsz; + ksegment->mem = addr; + ksegment->memsz = size; image->nr_segments++; *load_addr = ksegment->mem;return 0 ;Signature · 7 lines
1.9.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 2/8] kexec_file: Generalize kexec_add_buffer.
In reply to Thiago Jung BauermannQuoted 3 lines · Thiago Jung Bauermann
Allow architectures to specify different memory walking functions for
kexec_add_buffer. Intel uses iomem to track reserved memory ranges, but PowerPC uses the memblock subsystem.
Can the crashk_res be inserted to iomem_resource so that only one weak function for system ram is needed?
Quoted 177 lines
Also, factor
kexec_locate_mem_holeout ofkexec_add_buffer. It will be used by the PowerPCkexec_file_loadimplementation to find free memory for the purgatory stack.--- include/linux/kexec.h | 10 ++++++ kernel/kexec_file.c | 96 +++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 81 insertions(+), 25 deletions(-)include/linux/kexec.h +10
-0@@ -210,6 +210,10 @@ extern asmlinkage long sys_kexec_load(unsigned long entry,struct kexec_segment __user *segments, unsigned long flags);extern int kernel_kexec (void ); +int kexec_locate_mem_hole (struct kimage *image,unsigned long size, +unsigned long align,unsigned long start, +unsigned long end,bool top_down, +unsigned long *addr); extern int kexec_add_buffer(struct kimage *image, char *buffer, unsigned long bufsz, unsigned long memsz, unsigned long buf_align, unsigned long buf_min,@@ -315,6 +319,12 @@ int __weak arch_kexec_apply_relocations_add(const Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, unsigned int relsec);int __weak arch_kexec_apply_relocations (const Elf_Ehdr *ehdr,Elf_Shdr *sechdrs,unsigned int relsec); +int __weak arch_walk_iomem (unsigned long desc,unsigned long start, +unsigned long end,bool top_down,void *data, +int (*func)(u64 ,u64 ,void *)); +int __weak arch_walk_system_ram (unsigned long start,unsigned long end, +bool top_down,void *data, +int (*func)(u64 ,u64 ,void *));void arch_kexec_protect_crashkres (void );void arch_kexec_unprotect_crashkres (void );kernel/kexec_file.c +71
-25@@ -428,6 +428,68 @@ static int locate_mem_hole_callback(u64 start, u64 end, void *arg)return locate_mem_hole_bottom_up (start, end, kbuf); } +int __weak arch_walk_iomem (unsigned long desc,unsigned long start, +unsigned long end,bool top_down,void *data, +int (*func)(u64 ,u64 ,void *)) +{ +return walk_iomem_res_desc (desc, +IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY , + start, end, data, func); +} + +int __weak arch_walk_system_ram (unsigned long start,unsigned long end, +bool top_down,void *data, +int (*func)(u64 ,u64 ,void *)) +{ +return walk_system_ram_res (start, end, data, func); +} + +/** +* kexec_locate_mem_hole - find free memory to load segment or use in purgatory +* @image: kexec image being updated. +* @size: Memory size. +* @align: Minimum alignment needed. +* @start: Minimum starting address. +* @end: Maximum end address. +* @top_down Find the highest free memory region? +* @addr On success, will have start address of the memory region found. +* +* Return: 0 on success, negative erro on failure. +*/ +int kexec_locate_mem_hole (struct kimage *image,unsigned long size, +unsigned long align,unsigned long start, +unsigned long end,bool top_down,unsigned long *addr) +{ +int ret; +struct kexec_buf buf; + +memset (&buf,0 ,sizeof (struct kexec_buf )); + buf.image = image; + + buf.memsz = size; + buf.buf_align = align; + buf.buf_min = start; + buf.buf_max = end; + buf.top_down = top_down; + +/* Walk the RAM ranges and allocate a suitable range for the buffer */ +if (image->type ==KEXEC_TYPE_CRASH ) + ret =arch_walk_iomem (crashk_res.desc, crashk_res.start, + crashk_res.end, top_down, &buf, + locate_mem_hole_callback); +else + ret =arch_walk_system_ram (0 ,-1 , top_down, &buf, + locate_mem_hole_callback); +if (ret !=1 ) { +/* A suitable memory range could not be found for buffer */ +return -EADDRNOTAVAIL ; + } + + *addr = buf.mem; + +return 0 ; +} +/* * Helper function for placing a buffer in a kexec segment. This assumes * that kexec_mutex is held. @@ -439,8 +501,8 @@ int kexec_add_buffer(struct kimage *image, char *buffer, unsigned long bufsz, {struct kexec_segment *ksegment; -struct kexec_buf buf, *kbuf;int ret; +unsigned long addr, align, size;/* Currently adding segment this way is allowed only in file mode */ if (!image->file_mode)@@ -461,36 +523,20 @@ int kexec_add_buffer(struct kimage *image, char *buffer, unsigned long bufsz,return -EINVAL ; } -memset (&buf,0 ,sizeof (struct kexec_buf )); - kbuf = &buf; - kbuf->image = image; - - kbuf->memsz =ALIGN (memsz,PAGE_SIZE ); - kbuf->buf_align =max (buf_align,PAGE_SIZE ); - kbuf->buf_min = buf_min; - kbuf->buf_max = buf_max; - kbuf->top_down = top_down; + size =ALIGN (memsz,PAGE_SIZE ); + align =max (buf_align,PAGE_SIZE ); -/* Walk the RAM ranges and allocate a suitable range for the buffer */ -if (image->type ==KEXEC_TYPE_CRASH ) - ret =walk_iomem_res_desc (crashk_res.desc, -IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY , - crashk_res.start, crashk_res.end, kbuf, - locate_mem_hole_callback); -else - ret =walk_system_ram_res (0 ,-1 , kbuf, - locate_mem_hole_callback); -if (ret !=1 ) { -/* A suitable memory range could not be found for buffer */ -return -EADDRNOTAVAIL ; - } + ret =kexec_locate_mem_hole (image, size, align, buf_min, buf_max, + top_down, &addr); +if (ret) +return ret;/* Found a suitable memory range */ ksegment = &image->segment[image->nr_segments]; ksegment->kbuf = buffer; ksegment->bufsz = bufsz; - ksegment->mem = kbuf->mem; - ksegment->memsz = kbuf->memsz; + ksegment->mem = addr; + ksegment->memsz = size; image->nr_segments++; *load_addr = ksegment->mem;return 0 ;Signature · 7 lines
1.9.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 2/8] kexec_file: Generalize kexec_add_buffer.
Hello Dave,
Thanks for the quick review and for your comments.
I'll separate the change to add arch_walk_system_ram and the change to add kexec_locate_mem_hole into different patches, and add error handling for KEXEC_ON_CRASH.
Am Montag, 13 Juni 2016, 15:29:39 schrieb Dave Young:
Quoted 7 lines · Thiago Jung Bauermann
Quoted 3 lines
Allow architectures to specify different memory walking functions for
kexec_add_buffer. Intel uses iomem to track reserved memory ranges, but PowerPC uses the memblock subsystem.Can the
crashk_resbe inserted toiomem_resourceso that only one weak function for system ram is needed?
Sorry, it's not clear to me what you mean by inserting crashk_res into iomem_resource, but I can add a bool for_crashkernel to arch_walk_system_ram so that it can decide which kind of memory to traverse, so the default implementation of kexec_file.c would be:
int __weak arch_walk_system_ram(bool for_crashkernel, unsigned long start,
unsigned long end, bool top_down,
void *data,
int (*func)(u64, u64, void *))
{
int ret;
if (for_crashkernel)
ret = walk_iomem_res_desc(crashk_res.desc,
IORESOURCE_SYSTEM_RAM |
IORESOURCE_BUSY,
start, end, data, func);
else
ret = walk_system_ram_res(start, end, data, func);
if (ret != 1) {
/* A suitable memory range could not be found for buffer */
return -EADDRNOTAVAIL;
}
}and kexec_add_buffer / kexec_locate_mem_hole would call it with:
if (image->type == KEXEC_TYPE_CRASH) ret = arch_walk_system_ram(true, crashk_res.start, crashk_res.end, top_down, &buf, locate_mem_hole_callback); else ret = arch_walk_system_ram(false, 0, -1, top_down, &buf, locate_mem_hole_callback);
What do you think?
Signature · 3 lines
[]'s Thiago Jung Bauermann IBM Linux Technology Center
Re: [PATCH 2/8] kexec_file: Generalize kexec_add_buffer.
Hi Dave,
Am Montag, 13 Juni 2016, 16:08:19 schrieb Thiago Jung Bauermann:
Quoted 6 lines
Am Montag, 13 Juni 2016, 15:29:39 schrieb Dave Young:
Quoted 5 lines · Thiago Jung Bauermann
Quoted 3 lines
Allow architectures to specify different memory walking functions for
kexec_add_buffer. Intel uses iomem to track reserved memory ranges, but PowerPC uses the memblock subsystem.
Quoted 7 lines
Quoted 2 lines
Can the
crashk_resbe inserted toiomem_resourceso that only one weak function for system ram is needed?Sorry, it's not clear to me what you mean by inserting
crashk_resintoiomem_resource, but I can add a boolfor_crashkerneltoarch_walk_system_ramso that it can decide which kind of memory to traverse.
This is the patch implementing that idea. What do you think?
Signature · 15 lines
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
kexec_file: Generalize kexec_add_buffer.
Allow architectures to specify different memory walking functions for
kexec_add_buffer. Intel uses iomem to track reserved memory ranges,
but PowerPC uses the memblock subsystem.
Signed-off-by: Thiago Jung Bauermann <[email protected]>
Cc: Eric Biederman <[email protected]>
Cc: [email protected]
Cc: [email protected]include/linux/kexec.h +3 -0
@@ -315,6 +315,9 @@ int __weak arch_kexec_apply_relocations_add(const Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, unsigned int relsec);int __weak arch_kexec_apply_relocations (const Elf_Ehdr *ehdr,Elf_Shdr *sechdrs,unsigned int relsec); +int __weak arch_walk_system_ram (bool for_crashkernel,unsigned long start, +unsigned long end,bool top_down,void *data, +int (*func)(u64 ,u64 ,void *));void arch_kexec_protect_crashkres (void );void arch_kexec_unprotect_crashkres (void );
kernel/kexec_file.c +39 -10
62 lines not on this page · raw message
Re: [PATCH 2/8] kexec_file: Generalize kexec_add_buffer.
In reply to Thiago Jung BauermannQuoted 10 lines · Thiago Jung Bauermann
Hello Dave,
Thanks for the quick review and for your comments.
I'll separate the change to add
arch_walk_system_ramand the change to addkexec_locate_mem_holeinto different patches, and add error handling forKEXEC_ON_CRASH.Am Montag, 13 Juni 2016, 15:29:39 schrieb Dave Young:
Quoted 1 line · Thiago Jung Bauermann
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Allow architectures to specify different memory walking functions for
kexec_add_buffer. Intel uses iomem to track reserved memory ranges, but PowerPC uses the memblock subsystem.Can the
crashk_resbe inserted toiomem_resourceso that only one weak function for system ram is needed?Sorry, it's not clear to me what you mean by inserting
crashk_resinto
Hmm, I means exporting crashkernel mem to /proc/iomem like other arches It is just oneline:insert_resource(&iomem_resource, &crashk_res)
But your proposal below is also fine.
Quoted 8 lines
iomem_resource, but I can add a boolfor_crashkerneltoarch_walk_system_ramso that it can decide which kind of memory to traverse, so the default implementation ofkexec_file.cwould be:int
__weakarch_walk_system_ram(boolfor_crashkernel, unsigned long start,unsigned long end, bool top_down, void *data, int (*func)(u64, u64, void *))
arch_walk_mem sounds better?
Quoted 27 lines
{ int ret; if (for_crashkernel) ret = walk_iomem_res_desc(crashk_res.desc, IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY, start, end, data, func); else ret = walk_system_ram_res(start, end, data, func); if (ret != 1) { /* A suitable memory range could not be found for buffer */ return -EADDRNOTAVAIL; } }and
kexec_add_buffer/kexec_locate_mem_holewould call it with:if (image->type == KEXEC_TYPE_CRASH) ret = arch_walk_system_ram(true, crashk_res.start, crashk_res.end, top_down, &buf, locate_mem_hole_callback); else ret = arch_walk_system_ram(false, 0, -1, top_down, &buf, locate_mem_hole_callback);
Quoted 1 line
What do you think?
Sounds good, but for_crashkernel can be image_type instead. and image->type can be passed to the arch_walk_mem function directly.
Thanks
Dave
PATCH 3/8 powerpc: Factor out relocation code from module_64.c to elf_util_64.c.
In reply to Thiago Jung BauermannThe kexec_file_load system call needs to relocate the purgatory, so factor out the module relocation code so that it can be shared.
This patch's purpose is to move the ELF relocation logic from apply_relocate_add to elf_util_64.c with as few changes as possible. The following changes were needed:
To avoid having module-specific code in a general purpose utility function, struct elf_info was created to contain the information needed for ELF binaries manipulation.
my_r2, stub_for_addr and create_stub were changed to use it instead of having to receive a struct module, since they are called from elf64_apply_relocate_add.
local_entry_offset and squash_toc_save_inst were only used by apply_rellocate_add, so they were moved to elf_util_64.c as well.
--- arch/powerpc/include/asm/elf_util.h | 70 ++++++++ arch/powerpc/include/asm/module.h | 14 +- arch/powerpc/kernel/Makefile | 4 + arch/powerpc/kernel/elf_util_64.c | 269 +++++++++++++++++++++++++++++++ arch/powerpc/kernel/module_64.c | 312 ++++-------------------------------- 5 files changed, 386 insertions(+), 283 deletions(-)
arch/powerpc/include/asm/elf_util.h new file +70 -0
@@ -0,0 +1,70 @@ +/* +* Utility functions to work with ELF files. +* +* Copyright (C) 2016, IBM Corporation +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2, or (at your option) +* any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _ASM_POWERPC_ELF_UTIL_H +#define _ASM_POWERPC_ELF_UTIL_H + +#include <linux/elf.h> + +struct elf_info { +struct elf_shdr *sechdrs; + +/* Index of stubs section. */ +unsigned int stubs_section; +/* Index of TOC section. */ +unsigned int toc_section; +}; + +#ifdef __powerpc64__ +#if defined(_CALL_ELF) && _CALL_ELF ==2 + +/* An address is simply the address of the function. */ +typedef unsigned long func_desc_t ; +#else + +/* An address is address of the OPD entry, which contains address of fn. */ +typedef struct ppc64_opd_entry func_desc_t ; +#endif + +/* Like PPC32, we need little trampolines to do > 24-bit jumps (into +the kernel itself). But on PPC64, these need to be used for every +jump, actually, to reset r2 (TOC+0x8000). */ +struct ppc64_stub_entry +{ +/* 28 byte jump instruction sequence (7 instructions). We only +* need 6 instructions on ABIv2 but we always allocate 7 so +* so we don't have to modify the trampoline load instruction. */ +u32 jump[7 ]; +/* Used by ftrace to identify stubs */ +u32 magic; +/* Data for the above code */ +func_desc_t funcdata; +}; +#endif + +/* r2 is the TOC pointer: it actually points 0x8000 into the TOC (this +gives the value maximum span in an instruction which uses a signed +offset) */ +static inline unsigned long my_r2 (const struct elf_info *elf_info) +{ +return elf_info->sechdrs[elf_info->toc_section].sh_addr +0x8000 ; +} + +int elf64_apply_relocate_add (const struct elf_info *elf_info, +const char *strtab,unsigned int symindex, +unsigned int relsec,const char *obj_name); + +#endif /* _ASM_POWERPC_ELF_UTIL_H */
arch/powerpc/include/asm/module.h +12 -2
@@ -12,7 +12,14 @@#include <linux/list.h> #include <asm/bug.h> #include <asm-generic/module.h> +#include <asm/elf_util.h> +/* Both low and high 16 bits are added as SIGNED additions, so if low +16 bits has high bit set, high 16 bits must be adjusted. These +macros do that (stolen from binutils). */ +#define PPC_LO (v) ((v) & 0xffff) +#define PPC_HI (v) (((v) >> 16) & 0xffff) +#define PPC_HA (v) PPC_HI ((v) + 0x8000)#ifndef __powerpc64__/*
@@ -33,8 +40,7 @@ struct ppc_plt_entry {struct mod_arch_specific {#ifdef __powerpc64__ -unsigned int stubs_section;/* Index of stubs section in module */ -unsigned int toc_section;/* What section is the TOC? */ +struct elf_info elf_info;bool toc_fixed;/* Have we fixed up .TOC.? */ #ifdef CONFIG_DYNAMIC_FTRACE unsigned long toc;
@@ -90,6 +96,10 @@ static inline int module_finalize_ftrace(struct module *mod, const Elf_Shdr *sec }#endif +unsigned long stub_for_addr (const struct elf_info *elf_info,unsigned long addr, +const char *obj_name); +int restore_r2 (u32 *instruction,const char *obj_name); +struct exception_table_entry ;void sort_ex_table (struct exception_table_entry *start,struct exception_table_entry *finish);
arch/powerpc/kernel/Makefile +4 -0
@@ -124,6 +124,10 @@ ifneq ($(CONFIG_PPC_INDIRECT_PIO),y) obj-y += iomap.o endif +ifeq ($(CONFIG_MODULES)$(CONFIG_WORD_SIZE),y64) +obj-y += elf_util_64.o +endif + obj64-$(CONFIG_PPC_TRANSACTIONAL_MEM) += tm.o obj-$(CONFIG_PPC64) += $(obj64-y)
arch/powerpc/kernel/elf_util_64.c new file +269 -0
269 lines not on this page · raw message
arch/powerpc/kernel/module_64.c +31 -281
447 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH 4/8 powerpc: Generalize elf64_apply_relocate_add.
In reply to Thiago Jung BauermannWhen apply_relocate_add is called, modules are already loaded at their final location in memory so Elf64_Shdr.sh_addr can be used for accessing the section contents as well as the base address for relocations.
This is not the case for kexec's purgatory, because it will only be copied to its final location right before being executed. Therefore, it needs to be relocated while it is still in a temporary buffer. In this case, Elf64_Shdr.sh_addr can't be used to access the sections' contents.
This patch allows elf64_apply_relocate_add to be used when the ELF binary is not yet at its final location by adding an addr_base argument to specify the address at which the section will be loaded, and rela, loc_base and syms_base to point to the sections' contents.
--- arch/powerpc/include/asm/elf_util.h | 6 ++-- arch/powerpc/kernel/elf_util_64.c | 63 +++++++++++++++++++++++++------------ arch/powerpc/kernel/module_64.c | 17 ++++++++-- 3 files changed, 61 insertions(+), 25 deletions(-)
arch/powerpc/include/asm/elf_util.h +4 -2
@@ -64,7 +64,9 @@ static inline unsigned long my_r2(const struct elf_info *elf_info) }int elf64_apply_relocate_add (const struct elf_info *elf_info, -const char *strtab,unsigned int symindex, -unsigned int relsec,const char *obj_name); +const char *strtab,const Elf64_Rela *rela, +unsigned int num_rela,void *syms_base, +void *loc_base,Elf64_Addr addr_base, +const char *obj_name);#endif /* _ASM_POWERPC_ELF_UTIL_H */
arch/powerpc/kernel/elf_util_64.c +43 -20
111 lines not on this page · raw message
arch/powerpc/kernel/module_64.c +14 -3
@@ -438,16 +438,26 @@ int restore_r2(u32 *instruction, const char *obj_name)return 1 ; } +/* +* When this function is called, the module is already at its final location in +* memory, so Elf64_Shdr.sh_addr can be used for accessing the section +* contents as well as the base address for relocations. +*/ int apply_relocate_add (Elf64_Shdr *sechdrs,const char *strtab,unsigned int symindex,unsigned int relsec,struct module *me) { +Elf64_Shdr *rel_section = &sechdrs[relsec]; +void *syms_base = (void *) sechdrs[symindex].sh_addr; +Elf64_Addr addr_base = sechdrs[rel_section->sh_info].sh_addr; +const Elf64_Rela *rela = (const Elf64_Rela *) rel_section->sh_addr; +unsigned int num_rela = rel_section->sh_size /sizeof (Elf64_Rela);Elf64_Sym *sym;pr_debug ("Applying ADD relocate section %u to %u\n" , relsec, - sechdrs[relsec].sh_info); + rel_section->sh_info);/* First time we're called, we can fix up .TOC. */ if (!me->arch.toc_fixed) {
@@ -459,8 +469,9 @@ int apply_relocate_add(Elf64_Shdr *sechdrs, me->arch.toc_fixed = true; } -return elf64_apply_relocate_add (&me->arch.elf_info, strtab, symindex, - relsec, me->name); +return elf64_apply_relocate_add (&me->arch.elf_info, strtab, rela, + num_rela, syms_base, (void *) addr_base, + addr_base, me->name); }#ifdef CONFIG_DYNAMIC_FTRACE
Signature · 1 line
1.9.1
PATCH 5/8 powerpc: Add functions to read ELF files of any endianness.
In reply to Thiago Jung BauermannA little endian kernel might need to kexec a big endian kernel (the opposite is less likely but could happen as well), so we can't just cast the buffer with the binary to ELF structs and use them as is done elsewhere.
This patch adds functions which do byte-swapping as necessary when populating the ELF structs. These functions will be used in the next patch in the series.
--- arch/powerpc/include/asm/elf_util.h | 19 ++ arch/powerpc/kernel/Makefile | 2 +- arch/powerpc/kernel/elf_util.c | 476 ++++++++++++++++++++++++++++++++++++ 3 files changed, 496 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/elf_util.h +19 -0
@@ -20,6 +20,14 @@#include <linux/elf.h> struct elf_info { +/* +* Where the ELF binary contents are kept. +* Memory managed by the user of the struct. +*/ +const char *buffer; + +const struct elfhdr *ehdr; +const struct elf_phdr *proghdrs;struct elf_shdr *sechdrs;/* Index of stubs section. */
@@ -63,6 +71,17 @@ static inline unsigned long my_r2(const struct elf_info *elf_info)return elf_info->sechdrs[elf_info->toc_section].sh_addr +0x8000 ; } +static inline bool elf_is_elf_file (const struct elfhdr *ehdr) +{ +return memcmp (ehdr->e_ident,ELFMAG ,SELFMAG ) ==0 ; +} + +int elf_read_from_buffer (const char *buf,size_t len,struct elfhdr *ehdr, +struct elf_info *elf_info); +void elf_init_elf_info (const struct elfhdr *ehdr,struct elf_shdr *sechdrs, +struct elf_info *elf_info); +void elf_free_info (struct elf_info *elf_info); + int elf64_apply_relocate_add(const struct elf_info *elf_info, const char *strtab, const Elf64_Rela *rela, unsigned int num_rela, void *syms_base,
arch/powerpc/kernel/Makefile +1 -1
@@ -125,7 +125,7 @@ obj-y += iomap.o endif ifeq ($(CONFIG_MODULES)$(CONFIG_WORD_SIZE),y64) -obj-y += elf_util_64.o +obj-y += elf_util.o elf_util_64.o endif obj64-$(CONFIG_PPC_TRANSACTIONAL_MEM) += tm.o
arch/powerpc/kernel/elf_util.c new file +476 -0
476 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH 6/8 powerpc: Implement kexec_file_load.
In reply to Thiago Jung BauermannAdds the machinery needed by kexec_file_load, except actually loading a kernel and initrd.
elf64_apply_relocate_add was extended to support relative symbols. This is necessary because before relocation, the module loading mechanism adjusts Elf64_Sym.st_value to point to the absolute memory address, while the kexec purgatory relocation code does that during relocation.
We also add relocation types used by the purgatory.
--- arch/powerpc/Kconfig | 13 +++ arch/powerpc/include/asm/elf_util.h | 1 + arch/powerpc/include/asm/systbl.h | 1 + arch/powerpc/include/asm/unistd.h | 2 +- arch/powerpc/include/uapi/asm/unistd.h | 1 + arch/powerpc/kernel/Makefile | 4 +- arch/powerpc/kernel/elf_util_64.c | 83 +++++++++++++++++++- arch/powerpc/kernel/machine_kexec_64.c | 139 +++++++++++++++++++++++++++++++++ arch/powerpc/kernel/module_64.c | 5 +- 9 files changed, 245 insertions(+), 4 deletions(-)
arch/powerpc/Kconfig +13 -0
@@ -457,6 +457,19 @@ config KEXEC interface is strongly in flux, so no good recommendation can be made. +config KEXEC_FILE + bool "kexec file based system call" + select KEXEC_CORE + select BUILD_BIN2C + depends on PPC64 + depends on CRYPTO=y + depends on CRYPTO_SHA256=y + help + This is a new version of the kexec system call. This call is + file based and takes in file descriptors as system call arguments + for kernel and initramfs as opposed to a list of segments as is the + case for the older kexec call. + config CRASH_DUMP bool "Build a kdump crash kernel" depends on PPC64 || 6xx || FSL_BOOKE || (44x && !SMP)
arch/powerpc/include/asm/elf_util.h +1 -0
@@ -86,6 +86,7 @@ int elf64_apply_relocate_add(const struct elf_info *elf_info, const char *strtab, const Elf64_Rela *rela, unsigned int num_rela, void *syms_base, void *loc_base, Elf64_Addr addr_base, + bool relative_symbols, bool check_symbols, const char *obj_name);#endif /* _ASM_POWERPC_ELF_UTIL_H */
arch/powerpc/include/asm/systbl.h +1 -0
@@ -386,3 +386,4 @@ SYSCALL(mlock2) SYSCALL(copy_file_range) COMPAT_SYS_SPU(preadv2) COMPAT_SYS_SPU(pwritev2) +SYSCALL(kexec_file_load)
arch/powerpc/include/asm/unistd.h +1 -1
@@ -12,7 +12,7 @@#include <uapi/asm/unistd.h> -#define NR_syscalls 382 +#define NR_syscalls 383#define __NR__exit __NR_exit
arch/powerpc/include/uapi/asm/unistd.h +1 -0
@@ -392,5 +392,6 @@#define __NR_copy_file_range 379#define __NR_preadv2 380#define __NR_pwritev2 381 +#define __NR_kexec_file_load 382#endif /* _UAPI_ASM_POWERPC_UNISTD_H_ */
arch/powerpc/kernel/Makefile +3 -1
@@ -124,9 +124,11 @@ ifneq ($(CONFIG_PPC_INDIRECT_PIO),y) obj-y += iomap.o endif -ifeq ($(CONFIG_MODULES)$(CONFIG_WORD_SIZE),y64) +ifneq ($(CONFIG_MODULES)$(CONFIG_KEXEC_FILE),) +ifeq ($(CONFIG_WORD_SIZE),64) obj-y += elf_util.o elf_util_64.o endif +endif obj64-$(CONFIG_PPC_TRANSACTIONAL_MEM) += tm.o
arch/powerpc/kernel/elf_util_64.c +82 -1
136 lines not on this page · raw message
arch/powerpc/kernel/machine_kexec_64.c +139 -0
160 lines not on this page · raw message
arch/powerpc/kernel/module_64.c +4 -1
@@ -442,6 +442,9 @@ int restore_r2(u32 *instruction, const char *obj_name)* When this function is called, the module is already at its final location in * memory, so Elf64_Shdr.sh_addr can be used for accessing the section * contents as well as the base address for relocations. +* +* Also, simplify_symbols already changed all symbols' st_value members +* to absolute addresses. */ int apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
@@ -471,7 +474,7 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,return elf64_apply_relocate_add (&me->arch.elf_info, strtab, rela, num_rela, syms_base, (void *) addr_base, - addr_base, me->name); + addr_base, false, false, me->name); }#ifdef CONFIG_DYNAMIC_FTRACE
Signature · 1 line
1.9.1
PATCH 7/8 powerpc: Add support for loading ELF kernels with kexec_file_load.
In reply to Thiago Jung BauermannThis uses all the infrastructure built up by the previous patches in the series to load an ELF vmlinux file and an initrd. It uses the flattened device tree at initial_boot_params as a base and adjusts memory reservations and its /chosen node for the next kernel.
--- arch/powerpc/include/asm/kexec_elf_64.h | 10 + arch/powerpc/kernel/Makefile | 1 + arch/powerpc/kernel/kexec_elf_64.c | 564 ++++++++++++++++++++++++++++++++ arch/powerpc/kernel/machine_kexec_64.c | 5 +- 4 files changed, 579 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/kexec_elf_64.h new file +10 -0
@@ -0,0 +1,10 @@ +#ifndef __POWERPC_KEXEC_ELF_64_H__ +#define __POWERPC_KEXEC_ELF_64_H__ + +#ifdef CONFIG_KEXEC_FILE + +extern struct kexec_file_ops kexec_elf64_ops; + +#endif /* CONFIG_KEXEC_FILE */ + +#endif /* __POWERPC_KEXEC_ELF_64_H__ */
arch/powerpc/kernel/Makefile +1 -0
@@ -110,6 +110,7 @@ obj-$(CONFIG_PCI) += pci_$(CONFIG_WORD_SIZE).o $(pci64-y) \ obj-$(CONFIG_PCI_MSI) += msi.o obj-$(CONFIG_KEXEC) += machine_kexec.o crash.o \ machine_kexec_$(CONFIG_WORD_SIZE).o +obj-$(CONFIG_KEXEC_FILE) += kexec_elf_$(CONFIG_WORD_SIZE).o obj-$(CONFIG_AUDIT) += audit.o obj64-$(CONFIG_AUDIT) += compat_audit.o
arch/powerpc/kernel/kexec_elf_64.c new file +564 -0
564 lines not on this page · raw message
arch/powerpc/kernel/machine_kexec_64.c +4 -1
@@ -31,9 +31,12 @@#include <asm/prom.h> #include <asm/smp.h> #include <asm/hw_breakpoint.h> +#include <asm/kexec_elf_64.h> #ifdef CONFIG_KEXEC_FILE -static struct kexec_file_ops *kexec_file_loaders[] = { }; +static struct kexec_file_ops *kexec_file_loaders[] = { + &kexec_elf64_ops, +};#endif #ifdef CONFIG_PPC_BOOK3E
Signature · 1 line
1.9.1
PATCH 8/8 powerpc: Add purgatory for kexec_file_load implementation.
In reply to Thiago Jung BauermannThis purgatory implementation comes from kexec-tools, almost unchanged.
The only changes were that the sha256_regions global variable was renamed to sha_regions to match what kexec_file_load expects, and to use the sha256.c file from x86's purgatory to avoid adding yet another SHA-256 implementation.
--- arch/powerpc/Makefile | 4 + arch/powerpc/purgatory/.gitignore | 2 + arch/powerpc/purgatory/Makefile | 36 +++++++ arch/powerpc/purgatory/console-ppc64.c | 43 ++++++++ arch/powerpc/purgatory/crashdump-ppc64.h | 42 ++++++++ arch/powerpc/purgatory/crashdump_backup.c | 40 +++++++ arch/powerpc/purgatory/crtsavres.S | 5 + arch/powerpc/purgatory/hvCall.S | 27 +++++ arch/powerpc/purgatory/hvCall.h | 8 ++ arch/powerpc/purgatory/kexec-sha256.h | 11 ++ arch/powerpc/purgatory/ppc64_asm.h | 18 ++++ arch/powerpc/purgatory/printf.c | 171 ++++++++++++++++++++++++++++++ arch/powerpc/purgatory/purgatory-ppc64.c | 46 ++++++++ arch/powerpc/purgatory/purgatory-ppc64.h | 6 ++ arch/powerpc/purgatory/purgatory.c | 66 ++++++++++++ arch/powerpc/purgatory/purgatory.h | 11 ++ arch/powerpc/purgatory/sha256.c | 6 ++ arch/powerpc/purgatory/sha256.h | 1 + arch/powerpc/purgatory/string.S | 1 + arch/powerpc/purgatory/v2wrap.S | 139 ++++++++++++++++++++++++ 20 files changed, 683 insertions(+)
arch/powerpc/Makefile +4 -0
@@ -249,6 +249,7 @@ core-y += arch/powerpc/kernel/ \ core-$(CONFIG_XMON) += arch/powerpc/xmon/ core-$(CONFIG_KVM) += arch/powerpc/kvm/ core-$(CONFIG_PERF_EVENTS) += arch/powerpc/perf/ +core-$(CONFIG_KEXEC_FILE) += arch/powerpc/purgatory/ drivers-$(CONFIG_OPROFILE) += arch/powerpc/oprofile/
@@ -370,6 +371,9 @@ archclean: $(Q)$(MAKE) $(clean)=$(boot) archprepare: checkbin +ifeq ($(CONFIG_KEXEC_FILE),y) + $(Q)$(MAKE) $(build)=arch/powerpc/purgatory arch/powerpc/purgatory/kexec-purgatory.c +endif # Use the file '.tmp_gas_check' for binutils tests, as gas won't output # to stdout and these checks are run even on install targets.
arch/powerpc/purgatory/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +kexec-purgatory.c +purgatory.ro
arch/powerpc/purgatory/Makefile new file +36 -0
@@ -0,0 +1,36 @@ +purgatory-y := purgatory.o printf.o string.o v2wrap.o hvCall.o \ + purgatory-ppc64.o console-ppc64.o crashdump_backup.o \ + crtsavres.o sha256.o + +targets += $(purgatory-y) +PURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y)) + +LDFLAGS_purgatory.ro := -e purgatory_start -r --no-undefined -nostartfiles \ + -nostdlib -nodefaultlibs +targets += purgatory.ro + +# Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That +# in turn leaves some undefined symbols like __fentry__ in purgatory and not +# sure how to relocate those. Like kexec-tools, use custom flags. + +KBUILD_CFLAGS := -Wall -Wstrict-prototypes -fno-strict-aliasing \ + -fno-zero-initialized-in-bss -fno-builtin -ffreestanding \ + -fno-PIC -fno-PIE -fno-stack-protector -fno-exceptions \ + -msoft-float -MD -Os +KBUILD_CFLAGS += -m$(CONFIG_WORD_SIZE) + +$(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE + $(call if_changed,ld) + +targets += kexec-purgatory.c + +CMD_BIN2C = $(objtree)/scripts/basic/bin2c +quiet_cmd_bin2c = BIN2C $@ + cmd_bin2c = $(CMD_BIN2C) kexec_purgatory < $< > $@ + +$(obj)/kexec-purgatory.c: $(obj)/purgatory.ro FORCE + $(call if_changed,bin2c) + @: + + +obj-$(CONFIG_KEXEC_FILE) += kexec-purgatory.o
arch/powerpc/purgatory/console-ppc64.c new file +43 -0
43 lines not on this page · raw message
arch/powerpc/purgatory/crashdump-ppc64.h new file +42 -0
42 lines not on this page · raw message
arch/powerpc/purgatory/crashdump_backup.c new file +40 -0
@@ -0,0 +1,40 @@ +/* +* kexec: Linux boots Linux +* +* Created by: Mohan Kumar M ([email protected]) +* +* Copyright (C) IBM Corporation, 2005. All rights reserved +* +* Code taken from kexec-tools. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation (version 2 of the License). +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "../boot/string.h" +#include "crashdump-ppc64.h" + +extern unsigned long backup_start; + +/* Backup first 32KB of memory to backup region reserved by kexec */ +void crashdump_backup_memory (void ) +{ +void *dest, *src; + + src = (void *)BACKUP_SRC_START ; + +if (backup_start) { + dest = (void *)(backup_start); +memcpy (dest, src,BACKUP_SRC_SIZE ); + } +}
arch/powerpc/purgatory/crtsavres.S new file +5 -0
@@ -0,0 +1,5 @@ +#ifndef CONFIG_CC_OPTIMIZE_FOR_SIZE +#define CONFIG_CC_OPTIMIZE_FOR_SIZE 1 +#endif + +#include "../lib/crtsavres.S"
arch/powerpc/purgatory/hvCall.S new file +27 -0
@@ -0,0 +1,27 @@ +/* + * This file contains the generic function to perform a call to the + * pSeries LPAR hypervisor. + * + * Taken from linux/arch/powerpc/platforms/pseries/hvCall.S + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + */ +#include "ppc64_asm.h" + +#define HVSC .long 0x44000022 +.text + .machine ppc64 +.globl DOTSYM(plpar_hcall_norets) +DOTSYM(plpar_hcall_norets): + or 6,6,6 # medium low priority + mfcr 0 + stw 0,8(1) + + HVSC /* invoke the hypervisor */ + + lwz 0,8(1) + mtcrf 0xff,0 + blr /* return r3 = status */
arch/powerpc/purgatory/hvCall.h new file +8 -0
@@ -0,0 +1,8 @@ +#ifndef HVCALL_H +#define HVCALL_H + +#define H_PUT_TERM_CHAR 0x58 + +long plpar_hcall_norets (unsigned long opcode, ...); + +#endif
arch/powerpc/purgatory/kexec-sha256.h new file +11 -0
@@ -0,0 +1,11 @@ +#ifndef KEXEC_SHA256_H +#define KEXEC_SHA256_H + +struct kexec_sha_region { +unsigned long start; +unsigned long len; +}; + +#define SHA256_REGIONS 16 + +#endif /* KEXEC_SHA256_H */
arch/powerpc/purgatory/ppc64_asm.h new file +18 -0
@@ -0,0 +1,18 @@ +/* +* ppc64_asm.h - common defines for PPC64 assembly parts +* +* Code taken from kexec-tools. +* +* This source code is licensed under the GNU General Public License, +* Version 2. See the file COPYING for more details. +*/ + +/* +* ABIv1 requires dot symbol while ABIv2 does not. +*/ +#if defined(_CALL_ELF) && _CALL_ELF ==2 +#define DOTSYM (a) a +#else +#define GLUE (a,b) a##b +#define DOTSYM (a) GLUE(.,a) +#endif
arch/powerpc/purgatory/printf.c new file +171 -0
171 lines not on this page · raw message
arch/powerpc/purgatory/purgatory-ppc64.c new file +46 -0
46 lines not on this page · raw message
arch/powerpc/purgatory/purgatory-ppc64.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef PURGATORY_PPC64_H +#define PURGATORY_PPC64_H + +void crashdump_backup_memory (void ); + +#endif /* PURGATORY_PPC64_H */
arch/powerpc/purgatory/purgatory.c new file +66 -0
66 lines not on this page · raw message
arch/powerpc/purgatory/purgatory.h new file +11 -0
@@ -0,0 +1,11 @@ +#ifndef PURGATORY_H +#define PURGATORY_H + +void putchar (int ch); +void sprintf (char *buffer,const char *fmt, ...) + __attribute__ ((format (printf,2 ,3 ))); +void printf (const char *fmt, ...) __attribute__ ((format (printf,1 ,2 ))); +void setup_arch (void ); +void post_verification_setup_arch (void ); + +#endif /* PURGATORY_H */
arch/powerpc/purgatory/sha256.c new file +6 -0
@@ -0,0 +1,6 @@ +#include "../boot/string.h" + +/* Avoid including x86's boot/string.h in sha256.c. */ +#define BOOT_STRING_H + +#include "../../x86/purgatory/sha256.c"
arch/powerpc/purgatory/sha256.h new file +1 -0
@@ -0,0 +1 @@ +#include "../../x86/purgatory/sha256.h"
arch/powerpc/purgatory/string.S new file +1 -0
@@ -0,0 +1 @@ +#include "../boot/string.S"
arch/powerpc/purgatory/v2wrap.S new file +139 -0
139 lines not on this page · raw message
Signature · 1 line
1.9.1
Quoted 12 lines · Thiago Jung Bauermann
Hello,
This patch series implements the
kexec_file_loadsystem call on PowerPC.It starts by removing an x86 assumption from
kexec_file:kexec_add_bufferuses iomem to find reserved memory ranges, but PowerPC uses the memblock subsystem. Hooks are added so that each arch can specify how memory ranges can be found.Also, the memory-walking logic in
kexec_add_bufferis useful in this implementation to find a free area for the purgatory's stack, so that same patch moves that logic tokexec_locate_mem_hole.
Quoted 8 lines
The
kexec_file_loadsystem call needs to apply relocations to the purgatory but adding code for that would duplicate functionality with the module loading mechanism, which also needs to apply relocations to the kernel modules. Therefore, this patch series factors out the module relocation code so that it can be shared.One thing that is still missing is crashkernel support, which I intend to submit shortly.
But seems there's no error handling in patches about KEXEC_ON_CRASH? It would be good to either sending out the whole set or handle the error cases correctly.
[snip]
Thanks
Dave