On 1/9/23 01:36, Baoquan He wrote:
On 01/05/23 at 10:17am, Eric DeVolder wrote:
......
@@ -394,10 +409,37 @@ int crash_load_segments(struct kimage *image)
        if (ret)
                return ret;
- image->elf_headers = kbuf.buffer;
-       image->elf_headers_sz = kbuf.bufsz;
+       image->elf_headers   = kbuf.buffer;
+       image->elf_headers_sz        = kbuf.bufsz;
+       kbuf.memsz              = kbuf.bufsz;
+
+       if (IS_ENABLED(CONFIG_CRASH_HOTPLUG)) {
+               /*
+                * Ensure the elfcorehdr segment large enough for hotplug 
changes.
+                * Start with VMCOREINFO and kernel_map.
+                */
+               unsigned long pnum = 2;
+
+               if (IS_ENABLED(CONFIG_HOTPLUG_CPU))
+                       pnum += CONFIG_NR_CPUS_DEFAULT;
+
+               if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG))
+                       pnum += CRASH_MAX_MEMORY_RANGES;

Logic of pnum calculating is a little confusing to me. If I only enable
one of CONFIG_HOTPLUG_CPU and CONFIG_MEMORY_HOTPLUG, is it OK? Say I
only enable CONFIG_HOTPLUG_CPU and CONFIG_SMP, on x86_64,
CONFIG_NR_CPUS_DEFAULT will be 64. pnum will be 64, is it OK. Am I miss
anything?

Ah, your understanding is correct, and the issue you point out I need to fix.
Specifically is only one of HOTPLUG_CPU or MEMORY_HOTPLUG is set, then I need
to allow a default for the other. Using the example you have above, there would
not be room for a single memory region, so I need to allow for a default number
of memory regions.

Good find!
eric


+
+               if (pnum < (unsigned long)PN_XNUM) {
+                       kbuf.memsz = pnum * sizeof(Elf64_Phdr);
+                       kbuf.memsz += sizeof(Elf64_Ehdr);
+
+                       image->elfcorehdr_index = image->nr_segments;
+                       image->elfcorehdr_index_valid = true;
+
+                       /* Mark as usable to crash kernel, else crash kernel 
fails on boot */
+                       image->elf_headers_sz = kbuf.memsz;
+               } else {
+                       pr_err("number of Phdrs %lu exceeds max\n", pnum);
+               }
+       }
- kbuf.memsz = kbuf.bufsz;
        kbuf.buf_align = ELF_CORE_HEADER_ALIGN;
        kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
        ret = kexec_add_buffer(&kbuf);
@@ -412,3 +454,67 @@ int crash_load_segments(struct kimage *image)
        return ret;
  }
  #endif /* CONFIG_KEXEC_FILE */


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

Reply via email to