2023-11-30 02:40:45

by Baoquan He

[permalink] [raw]
Subject: [PATCH v3 0/7] kexec_file: print out debugging message if required

Currently, specifying '-d' on kexec command will print a lot of debugging
informationabout kexec/kdump loading with kexec_load interface.

However, kexec_file_load prints nothing even though '-d' is specified.
It's very inconvenient to debug or analyze the kexec/kdump loading when
something wrong happened with kexec/kdump itself or develper want to
check the kexec/kdump loading.

In this patchset, a kexec_file flag is KEXEC_FILE_DEBUG added and checked
in code. If it's passed in, debugging message of kexec_file code will be
printed out and can be seen from console and dmesg. Otherwise, the
debugging message is printed like beofre when pr_debug() is taken.

Note:
****
=====
1) The code in kexec-tools utility also need be changed to support
passing KEXEC_FILE_DEBUG to kernel when 'kexec -s -d' is specified.
The patch link is here:
=========
[PATCH] kexec_file: add kexec_file flag to support debug printing
http://lists.infradead.org/pipermail/kexec/2023-November/028505.html

2) s390 also has kexec_file code, while I am not sure what debugging
information is necessary. So leave it to s390 developer.

Test:
****
====
Testing was done in v1 on x86_64 and arm64. For v3, tested on x86_64
again. And on x86_64, the printed messages look like below:
--------------------------------------------------------------
kexec measurement buffer for the loaded kernel at 0x207fffe000.
Loaded purgatory at 0x207fff9000
Loaded boot_param, command line and misc at 0x207fff3000 bufsz=0x1180 memsz=0x1180
Loaded 64bit kernel at 0x207c000000 bufsz=0xc88200 memsz=0x3c4a000
Loaded initrd at 0x2079e79000 bufsz=0x2186280 memsz=0x2186280
Final command line is: root=/dev/mapper/fedora_intel--knightslanding--lb--02-root ro
rd.lvm.lv=fedora_intel-knightslanding-lb-02/root console=ttyS0,115200N81 crashkernel=256M
E820 memmap:
0000000000000000-000000000009a3ff (1)
000000000009a400-000000000009ffff (2)
00000000000e0000-00000000000fffff (2)
0000000000100000-000000006ff83fff (1)
000000006ff84000-000000007ac50fff (2)
......
000000207fff6150-000000207fff615f (128)
000000207fff6160-000000207fff714f (1)
000000207fff7150-000000207fff715f (128)
000000207fff7160-000000207fff814f (1)
000000207fff8150-000000207fff815f (128)
000000207fff8160-000000207fffffff (1)
nr_segments = 5
segment[0]: buf=0x000000004e5ece74 bufsz=0x211 mem=0x207fffe000 memsz=0x1000
segment[1]: buf=0x000000009e871498 bufsz=0x4000 mem=0x207fff9000 memsz=0x5000
segment[2]: buf=0x00000000d879f1fe bufsz=0x1180 mem=0x207fff3000 memsz=0x2000
segment[3]: buf=0x000000001101cd86 bufsz=0xc88200 mem=0x207c000000 memsz=0x3c4a000
segment[4]: buf=0x00000000c6e38ac7 bufsz=0x2186280 mem=0x2079e79000 memsz=0x2187000
kexec_file_load: type:0, start:0x207fff91a0 head:0x109e004002 flags:0x8
---------------------------------------------------------------------------

History:
********
=========
v2->v3:
- Adjust all the indentation of continuation line to the open parenthesis
for all kexec_dprintk() call sites. Thank Joe to point this out.
- Fix the LKP report that macro kexec_dprintk() is invalid when
CONFIG_KEXEC=Y, CONFIG_KEXEC_FILE=n, CONFIG_CRASH_DUMP=y.

v1->v2:
- Take the new format of kexec_dprintk() suggested by Joe which can
reduce kernel text size.
- Fix building error of patch 2 in kernel/crash_core.c reported by LKP.
- Fix building warning on arm64 in patch 4 reported by LKP.

Baoquan He (7):
kexec_file: add kexec_file flag to control debug printing
kexec_file: print out debugging message if required
kexec_file, x86: print out debugging message if required
kexec_file, arm64: print out debugging message if required
kexec_file, ricv: print out debugging message if required
kexec_file, power: print out debugging message if required
kexec_file, parisc: print out debugging message if required

arch/arm64/kernel/kexec_image.c | 6 +++---
arch/arm64/kernel/machine_kexec.c | 26 ++++++--------------------
arch/arm64/kernel/machine_kexec_file.c | 12 ++++++------
arch/parisc/kernel/kexec_file.c | 8 ++++----
arch/powerpc/kexec/elf_64.c | 8 ++++----
arch/powerpc/kexec/file_load_64.c | 18 +++++++++---------
arch/riscv/kernel/elf_kexec.c | 11 ++++++-----
arch/riscv/kernel/machine_kexec.c | 26 --------------------------
arch/x86/kernel/crash.c | 4 ++--
arch/x86/kernel/kexec-bzimage64.c | 23 ++++++++++++++---------
include/linux/kexec.h | 9 ++++++++-
include/uapi/linux/kexec.h | 1 +
kernel/crash_core.c | 9 ++++++---
kernel/kexec_core.c | 2 ++
kernel/kexec_file.c | 14 +++++++++++---
security/integrity/ima/ima_kexec.c | 4 ++--
16 files changed, 84 insertions(+), 97 deletions(-)

--
2.41.0


2023-11-30 02:41:42

by Baoquan He

[permalink] [raw]
Subject: [PATCH v3 6/7] kexec_file, power: print out debugging message if required

Replace pr_debug() with the newly added kexec_dprintk() in kexec_file
loading related codes.

Signed-off-by: Baoquan He <[email protected]>
---
arch/powerpc/kexec/elf_64.c | 8 ++++----
arch/powerpc/kexec/file_load_64.c | 18 +++++++++---------
2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/arch/powerpc/kexec/elf_64.c b/arch/powerpc/kexec/elf_64.c
index eeb258002d1e..904016cf89ea 100644
--- a/arch/powerpc/kexec/elf_64.c
+++ b/arch/powerpc/kexec/elf_64.c
@@ -59,7 +59,7 @@ 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) {
@@ -67,7 +67,7 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
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) {
@@ -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,
@@ -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,
diff --git a/arch/powerpc/kexec/file_load_64.c b/arch/powerpc/kexec/file_load_64.c
index 961a6dd67365..5b4c5cb23354 100644
--- a/arch/powerpc/kexec/file_load_64.c
+++ b/arch/powerpc/kexec/file_load_64.c
@@ -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);
@@ -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)) {
@@ -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;
@@ -776,8 +776,8 @@ 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",
- image->arch.backup_start);
+ kexec_dprintk("Backup region offset updated to 0x%lx\n",
+ image->arch.backup_start);
return;
}
}
@@ -850,7 +850,7 @@ 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);
@@ -858,8 +858,8 @@ int load_crashdump_segments_ppc64(struct kimage *image,
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",
- image->elf_load_addr, kbuf->bufsz, kbuf->memsz);
+ 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;
}
--
2.41.0

2023-11-30 02:41:44

by Baoquan He

[permalink] [raw]
Subject: [PATCH v3 5/7] kexec_file, ricv: print out debugging message if required

Replace pr_debug() with the newly added kexec_dprintk() in kexec_file
loading related codes.

And also remove kexec_image_info() because the content has been printed
out in generic code.

Signed-off-by: Baoquan He <[email protected]>
---
arch/riscv/kernel/elf_kexec.c | 11 ++++++-----
arch/riscv/kernel/machine_kexec.c | 26 --------------------------
2 files changed, 6 insertions(+), 31 deletions(-)

diff --git a/arch/riscv/kernel/elf_kexec.c b/arch/riscv/kernel/elf_kexec.c
index e60fbd8660c4..5bd1ec3341fe 100644
--- a/arch/riscv/kernel/elf_kexec.c
+++ b/arch/riscv/kernel/elf_kexec.c
@@ -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,
@@ -252,8 +251,8 @@ 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",
- image->elf_load_addr, kbuf.bufsz, kbuf.memsz);
+ 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 */
modified_cmdline = setup_kdump_cmdline(image, cmdline,
@@ -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);
@@ -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 */
@@ -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:
diff --git a/arch/riscv/kernel/machine_kexec.c b/arch/riscv/kernel/machine_kexec.c
index 2d139b724bc8..ed9cad20c039 100644
--- a/arch/riscv/kernel/machine_kexec.c
+++ b/arch/riscv/kernel/machine_kexec.c
@@ -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
*
@@ -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))
--
2.41.0

2023-11-30 02:41:51

by Baoquan He

[permalink] [raw]
Subject: [PATCH v3 2/7] kexec_file: print out debugging message if required

Replace pr_debug() with the newly added kexec_dprintk() in kexec_file
loading related codes.

And also print out type/start/head of kimage and flags to help debug.

Signed-off-by: Baoquan He <[email protected]>
---
kernel/crash_core.c | 9 ++++++---
kernel/kexec_file.c | 11 ++++++++---
security/integrity/ima/ima_kexec.c | 4 ++--
3 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/kernel/crash_core.c b/kernel/crash_core.c
index efe87d501c8c..b2531eaacd1e 100644
--- a/kernel/crash_core.c
+++ b/kernel/crash_core.c
@@ -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",
- phdr, phdr->p_vaddr, phdr->p_paddr, phdr->p_filesz,
- ehdr->e_phnum, phdr->p_offset);
+#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++;
}

diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
index aca5dac74044..76de1ac7c424 100644
--- a/kernel/kexec_file.c
+++ b/kernel/kexec_file.c
@@ -204,6 +204,8 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd,
if (ret < 0)
return ret;
image->kernel_buf_len = ret;
+ kexec_dprintk("kernel: %p kernel_size: %#lx\n",
+ image->kernel_buf, image->kernel_buf_len);

/* Call arch image probe handlers */
ret = arch_kexec_kernel_image_probe(image, image->kernel_buf,
@@ -387,13 +389,14 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd,
if (ret)
goto out;

+ kexec_dprintk("nr_segments = %lu\n", image->nr_segments);
for (i = 0; i < image->nr_segments; i++) {
struct kexec_segment *ksegment;

ksegment = &image->segment[i];
- pr_debug("Loading segment %d: buf=0x%p bufsz=0x%zx mem=0x%lx memsz=0x%zx\n",
- i, ksegment->buf, ksegment->bufsz, ksegment->mem,
- ksegment->memsz);
+ kexec_dprintk("segment[%d]: buf=0x%p bufsz=0x%zx mem=0x%lx memsz=0x%zx\n",
+ i, ksegment->buf, ksegment->bufsz, ksegment->mem,
+ ksegment->memsz);

ret = kimage_load_segment(image, &image->segment[i]);
if (ret)
@@ -406,6 +409,8 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd,
if (ret)
goto out;

+ kexec_dprintk("kexec_file_load: type:%u, start:0x%lx head:0x%lx flags:0x%lx\n",
+ image->type, image->start, image->head, flags);
/*
* Free up any temporary buffers allocated which are not needed
* after image has been loaded
diff --git a/security/integrity/ima/ima_kexec.c b/security/integrity/ima/ima_kexec.c
index ad133fe120db..dadc1d138118 100644
--- a/security/integrity/ima/ima_kexec.c
+++ b/security/integrity/ima/ima_kexec.c
@@ -129,8 +129,8 @@ void ima_add_kexec_buffer(struct kimage *image)
image->ima_buffer_size = kexec_segment_size;
image->ima_buffer = kexec_buffer;

- pr_debug("kexec measurement buffer for the loaded kernel at 0x%lx.\n",
- kbuf.mem);
+ kexec_dprintk("kexec measurement buffer for the loaded kernel at 0x%lx.\n",
+ kbuf.mem);
}
#endif /* IMA_KEXEC */

--
2.41.0

2023-11-30 02:41:51

by Baoquan He

[permalink] [raw]
Subject: [PATCH v3 7/7] kexec_file, parisc: print out debugging message if required

Replace pr_debug() with the newly added kexec_dprintk() in kexec_file
loading related codes.

Signed-off-by: Baoquan He <[email protected]>
---
arch/parisc/kernel/kexec_file.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/parisc/kernel/kexec_file.c b/arch/parisc/kernel/kexec_file.c
index 8c534204f0fd..3fc82130b6c3 100644
--- a/arch/parisc/kernel/kexec_file.c
+++ b/arch/parisc/kernel/kexec_file.c
@@ -38,8 +38,8 @@ 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",
- kernel_load_addr, image->start);
+ kexec_dprintk("Loaded the kernel at 0x%lx, entry at 0x%lx\n",
+ kernel_load_addr, image->start);

if (initrd != NULL) {
kbuf.buffer = initrd;
@@ -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;
}
@@ -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:
--
2.41.0

2023-11-30 02:52:48

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH v3 2/7] kexec_file: print out debugging message if required

On Thu, 2023-11-30 at 10:39 +0800, Baoquan He wrote:
> Replace pr_debug() with the newly added kexec_dprintk() in kexec_file
> loading related codes.

trivia:

> diff --git a/kernel/crash_core.c b/kernel/crash_core.c
[]
> @@ -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",
> - phdr, phdr->p_vaddr, phdr->p_paddr, phdr->p_filesz,
> - ehdr->e_phnum, phdr->p_offset);
> +#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

Perhaps run checkpatch and coalesce the format string.

2023-12-01 10:39:26

by Conor Dooley

[permalink] [raw]
Subject: Re: [PATCH v3 5/7] kexec_file, ricv: print out debugging message if required

On Thu, Nov 30, 2023 at 10:39:53AM +0800, Baoquan He wrote:

$subject has a typo in the arch bit :)

> Replace pr_debug() with the newly added kexec_dprintk() in kexec_file
> loading related codes.

Commit messages should be understandable in isolation, but this only
explains (part of) what is obvious in the diff. Why is this change
being made?

>
> And also remove kexec_image_info() because the content has been printed
> out in generic code.
>
> Signed-off-by: Baoquan He <[email protected]>
> ---
> arch/riscv/kernel/elf_kexec.c | 11 ++++++-----
> arch/riscv/kernel/machine_kexec.c | 26 --------------------------
> 2 files changed, 6 insertions(+), 31 deletions(-)
>
> diff --git a/arch/riscv/kernel/elf_kexec.c b/arch/riscv/kernel/elf_kexec.c
> index e60fbd8660c4..5bd1ec3341fe 100644
> --- a/arch/riscv/kernel/elf_kexec.c
> +++ b/arch/riscv/kernel/elf_kexec.c
> @@ -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,
> @@ -252,8 +251,8 @@ 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",
> - image->elf_load_addr, kbuf.bufsz, kbuf.memsz);
> + 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 */
> modified_cmdline = setup_kdump_cmdline(image, cmdline,
> @@ -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);
> @@ -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);

This is not a pr_debug().

> }
>
> /* Add the DTB to the image */
> @@ -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);

Neither is this. Why are they being moved from pr_notice()?

Thanks,
Conor.

> goto out;
>
> out_free_fdt:
> diff --git a/arch/riscv/kernel/machine_kexec.c b/arch/riscv/kernel/machine_kexec.c
> index 2d139b724bc8..ed9cad20c039 100644
> --- a/arch/riscv/kernel/machine_kexec.c
> +++ b/arch/riscv/kernel/machine_kexec.c
> @@ -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
> *
> @@ -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))
> --
> 2.41.0
>


Attachments:
(No filename) (4.37 kB)
signature.asc (235.00 B)
Download all attachments

2023-12-04 08:44:25

by Baoquan He

[permalink] [raw]
Subject: Re: [PATCH v3 2/7] kexec_file: print out debugging message if required

On 11/29/23 at 06:52pm, Joe Perches wrote:
> On Thu, 2023-11-30 at 10:39 +0800, Baoquan He wrote:
> > Replace pr_debug() with the newly added kexec_dprintk() in kexec_file
> > loading related codes.
>
> trivia:
>
> > diff --git a/kernel/crash_core.c b/kernel/crash_core.c
> []
> > @@ -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",
> > - phdr, phdr->p_vaddr, phdr->p_paddr, phdr->p_filesz,
> > - ehdr->e_phnum, phdr->p_offset);
> > +#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
>
> Perhaps run checkpatch and coalesce the format string.

Sorry for being late to reply, this comment was missed.

I broke it into two because it's a too long line and not friendly for
reading. I did notice there's such line breaking code. I can change it
if it's not suggested. Thanks for careful checking.

2023-12-04 15:38:29

by Baoquan He

[permalink] [raw]
Subject: Re: [PATCH v3 5/7] kexec_file, ricv: print out debugging message if required

On 12/01/23 at 10:38am, Conor Dooley wrote:
> On Thu, Nov 30, 2023 at 10:39:53AM +0800, Baoquan He wrote:
>
> $subject has a typo in the arch bit :)

Indeed, will fix if need report. Thanks for careful checking.

>
> > Replace pr_debug() with the newly added kexec_dprintk() in kexec_file
> > loading related codes.
>
> Commit messages should be understandable in isolation, but this only
> explains (part of) what is obvious in the diff. Why is this change
> being made?

The purpose has been detailedly described in cover letter and patch 1
log. Andrew has picked these patches into his tree and grabbed the cover
letter log into the relevant commit for people's later checking. All
these seven patches will be present in mainline together. This is common
way when posting patch series? Please let me know if I misunderstand
anything.
>
> >
> > And also remove kexec_image_info() because the content has been printed
> > out in generic code.
> >
> > Signed-off-by: Baoquan He <[email protected]>
> > ---
> > arch/riscv/kernel/elf_kexec.c | 11 ++++++-----
> > arch/riscv/kernel/machine_kexec.c | 26 --------------------------
> > 2 files changed, 6 insertions(+), 31 deletions(-)
> >
> > diff --git a/arch/riscv/kernel/elf_kexec.c b/arch/riscv/kernel/elf_kexec.c
> > index e60fbd8660c4..5bd1ec3341fe 100644
> > --- a/arch/riscv/kernel/elf_kexec.c
> > +++ b/arch/riscv/kernel/elf_kexec.c
> > @@ -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,
> > @@ -252,8 +251,8 @@ 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",
> > - image->elf_load_addr, kbuf.bufsz, kbuf.memsz);
> > + 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 */
> > modified_cmdline = setup_kdump_cmdline(image, cmdline,
> > @@ -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);
> > @@ -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);
>
> This is not a pr_debug().
>
> > }
> >
> > /* Add the DTB to the image */
> > @@ -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);
>
> Neither is this. Why are they being moved from pr_notice()?

You are right.

While always printing out the loaded location of purgatory and
device tree doesn't make sense. It will be confusing when users
see these even when they do normal kexec/kdump loading. It should be
changed to pr_debug().

Which way do you suggest?
1) change it back to pr_debug(), fix it in another patch;
2) keep it as is in the patch;

Thanks
Baoquan

2023-12-04 16:15:05

by Conor Dooley

[permalink] [raw]
Subject: Re: [PATCH v3 5/7] kexec_file, ricv: print out debugging message if required

On Mon, Dec 04, 2023 at 11:38:05PM +0800, Baoquan He wrote:
> On 12/01/23 at 10:38am, Conor Dooley wrote:
> > On Thu, Nov 30, 2023 at 10:39:53AM +0800, Baoquan He wrote:
> >
> > $subject has a typo in the arch bit :)
>
> Indeed, will fix if need report. Thanks for careful checking.
>
> >
> > > Replace pr_debug() with the newly added kexec_dprintk() in kexec_file
> > > loading related codes.
> >
> > Commit messages should be understandable in isolation, but this only
> > explains (part of) what is obvious in the diff. Why is this change
> > being made?
>
> The purpose has been detailedly described in cover letter and patch 1
> log. Andrew has picked these patches into his tree and grabbed the cover
> letter log into the relevant commit for people's later checking. All
> these seven patches will be present in mainline together. This is common
> way when posting patch series? Please let me know if I misunderstand
> anything.

Each patch having a commit message that explains why a change is being
made is the expectation. It is especially useful to explain the why
here, since it is not just a mechanical conversion of pr_debug()s as the
commit message suggests.

> >
> > >
> > > And also remove kexec_image_info() because the content has been printed
> > > out in generic code.
> > >
> > > Signed-off-by: Baoquan He <[email protected]>
> > > ---
> > > arch/riscv/kernel/elf_kexec.c | 11 ++++++-----
> > > arch/riscv/kernel/machine_kexec.c | 26 --------------------------
> > > 2 files changed, 6 insertions(+), 31 deletions(-)
> > >
> > > diff --git a/arch/riscv/kernel/elf_kexec.c b/arch/riscv/kernel/elf_kexec.c
> > > index e60fbd8660c4..5bd1ec3341fe 100644
> > > --- a/arch/riscv/kernel/elf_kexec.c
> > > +++ b/arch/riscv/kernel/elf_kexec.c
> > > @@ -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,
> > > @@ -252,8 +251,8 @@ 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",
> > > - image->elf_load_addr, kbuf.bufsz, kbuf.memsz);
> > > + 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 */
> > > modified_cmdline = setup_kdump_cmdline(image, cmdline,
> > > @@ -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);
> > > @@ -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);
> >
> > This is not a pr_debug().
> >
> > > }
> > >
> > > /* Add the DTB to the image */
> > > @@ -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);
> >
> > Neither is this. Why are they being moved from pr_notice()?
>
> You are right.
>
> While always printing out the loaded location of purgatory and
> device tree doesn't make sense. It will be confusing when users
> see these even when they do normal kexec/kdump loading. It should be
> changed to pr_debug().
>
> Which way do you suggest?
> 1) change it back to pr_debug(), fix it in another patch;
> 2) keep it as is in the patch;

Personally I think it is fine to change them all in one patch, but the
rationale for converting pr_notice() to your new debug infrastructure
needs to be in the commit message.

Thanks,
Conor.


Attachments:
(No filename) (4.49 kB)
signature.asc (235.00 B)
Download all attachments

2023-12-06 15:38:26

by Baoquan He

[permalink] [raw]
Subject: Re: [PATCH v3 5/7] kexec_file, ricv: print out debugging message if required

On 12/04/23 at 04:14pm, Conor Dooley wrote:
> On Mon, Dec 04, 2023 at 11:38:05PM +0800, Baoquan He wrote:
> > On 12/01/23 at 10:38am, Conor Dooley wrote:
> > > On Thu, Nov 30, 2023 at 10:39:53AM +0800, Baoquan He wrote:
> > >
> > > $subject has a typo in the arch bit :)
> >
> > Indeed, will fix if need report. Thanks for careful checking.
> >
> > >
> > > > Replace pr_debug() with the newly added kexec_dprintk() in kexec_file
> > > > loading related codes.
> > >
> > > Commit messages should be understandable in isolation, but this only
> > > explains (part of) what is obvious in the diff. Why is this change
> > > being made?
> >
> > The purpose has been detailedly described in cover letter and patch 1
> > log. Andrew has picked these patches into his tree and grabbed the cover
> > letter log into the relevant commit for people's later checking. All
> > these seven patches will be present in mainline together. This is common
> > way when posting patch series? Please let me know if I misunderstand
> > anything.
>
> Each patch having a commit message that explains why a change is being
> made is the expectation. It is especially useful to explain the why
> here, since it is not just a mechanical conversion of pr_debug()s as the
> commit message suggests.

Sounds reasonable. I rephrase the patch 3 log as below, do you think
it's OK to you?

I will also adjust patch logs on other ARCH once this one is done.
Thanks.

=============================
Subject: [PATCH v3 5/7] kexec_file, ricv: print out debugging message if required

Then when specifying '-d' for kexec_file_load interface, loaded
locations of kernel/initrd/cmdline etc can be printed out to help debug.

Here replace pr_debug() with the newly added kexec_dprintk() in kexec_file
loading related codes.

And also replace pr_notice() with kexec_dprintk() in elf_kexec_load()
because it's make sense to always print out loaded location of purgatory
and device tree even though users don't expect the message.

And also remove kexec_image_info() because the content has been printed
out in generic code.

============================

>
> > >
> > > >
> > > > And also remove kexec_image_info() because the content has been printed
> > > > out in generic code.
> > > >
> > > > Signed-off-by: Baoquan He <[email protected]>
> > > > ---
> > > > arch/riscv/kernel/elf_kexec.c | 11 ++++++-----
> > > > arch/riscv/kernel/machine_kexec.c | 26 --------------------------
> > > > 2 files changed, 6 insertions(+), 31 deletions(-)
> > > >
> > > > diff --git a/arch/riscv/kernel/elf_kexec.c b/arch/riscv/kernel/elf_kexec.c
> > > > index e60fbd8660c4..5bd1ec3341fe 100644
> > > > --- a/arch/riscv/kernel/elf_kexec.c
> > > > +++ b/arch/riscv/kernel/elf_kexec.c
> > > > @@ -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,
> > > > @@ -252,8 +251,8 @@ 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",
> > > > - image->elf_load_addr, kbuf.bufsz, kbuf.memsz);
> > > > + 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 */
> > > > modified_cmdline = setup_kdump_cmdline(image, cmdline,
> > > > @@ -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);
> > > > @@ -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);
> > >
> > > This is not a pr_debug().
> > >
> > > > }
> > > >
> > > > /* Add the DTB to the image */
> > > > @@ -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);
> > >
> > > Neither is this. Why are they being moved from pr_notice()?
> >
> > You are right.
> >
> > While always printing out the loaded location of purgatory and
> > device tree doesn't make sense. It will be confusing when users
> > see these even when they do normal kexec/kdump loading. It should be
> > changed to pr_debug().
> >
> > Which way do you suggest?
> > 1) change it back to pr_debug(), fix it in another patch;
> > 2) keep it as is in the patch;
>
> Personally I think it is fine to change them all in one patch, but the
> rationale for converting pr_notice() to your new debug infrastructure
> needs to be in the commit message.

Sure, sounds good to me. I have changed the patch log to reflect this as
you suggested, please help check. Thanks again.

2023-12-06 16:54:52

by Conor Dooley

[permalink] [raw]
Subject: Re: [PATCH v3 5/7] kexec_file, ricv: print out debugging message if required

On Wed, Dec 06, 2023 at 11:37:52PM +0800, Baoquan He wrote:
> On 12/04/23 at 04:14pm, Conor Dooley wrote:
> > On Mon, Dec 04, 2023 at 11:38:05PM +0800, Baoquan He wrote:
> > > On 12/01/23 at 10:38am, Conor Dooley wrote:
> > > > On Thu, Nov 30, 2023 at 10:39:53AM +0800, Baoquan He wrote:
> > > >
> > > > $subject has a typo in the arch bit :)
> > >
> > > Indeed, will fix if need report. Thanks for careful checking.
> > >
> > > >
> > > > > Replace pr_debug() with the newly added kexec_dprintk() in kexec_file
> > > > > loading related codes.
> > > >
> > > > Commit messages should be understandable in isolation, but this only
> > > > explains (part of) what is obvious in the diff. Why is this change
> > > > being made?
> > >
> > > The purpose has been detailedly described in cover letter and patch 1
> > > log. Andrew has picked these patches into his tree and grabbed the cover
> > > letter log into the relevant commit for people's later checking. All
> > > these seven patches will be present in mainline together. This is common
> > > way when posting patch series? Please let me know if I misunderstand
> > > anything.
> >
> > Each patch having a commit message that explains why a change is being
> > made is the expectation. It is especially useful to explain the why
> > here, since it is not just a mechanical conversion of pr_debug()s as the
> > commit message suggests.
>
> Sounds reasonable. I rephrase the patch 3 log as below, do you think
> it's OK to you?

Yes, but with one comment.

>
> I will also adjust patch logs on other ARCH once this one is done.
> Thanks.
>
> =============================
> Subject: [PATCH v3 5/7] kexec_file, ricv: print out debugging message if required
>
> Then when specifying '-d' for kexec_file_load interface, loaded
> locations of kernel/initrd/cmdline etc can be printed out to help debug.
>
> Here replace pr_debug() with the newly added kexec_dprintk() in kexec_file
> loading related codes.
>

> And also replace pr_notice() with kexec_dprintk() in elf_kexec_load()
> because it's make sense to always print out loaded location of purgatory
> and device tree even though users don't expect the message.

This seems to contradict what you said in your earlier mail, about
moving these from notice to debug. I think you missed a negation in your
new version of the commit message. What you said in response to me seems
like a more complete explanation anyway:
always printing out the loaded location of purgatory and
device tree doesn't make sense. It will be confusing when users
see these even when they do normal kexec/kdump loading.

Thanks,
Conor.

> And also remove kexec_image_info() because the content has been printed
> out in generic code.
>
> ============================
>
> >
> > > >
> > > > >
> > > > > And also remove kexec_image_info() because the content has been printed
> > > > > out in generic code.
> > > > >
> > > > > Signed-off-by: Baoquan He <[email protected]>
> > > > > ---
> > > > > arch/riscv/kernel/elf_kexec.c | 11 ++++++-----
> > > > > arch/riscv/kernel/machine_kexec.c | 26 --------------------------
> > > > > 2 files changed, 6 insertions(+), 31 deletions(-)
> > > > >
> > > > > diff --git a/arch/riscv/kernel/elf_kexec.c b/arch/riscv/kernel/elf_kexec.c
> > > > > index e60fbd8660c4..5bd1ec3341fe 100644
> > > > > --- a/arch/riscv/kernel/elf_kexec.c
> > > > > +++ b/arch/riscv/kernel/elf_kexec.c
> > > > > @@ -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,
> > > > > @@ -252,8 +251,8 @@ 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",
> > > > > - image->elf_load_addr, kbuf.bufsz, kbuf.memsz);
> > > > > + 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 */
> > > > > modified_cmdline = setup_kdump_cmdline(image, cmdline,
> > > > > @@ -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);
> > > > > @@ -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);
> > > >
> > > > This is not a pr_debug().
> > > >
> > > > > }
> > > > >
> > > > > /* Add the DTB to the image */
> > > > > @@ -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);
> > > >
> > > > Neither is this. Why are they being moved from pr_notice()?
> > >
> > > You are right.
> > >
> > > While always printing out the loaded location of purgatory and
> > > device tree doesn't make sense. It will be confusing when users
> > > see these even when they do normal kexec/kdump loading. It should be
> > > changed to pr_debug().
> > >
> > > Which way do you suggest?
> > > 1) change it back to pr_debug(), fix it in another patch;
> > > 2) keep it as is in the patch;
> >
> > Personally I think it is fine to change them all in one patch, but the
> > rationale for converting pr_notice() to your new debug infrastructure
> > needs to be in the commit message.
>
> Sure, sounds good to me. I have changed the patch log to reflect this as
> you suggested, please help check. Thanks again.
>


Attachments:
(No filename) (6.51 kB)
signature.asc (235.00 B)
Download all attachments

2023-12-06 23:22:32

by Baoquan He

[permalink] [raw]
Subject: Re: [PATCH v3 5/7] kexec_file, ricv: print out debugging message if required

On 12/06/23 at 04:54pm, Conor Dooley wrote:
> On Wed, Dec 06, 2023 at 11:37:52PM +0800, Baoquan He wrote:
> > On 12/04/23 at 04:14pm, Conor Dooley wrote:
> > > On Mon, Dec 04, 2023 at 11:38:05PM +0800, Baoquan He wrote:
> > > > On 12/01/23 at 10:38am, Conor Dooley wrote:
> > > > > On Thu, Nov 30, 2023 at 10:39:53AM +0800, Baoquan He wrote:
> > > > >
> > > > > $subject has a typo in the arch bit :)
> > > >
> > > > Indeed, will fix if need report. Thanks for careful checking.
> > > >
> > > > >
> > > > > > Replace pr_debug() with the newly added kexec_dprintk() in kexec_file
> > > > > > loading related codes.
> > > > >
> > > > > Commit messages should be understandable in isolation, but this only
> > > > > explains (part of) what is obvious in the diff. Why is this change
> > > > > being made?
> > > >
> > > > The purpose has been detailedly described in cover letter and patch 1
> > > > log. Andrew has picked these patches into his tree and grabbed the cover
> > > > letter log into the relevant commit for people's later checking. All
> > > > these seven patches will be present in mainline together. This is common
> > > > way when posting patch series? Please let me know if I misunderstand
> > > > anything.
> > >
> > > Each patch having a commit message that explains why a change is being
> > > made is the expectation. It is especially useful to explain the why
> > > here, since it is not just a mechanical conversion of pr_debug()s as the
> > > commit message suggests.
> >
> > Sounds reasonable. I rephrase the patch 3 log as below, do you think
> > it's OK to you?
>
> Yes, but with one comment.
>
> >
> > I will also adjust patch logs on other ARCH once this one is done.
> > Thanks.
> >
> > =============================
> > Subject: [PATCH v3 5/7] kexec_file, ricv: print out debugging message if required
> >
> > Then when specifying '-d' for kexec_file_load interface, loaded
> > locations of kernel/initrd/cmdline etc can be printed out to help debug.
> >
> > Here replace pr_debug() with the newly added kexec_dprintk() in kexec_file
> > loading related codes.
> >
>
> > And also replace pr_notice() with kexec_dprintk() in elf_kexec_load()
> > because it's make sense to always print out loaded location of purgatory
~
> > and device tree even though users don't expect the message.

Fixed typo:
==========

And also replace pr_notice() with kexec_dprintk() in elf_kexec_load()
because it doesn't make sense to always print out loaded location of
purgatory and device tree even though users don't expect the message.

>
> This seems to contradict what you said in your earlier mail, about
> moving these from notice to debug. I think you missed a negation in your
> new version of the commit message. What you said in response to me seems
> like a more complete explanation anyway:

Ah, I made mistake when typing, these printing is only for debugging,
so always printing out them is not suggested.

> always printing out the loaded location of purgatory and
> device tree doesn't make sense. It will be confusing when users
> see these even when they do normal kexec/kdump loading.
>
> Thanks,
> Conor.
>
> > And also remove kexec_image_info() because the content has been printed
> > out in generic code.
> >
> > ============================
> >
> > >
> > > > >
> > > > > >
> > > > > > And also remove kexec_image_info() because the content has been printed
> > > > > > out in generic code.
> > > > > >
> > > > > > Signed-off-by: Baoquan He <[email protected]>
> > > > > > ---
> > > > > > arch/riscv/kernel/elf_kexec.c | 11 ++++++-----
> > > > > > arch/riscv/kernel/machine_kexec.c | 26 --------------------------
> > > > > > 2 files changed, 6 insertions(+), 31 deletions(-)
> > > > > >
> > > > > > diff --git a/arch/riscv/kernel/elf_kexec.c b/arch/riscv/kernel/elf_kexec.c
> > > > > > index e60fbd8660c4..5bd1ec3341fe 100644
> > > > > > --- a/arch/riscv/kernel/elf_kexec.c
> > > > > > +++ b/arch/riscv/kernel/elf_kexec.c
> > > > > > @@ -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,
> > > > > > @@ -252,8 +251,8 @@ 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",
> > > > > > - image->elf_load_addr, kbuf.bufsz, kbuf.memsz);
> > > > > > + 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 */
> > > > > > modified_cmdline = setup_kdump_cmdline(image, cmdline,
> > > > > > @@ -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);
> > > > > > @@ -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);
> > > > >
> > > > > This is not a pr_debug().
> > > > >
> > > > > > }
> > > > > >
> > > > > > /* Add the DTB to the image */
> > > > > > @@ -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);
> > > > >
> > > > > Neither is this. Why are they being moved from pr_notice()?
> > > >
> > > > You are right.
> > > >
> > > > While always printing out the loaded location of purgatory and
> > > > device tree doesn't make sense. It will be confusing when users
> > > > see these even when they do normal kexec/kdump loading. It should be
> > > > changed to pr_debug().
> > > >
> > > > Which way do you suggest?
> > > > 1) change it back to pr_debug(), fix it in another patch;
> > > > 2) keep it as is in the patch;
> > >
> > > Personally I think it is fine to change them all in one patch, but the
> > > rationale for converting pr_notice() to your new debug infrastructure
> > > needs to be in the commit message.
> >
> > Sure, sounds good to me. I have changed the patch log to reflect this as
> > you suggested, please help check. Thanks again.
> >


2023-12-13 03:23:40

by Baoquan He

[permalink] [raw]
Subject: Re: [PATCH v3 5/7] kexec_file, ricv: print out debugging message if required

On 12/07/23 at 07:22am, Baoquan He wrote:
> On 12/06/23 at 04:54pm, Conor Dooley wrote:
> > On Wed, Dec 06, 2023 at 11:37:52PM +0800, Baoquan He wrote:
> > > On 12/04/23 at 04:14pm, Conor Dooley wrote:
> > > > On Mon, Dec 04, 2023 at 11:38:05PM +0800, Baoquan He wrote:
> > > > > On 12/01/23 at 10:38am, Conor Dooley wrote:
> > > > > > On Thu, Nov 30, 2023 at 10:39:53AM +0800, Baoquan He wrote:
> > > > > >
> > > > > > $subject has a typo in the arch bit :)
> > > > >
> > > > > Indeed, will fix if need report. Thanks for careful checking.
> > > > >
> > > > > >
> > > > > > > Replace pr_debug() with the newly added kexec_dprintk() in kexec_file
> > > > > > > loading related codes.
> > > > > >
> > > > > > Commit messages should be understandable in isolation, but this only
> > > > > > explains (part of) what is obvious in the diff. Why is this change
> > > > > > being made?
> > > > >
> > > > > The purpose has been detailedly described in cover letter and patch 1
> > > > > log. Andrew has picked these patches into his tree and grabbed the cover
> > > > > letter log into the relevant commit for people's later checking. All
> > > > > these seven patches will be present in mainline together. This is common
> > > > > way when posting patch series? Please let me know if I misunderstand
> > > > > anything.
> > > >
> > > > Each patch having a commit message that explains why a change is being
> > > > made is the expectation. It is especially useful to explain the why
> > > > here, since it is not just a mechanical conversion of pr_debug()s as the
> > > > commit message suggests.
> > >
> > > Sounds reasonable. I rephrase the patch 3 log as below, do you think
> > > it's OK to you?
> >
> > Yes, but with one comment.
> >
> > >
> > > I will also adjust patch logs on other ARCH once this one is done.
> > > Thanks.
> > >
> > > =============================
> > > Subject: [PATCH v3 5/7] kexec_file, ricv: print out debugging message if required
> > >
> > > Then when specifying '-d' for kexec_file_load interface, loaded
> > > locations of kernel/initrd/cmdline etc can be printed out to help debug.
> > >
> > > Here replace pr_debug() with the newly added kexec_dprintk() in kexec_file
> > > loading related codes.
> > >
> >
> > > And also replace pr_notice() with kexec_dprintk() in elf_kexec_load()
> > > because it's make sense to always print out loaded location of purgatory
> ~
> > > and device tree even though users don't expect the message.
>
> Fixed typo:
> ==========
>
> And also replace pr_notice() with kexec_dprintk() in elf_kexec_load()
> because it doesn't make sense to always print out loaded location of
> purgatory and device tree even though users don't expect the message.

I will post v4 to include these suggested changes, please add comments
if there's any concern. Thanks for reviewing.

>
> >
> > This seems to contradict what you said in your earlier mail, about
> > moving these from notice to debug. I think you missed a negation in your
> > new version of the commit message. What you said in response to me seems
> > like a more complete explanation anyway:
>
> Ah, I made mistake when typing, these printing is only for debugging,
> so always printing out them is not suggested.
>
> > always printing out the loaded location of purgatory and
> > device tree doesn't make sense. It will be confusing when users
> > see these even when they do normal kexec/kdump loading.
> >
> > Thanks,
> > Conor.
> >
> > > And also remove kexec_image_info() because the content has been printed
> > > out in generic code.
> > >
> > > ============================
> > >
> > > >
> > > > > >
> > > > > > >
> > > > > > > And also remove kexec_image_info() because the content has been printed
> > > > > > > out in generic code.
> > > > > > >
> > > > > > > Signed-off-by: Baoquan He <[email protected]>
> > > > > > > ---
> > > > > > > arch/riscv/kernel/elf_kexec.c | 11 ++++++-----
> > > > > > > arch/riscv/kernel/machine_kexec.c | 26 --------------------------
> > > > > > > 2 files changed, 6 insertions(+), 31 deletions(-)
> > > > > > >
> > > > > > > diff --git a/arch/riscv/kernel/elf_kexec.c b/arch/riscv/kernel/elf_kexec.c
> > > > > > > index e60fbd8660c4..5bd1ec3341fe 100644
> > > > > > > --- a/arch/riscv/kernel/elf_kexec.c
> > > > > > > +++ b/arch/riscv/kernel/elf_kexec.c
> > > > > > > @@ -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,
> > > > > > > @@ -252,8 +251,8 @@ 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",
> > > > > > > - image->elf_load_addr, kbuf.bufsz, kbuf.memsz);
> > > > > > > + 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 */
> > > > > > > modified_cmdline = setup_kdump_cmdline(image, cmdline,
> > > > > > > @@ -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);
> > > > > > > @@ -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);
> > > > > >
> > > > > > This is not a pr_debug().
> > > > > >
> > > > > > > }
> > > > > > >
> > > > > > > /* Add the DTB to the image */
> > > > > > > @@ -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);
> > > > > >
> > > > > > Neither is this. Why are they being moved from pr_notice()?
> > > > >
> > > > > You are right.
> > > > >
> > > > > While always printing out the loaded location of purgatory and
> > > > > device tree doesn't make sense. It will be confusing when users
> > > > > see these even when they do normal kexec/kdump loading. It should be
> > > > > changed to pr_debug().
> > > > >
> > > > > Which way do you suggest?
> > > > > 1) change it back to pr_debug(), fix it in another patch;
> > > > > 2) keep it as is in the patch;
> > > >
> > > > Personally I think it is fine to change them all in one patch, but the
> > > > rationale for converting pr_notice() to your new debug infrastructure
> > > > needs to be in the commit message.
> > >
> > > Sure, sounds good to me. I have changed the patch log to reflect this as
> > > you suggested, please help check. Thanks again.
> > >
>
>