Skip to content

Commit

Permalink
From patchwork series 383642
Browse files Browse the repository at this point in the history
  • Loading branch information
Fox Snowpatch committed Nov 24, 2023
1 parent 9a15ae6 commit 0de1e1d
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 82 deletions.
2 changes: 1 addition & 1 deletion arch/arm64/kernel/kexec_image.c
Expand Up @@ -122,7 +122,7 @@ static void *image_load(struct kimage *image,
kernel_segment->memsz -= text_offset;
image->start = kernel_segment->mem;

pr_debug("Loaded kernel at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
kexec_dprintk("Loaded kernel at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
kernel_segment->mem, kbuf.bufsz,
kernel_segment->memsz);

Expand Down
26 changes: 6 additions & 20 deletions arch/arm64/kernel/machine_kexec.c
Expand Up @@ -32,26 +32,12 @@
static void _kexec_image_info(const char *func, int line,
const struct kimage *kimage)
{
unsigned long i;

pr_debug("%s:%d:\n", func, line);
pr_debug(" kexec kimage info:\n");
pr_debug(" type: %d\n", kimage->type);
pr_debug(" start: %lx\n", kimage->start);
pr_debug(" head: %lx\n", kimage->head);
pr_debug(" nr_segments: %lu\n", kimage->nr_segments);
pr_debug(" dtb_mem: %pa\n", &kimage->arch.dtb_mem);
pr_debug(" kern_reloc: %pa\n", &kimage->arch.kern_reloc);
pr_debug(" el2_vectors: %pa\n", &kimage->arch.el2_vectors);

for (i = 0; i < kimage->nr_segments; i++) {
pr_debug(" segment[%lu]: %016lx - %016lx, 0x%lx bytes, %lu pages\n",
i,
kimage->segment[i].mem,
kimage->segment[i].mem + kimage->segment[i].memsz,
kimage->segment[i].memsz,
kimage->segment[i].memsz / PAGE_SIZE);
}
kexec_dprintk("%s:%d:\n", func, line);
kexec_dprintk(" kexec kimage info:\n");
kexec_dprintk(" type: %d\n", kimage->type);
kexec_dprintk(" head: %lx\n", kimage->head);
kexec_dprintk(" kern_reloc: %pa\n", &kimage->arch.kern_reloc);
kexec_dprintk(" el2_vectors: %pa\n", &kimage->arch.el2_vectors);
}

void machine_kexec_cleanup(struct kimage *kimage)
Expand Down
6 changes: 3 additions & 3 deletions arch/arm64/kernel/machine_kexec_file.c
Expand Up @@ -127,7 +127,7 @@ int load_other_segments(struct kimage *image,
image->elf_load_addr = kbuf.mem;
image->elf_headers_sz = headers_sz;

pr_debug("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
kexec_dprintk("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
image->elf_load_addr, kbuf.bufsz, kbuf.memsz);
}

Expand All @@ -148,7 +148,7 @@ int load_other_segments(struct kimage *image,
goto out_err;
initrd_load_addr = kbuf.mem;

pr_debug("Loaded initrd at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
kexec_dprintk("Loaded initrd at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
initrd_load_addr, kbuf.bufsz, kbuf.memsz);
}

Expand Down Expand Up @@ -179,7 +179,7 @@ int load_other_segments(struct kimage *image,
image->arch.dtb = dtb;
image->arch.dtb_mem = kbuf.mem;

pr_debug("Loaded dtb at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
kexec_dprintk("Loaded dtb at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
kbuf.mem, kbuf.bufsz, kbuf.memsz);

return 0;
Expand Down
6 changes: 3 additions & 3 deletions arch/parisc/kernel/kexec_file.c
Expand Up @@ -38,7 +38,7 @@ static void *elf_load(struct kimage *image, char *kernel_buf,
for (i = 0; i < image->nr_segments; i++)
image->segment[i].mem = __pa(image->segment[i].mem);

pr_debug("Loaded the kernel at 0x%lx, entry at 0x%lx\n",
kexec_dprintk("Loaded the kernel at 0x%lx, entry at 0x%lx\n",
kernel_load_addr, image->start);

if (initrd != NULL) {
Expand All @@ -51,7 +51,7 @@ static void *elf_load(struct kimage *image, char *kernel_buf,
if (ret)
goto out;

pr_debug("Loaded initrd at 0x%lx\n", kbuf.mem);
kexec_dprintk("Loaded initrd at 0x%lx\n", kbuf.mem);
image->arch.initrd_start = kbuf.mem;
image->arch.initrd_end = kbuf.mem + initrd_len;
}
Expand All @@ -68,7 +68,7 @@ static void *elf_load(struct kimage *image, char *kernel_buf,
if (ret)
goto out;

pr_debug("Loaded cmdline at 0x%lx\n", kbuf.mem);
kexec_dprintk("Loaded cmdline at 0x%lx\n", kbuf.mem);
image->arch.cmdline = kbuf.mem;
}
out:
Expand Down
8 changes: 4 additions & 4 deletions arch/powerpc/kexec/elf_64.c
Expand Up @@ -59,15 +59,15 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
if (ret)
goto out;

pr_debug("Loaded the kernel at 0x%lx\n", kernel_load_addr);
kexec_dprintk("Loaded the kernel at 0x%lx\n", kernel_load_addr);

ret = kexec_load_purgatory(image, &pbuf);
if (ret) {
pr_err("Loading purgatory failed.\n");
goto out;
}

pr_debug("Loaded purgatory at 0x%lx\n", pbuf.mem);
kexec_dprintk("Loaded purgatory at 0x%lx\n", pbuf.mem);

/* Load additional segments needed for panic kernel */
if (image->type == KEXEC_TYPE_CRASH) {
Expand Down Expand Up @@ -99,7 +99,7 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
goto out;
initrd_load_addr = kbuf.mem;

pr_debug("Loaded initrd at 0x%lx\n", initrd_load_addr);
kexec_dprintk("Loaded initrd at 0x%lx\n", initrd_load_addr);
}

fdt = of_kexec_alloc_and_setup_fdt(image, initrd_load_addr,
Expand Down Expand Up @@ -132,7 +132,7 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,

fdt_load_addr = kbuf.mem;

pr_debug("Loaded device tree at 0x%lx\n", fdt_load_addr);
kexec_dprintk("Loaded device tree at 0x%lx\n", fdt_load_addr);

slave_code = elf_info.buffer + elf_info.proghdrs[0].p_offset;
ret = setup_purgatory_ppc64(image, slave_code, fdt, kernel_load_addr,
Expand Down
14 changes: 7 additions & 7 deletions arch/powerpc/kexec/file_load_64.c
Expand Up @@ -577,7 +577,7 @@ static int add_usable_mem_property(void *fdt, struct device_node *dn,
NODE_PATH_LEN, dn);
return -EOVERFLOW;
}
pr_debug("Memory node path: %s\n", path);
kexec_dprintk("Memory node path: %s\n", path);

/* Now that we know the path, find its offset in kdump kernel's fdt */
node = fdt_path_offset(fdt, path);
Expand All @@ -590,8 +590,8 @@ static int add_usable_mem_property(void *fdt, struct device_node *dn,
/* Get the address & size cells */
n_mem_addr_cells = of_n_addr_cells(dn);
n_mem_size_cells = of_n_size_cells(dn);
pr_debug("address cells: %d, size cells: %d\n", n_mem_addr_cells,
n_mem_size_cells);
kexec_dprintk("address cells: %d, size cells: %d\n", n_mem_addr_cells,
n_mem_size_cells);

um_info->idx = 0;
if (!check_realloc_usable_mem(um_info, 2)) {
Expand Down Expand Up @@ -664,7 +664,7 @@ static int update_usable_mem_fdt(void *fdt, struct crash_mem *usable_mem)

node = fdt_path_offset(fdt, "/ibm,dynamic-reconfiguration-memory");
if (node == -FDT_ERR_NOTFOUND)
pr_debug("No dynamic reconfiguration memory found\n");
kexec_dprintk("No dynamic reconfiguration memory found\n");
else if (node < 0) {
pr_err("Malformed device tree: error reading /ibm,dynamic-reconfiguration-memory.\n");
return -EINVAL;
Expand Down Expand Up @@ -776,7 +776,7 @@ static void update_backup_region_phdr(struct kimage *image, Elf64_Ehdr *ehdr)
for (i = 0; i < ehdr->e_phnum; i++) {
if (phdr->p_paddr == BACKUP_SRC_START) {
phdr->p_offset = image->arch.backup_start;
pr_debug("Backup region offset updated to 0x%lx\n",
kexec_dprintk("Backup region offset updated to 0x%lx\n",
image->arch.backup_start);
return;
}
Expand Down Expand Up @@ -850,15 +850,15 @@ int load_crashdump_segments_ppc64(struct kimage *image,
pr_err("Failed to load backup segment\n");
return ret;
}
pr_debug("Loaded the backup region at 0x%lx\n", kbuf->mem);
kexec_dprintk("Loaded the backup region at 0x%lx\n", kbuf->mem);

/* Load elfcorehdr segment - to export crashing kernel's vmcore */
ret = load_elfcorehdr_segment(image, kbuf);
if (ret) {
pr_err("Failed to load elfcorehdr segment\n");
return ret;
}
pr_debug("Loaded elf core header at 0x%lx, bufsz=0x%lx memsz=0x%lx\n",
kexec_dprintk("Loaded elf core header at 0x%lx, bufsz=0x%lx memsz=0x%lx\n",
image->elf_load_addr, kbuf->bufsz, kbuf->memsz);

return 0;
Expand Down
9 changes: 5 additions & 4 deletions arch/riscv/kernel/elf_kexec.c
Expand Up @@ -216,7 +216,6 @@ static void *elf_kexec_load(struct kimage *image, char *kernel_buf,
if (ret)
goto out;
kernel_start = image->start;
pr_notice("The entry point of kernel at 0x%lx\n", image->start);

/* Add the kernel binary to the image */
ret = riscv_kexec_elf_load(image, &ehdr, &elf_info,
Expand Down Expand Up @@ -252,7 +251,7 @@ static void *elf_kexec_load(struct kimage *image, char *kernel_buf,
image->elf_load_addr = kbuf.mem;
image->elf_headers_sz = headers_sz;

pr_debug("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
kexec_dprintk("Loaded elf core header at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
image->elf_load_addr, kbuf.bufsz, kbuf.memsz);

/* Setup cmdline for kdump kernel case */
Expand All @@ -275,6 +274,8 @@ static void *elf_kexec_load(struct kimage *image, char *kernel_buf,
pr_err("Error loading purgatory ret=%d\n", ret);
goto out;
}
kexec_dprintk("Loaded purgatory at 0x%lx\n", kbuf.mem);

ret = kexec_purgatory_get_set_symbol(image, "riscv_kernel_entry",
&kernel_start,
sizeof(kernel_start), 0);
Expand All @@ -293,7 +294,7 @@ static void *elf_kexec_load(struct kimage *image, char *kernel_buf,
if (ret)
goto out;
initrd_pbase = kbuf.mem;
pr_notice("Loaded initrd at 0x%lx\n", initrd_pbase);
kexec_dprintk("Loaded initrd at 0x%lx\n", initrd_pbase);
}

/* Add the DTB to the image */
Expand All @@ -318,7 +319,7 @@ static void *elf_kexec_load(struct kimage *image, char *kernel_buf,
}
/* Cache the fdt buffer address for memory cleanup */
image->arch.fdt = fdt;
pr_notice("Loaded device tree at 0x%lx\n", kbuf.mem);
kexec_dprintk("Loaded device tree at 0x%lx\n", kbuf.mem);
goto out;

out_free_fdt:
Expand Down
26 changes: 0 additions & 26 deletions arch/riscv/kernel/machine_kexec.c
Expand Up @@ -18,30 +18,6 @@
#include <linux/interrupt.h>
#include <linux/irq.h>

/*
* kexec_image_info - Print received image details
*/
static void
kexec_image_info(const struct kimage *image)
{
unsigned long i;

pr_debug("Kexec image info:\n");
pr_debug("\ttype: %d\n", image->type);
pr_debug("\tstart: %lx\n", image->start);
pr_debug("\thead: %lx\n", image->head);
pr_debug("\tnr_segments: %lu\n", image->nr_segments);

for (i = 0; i < image->nr_segments; i++) {
pr_debug("\t segment[%lu]: %016lx - %016lx", i,
image->segment[i].mem,
image->segment[i].mem + image->segment[i].memsz);
pr_debug("\t\t0x%lx bytes, %lu pages\n",
(unsigned long) image->segment[i].memsz,
(unsigned long) image->segment[i].memsz / PAGE_SIZE);
}
}

/*
* machine_kexec_prepare - Initialize kexec
*
Expand All @@ -60,8 +36,6 @@ machine_kexec_prepare(struct kimage *image)
unsigned int control_code_buffer_sz = 0;
int i = 0;

kexec_image_info(image);

/* Find the Flattened Device Tree and save its physical address */
for (i = 0; i < image->nr_segments; i++) {
if (image->segment[i].memsz <= sizeof(fdt))
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/crash.c
Expand Up @@ -386,7 +386,7 @@ int crash_load_segments(struct kimage *image)
if (ret)
return ret;
image->elf_load_addr = kbuf.mem;
pr_debug("Loaded ELF headers at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
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;
Expand Down
23 changes: 14 additions & 9 deletions arch/x86/kernel/kexec-bzimage64.c
Expand Up @@ -82,7 +82,7 @@ static int setup_cmdline(struct kimage *image, struct boot_params *params,

cmdline_ptr[cmdline_len - 1] = '\0';

pr_debug("Final command line is: %s\n", cmdline_ptr);
kexec_dprintk("Final command line is: %s\n", cmdline_ptr);
cmdline_ptr_phys = bootparams_load_addr + cmdline_offset;
cmdline_low_32 = cmdline_ptr_phys & 0xffffffffUL;
cmdline_ext_32 = cmdline_ptr_phys >> 32;
Expand Down Expand Up @@ -272,7 +272,12 @@ setup_boot_parameters(struct kimage *image, struct boot_params *params,

nr_e820_entries = params->e820_entries;

kexec_dprintk("E820 memmap:\n");
for (i = 0; i < nr_e820_entries; i++) {
kexec_dprintk("%016llx-%016llx (%d)\n",
params->e820_table[i].addr,
params->e820_table[i].addr + params->e820_table[i].size - 1,
params->e820_table[i].type);
if (params->e820_table[i].type != E820_TYPE_RAM)
continue;
start = params->e820_table[i].addr;
Expand Down Expand Up @@ -424,7 +429,7 @@ static void *bzImage64_load(struct kimage *image, char *kernel,
* command line. Make sure it does not overflow
*/
if (cmdline_len + MAX_ELFCOREHDR_STR_LEN > header->cmdline_size) {
pr_debug("Appending elfcorehdr=<addr> to command line exceeds maximum allowed length\n");
kexec_dprintk("Appending elfcorehdr=<addr> to command line exceeds maximum allowed length\n");
return ERR_PTR(-EINVAL);
}

Expand All @@ -445,7 +450,7 @@ static void *bzImage64_load(struct kimage *image, char *kernel,
return ERR_PTR(ret);
}

pr_debug("Loaded purgatory at 0x%lx\n", pbuf.mem);
kexec_dprintk("Loaded purgatory at 0x%lx\n", pbuf.mem);


/*
Expand Down Expand Up @@ -490,8 +495,8 @@ static void *bzImage64_load(struct kimage *image, char *kernel,
if (ret)
goto out_free_params;
bootparam_load_addr = kbuf.mem;
pr_debug("Loaded boot_param, command line and misc at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
bootparam_load_addr, kbuf.bufsz, kbuf.bufsz);
kexec_dprintk("Loaded boot_param, command line and misc at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
bootparam_load_addr, kbuf.bufsz, kbuf.bufsz);

/* Load kernel */
kbuf.buffer = kernel + kern16_size;
Expand All @@ -505,8 +510,8 @@ static void *bzImage64_load(struct kimage *image, char *kernel,
goto out_free_params;
kernel_load_addr = kbuf.mem;

pr_debug("Loaded 64bit kernel at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
kernel_load_addr, kbuf.bufsz, kbuf.memsz);
kexec_dprintk("Loaded 64bit kernel at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
kernel_load_addr, kbuf.bufsz, kbuf.memsz);

/* Load initrd high */
if (initrd) {
Expand All @@ -520,8 +525,8 @@ static void *bzImage64_load(struct kimage *image, char *kernel,
goto out_free_params;
initrd_load_addr = kbuf.mem;

pr_debug("Loaded initrd at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
initrd_load_addr, initrd_len, initrd_len);
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);
}
Expand Down
10 changes: 9 additions & 1 deletion include/linux/kexec.h
Expand Up @@ -264,6 +264,14 @@ arch_kexec_apply_relocations(struct purgatory_info *pi, Elf_Shdr *section,
return -ENOEXEC;
}
#endif

extern bool kexec_file_dbg_print;

#define kexec_dprintk(fmt, ...) \
printk("%s" fmt, \
kexec_file_dbg_print ? KERN_INFO : KERN_DEBUG, \
##__VA_ARGS__)

#endif /* CONFIG_KEXEC_FILE */

#ifdef CONFIG_KEXEC_ELF
Expand Down Expand Up @@ -403,7 +411,7 @@ bool kexec_load_permitted(int kexec_image_type);

/* List of defined/legal kexec file flags */
#define KEXEC_FILE_FLAGS (KEXEC_FILE_UNLOAD | KEXEC_FILE_ON_CRASH | \
KEXEC_FILE_NO_INITRAMFS)
KEXEC_FILE_NO_INITRAMFS | KEXEC_FILE_DEBUG)

/* flag to track if kexec reboot is in progress */
extern bool kexec_in_progress;
Expand Down
1 change: 1 addition & 0 deletions include/uapi/linux/kexec.h
Expand Up @@ -25,6 +25,7 @@
#define KEXEC_FILE_UNLOAD 0x00000001
#define KEXEC_FILE_ON_CRASH 0x00000002
#define KEXEC_FILE_NO_INITRAMFS 0x00000004
#define KEXEC_FILE_DEBUG 0x00000008

/* These values match the ELF architecture values.
* Unless there is a good reason that should continue to be the case.
Expand Down
5 changes: 4 additions & 1 deletion kernel/crash_core.c
Expand Up @@ -551,9 +551,12 @@ int crash_prepare_elf64_headers(struct crash_mem *mem, int need_kernel_map,
phdr->p_filesz = phdr->p_memsz = mend - mstart + 1;
phdr->p_align = 0;
ehdr->e_phnum++;
pr_debug("Crash PT_LOAD ELF header. phdr=%p vaddr=0x%llx, paddr=0x%llx, sz=0x%llx e_phnum=%d p_offset=0x%llx\n",
#ifdef CONFIG_KEXEC_FILE
kexec_dprintk("Crash PT_LOAD ELF header. phdr=%p vaddr=0x%llx, paddr=0x%llx, "
"sz=0x%llx e_phnum=%d p_offset=0x%llx\n",
phdr, phdr->p_vaddr, phdr->p_paddr, phdr->p_filesz,
ehdr->e_phnum, phdr->p_offset);
#endif
phdr++;
}

Expand Down

0 comments on commit 0de1e1d

Please sign in to comment.