Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1718987
| From | AKASHI Takahiro <takahiro.akashi@linaro.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 11/14] arm64: kexec_file: set up for crash dump adding elf core header |
| Date | 2017-08-24 10:30 +0200 |
| Message-ID | <uhVGA-405-69@gated-at.bofh.it> (permalink) |
| References | <uhVwR-3Wx-1@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
load_crashdump_segments() creates and loads a memory segment of elf core
header for crash dump.
"linux,usable-memory-range" and "linux,elfcorehdr" will add to the 2nd
kernel's device-tree blob. The logic of this cod is also from kexec-tools.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
---
arch/arm64/include/asm/kexec.h | 5 ++
arch/arm64/kernel/machine_kexec_file.c | 145 +++++++++++++++++++++++++++++++++
2 files changed, 150 insertions(+)
diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h
index ebc4aaa707ae..46b21512efbe 100644
--- a/arch/arm64/include/asm/kexec.h
+++ b/arch/arm64/include/asm/kexec.h
@@ -98,6 +98,10 @@ static inline void crash_post_resume(void) {}
struct kimage_arch {
void *dtb_buf;
+ /* Core ELF header buffer */
+ void *elf_headers;
+ unsigned long elf_headers_sz;
+ unsigned long elf_load_addr;
};
struct kimage;
@@ -109,6 +113,7 @@ extern int load_other_segments(struct kimage *image,
unsigned long kernel_load_addr,
char *initrd, unsigned long initrd_len,
char *cmdline, unsigned long cmdline_len);
+extern int load_crashdump_segments(struct kimage *image);
#endif
#endif /* __ASSEMBLY__ */
diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c
index cd12e451e474..012063307001 100644
--- a/arch/arm64/kernel/machine_kexec_file.c
+++ b/arch/arm64/kernel/machine_kexec_file.c
@@ -281,6 +281,77 @@ int arch_kexec_walk_mem(struct kexec_buf *kbuf, int (*func)(u64, u64, void *))
return walk_system_ram_res(0, ULONG_MAX, kbuf, func);
}
+static int __init arch_kexec_file_init(void)
+{
+ /* Those values are used later on loading the kernel */
+ __dt_root_addr_cells = dt_root_addr_cells;
+ __dt_root_size_cells = dt_root_size_cells;
+
+ return 0;
+}
+late_initcall(arch_kexec_file_init);
+
+#define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
+#define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE))
+
+static int fdt_prop_len(const char *prop_name, int len)
+{
+ return (strlen(prop_name) + 1) +
+ sizeof(struct fdt_property) +
+ FDT_TAGALIGN(len);
+}
+
+static bool cells_size_fitted(unsigned long base, unsigned long size)
+{
+ /* if *_cells >= 2, cells can hold 64-bit values anyway */
+ if ((__dt_root_addr_cells == 1) && (base >= (1ULL << 32)))
+ return false;
+
+ if ((__dt_root_size_cells == 1) && (size >= (1ULL << 32)))
+ return false;
+
+ return true;
+}
+
+static void fill_property(void *buf, u64 val64, int cells)
+{
+ u32 val32;
+ int i;
+
+ if (cells == 1) {
+ val32 = cpu_to_fdt32((u32)val64);
+ memcpy(buf, &val32, sizeof(val32));
+ } else {
+ for (i = 0; i < (cells * sizeof(u32) - sizeof(u64)); i++)
+ *(char *)buf++ = 0;
+
+ val64 = cpu_to_fdt64(val64);
+ memcpy(buf, &val64, sizeof(val64));
+ }
+}
+
+static int fdt_setprop_range(void *fdt, int nodeoffset, const char *name,
+ unsigned long addr, unsigned long size)
+{
+ u64 range[2];
+ void *prop;
+ size_t buf_size;
+ int result;
+
+ prop = range;
+ buf_size = (__dt_root_addr_cells + __dt_root_size_cells) * sizeof(u32);
+
+ fill_property(prop, addr, __dt_root_addr_cells);
+ prop += __dt_root_addr_cells * sizeof(u32);
+
+ fill_property(prop, size, __dt_root_size_cells);
+ prop += __dt_root_size_cells * sizeof(u32);
+
+ result = fdt_setprop(fdt, nodeoffset, name, range, buf_size);
+
+ return result;
+}
+
int setup_dtb(struct kimage *image,
unsigned long initrd_load_addr, unsigned long initrd_len,
char *cmdline, unsigned long cmdline_len,
@@ -293,10 +364,26 @@ int setup_dtb(struct kimage *image,
int range_len;
int ret;
+ /* check ranges against root's #address-cells and #size-cells */
+ if (image->type == KEXEC_TYPE_CRASH &&
+ (!cells_size_fitted(image->arch.elf_load_addr,
+ image->arch.elf_headers_sz) ||
+ !cells_size_fitted(crashk_res.start,
+ crashk_res.end - crashk_res.start + 1))) {
+ pr_err("Crash memory region doesn't fit into DT's root cell sizes.\n");
+ ret = -EINVAL;
+ goto out_err;
+ }
+
/* duplicate dt blob */
buf_size = fdt_totalsize(initial_boot_params);
range_len = (__dt_root_addr_cells + __dt_root_size_cells) * sizeof(u32);
+ if (image->type == KEXEC_TYPE_CRASH)
+ buf_size += fdt_prop_len("linux,elfcorehdr", range_len)
+ + fdt_prop_len("linux,usable-memory-range",
+ range_len);
+
if (initrd_load_addr)
buf_size += fdt_prop_len("initrd-start", sizeof(u64))
+ fdt_prop_len("initrd-end", sizeof(u64));
@@ -318,6 +405,23 @@ int setup_dtb(struct kimage *image,
if (nodeoffset < 0)
goto out_err;
+ if (image->type == KEXEC_TYPE_CRASH) {
+ /* add linux,elfcorehdr */
+ ret = fdt_setprop_range(buf, nodeoffset, "linux,elfcorehdr",
+ image->arch.elf_load_addr,
+ image->arch.elf_headers_sz);
+ if (ret)
+ goto out_err;
+
+ /* add linux,usable-memory-range */
+ ret = fdt_setprop_range(buf, nodeoffset,
+ "linux,usable-memory-range",
+ crashk_res.start,
+ crashk_res.end - crashk_res.start + 1);
+ if (ret)
+ goto out_err;
+ }
+
/* add bootargs */
if (cmdline) {
ret = fdt_setprop(buf, nodeoffset, "bootargs",
@@ -452,3 +556,44 @@ int load_other_segments(struct kimage *image, unsigned long kernel_load_addr,
image->arch.dtb_buf = NULL;
return ret;
}
+
+int load_crashdump_segments(struct kimage *image)
+{
+ void *elf_addr;
+ unsigned long elf_sz;
+ struct kexec_buf kbuf;
+ int ret;
+
+ if (image->type != KEXEC_TYPE_CRASH)
+ return 0;
+
+ /* Prepare elf headers and add a segment */
+ ret = prepare_elf_headers(image, &elf_addr, &elf_sz);
+ if (ret) {
+ pr_err("Preparing elf core header failed\n");
+ return ret;
+ }
+
+ kbuf.image = image;
+ kbuf.buffer = elf_addr;
+ kbuf.bufsz = elf_sz;
+ kbuf.memsz = elf_sz;
+ kbuf.buf_align = PAGE_SIZE;
+ kbuf.buf_min = crashk_res.start;
+ kbuf.buf_max = crashk_res.end + 1;
+ kbuf.top_down = 1;
+
+ ret = kexec_add_buffer(&kbuf);
+ if (ret) {
+ vfree(elf_addr);
+ return ret;
+ }
+ image->arch.elf_headers = elf_addr;
+ image->arch.elf_headers_sz = elf_sz;
+ image->arch.elf_load_addr = kbuf.mem;
+
+ pr_debug("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
+ image->arch.elf_load_addr, elf_sz, elf_sz);
+
+ return ret;
+}
--
2.14.1
Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread
[PATCH 00/14] arm64: kexec: add kexec_file_load support AKASHI Takahiro <takahiro.akashi@linaro.org> - 2017-08-24 10:20 +0200
[PATCH 14/14] arm64: kexec_file: add vmlinux format support AKASHI Takahiro <takahiro.akashi@linaro.org> - 2017-08-24 10:20 +0200
Re: [PATCH 14/14] arm64: kexec_file: add vmlinux format support Mark Rutland <mark.rutland@arm.com> - 2017-08-24 19:40 +0200
Re: [PATCH 14/14] arm64: kexec_file: add vmlinux format support AKASHI Takahiro <takahiro.akashi@linaro.org> - 2017-08-25 04:10 +0200
Re: [PATCH 14/14] arm64: kexec_file: add vmlinux format support Dave Young <dyoung@redhat.com> - 2017-08-25 08:20 +0200
[PATCH 08/14] arm64: kexec_file: create purgatory AKASHI Takahiro <takahiro.akashi@linaro.org> - 2017-08-24 10:20 +0200
Re: [PATCH 08/14] arm64: kexec_file: create purgatory Ard Biesheuvel <ard.biesheuvel@linaro.org> - 2017-08-24 11:20 +0200
Re: [PATCH 08/14] arm64: kexec_file: create purgatory AKASHI Takahiro <takahiro.akashi@linaro.org> - 2017-08-25 03:20 +0200
Re: [PATCH 08/14] arm64: kexec_file: create purgatory Mark Rutland <mark.rutland@arm.com> - 2017-08-24 19:00 +0200
Re: [PATCH 08/14] arm64: kexec_file: create purgatory AKASHI Takahiro <takahiro.akashi@linaro.org> - 2017-08-25 03:10 +0200
Re: [PATCH 08/14] arm64: kexec_file: create purgatory Mark Rutland <mark.rutland@arm.com> - 2017-08-25 12:30 +0200
[PATCH 02/14] include: pe.h: remove message[] from mz header definition AKASHI Takahiro <takahiro.akashi@linaro.org> - 2017-08-24 10:20 +0200
Re: [PATCH 02/14] include: pe.h: remove message[] from mz header definition Ard Biesheuvel <ard.biesheuvel@linaro.org> - 2017-08-24 11:10 +0200
[PATCH 01/14] MODSIGN: Export module signature definitions AKASHI Takahiro <takahiro.akashi@linaro.org> - 2017-08-24 10:20 +0200
[PATCH 09/14] arm64: kexec_file: add sha256 digest check in purgatory AKASHI Takahiro <takahiro.akashi@linaro.org> - 2017-08-24 10:30 +0200
Re: [PATCH 09/14] arm64: kexec_file: add sha256 digest check in purgatory Ard Biesheuvel <ard.biesheuvel@linaro.org> - 2017-08-24 11:20 +0200
Re: [PATCH 09/14] arm64: kexec_file: add sha256 digest check in purgatory AKASHI Takahiro <takahiro.akashi@linaro.org> - 2017-08-25 03:30 +0200
Re: [PATCH 09/14] arm64: kexec_file: add sha256 digest check in purgatory Mark Rutland <mark.rutland@arm.com> - 2017-08-24 19:10 +0200
Re: [PATCH 09/14] arm64: kexec_file: add sha256 digest check in purgatory AKASHI Takahiro <takahiro.akashi@linaro.org> - 2017-08-25 03:30 +0200
Re: [PATCH 09/14] arm64: kexec_file: add sha256 digest check in purgatory Mark Rutland <mark.rutland@arm.com> - 2017-08-25 12:50 +0200
[PATCH 07/14] asm-generic: add kexec_file_load system call to unistd.h AKASHI Takahiro <takahiro.akashi@linaro.org> - 2017-08-24 10:30 +0200
Re: [PATCH 07/14] asm-generic: add kexec_file_load system call to unistd.h Arnd Bergmann <arnd@arndb.de> - 2017-08-24 13:00 +0200
[PATCH 13/14] arm64: kexec_file: add Image format support AKASHI Takahiro <takahiro.akashi@linaro.org> - 2017-08-24 10:30 +0200
Re: [PATCH 13/14] arm64: kexec_file: add Image format support Mark Rutland <mark.rutland@arm.com> - 2017-08-24 19:30 +0200
Re: [PATCH 13/14] arm64: kexec_file: add Image format support AKASHI Takahiro <takahiro.akashi@linaro.org> - 2017-08-25 04:00 +0200
[PATCH 03/14] resource: add walk_system_ram_res_rev() AKASHI Takahiro <takahiro.akashi@linaro.org> - 2017-08-24 10:30 +0200
Re: [PATCH 03/14] resource: add walk_system_ram_res_rev() Ard Biesheuvel <ard.biesheuvel@linaro.org> - 2017-08-24 11:10 +0200
Re: [PATCH 03/14] resource: add walk_system_ram_res_rev() AKASHI Takahiro <takahiro.akashi@linaro.org> - 2017-08-25 03:00 +0200
[PATCH 10/14] arm64: kexec_file: load initrd, device-tree and purgatory segments AKASHI Takahiro <takahiro.akashi@linaro.org> - 2017-08-24 10:30 +0200
Re: [PATCH 10/14] arm64: kexec_file: load initrd, device-tree and purgatory segments Mark Rutland <mark.rutland@arm.com> - 2017-08-24 19:20 +0200
Re: [PATCH 10/14] arm64: kexec_file: load initrd, device-tree and purgatory segments AKASHI Takahiro <takahiro.akashi@linaro.org> - 2017-08-25 03:40 +0200
[PATCH 04/14] kexec_file: factor out vmlinux (elf) parser from powerpc AKASHI Takahiro <takahiro.akashi@linaro.org> - 2017-08-24 10:30 +0200
[PATCH 05/14] kexec_file: factor out crashdump elf header function from x86 AKASHI Takahiro <takahiro.akashi@linaro.org> - 2017-08-24 10:30 +0200
Re: [PATCH 05/14] kexec_file: factor out crashdump elf header function from x86 Dave Young <dyoung@redhat.com> - 2017-08-25 07:50 +0200
[PATCH 06/14] kexec_file: add kexec_add_segment() AKASHI Takahiro <takahiro.akashi@linaro.org> - 2017-08-24 10:30 +0200
[PATCH 12/14] arm64: enable KEXEC_FILE config AKASHI Takahiro <takahiro.akashi@linaro.org> - 2017-08-24 10:30 +0200
[PATCH 11/14] arm64: kexec_file: set up for crash dump adding elf core header AKASHI Takahiro <takahiro.akashi@linaro.org> - 2017-08-24 10:30 +0200
csiph-web