Skip to contentSkip to conversation

Avoid kdump service reload on CPU hotplug events

RFC PATCH New Sourabh Jain 2 participants 8 messages Feb 21, 2022 – Feb 24, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Avoid kdump service reload on CPU hotplug events

On hotplug event (CPU/memory) the CPU information prepared for the kdump kernel becomes stale unless it is prepared again. To keep the CPU information up-to-date a kdump service reload is triggered via the udev rule.

The above approach has two downsides:

1) The udev rules are prone to races if hotplug event is frequent. The time is taken to settle down all the kdump service reload requested is significant when multiple CPU/memory hotplug is performed at the same time. This creates a window where kernel crash might not lead to successfully dump collection.

2) Unnecessary CPU cycles are consumed to reload all the kdump components including initrd, vmlinux, FDT, etc. whereas only one component needs to update that is FDT.

How this patch series solve the above issue?
--------------------------------------------
As mentioned above the only kexec segment that gets updated during the kdump service reload (due to hotplug event) is FDT. So, instead of re-creating the FDT on every hotplug event, it is just created once and updated on every hotplug event. This FDT is referred as kexec crash FDT.

How kexec crash FDT is managed?
-------------------------------
During the kernel boot, a hole is allocated for kexec crash FDT in the kdump reserved region. On kdump service start a fresh copy of kdump FDT (created by kexec tool or kernel-based on which system call is used) is copied to the pre-allocated hole for kexec crash FDT. Once a kexec crash FDT is loaded all the subsequent updates needed due to CPU hot-add event can directly be done to kexec crash FDT without reloading all the kexec segment again. A hook is added on the CPU hot-add path to update the kexec crash FDT.

How kexec crash FDT is accessed in kexec_load and kexec_file_load system call?
------------------------------------------------------------------------------
Since kexec_file_load creates all kexec segments are prepared in the kernel, it can easily access the kexec crash FDT with help of two global variables, that holds the start address and the size of the kexec crash FDT.

In kexec_load system call, the kexec segments are prepared by the kexec tool in userspace. The start address and the size of kexec crash fdt is provided to userspace via two sysfs files /sys/kernel/kexec_crash_fdt and /sys/kernel/kexec_crash_fdt_size.

A couple of minor changes are required to realise the benefit of the patch series:

- disalble the udev rule:

comment out the below line in kdump udev rule file:
RHEL: /usr/lib/udev/rules.d/98-kexec.rules
# SUBSYSTEM=="cpu", ACTION=="online", GOTO="kdump_reload_cpu"

- kexec tool needs to be updated with patch for kexec_load system call to work (not needed if -s option is used during kexec panic load):

---
From 37aa38713c163b31d9c6e80ddc059424c9fcd66d Mon Sep 17 00:00:00 2001
From: Sourabh Jain <[email protected]>
Date: Mon, 22 Nov 2021 14:12:52 +0530
Subject: [PATCH] kexec/ppc64: use pre-allocated memory hole for kexec crash
FDT

Enabled kexec to use the per allocated memory hole for kexec crash FDT which is exported via /sys/kernel/kexec_crash_fdt and /sys/kernel/kexec_crash_fdt_size sysfs files. Using this pre-allocated memory hole for kdump fdt will allow the kernel to keep the kdump fdt up-to-date with the latest CPU information.

In case a pre-allocated memory hole is used for kdump fdt, the kdump fdt the segment is not included in SHA calculation because kdump fdt will be modified by the kernel.

To maintain the backward compatibility, we fall back to the old option of finding hole for kdump fdt segment if the pre-allocated buffer is not provided by the kernel.

---
 kexec/arch/ppc64/kexec-elf-ppc64.c | 11 +++++--
 kexec/arch/ppc64/kexec-ppc64.c     | 49 ++++++++++++++++++++++++++++++
 kexec/kexec.c                      |  9 ++++++
 kexec/kexec.h                      |  4 +++
 4 files changed, 71 insertions(+), 2 deletions(-)
kexec/arch/ppc64/kexec-elf-ppc64.c +9 -2
index 695b8b0..8e66ef0 100644
@@ -329,8 +329,15 @@ int elf_ppc64_load(int argc, char **argv, const char *buf, off_t len,
 	if (result < 0)
 		return result;
 
-	my_dt_offset = add_buffer(info, seg_buf, seg_size, seg_size,
-				0, 0, max_addr, -1);
+        if (kexec_crash_fdt) {
+                my_dt_offset = kexec_crash_fdt;
+                add_segment_phys_virt(info, seg_buf, seg_size,
+				      my_dt_offset, kexec_crash_fdt_size, 0);
+        }
+        else {
+                my_dt_offset = add_buffer(info, seg_buf, seg_size, seg_size,
+                                          0, 0, max_addr, -1);
+        }
 
 #ifdef NEED_RESERVE_DTB
 	/* patch reserve map address for flattened device-tree
kexec/arch/ppc64/kexec-ppc64.c +49 -0

67 lines not on this page · raw message

kexec/kexec.c +9 -0
index f63b36b..89283f7 100644
@@ -62,6 +62,10 @@ static unsigned long kexec_flags = 0;
 /* Flags for kexec file (fd) based syscall */
 static unsigned long kexec_file_flags = 0;
 int kexec_debug = 0;
+#if defined(__powerpc__) || defined(__powerpc64__)
+uint64_t kexec_crash_fdt;
+uint32_t kexec_cras_fdt_size;
+#endif
 
 void dbgprint_mem_range(const char *prefix, struct memory_range *mr, int nr_mr)
 {
@@ -672,6 +676,11 @@ static void update_purgatory(struct kexec_info *info)
 		if (info->segment[i].mem == (void *)info->rhdr.rel_addr) {
 			continue;
 		}
+
+#if defined(__powerpc__) || defined(__powerpc64__)
+		if (kexec_crash_fdt && (unsigned long)info->segment[i].mem == kexec_crash_fdt)
+			continue;
+#endif
 		sha256_update(&ctx, info->segment[i].buf,
 			      info->segment[i].bufsz);
 		nullsz = info->segment[i].memsz - info->segment[i].bufsz;
kexec/kexec.h +4 -0
index 595dd68..48e8b9f 100644
@@ -205,6 +205,10 @@ struct file_type {
 
 extern struct file_type file_type[];
 extern int file_types;
+#if defined(__powerpc__) || defined(__powerpc64__)
+extern uint64_t fdt;
+extern uint32_t fdt_size;
+#endif
 
 #define OPT_HELP		'h'
 #define OPT_VERSION		'v'
Signature · 22 lines
2.34.1
---


Sourabh Jain (5):
  powerpc/kdump: export functions from file_load_64.c
  powerpc/kdump: setup kexec crash FDT
  powerpc/kdump: update kexec crash FDT on CPU hot add event
  powerpc/kdump: enable kexec_file_load system call to use kexec crash
    FDT
  powerpc/kdump: export kexec crash FDT details via sysfs

 arch/powerpc/Kconfig                         |  11 +
 arch/powerpc/include/asm/kexec.h             |  10 +
 arch/powerpc/kexec/core_64.c                 | 318 +++++++++++++++++++
 arch/powerpc/kexec/elf_64.c                  |  22 +-
 arch/powerpc/kexec/file_load_64.c            | 239 +-------------
 arch/powerpc/platforms/pseries/hotplug-cpu.c |   7 +
 6 files changed, 369 insertions(+), 238 deletions(-)

-- 
2.34.1
#1 lore raw

RFC PATCH 1/5 powerpc/kdump: export functions from file_load_64.c

Functions get_exclude_memory_ranges and locate_mem_hole_top_down_ppc64 can be shared across different kexec components, so export them as global functions.

The locate_mem_hole_top_down_ppc64 and get_exclude_memory_ranges functions definition is moved to core_64.c so that both kexec_load and kexec_file_load system call can use them.

---
 arch/powerpc/include/asm/kexec.h  |   4 +
 arch/powerpc/kexec/core_64.c      | 150 ++++++++++++++++++++++++++++++
 arch/powerpc/kexec/file_load_64.c | 148 -----------------------------
 3 files changed, 154 insertions(+), 148 deletions(-)
arch/powerpc/include/asm/kexec.h +4 -0
index 88d0d7cf3a79..c2398140aa3b 100644
@@ -128,6 +128,10 @@ unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image);
 int setup_new_fdt_ppc64(const struct kimage *image, void *fdt,
 			unsigned long initrd_load_addr,
 			unsigned long initrd_len, const char *cmdline);
+int get_exclude_memory_ranges(struct crash_mem **mem_ranges);
+int locate_mem_hole_top_down_ppc64(struct kexec_buf *kbuf,
+				   u64 buf_min, u64 buf_max,
+				   const struct crash_mem *emem);
 #endif /* CONFIG_PPC64 */
 
 #endif /* CONFIG_KEXEC_FILE */
arch/powerpc/kexec/core_64.c +150 -0

168 lines not on this page · raw message

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

160 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

RFC PATCH 2/5 powerpc/kdump: setup kexec crash FDT

In reply to Sourabh Jain

DLPAR operation post kexec_load or kexec_file_load system call makes the kexec crash kernel FDT stale. Booting kdump kernel with stale FDT leads to kernel hang. To keep the kdump FDT updated kdump reload is performed after DLPAR operation.

The kdump reloading after each DLPAR operation can be avoided if kdump_load and kexec_file_load can use the FDT created and maintained by the kernel.

Set up a kexec crash FDT in crashkernel reserved region by allocating a memory hole in crashkernel reserved region. Subsequent patches take care of updating this FDT and using this FDT in kexec_load and kexec_file_load system calls.

A new config KEXEC_CRASH_FDT is added to include this feature at the build time.

---
 arch/powerpc/Kconfig             | 11 +++++++
 arch/powerpc/include/asm/kexec.h |  5 +++
 arch/powerpc/kexec/core_64.c     | 52 ++++++++++++++++++++++++++++++++
 3 files changed, 68 insertions(+)
arch/powerpc/Kconfig +11 -0
index ba5b66189358..b11a50851d2c 100644
@@ -634,6 +634,17 @@ config PRESERVE_FA_DUMP
 	  memory preserving kernel boot would process this crash data.
 	  Petitboot kernel is the typical usecase for this option.
 
+config KEXEC_CRASH_FDT
+	bool "Update crash kernel FDT on hotplug event"
+	depends on CRASH_DUMP && HOTPLUG_CPU
+	help
+	  This option avoids the need to reload kdump on every hotplug event.
+	  During boot, the kernel pre-allocates the space for kdump FDT in
+	  the reserved area and uses the same space to store the FDT created
+	  during kexec_load or kexec_file_load. This helps the kernel to just
+	  update the FDT with the latest hotplug event info rather than
+	  preparing and reloading all the kexec components again.
+
 config OPAL_CORE
 	bool "Export OPAL memory as /sys/firmware/opal/core"
 	depends on PPC64 && PPC_POWERNV
arch/powerpc/include/asm/kexec.h +5 -0
index c2398140aa3b..dc5b29eb2ddb 100644
@@ -119,6 +119,11 @@ int setup_purgatory(struct kimage *image, const void *slave_code,
 #ifdef CONFIG_PPC64
 struct kexec_buf;
 
+#ifdef CONFIG_KEXEC_CRASH_FDT
+extern void *kexec_crash_fdt;
+extern u32 kexec_crash_fdt_size;
+#endif /* CONFIG_KEXEC_CRASH_FDT */
+
 int load_crashdump_segments_ppc64(struct kimage *image,
 				  struct kexec_buf *kbuf);
 int setup_purgatory_ppc64(struct kimage *image, const void *slave_code,
arch/powerpc/kexec/core_64.c +52 -0

67 lines not on this page · raw message

Signature · 1 line
2.34.1
#3 lore raw

RFC PATCH 3/5 powerpc/kdump: update kexec crash FDT on CPU hot add event

In reply to Sourabh Jain

Add a hook in CPU hot add path to update the kexec crash FDT with latest CPU data.

To avoid code replication update_cpus_node function defined in kexec/file_load_64.c is exported and moved to core_64.c file so that it will be accessible to both kexec_load and kexec_file_load system call.

---
 arch/powerpc/include/asm/kexec.h             |  1 +
 arch/powerpc/kexec/core_64.c                 | 89 ++++++++++++++++++++
 arch/powerpc/kexec/file_load_64.c            | 87 -------------------
 arch/powerpc/platforms/pseries/hotplug-cpu.c |  7 ++
 4 files changed, 97 insertions(+), 87 deletions(-)
arch/powerpc/include/asm/kexec.h +1 -0
index dc5b29eb2ddb..d608c661758e 100644
@@ -137,6 +137,7 @@ int get_exclude_memory_ranges(struct crash_mem **mem_ranges);
 int locate_mem_hole_top_down_ppc64(struct kexec_buf *kbuf,
 				   u64 buf_min, u64 buf_max,
 				   const struct crash_mem *emem);
+int update_cpus_node(void *fdt);
 #endif /* CONFIG_PPC64 */
 
 #endif /* CONFIG_KEXEC_FILE */
arch/powerpc/kexec/core_64.c +89 -0

107 lines not on this page · raw message

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

93 lines not on this page · raw message

arch/powerpc/platforms/pseries/hotplug-cpu.c +7 -0
index d646c22e94ab..701a34574e0b 100644
@@ -26,6 +26,7 @@
 #include <linux/slab.h>
 #include <asm/prom.h>
 #include <asm/rtas.h>
+#include <asm/kexec.h>
 #include <asm/firmware.h>
 #include <asm/machdep.h>
 #include <asm/vdso_datapage.h>
@@ -595,6 +596,12 @@ static ssize_t dlpar_cpu_add(u32 drc_index)
 		return saved_rc;
 	}
 
+#ifdef CONFIG_KEXEC_CRASH_FDT
+	/* kdump should be aware of new CPU */
+	if (update_cpus_node(kexec_crash_fdt))
+		pr_err("unable to update kexec crash fdt\n");
+#endif
+
 	pr_debug("Successfully added CPU %pOFn, drc index: %x\n", dn,
 		 drc_index);
 	return rc;
Signature · 1 line
2.34.1
#4 lore raw

RFC PATCH 4/5 powerpc/kdump: enable kexec_file_load system call to use kexec crash FDT

In reply to Sourabh Jain

This patch enables the kexec_file_load system to utilize the pre-allocated space for kexec crash FDT during the system boot.

---
 arch/powerpc/kexec/elf_64.c       | 22 +++++++++++++++++++---
 arch/powerpc/kexec/file_load_64.c |  4 ++++
 2 files changed, 23 insertions(+), 3 deletions(-)
arch/powerpc/kexec/elf_64.c +19 -3
index eeb258002d1e..3176dea0910d 100644
@@ -116,13 +116,29 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
 	if (ret)
 		goto out_free_fdt;
 
-	fdt_pack(fdt);
+#ifdef CONFIG_KEXEC_CRASH_FDT
+	if (kexec_crash_fdt && image->type == KEXEC_TYPE_CRASH) {
+		memcpy(kexec_crash_fdt, fdt, fdt_totalsize(fdt));
+		/* retain the original total size */
+		((struct fdt_header *)(kexec_crash_fdt))->totalsize = cpu_to_fdt32(kexec_crash_fdt_size);
+	} else
+#endif
+	{
+		kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
+	}
 
 	kbuf.buffer = fdt;
-	kbuf.bufsz = kbuf.memsz = fdt_totalsize(fdt);
+
+#ifdef CONFIG_KEXEC_CRASH_FDT
+	if (kexec_crash_fdt && image->type == KEXEC_TYPE_CRASH) {
+		kbuf.bufsz = kbuf.memsz = fdt_totalsize(kexec_crash_fdt);
+	} else
+#endif
+	{
+		kbuf.bufsz = kbuf.memsz = fdt_totalsize(fdt);
+	}
 	kbuf.buf_align = PAGE_SIZE;
 	kbuf.top_down = true;
-	kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
 	ret = kexec_add_buffer(&kbuf);
 	if (ret)
 		goto out_free_fdt;
arch/powerpc/kexec/file_load_64.c +4 -0
index 02bb2adb1fe2..7a320d9e2098 100644
@@ -906,6 +906,10 @@ int arch_kexec_locate_mem_hole(struct kexec_buf *kbuf)
 	u64 buf_min, buf_max;
 	int ret;
 
+	/* kbuf.mem is already pointing to validate memory hole */
+	if (kbuf->mem != KEXEC_BUF_MEM_UNKNOWN)
+		return 0;
+
 	/* Look up the exclude ranges list while locating the memory hole */
 	emem = &(kbuf->image->arch.exclude_ranges);
 	if (!(*emem) || ((*emem)->nr_ranges == 0)) {
Signature · 1 line
2.34.1
#5 lore raw

RFC PATCH 5/5 powerpc/kdump: export kexec crash FDT details via sysfs

In reply to Sourabh Jain

Export kexec crash FDT address and size to /sys/kernel/kexec_crash_fdt and /sys/kernel/kexec_crash_fdt_size files to enabled kexec tool to utilize pre-allocated space kdump FDT.

---
 arch/powerpc/kexec/core_64.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
arch/powerpc/kexec/core_64.c +27 -0
index 57afceee53a6..9bc9973ab3d3 100644
@@ -677,6 +677,23 @@ static u32 get_kexec_crash_fdt_size(void)
 	return 1024*1024;
 }
 
+static ssize_t kexec_crash_fdt_show(struct kobject *kobj,
+				    struct kobj_attribute *attr, char *buf)
+{
+	return sprintf(buf, "%lx\n", __pa(kexec_crash_fdt));
+}
+static struct kobj_attribute kexec_crash_fdt_attr = __ATTR_RO(kexec_crash_fdt);
+
+static ssize_t kexec_crash_fdt_size_show(struct kobject *kobj,
+					 struct kobj_attribute *attr,
+					 char *buf)
+{
+	return sprintf(buf, "%d\n", kexec_crash_fdt_size);
+}
+static struct kobj_attribute kexec_crash_fdt_size_attr = \
+			__ATTR_RO(kexec_crash_fdt_size);
+
+
 /* Setup the memory hole for kdump fdt in reserved region below RMA.
  */
 static int __init setup_kexec_crash_fdt(void)
@@ -707,6 +724,16 @@ static int __init setup_kexec_crash_fdt(void)
 	kexec_crash_fdt = __va(kbuf.mem);
 	kexec_crash_fdt_size = kbuf.memsz;
 
+	if (sysfs_create_file(kernel_kobj, &kexec_crash_fdt_attr.attr)) {
+		pr_err("unable to create kdump_fdt sysfs file\n.");
+		return -1;
+	}
+
+	if (sysfs_create_file(kernel_kobj, &kexec_crash_fdt_size_attr.attr)) {
+		pr_err("unable to cerate kexec_crash_fdt_size sysfs file.\n");
+		return -1;
+	}
+
 out:
 	return ret;
 }
Signature · 1 line
2.34.1
#6 lore raw

cover Avoid kdump service reload on CPU hotplug events

In reply to Sourabh Jain

Hi,

Quoted 6 lines · Sourabh Jain

On hotplug event (CPU/memory) the CPU information prepared for the kdump kernel becomes stale unless it is prepared again. To keep the CPU information up-to-date a kdump service reload is triggered via the udev rule.

The above approach has two downsides:

Quoted 8 lines

1) The udev rules are prone to races if hotplug event is frequent. The time is taken to settle down all the kdump service reload requested is significant when multiple CPU/memory hotplug is performed at the same time. This creates a window where kernel crash might not lead to successfully dump collection.

2) Unnecessary CPU cycles are consumed to reload all the kdump components including initrd, vmlinux, FDT, etc. whereas only one component needs to update that is FDT.

I roughly went through this sereis, while haven't read the code carefully. Seems the issue and the approach are similar to what below patchset is doing. Do you notice below patchset from Oracle engineer? And is there stuff the ppc code can be rebased on and reused?

[PATCH v4 00/10] crash: Kernel handling of CPU and memory hot un/plug
https://lore.kernel.org/all/20220209195706.51522-1-eric.devolder at oracle.com/T/#u

Quoted 243 lines

How this patch series solve the above issue?
--------------------------------------------
As mentioned above the only kexec segment that gets updated during the kdump service reload (due to hotplug event) is FDT. So, instead of re-creating the FDT on every hotplug event, it is just created once and updated on every hotplug event. This FDT is referred as kexec crash FDT.

How kexec crash FDT is managed?
-------------------------------
During the kernel boot, a hole is allocated for kexec crash FDT in the kdump reserved region. On kdump service start a fresh copy of kdump FDT (created by kexec tool or kernel-based on which system call is used) is copied to the pre-allocated hole for kexec crash FDT. Once a kexec crash FDT is loaded all the subsequent updates needed due to CPU hot-add event can directly be done to kexec crash FDT without reloading all the kexec segment again. A hook is added on the CPU hot-add path to update the kexec crash FDT.

How kexec crash FDT is accessed in kexec_load and kexec_file_load system call?
------------------------------------------------------------------------------
Since kexec_file_load creates all kexec segments are prepared in the kernel, it can easily access the kexec crash FDT with help of two global variables, that holds the start address and the size of the kexec crash FDT.

In kexec_load system call, the kexec segments are prepared by the kexec tool in userspace. The start address and the size of kexec crash fdt is provided to userspace via two sysfs files /sys/kernel/kexec_crash_fdt and /sys/kernel/kexec_crash_fdt_size.

A couple of minor changes are required to realise the benefit of the patch series:

- disalble the udev rule:

comment out the below line in kdump udev rule file:
RHEL: /usr/lib/udev/rules.d/98-kexec.rules
# SUBSYSTEM=="cpu", ACTION=="online", GOTO="kdump_reload_cpu"

- kexec tool needs to be updated with patch for kexec_load system call to work (not needed if -s option is used during kexec panic load):

---
From 37aa38713c163b31d9c6e80ddc059424c9fcd66d Mon Sep 17 00:00:00 2001
From: Sourabh Jain <[email protected]>
Date: Mon, 22 Nov 2021 14:12:52 +0530
Subject: [PATCH] kexec/ppc64: use pre-allocated memory hole for kexec crash
FDT

Enabled kexec to use the per allocated memory hole for kexec crash FDT which is exported via /sys/kernel/kexec_crash_fdt and /sys/kernel/kexec_crash_fdt_size sysfs files. Using this pre-allocated memory hole for kdump fdt will allow the kernel to keep the kdump fdt up-to-date with the latest CPU information.

In case a pre-allocated memory hole is used for kdump fdt, the kdump fdt the segment is not included in SHA calculation because kdump fdt will be modified by the kernel.

To maintain the backward compatibility, we fall back to the old option of finding hole for kdump fdt segment if the pre-allocated buffer is not provided by the kernel.

---
 kexec/arch/ppc64/kexec-elf-ppc64.c | 11 +++++--
 kexec/arch/ppc64/kexec-ppc64.c     | 49 ++++++++++++++++++++++++++++++
 kexec/kexec.c                      |  9 ++++++
 kexec/kexec.h                      |  4 +++
 4 files changed, 71 insertions(+), 2 deletions(-)
kexec/arch/ppc64/kexec-elf-ppc64.c +9 -2
index 695b8b0..8e66ef0 100644
@@ -329,8 +329,15 @@ int elf_ppc64_load(int argc, char **argv, const char *buf, off_t len,
 	if (result < 0)
 		return result;
 
-	my_dt_offset = add_buffer(info, seg_buf, seg_size, seg_size,
-				0, 0, max_addr, -1);
+        if (kexec_crash_fdt) {
+                my_dt_offset = kexec_crash_fdt;
+                add_segment_phys_virt(info, seg_buf, seg_size,
+				      my_dt_offset, kexec_crash_fdt_size, 0);
+        }
+        else {
+                my_dt_offset = add_buffer(info, seg_buf, seg_size, seg_size,
+                                          0, 0, max_addr, -1);
+        }
 
 #ifdef NEED_RESERVE_DTB
 	/* patch reserve map address for flattened device-tree
kexec/arch/ppc64/kexec-ppc64.c +49 -0
index 5b17740..d4385bd 100644
@@ -24,6 +24,7 @@
 #include <errno.h>
 #include <stdint.h>
 #include <string.h>
+#include <fcntl.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <dirent.h>
@@ -373,6 +374,52 @@ void scan_reserved_ranges(unsigned long kexec_flags, int *range_index)
 	*range_index = i;
 }
 
+void get_kexec_crash_fdt_details(unsigned long kexec_flags)
+{
+	int fd, len;
+	char buf[MAXBYTES] = { 0 };
+
+	const char * const kexec_fdt_sysfs = "/sys/kernel/kexec_crash_fdt";
+	const char * const kexec_fdt_size_sysfs = "/sys/kernel/kexec_crash_fdt_size";
+
+        fd = open(kexec_fdt_sysfs, O_RDONLY);
+        if (fd < 0)
+                return;
+
+        len = read(fd, buf, MAXBYTES);
+        if (len < 0)
+                goto err_out;
+
+        kexec_crash_fdt = strtoul(buf, NULL, 16);
+
+	fd = open(kexec_fdt_size_sysfs, O_RDONLY);
+	if (fd < 0)
+		goto err_out;
+
+	len = read(fd, buf, MAXBYTES);
+	if (len < 0)
+		goto err_out;
+
+	kexec_crash_fdt_size = strtoul(buf, NULL, 10);
+
+        exclude_range[nr_exclude_ranges].start = kexec_crash_fdt;
+        exclude_range[nr_exclude_ranges].end = kexec_crash_fdt + \
+					       kexec_crash_fdt_size;
+        nr_exclude_ranges++;
+
+        if (nr_exclude_ranges >= max_memory_ranges)
+                realloc_memory_ranges();
+
+	goto out;
+
+err_out:
+	kexec_crash_fdt = kexec_fdt_size = 0;
+
+out:
+        close (fd);
+        return;
+}
+
 /* Return 0 if fname/value valid, -1 otherwise */
 int get_devtree_value(const char *fname, unsigned long long *value)
 {
@@ -804,6 +851,8 @@ int setup_memory_ranges(unsigned long kexec_flags)
 		goto out;
 	if (get_devtree_details(kexec_flags))
 		goto out;
+	if (kexec_flags & KEXEC_ON_CRASH)
+		get_kexec_crash_fdt_details(kexec_flags);
 
 	for (i = 0; i < nr_exclude_ranges; i++) {
 		/* If first exclude range does not start with 0, include the
kexec/kexec.c +9 -0
index f63b36b..89283f7 100644
@@ -62,6 +62,10 @@ static unsigned long kexec_flags = 0;
 /* Flags for kexec file (fd) based syscall */
 static unsigned long kexec_file_flags = 0;
 int kexec_debug = 0;
+#if defined(__powerpc__) || defined(__powerpc64__)
+uint64_t kexec_crash_fdt;
+uint32_t kexec_cras_fdt_size;
+#endif
 
 void dbgprint_mem_range(const char *prefix, struct memory_range *mr, int nr_mr)
 {
@@ -672,6 +676,11 @@ static void update_purgatory(struct kexec_info *info)
 		if (info->segment[i].mem == (void *)info->rhdr.rel_addr) {
 			continue;
 		}
+
+#if defined(__powerpc__) || defined(__powerpc64__)
+		if (kexec_crash_fdt && (unsigned long)info->segment[i].mem == kexec_crash_fdt)
+			continue;
+#endif
 		sha256_update(&ctx, info->segment[i].buf,
 			      info->segment[i].bufsz);
 		nullsz = info->segment[i].memsz - info->segment[i].bufsz;
kexec/kexec.h +4 -0
index 595dd68..48e8b9f 100644
@@ -205,6 +205,10 @@ struct file_type {
 
 extern struct file_type file_type[];
 extern int file_types;
+#if defined(__powerpc__) || defined(__powerpc64__)
+extern uint64_t fdt;
+extern uint32_t fdt_size;
+#endif
 
 #define OPT_HELP		'h'
 #define OPT_VERSION		'v'
Signature · 28 lines
2.34.1
---


Sourabh Jain (5):
  powerpc/kdump: export functions from file_load_64.c
  powerpc/kdump: setup kexec crash FDT
  powerpc/kdump: update kexec crash FDT on CPU hot add event
  powerpc/kdump: enable kexec_file_load system call to use kexec crash
    FDT
  powerpc/kdump: export kexec crash FDT details via sysfs

 arch/powerpc/Kconfig                         |  11 +
 arch/powerpc/include/asm/kexec.h             |  10 +
 arch/powerpc/kexec/core_64.c                 | 318 +++++++++++++++++++
 arch/powerpc/kexec/elf_64.c                  |  22 +-
 arch/powerpc/kexec/file_load_64.c            | 239 +-------------
 arch/powerpc/platforms/pseries/hotplug-cpu.c |   7 +
 6 files changed, 369 insertions(+), 238 deletions(-)

-- 
2.34.1


_______________________________________________
kexec mailing list
kexec at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
#7 lore raw

cover Avoid kdump service reload on CPU hotplug events

Hello Baoquan,

Quoted 17 lines

Hi,

Quoted 6 lines · Sourabh Jain

On hotplug event (CPU/memory) the CPU information prepared for the kdump kernel becomes stale unless it is prepared again. To keep the CPU information up-to-date a kdump service reload is triggered via the udev rule.

The above approach has two downsides:

Quoted 8 lines

1) The udev rules are prone to races if hotplug event is frequent. The time is taken to settle down all the kdump service reload requested is significant when multiple CPU/memory hotplug is performed at the same time. This creates a window where kernel crash might not lead to successfully dump collection.

2) Unnecessary CPU cycles are consumed to reload all the kdump components including initrd, vmlinux, FDT, etc. whereas only one component needs to update that is FDT.

Quoted 7 lines

I roughly went through this sereis, while haven't read the code carefully. Seems the issue and the approach are similar to what below patchset is doing. Do you notice below patchset from Oracle engineer? And is there stuff the ppc code can be rebased on and reused?

[PATCH v4 00/10] crash: Kernel handling of CPU and memory hot un/plug
https://lore.kernel.org/all/20220209195706.51522-1-eric.devolder at oracle.com/T/#u

Thanks for the suggestion. I have seen earlier versions of this patch series but since it did not have support for kexec_load system call we tried implementing
something from scratch.

Since Eric's added support for kexec_load and has a generic handler for CPU and
memory hotplug let me see if I can rebase my PowerPC changes on top of his patches.
The major difference across the distro is that on PowerPC we need to update FDT instead
of elfcorehdr on hotplug event.

Thanks,
Sourabh Jain