kexec_file: print out debugging message if required
authorBaoquan He <bhe@redhat.com>
Wed, 13 Dec 2023 05:57:42 +0000 (13:57 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 20 Dec 2023 23:02:57 +0000 (15:02 -0800)
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 print out type/start/head of kimage and flags to help debug.

Link: https://lkml.kernel.org/r/20231213055747.61826-3-bhe@redhat.com
Signed-off-by: Baoquan He <bhe@redhat.com>
Cc: Conor Dooley <conor@kernel.org>
Cc: Joe Perches <joe@perches.com>
Cc: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
kernel/crash_core.c
kernel/kexec_file.c
security/integrity/ima/ima_kexec.c

index d4313b53837e3de5bb42b553152b086b5d0657ef..c97e825a0fd9c584232d5334547c4cc53c15eaae 100644 (file)
@@ -551,9 +551,11 @@ 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++;
        }
 
index 3ee204474de6038007a618e3241c61b4e5c2db30..aca5f3668f4cff178494c6e776f80a0c6d8015ae 100644 (file)
@@ -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
index ad133fe120db29776299452937056a64f262779f..dadc1d13811841b08d1b54cf6ca4f1f1d6a9b88e 100644 (file)
@@ -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 */