kexec_file_load implementation for PowerPC
Subsystems (4)
v3 cover kexec_file_load implementation for PowerPC
Hello,
This patch series implements the kexec_file_load system call on PowerPC.
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. Yesterday I posted a set of patches which allows 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.
This patch series 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 v3:
- Rebased series on today's powerpc/next.
- Patch "kexec_file: Generalize kexec_add_buffer.":
- Removed most arguments from arch_kexec_walk_mem and pass kbuf explicitly.
- Patch "powerpc: Add functions to read ELF files of any endianness.":
- Fixed whitespace issues found by checkpatch.pl.
- Patch "powerpc: Factor out relocation code from module_64.c to elf_util_64.c.":
- Changed to use the new PPC64_ELF_ABI_v2 macro.
- Patch "powerpc: Add support for loading ELF kernels with kexec_file_load.":
- Adapted arch_kexec_walk_mem implementation to changes in its argument list.
- Fixed whitespace and GPL header issues found by checkpatch.pl.
- Patch "powerpc: Add purgatory for kexec_file_load implementation.":
- Fixed whitespace and GPL header issues found by checkpatch.pl.
- Changed to use the new PPC64_ELF_ABI_v2 macro.
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.
Changes for v3:
- Rebased series on today's powerpc/next.
- Patch "kexec_file: Generalize kexec_add_buffer.":
- Removed most arguments from arch_kexec_walk_mem and pass kbuf explicitly.
- Patch "powerpc: Add functions to read ELF files of any endianness.":
- Fixed whitespace issues found by checkpatch.pl.
- Patch "powerpc: Factor out relocation code from module_64.c to elf_util_64.c.":
- Changed to use the new PPC64_ELF_ABI_v2 macro.
- Patch "powerpc: Add support for loading ELF kernels with kexec_file_load.":
- Adapted arch_kexec_walk_mem implementation to changes in its argument list.
- Fixed whitespace and GPL header issues found by checkpatch.pl.
- Patch "powerpc: Add purgatory for kexec_file_load implementation.":
- Fixed whitespace and GPL header issues found by checkpatch.pl.
- Changed to use the new PPC64_ELF_ABI_v2 macro.
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 | 374 ++++++++++++++++++++ arch/powerpc/kernel/kexec_elf_64.c | 560 ++++++++++++++++++++++++++++++ arch/powerpc/kernel/machine_kexec_64.c | 134 +++++++ arch/powerpc/kernel/module_64.c | 328 +++-------------- arch/powerpc/purgatory/.gitignore | 2 + arch/powerpc/purgatory/Makefile | 36 ++ arch/powerpc/purgatory/console-ppc64.c | 38 ++ arch/powerpc/purgatory/crashdump-ppc64.h | 42 +++ arch/powerpc/purgatory/crashdump_backup.c | 36 ++ 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 | 20 ++ arch/powerpc/purgatory/printf.c | 164 +++++++++ arch/powerpc/purgatory/purgatory-ppc64.c | 41 +++ arch/powerpc/purgatory/purgatory-ppc64.h | 6 + arch/powerpc/purgatory/purgatory.c | 62 ++++ 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 | 134 +++++++ include/linux/kexec.h | 23 +- kernel/kexec_file.c | 100 ++++-- kernel/kexec_internal.h | 16 - 36 files changed, 2476 insertions(+), 330 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 v3 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 v3 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 | 19 ++++++++++++++++++- kernel/kexec_file.c | 30 ++++++++++++++++++++++-------- kernel/kexec_internal.h | 14 -------------- 3 files changed, 40 insertions(+), 23 deletions(-)
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) { }
Signature · 1 line
1.9.1
PATCH v3 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 | 66 ++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 53 insertions(+), 17 deletions(-)
include/linux/kexec.h +4 -0
@@ -227,6 +227,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 +49 -17
92 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v3 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__ +#ifdef PPC64_ELF_ABI_v2 + +/* 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 /* PPC64_ELF_ABI_v2 */ + +/* 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 v3 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 v3 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 v3 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 | 50 ++++++++++++++++++++++++++++++++++ 5 files changed, 66 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 +50 -0
59 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v3 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 | 84 ++++- arch/powerpc/kernel/kexec_elf_64.c | 560 ++++++++++++++++++++++++++++++++ arch/powerpc/kernel/machine_kexec_64.c | 86 ++++- arch/powerpc/kernel/module_64.c | 5 +- 7 files changed, 747 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 +83 -1
132 lines not on this page · raw message
arch/powerpc/kernel/kexec_elf_64.c new file +560 -0
560 lines not on this page · raw message
arch/powerpc/kernel/machine_kexec_64.c +85 -1
104 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 v3 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.
Also, some formatting warnings found by checkpatch.pl were fixed.
--- arch/powerpc/Makefile | 4 + arch/powerpc/purgatory/.gitignore | 2 + arch/powerpc/purgatory/Makefile | 36 +++++++ arch/powerpc/purgatory/console-ppc64.c | 38 +++++++ arch/powerpc/purgatory/crashdump-ppc64.h | 42 ++++++++ arch/powerpc/purgatory/crashdump_backup.c | 36 +++++++ 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 | 20 ++++ arch/powerpc/purgatory/printf.c | 164 ++++++++++++++++++++++++++++++ arch/powerpc/purgatory/purgatory-ppc64.c | 41 ++++++++ arch/powerpc/purgatory/purgatory-ppc64.h | 6 ++ arch/powerpc/purgatory/purgatory.c | 62 +++++++++++ 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 | 134 ++++++++++++++++++++++++ 20 files changed, 655 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 +38 -0
@@ -0,0 +1,38 @@ +/* +* 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. +*/ + +#include "hvCall.h" +#include <asm/byteorder.h> + +extern int debug; + +void putchar (int c) +{ +char buff[8 ]; +unsigned long *lbuf = (unsigned long *)buff; + +if (!debug)/* running on non pseries */ +return ; + +if (c =='\n' ) +putchar ('\r' ); + + buff[0 ] = c; +plpar_hcall_norets (H_PUT_TERM_CHAR ,0 ,1 ,__cpu_to_be64 (*lbuf),0 ); +}
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 +36 -0
@@ -0,0 +1,36 @@ +/* +* 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. +*/ + +#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 +20 -0
@@ -0,0 +1,20 @@ +/* +* 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. +*/ + +#include <asm/types.h> + +/* +* ABIv1 requires dot symbol while ABIv2 does not. +*/ +#ifdef PPC64_ELF_ABI_v2 +#define DOTSYM (a) a +#else +#define GLUE (a, b) a##b +#define DOTSYM (a) GLUE(., a) +#endif
arch/powerpc/purgatory/printf.c new file +164 -0
164 lines not on this page · raw message
arch/powerpc/purgatory/purgatory-ppc64.c new file +41 -0
41 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 +62 -0
62 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 +134 -0
134 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [PATCH v3 3/9] kexec_file: Factor out kexec_locate_mem_hole from kexec_add_buffer.
In reply to Thiago Jung BauermannQuoted 54 lines · Thiago Jung Bauermann
kexec_locate_mem_holewill be used by the PowerPCkexec_file_loadimplementation to find free memory for the purgatory stack.Signed-off-by Thiago Jung Bauermann <[email protected]>Cc Eric Biederman <[email protected]>Cc Dave Young <[email protected]>--- include/linux/kexec.h | 4 ++++ kernel/kexec_file.c | 66 ++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 53 insertions(+), 17 deletions(-)include/linux/kexec.h +4
-0@@ -227,6 +227,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 +18
-0@@ -449,6 +449,46 @@ int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf,return walk_system_ram_res (0 ,ULONG_MAX , kbuf, 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. +* @min_addr: Minimum starting address. +* @max_addr: 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 errno on error. +*/ +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) +{ +int ret;
kernel/kexec_file.c int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf, · line 479
Quoted 10 lines
kernel/kexec_file.c +10
-0+struct kexec_buf buf; + +memset (&buf,0 ,sizeof (struct kexec_buf )); + buf.image = image; + + buf.memsz = size; + buf.buf_align = align; + buf.buf_min = min_addr; + buf.buf_max = max_addr; + buf.top_down = top_down;
Since patch 2/9 moved kexec_buf from internal header file to kexec.h it will be natural to passing a kexec_buf pointer intead of passing all these arguments in kexec_locate_mem_hole.
kbuf.mem can be used for addr.
Quoted 53 lines
kernel/kexec_file.c +19
-15+ + ret =arch_kexec_walk_mem (&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. @@ -460,8 +500,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)@@ -482,29 +522,21 @@ 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 */ - 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 ; - } + ret =kexec_locate_mem_hole (image, size, align, buf_min, buf_max, + top_down, &addr); +if (ret) +return ret;/* Found a suitable memory range */
kernel/kexec_file.c int kexec_add_buffer(struct kimage *image, char *buffer, unsigned long bufsz, · line 542
Quoted 10 lines
kernel/kexec_file.c +2
-2ksegment = &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 ;
Thanks
Dave
Re: [PATCH v3 2/9] kexec_file: Generalize kexec_add_buffer.
In reply to Thiago Jung BauermannThe patch looks good, but could the subject be more specific?
For example just like the first sentence of the patch descriotion:
Allow architectures to specify their own memory walking function
Quoted 108 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 | 19 ++++++++++++++++++- kernel/kexec_file.c | 30 ++++++++++++++++++++++-------- kernel/kexec_internal.h | 14 -------------- 3 files changed, 40 insertions(+), 23 deletions(-)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
-7@@ -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;
kernel/kexec_internal.h struct kexec_sha_region { · line 25
Quoted 10 lines
kernel/kexec_internal.h +0
-7-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) { }
Thanks
Dave
Quoted 14 lines · On Tue, 21 Jun 2016 16:48:32 -0300 Thiago Jung Bauermann…
Hello,
This patch series implements the
kexec_file_loadsystem call on PowerPC.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.
Quoted 7 lines
The above are the functions kexec already has built into
kexec_file_load. Yesterday I posted a set of patches which allows 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.
OK.. and this is safe? Do both the kernels need to be signed by the same certificate?
Balbir Singh
Hello Balbir,
Am Mittwoch, 22 Juni 2016, 23:29:46 schrieb Balbir Singh:
Quoted 19 lines
Quoted 17 lines · On Tue, 21 Jun 2016 16:48:32 -0300 Thiago Jung Bauermann…
This patch series implements the
kexec_file_loadsystem call on PowerPC.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, kernelcommand line and other boot inputs for the Integrity Measurement Architecture subsystem.
The above are the functions kexec already has built into
kexec_file_load. Yesterday I posted a set of patches which allows a third feature:
Quoted 7 lines
Quoted 4 lines
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.
OK.. and this is safe? Do both the kernels need to be signed by the same certificate?
They don't. The integrity of the event log (assuming that is what you mean by "this" in "this is safe") is guaranteed by the TPM device. Each event in the measurement list extends a PCR and records its PCR value. It is cryptographically guaranteed that if you replay the PCR extends recorded in the event log and in the end of the process they match the current PCR values in the TPM device, then that event log is correct.
The kernel signature serves to ensure that you only run kernels from an authorized provider. It doesn't play a role in integrity assurance, which aims to verify that the machine is really running the code it says it is running. As I understand it, at least. It's a bit subtle and I could be missing something...
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
Re: [PATCH v3 2/9] kexec_file: Generalize kexec_add_buffer.
In reply to Dave YoungAm Mittwoch, 22 Juni 2016, 18:20:47 schrieb Dave Young:
Quoted 4 lines
The patch looks good, but could the subject be more specific?
For example just like the first sentence of the patch descriotion:
Allow architectures to specify their own memory walking function
Ok, What about this? I also changed the description to refer to x86 arch instead of Intel arch.
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
Subject: [PATCH 2/9] kexec_file: Allow arch-specific memory walking for
kexec_add_buffer
Allow architectures to specify a different memory walking function for kexec_add_buffer. x86 uses iomem to track reserved memory ranges, but PowerPC uses the memblock subsystem.
--- include/linux/kexec.h | 19 ++++++++++++++++++- kernel/kexec_file.c | 30 ++++++++++++++++++++++-------- kernel/kexec_internal.h | 14 -------------- 3 files changed, 40 insertions(+), 23 deletions(-)
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) { }
Signature · 1 line
1.9.1
Re: [PATCH v3 3/9] kexec_file: Factor out kexec_locate_mem_hole from kexec_add_buffer.
In reply to Dave YoungAm Mittwoch, 22 Juni 2016, 18:18:01 schrieb Dave Young:
Quoted 35 lines · Thiago Jung Bauermann
Quoted 19 lines
+/**
+ *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.
+ * @min_addr: Minimum starting address.
+ * @max_addr: 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 errno on error.
+ */(quoted diff) +6
-0+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) +{ + int ret;Review
Quoted 10 lines
(quoted diff) +10
-0+ struct kexec_buf buf; + + memset(&buf, 0, sizeof(struct kexec_buf)); + buf.image = image; + + buf.memsz = size; + buf.buf_align = align; + buf.buf_min = min_addr; + buf.buf_max = max_addr; + buf.top_down = top_down;Since patch 2/9 moved
kexec_buffrom internal header file tokexec.hit will be natural to passing akexec_bufpointer intead of passing all these arguments inkexec_locate_mem_hole.
Quoted 1 line
kbuf.mem can be used for addr.
Ok. What about this version?
Signature · 20 lines
[]'s Thiago Jung Bauermann IBM Linux Technology Center Subject: [PATCH 3/9] kexec_file: Factor out kexec_locate_mem_hole from kexec_add_buffer. kexec_locate_mem_hole will be used by the PowerPC kexec_file_load implementation to find free memory for the purgatory stack. 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 | 12 +++++++++--- kernel/kexec_file.c | 25 ++++++++++++++++++++----- 2 files changed, 29 insertions(+), 8 deletions(-)
include/linux/kexec.h +9 -3
@@ -147,9 +147,14 @@ struct kexec_file_ops {#endif }; -/* -* Keeps track of buffer parameters as provided by caller for requesting -* memory placement of buffer. +/** +* struct kexec_buf - parameters for finding a place for a buffer in memory +* @image: kexec image in which memory to search. +* @size: Memory size for the buffer. +* @align: Minimum alignment needed. +* @min_addr: Minimum starting address. +* @max_addr: Maximum end address. +* @top_down: Find the highest free memory region? */ struct kexec_buf {struct kimage *image;
@@ -163,6 +168,7 @@ struct kexec_buf {int __weak arch_kexec_walk_mem (struct kexec_buf *kbuf,int (*func)(u64 ,u64 ,void *)); +int kexec_locate_mem_hole (struct kexec_buf *kbuf);#endif /* CONFIG_KEXEC_FILE */ struct kimage {
kernel/kexec_file.c +20 -5
@@ -449,6 +449,23 @@ int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf,return walk_system_ram_res (0 ,ULONG_MAX , kbuf, func); } +/** +* kexec_locate_mem_hole - find free memory to load segment or use in purgatory +* @kbuf: Parameters for the memory search. +* +* On success, kbuf->mem will have the start address of the memory region found. +* +* Return: 0 on success, negative errno on error. +*/ +int kexec_locate_mem_hole (struct kexec_buf *kbuf) +{ +int ret; + + ret =arch_kexec_walk_mem (kbuf, locate_mem_hole_callback); + +return ret ==1 ?0 : -EADDRNOTAVAIL ; +} +/* * Helper function for placing a buffer in a kexec segment. This assumes * that kexec_mutex is held.
@@ -493,11 +510,9 @@ 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 */ - 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 ; - } + ret =kexec_locate_mem_hole (kbuf); +if (ret) +return ret;/* Found a suitable memory range */ ksegment = &image->segment[image->nr_segments];
Signature · 1 line
1.9.1
Quoted 2 lines · Thiago Jung Bauermann
Hello Balbir,
Hi Thiago
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
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.
OK.. and this is safe? Do both the kernels need to be signed by the same certificate?
Quoted 6 lines
They don't. The integrity of the event log (assuming that is what you mean by "this" in "this is safe") is guaranteed by the TPM device. Each event in the measurement list extends a PCR and records its PCR value. It is cryptographically guaranteed that if you replay the PCR extends recorded in the event log and in the end of the process they match the current PCR values in the TPM device, then that event log is correct.
What I meant was how does the new kernel know that the old kernel did not cheat while passing on the values? I presume because we trust that kernel via a signature.
and
How do we know the new kernel is safe to load - I guess via a signature that the new kernel is signed with (assuming it is present in the key ring).
Balbir Singh
Re: [PATCH v3 2/9] kexec_file: Generalize kexec_add_buffer.
In reply to Thiago Jung BauermannQuoted 8 lines · Thiago Jung Bauermann
Am Mittwoch, 22 Juni 2016, 18:20:47 schrieb Dave Young:
Quoted 4 lines
The patch looks good, but could the subject be more specific?
For example just like the first sentence of the patch descriotion:
Allow architectures to specify their own memory walking functionOk, What about this? I also changed the description to refer to x86 arch instead of Intel arch.
It looks good to me.
Thanks
Dave
Quoted 138 lines
[]'s
Thiago Jung Bauermann
IBM Linux Technology CenterSubject: [PATCH 2/9]
kexec_file: Allow arch-specific memory walking for
kexec_add_bufferAllow architectures to specify a different memory walking function for
kexec_add_buffer. x86 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 | 19 ++++++++++++++++++- kernel/kexec_file.c | 30 ++++++++++++++++++++++-------- kernel/kexec_internal.h | 14 -------------- 3 files changed, 40 insertions(+), 23 deletions(-)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) { }Signature · 8 lines
1.9.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v3 3/9] kexec_file: Factor out kexec_locate_mem_hole from kexec_add_buffer.
In reply to Thiago Jung BauermannQuoted 70 lines · Thiago Jung Bauermann
Am Mittwoch, 22 Juni 2016, 18:18:01 schrieb Dave Young:
Quoted 35 lines · Thiago Jung Bauermann
Quoted 19 lines
+/**
+ *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.
+ * @min_addr: Minimum starting address.
+ * @max_addr: 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 errno on error.
+ */(quoted diff) +6
-0+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) +{ + int ret;Review
Quoted 10 lines
(quoted diff) +10
-0+ struct kexec_buf buf; + + memset(&buf, 0, sizeof(struct kexec_buf)); + buf.image = image; + + buf.memsz = size; + buf.buf_align = align; + buf.buf_min = min_addr; + buf.buf_max = max_addr; + buf.top_down = top_down;Since patch 2/9 moved
kexec_buffrom internal header file tokexec.hit will be natural to passing akexec_bufpointer intead of passing all these arguments inkexec_locate_mem_hole.Quoted 1 line
kbuf.mem can be used for addr.
Ok. What about this version?
Signature · 20 lines
[]'s Thiago Jung Bauermann IBM Linux Technology Center Subject: [PATCH 3/9] kexec_file: Factor out kexec_locate_mem_hole from kexec_add_buffer. kexec_locate_mem_hole will be used by the PowerPC kexec_file_load implementation to find free memory for the purgatory stack. 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 | 12 +++++++++--- kernel/kexec_file.c | 25 ++++++++++++++++++++----- 2 files changed, 29 insertions(+), 8 deletions(-)include/linux/kexec.h +0
-1@@ -147,9 +147,14 @@ struct kexec_file_ops {#endif }; -/*
include/linux/kexec.h struct kexec_file_ops { · line 157
Quoted 10 lines
include/linux/kexec.h +8
-2-* Keeps track of buffer parameters as provided by caller for requesting -* memory placement of buffer. +/** +* struct kexec_buf - parameters for finding a place for a buffer in memory +* @image: kexec image in which memory to search. +* @size: Memory size for the buffer. +* @align: Minimum alignment needed. +* @min_addr: Minimum starting address. +* @max_addr: Maximum end address. +* @top_down: Find the highest free memory region?
Above parameter comments should go to previous patch. Other than that it looks good.
Thanks
Dave
Quoted 65 lines
include/linux/kexec.h +1
-0*/ struct kexec_buf {struct kimage *image;@@ -163,6 +168,7 @@ struct kexec_buf {int __weak arch_kexec_walk_mem (struct kexec_buf *kbuf,int (*func)(u64 ,u64 ,void *)); +int kexec_locate_mem_hole (struct kexec_buf *kbuf);#endif /* CONFIG_KEXEC_FILE */ struct kimage {kernel/kexec_file.c +20
-5@@ -449,6 +449,23 @@ int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf,return walk_system_ram_res (0 ,ULONG_MAX , kbuf, func); } +/** +* kexec_locate_mem_hole - find free memory to load segment or use in purgatory +* @kbuf: Parameters for the memory search. +* +* On success, kbuf->mem will have the start address of the memory region found. +* +* Return: 0 on success, negative errno on error. +*/ +int kexec_locate_mem_hole (struct kexec_buf *kbuf) +{ +int ret; + + ret =arch_kexec_walk_mem (kbuf, locate_mem_hole_callback); + +return ret ==1 ?0 : -EADDRNOTAVAIL ; +} +/* * Helper function for placing a buffer in a kexec segment. This assumes * that kexec_mutex is held. @@ -493,11 +510,9 @@ 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 */ - 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 ; - } + ret =kexec_locate_mem_hole (kbuf); +if (ret) +return ret;/* Found a suitable memory range */ ksegment = &image->segment[image->nr_segments];Signature · 8 lines
1.9.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v3 3/9] kexec_file: Factor out kexec_locate_mem_hole from kexec_add_buffer.
----- Original Message -----
From: "Dave Young" <[email protected]>
To: "Thiago Jung Bauermann" <[email protected]>
Cc: [email protected], [email protected], [email protected], "Eric Biederman" <[email protected]>
Sent: Thursday, June 23, 2016 10:30:52 AM
Subject: Re: [PATCH v3 3/9] kexec_file: Factor out kexec_locate_mem_hole from kexec_add_buffer.
Quoted 70 lines · Thiago Jung Bauermann
Am Mittwoch, 22 Juni 2016, 18:18:01 schrieb Dave Young:
Quoted 35 lines · Thiago Jung Bauermann
Quoted 19 lines
+/**
+ *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.
+ * @min_addr: Minimum starting address.
+ * @max_addr: 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 errno on error.
+ */(quoted diff) +6
-0+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) +{ + int ret;Review
Quoted 10 lines
(quoted diff) +10
-0+ struct kexec_buf buf; + + memset(&buf, 0, sizeof(struct kexec_buf)); + buf.image = image; + + buf.memsz = size; + buf.buf_align = align; + buf.buf_min = min_addr; + buf.buf_max = max_addr; + buf.top_down = top_down;Since patch 2/9 moved
kexec_buffrom internal header file tokexec.hit will be natural to passing akexec_bufpointer intead of passing all these arguments inkexec_locate_mem_hole.Quoted 1 line
kbuf.mem can be used for addr.
Ok. What about this version?
Signature · 20 lines
[]'s Thiago Jung Bauermann IBM Linux Technology Center Subject: [PATCH 3/9] kexec_file: Factor out kexec_locate_mem_hole from kexec_add_buffer. kexec_locate_mem_hole will be used by the PowerPC kexec_file_load implementation to find free memory for the purgatory stack. 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 | 12 +++++++++--- kernel/kexec_file.c | 25 ++++++++++++++++++++----- 2 files changed, 29 insertions(+), 8 deletions(-)include/linux/kexec.h +0
-1@@ -147,9 +147,14 @@ struct kexec_file_ops {#endif }; -/*
include/linux/kexec.h struct kexec_file_ops { · line 157
Quoted 10 lines
include/linux/kexec.h +8
-2-* Keeps track of buffer parameters as provided by caller for requesting -* memory placement of buffer. +/** +* struct kexec_buf - parameters for finding a place for a buffer in memory +* @image: kexec image in which memory to search. +* @size: Memory size for the buffer. +* @align: Minimum alignment needed. +* @min_addr: Minimum starting address. +* @max_addr: Maximum end address. +* @top_down: Find the highest free memory region?
Hmm, hold on. For declaring a struct in a header file, comment should be just after each fields, like below, your format is for a function instead:
struct pci_slot {
struct pci_bus *bus; /* The bus this slot is on */
struct list_head list; /* node in list of slots on this bus */
struct hotplug_slot *hotplug; /* Hotplug info (migrate over time) */
unsigned char number; /* PCI_SLOT(pci_dev->devfn) */
struct kobject kobj;
};BTW, what is @size? there's no size field in kexec_buf. I think it is not necessary to add these comment, they are easy to understand. If you really want, please rewrite them correctly, for example "image" description is wrong. It is not only for searching memory only, top_down description is also bad.
Thanks
Dave
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v3 3/9] kexec_file: Factor out kexec_locate_mem_hole from kexec_add_buffer.
Am Donnerstag, 23 Juni 2016, 01:44:07 schrieb Dave Young:
Quoted 9 lines
Hmm, hold on. For declaring a struct in a header file, comment should be just after each fields, like below, your format is for a function instead:
structpci_slot{
structpci_bus*bus; /* The bus this slot is on */
structlist_headlist; /* node in list of slots on this
bus */ structhotplug_slot*hotplug; /* Hotplug info (migrate over
time) */ unsigned char number; /*PCI_SLOT(pci_dev->devfn)*/
struct kobject kobj;
};
The comment style you mention above is not extractable documentation. The style I used is what is described in section "kernel-doc for structs, unions, enums, and typedefs" in Documentation/kernel-doc-nano-HOWTO.txt.
Quoted 5 lines
BTW, what is @size? there's no size field in
kexec_buf. I think it is not necessary to add these comment, they are easy to understand. If you really want, please rewrite them correctly, for example "image" description is wrong. It is not only for searching memory only,top_downdescription is also bad.
Sorry, I moved these comments from kexec_locate_mem_hole but forgot to rename the parameters to what they are called in struct kexec_buf. @size should have been @memsz (other fields also have wrong names, I'll fix them as well). The image description is correct in the context of where struct kexec_buf is used and explains what it will be used for in the function taking kexec_buf as an argument. It is not meant as a general description of the purpose of struct kimage. What is bad about the description of top_down?
I decided to add these comments because struct kexec_buf is now part of the kernel API for kexec. kernel-doc-nano-HOWTO.txt says:
Quoted 11 lines
We definitely need kernel-doc formatted documentation for functions that are exported to loadable modules using
EXPORT_SYMBOL.We also look to provide kernel-doc formatted documentation for functions externally visible to other kernel files (not marked "static").
We also recommend providing kernel-doc formatted documentation for private (file "static") routines, for consistency of kernel source code layout. But this is lower priority and at the discretion of the MAINTAINER of that kernel source file.
If you think they are not necessary or just add clutter I can leave them out.
Signature · 3 lines
[]'s Thiago Jung Bauermann IBM Linux Technology Center
Am Donnerstag, 23 Juni 2016, 09:57:51 schrieb Balbir Singh:
Quoted 16 lines · Thiago Jung Bauermann
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
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.
OK.. and this is safe? Do both the kernels need to be signed by the same certificate?
Quoted 6 lines
They don't. The integrity of the event log (assuming that is what you mean by "this" in "this is safe") is guaranteed by the TPM device. Each event in the measurement list extends a PCR and records its PCR value. It is cryptographically guaranteed that if you replay the PCR extends recorded in the event log and in the end of the process they match the current PCR values in the TPM device, then that event log is correct.
Quoted 3 lines
What I meant was how does the new kernel know that the old kernel did not cheat while passing on the values? I presume because we trust that kernel via a signature.
Sorry, I still don't understand your concern. What kind of cheating? Which values? If it's the values in the event log, there's no need to trust the old kernel. The new kernel knows that the old kernel didn't pass wrong measurement values in the event log because it can recalculate the PCR extend operations recorded in the log and compare the results of the replay with the current PCR values stored in the TPM device. If they match, then the event log is guaranteed to be correct. If they don't match, either the memory was corrupted somehow during the kexec process, or the old kernel tried to pass a falsified event log.
There's no known way to construct an alternative series of PCR extend operations that will result in the same final value in the PCR register of the TPM device. If you can do that, you discovered a hash collision attack on the SHA-1 or SHA-256 algorithms (depending on which algorithm is being used by IMA in the event log). Or a bug in the TPM device implementation.
Quoted 5 lines
and
How do we know the new kernel is safe to load - I guess via a signature that the new kernel is signed with (assuming it is present in the key ring).
Correct. That goal is met by signature verification, not by integrity assurance.
I'll note that even with both of my patch series there's still code missing for kernel signature verification in PowerPC. I believe there's not a file format defined yet for how to store a signature in a PowerPC kernel image.
Integrity assurance doesn't depend on kernel signature verification though. There's value in both my patch series even without kernel signature verification support. They're complementary features.
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
Quoted 21 lines · Thiago Jung Bauermann
Am Donnerstag, 23 Juni 2016, 09:57:51 schrieb Balbir Singh:
Quoted 16 lines · Thiago Jung Bauermann
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
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.
OK.. and this is safe? Do both the kernels need to be signed by the same certificate?
Quoted 6 lines
They don't. The integrity of the event log (assuming that is what you mean by "this" in "this is safe") is guaranteed by the TPM device. Each event in the measurement list extends a PCR and records its PCR value. It is cryptographically guaranteed that if you replay the PCR extends recorded in the event log and in the end of the process they match the current PCR values in the TPM device, then that event log is correct.
Quoted 3 lines
What I meant was how does the new kernel know that the old kernel did not cheat while passing on the values? I presume because we trust that kernel via a signature.
Quoted 10 lines
Sorry, I still don't understand your concern. What kind of cheating? Which values? If it's the values in the event log, there's no need to trust the old kernel. The new kernel knows that the old kernel didn't pass wrong measurement values in the event log because it can recalculate the PCR extend operations recorded in the log and compare the results of the replay with the current PCR values stored in the TPM device. If they match, then the event log is guaranteed to be correct. If they don't match, either the memory was corrupted somehow during the kexec process, or the old kernel tried to pass a falsified event log.
Yep, get it/got it. My concern was anything using passed on the values should compare the results with the current PCR values.
BTW, what do we gain by passing the values if we are relying on the PCR registers anyway, can't we directly read them off from there? Aren't we going to ready anyway to compare, what does passing the values gain?
[snip]
Quoted 9 lines
Quoted 5 lines
and
How do we know the new kernel is safe to load - I guess via a signature that the new kernel is signed with (assuming it is present in the key ring).
Correct. That goal is met by signature verification, not by integrity assurance.
Quoted 8 lines
I'll note that even with both of my patch series there's still code missing for kernel signature verification in PowerPC. I believe there's not a file format defined yet for how to store a signature in a PowerPC kernel image.
Integrity assurance doesn't depend on kernel signature verification though. There's value in both my patch series even without kernel signature verification support. They're complementary features.
Thanks for clarifying
Balbir Singh.
Am Freitag, 24 Juni 2016, 08:33:24 schrieb Balbir Singh:
Quoted 11 lines · Thiago Jung Bauermann
Quoted 9 lines
Sorry, I still don't understand your concern. What kind of cheating? Which values? If it's the values in the event log, there's no need to trust the old kernel. The new kernel knows that the old kernel didn't pass wrong measurement values in the event log because it can recalculate the PCR extend operations recorded in the log and compare the results of the replay with the current PCR values stored in the TPM device. If they match, then the event log is guaranteed to be correct. If they don't match, either the memory was corrupted somehow during the kexec process, or the old kernel tried to pass a falsified event log.
Quoted 6 lines
Yep, get it/got it. My concern was anything using passed on the values should compare the results with the current PCR values.
BTW, what do we gain by passing the values if we are relying on the PCR registers anyway, can't we directly read them off from there? Aren't we going to ready anyway to compare, what does passing the values gain?
The PCR values themselves change for reasons that the application/user may not care about. For example, just changing the order in which measurements are made changes the final value of the PCR, even if all the measurements themselves don't change. And in current multi-processor machines this order does change at each boot, so you can't rely on two boots of the same machine with the same software to have the same PCR values.
Also, you may want to verify only the measurement of one of the components and not care about the other components.
With an event log, you can verify the checksum of each measured component individually, and the PCR value serves to confirm that the event log is correct. Just having the final PCR value without the event log, you don't know which measurements were made.
Quoted 14 lines
Quoted 14 lines
Quoted 5 lines
and
How do we know the new kernel is safe to load - I guess via a signature that the new kernel is signed with (assuming it is present in the key ring).
Correct. That goal is met by signature verification, not by integrity assurance.
I'll note that even with both of my patch series there's still code missing for kernel signature verification in PowerPC. I believe there's not a file format defined yet for how to store a signature in a PowerPC kernel image.
Quoted 5 lines
Quoted 3 lines
Integrity assurance doesn't depend on kernel signature verification though. There's value in both my patch series even without kernel signature verification support. They're complementary features.
Thanks for clarifying
Thank you for your interest.
Signature · 3 lines
[]'s Thiago Jung Bauermann IBM Linux Technology Center
Re: [PATCH v3 3/9] kexec_file: Factor out kexec_locate_mem_hole from kexec_add_buffer.
In reply to Thiago Jung BauermannQuoted 11 lines · Thiago Jung Bauermann
Am Donnerstag, 23 Juni 2016, 01:44:07 schrieb Dave Young:
Quoted 9 lines
Hmm, hold on. For declaring a struct in a header file, comment should be just after each fields, like below, your format is for a function instead:
structpci_slot{
structpci_bus*bus; /* The bus this slot is on */
structlist_headlist; /* node in list of slots on this
bus */ structhotplug_slot*hotplug; /* Hotplug info (migrate over
time) */ unsigned char number; /*PCI_SLOT(pci_dev->devfn)*/
struct kobject kobj;
};
Quoted 3 lines
The comment style you mention above is not extractable documentation. The style I used is what is described in section "kernel-doc for structs, unions, enums, and typedefs" in
Documentation/kernel-doc-nano-HOWTO.txt.
You are right and I was wrong!
Quoted 7 lines
Quoted 6 lines
BTW, what is @size? there's no size field in
kexec_buf. I think it is not necessary to add these comment, they are easy to understand. If you really want, please rewrite them correctly, for example "image" description is wrong. It is not only for searching memory only,top_downdescription is also bad.
Quoted 7 lines
Sorry, I moved these comments from
kexec_locate_mem_holebut forgot to rename the parameters to what they are called in structkexec_buf. @size should have been @memsz (other fields also have wrong names, I'll fix them as well). The image description is correct in the context of where structkexec_bufis used and explains what it will be used for in the function takingkexec_bufas an argument. It is not meant as a general description of the purpose of struct kimage. What is bad about the description oftop_down?
It is not clear enough to me, I personally think the original one in source code is better:
/* allocate from top of memory hole */
Quoted 11 lines
I decided to add these comments because struct
kexec_bufis now part of the kernel API for kexec. kernel-doc-nano-HOWTO.txt says:Quoted 7 lines
We definitely need kernel-doc formatted documentation for functions that are exported to loadable modules using
EXPORT_SYMBOL.We also look to provide kernel-doc formatted documentation for functions externally visible to other kernel files (not marked "static").
Quoted 7 lines
Quoted 4 lines
We also recommend providing kernel-doc formatted documentation for private (file "static") routines, for consistency of kernel source code layout. But this is lower priority and at the discretion of the MAINTAINER of that kernel source file.
If you think they are not necessary or just add clutter I can leave them out.
I'm fine with either way.
THanks
Dave
Re: [PATCH v3 3/9] kexec_file: Factor out kexec_locate_mem_hole from kexec_add_buffer.
Am Dienstag, 28 Juni 2016, 00:19:48 schrieb Dave Young:
Quoted 6 lines · Thiago Jung Bauermann
Quoted 2 lines
Am Donnerstag, 23 Juni 2016, 01:44:07 schrieb Dave Young:
What is bad about the description oftop_down?It is not clear enough to me, I personally think the original one in source code is better:
/* allocate from top of memory hole */
Actually I realized there's some discrepancy in how the x86 code uses top_down and how I need it to work in powerpc. This may be what is confusing about my comment and the existing comment.
x86 always walks memory from bottom to top but if top_down is true, in each memory region it will allocate the memory hole in the highest address within that region. I don't know why it is done that way, though.
On powerpc, the memory walk itself should be from top to bottom, as well as the memory hole allocation within each memory region.
Should I add a separate top_down argument to kexec_locate_mem_hole to control if the memory walk should be from top to bottom, and then the bottom_up member of struct kexec_buf controls where inside each memory region the memory hole will be allocated?
Signature · 3 lines
[]'s Thiago Jung Bauermann IBM Linux Technology Center
Re: [PATCH v3 3/9] kexec_file: Factor out kexec_locate_mem_hole from kexec_add_buffer.
Am Montag, 27 Juni 2016, 13:37:58 schrieb Thiago Jung Bauermann:
Quoted 4 lines
Should I add a separate
top_downargument tokexec_locate_mem_holeto control if the memory walk should be from top to bottom, and then thebottom_upmember of structkexec_bufcontrols where inside each memory region the memory hole will be allocated?
Er, "...the bottom_up member of struct kexec_buf..." should read "...the top_down member of struct kexec buf...".
Signature · 3 lines
[]'s Thiago Jung Bauermann IBM Linux Technology Center
Re: [PATCH v3 3/9] kexec_file: Factor out kexec_locate_mem_hole from kexec_add_buffer.
In reply to Thiago Jung BauermannPlease ignore previous reply, I mistakenly send a broken mail without subject, sorry about it. Resend the reply here.
Quoted 8 lines · Thiago Jung Bauermann
Am Dienstag, 28 Juni 2016, 00:19:48 schrieb Dave Young:
Quoted 6 lines · Thiago Jung Bauermann
Quoted 2 lines
Am Donnerstag, 23 Juni 2016, 01:44:07 schrieb Dave Young:
What is bad about the description oftop_down?It is not clear enough to me, I personally think the original one in source code is better:
/* allocate from top of memory hole */
Quoted 7 lines
Actually I realized there's some discrepancy in how the x86 code uses
top_downand how I need it to work in powerpc. This may be what is confusing about my comment and the existing comment.x86 always walks memory from bottom to top but if
top_downis true, in each memory region it will allocate the memory hole in the highest address within that region. I don't know why it is done that way, though.
I think we did not meaning to do this, considering kdump we have only one crashkernel region for searching (crashk_res) so it is fine. For kexec maybe changing the walking function to accept top_down is reasonable.
Ccing Vivek see if he can remember something..
Quoted 14 lines
On powerpc, the memory walk itself should be from top to bottom, as well as the memory hole allocation within each memory region.
Should I add a separate
top_downargument tokexec_locate_mem_holeto control if the memory walk should be from top to bottom, and then thebottom_upmember of structkexec_bufcontrols where inside each memory region the memory hole will be allocated?Signature · 3 lines
[]'s Thiago Jung Bauermann IBM Linux Technology Center
Re: [PATCH v3 3/9] kexec_file: Factor out kexec_locate_mem_hole from kexec_add_buffer.
Quoted 20 lines · Dave Young
Please ignore previous reply, I mistakenly send a broken mail without subject, sorry about it. Resend the reply here.
Quoted 8 lines · Thiago Jung Bauermann
Am Dienstag, 28 Juni 2016, 00:19:48 schrieb Dave Young:
Quoted 6 lines · Thiago Jung Bauermann
Quoted 2 lines
Am Donnerstag, 23 Juni 2016, 01:44:07 schrieb Dave Young:
What is bad about the description oftop_down?It is not clear enough to me, I personally think the original one in source code is better:
/* allocate from top of memory hole */Quoted 7 lines
Actually I realized there's some discrepancy in how the x86 code uses
top_downand how I need it to work in powerpc. This may be what is confusing about my comment and the existing comment.x86 always walks memory from bottom to top but if
top_downis true, in each memory region it will allocate the memory hole in the highest address within that region. I don't know why it is done that way, though.
Quoted 10 lines
I think we did not meaning to do this, considering kdump we have only one crashkernel region for searching (
crashk_res) so it is fine. For kexec maybe changing the walking function to accepttop_downis reasonable.Ccing Vivek see if he can remember something..
Quoted 3 lines
On powerpc, the memory walk itself should be from top to bottom, as well as the memory hole allocation within each memory region.
What is the particular reason in powerpc for a mandatory top to bottom walking?
Quoted 5 lines
Quoted 5 lines
Should I add a separate
top_downargument tokexec_locate_mem_holeto control if the memory walk should be from top to bottom, and then thebottom_upmember of structkexec_bufcontrols where inside each memory region the memory hole will be allocated?
Using one argument for both sounds more reasonable than using a separate argument for memory walk..
Thanks
Dave
Re: [PATCH v3 2/9] kexec_file: Generalize kexec_add_buffer.
In reply to Dave YoungAm Donnerstag, 23 Juni 2016, 10:25:06 schrieb Dave Young:
Quoted 11 lines · Thiago Jung Bauermann
Quoted 8 lines
Am Mittwoch, 22 Juni 2016, 18:20:47 schrieb Dave Young:
Quoted 4 lines
The patch looks good, but could the subject be more specific?
For example just like the first sentence of the patch descriotion:
Allow architectures to specify their own memory walking functionOk, What about this? I also changed the description to refer to x86 arch instead of Intel arch.
It looks good to me.
This version has the struct kexec_buf documentation comments that were in patch 3/9. I fixed the names of the struct members, and changed their descriptions to try to be clearer.
Signature · 22 lines
[]'s Thiago Jung Bauermann IBM Linux Technology Center Subject: [PATCH 2/9] kexec_file: Allow arch-specific memory walking for kexec_add_buffer Allow architectures to specify a different memory walking function for kexec_add_buffer. x86 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 | 25 ++++++++++++++++++++++++- kernel/kexec_file.c | 30 ++++++++++++++++++++++-------- kernel/kexec_internal.h | 14 -------------- 3 files changed, 46 insertions(+), 23 deletions(-)
include/linux/kexec.h +24 -1
@@ -146,7 +146,30 @@ struct kexec_file_ops {kexec_verify_sig_t *verify_sig;#endif }; -#endif + +/** +* struct kexec_buf - parameters for finding a place for a buffer in memory +* @image: kexec image in which memory to search. +* @mem: On return will have address of the buffer in memory. +* @memsz: Size for the buffer in memory. +* @buf_align: Minimum alignment needed. +* @buf_min: The buffer can't be placed below this address. +* @buf_max: The buffer can't be placed above this address. +* @top_down: Allocate from top of memory. +*/ +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; +}; + +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) { }
Signature · 1 line
1.9.1
Re: [PATCH v3 3/9] kexec_file: Factor out kexec_locate_mem_hole from kexec_add_buffer.
In reply to Dave YoungAm Dienstag, 28 Juni 2016, 15:20:55 schrieb Dave Young:
Quoted 28 lines · Dave Young
Quoted 27 lines
Please ignore previous reply, I mistakenly send a broken mail without subject, sorry about it. Resend the reply here.
Quoted 9 lines · Thiago Jung Bauermann
Am Dienstag, 28 Juni 2016, 00:19:48 schrieb Dave Young:
Quoted 7 lines · Thiago Jung Bauermann
Quoted 2 lines
Am Donnerstag, 23 Juni 2016, 01:44:07 schrieb Dave Young:
What is bad about the description oftop_down?It is not clear enough to me, I personally think the original one in source code is better:
/* allocate from top of memory hole */Quoted 8 lines
Actually I realized there's some discrepancy in how the x86 code uses
top_downand how I need it to work in powerpc. This may be what is confusing about my comment and the existing comment.x86 always walks memory from bottom to top but if
top_downis true, in each memory region it will allocate the memory hole in the highest address within that region. I don't know why it is done that way, though.I think we did not meaning to do this, considering kdump we have only one crashkernel region for searching (
crashk_res) so it is fine. For kexec maybe changing the walking function to accepttop_downis reasonable.
Quoted 7 lines
Quoted 4 lines
Ccing Vivek see if he can remember something..
Quoted 2 lines
On powerpc, the memory walk itself should be from top to bottom, as well as the memory hole allocation within each memory region.
What is the particular reason in powerpc for a mandatory top to bottom walking?
I'm walking unreserved memory ranges, so reservations made low in memory (such as the reservation for the initrd) may create a memory hole that is a lot lower than the true memory limit where I want to allocate from (768 MB). In this situation, allocating at the highest address in the lowest free memory range will allocate the buffer very low in memory, and in that case top_down doesn't mean much.
Walking memory from lowest to highest address but then allocating memory at the highest address inside the memory range is peculiar and surprising. Is there a particular reason for it?
If it's an accident and doesn't affect x86, I'd suggest that top_down should have its expected behavior, which (at least for me) is: allocate from the highest available memory address within the desired range.
In any case, my patch series allows each architecture to define what top_down should mean. It doesn't change the behavior in x86, since the default implementation of arch_kexec_walk_mem ignores kexec_buf.top_down, and allows powerpc to take top_down into account when walking memory.
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Should I add a separate
top_downargument tokexec_locate_mem_holeto control if the memory walk should be from top to bottom, and then thebottom_upmember of structkexec_bufcontrols where inside each memory region the memory hole will be allocated?Using one argument for both sounds more reasonable than using a separate argument for memory walk..
I agree. This patch doesn't use a separate top_down argument, it's the same patch I sent earlier except that the comments to struct kexec_buf are in patch 2/9. What do you think?
Signature · 20 lines
[]'s Thiago Jung Bauermann IBM Linux Technology Center Subject: [PATCH 3/9] kexec_file: Factor out kexec_locate_mem_hole from kexec_add_buffer. kexec_locate_mem_hole will be used by the PowerPC kexec_file_load implementation to find free memory for the purgatory stack. 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 | 1 + kernel/kexec_file.c | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-)
include/linux/kexec.h +1 -0
@@ -169,6 +169,7 @@ struct kexec_buf {int __weak arch_kexec_walk_mem (struct kexec_buf *kbuf,int (*func)(u64 ,u64 ,void *)); +int kexec_locate_mem_hole (struct kexec_buf *kbuf);#endif /* CONFIG_KEXEC_FILE */ struct kimage {
kernel/kexec_file.c +20 -5
@@ -449,6 +449,23 @@ int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf,return walk_system_ram_res (0 ,ULONG_MAX , kbuf, func); } +/** +* kexec_locate_mem_hole - find free memory to load segment or use in purgatory +* @kbuf: Parameters for the memory search. +* +* On success, kbuf->mem will have the start address of the memory region found. +* +* Return: 0 on success, negative errno on error. +*/ +int kexec_locate_mem_hole (struct kexec_buf *kbuf) +{ +int ret; + + ret =arch_kexec_walk_mem (kbuf, locate_mem_hole_callback); + +return ret ==1 ?0 : -EADDRNOTAVAIL ; +} +/* * Helper function for placing a buffer in a kexec segment. This assumes * that kexec_mutex is held.
@@ -493,11 +510,9 @@ 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 */ - 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 ; - } + ret =kexec_locate_mem_hole (kbuf); +if (ret) +return ret;/* Found a suitable memory range */ ksegment = &image->segment[image->nr_segments];
Signature · 1 line
1.9.1
Re: [PATCH v3 3/9] kexec_file: Factor out kexec_locate_mem_hole from kexec_add_buffer.
Quoted 44 lines · Thiago Jung Bauermann
Am Dienstag, 28 Juni 2016, 15:20:55 schrieb Dave Young:
Quoted 28 lines · Dave Young
Quoted 27 lines
Please ignore previous reply, I mistakenly send a broken mail without subject, sorry about it. Resend the reply here.
Quoted 9 lines · Thiago Jung Bauermann
Am Dienstag, 28 Juni 2016, 00:19:48 schrieb Dave Young:
Quoted 7 lines · Thiago Jung Bauermann
Quoted 2 lines
Am Donnerstag, 23 Juni 2016, 01:44:07 schrieb Dave Young:
What is bad about the description oftop_down?It is not clear enough to me, I personally think the original one in source code is better:
/* allocate from top of memory hole */Quoted 8 lines
Actually I realized there's some discrepancy in how the x86 code uses
top_downand how I need it to work in powerpc. This may be what is confusing about my comment and the existing comment.x86 always walks memory from bottom to top but if
top_downis true, in each memory region it will allocate the memory hole in the highest address within that region. I don't know why it is done that way, though.I think we did not meaning to do this, considering kdump we have only one crashkernel region for searching (
crashk_res) so it is fine. For kexec maybe changing the walking function to accepttop_downis reasonable.Quoted 7 lines
Quoted 4 lines
Ccing Vivek see if he can remember something..
Quoted 2 lines
On powerpc, the memory walk itself should be from top to bottom, as well as the memory hole allocation within each memory region.
What is the particular reason in powerpc for a mandatory top to bottom walking?
I'm walking unreserved memory ranges, so reservations made low in memory (such as the reservation for the initrd) may create a memory hole that is a lot lower than the true memory limit where I want to allocate from (768 MB). In this situation, allocating at the highest address in the lowest free memory range will allocate the buffer very low in memory, and in that case
top_downdoesn't mean much.
Quoted 3 lines
Walking memory from lowest to highest address but then allocating memory at the highest address inside the memory range is peculiar and surprising. Is there a particular reason for it?
I do not know if there's some historic reason, personally I think it should be an accident.
Quoted 4 lines
If it's an accident and doesn't affect x86, I'd suggest that
top_downshould have its expected behavior, which (at least for me) is: allocate from the highest available memory address within the desired range.
I tend to agree, but we need test it first to see if it breaks something.
Quoted 12 lines
In any case, my patch series allows each architecture to define what
top_downshould mean. It doesn't change the behavior in x86, since the default implementation ofarch_kexec_walk_memignores kexec_buf.top_down, and allows powerpc to taketop_downinto account when walking memory.Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
Should I add a separate
top_downargument tokexec_locate_mem_holeto control if the memory walk should be from top to bottom, and then thebottom_upmember of structkexec_bufcontrols where inside each memory region the memory hole will be allocated?
Quoted 6 lines
Quoted 2 lines
Using one argument for both sounds more reasonable than using a separate argument for memory walk..
I agree. This patch doesn't use a separate
top_downargument, it's the same patch I sent earlier except that the comments to structkexec_bufare in patch 2/9. What do you think?
It looks good except one nitpick inline..
Quoted 40 lines
Signature · 21 lines
-- []'s Thiago Jung Bauermann IBM Linux Technology Center Subject: [PATCH 3/9] kexec_file: Factor out kexec_locate_mem_hole from kexec_add_buffer. kexec_locate_mem_hole will be used by the PowerPC kexec_file_load implementation to find free memory for the purgatory stack. 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 | 1 + kernel/kexec_file.c | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-)include/linux/kexec.h +1
-0@@ -169,6 +169,7 @@ struct kexec_buf {int __weak arch_kexec_walk_mem (struct kexec_buf *kbuf,int (*func)(u64 ,u64 ,void *)); +int kexec_locate_mem_hole (struct kexec_buf *kbuf);#endif /* CONFIG_KEXEC_FILE */ struct kimage {kernel/kexec_file.c +0
-0
kernel/kexec_file.c int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf, · line 453
Quoted 5 lines
kernel/kexec_file.c +2
-0@@ -449,6 +449,23 @@ int __weak arch_kexec_walk_mem(struct kexec_buf *kbuf,return walk_system_ram_res (0 ,ULONG_MAX , kbuf, func); } +/** +* kexec_locate_mem_hole - find free memory to load segment or use in purgatory
It is not necessary to use only for purgatory load..
Quoted 37 lines
kernel/kexec_file.c +18
-5+* @kbuf: Parameters for the memory search. +* +* On success, kbuf->mem will have the start address of the memory region found. +* +* Return: 0 on success, negative errno on error. +*/ +int kexec_locate_mem_hole (struct kexec_buf *kbuf) +{ +int ret; + + ret =arch_kexec_walk_mem (kbuf, locate_mem_hole_callback); + +return ret ==1 ?0 : -EADDRNOTAVAIL ; +} +/* * Helper function for placing a buffer in a kexec segment. This assumes * that kexec_mutex is held. @@ -493,11 +510,9 @@ 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 */ - 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 ; - } + ret =kexec_locate_mem_hole (kbuf); +if (ret) +return ret;/* Found a suitable memory range */ ksegment = &image->segment[image->nr_segments];Signature · 1 line
1.9.1
Thanks
Dave
Re: [PATCH v3 2/9] kexec_file: Generalize kexec_add_buffer.
In reply to Thiago Jung BauermannQuoted 59 lines · Thiago Jung Bauermann
Am Donnerstag, 23 Juni 2016, 10:25:06 schrieb Dave Young:
Quoted 11 lines · Thiago Jung Bauermann
Quoted 8 lines
Am Mittwoch, 22 Juni 2016, 18:20:47 schrieb Dave Young:
Quoted 4 lines
The patch looks good, but could the subject be more specific?
For example just like the first sentence of the patch descriotion:
Allow architectures to specify their own memory walking functionOk, What about this? I also changed the description to refer to x86 arch instead of Intel arch.
It looks good to me.
This version has the struct
kexec_bufdocumentation comments that were in patch 3/9. I fixed the names of the struct members, and changed their descriptions to try to be clearer.Signature · 22 lines
[]'s Thiago Jung Bauermann IBM Linux Technology Center Subject: [PATCH 2/9] kexec_file: Allow arch-specific memory walking for kexec_add_buffer Allow architectures to specify a different memory walking function for kexec_add_buffer. x86 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 | 25 ++++++++++++++++++++++++- kernel/kexec_file.c | 30 ++++++++++++++++++++++-------- kernel/kexec_internal.h | 14 -------------- 3 files changed, 46 insertions(+), 23 deletions(-)include/linux/kexec.h +10
-1@@ -146,7 +146,30 @@ struct kexec_file_ops {kexec_verify_sig_t *verify_sig;#endif }; -#endif + +/** +* struct kexec_buf - parameters for finding a place for a buffer in memory +* @image: kexec image in which memory to search. +* @mem: On return will have address of the buffer in memory. +* @memsz: Size for the buffer in memory. +* @buf_align: Minimum alignment needed. +* @buf_min: The buffer can't be placed below this address. +* @buf_max: The buffer can't be placed above this address. +* @top_down: Allocate from top of memory.
include/linux/kexec.h struct kexec_file_ops { · line 168
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; +};
Rethink about the first patch, you dropped the user buffer in kexec_buf But later your passing IMA digests buffer patchset may need use it.
So keep it in kexec_buf should be better.
For the IMA buffer patchset I'm still reading and learning the background, will reply them later.
Quoted 84 lines
include/linux/kexec.h +4
-0+ +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) { }Signature · 1 line
1.9.1
Thanks
Dave
Re: [PATCH v3 3/9] kexec_file: Factor out kexec_locate_mem_hole from kexec_add_buffer.
In reply to Dave YoungAm Mittwoch, 29 Juni 2016, 15:45:18 schrieb Dave Young:
Quoted 11 lines · Thiago Jung Bauermann
Quoted 9 lines
Am Dienstag, 28 Juni 2016, 15:20:55 schrieb Dave Young:
Quoted 4 lines · Dave Young
Using one argument for both sounds more reasonable than using a separate
argument for memory walk..I agree. This patch doesn't use a separate
top_downargument, it's the same patch I sent earlier except that the comments to structkexec_bufare in patch 2/9. What do you think?
Quoted 8 lines
It looks good except one nitpick inline..
Quoted 3 lines
+/**
+ *kexec_locate_mem_hole- find free memory to load segment or use in purgatoryIt is not necessary to use only for purgatory load..
Ok, what about this?
/**
* kexec_locate_mem_hole - find free memory in a given kimage.
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
Re: [PATCH v3 2/9] kexec_file: Generalize kexec_add_buffer.
In reply to Dave YoungAm Mittwoch, 29 Juni 2016, 15:47:51 schrieb Dave Young:
Quoted 37 lines · Thiago Jung Bauermann
Quoted 23 lines
include/linux/kexec.h +3
-1@@ -146,7 +146,30 @@ struct kexec_file_ops {kexec_verify_sig_t *verify_sig;#endif }; -#endif + +/** +* struct kexec_buf - parameters for finding a place for a buffer in memory + * @image: kexec image in which memory to search.
+ * @mem: On return will have address of the buffer in memory.
+ * @memsz: Size for the buffer in memory.
+ * @buf_align: Minimum alignment needed.
+ * @buf_min: The buffer can't be placed below this address.
+ * @buf_max: The buffer can't be placed above this address.
+ * @top_down: Allocate from top of memory.
+ */include/linux/kexec.h struct kexec_file_ops { · line 168
Quoted 9 lines
include/linux/kexec.h +9
-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; +};Rethink about the first patch, you dropped the user buffer in
kexec_bufBut later your passing IMA digests buffer patchset may need use it.
Quoted 1 line
So keep it in
kexec_bufshould be better.
I'm not following. The IMA buffer patchset doesn't use kexec_locate_mem_hole nor struct kexec_buf.
Quoted 2 lines
For the IMA buffer patchset I'm still reading and learning the background, will reply them later.
Thank you!
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
Re: [PATCH v3 2/9] kexec_file: Generalize kexec_add_buffer.
Quoted 38 lines · Thiago Jung Bauermann
Am Mittwoch, 29 Juni 2016, 15:47:51 schrieb Dave Young:
Quoted 37 lines · Thiago Jung Bauermann
Quoted 23 lines
include/linux/kexec.h +3
-1@@ -146,7 +146,30 @@ struct kexec_file_ops {kexec_verify_sig_t *verify_sig;#endif }; -#endif + +/** +* struct kexec_buf - parameters for finding a place for a buffer in memory + * @image: kexec image in which memory to search.
+ * @mem: On return will have address of the buffer in memory.
+ * @memsz: Size for the buffer in memory.
+ * @buf_align: Minimum alignment needed.
+ * @buf_min: The buffer can't be placed below this address.
+ * @buf_max: The buffer can't be placed above this address.
+ * @top_down: Allocate from top of memory.
+ */include/linux/kexec.h struct kexec_file_ops { · line 168
Quoted 9 lines
include/linux/kexec.h +9
-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; +};Rethink about the first patch, you dropped the user buffer in
kexec_bufBut later your passing IMA digests buffer patchset may need use it.
Quoted 4 lines
Quoted 1 line
So keep it in
kexec_bufshould be better.I'm not following. The IMA buffer patchset doesn't use
kexec_locate_mem_holenor structkexec_buf.
It does not use kexec_locate_mem_hole, but the buffer being passed is very similar to a kexec_buf struct, no?
So you may refactor kexec_add_buffer and your new function to pass only kimage and a kbuf, it will be better than passing all those arguments separately.
Quoted 10 lines
Quoted 3 lines
For the IMA buffer patchset I'm still reading and learning the background, will reply them later.
Thank you!
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
Thanks
Dave
Re: [PATCH v3 3/9] kexec_file: Factor out kexec_locate_mem_hole from kexec_add_buffer.
In reply to Thiago Jung BauermannQuoted 19 lines · Thiago Jung Bauermann
Am Mittwoch, 29 Juni 2016, 15:45:18 schrieb Dave Young:
Quoted 17 lines · Thiago Jung Bauermann
Quoted 9 lines
Am Dienstag, 28 Juni 2016, 15:20:55 schrieb Dave Young:
Quoted 4 lines · Dave Young
Using one argument for both sounds more reasonable than using a separate
argument for memory walk..I agree. This patch doesn't use a separate
top_downargument, it's the same patch I sent earlier except that the comments to structkexec_bufare in patch 2/9. What do you think?It looks good except one nitpick inline..
Quoted 3 lines
+/**
+ *kexec_locate_mem_hole- find free memory to load segment or use in purgatory
Quoted 6 lines
Quoted 1 line
It is not necessary to use only for purgatory load..
Ok, what about this?
/**
*kexec_locate_mem_hole- find free memory in a given kimage.
Hmm, a given kimage sounds not correct, I can not get a better way to describe it. How about below with a little change to your previous one:
kexec_locate_mem_hole - find a free chunk of memory to load kexec segment. In powerpc the memory chunk can also be used for the purgatory stack.
Thanks
Dave
Re: [PATCH v3 2/9] kexec_file: Generalize kexec_add_buffer.
In reply to Dave YoungAm Donnerstag, 30 Juni 2016, 11:07:00 schrieb Dave Young:
Quoted 28 lines · Thiago Jung Bauermann
Quoted 27 lines
Am Mittwoch, 29 Juni 2016, 15:47:51 schrieb Dave Young:
Quoted 26 lines · Thiago Jung Bauermann
Quoted 11 lines
+/**
+ * structkexec_buf- parameters for finding a place for a buffer in
memory + * @image: kexec image in which memory to search.
+ * @mem: On return will have address of the buffer in memory.
+ * @memsz: Size for the buffer in memory.
+ * @buf_align: Minimum alignment needed.
+ * @buf_min: The buffer can't be placed below this address.
+ * @buf_max: The buffer can't be placed above this address.
+ * @top_down: Allocate from top of memory.
+ */include/linux/kexec.h struct kexec_file_ops { · line 168
Quoted 9 lines
include/linux/kexec.h +9
-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; +};Rethink about the first patch, you dropped the user buffer in
kexec_buf
But later your passing IMA digests buffer patchset may need use it.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
So keep it in
kexec_bufshould be better.I'm not following. The IMA buffer patchset doesn't use
kexec_locate_mem_holenor structkexec_buf.It does not use
kexec_locate_mem_hole, but the buffer being passed is very similar to akexec_bufstruct, no?
If what you're saying is that the arguments passed to kexec_add_handover_buffer in the IMA buffer patchset are very similar to the arguments passed to kexec_add_buffer then yes, it's true.
Quoted 3 lines
So you may refactor
kexec_add_bufferand your new function to pass only kimage and a kbuf, it will be better than passing all those arguments separately.
To be honest I think struct kexec_buf is an implementation detail inside kexec_locate_mem_hole, made necessary because the callback functions it uses need to access its arguments. Callers of kexec_locate_mem_hole, kexec_add_handover_buffer and kexec_add_buffer shouldn't need to know it exists.
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
Re: [PATCH v3 3/9] kexec_file: Factor out kexec_locate_mem_hole from kexec_add_buffer.
In reply to Dave YoungAm Donnerstag, 30 Juni 2016, 11:41:19 schrieb Dave Young:
Quoted 18 lines · Thiago Jung Bauermann
Quoted 17 lines
Am Mittwoch, 29 Juni 2016, 15:45:18 schrieb Dave Young:
Quoted 11 lines · Thiago Jung Bauermann
Quoted 2 lines
Am Dienstag, 28 Juni 2016, 15:20:55 schrieb Dave Young:
Quoted 1 line · Dave Young
It looks good except one nitpick inline..
Quoted 4 lines
+/**
+ *kexec_locate_mem_hole- find free memory to load segment or use in
purgatoryIt is not necessary to use only for purgatory load..
Ok, what about this?
/**
Quoted 7 lines
Quoted 1 line
*
kexec_locate_mem_hole- find free memory in a given kimage.Hmm, a given kimage sounds not correct, I can not get a better way to describe it. How about below with a little change to your previous one:
kexec_locate_mem_hole- find a free chunk of memory to load kexec segment. In powerpc the memory chunk can also be used for the purgatory stack.
That describes what the memory currently is used for. If powerpc or any other architecture starts to use the memory for something else, this comment would need to be updated. :-)
What the function really does is find free memory in the physical address space after the currently running kernel hands over control to whatever runs next. What that memory is used for is decided by the caller of the function.
Since (at least for now), the only things that run next are the purgatory and the next kernel, what about this?
kexec_locate_mem_hole - find free memory for the purgatory or the next kernel
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
Re: [PATCH v3 2/9] kexec_file: Generalize kexec_add_buffer.
In reply to Thiago Jung BauermannAm Donnerstag, 30 Juni 2016, 12:49:44 schrieb Thiago Jung Bauermann:
Quoted 16 lines
Am Donnerstag, 30 Juni 2016, 11:07:00 schrieb Dave Young:
Quoted 6 lines · Thiago Jung Bauermann
Quoted 2 lines
I'm not following. The IMA buffer patchset doesn't use
kexec_locate_mem_holenor structkexec_buf.It does not use
kexec_locate_mem_hole, but the buffer being passed is very similar to akexec_bufstruct, no?If what you're saying is that the arguments passed to
kexec_add_handover_bufferin the IMA buffer patchset are very similar to the arguments passed tokexec_add_bufferthen yes, it's true.Quoted 3 lines
So you may refactor
kexec_add_bufferand your new function to pass only kimage and a kbuf, it will be better than passing all those arguments separately.
Quoted 5 lines
To be honest I think struct
kexec_bufis an implementation detail insidekexec_locate_mem_hole, made necessary because the callback functions it uses need to access its arguments. Callers ofkexec_locate_mem_hole,kexec_add_handover_bufferandkexec_add_buffershouldn't need to know it exists.
Elaborating a bit more: the argument list for these three functions are equal or similar because kexec_add_handover_buffer uses kexec_add_buffer, which uses kexec_locate_mem_hole.
It could be beneficial to have a struct to collect the arguments to these functions if someone using one of them would be likely to use another one with the same arguments. In that case, you set up kexec_buf once and then just pass it whenever you need to call one of those functions.
But that is unlikely to happen. A user of the kexec API will need to use only one of these functions with a given set of arguments, so they don't gain anything by setting up a struct.
Syntactically, I also don't think it's clearer to set struct members instead of simply passing arguments to a function, even if the argument list is long.
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
Re: [PATCH v3 3/9] kexec_file: Factor out kexec_locate_mem_hole from kexec_add_buffer.
In reply to Thiago Jung BauermannQuoted 35 lines · Thiago Jung Bauermann
Am Donnerstag, 30 Juni 2016, 11:41:19 schrieb Dave Young:
Quoted 18 lines · Thiago Jung Bauermann
Quoted 17 lines
Am Mittwoch, 29 Juni 2016, 15:45:18 schrieb Dave Young:
Quoted 11 lines · Thiago Jung Bauermann
Quoted 2 lines
Am Dienstag, 28 Juni 2016, 15:20:55 schrieb Dave Young:
Quoted 1 line · Dave Young
It looks good except one nitpick inline..
Quoted 4 lines
+/**
+ *kexec_locate_mem_hole- find free memory to load segment or use in
purgatoryIt is not necessary to use only for purgatory load..
Ok, what about this?
/**
Quoted 7 lines
Quoted 1 line
*
kexec_locate_mem_hole- find free memory in a given kimage.Hmm, a given kimage sounds not correct, I can not get a better way to describe it. How about below with a little change to your previous one:
kexec_locate_mem_hole- find a free chunk of memory to load kexec segment. In powerpc the memory chunk can also be used for the purgatory stack.That describes what the memory currently is used for. If powerpc or any other architecture starts to use the memory for something else, this comment would need to be updated. :-)
What the function really does is find free memory in the physical address space after the currently running kernel hands over control to whatever runs next. What that memory is used for is decided by the caller of the function.
Quoted 5 lines
Since (at least for now), the only things that run next are the purgatory and the next kernel, what about this?
kexec_locate_mem_hole- find free memory for the purgatory or the next kernel
Ok, I'm fine with above version.
Thanks
Dave
Re: [PATCH v3 2/9] kexec_file: Generalize kexec_add_buffer.
In reply to Thiago Jung BauermannQuoted 32 lines · Thiago Jung Bauermann
Am Donnerstag, 30 Juni 2016, 12:49:44 schrieb Thiago Jung Bauermann:
Quoted 16 lines
Am Donnerstag, 30 Juni 2016, 11:07:00 schrieb Dave Young:
Quoted 6 lines · Thiago Jung Bauermann
Quoted 2 lines
I'm not following. The IMA buffer patchset doesn't use
kexec_locate_mem_holenor structkexec_buf.It does not use
kexec_locate_mem_hole, but the buffer being passed is very similar to akexec_bufstruct, no?If what you're saying is that the arguments passed to
kexec_add_handover_bufferin the IMA buffer patchset are very similar to the arguments passed tokexec_add_bufferthen yes, it's true.Quoted 3 lines
So you may refactor
kexec_add_bufferand your new function to pass only kimage and a kbuf, it will be better than passing all those arguments separately.Quoted 5 lines
To be honest I think struct
kexec_bufis an implementation detail insidekexec_locate_mem_hole, made necessary because the callback functions it uses need to access its arguments. Callers ofkexec_locate_mem_hole,kexec_add_handover_bufferandkexec_add_buffershouldn't need to know it exists.Elaborating a bit more: the argument list for these three functions are equal or similar because
kexec_add_handover_bufferuseskexec_add_buffer, which useskexec_locate_mem_hole.It could be beneficial to have a struct to collect the arguments to these functions if someone using one of them would be likely to use another one with the same arguments. In that case, you set up
kexec_bufonce and then just pass it whenever you need to call one of those functions.
Quoted 7 lines
But that is unlikely to happen. A user of the kexec API will need to use only one of these functions with a given set of arguments, so they don't gain anything by setting up a struct.
Syntactically, I also don't think it's clearer to set struct members instead of simply passing arguments to a function, even if the argument list is long.
Sorry, I'm not sure I get your points but the long argument list really looks ugly, since you are introducing more callbacks I still think a cleanup is necessary.
kexec_buffer struct is pretty fine to be a abstract of all these buffers.
Thanks
Dave
Re: [PATCH v3 2/9] kexec_file: Generalize kexec_add_buffer.
Am Donnerstag, 30 Juni 2016, 17:43:57 schrieb Dave Young:
Quoted 32 lines · Thiago Jung Bauermann
Quoted 23 lines
Am Donnerstag, 30 Juni 2016, 12:49:44 schrieb Thiago Jung Bauermann:
Quoted 8 lines
To be honest I think struct
kexec_bufis an implementation detail insidekexec_locate_mem_hole, made necessary because the callback functions it
uses need to access its arguments. Callers ofkexec_locate_mem_hole,kexec_add_handover_bufferandkexec_add_buffershouldn't need to know it
exists.Elaborating a bit more: the argument list for these three functions are equal or similar because
kexec_add_handover_bufferuseskexec_add_buffer,
which useskexec_locate_mem_hole.It could be beneficial to have a struct to collect the arguments to these
functions if someone using one of them would be likely to use another one
with the same arguments. In that case, you set upkexec_bufonce and then
just pass it whenever you need to call one of those functions.Quoted 7 lines
But that is unlikely to happen. A user of the kexec API will need to use only one of these functions with a given set of arguments, so they don't gain anything by setting up a struct.
Syntactically, I also don't think it's clearer to set struct members instead of simply passing arguments to a function, even if the argument list is long.
Quoted 5 lines
Sorry, I'm not sure I get your points but the long argument list really looks ugly, since you are introducing more callbacks I still think a cleanup is necessary.
kexec_bufferstruct is pretty fine to be a abstract of all these buffers.
What I understood from what you said is that making the following change results in code that is easier to understand:
@@ -650,6 +639,7 @@ static int __kexec_load_purgatory(struct kimage *image, unsigned long min,
const Elf_Shdr *sechdrs_c;
Elf_Shdr *sechdrs = NULL;
void *purgatory_buf = NULL;
+ struct kexec_buf buf;
/*
* sechdrs_c points to section headers in purgatory and are read
@@ -757,11 +747,19 @@ static int __kexec_load_purgatory(struct kimage *image, unsigned long min,
buf_align = bss_align;
/* Add buffer to segment list */
- ret = kexec_add_buffer(image, purgatory_buf, buf_sz, memsz,
- buf_align, min, max, top_down,
- &pi->purgatory_load_addr);
+ memset(&buf, 0, sizeof(struct kexec_buf));
+ buf.image = image;
+ buf.buffer = purgatory_buf;
+ buf.bufsz = buf_sz,
+ buf.memsz = memsz;
+ buf.buf_align = buf_align;
+ buf.buf_min = min;
+ buf.buf_max = max;
+ buf.top_down = top_down;
+ ret = kexec_add_buffer(&buf);
if (ret)
goto out;
+ pi->purgatory_load_addr = buf.mem;
/* Load SHF_ALLOC sections */
buf_addr = purgatory_buf;
There are 9 calls to kexec_add_buffer in the kernel (including arch/x86, arch/powerpc/ and kernel/), plus 1 to kexec_locate_mem_hole and 1 to kexec_add_handover_buffer, so there would be 11 places in the code settings up kexec_buf. My opinion is that this change doesn't improve code readability.
Also, I think that kexec_buf abstracts something that, from the perspective of the user of the kexec API, lives only for the duration of a single call to either of kexec_add_buffer, kexec_locate_mem_hole, or kexec_add_handover_buffer. Because of this, there's no need from the perspective of the API user to initialize this "object", so this just adds to their cognitive load without any benefit to them.
I understand that this is all somewhat subjective, so if you still disagree with my points I can provide a patch set implementing the change above.
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
Re: [PATCH v3 2/9] kexec_file: Generalize kexec_add_buffer.
Quoted 74 lines · Thiago Jung Bauermann
Am Donnerstag, 30 Juni 2016, 17:43:57 schrieb Dave Young:
Quoted 32 lines · Thiago Jung Bauermann
Quoted 23 lines
Am Donnerstag, 30 Juni 2016, 12:49:44 schrieb Thiago Jung Bauermann:
Quoted 8 lines
To be honest I think struct
kexec_bufis an implementation detail insidekexec_locate_mem_hole, made necessary because the callback functions it
uses need to access its arguments. Callers ofkexec_locate_mem_hole,kexec_add_handover_bufferandkexec_add_buffershouldn't need to know it
exists.Elaborating a bit more: the argument list for these three functions are equal or similar because
kexec_add_handover_bufferuseskexec_add_buffer,
which useskexec_locate_mem_hole.It could be beneficial to have a struct to collect the arguments to these
functions if someone using one of them would be likely to use another one
with the same arguments. In that case, you set upkexec_bufonce and then
just pass it whenever you need to call one of those functions.Quoted 7 lines
But that is unlikely to happen. A user of the kexec API will need to use only one of these functions with a given set of arguments, so they don't gain anything by setting up a struct.
Syntactically, I also don't think it's clearer to set struct members instead of simply passing arguments to a function, even if the argument list is long.
Quoted 5 lines
Sorry, I'm not sure I get your points but the long argument list really looks ugly, since you are introducing more callbacks I still think a cleanup is necessary.
kexec_bufferstruct is pretty fine to be a abstract of all these buffers.What I understood from what you said is that making the following change results in code that is easier to understand:
(quoted diff) +12
-3@@ -650,6 +639,7 @@ static int __kexec_load_purgatory(struct kimage *image, unsigned long min, const Elf_Shdr *sechdrs_c; Elf_Shdr *sechdrs = NULL; void *purgatory_buf = NULL; + struct kexec_buf buf; /* * sechdrs_c points to section headers in purgatory and are read@@ -757,11 +747,19 @@ static int __kexec_load_purgatory(struct kimage *image, unsigned long min, buf_align = bss_align; /* Add buffer to segment list */ - ret = kexec_add_buffer(image, purgatory_buf, buf_sz, memsz, - buf_align, min, max, top_down, - &pi->purgatory_load_addr); + memset(&buf, 0, sizeof(struct kexec_buf)); + buf.image = image; + buf.buffer = purgatory_buf; + buf.bufsz = buf_sz, + buf.memsz = memsz; + buf.buf_align = buf_align; + buf.buf_min = min; + buf.buf_max = max; + buf.top_down = top_down; + ret = kexec_add_buffer(&buf); if (ret) goto out; + pi->purgatory_load_addr = buf.mem; /* Load SHF_ALLOC sections */ buf_addr = purgatory_buf;
Quoted 5 lines
There are 9 calls to
kexec_add_bufferin the kernel (includingarch/x86,arch/powerpc/andkernel/), plus 1 tokexec_locate_mem_holeand 1 tokexec_add_handover_buffer, so there would be 11 places in the code settings upkexec_buf. My opinion is that this change doesn't improve code readability.
But the assignment can be moved to the beginning of the function __kexec_load_purgatory, and avoid the local variables from the very beginning. Just use kbuf.member instead.
Quoted 10 lines
Also, I think that
kexec_bufabstracts something that, from the perspective of the user of the kexec API, lives only for the duration of a single call to either ofkexec_add_buffer,kexec_locate_mem_hole, orkexec_add_handover_buffer. Because of this, there's no need from the perspective of the API user to initialize this "object", so this just adds to their cognitive load without any benefit to them.I understand that this is all somewhat subjective, so if you still disagree with my points I can provide a patch set implementing the change above.
I still feel it should be changed if more callbacks being introduced, though you can regard it is internal api, like above comment we do not need to assign them seperately, the member values can be assigned from the beginning.
Thanks
Dave
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v3 2/9] kexec_file: Generalize kexec_add_buffer.
Am Freitag, 01 Juli 2016, 14:36:02 schrieb Dave Young:
Quoted 11 lines · Thiago Jung Bauermann
Quoted 6 lines
Am Donnerstag, 30 Juni 2016, 17:43:57 schrieb Dave Young:
Quoted 2 lines · Thiago Jung Bauermann
Quoted 1 line
Am Donnerstag, 30 Juni 2016, 12:49:44 schrieb Thiago Jung Bauermann:
I understand that this is all somewhat subjective, so if you still disagree with my points I can provide a patch set implementing the change above.
I still feel it should be changed if more callbacks being introduced, though you can regard it is internal api, like above comment we do not need to assign them seperately, the member values can be assigned from the beginning.
Ok, I'll implement the changes and submit a v4. Thanks for your review.
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
Re: [PATCH v3 2/9] kexec_file: Generalize kexec_add_buffer.
Am Freitag, 01 Juli 2016, 17:02:23 schrieb Thiago Jung Bauermann:
Quoted 9 lines
Am Freitag, 01 Juli 2016, 14:36:02 schrieb Dave Young:
Quoted 8 lines · Thiago Jung Bauermann
Quoted 6 lines
Am Donnerstag, 30 Juni 2016, 17:43:57 schrieb Dave Young:
Quoted 2 lines · Thiago Jung Bauermann
Quoted 1 line
Am Donnerstag, 30 Juni 2016, 12:49:44 schrieb Thiago Jung Bauermann:
I understand that this is all somewhat subjective, so if you still disagree with my points I can provide a patch set implementing the change above.
Quoted 6 lines
Quoted 4 lines
I still feel it should be changed if more callbacks being introduced, though you can regard it is internal api, like above comment we do not need to assign them seperately, the member values can be assigned from the beginning.
Ok, I'll implement the changes and submit a v4. Thanks for your review.
Sorry for creating more email traffic, but it'll be better if I ask this before I change all other places in the code. Is the code below what you have in mind?
In particular, this version doesn't do the memset(&buf, 0, sizeof(buf)) that the previous code I sent earlier did. Is that ok?
@@ -643,13 +632,14 @@ static int __kexec_load_purgatory(struct kimage *image, unsigned long min,
unsigned long max, int top_down)
{
struct purgatory_info *pi = &image->purgatory_info;
- unsigned long align, buf_align, bss_align, buf_sz, bss_sz, bss_pad;
- unsigned long memsz, entry, load_addr, curr_load_addr, bss_addr, offset;
+ unsigned long align, bss_align, bss_sz, bss_pad;
+ unsigned long entry, load_addr, curr_load_addr, bss_addr, offset;
unsigned char *buf_addr, *src;
int i, ret = 0, entry_sidx = -1;
const Elf_Shdr *sechdrs_c;
Elf_Shdr *sechdrs = NULL;
- void *purgatory_buf = NULL;
+ struct kexec_buf buf = { .image = image, .buf_min = min,
+ .buf_max = max, .top_down = top_down };
/*
* sechdrs_c points to section headers in purgatory and are read
@@ -715,9 +705,9 @@ static int __kexec_load_purgatory(struct kimage *image, unsigned long min,
}
/* Determine how much memory is needed to load relocatable object. */
- buf_align = 1;
+ buf.buf_align = 1;
bss_align = 1;
- buf_sz = 0;
+ buf.bufsz = 0;
bss_sz = 0;
for (i = 0; i < pi->ehdr->e_shnum; i++) {
@@ -726,10 +716,10 @@ static int __kexec_load_purgatory(struct kimage *image, unsigned long min,
align = sechdrs[i].sh_addralign;
if (sechdrs[i].sh_type != SHT_NOBITS) {
- if (buf_align < align)
- buf_align = align;
- buf_sz = ALIGN(buf_sz, align);
- buf_sz += sechdrs[i].sh_size;
+ if (buf.buf_align < align)
+ buf.buf_align = align;
+ buf.bufsz = ALIGN(buf.bufsz, align);
+ buf.bufsz += sechdrs[i].sh_size;
} else {
/* bss section */
if (bss_align < align)
@@ -741,32 +731,31 @@ static int __kexec_load_purgatory(struct kimage *image, unsigned long min,
/* Determine the bss padding required to align bss properly */ bss_pad = 0;
- if (buf_sz & (bss_align - 1))
- bss_pad = bss_align - (buf_sz & (bss_align - 1));
+ if (buf.bufsz & (bss_align - 1))
+ bss_pad = bss_align - (buf.bufsz & (bss_align - 1));
- memsz = buf_sz + bss_pad + bss_sz;
+ buf.memsz = buf.bufsz + bss_pad + bss_sz;
/* Allocate buffer for purgatory */
- purgatory_buf = vzalloc(buf_sz);
- if (!purgatory_buf) {
+ buf.buffer = vzalloc(buf.bufsz);
+ if (!buf.buffer) {
ret = -ENOMEM;
goto out;
}
- if (buf_align < bss_align)
- buf_align = bss_align;
+ if (buf.buf_align < bss_align)
+ buf.buf_align = bss_align;
/* Add buffer to segment list */
- ret = kexec_add_buffer(image, purgatory_buf, buf_sz, memsz,
- buf_align, min, max, top_down,
- &pi->purgatory_load_addr);
+ ret = kexec_add_buffer(&buf);
if (ret)
goto out;
+ pi->purgatory_load_addr = buf.mem;
/* Load SHF_ALLOC sections */
- buf_addr = purgatory_buf;
+ buf_addr = buf.buffer;
load_addr = curr_load_addr = pi->purgatory_load_addr;
- bss_addr = load_addr + buf_sz + bss_pad;
+ bss_addr = load_addr + buf.bufsz + bss_pad;
for (i = 0; i < pi->ehdr->e_shnum; i++) {
if (!(sechdrs[i].sh_flags & SHF_ALLOC))
@@ -812,11 +801,11 @@ static int __kexec_load_purgatory(struct kimage *image, unsigned long min,
* Used later to identify which section is purgatory and skip it
* from checksumming.
*/
- pi->purgatory_buf = purgatory_buf;
+ pi->purgatory_buf = buf.buffer;
return ret;
out:
vfree(sechdrs);
- vfree(purgatory_buf);
+ vfree(buf.buffer);
return ret;
}
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center
Re: [PATCH v3 2/9] kexec_file: Generalize kexec_add_buffer.
Quoted 15 lines · Thiago Jung Bauermann
Am Freitag, 01 Juli 2016, 17:02:23 schrieb Thiago Jung Bauermann:
Quoted 14 lines
Am Freitag, 01 Juli 2016, 14:36:02 schrieb Dave Young:
Quoted 12 lines · Thiago Jung Bauermann
Quoted 6 lines
Am Donnerstag, 30 Juni 2016, 17:43:57 schrieb Dave Young:
Quoted 2 lines · Thiago Jung Bauermann
Quoted 1 line
Am Donnerstag, 30 Juni 2016, 12:49:44 schrieb Thiago Jung Bauermann:
I understand that this is all somewhat subjective, so if you still disagree with my points I can provide a patch set implementing the change above.
I still feel it should be changed if more callbacks being introduced, though you can regard it is internal api, like above comment we do not need to assign them seperately, the member values can be assigned from the beginning.
Quoted 5 lines
Quoted 1 line
Ok, I'll implement the changes and submit a v4. Thanks for your review.
Sorry for creating more email traffic, but it'll be better if I ask this before I change all other places in the code. Is the code below what you have in mind?
Thanks for the update, almost except a nitpick :)
Quoted 23 lines
In particular, this version doesn't do the
memset(&buf, 0, sizeof(buf))that the previous code I sent earlier did. Is that ok?(quoted diff) +4
-3@@ -643,13 +632,14 @@ static int __kexec_load_purgatory(struct kimage *image, unsigned long min, unsigned long max, int top_down) { struct purgatory_info *pi = &image->purgatory_info; - unsigned long align, buf_align, bss_align, buf_sz, bss_sz, bss_pad; - unsigned long memsz, entry, load_addr, curr_load_addr, bss_addr, offset; + unsigned long align, bss_align, bss_sz, bss_pad; + unsigned long entry, load_addr, curr_load_addr, bss_addr, offset; unsigned char *buf_addr, *src; int i, ret = 0, entry_sidx = -1; const Elf_Shdr *sechdrs_c; Elf_Shdr *sechdrs = NULL; - void *purgatory_buf = NULL; + struct kexec_buf buf = { .image = image, .buf_min = min, + .buf_max = max, .top_down = top_down }; /* * sechdrs_c points to section headers in purgatory and are read
Review static int __kexec_load_purgatory(struct kimage *image, unsigned long min, · line 711
Quoted 9 lines
(quoted diff) +2
-2@@ -715,9 +705,9 @@ static int __kexec_load_purgatory(struct kimage *image, unsigned long min, } /* Determine how much memory is needed to load relocatable object. */ - buf_align = 1; + buf.buf_align = 1; bss_align = 1; - buf_sz = 0; + buf.bufsz = 0; bss_sz = 0;
Above chunk can go to the initializatioin of struct kexec buf ealier.
Quoted 80 lines
(quoted diff) +17
-18for (i = 0; i < pi->ehdr->e_shnum; i++) {@@ -726,10 +716,10 @@ static int __kexec_load_purgatory(struct kimage *image, unsigned long min, align = sechdrs[i].sh_addralign; if (sechdrs[i].sh_type != SHT_NOBITS) { - if (buf_align < align) - buf_align = align; - buf_sz = ALIGN(buf_sz, align); - buf_sz += sechdrs[i].sh_size; + if (buf.buf_align < align) + buf.buf_align = align; + buf.bufsz = ALIGN(buf.bufsz, align); + buf.bufsz += sechdrs[i].sh_size; } else { /* bss section */ if (bss_align < align)@@ -741,32 +731,31 @@ static int __kexec_load_purgatory(struct kimage *image, unsigned long min, /* Determine the bss padding required to align bss properly */ bss_pad = 0; - if (buf_sz & (bss_align - 1)) - bss_pad = bss_align - (buf_sz & (bss_align - 1)); + if (buf.bufsz & (bss_align - 1)) + bss_pad = bss_align - (buf.bufsz & (bss_align - 1)); - memsz = buf_sz + bss_pad + bss_sz; + buf.memsz = buf.bufsz + bss_pad + bss_sz; /* Allocate buffer for purgatory */ - purgatory_buf = vzalloc(buf_sz); - if (!purgatory_buf) { + buf.buffer = vzalloc(buf.bufsz); + if (!buf.buffer) { ret = -ENOMEM; goto out; } - if (buf_align < bss_align) - buf_align = bss_align; + if (buf.buf_align < bss_align) + buf.buf_align = bss_align; /* Add buffer to segment list */ - ret = kexec_add_buffer(image, purgatory_buf, buf_sz, memsz, - buf_align, min, max, top_down, - &pi->purgatory_load_addr); + ret = kexec_add_buffer(&buf); if (ret) goto out; + pi->purgatory_load_addr = buf.mem; /* Load SHF_ALLOC sections */ - buf_addr = purgatory_buf; + buf_addr = buf.buffer; load_addr = curr_load_addr = pi->purgatory_load_addr; - bss_addr = load_addr + buf_sz + bss_pad; + bss_addr = load_addr + buf.bufsz + bss_pad; for (i = 0; i < pi->ehdr->e_shnum; i++) { if (!(sechdrs[i].sh_flags & SHF_ALLOC))@@ -812,11 +801,11 @@ static int __kexec_load_purgatory(struct kimage *image, unsigned long min, * Used later to identify which section is purgatory and skip it * from checksumming. */ - pi->purgatory_buf = purgatory_buf; + pi->purgatory_buf = buf.buffer; return ret; out: vfree(sechdrs); - vfree(purgatory_buf); + vfree(buf.buffer); return ret; }[]'s
Thiago Jung Bauermann
IBM Linux Technology Center