crash_load_segments() open codes the elf core header loading: it builds
the header, accounts for crash hotplug and places the segment.

Use kexec_prepare_elf_core_header() and kexec_add_elf_core_header()
instead.

bzImage64_load() also loads the initrd by hand, use kexec_add_initrd()
for it.

Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Cc: [email protected]
Cc: Andrew Morton <[email protected]>
Cc: Baoquan He <[email protected]>
Cc: Mike Rapoport <[email protected]>
Signed-off-by: Jinjie Ruan <[email protected]>
---
 arch/x86/kernel/crash.c           | 25 +++++--------------------
 arch/x86/kernel/kexec-bzimage64.c |  8 +-------
 2 files changed, 6 insertions(+), 27 deletions(-)

diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
index e6f23933a6df..8d56d39ebbd5 100644
--- a/arch/x86/kernel/crash.c
+++ b/arch/x86/kernel/crash.c
@@ -354,14 +354,12 @@ int crash_load_segments(struct kimage *image)
                                  .buf_max = ULONG_MAX, .top_down = false };
 
        /* Prepare elf headers and add a segment */
-       ret = crash_prepare_headers(IS_ENABLED(CONFIG_X86_64), &kbuf.buffer,
-                                   &kbuf.bufsz, &pnum);
+       ret = kexec_prepare_elf_core_header(image, IS_ENABLED(CONFIG_X86_64),
+                                           &pnum);
        if (ret)
                return ret;
 
-       image->elf_headers      = kbuf.buffer;
-       image->elf_headers_sz   = kbuf.bufsz;
-       kbuf.memsz              = kbuf.bufsz;
+       kbuf.memsz = image->elf_headers_sz;
 
 #ifdef CONFIG_CRASH_HOTPLUG
        /*
@@ -374,28 +372,15 @@ int crash_load_segments(struct kimage *image)
                pnum += 2 + CONFIG_NR_CPUS;
 
        if (pnum < (unsigned long)PN_XNUM) {
-               kbuf.memsz = pnum * sizeof(Elf64_Phdr);
-               kbuf.memsz += sizeof(Elf64_Ehdr);
-
-               image->elfcorehdr_index = image->nr_segments;
-
-               /* Mark as usable to crash kernel, else crash kernel fails on 
boot */
-               image->elf_headers_sz = kbuf.memsz;
+               kbuf.memsz = pnum * sizeof(Elf64_Phdr) + sizeof(Elf64_Ehdr);
        } else {
                pr_err("number of Phdrs %lu exceeds max\n", pnum);
        }
 #endif
 
        kbuf.buf_align = ELF_CORE_HEADER_ALIGN;
-       kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
-       ret = kexec_add_buffer(&kbuf);
-       if (ret)
-               return ret;
-       image->elf_load_addr = kbuf.mem;
-       kexec_dprintk("Loaded ELF headers at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
-                     image->elf_load_addr, kbuf.bufsz, kbuf.memsz);
 
-       return ret;
+       return kexec_add_elf_core_header(image, &kbuf);
 }
 #endif /* CONFIG_KEXEC_FILE */
 
diff --git a/arch/x86/kernel/kexec-bzimage64.c 
b/arch/x86/kernel/kexec-bzimage64.c
index 3aa77006adab..c8e285c9a4c6 100644
--- a/arch/x86/kernel/kexec-bzimage64.c
+++ b/arch/x86/kernel/kexec-bzimage64.c
@@ -626,19 +626,13 @@ static void *bzImage64_load(struct kimage *image, char 
*kernel,
 
        /* Load initrd high */
        if (initrd) {
-               kbuf.buffer = initrd;
-               kbuf.bufsz = kbuf.memsz = initrd_len;
                kbuf.buf_align = PAGE_SIZE;
                kbuf.buf_min = MIN_INITRD_LOAD_ADDR;
-               kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
-               ret = kexec_add_buffer(&kbuf);
+               ret = kexec_add_initrd(image, &kbuf);
                if (ret)
                        goto out_free_params;
                initrd_load_addr = kbuf.mem;
 
-               kexec_dprintk("Loaded initrd at 0x%lx bufsz=0x%lx 
memsz=0x%lx\n",
-                             initrd_load_addr, initrd_len, initrd_len);
-
                setup_initrd(params, initrd_load_addr, initrd_len);
        }
 
-- 
2.34.1


Reply via email to