kexec_file_load implementation for PowerPC
Subsystems (4)
v2 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. A hook is 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 the next 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. For now, arch_kexec_kernel_image_probe rejects crash kernels.
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.
Changes for v2:
- All patches: forgot to add Signed-off-by lines in v1, so added them now.
- Patch "kexec_file: Generalize kexec_add_buffer.": broke in two, one adding arch_kexec_walk_mem and the other adding kexec_locate_mem_hole.
- Patch "powerpc: Implement kexec_file_load.":
- Moved relocation changes and the arch_kexec_walk_mem implementation to the next patch in the series.
- Removed pr_fmt from machine_kexec_64.c, since the patch doesn't add any call to pr_debug in that file.
- Changed arch_kexec_kernel_image_probe to reject crash kernels.
Thiago Jung Bauermann (9):
kexec_file: Remove unused members from struct kexec_buf.
kexec_file: Generalize kexec_add_buffer.
kexec_file: Factor out kexec_locate_mem_hole from 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 | 372 ++++++++++++++++++++ arch/powerpc/kernel/kexec_elf_64.c | 564 ++++++++++++++++++++++++++++++ arch/powerpc/kernel/machine_kexec_64.c | 151 ++++++++ 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 | 7 + kernel/kexec_file.c | 116 ++++-- kernel/kexec_internal.h | 2 - 36 files changed, 2523 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 v2 1/9 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
PATCH v2 2/9 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.
--- include/linux/kexec.h | 3 +++ kernel/kexec_file.c | 44 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 39 insertions(+), 8 deletions(-)
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_kexec_walk_mem (unsigned int image_type,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 +36 -8
62 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [PATCH v2 2/9] kexec_file: Generalize kexec_add_buffer.
Hi, Thiago
Quoted 81 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.Signed-off-by Thiago Jung Bauermann <[email protected]>Cc Eric Biederman <[email protected]>Cc Dave Young <[email protected]>--- include/linux/kexec.h | 3 +++ kernel/kexec_file.c | 44 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 39 insertions(+), 8 deletions(-)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_kexec_walk_mem (unsigned int image_type,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 +26
-5@@ -428,6 +428,31 @@ static int locate_mem_hole_callback(u64 start, u64 end, void *arg)return locate_mem_hole_bottom_up (start, end, kbuf); } +/** +* arch_kexec_walk_mem - call func(data) on free memory regions +* @image_type: kimage.type +* @start: Don't visit memory regions below this address. +* @end: Don't visit memory regions above this address. +* @top_down: Start from the highest address? +* @data: Argument to pass to @func. +* @func: Function to call for each memory region. +* +* Return: The memory walk will stop when func returns a non-zero value +* and that value will be returned. If all free regions are visited without +* func returning non-zero, then zero will be returned. +*/ +int __weak arch_kexec_walk_mem (unsigned int image_type,unsigned long start, +unsigned long end,bool top_down,void *data, +int (*func)(u64 ,u64 ,void *)) +{ +if (image_type ==KEXEC_TYPE_CRASH ) +return walk_iomem_res_desc (crashk_res.desc, +IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY , + start, end, data, func); +else +return walk_system_ram_res (start, end, data, func); +} +/* * Helper function for placing a buffer in a kexec segment. This assumes * that kexec_mutex is held. @@ -441,6 +466,7 @@ 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 start, end;/* Currently adding segment this way is allowed only in file mode */ if (!image->file_mode)@@ -472,14 +498,16 @@ int kexec_add_buffer(struct kimage *image, char *buffer, unsigned long bufsz, kbuf->top_down = top_down;/* 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);
kernel/kexec_file.c int kexec_add_buffer(struct kimage *image, char *buffer, unsigned long bufsz, · line 507
Quoted 10 lines
kernel/kexec_file.c +7
-3-else - ret =walk_system_ram_res (0 ,-1 , kbuf, - locate_mem_hole_callback); +if (image->type ==KEXEC_TYPE_CRASH ) { + start = crashk_res.start; + end = crashk_res.end; + }else { + start =0 ; + end =ULONG_MAX ; + }
For crashk_res, start and end is global, the non-crash values are hard coded, thus it is not necessary to pass these two in arguments.
Moving above to arch_kexec_walk_mem will make it cleaner.
Quoted 14 lines
kernel/kexec_file.c +3
-0+ + ret =arch_kexec_walk_mem (image->type, start, end, top_down, kbuf, + locate_mem_hole_callback);if (ret !=1 ) {/* A suitable memory range could not be found for buffer */ return -EADDRNOTAVAIL ;Signature · 7 lines
1.9.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Thanks
Dave
Re: [PATCH v2 2/9] kexec_file: Generalize kexec_add_buffer.
Hello Dave,
Am Mittwoch, 15 Juni 2016, 15:33:02 schrieb Dave Young:
Quoted 25 lines
Quoted 11 lines
(quoted diff) +0
-5@@ -472,14 +498,16 @@ int kexec_add_buffer(struct kimage *image, char *buffer, unsigned long bufsz,> kbuf->top_down = top_down; /* 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);Review int kexec_add_buffer(struct kimage *image, char · line 509
Quoted 10 lines
(quoted diff) +7
-3- else - ret = walk_system_ram_res(0, -1, kbuf, - locate_mem_hole_callback); + if (image->type == KEXEC_TYPE_CRASH) { + start = crashk_res.start; + end = crashk_res.end; + } else { + start = 0; + end = ULONG_MAX; + }For
crashk_res, start and end is global, the non-crash values are hard coded, thus it is not necessary to pass these two in arguments.
Quoted 1 line
Moving above to
arch_kexec_walk_memwill make it cleaner.
That's true. What about this version?
[]'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.
include/linux/kexec.h +2 -0
@@ -315,6 +315,8 @@ 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_kexec_walk_mem (unsigned int image_type,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 +25 -8
@@ -428,6 +428,29 @@ static int locate_mem_hole_callback(u64 start, u64 end, void *arg)return locate_mem_hole_bottom_up (start, end, kbuf); } +/** +* arch_kexec_walk_mem - call func(data) on free memory regions +* @image_type: kimage.type +* @top_down: Start from the highest address? +* @data: Argument to pass to @func. +* @func: Function to call for each memory region. +* +* Return: The memory walk will stop when func returns a non-zero value +* and that value will be returned. If all free regions are visited without +* func returning non-zero, then zero will be returned. +*/ +int __weak arch_kexec_walk_mem (unsigned int image_type,bool top_down, +void *data,int (*func)(u64 ,u64 ,void *)) +{ +if (image_type ==KEXEC_TYPE_CRASH ) +return walk_iomem_res_desc (crashk_res.desc, +IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY , + crashk_res.start, crashk_res.end, + data, func); +else +return walk_system_ram_res (0 ,ULONG_MAX , data, func); +} +/* * Helper function for placing a buffer in a kexec segment. This assumes * that kexec_mutex is held.
@@ -472,14 +495,8 @@ int kexec_add_buffer(struct kimage *image, char *buffer, unsigned long bufsz, kbuf->top_down = top_down;/* 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); + ret =arch_kexec_walk_mem (image->type, top_down, kbuf, + locate_mem_hole_callback);if (ret !=1 ) {/* A suitable memory range could not be found for buffer */ return -EADDRNOTAVAIL ;
Re: [PATCH v2 2/9] kexec_file: Generalize kexec_add_buffer.
Quoted 74 lines · Thiago Jung Bauermann
Hello Dave,
Am Mittwoch, 15 Juni 2016, 15:33:02 schrieb Dave Young:
Quoted 25 lines
Quoted 11 lines
kernel/kexec_file.c +0
-5@@ -472,14 +498,16 @@ int kexec_add_buffer(struct kimage *image, char *buffer, unsigned long bufsz,> kbuf->top_down = top_down;/* 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);kernel/kexec_file.c int kexec_add_buffer(struct kimage *image, char · line 509
Quoted 10 lines
kernel/kexec_file.c +7
-3-else - ret =walk_system_ram_res (0 ,-1 , kbuf, - locate_mem_hole_callback); +if (image->type ==KEXEC_TYPE_CRASH ) { + start = crashk_res.start; + end = crashk_res.end; + }else { + start =0 ; + end =ULONG_MAX ; + }For
crashk_res, start and end is global, the non-crash values are hard coded, thus it is not necessary to pass these two in arguments.Quoted 1 line
Moving above to
arch_kexec_walk_memwill make it cleaner.That's true. What about this version?
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
kexec_file: Generalizekexec_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 Dave Young <[email protected]>include/linux/kexec.h +2
-0@@ -315,6 +315,8 @@ 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_kexec_walk_mem (unsigned int image_type,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 +4
-0@@ -428,6 +428,29 @@ static int locate_mem_hole_callback(u64 start, u64 end, void *arg)return locate_mem_hole_bottom_up (start, end, kbuf); } +/** +* arch_kexec_walk_mem - call func(data) on free memory regions +* @image_type: kimage.type +* @top_down: Start from the highest address?
kernel/kexec_file.c static int locate_mem_hole_callback(u64 start, u64 end, void *arg) · line 444
Quoted 10 lines
kernel/kexec_file.c +10
-0+* @data: Argument to pass to @func. +* @func: Function to call for each memory region. +* +* Return: The memory walk will stop when func returns a non-zero value +* and that value will be returned. If all free regions are visited without +* func returning non-zero, then zero will be returned. +*/ +int __weak arch_kexec_walk_mem (unsigned int image_type,bool top_down, +void *data,int (*func)(u64 ,u64 ,void *)) +{
top_down is also not used?
Rethink about the argument name type should be better than image_type, it is obvious in the comments and the code and simpler.
Quoted 30 lines
kernel/kexec_file.c +11
-8+if (image_type ==KEXEC_TYPE_CRASH ) +return walk_iomem_res_desc (crashk_res.desc, +IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY , + crashk_res.start, crashk_res.end, + data, func); +else +return walk_system_ram_res (0 ,ULONG_MAX , data, func); +} +/* * Helper function for placing a buffer in a kexec segment. This assumes * that kexec_mutex is held. @@ -472,14 +495,8 @@ int kexec_add_buffer(struct kimage *image, char *buffer, unsigned long bufsz, kbuf->top_down = top_down;/* 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); + ret =arch_kexec_walk_mem (image->type, top_down, kbuf, + locate_mem_hole_callback);if (ret !=1 ) {/* A suitable memory range could not be found for buffer */ return -EADDRNOTAVAIL ;
Re: [PATCH v2 2/9] kexec_file: Generalize kexec_add_buffer.
Am Donnerstag, 16 Juni 2016, 09:58:53 schrieb Dave Young:
Quoted 9 lines · Thiago Jung Bauermann
Quoted 8 lines
+/**
+ *arch_kexec_walk_mem- call func(data) on free memory regions
+ * @image_type: kimage.type
+ * @top_down: Start from the highest address?
+ * @data: Argument to pass to @func.
+ * @func: Function to call for each memory region.
+ *
+ * Return: The memory walk will stop when func returns a non-zero value
Quoted 8 lines
Review
Quoted 6 lines
+ * and that value will be returned. If all free regions are visited without + * func returning non-zero, then zero will be returned.
+ */(quoted diff) +3
-0+int __weak arch_kexec_walk_mem(unsigned int image_type, bool top_down, + void *data, int (*func)(u64, u64, void *)) +{
top_downis also not used?
It's unused in the default implementation, but the powerpc implementation in patch 8 uses it:
int arch_kexec_walk_mem(unsigned int type, bool top_down, void *data,
int (*func)(u64, u64, void *))
{
int ret = 0;
u64 i;
phys_addr_t mstart, mend;
if (top_down) {
for_each_free_mem_range_reverse(i, NUMA_NO_NODE, 0,
&mstart, &mend, NULL) {
ret = func(mstart, mend, data);
if (ret)
break;
}
} else {
for_each_free_mem_range(i, NUMA_NO_NODE, 0, &mstart, &mend,
NULL) {
ret = func(mstart, mend, data);
if (ret)
break;
}
}
return ret;
}Quoted 2 lines
Rethink about the argument name type should be better than
image_type, it is obvious in the comments and the code and simpler.
Ok, renamed in the patch below.
[]'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.
include/linux/kexec.h +2 -0
@@ -315,6 +315,8 @@ 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_kexec_walk_mem (unsigned int type,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 +25 -8
@@ -428,6 +428,29 @@ static int locate_mem_hole_callback(u64 start, u64 end, void *arg)return locate_mem_hole_bottom_up (start, end, kbuf); } +/** +* arch_kexec_walk_mem - call func(data) on free memory regions +* @type: kimage.type +* @top_down: Start from the highest address? +* @data: Argument to pass to @func. +* @func: Function to call for each memory region. +* +* Return: The memory walk will stop when func returns a non-zero value +* and that value will be returned. If all free regions are visited without +* func returning non-zero, then zero will be returned. +*/ +int __weak arch_kexec_walk_mem (unsigned int type,bool top_down,void *data, +int (*func)(u64 ,u64 ,void *)) +{ +if (type ==KEXEC_TYPE_CRASH ) +return walk_iomem_res_desc (crashk_res.desc, +IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY , + crashk_res.start, crashk_res.end, + data, func); +else +return walk_system_ram_res (0 ,ULONG_MAX , data, func); +} +/* * Helper function for placing a buffer in a kexec segment. This assumes * that kexec_mutex is held.
@@ -472,14 +495,8 @@ int kexec_add_buffer(struct kimage *image, char *buffer, unsigned long bufsz, kbuf->top_down = top_down;/* 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); + ret =arch_kexec_walk_mem (image->type, top_down, kbuf, + locate_mem_hole_callback);if (ret !=1 ) {/* A suitable memory range could not be found for buffer */ return -EADDRNOTAVAIL ;
Re: [PATCH v2 2/9] kexec_file: Generalize kexec_add_buffer.
Quoted 19 lines · Thiago Jung Bauermann
Am Donnerstag, 16 Juni 2016, 09:58:53 schrieb Dave Young:
Quoted 9 lines · Thiago Jung Bauermann
Quoted 8 lines
+/**
+ *arch_kexec_walk_mem- call func(data) on free memory regions
+ * @image_type: kimage.type
+ * @top_down: Start from the highest address?
+ * @data: Argument to pass to @func.
+ * @func: Function to call for each memory region.
+ *
+ * Return: The memory walk will stop when func returns a non-zero valueQuoted 8 lines
Review
Quoted 6 lines
+ * and that value will be returned. If all free regions are visited without + * func returning non-zero, then zero will be returned.
+ */(quoted diff) +3
-0+int __weak arch_kexec_walk_mem(unsigned int image_type, bool top_down, + void *data, int (*func)(u64, u64, void *)) +{
top_downis also not used?
Quoted 1 line
It's unused in the default implementation, but the powerpc implementation in patch 8 uses it:
Well, arch_kexec_walk_mem use kbuf as "data", you can even drop "image_type" since kbuf has all you want kbuf->image->type, and kbuf->top_down
int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf,
int (*func)(u64, u64, void *))
Quoted 115 lines
int arch_kexec_walk_mem(unsigned int type, bool
top_down, void *data,int (*func)(u64, u64, void *)) { int ret = 0; u64 i; phys_addr_t mstart, mend; if (top_down) { for_each_free_mem_range_reverse(i, NUMA_NO_NODE, 0, &mstart, &mend, NULL) { ret = func(mstart, mend, data); if (ret) break; } } else { for_each_free_mem_range(i, NUMA_NO_NODE, 0, &mstart, &mend, NULL) { ret = func(mstart, mend, data); if (ret) break; } } return ret; }Quoted 2 lines
Rethink about the argument name type should be better than
image_type, it is obvious in the comments and the code and simpler.Ok, renamed in the patch below.
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
kexec_file: Generalizekexec_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 Dave Young <[email protected]>include/linux/kexec.h +2
-0@@ -315,6 +315,8 @@ 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_kexec_walk_mem (unsigned int type,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 +25
-8@@ -428,6 +428,29 @@ static int locate_mem_hole_callback(u64 start, u64 end, void *arg)return locate_mem_hole_bottom_up (start, end, kbuf); } +/** +* arch_kexec_walk_mem - call func(data) on free memory regions +* @type: kimage.type +* @top_down: Start from the highest address? +* @data: Argument to pass to @func. +* @func: Function to call for each memory region. +* +* Return: The memory walk will stop when func returns a non-zero value +* and that value will be returned. If all free regions are visited without +* func returning non-zero, then zero will be returned. +*/ +int __weak arch_kexec_walk_mem (unsigned int type,bool top_down,void *data, +int (*func)(u64 ,u64 ,void *)) +{ +if (type ==KEXEC_TYPE_CRASH ) +return walk_iomem_res_desc (crashk_res.desc, +IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY , + crashk_res.start, crashk_res.end, + data, func); +else +return walk_system_ram_res (0 ,ULONG_MAX , data, func); +} +/* * Helper function for placing a buffer in a kexec segment. This assumes * that kexec_mutex is held. @@ -472,14 +495,8 @@ int kexec_add_buffer(struct kimage *image, char *buffer, unsigned long bufsz, kbuf->top_down = top_down;/* 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); + ret =arch_kexec_walk_mem (image->type, top_down, kbuf, + locate_mem_hole_callback);if (ret !=1 ) {/* A suitable memory range could not be found for buffer */ return -EADDRNOTAVAIL ;
Quoted 4 lines
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Thanks
Dave
Re: [PATCH v2 2/9] kexec_file: Generalize kexec_add_buffer.
Am Freitag, 17 Juni 2016, 15:35:23 schrieb Dave Young:
Quoted 10 lines · Thiago Jung Bauermann
Quoted 9 lines
Am Donnerstag, 16 Juni 2016, 09:58:53 schrieb Dave Young:
Quoted 7 lines · Thiago Jung Bauermann
Review
Quoted 4 lines
+int
__weakarch_kexec_walk_mem(unsigned intimage_type, booltop_down,(quoted diff) +2
-0+ void *data, int (*func)(u64, u64, void *)) +{
top_downis also not used?
Quoted 8 lines
Quoted 2 lines
It's unused in the default implementation, but the powerpc implementation in patch 8 uses it:
Well,
arch_kexec_walk_memuse kbuf as "data", you can even drop "image_type" since kbuf has all you wantkbuf->image->type, andkbuf->top_downint
__weakarch_kexec_walk_mem(structkexec_buf*kbuf,int (*func)(u64, u64, void *))
Sounds good to me, but I had to move struct kexec_buf from kernel/kexec_internal.h to include/linux/kexec.h.
Here's the updated patch. What do you think?
[]'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.
include/linux/kexec.h +16 -0
@@ -201,6 +201,20 @@ struct kimage {#endif }; +/* +* Keeps track of buffer parameters as provided by caller for requesting +* memory placement of buffer. +*/ +struct kexec_buf { +struct kimage *image; +unsigned long mem; +unsigned long memsz; +unsigned long buf_align; +unsigned long buf_min; +unsigned long buf_max; +bool top_down;/* allocate from top of memory hole */ +}; +/* kexec interface functions */ extern void machine_kexec (struct kimage *image);extern int machine_kexec_prepare (struct kimage *image);
@@ -315,6 +329,8 @@ 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_kexec_walk_mem (struct kexec_buf *kbuf, +int (*func)(u64 ,u64 ,void *));void arch_kexec_protect_crashkres (void );void arch_kexec_unprotect_crashkres (void );
kernel/kexec_file.c +22 -8
@@ -428,6 +428,27 @@ static int locate_mem_hole_callback(u64 start, u64 end, void *arg)return locate_mem_hole_bottom_up (start, end, kbuf); } +/** +* arch_kexec_walk_mem - call func(data) on free memory regions +* @kbuf: Context info for the search. Also passed to @func. +* @func: Function to call for each memory region. +* +* Return: The memory walk will stop when func returns a non-zero value +* and that value will be returned. If all free regions are visited without +* func returning non-zero, then zero will be returned. +*/ +int __weak arch_kexec_walk_mem (struct kexec_buf *kbuf, +int (*func)(u64 ,u64 ,void *)) +{ +if (kbuf->image->type ==KEXEC_TYPE_CRASH ) +return walk_iomem_res_desc (crashk_res.desc, +IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY , + crashk_res.start, crashk_res.end, + kbuf, func); +else +return walk_system_ram_res (0 ,ULONG_MAX , kbuf, func); +} +/* * Helper function for placing a buffer in a kexec segment. This assumes * that kexec_mutex is held.
@@ -472,14 +493,7 @@ int kexec_add_buffer(struct kimage *image, char *buffer, unsigned long bufsz, kbuf->top_down = top_down;/* 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); + ret =arch_kexec_walk_mem (kbuf, locate_mem_hole_callback);if (ret !=1 ) {/* A suitable memory range could not be found for buffer */ return -EADDRNOTAVAIL ;
kernel/kexec_internal.h +0 -14
@@ -20,20 +20,6 @@ struct kexec_sha_region { unsigned long len; }; -/* -* Keeps track of buffer parameters as provided by caller for requesting -* memory placement of buffer. -*/ -struct kexec_buf { -struct kimage *image; -unsigned long mem; -unsigned long memsz; -unsigned long buf_align; -unsigned long buf_min; -unsigned long buf_max; -bool top_down;/* allocate from top of memory hole */ -}; -void kimage_file_post_load_cleanup (struct kimage *image);#else /* CONFIG_KEXEC_FILE */ static inline void kimage_file_post_load_cleanup (struct kimage *image) { }
Re: [PATCH v2 2/9] kexec_file: Generalize kexec_add_buffer.
Quoted 54 lines · Thiago Jung Bauermann
Am Freitag, 17 Juni 2016, 15:35:23 schrieb Dave Young:
Quoted 10 lines · Thiago Jung Bauermann
Quoted 9 lines
Am Donnerstag, 16 Juni 2016, 09:58:53 schrieb Dave Young:
Quoted 7 lines · Thiago Jung Bauermann
Review
Quoted 4 lines
+int
__weakarch_kexec_walk_mem(unsigned intimage_type, booltop_down,(quoted diff) +2
-0+ void *data, int (*func)(u64, u64, void *)) +{
top_downis also not used?Quoted 8 lines
Quoted 2 lines
It's unused in the default implementation, but the powerpc implementation in patch 8 uses it:
Well,
arch_kexec_walk_memuse kbuf as "data", you can even drop "image_type" since kbuf has all you wantkbuf->image->type, andkbuf->top_downint
__weakarch_kexec_walk_mem(structkexec_buf*kbuf,int (*func)(u64, u64, void *))Sounds good to me, but I had to move struct
kexec_buffromkernel/kexec_internal.htoinclude/linux/kexec.h.Here's the updated patch. What do you think?
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
kexec_file: Generalizekexec_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 Dave Young <[email protected]>include/linux/kexec.h +4
-0@@ -201,6 +201,20 @@ struct kimage {#endif }; +/* +* Keeps track of buffer parameters as provided by caller for requesting +* memory placement of buffer. +*/
include/linux/kexec.h struct kimage { · line 217
Quoted 10 lines
include/linux/kexec.h +10
-0+struct kexec_buf { +struct kimage *image; +unsigned long mem; +unsigned long memsz; +unsigned long buf_align; +unsigned long buf_min; +unsigned long buf_max; +bool top_down;/* allocate from top of memory hole */ +}; +
kexec_buf should go within #ifdef for kexec file like struct purgatory_info
Other than that it looks good.
Thanks
Dave
Re: [PATCH v2 2/9] kexec_file: Generalize kexec_add_buffer.
Am Montag, 20 Juni 2016, 10:26:05 schrieb Dave Young:
Quoted 4 lines
kexec_bufshould go within #ifdef for kexec file like structpurgatory_infoOther than that it looks good.
Great! Here it is.
Signature · 16 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: Dave Young <[email protected]>
Cc: [email protected]
Cc: [email protected]include/linux/kexec.h +18 -1
@@ -146,7 +146,24 @@ struct kexec_file_ops {kexec_verify_sig_t *verify_sig;#endif }; -#endif + +/* +* Keeps track of buffer parameters as provided by caller for requesting +* memory placement of buffer. +*/ +struct kexec_buf { +struct kimage *image; +unsigned long mem; +unsigned long memsz; +unsigned long buf_align; +unsigned long buf_min; +unsigned long buf_max; +bool top_down;/* allocate from top of memory hole */ +}; + +int __weak arch_kexec_walk_mem (struct kexec_buf *kbuf, +int (*func)(u64 ,u64 ,void *)); +#endif /* CONFIG_KEXEC_FILE */ struct kimage {kimage_entry_t head;
kernel/kexec_file.c +22 -8
@@ -428,6 +428,27 @@ static int locate_mem_hole_callback(u64 start, u64 end, void *arg)return locate_mem_hole_bottom_up (start, end, kbuf); } +/** +* arch_kexec_walk_mem - call func(data) on free memory regions +* @kbuf: Context info for the search. Also passed to @func. +* @func: Function to call for each memory region. +* +* Return: The memory walk will stop when func returns a non-zero value +* and that value will be returned. If all free regions are visited without +* func returning non-zero, then zero will be returned. +*/ +int __weak arch_kexec_walk_mem (struct kexec_buf *kbuf, +int (*func)(u64 ,u64 ,void *)) +{ +if (kbuf->image->type ==KEXEC_TYPE_CRASH ) +return walk_iomem_res_desc (crashk_res.desc, +IORESOURCE_SYSTEM_RAM |IORESOURCE_BUSY , + crashk_res.start, crashk_res.end, + kbuf, func); +else +return walk_system_ram_res (0 ,ULONG_MAX , kbuf, func); +} +/* * Helper function for placing a buffer in a kexec segment. This assumes * that kexec_mutex is held.
@@ -472,14 +493,7 @@ int kexec_add_buffer(struct kimage *image, char *buffer, unsigned long bufsz, kbuf->top_down = top_down;/* 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); + ret =arch_kexec_walk_mem (kbuf, locate_mem_hole_callback);if (ret !=1 ) {/* A suitable memory range could not be found for buffer */ return -EADDRNOTAVAIL ;
kernel/kexec_internal.h +0 -14
@@ -20,20 +20,6 @@ struct kexec_sha_region { unsigned long len; }; -/* -* Keeps track of buffer parameters as provided by caller for requesting -* memory placement of buffer. -*/ -struct kexec_buf { -struct kimage *image; -unsigned long mem; -unsigned long memsz; -unsigned long buf_align; -unsigned long buf_min; -unsigned long buf_max; -bool top_down;/* allocate from top of memory hole */ -}; -void kimage_file_post_load_cleanup (struct kimage *image);#else /* CONFIG_KEXEC_FILE */ static inline void kimage_file_post_load_cleanup (struct kimage *image) { }
PATCH v2 3/9 kexec_file: Factor out kexec_locate_mem_hole from kexec_add_buffer.
In reply to Thiago Jung Bauermannkexec_locate_mem_hole will be used by the PowerPC kexec_file_load implementation to find free memory for the purgatory stack.
--- include/linux/kexec.h | 4 +++ kernel/kexec_file.c | 88 +++++++++++++++++++++++++++++++++++---------------- 2 files changed, 64 insertions(+), 28 deletions(-)
include/linux/kexec.h +4 -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 min_addr, +unsigned long max_addr,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,
kernel/kexec_file.c +60 -28
113 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v2 4/9 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 v2 5/9 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 v2 6/9 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 v2 7/9 powerpc: Implement kexec_file_load.
In reply to Thiago Jung BauermannAdds the basic machinery needed by kexec_file_load.
--- arch/powerpc/Kconfig | 13 +++++++++ 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/machine_kexec_64.c | 51 ++++++++++++++++++++++++++++++++++ 5 files changed, 67 insertions(+), 1 deletion(-)
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/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/machine_kexec_64.c +51 -0
60 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v2 8/9 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.
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.
The patch also adds relocation types used by the purgatory.
--- arch/powerpc/include/asm/elf_util.h | 1 + arch/powerpc/include/asm/kexec_elf_64.h | 10 + arch/powerpc/kernel/Makefile | 5 +- arch/powerpc/kernel/elf_util_64.c | 82 ++++- arch/powerpc/kernel/kexec_elf_64.c | 564 ++++++++++++++++++++++++++++++++ arch/powerpc/kernel/machine_kexec_64.c | 102 +++++- arch/powerpc/kernel/module_64.c | 5 +- 7 files changed, 765 insertions(+), 4 deletions(-)
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/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 +4 -1
@@ -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
@@ -124,9 +125,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 +81 -1
130 lines not on this page · raw message
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 +101 -1
120 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 v2 9/9 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
Michael Ellerman
reviewerQuoted 3 lines · Thiago Jung Bauermann
Hello,
This patch series implements the
kexec_file_loadsystem call on PowerPC.
Can you tell me what this syscall does and why I would want it?
cheers
Am Donnerstag, 16 Juni 2016, 15:48:30 schrieb Michael Ellerman:
Quoted 6 lines · Thiago Jung Bauermann
Quoted 3 lines
Hello,
This patch series implements the
kexec_file_loadsystem call on PowerPC.Can you tell me what this syscall does and why I would want it?
Sorry, should have provided the motivation when I posted the patches.
This system call moves the reading of the kernel, initrd and the device tree from the userspace kexec tool to the kernel. This is needed if you want to do one or both of the following:
1. only allow loading of signed kernels.
2. "measure" (i.e., record the hashes of) the kernel, initrd, kernel command line and other boot inputs for the Integrity Measurement Architecture subsystem.
The above are the functions kexec already has built into kexec_file_load. I will soon post a set of patches which will allow a third feature:
3. have IMA pass-on its event log (where integrity measurements are registered) accross kexec to the second kernel, so that the event history is preserved.
Because OpenPower uses an intermediary Linux instance as a boot loader (skiroot), feature 1 is needed to implement secure boot for the platform, while features 2 and 3 are needed to implement trusted boot.
There's an LWN article giving more context on the origins of the system call, if you are interested:
https://lwn.net/Articles/603116/
Signature · 3 lines
[]'s Thiago Jung Bauermann IBM Linux Technology Center