* [PATCH v3 0/9] kexec_file_load implementation for PowerPC
@ 2016-06-21 19:48 Thiago Jung Bauermann
2016-06-21 19:48 ` [PATCH v3 1/9] kexec_file: Remove unused members from struct kexec_buf Thiago Jung Bauermann
` (9 more replies)
0 siblings, 10 replies; 47+ messages in thread
From: Thiago Jung Bauermann @ 2016-06-21 19:48 UTC (permalink / raw)
To: linuxppc-dev; +Cc: kexec, linux-kernel, Thiago Jung Bauermann
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
--
1.9.1
^ permalink raw reply [flat|nested] 47+ messages in thread* [PATCH v3 1/9] kexec_file: Remove unused members from struct kexec_buf. 2016-06-21 19:48 [PATCH v3 0/9] kexec_file_load implementation for PowerPC Thiago Jung Bauermann @ 2016-06-21 19:48 ` Thiago Jung Bauermann 2016-06-21 19:48 ` [PATCH v3 2/9] kexec_file: Generalize kexec_add_buffer Thiago Jung Bauermann ` (8 subsequent siblings) 9 siblings, 0 replies; 47+ messages in thread From: Thiago Jung Bauermann @ 2016-06-21 19:48 UTC (permalink / raw) To: linuxppc-dev; +Cc: kexec, linux-kernel, Thiago Jung Bauermann, Eric Biederman 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. Signed-off-by: Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com> Cc: Eric Biederman <ebiederm@xmission.com> Cc: kexec@lists.infradead.org Cc: linux-kernel@vger.kernel.org Acked-by: Dave Young <dyoung@redhat.com> --- kernel/kexec_file.c | 6 ++---- kernel/kexec_internal.h | 2 -- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 01ab82a40d22..b6eec7527e9f 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -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++; diff --git a/kernel/kexec_internal.h b/kernel/kexec_internal.h index 0a52315d9c62..eefd5bf960c2 100644 --- a/kernel/kexec_internal.h +++ b/kernel/kexec_internal.h @@ -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; -- 1.9.1 ^ permalink raw reply related [flat|nested] 47+ messages in thread
* [PATCH v3 2/9] kexec_file: Generalize kexec_add_buffer. 2016-06-21 19:48 [PATCH v3 0/9] kexec_file_load implementation for PowerPC Thiago Jung Bauermann 2016-06-21 19:48 ` [PATCH v3 1/9] kexec_file: Remove unused members from struct kexec_buf Thiago Jung Bauermann @ 2016-06-21 19:48 ` Thiago Jung Bauermann 2016-06-22 10:20 ` Dave Young 2016-06-21 19:48 ` [PATCH v3 3/9] kexec_file: Factor out kexec_locate_mem_hole from kexec_add_buffer Thiago Jung Bauermann ` (7 subsequent siblings) 9 siblings, 1 reply; 47+ messages in thread From: Thiago Jung Bauermann @ 2016-06-21 19:48 UTC (permalink / raw) To: linuxppc-dev Cc: kexec, linux-kernel, Thiago Jung Bauermann, Eric Biederman, Dave Young 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 <bauerman@linux.vnet.ibm.com> Cc: Eric Biederman <ebiederm@xmission.com> Cc: Dave Young <dyoung@redhat.com> Cc: kexec@lists.infradead.org Cc: linux-kernel@vger.kernel.org --- include/linux/kexec.h | 19 ++++++++++++++++++- kernel/kexec_file.c | 30 ++++++++++++++++++++++-------- kernel/kexec_internal.h | 14 -------------- 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/include/linux/kexec.h b/include/linux/kexec.h index e8acb2b43dd9..3d91bcfc180d 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -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; diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index b6eec7527e9f..b1f1f6402518 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -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; diff --git a/kernel/kexec_internal.h b/kernel/kexec_internal.h index eefd5bf960c2..4cef7e4706b0 100644 --- a/kernel/kexec_internal.h +++ b/kernel/kexec_internal.h @@ -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) { } -- 1.9.1 ^ permalink raw reply related [flat|nested] 47+ messages in thread
* Re: [PATCH v3 2/9] kexec_file: Generalize kexec_add_buffer. 2016-06-21 19:48 ` [PATCH v3 2/9] kexec_file: Generalize kexec_add_buffer Thiago Jung Bauermann @ 2016-06-22 10:20 ` Dave Young 2016-06-22 23:30 ` Thiago Jung Bauermann 0 siblings, 1 reply; 47+ messages in thread From: Dave Young @ 2016-06-22 10:20 UTC (permalink / raw) To: Thiago Jung Bauermann; +Cc: linuxppc-dev, kexec, linux-kernel, Eric Biederman 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 On 06/21/16 at 04:48pm, Thiago Jung Bauermann wrote: > 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 <bauerman@linux.vnet.ibm.com> > Cc: Eric Biederman <ebiederm@xmission.com> > Cc: Dave Young <dyoung@redhat.com> > Cc: kexec@lists.infradead.org > Cc: linux-kernel@vger.kernel.org > --- > include/linux/kexec.h | 19 ++++++++++++++++++- > kernel/kexec_file.c | 30 ++++++++++++++++++++++-------- > kernel/kexec_internal.h | 14 -------------- > 3 files changed, 40 insertions(+), 23 deletions(-) > > diff --git a/include/linux/kexec.h b/include/linux/kexec.h > index e8acb2b43dd9..3d91bcfc180d 100644 > --- a/include/linux/kexec.h > +++ b/include/linux/kexec.h > @@ -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; > diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c > index b6eec7527e9f..b1f1f6402518 100644 > --- a/kernel/kexec_file.c > +++ b/kernel/kexec_file.c > @@ -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; > diff --git a/kernel/kexec_internal.h b/kernel/kexec_internal.h > index eefd5bf960c2..4cef7e4706b0 100644 > --- a/kernel/kexec_internal.h > +++ b/kernel/kexec_internal.h > @@ -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) { } Thanks Dave ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [PATCH v3 2/9] kexec_file: Generalize kexec_add_buffer. 2016-06-22 10:20 ` Dave Young @ 2016-06-22 23:30 ` Thiago Jung Bauermann 2016-06-23 2:25 ` Dave Young 0 siblings, 1 reply; 47+ messages in thread From: Thiago Jung Bauermann @ 2016-06-22 23:30 UTC (permalink / raw) To: Dave Young; +Cc: linuxppc-dev, kexec, linux-kernel, Eric Biederman Am Mittwoch, 22 Juni 2016, 18:20:47 schrieb Dave Young: > 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. Signed-off-by: Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com> Cc: Eric Biederman <ebiederm@xmission.com> Cc: Dave Young <dyoung@redhat.com> Cc: kexec@lists.infradead.org Cc: linux-kernel@vger.kernel.org --- include/linux/kexec.h | 19 ++++++++++++++++++- kernel/kexec_file.c | 30 ++++++++++++++++++++++-------- kernel/kexec_internal.h | 14 -------------- 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/include/linux/kexec.h b/include/linux/kexec.h index e8acb2b43dd9..3d91bcfc180d 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -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; diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index b6eec7527e9f..b1f1f6402518 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -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; diff --git a/kernel/kexec_internal.h b/kernel/kexec_internal.h index eefd5bf960c2..4cef7e4706b0 100644 --- a/kernel/kexec_internal.h +++ b/kernel/kexec_internal.h @@ -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) { } -- 1.9.1 ^ permalink raw reply related [flat|nested] 47+ messages in thread
* Re: [PATCH v3 2/9] kexec_file: Generalize kexec_add_buffer. 2016-06-22 23:30 ` Thiago Jung Bauermann @ 2016-06-23 2:25 ` Dave Young 2016-06-28 22:18 ` Thiago Jung Bauermann 0 siblings, 1 reply; 47+ messages in thread From: Dave Young @ 2016-06-23 2:25 UTC (permalink / raw) To: Thiago Jung Bauermann; +Cc: kexec, linuxppc-dev, linux-kernel, Eric Biederman On 06/22/16 at 08:30pm, Thiago Jung Bauermann wrote: > Am Mittwoch, 22 Juni 2016, 18:20:47 schrieb Dave Young: > > 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. It looks good to me. Thanks Dave > > []'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 <bauerman@linux.vnet.ibm.com> > Cc: Eric Biederman <ebiederm@xmission.com> > Cc: Dave Young <dyoung@redhat.com> > Cc: kexec@lists.infradead.org > Cc: linux-kernel@vger.kernel.org > --- > include/linux/kexec.h | 19 ++++++++++++++++++- > kernel/kexec_file.c | 30 ++++++++++++++++++++++-------- > kernel/kexec_internal.h | 14 -------------- > 3 files changed, 40 insertions(+), 23 deletions(-) > > diff --git a/include/linux/kexec.h b/include/linux/kexec.h > index e8acb2b43dd9..3d91bcfc180d 100644 > --- a/include/linux/kexec.h > +++ b/include/linux/kexec.h > @@ -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; > diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c > index b6eec7527e9f..b1f1f6402518 100644 > --- a/kernel/kexec_file.c > +++ b/kernel/kexec_file.c > @@ -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; > diff --git a/kernel/kexec_internal.h b/kernel/kexec_internal.h > index eefd5bf960c2..4cef7e4706b0 100644 > --- a/kernel/kexec_internal.h > +++ b/kernel/kexec_internal.h > @@ -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) { } > -- > 1.9.1 > > > > _______________________________________________ > kexec mailing list > kexec@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/kexec > > ^ permalink raw reply [flat|nested] 47+ messages in thread
* Re: [PATCH v3 2/9] kexec_file: Generalize kexec_add_buffer. 2016-06-23 2:25 ` Dave Young @ 2016-06-28 22:18 ` Thiago Jung Bauermann 2016-06-29 19:47 ` Dave Young 0 siblings, 1 reply; 47+ messages in thread From: Thiago Jung Bauermann @ 2016-06-28 22:18 UTC (permalink / raw) To: Dave Young; +Cc: kexec, linuxppc-dev, linux-kernel, Eric Biederman Am Donnerstag, 23 Juni 2016, 10:25:06 schrieb Dave Young: > On 06/22/16 at 08:30pm, Thiago Jung Bauermann wrote: > > Am Mittwoch, 22 Juni 2016, 18:20:47 schrieb Dave Young: > > > 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. > > 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