Commit 8b909e35 authored by Thiago Jung Bauermann's avatar Thiago Jung Bauermann Committed by Michael Ellerman

powerpc/kexec: Fix loading of kernel + initramfs with kexec_file_load()

Commit b6664ba4 ("s390, kexec_file: drop arch_kexec_mem_walk()")
changed kexec_add_buffer() to skip searching for a memory location if
kexec_buf.mem is already set, and use the address that is there.

In powerpc code we reuse a kexec_buf variable for loading both the
kernel and the initramfs by resetting some of the fields between those
uses, but not mem. This causes kexec_add_buffer() to try to load the
kernel at the same address where initramfs will be loaded, which is
naturally rejected:

  # kexec -s -l --initrd initramfs vmlinuz
  kexec_file_load failed: Invalid argument

Setting the mem field before every call to kexec_add_buffer() fixes
this regression.

Fixes: b6664ba4 ("s390, kexec_file: drop arch_kexec_mem_walk()")
Cc: stable@vger.kernel.org # v5.0+
Signed-off-by: default avatarThiago Jung Bauermann <bauerman@linux.ibm.com>
Reviewed-by: default avatarDave Young <dyoung@redhat.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent 3202e35e
...@@ -547,6 +547,7 @@ static int elf_exec_load(struct kimage *image, struct elfhdr *ehdr, ...@@ -547,6 +547,7 @@ static int elf_exec_load(struct kimage *image, struct elfhdr *ehdr,
kbuf.memsz = phdr->p_memsz; kbuf.memsz = phdr->p_memsz;
kbuf.buf_align = phdr->p_align; kbuf.buf_align = phdr->p_align;
kbuf.buf_min = phdr->p_paddr + base; kbuf.buf_min = phdr->p_paddr + base;
kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
ret = kexec_add_buffer(&kbuf); ret = kexec_add_buffer(&kbuf);
if (ret) if (ret)
goto out; goto out;
...@@ -581,7 +582,8 @@ static void *elf64_load(struct kimage *image, char *kernel_buf, ...@@ -581,7 +582,8 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
struct kexec_buf kbuf = { .image = image, .buf_min = 0, struct kexec_buf kbuf = { .image = image, .buf_min = 0,
.buf_max = ppc64_rma_size }; .buf_max = ppc64_rma_size };
struct kexec_buf pbuf = { .image = image, .buf_min = 0, struct kexec_buf pbuf = { .image = image, .buf_min = 0,
.buf_max = ppc64_rma_size, .top_down = true }; .buf_max = ppc64_rma_size, .top_down = true,
.mem = KEXEC_BUF_MEM_UNKNOWN };
ret = build_elf_exec_info(kernel_buf, kernel_len, &ehdr, &elf_info); ret = build_elf_exec_info(kernel_buf, kernel_len, &ehdr, &elf_info);
if (ret) if (ret)
...@@ -606,6 +608,7 @@ static void *elf64_load(struct kimage *image, char *kernel_buf, ...@@ -606,6 +608,7 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
kbuf.bufsz = kbuf.memsz = initrd_len; kbuf.bufsz = kbuf.memsz = initrd_len;
kbuf.buf_align = PAGE_SIZE; kbuf.buf_align = PAGE_SIZE;
kbuf.top_down = false; kbuf.top_down = false;
kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
ret = kexec_add_buffer(&kbuf); ret = kexec_add_buffer(&kbuf);
if (ret) if (ret)
goto out; goto out;
...@@ -638,6 +641,7 @@ static void *elf64_load(struct kimage *image, char *kernel_buf, ...@@ -638,6 +641,7 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
kbuf.bufsz = kbuf.memsz = fdt_size; kbuf.bufsz = kbuf.memsz = fdt_size;
kbuf.buf_align = PAGE_SIZE; kbuf.buf_align = PAGE_SIZE;
kbuf.top_down = true; kbuf.top_down = true;
kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
ret = kexec_add_buffer(&kbuf); ret = kexec_add_buffer(&kbuf);
if (ret) if (ret)
goto out; goto out;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment