Skip to contentSkip to conversation

x86/kexec: fix a kexec_file_load failure

PATCH Superseded Dave Young 1 participant 2 messages Dec 27, 2018 – Dec 28, 2018

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Dave Young

author
#0 lore raw

PATCH 1/1 x86/kexec: fix a kexec_file_load failure

The code cleanup mentioned in Fixes tag changed the behavior of kexec_locate_mem_hole. The kexec_locate_mem_hole will try to allocate free memory only when kbuf.mem is initialized as zero.

But in x86 kexec_file_load implementation there are a few places the kbuf.mem is reused like below:
/* kbuf initialized, kbuf.mem = 0 */
...
kexec_add_buffer()
...
kexec_add_buffer()

The second kexec_add_buffer will reuse previous kbuf but not reinitialize the kbuf.mem.

Thus kexec_file_load failed because the sanity check failed.

So explictily reset mem = 0 to fix the issue.

Fixes b6664ba42f14 ("s390, kexec_file: drop arch_kexec_mem_walk()")
---
 arch/x86/kernel/crash.c           | 1 +
 arch/x86/kernel/kexec-bzimage64.c | 2 ++
 2 files changed, 3 insertions(+)
arch/x86/kernel/crash.c +1 -0
index f631a3f15587..37147509d2c8 100644
@@ -469,6 +469,7 @@ int crash_load_segments(struct kimage *image)
 
 	kbuf.memsz = kbuf.bufsz;
 	kbuf.buf_align = ELF_CORE_HEADER_ALIGN;
+	kbuf.mem = 0;
 	ret = kexec_add_buffer(&kbuf);
 	if (ret) {
 		vfree((void *)image->arch.elf_headers);
arch/x86/kernel/kexec-bzimage64.c +2 -0
index 278cd07228dd..558204bdf412 100644
@@ -434,6 +434,7 @@ static void *bzImage64_load(struct kimage *image, char *kernel,
 	kbuf.memsz = PAGE_ALIGN(header->init_size);
 	kbuf.buf_align = header->kernel_alignment;
 	kbuf.buf_min = MIN_KERNEL_LOAD_ADDR;
+	kbuf.mem = 0;
 	ret = kexec_add_buffer(&kbuf);
 	if (ret)
 		goto out_free_params;
@@ -448,6 +449,7 @@ static void *bzImage64_load(struct kimage *image, char *kernel,
 		kbuf.bufsz = kbuf.memsz = initrd_len;
 		kbuf.buf_align = PAGE_SIZE;
 		kbuf.buf_min = MIN_INITRD_LOAD_ADDR;
+		kbuf.mem = 0;
 		ret = kexec_add_buffer(&kbuf);
 		if (ret)
 			goto out_free_params;
Signature · 1 line
2.17.0
author
#1 lore raw
Quoted 32 lines · Dave Young

The code cleanup mentioned in Fixes tag changed the behavior of kexec_locate_mem_hole. The kexec_locate_mem_hole will try to allocate free memory only when kbuf.mem is initialized as zero.

But in x86 kexec_file_load implementation there are a few places the kbuf.mem is reused like below:
/* kbuf initialized, kbuf.mem = 0 */
...
kexec_add_buffer()
...
kexec_add_buffer()

The second kexec_add_buffer will reuse previous kbuf but not reinitialize the kbuf.mem.

Thus kexec_file_load failed because the sanity check failed.

So explictily reset mem = 0 to fix the issue.

Fixes b6664ba42f14 ("s390, kexec_file: drop arch_kexec_mem_walk()")
---
 arch/x86/kernel/crash.c           | 1 +
 arch/x86/kernel/kexec-bzimage64.c | 2 ++
 2 files changed, 3 insertions(+)
arch/x86/kernel/crash.c +0 -0
index f631a3f15587..37147509d2c8 100644

arch/x86/kernel/crash.c int crash_load_segments(struct kimage *image) · line 472

Quoted 4 lines
arch/x86/kernel/crash.c +1 -0
@@ -469,6 +469,7 @@ int crash_load_segments(struct kimage *image)
 
 	kbuf.memsz = kbuf.bufsz;
 	kbuf.buf_align = ELF_CORE_HEADER_ALIGN;
+	kbuf.mem = 0;

Self NAK, will resend with KEXEC_BUF_MEM_UNKNOWN instead of "0"

Quoted 26 lines
arch/x86/kernel/crash.c +0 -0
 	ret = kexec_add_buffer(&kbuf);
 	if (ret) {
 		vfree((void *)image->arch.elf_headers);
arch/x86/kernel/kexec-bzimage64.c +2 -0
index 278cd07228dd..558204bdf412 100644
@@ -434,6 +434,7 @@ static void *bzImage64_load(struct kimage *image, char *kernel,
 	kbuf.memsz = PAGE_ALIGN(header->init_size);
 	kbuf.buf_align = header->kernel_alignment;
 	kbuf.buf_min = MIN_KERNEL_LOAD_ADDR;
+	kbuf.mem = 0;
 	ret = kexec_add_buffer(&kbuf);
 	if (ret)
 		goto out_free_params;
@@ -448,6 +449,7 @@ static void *bzImage64_load(struct kimage *image, char *kernel,
 		kbuf.bufsz = kbuf.memsz = initrd_len;
 		kbuf.buf_align = PAGE_SIZE;
 		kbuf.buf_min = MIN_INITRD_LOAD_ADDR;
+		kbuf.mem = 0;
 		ret = kexec_add_buffer(&kbuf);
 		if (ret)
 			goto out_free_params;
Signature · 1 line
2.17.0