Skip to content

Commit

Permalink
powerpc/kexec_file: Fix kexec load failure with lack of memory hole
Browse files Browse the repository at this point in the history
The kexec purgatory has to run in real mode. Only the first memory
block maybe accessible in real mode. And, unlike the case with panic
kernel, no memory is set aside for regular kexec load. Another thing
to note is, the memory for crashkernel is reserved at an offset of
128MB. So, when crashkernel memory is reserved, the memory ranges to
load kexec segments shrink further as the generic code only looks for
memblock free memory ranges and in all likelihood only a tiny bit of
memory from 0 to 128MB would be available to load kexec segments.

With kdump being used by default in general, kexec file load is likely
to fail almost always. This can be fixed by changing the memory hole
lookup logic for regular kexec to use the same method as kdump. This
would mean that most kexec segments will overlap with crashkernel
memory region. That should still be ok as the pages, whose destination
address isn't available while loading, are placed in an intermediate
location till a flush to the actual destination address happens during
kexec boot sequence.

Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
Tested-by: Pingfan Liu <piliu@redhat.com>
Reviewed-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/159602302326.575379.14038896654942043093.stgit@hbathini
  • Loading branch information
Hari Bathini authored and Michael Ellerman committed Jul 29, 2020
1 parent 6ecd016 commit b5667d1
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions arch/powerpc/kexec/file_load_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -1012,25 +1012,22 @@ int arch_kexec_locate_mem_hole(struct kexec_buf *kbuf)
u64 buf_min, buf_max;
int ret;

/*
* Use the generic kexec_locate_mem_hole for regular
* kexec_file_load syscall
*/
if (kbuf->image->type != KEXEC_TYPE_CRASH)
return kexec_locate_mem_hole(kbuf);

/* Look up the exclude ranges list while locating the memory hole */
emem = &(kbuf->image->arch.exclude_ranges);
if (!(*emem) || ((*emem)->nr_ranges == 0)) {
pr_warn("No exclude range list. Using the default locate mem hole method\n");
return kexec_locate_mem_hole(kbuf);
}

buf_min = kbuf->buf_min;
buf_max = kbuf->buf_max;
/* Segments for kdump kernel should be within crashkernel region */
buf_min = (kbuf->buf_min < crashk_res.start ?
crashk_res.start : kbuf->buf_min);
buf_max = (kbuf->buf_max > crashk_res.end ?
crashk_res.end : kbuf->buf_max);
if (kbuf->image->type == KEXEC_TYPE_CRASH) {
buf_min = (buf_min < crashk_res.start ?
crashk_res.start : buf_min);
buf_max = (buf_max > crashk_res.end ?
crashk_res.end : buf_max);
}

if (buf_min > buf_max) {
pr_err("Invalid buffer min and/or max values\n");
Expand Down Expand Up @@ -1067,15 +1064,13 @@ int arch_kexec_locate_mem_hole(struct kexec_buf *kbuf)
int arch_kexec_kernel_image_probe(struct kimage *image, void *buf,
unsigned long buf_len)
{
if (image->type == KEXEC_TYPE_CRASH) {
int ret;
int ret;

/* Get exclude memory ranges needed for setting up kdump segments */
ret = get_exclude_memory_ranges(&(image->arch.exclude_ranges));
if (ret) {
pr_err("Failed to setup exclude memory ranges for buffer lookup\n");
return ret;
}
/* Get exclude memory ranges needed for setting up kexec segments */
ret = get_exclude_memory_ranges(&(image->arch.exclude_ranges));
if (ret) {
pr_err("Failed to setup exclude memory ranges for buffer lookup\n");
return ret;
}

return kexec_image_probe_default(image, buf, buf_len);
Expand Down

0 comments on commit b5667d1

Please sign in to comment.