Skip to contentSkip to conversation

In kernel handling of CPU hotplug events for crash kernel

PATCH Superseded Sourabh Jain 2 participants 14 messages Jan 15, 2023 – Jan 23, 2023

Subsystems (6)

v7 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v7 cover In kernel handling of CPU hotplug events for crash kernel

This patch series implements the crash hotplug handler on PowerPC introduced by https://lkml.org/lkml/2022/12/9/520 patch series.

The Problem:
============
Post hotplug/DLPAR events the capture kernel holds stale information about the system. Dump collection with stale capture kernel might end up in dump capture failure or an inaccurate dump collection.

Existing solution:
==================
The existing solution to keep the capture kernel up-to-date by monitoring hotplug event via udev rule and trigger a full capture kernel reload for every hotplug event.

Shortcomings:
------------------------------------------------
- Leaves a window where kernel crash might not lead to a successful dump collection.
- Reloading all kexec components for each hotplug is inefficient.
- udev rules are prone to races if hotplug events are frequent.

More about issues with an existing solution is posted here:
- https://lkml.org/lkml/2020/12/14/532
- https://lists.ozlabs.org/pipermail/linuxppc-dev/2022-February/240254.html

Proposed Solution:
==================
Instead of reloading all kexec segments on hotplug event, this patch series focuses on updating only the relevant kexec segment. Once the kexec segments are loaded in the kernel reserved area then an arch-specific hotplug handler will update the relevant kexec segment based on hotplug event type.

---
Changelog:

v6 -> v7
- added a new config to configure this feature
- pass hotplug action type to arch specific handler

v5 -> v6
- Added crash memory hotplug support

v4 -> v5:
- Replace COFNIG_CRASH_HOTPLUG with CONFIG_HOTPLUG_CPU.
- Move fdt segment identification for kexec_load case to load path instead of crash hotplug handler
- Keep new attribute defined under kimage_arch to track FDT segment under CONFIG_HOTPLUG_CPU config.

v3 -> v4:
- Update the logic to find the additional space needed for hotadd CPUs post kexec load. Refer "[RFC v4 PATCH 4/5] powerpc/crash hp: add crash hotplug support for kexec_file_load" patch to know more about the change.
- Fix a couple of typo.
- Replace pr_err to pr_info_once to warn user about memory hotplug support.
- In crash hotplug handle exit the for loop if FDT segment is found.

v2 -> v3
- Move fdt_index and fdt_index_vaild variables to kimage_arch struct.
- Rebase patche on top of https://lkml.org/lkml/2022/3/3/674 [v5]
- Fixed warning reported by checpatch script

v1 -> v2:
- Use generic hotplug handler introduced by https://lkml.org/lkml/2022/2/9/1406, a significant change from v1.
---

Sourabh Jain (8):
powerpc/kexec: turn some static helper functions public powerpc/crash hp: introduce a new config option CRASH_HOTPLUG powerpc/crash: update kimage_arch struct
crash: add phdr for possible CPUs in elfcorehdr
crash: pass hotplug action type to arch crash hotplug handler powerpc/crash: add crash CPU hotplug support
crash: forward memory_notify args to arch crash hotplug handler powerpc/kexec: add crash memory hotplug support

 arch/powerpc/Kconfig                    |  12 +
 arch/powerpc/include/asm/kexec.h        |  17 ++
 arch/powerpc/include/asm/kexec_ranges.h |   1 +
 arch/powerpc/kexec/core_64.c            | 290 ++++++++++++++++++++++++
 arch/powerpc/kexec/elf_64.c             |  73 +++++-
 arch/powerpc/kexec/file_load_64.c       | 179 ++-------------
 arch/powerpc/kexec/ranges.c             |  60 +++++
 arch/x86/include/asm/kexec.h            |   3 +-
 arch/x86/kernel/crash.c                 |   5 +-
 include/linux/kexec.h                   |   6 +-
 kernel/crash_core.c                     |  23 +-
 11 files changed, 491 insertions(+), 178 deletions(-)
Signature · 7 lines
2.39.0


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

PATCH v7 1/8 powerpc/kexec: turn some static helper functions public

Move update_cpus_node and get_crash_memory_ranges functions from kexec/file_load.c to kexec/core_64.c to make these functions usable by other kexec compoenets.

Later in the series, both functions are used for in-kernel updates to kexec segments in the event of CPU/Memory hotplug for both kexec_load and kexec_file_load system call.

No functional change intended.

---
 arch/powerpc/include/asm/kexec.h  |   6 ++
 arch/powerpc/kexec/core_64.c      | 166 ++++++++++++++++++++++++++++++
 arch/powerpc/kexec/file_load_64.c | 162 -----------------------------
 3 files changed, 172 insertions(+), 162 deletions(-)
arch/powerpc/include/asm/kexec.h +6 -0
index a1ddba01e7d13..8090ad7d97d9d 100644
@@ -99,6 +99,12 @@ void relocate_new_kernel(unsigned long indirection_page, unsigned long reboot_co
 
 void kexec_copy_flush(struct kimage *image);
 
+#ifdef CONFIG_PPC64
+struct crash_mem;
+int update_cpus_node(void *fdt);
+int get_crash_memory_ranges(struct crash_mem **mem_ranges);
+#endif
+
 #if defined(CONFIG_CRASH_DUMP) && defined(CONFIG_PPC_RTAS)
 void crash_free_reserved_phys_range(unsigned long begin, unsigned long end);
 #define crash_free_reserved_phys_range crash_free_reserved_phys_range
arch/powerpc/kexec/core_64.c +166 -0

184 lines not on this page · raw message

arch/powerpc/kexec/file_load_64.c +0 -162

174 lines not on this page · raw message

Signature · 7 lines
2.39.0


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

PATCH v7 2/8 powerpc/crash hp: introduce a new config option CRASH_HOTPLUG

In reply to Sourabh Jain

The config option CRASH_HOTPLUG enables in kernel update to kexec segments due to CPU/Memory hotplug events. By default it is disabled.

---
 arch/powerpc/Kconfig | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/powerpc/Kconfig +12 -0
index b8c4ac56bddc5..57d18cc5d27c5 100644
@@ -668,6 +668,18 @@ config CRASH_DUMP
 	  The same kernel binary can be used as production kernel and dump
 	  capture kernel.
 
+config CRASH_HOTPLUG
+	bool "Update crash capture system on CPU/Memory hotplug event"
+	default n
+	depends on CRASH_DUMP && (HOTPLUG_CPU || MEMORY_HOTPLUG)
+	help
+	  In kernel update to relevant kexec segments due to change
+	  in system configuration, rather reloading all the kexec
+	  segments again from userspace by monitoring CPU/Memory
+	  hotplug event in userspace using udev.
+
+	  If unsure, say Y.
+
 config FA_DUMP
 	bool "Firmware-assisted dump"
 	depends on PPC64 && (PPC_RTAS || PPC_POWERNV)
Signature · 7 lines
2.39.0


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

PATCH v7 3/8 powerpc/crash: update kimage_arch struct

In reply to Sourabh Jain

Add a new member "fdt_index" to kimage_arch struct to hold the index of the FDT (Flattened Device Tree) segment in the kexec segment array.

Having direct access to FDT segment will help arch crash hotplug handler to avoid looping kexec segment array to identify the FDT segment index for every FDT update on hotplug events.

The fdt_index is initialized during the kexec load for both kexec_load and kexec_file_load system call.

---
 arch/powerpc/include/asm/kexec.h  |  7 +++++++
 arch/powerpc/kexec/core_64.c      | 27 +++++++++++++++++++++++++++
 arch/powerpc/kexec/elf_64.c       |  6 ++++++
 arch/powerpc/kexec/file_load_64.c |  5 +++++
 4 files changed, 45 insertions(+)
arch/powerpc/include/asm/kexec.h +7 -0
index 8090ad7d97d9d..5a322c1737661 100644
@@ -103,6 +103,10 @@ void kexec_copy_flush(struct kimage *image);
 struct crash_mem;
 int update_cpus_node(void *fdt);
 int get_crash_memory_ranges(struct crash_mem **mem_ranges);
+#if defined(CONFIG_CRASH_HOTPLUG)
+int machine_kexec_post_load(struct kimage *image);
+#define machine_kexec_post_load machine_kexec_post_load
+#endif
 #endif
 
 #if defined(CONFIG_CRASH_DUMP) && defined(CONFIG_PPC_RTAS)
@@ -118,6 +122,9 @@ extern const struct kexec_file_ops kexec_elf64_ops;
 struct kimage_arch {
 	struct crash_mem *exclude_ranges;
 
+#if defined(CONFIG_CRASH_HOTPLUG)
+	int fdt_index;
+#endif
 	unsigned long backup_start;
 	void *backup_buf;
 	void *fdt;
arch/powerpc/kexec/core_64.c +27 -0
index 0b292f93a74cc..3d4fe1aa6f761 100644
@@ -77,6 +77,33 @@ int machine_kexec_prepare(struct kimage *image)
 	return 0;
 }
 
+#if defined(CONFIG_CRASH_HOTPLUG)
+int machine_kexec_post_load(struct kimage *kimage)
+{
+	int i;
+	void *ptr;
+	unsigned long mem;
+
+	/* Mark fdt_index invalid */
+	kimage->arch.fdt_index = -1;
+
+	if (kimage->type != KEXEC_TYPE_CRASH)
+		return 0;
+
+	for (i = 0; i < kimage->nr_segments; i++) {
+		mem = kimage->segment[i].mem;
+		ptr = __va(mem);
+
+		if (ptr && fdt_magic(ptr) == FDT_MAGIC) {
+			kimage->arch.fdt_index = i;
+			break;
+		}
+	}
+
+	return 0;
+}
+#endif
+
 /* Called during kexec sequence with MMU off */
 static notrace void copy_segments(unsigned long ind)
 {
arch/powerpc/kexec/elf_64.c +6 -0
index eeb258002d1e0..2a17f171661f1 100644
@@ -123,6 +123,12 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
 	kbuf.buf_align = PAGE_SIZE;
 	kbuf.top_down = true;
 	kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
+
+#if defined(CONFIG_CRASH_HOTPLUG)
+	image->arch.fdt_index = image->nr_segments;
+#endif
+	kbuf.memsz = fdt_totalsize(fdt);
+
 	ret = kexec_add_buffer(&kbuf);
 	if (ret)
 		goto out_free_fdt;
arch/powerpc/kexec/file_load_64.c +5 -0
index 9bc70b4d8eafc..725f74d1b928c 100644
@@ -1153,6 +1153,11 @@ int arch_kexec_kernel_image_probe(struct kimage *image, void *buf,
 		return ret;
 	}
 
+#if defined(CONFIG_CRASH_HOTPLUG)
+	/* Mark fdt_index invalid */
+	image->arch.fdt_index = -1;
+#endif
+
 	return kexec_image_probe_default(image, buf, buf_len);
 }
 
Signature · 7 lines
2.39.0


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

Re: [PATCH v7 3/8] powerpc/crash: update kimage_arch struct

Quoted 48 lines · Sourabh Jain

Add a new member "fdt_index" to kimage_arch struct to hold the index of the FDT (Flattened Device Tree) segment in the kexec segment array.

Having direct access to FDT segment will help arch crash hotplug handler to avoid looping kexec segment array to identify the FDT segment index for every FDT update on hotplug events.

The fdt_index is initialized during the kexec load for both kexec_load and kexec_file_load system call.

---
 arch/powerpc/include/asm/kexec.h  |  7 +++++++
 arch/powerpc/kexec/core_64.c      | 27 +++++++++++++++++++++++++++
 arch/powerpc/kexec/elf_64.c       |  6 ++++++
 arch/powerpc/kexec/file_load_64.c |  5 +++++
 4 files changed, 45 insertions(+)
arch/powerpc/include/asm/kexec.h +7 -0
index 8090ad7d97d9d..5a322c1737661 100644
@@ -103,6 +103,10 @@ void kexec_copy_flush(struct kimage *image);
 struct crash_mem;
 int update_cpus_node(void *fdt);
 int get_crash_memory_ranges(struct crash_mem **mem_ranges);
+#if defined(CONFIG_CRASH_HOTPLUG)
+int machine_kexec_post_load(struct kimage *image);
+#define machine_kexec_post_load machine_kexec_post_load
+#endif
 #endif
 
 #if defined(CONFIG_CRASH_DUMP) && defined(CONFIG_PPC_RTAS)
@@ -118,6 +122,9 @@ extern const struct kexec_file_ops kexec_elf64_ops;
 struct kimage_arch {
 	struct crash_mem *exclude_ranges;
 
+#if defined(CONFIG_CRASH_HOTPLUG)
+	int fdt_index;
+#endif
 	unsigned long backup_start;
 	void *backup_buf;
 	void *fdt;
arch/powerpc/kexec/core_64.c +0 -0
index 0b292f93a74cc..3d4fe1aa6f761 100644

arch/powerpc/kexec/core_64.c int machine_kexec_prepare(struct kimage *image) · line 80

Quoted 4 lines
arch/powerpc/kexec/core_64.c +1 -0
@@ -77,6 +77,33 @@ int machine_kexec_prepare(struct kimage *image)
 	return 0;
 }
 
+#if defined(CONFIG_CRASH_HOTPLUG)

I think you should add a small function header describing that this function is recording the index of the FDT segment for later use.

arch/powerpc/kexec/core_64.c int machine_kexec_prepare(struct kimage *image) · line 88

Quoted 8 lines
arch/powerpc/kexec/core_64.c +8 -0
+int machine_kexec_post_load(struct kimage *kimage)
+{
+	int i;
+	void *ptr;
+	unsigned long mem;
+
+	/* Mark fdt_index invalid */
+	kimage->arch.fdt_index = -1;

Is that really needed?
This is already done in arch_kexec_kernel_image_probe() called before this function, isn't it?

Quoted 26 lines
arch/powerpc/kexec/core_64.c +18 -0
+
+	if (kimage->type != KEXEC_TYPE_CRASH)
+		return 0;
+
+	for (i = 0; i < kimage->nr_segments; i++) {
+		mem = kimage->segment[i].mem;
+		ptr = __va(mem);
+
+		if (ptr && fdt_magic(ptr) == FDT_MAGIC) {
+			kimage->arch.fdt_index = i;
+			break;
+		}
+	}
+
+	return 0;
+}
+#endif
+
 /* Called during kexec sequence with MMU off */
 static notrace void copy_segments(unsigned long ind)
 {
arch/powerpc/kexec/elf_64.c +0 -0
index eeb258002d1e0..2a17f171661f1 100644

arch/powerpc/kexec/elf_64.c static void *elf64_load(struct kimage *image, char *kernel_buf, · line 128

Quoted 6 lines
arch/powerpc/kexec/elf_64.c +3 -0
@@ -123,6 +123,12 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
 	kbuf.buf_align = PAGE_SIZE;
 	kbuf.top_down = true;
 	kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
+
+#if defined(CONFIG_CRASH_HOTPLUG)
+	image->arch.fdt_index = image->nr_segments;

I'm sorry, I'm not familliar with that code, could you explain why fdt_index has to be assigned here, and to that value?

Quoted 22 lines
arch/powerpc/kexec/elf_64.c +3 -0
+#endif
+	kbuf.memsz = fdt_totalsize(fdt);
+
 	ret = kexec_add_buffer(&kbuf);
 	if (ret)
 		goto out_free_fdt;
arch/powerpc/kexec/file_load_64.c +5 -0
index 9bc70b4d8eafc..725f74d1b928c 100644
@@ -1153,6 +1153,11 @@ int arch_kexec_kernel_image_probe(struct kimage *image, void *buf,
 		return ret;
 	}
 
+#if defined(CONFIG_CRASH_HOTPLUG)
+	/* Mark fdt_index invalid */
+	image->arch.fdt_index = -1;
+#endif
+
 	return kexec_image_probe_default(image, buf, buf_len);
 }
 
#5 lore raw

Re: [PATCH v7 3/8] powerpc/crash: update kimage_arch struct

Hello Laurent,

Quoted 52 lines · Laurent Dufour
Quoted 51 lines · Sourabh Jain

Add a new member "fdt_index" to kimage_arch struct to hold the index of the FDT (Flattened Device Tree) segment in the kexec segment array.

Having direct access to FDT segment will help arch crash hotplug handler to avoid looping kexec segment array to identify the FDT segment index for every FDT update on hotplug events.

The fdt_index is initialized during the kexec load for both kexec_load and kexec_file_load system call.

---
  arch/powerpc/include/asm/kexec.h  |  7 +++++++
  arch/powerpc/kexec/core_64.c      | 27 +++++++++++++++++++++++++++
  arch/powerpc/kexec/elf_64.c       |  6 ++++++
  arch/powerpc/kexec/file_load_64.c |  5 +++++
  4 files changed, 45 insertions(+)
arch/powerpc/include/asm/kexec.h +7 -0
index 8090ad7d97d9d..5a322c1737661 100644
@@ -103,6 +103,10 @@ void kexec_copy_flush(struct kimage *image);
  struct crash_mem;
  int update_cpus_node(void *fdt);
  int get_crash_memory_ranges(struct crash_mem **mem_ranges);
+#if defined(CONFIG_CRASH_HOTPLUG)
+int machine_kexec_post_load(struct kimage *image);
+#define machine_kexec_post_load machine_kexec_post_load
+#endif
  #endif
 
  #if defined(CONFIG_CRASH_DUMP) && defined(CONFIG_PPC_RTAS)
@@ -118,6 +122,9 @@ extern const struct kexec_file_ops kexec_elf64_ops;
  struct kimage_arch {
  	struct crash_mem *exclude_ranges;
 
+#if defined(CONFIG_CRASH_HOTPLUG)
+	int fdt_index;
+#endif
  	unsigned long backup_start;
  	void *backup_buf;
  	void *fdt;
arch/powerpc/kexec/core_64.c +0 -0
index 0b292f93a74cc..3d4fe1aa6f761 100644
@@ -77,6 +77,33 @@ int machine_kexec_prepare(struct kimage *image)
  	return 0;
  }
 
Quoted 3 lines

arch/powerpc/kexec/core_64.c int machine_kexec_prepare(struct kimage *image) · line 80

Quoted 1 line
arch/powerpc/kexec/core_64.c +1 -0
+#if defined(CONFIG_CRASH_HOTPLUG)

I think you should add a small function header describing that this function is recording the index of the FDT segment for later use.

Yes good to have one,  I will add it in the next version.

Quoted 12 lines

arch/powerpc/kexec/core_64.c int machine_kexec_prepare(struct kimage *image) · line 88

Quoted 9 lines
arch/powerpc/kexec/core_64.c +8 -0
+int machine_kexec_post_load(struct kimage *kimage)
+{
+	int i;
+	void *ptr;
+	unsigned long mem;
+
+	/* Mark fdt_index invalid */
+	kimage->arch.fdt_index = -1;

Is that really needed?
This is already done in arch_kexec_kernel_image_probe() called before this function, isn't it?

Oh I didn't realize machine_kexec_post load is called for both kexec_load and kexec_file_load system call.

The intention was to initialize fdt_index for both system calls but since machine_kexec_post_load is called for both system calls, initializing fdt_index in arch_kernel_image_probe function is redundant.

Thanks for point it out. I will fix this in the next version by only initializing the fdtindex in machine_kexec_post_load. With this fdt_index will be initialized for both syscalls.

Quoted 26 lines
Quoted 26 lines
arch/powerpc/kexec/core_64.c +18 -0
+
+	if (kimage->type != KEXEC_TYPE_CRASH)
+		return 0;
+
+	for (i = 0; i < kimage->nr_segments; i++) {
+		mem = kimage->segment[i].mem;
+		ptr = __va(mem);
+
+		if (ptr && fdt_magic(ptr) == FDT_MAGIC) {
+			kimage->arch.fdt_index = i;
+			break;
+		}
+	}
+
+	return 0;
+}
+#endif
+
  /* Called during kexec sequence with MMU off */
  static notrace void copy_segments(unsigned long ind)
  {
arch/powerpc/kexec/elf_64.c +0 -0
index eeb258002d1e0..2a17f171661f1 100644
@@ -123,6 +123,12 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
Quoted 8 lines

arch/powerpc/kexec/elf_64.c static void *elf64_load(struct kimage *image, char *kernel_buf, · line 128

Quoted 6 lines
arch/powerpc/kexec/elf_64.c +3 -0
  	kbuf.buf_align = PAGE_SIZE;
  	kbuf.top_down = true;
  	kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
+
+#if defined(CONFIG_CRASH_HOTPLUG)
+	image->arch.fdt_index = image->nr_segments;

I'm sorry, I'm not familliar with that code, could you explain why fdt_index has to be assigned here, and to that value?

Again I didn't realize machine_kexec_post_load is also called for kexec_file_load system call too, which makes this assignment redundant.

Now why this value?

The image->nr-segments holds the count of total number of kexec segments and when a new segment/buffer is added ( by kexec_add_buffer()) it is incremented by 1. With this the index of newly added segment in the kexec segment array will be image->nr_segments - 1.

So instead of adding fdt segment first and then initializing fdt_index as image->nr_segments - 1, the fdt_index is initialized with nr_segments before adding the fdt kexec segment/buffer to the segment array.

Hope I answered you query.

Thanks for the review.

- Sourabh

Quoted 15 lines
Quoted 15 lines
arch/powerpc/kexec/elf_64.c +3 -0
+#endif
+	kbuf.memsz = fdt_totalsize(fdt);
+
  	ret = kexec_add_buffer(&kbuf);
  	if (ret)
  		goto out_free_fdt;
arch/powerpc/kexec/file_load_64.c +0 -0
index 9bc70b4d8eafc..725f74d1b928c 100644
@@ -1153,6 +1153,11 @@ int arch_kexec_kernel_image_probe(struct kimage *image, void *buf,
  		return ret;
  	}
 
Quoted 8 lines

arch/powerpc/kexec/file_load_64.c int arch_kexec_kernel_image_probe(struct kimage *image, void *buf, · line 1163

Quoted 8 lines
arch/powerpc/kexec/file_load_64.c +5 -0
+#if defined(CONFIG_CRASH_HOTPLUG)
+	/* Mark fdt_index invalid */
+	image->arch.fdt_index = -1;
+#endif
+
  	return kexec_image_probe_default(image, buf, buf_len);
  }
 

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

#6 lore raw

PATCH v7 4/8 crash: add phdr for possible CPUs in elfcorehdr

In reply to Sourabh Jain

On architectures like PowerPC the crash notes are available for all possible CPUs. So let's populate the elfcorehdr for all possible CPUs having crash notes to avoid updating elfcorehdr during in-kernel crash update on CPU hotplug events.

The similar technique is used in kexec-tool for kexec_load case.

---
 kernel/crash_core.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
kernel/crash_core.c +6 -3
index 910d377ea317e..19f987b3851e8 100644
@@ -364,8 +364,8 @@ int crash_prepare_elf64_headers(struct kimage *image, struct crash_mem *mem,
 	ehdr->e_ehsize = sizeof(Elf64_Ehdr);
 	ehdr->e_phentsize = sizeof(Elf64_Phdr);
 
-	/* Prepare one phdr of type PT_NOTE for each present CPU */
-	for_each_present_cpu(cpu) {
+	/* Prepare one phdr of type PT_NOTE for possible CPU with crash note. */
+	for_each_possible_cpu(cpu) {
 #ifdef CONFIG_CRASH_HOTPLUG
 		if (IS_ENABLED(CONFIG_HOTPLUG_CPU)) {
 			/* Skip the soon-to-be offlined cpu */
@@ -373,8 +373,11 @@ int crash_prepare_elf64_headers(struct kimage *image, struct crash_mem *mem,
 				continue;
 		}
 #endif
-		phdr->p_type = PT_NOTE;
 		notes_addr = per_cpu_ptr_to_phys(per_cpu_ptr(crash_notes, cpu));
+		if (!notes_addr)
+			continue;
+
+		phdr->p_type = PT_NOTE;
 		phdr->p_offset = phdr->p_paddr = notes_addr;
 		phdr->p_filesz = phdr->p_memsz = sizeof(note_buf_t);
 		(ehdr->e_phnum)++;
Signature · 7 lines
2.39.0


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

Re: [PATCH v7 4/8] crash: add phdr for possible CPUs in elfcorehdr

Quoted 11 lines · Sourabh Jain

On architectures like PowerPC the crash notes are available for all possible CPUs. So let's populate the elfcorehdr for all possible CPUs having crash notes to avoid updating elfcorehdr during in-kernel crash update on CPU hotplug events.

The similar technique is used in kexec-tool for kexec_load case.

---
 kernel/crash_core.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

This patch is not applying on ppc/next (53ab112a9508).

As far as I could see, crash_prepare_elf64_headers() is defined in the file kernel/kexec_file.c and that's not recent, see babac4a84a88 (kexec_file,
x86: move re-factored code to generic side, 2018-04-13)

Am I missing something?

Quoted 19 lines
kernel/crash_core.c +2 -2
index 910d377ea317e..19f987b3851e8 100644
@@ -364,8 +364,8 @@ int crash_prepare_elf64_headers(struct kimage *image, struct crash_mem *mem,
 	ehdr->e_ehsize = sizeof(Elf64_Ehdr);
 	ehdr->e_phentsize = sizeof(Elf64_Phdr);
 
-	/* Prepare one phdr of type PT_NOTE for each present CPU */
-	for_each_present_cpu(cpu) {
+	/* Prepare one phdr of type PT_NOTE for possible CPU with crash note. */
+	for_each_possible_cpu(cpu) {
 #ifdef CONFIG_CRASH_HOTPLUG
 		if (IS_ENABLED(CONFIG_HOTPLUG_CPU)) {
 			/* Skip the soon-to-be offlined cpu */
@@ -373,8 +373,11 @@ int crash_prepare_elf64_headers(struct kimage *image, struct crash_mem *mem,
 				continue;
 		}

kernel/crash_core.c int crash_prepare_elf64_headers(struct kimage *image, struct crash_mem *mem, · line 383

Quoted 10 lines
kernel/crash_core.c +4 -1
 #endif
-		phdr->p_type = PT_NOTE;
 		notes_addr = per_cpu_ptr_to_phys(per_cpu_ptr(crash_notes, cpu));
+		if (!notes_addr)
+			continue;
+
+		phdr->p_type = PT_NOTE;
 		phdr->p_offset = phdr->p_paddr = notes_addr;
 		phdr->p_filesz = phdr->p_memsz = sizeof(note_buf_t);
 		(ehdr->e_phnum)++;

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

#8 lore raw

Re: [PATCH v7 4/8] crash: add phdr for possible CPUs in elfcorehdr

Quoted 13 lines · Laurent Dufour
Quoted 11 lines · Sourabh Jain

On architectures like PowerPC the crash notes are available for all possible CPUs. So let's populate the elfcorehdr for all possible CPUs having crash notes to avoid updating elfcorehdr during in-kernel crash update on CPU hotplug events.

The similar technique is used in kexec-tool for kexec_load case.

---
 kernel/crash_core.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
Quoted 7 lines

This patch is not applying on ppc/next (53ab112a9508).

As far as I could see, crash_prepare_elf64_headers() is defined in the file kernel/kexec_file.c and that's not recent, see babac4a84a88 (kexec_file,
x86: move re-factored code to generic side, 2018-04-13)

Am I missing something?

My mistake, sounds that your series is based on top of the Eric's one (not yet upstream):

https://lore.kernel.org/lkml/[email protected]/

Quoted 22 lines
Quoted 22 lines
kernel/crash_core.c +2 -3
index 910d377ea317e..19f987b3851e8 100644
@@ -364,8 +364,8 @@ int crash_prepare_elf64_headers(struct kimage *image, struct crash_mem *mem,
 	ehdr->e_ehsize = sizeof(Elf64_Ehdr);
 	ehdr->e_phentsize = sizeof(Elf64_Phdr);
 
-	/* Prepare one phdr of type PT_NOTE for each present CPU */
-	for_each_present_cpu(cpu) {
+	/* Prepare one phdr of type PT_NOTE for possible CPU with crash note. */
+	for_each_possible_cpu(cpu) {
 #ifdef CONFIG_CRASH_HOTPLUG
 		if (IS_ENABLED(CONFIG_HOTPLUG_CPU)) {
 			/* Skip the soon-to-be offlined cpu */
@@ -373,8 +373,11 @@ int crash_prepare_elf64_headers(struct kimage *image, struct crash_mem *mem,
 				continue;
 		}
 #endif
-		phdr->p_type = PT_NOTE;
Quoted 9 lines

kernel/crash_core.c int crash_prepare_elf64_headers(struct kimage *image, struct crash_mem *mem, · line 383

Quoted 8 lines
kernel/crash_core.c +4 -0
 		notes_addr = per_cpu_ptr_to_phys(per_cpu_ptr(crash_notes, cpu));
+		if (!notes_addr)
+			continue;
+
+		phdr->p_type = PT_NOTE;
 		phdr->p_offset = phdr->p_paddr = notes_addr;
 		phdr->p_filesz = phdr->p_memsz = sizeof(note_buf_t);
 		(ehdr->e_phnum)++;

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

#9 lore raw

Re: [PATCH v7 4/8] crash: add phdr for possible CPUs in elfcorehdr

Quoted 15 lines · Laurent Dufour
Quoted 14 lines · Laurent Dufour
Quoted 11 lines · Sourabh Jain

On architectures like PowerPC the crash notes are available for all possible CPUs. So let's populate the elfcorehdr for all possible CPUs having crash notes to avoid updating elfcorehdr during in-kernel crash update on CPU hotplug events.

The similar technique is used in kexec-tool for kexec_load case.

---
  kernel/crash_core.c | 9 ++++++---
  1 file changed, 6 insertions(+), 3 deletions(-)

This patch is not applying on ppc/next (53ab112a9508).

Quoted 8 lines
Quoted 5 lines

As far as I could see, crash_prepare_elf64_headers() is defined in the file kernel/kexec_file.c and that's not recent, see babac4a84a88 (kexec_file,
x86: move re-factored code to generic side, 2018-04-13)

Am I missing something?

My mistake, sounds that your series is based on top of the Eric's one (not yet upstream):

https://lore.kernel.org/lkml/[email protected]/

Yes this patch series is dependent on the above patch series. In the next version I will share a git repo link that will have this patch series applied along with dependent patch series for easy try.

- Sourabh

#10 lore raw

PATCH v7 5/8 crash: pass hotplug action type to arch crash hotplug handler

In reply to Sourabh Jain

On PowerPC, the crash update action for CPU and Memory hotplug events is not the same. Since arch_crash_handle_hotplug_event is a common crash hotplug handler for both CPU and Memory hot un/plug events, it is hard to differentiate which hotplug event triggered the arch crash hotplug handler and decide the crash update action accordingly.

Pass the hotplug action type to arch specific crash hotplug handler so that corresponding crash update action can be taken based on the hotplug action type.

---
 arch/x86/include/asm/kexec.h | 2 +-
 arch/x86/kernel/crash.c      | 3 ++-
 include/linux/kexec.h        | 2 +-
 kernel/crash_core.c          | 2 +-
 4 files changed, 5 insertions(+), 4 deletions(-)
arch/x86/include/asm/kexec.h +1 -1
index 1bc852ce347d4..ec33a592a2ddd 100644
@@ -213,7 +213,7 @@ extern crash_vmclear_fn __rcu *crash_vmclear_loaded_vmcss;
 extern void kdump_nmi_shootdown_cpus(void);
 
 #ifdef CONFIG_CRASH_HOTPLUG
-void arch_crash_handle_hotplug_event(struct kimage *image);
+void arch_crash_handle_hotplug_event(struct kimage *image, unsigned int hp_action);
 #define arch_crash_handle_hotplug_event arch_crash_handle_hotplug_event
 
 #ifdef CONFIG_HOTPLUG_CPU
arch/x86/kernel/crash.c +2 -1
index 5186df48ce6c6..0026c5ad828d7 100644
@@ -465,12 +465,13 @@ int crash_load_segments(struct kimage *image)
 /**
  * arch_crash_handle_hotplug_event() - Handle hotplug elfcorehdr changes
  * @image: the active struct kimage
+ * @hp_action: the hot un/plug action being handled
  *
  * To accurately reflect hot un/plug changes, the new elfcorehdr
  * is prepared in a kernel buffer, and then it is written on top
  * of the existing/old elfcorehdr.
  */
-void arch_crash_handle_hotplug_event(struct kimage *image)
+void arch_crash_handle_hotplug_event(struct kimage *image, unsigned int hp_action)
 {
 	void *elfbuf = NULL, *old_elfcorehdr;
 	unsigned long mem, memsz;
include/linux/kexec.h +1 -1
index 0b1ad1ac06e37..ea8ff85b0b436 100644
@@ -509,7 +509,7 @@ static inline void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages) {
 #endif
 
 #ifndef arch_crash_handle_hotplug_event
-static inline void arch_crash_handle_hotplug_event(struct kimage *image) { }
+static inline void arch_crash_handle_hotplug_event(struct kimage *image, unsigned int hp_action) { }
 #endif
 
 #ifndef crash_hotplug_cpu_support
kernel/crash_core.c +1 -1
index 19f987b3851e8..bdf8c363a90aa 100644
@@ -707,7 +707,7 @@ static void handle_hotplug_event(unsigned int hp_action, unsigned int cpu)
 					cpu : KEXEC_CRASH_HP_INVALID_CPU;
 
 			/* Now invoke arch-specific update handler */
-			arch_crash_handle_hotplug_event(image);
+			arch_crash_handle_hotplug_event(image, hp_action);
 
 			/* No longer handling a hotplug event */
 			image->hotplug_event = false;
Signature · 7 lines
2.39.0


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

PATCH v7 6/8 powerpc/crash: add crash CPU hotplug support

In reply to Sourabh Jain

Introduce powerpc crash hotplug handler to update the necessary kexec segments on CPU/Memory hotplug events. A common crash hotplug handler is triggered from generic infrastructure for both CPU/Memory hot un/plugged events but in this patch, only CPU hot un/plugged events are introduced. The memory hotplug support is added in upcoming patches.

The elfcorehdr segment is used to exchange the CPU and other dump related information between the kernels. Ideally, the elfcorehdr segment needs to be recreated on CPU hotplug events to reflect the changes. But on PowerPC elfcorehdr is built with all possible CPUs instead of just online CPUs hence no elfcorehdr segment update/recreation is needed.

In addition to elfcorehdr there is one more kexec segment that holds CPU data FDT (Flattened Device Tree). To boot the PowerPC kernel the crashing CPU has to be part of the FDT segment. If the kdump kernel doesn't find the crashing CPU in the FDT segment, it fails to boot.

The only action needed on PowerPC to handle the crash CPU hotplug event is to add hot added CPUs in the FDT segment to avoid kdump kernel boot failure in case the system crashes on hot added CPU.

So for the CPU hot add events, the FDT segment is updated with hot added CPU and Since there is no need to remove the hot unplugged CPUs from the FDT segment hence no action taken on CPU hot remove event in PowerPC arch crash hotplug handler.

To accommodate a growing number of CPUs, FDT is built with additional buffer space to ensure that it can hold all possible CPUs.

The changes done here will also work for kexec_load system call given that the kexec tool builds the FDT segment with additional space to accommodate all possible CPUs as it is done for kexec_file_load system call in the kernel.

Since memory crash hotplug support is not there yet the crash hotplug handler simply warns the user and returns.

---
 arch/powerpc/include/asm/kexec.h |  4 ++
 arch/powerpc/kexec/core_64.c     | 43 ++++++++++++++++++++
 arch/powerpc/kexec/elf_64.c      | 69 +++++++++++++++++++++++++++++++-
 3 files changed, 114 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/kexec.h +4 -0
index 5a322c1737661..e7cd4fd2becf5 100644
@@ -106,6 +106,10 @@ int get_crash_memory_ranges(struct crash_mem **mem_ranges);
 #if defined(CONFIG_CRASH_HOTPLUG)
 int machine_kexec_post_load(struct kimage *image);
 #define machine_kexec_post_load machine_kexec_post_load
+
+void arch_crash_handle_hotplug_event(struct kimage *image, unsigned int hp_action);
+#define arch_crash_handle_hotplug_event arch_crash_handle_hotplug_event
+
 #endif
 #endif
 
arch/powerpc/kexec/core_64.c +43 -0

49 lines not on this page · raw message

arch/powerpc/kexec/elf_64.c +67 -2

88 lines not on this page · raw message

Signature · 7 lines
2.39.0


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

PATCH v7 7/8 crash: forward memory_notify args to arch crash hotplug handler

In reply to Sourabh Jain

The way memory hot remove is handled on PowerPC, it is hard to update the elfcorehdr without memory_notify args.

On PowePC memblock data structure is used to prepare elfcorehdr for kdump. Since the notifier used for memory hotplug crash handler get initiated before the memblock data structure update happens (as depicted below), the newly prepared elfcorehdr still holds the old memory regions. So if the system crash with obsolete elfcorehdr, makedumpfile failed to collect vmcore.

Sequence of actions done on PowerPC to serve the memory hot remove:

Initiate memory hot remove

          |
          v
 offline pages
          |
          v
 initiate memory notify call chain
 for MEM_OFFLINE event.
 (same is used for crash update)
          |
          v
 prepare new elfcorehdr for kdump using
 memblock data structure
          |
          v

update memblock data structure

How passing memory_notify to arch crash hotplug handler will help?

memory_notify holds the start PFN and page count, with that base address and size of hot unplugged memory can calculated and same can be use to avoid hot unplugged memory region to get added in the elfcorehdr.

---
 arch/powerpc/include/asm/kexec.h |  2 +-
 arch/powerpc/kexec/core_64.c     |  3 ++-
 arch/x86/include/asm/kexec.h     |  3 ++-
 arch/x86/kernel/crash.c          |  4 +++-
 include/linux/kexec.h            |  6 +++++-
 kernel/crash_core.c              | 14 +++++++-------
 6 files changed, 20 insertions(+), 12 deletions(-)
arch/powerpc/include/asm/kexec.h +1 -1
index e7cd4fd2becf5..743056f0bedf2 100644
@@ -107,7 +107,7 @@ int get_crash_memory_ranges(struct crash_mem **mem_ranges);
 int machine_kexec_post_load(struct kimage *image);
 #define machine_kexec_post_load machine_kexec_post_load
 
-void arch_crash_handle_hotplug_event(struct kimage *image, unsigned int hp_action);
+void arch_crash_handle_hotplug_event(struct kimage *image, unsigned int hp_action, void *arg);
 #define arch_crash_handle_hotplug_event arch_crash_handle_hotplug_event
 
 #endif
arch/powerpc/kexec/core_64.c +2 -1
index 7748b633c20fa..1f807b29db93f 100644
@@ -575,11 +575,12 @@ int update_cpus_node(void *fdt)
  * arch_crash_hotplug_handler() - Handle hotplug kexec segements changes FDT, elfcorehdr
  * @image: the active struct kimage
  * @hp_action: the hot un/plug action being handled
+ * @arg: struct memory_notify data handler
  *
  * To accurately reflect CPU hot un/plug changes, the FDT must be updated with the
  * new list of CPUs.
  */
-void arch_crash_handle_hotplug_event(struct kimage *image, unsigned int hp_action)
+void arch_crash_handle_hotplug_event(struct kimage *image, unsigned int hp_action, void *arg)
 {
 	void *fdt;
 
arch/x86/include/asm/kexec.h +2 -1
index ec33a592a2ddd..171edb8167a12 100644
@@ -213,7 +213,8 @@ extern crash_vmclear_fn __rcu *crash_vmclear_loaded_vmcss;
 extern void kdump_nmi_shootdown_cpus(void);
 
 #ifdef CONFIG_CRASH_HOTPLUG
-void arch_crash_handle_hotplug_event(struct kimage *image, unsigned int hp_action);
+void arch_crash_handle_hotplug_event(struct kimage *image,
+				     unsigned int hp_action, void *arg);
 #define arch_crash_handle_hotplug_event arch_crash_handle_hotplug_event
 
 #ifdef CONFIG_HOTPLUG_CPU
arch/x86/kernel/crash.c +3 -1
index 0026c5ad828d7..6bdfefebdd27c 100644
@@ -466,12 +466,14 @@ int crash_load_segments(struct kimage *image)
  * arch_crash_handle_hotplug_event() - Handle hotplug elfcorehdr changes
  * @image: the active struct kimage
  * @hp_action: the hot un/plug action being handled
+ * @arg: struct memory_notify data handler
  *
  * To accurately reflect hot un/plug changes, the new elfcorehdr
  * is prepared in a kernel buffer, and then it is written on top
  * of the existing/old elfcorehdr.
  */
-void arch_crash_handle_hotplug_event(struct kimage *image, unsigned int hp_action)
+void arch_crash_handle_hotplug_event(struct kimage *image,
+				     unsigned int hp_action, void *arg)
 {
 	void *elfbuf = NULL, *old_elfcorehdr;
 	unsigned long mem, memsz;
include/linux/kexec.h +5 -1
index ea8ff85b0b436..f640d3c30f41c 100644
@@ -509,7 +509,11 @@ static inline void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages) {
 #endif
 
 #ifndef arch_crash_handle_hotplug_event
-static inline void arch_crash_handle_hotplug_event(struct kimage *image, unsigned int hp_action) { }
+static inline void arch_crash_handle_hotplug_event(struct kimage *image,
+						   unsigned int hp_action,
+						   void *arg)
+{
+}
 #endif
 
 #ifndef crash_hotplug_cpu_support
kernel/crash_core.c +7 -7
index bdf8c363a90aa..735f2022593fa 100644
@@ -645,7 +645,7 @@ subsys_initcall(crash_save_vmcoreinfo_init);
  * list of segments it checks (since the elfcorehdr changes and thus
  * would require an update to purgatory itself to update the digest).
  */
-static void handle_hotplug_event(unsigned int hp_action, unsigned int cpu)
+static void handle_hotplug_event(unsigned int hp_action, unsigned int cpu, void *arg)
 {
 	/* Obtain lock while changing crash information */
 	if (kexec_trylock()) {
@@ -707,7 +707,7 @@ static void handle_hotplug_event(unsigned int hp_action, unsigned int cpu)
 					cpu : KEXEC_CRASH_HP_INVALID_CPU;
 
 			/* Now invoke arch-specific update handler */
-			arch_crash_handle_hotplug_event(image, hp_action);
+			arch_crash_handle_hotplug_event(image, hp_action, arg);
 
 			/* No longer handling a hotplug event */
 			image->hotplug_event = false;
@@ -722,17 +722,17 @@ static void handle_hotplug_event(unsigned int hp_action, unsigned int cpu)
 	}
 }
 
-static int crash_memhp_notifier(struct notifier_block *nb, unsigned long val, void *v)
+static int crash_memhp_notifier(struct notifier_block *nb, unsigned long val, void *arg)
 {
 	switch (val) {
 	case MEM_ONLINE:
 		handle_hotplug_event(KEXEC_CRASH_HP_ADD_MEMORY,
-			KEXEC_CRASH_HP_INVALID_CPU);
+			KEXEC_CRASH_HP_INVALID_CPU, arg);
 		break;
 
 	case MEM_OFFLINE:
 		handle_hotplug_event(KEXEC_CRASH_HP_REMOVE_MEMORY,
-			KEXEC_CRASH_HP_INVALID_CPU);
+			KEXEC_CRASH_HP_INVALID_CPU, arg);
 		break;
 	}
 	return NOTIFY_OK;
@@ -745,13 +745,13 @@ static struct notifier_block crash_memhp_nb = {
 
 static int crash_cpuhp_online(unsigned int cpu)
 {
-	handle_hotplug_event(KEXEC_CRASH_HP_ADD_CPU, cpu);
+	handle_hotplug_event(KEXEC_CRASH_HP_ADD_CPU, cpu, NULL);
 	return 0;
 }
 
 static int crash_cpuhp_offline(unsigned int cpu)
 {
-	handle_hotplug_event(KEXEC_CRASH_HP_REMOVE_CPU, cpu);
+	handle_hotplug_event(KEXEC_CRASH_HP_REMOVE_CPU, cpu, NULL);
 	return 0;
 }
 
Signature · 7 lines
2.39.0


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

PATCH v7 8/8 powerpc/kexec: add crash memory hotplug support

In reply to Sourabh Jain

Extend PowerPC arch crash hotplug handler to support memory hotplug events. Since elfcorehdr is used to exchange the memory info between the kernels hence it needs to be recreated to reflect the changes due to memory hotplug events.

The way memory hotplug events are handled on PowerPC and the notifier call chain used in generic code to trigger the arch crash handler, the process to recreate the elfcorehdr is different for memory add and remove events.

In the hot remove case, the memory region is first marked offline then the notifier call chain is triggered (same is used to initiate arch crash hotplug handler) and at last the memblock structure is updated. Whereas in the hot add case, memblock structure is updated before the notifier call chain is triggered.

On PowerPC, memblock structure is used to identify the memory ranges for elfcorehdr. In case of memory hot remove the memblock structure is updated after the arch crash hotplug handler is triggered, hence an additional step is taken to ensure that memory ranges used to build elfcorehdr do not include hot removed memory. Whereas no such extra steps are needed for the hot add case because memblock structure is updated before the arch crash hotplug handler is triggered.

The hot removed memory is explicitly removed from the memory ranges list before creating elfcorehdr for the hot remove case.

To accommodate a growing number of memory regions, elfcorehdr is built with additional buffer space to hold max memory regions.

The changes done here will also work for the kexec_load system call given that the kexec tool builds the elfcoredhr with additional space to accommodate future memory regions as it is done for kexec_file_load system call.

---
 arch/powerpc/include/asm/kexec_ranges.h |  1 +
 arch/powerpc/kexec/core_64.c            | 59 ++++++++++++++++++++++--
 arch/powerpc/kexec/file_load_64.c       | 12 ++++-
 arch/powerpc/kexec/ranges.c             | 60 +++++++++++++++++++++++++
 4 files changed, 127 insertions(+), 5 deletions(-)
arch/powerpc/include/asm/kexec_ranges.h +1 -0
index f83866a19e870..802abf580cf0f 100644
@@ -7,6 +7,7 @@
 void sort_memory_ranges(struct crash_mem *mrngs, bool merge);
 struct crash_mem *realloc_mem_ranges(struct crash_mem **mem_ranges);
 int add_mem_range(struct crash_mem **mem_ranges, u64 base, u64 size);
+int remove_mem_range(struct crash_mem **mem_ranges, u64 base, u64 size);
 int add_tce_mem_ranges(struct crash_mem **mem_ranges);
 int add_initrd_mem_range(struct crash_mem **mem_ranges);
 #ifdef CONFIG_PPC_64S_HASH_MMU
arch/powerpc/kexec/core_64.c +56 -3

84 lines not on this page · raw message

arch/powerpc/kexec/file_load_64.c +10 -2
index 725f74d1b928c..5ec5d0b1ec904 100644
@@ -21,6 +21,8 @@
 #include <linux/memblock.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
+#include <linux/elf.h>
+
 #include <asm/setup.h>
 #include <asm/drmem.h>
 #include <asm/firmware.h>
@@ -735,7 +737,13 @@ static int load_elfcorehdr_segment(struct kimage *image, struct kexec_buf *kbuf)
 
 	kbuf->buffer = headers;
 	kbuf->mem = KEXEC_BUF_MEM_UNKNOWN;
-	kbuf->bufsz = kbuf->memsz = headers_sz;
+	kbuf->bufsz = headers_sz;
+/* Additional buffer space to accommodate future memory ranges */
+#if defined(CONFIG_MEMORY_HOTPLUG)
+	kbuf->memsz = PN_XNUM * sizeof(Elf64_Phdr);
+#else
+	kbuf->memsz = headers_sz;
+#endif
 	kbuf->top_down = false;
 
 	ret = kexec_add_buffer(kbuf);
@@ -745,7 +753,7 @@ static int load_elfcorehdr_segment(struct kimage *image, struct kexec_buf *kbuf)
 	}
 
 	image->elf_load_addr = kbuf->mem;
-	image->elf_headers_sz = headers_sz;
+	image->elf_headers_sz = kbuf->memsz;
 	image->elf_headers = headers;
 out:
 	kfree(cmem);
arch/powerpc/kexec/ranges.c +60 -0

66 lines not on this page · raw message

Signature · 7 lines
2.39.0


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