Skip to contentSkip to conversation

kexec_load: Use new kexec flag for hotplug support

PATCH Superseded Sourabh Jain 3 participants 12 messages May 22, 2024 – Jun 10, 2024

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 kexec_load: Use new kexec flag for hotplug support

Kernel commit 79365026f869 (crash: add a new kexec flag for hotplug support) has introduced a new kexec flag to generalize hotplug support. The newly introduced kexec flags for hotplug allow architectures to exclude all the required kexec segments from SHA calculation so that the kernel can update them on hotplug events. This was not possible earlier with the KEXEC_UPDATE_ELFCOREHDR kexec flags since it was added only for the elfcorehdr segment.

To enable architectures to control the list of kexec segments to exclude when hotplug support is enabled, add a new architecture-specific function named arch_do_exclude_segment. During the SHA calculation, this function gets called to let the architecture decide whether a specific kexec segment should be considered for SHA calculation or not.

Given that the KEXEC_UPDATE_ELFCOREHDR is no longer required and was colliding with the KEXEC_LIVE_UPDATE update flag, it is removed.

Cc Aditya Gupta <[email protected]>
Cc Baoquan He <[email protected]>
Cc Coiby Xu <[email protected]>
Cc Hari Bathini <[email protected]>
Cc Mahesh Salgaonkar <[email protected]>
---
 kexec/arch/arm/kexec-arm.c             |  5 +++++
 kexec/arch/arm64/kexec-arm64.c         |  4 ++++
 kexec/arch/cris/kexec-cris.c           |  4 ++++
 kexec/arch/hppa/kexec-hppa.c           |  5 +++++
 kexec/arch/i386/kexec-x86.c            |  8 ++++++++
 kexec/arch/ia64/kexec-ia64.c           |  4 ++++
 kexec/arch/loongarch/kexec-loongarch.c |  5 +++++
 kexec/arch/m68k/kexec-m68k.c           |  5 +++++
 kexec/arch/mips/kexec-mips.c           |  4 ++++
 kexec/arch/ppc/kexec-ppc.c             |  4 ++++
 kexec/arch/ppc64/kexec-ppc64.c         |  5 +++++
 kexec/arch/s390/kexec-s390.c           |  5 +++++
 kexec/arch/sh/kexec-sh.c               |  5 +++++
 kexec/arch/x86_64/kexec-x86_64.c       |  5 +++++
 kexec/kexec-syscall.h                  |  2 +-
 kexec/kexec.c                          | 14 ++++++++------
 kexec/kexec.h                          |  2 ++
 17 files changed, 79 insertions(+), 7 deletions(-)
kexec/arch/arm/kexec-arm.c +5 -0
index 49f35b1..34531f9 100644
@@ -148,3 +148,8 @@ int have_sysfs_fdt(void)
 {
 	return !access(SYSFS_FDT, F_OK);
 }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/arm64/kexec-arm64.c +4 -0
index 4a67b0d..9d052b0 100644
@@ -1363,3 +1363,7 @@ void arch_reuse_initrd(void)
 void arch_update_purgatory(struct kexec_info *UNUSED(info))
 {
 }
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/cris/kexec-cris.c +4 -0
index 3b69709..7f09121 100644
@@ -109,3 +109,7 @@ unsigned long add_buffer(struct kexec_info *info, const void *buf,
                                     buf_min, buf_max, buf_end, 1);
 }
 
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/hppa/kexec-hppa.c +5 -0
index 77c9739..a64dc3d 100644
@@ -146,3 +146,8 @@ unsigned long virt_to_phys(unsigned long addr)
 {
 	return addr - phys_offset;
 }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/i386/kexec-x86.c +8 -0
index 444cb69..b4947a0 100644
@@ -208,3 +208,11 @@ void arch_update_purgatory(struct kexec_info *info)
 	elf_rel_set_symbol(&info->rhdr, "panic_kernel",
 		&panic_kernel, sizeof(panic_kernel));
 }
+
+int arch_do_exclude_segment(struct kexec_segment *seg_ptr, struct kexec_info *info)
+{
+	if (info->elfcorehdr == (unsigned long) seg_ptr->mem)
+		return 1;
+
+	return 0;
+}
kexec/arch/ia64/kexec-ia64.c +4 -0
index 418d997..8d9c1f3 100644
@@ -245,3 +245,7 @@ void arch_update_purgatory(struct kexec_info *UNUSED(info))
 {
 }
 
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/loongarch/kexec-loongarch.c +5 -0
index 32a42d2..9a50ff6 100644
@@ -378,3 +378,8 @@ unsigned long add_buffer(struct kexec_info *info, const void *buf,
 	return add_buffer_phys_virt(info, buf, bufsz, memsz, buf_align,
 				    buf_min, buf_max, buf_end, 1);
 }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/m68k/kexec-m68k.c +5 -0
index cb54927..0c7dbaf 100644
@@ -108,3 +108,8 @@ void add_segment(struct kexec_info *info, const void *buf, size_t bufsz,
 {
 	add_segment_phys_virt(info, buf, bufsz, base, memsz, 1);
 }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/mips/kexec-mips.c +4 -0
index d8cbea8..94224ee 100644
@@ -189,3 +189,7 @@ unsigned long add_buffer(struct kexec_info *info, const void *buf,
 				    buf_min, buf_max, buf_end, 1);
 }
 
+int arch_do_exclude_segment(const void *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/ppc/kexec-ppc.c +4 -0
index 03bec36..c8af870 100644
@@ -966,3 +966,7 @@ void arch_update_purgatory(struct kexec_info *UNUSED(info))
 {
 }
 
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/ppc64/kexec-ppc64.c +5 -0
index bd5274c..fb27b6b 100644
@@ -967,3 +967,8 @@ int arch_compat_trampoline(struct kexec_info *UNUSED(info))
 void arch_update_purgatory(struct kexec_info *UNUSED(info))
 {
 }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/s390/kexec-s390.c +5 -0
index 33ba6b9..0561ee7 100644
@@ -267,3 +267,8 @@ int get_crash_kernel_load_range(uint64_t *start, uint64_t *end)
 {
 	return parse_iomem_single("Crash kernel\n", start, end);
 }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/sh/kexec-sh.c +5 -0
index ce341c8..f84c40c 100644
@@ -257,3 +257,8 @@ unsigned long add_buffer(struct kexec_info *info, const void *buf,
 	return add_buffer_phys_virt(info, buf, bufsz, memsz, buf_align,
 				    buf_min, buf_max, buf_end, 1);
 }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/x86_64/kexec-x86_64.c +5 -0
index ffd84f0..42af90a 100644
@@ -188,3 +188,8 @@ void arch_update_purgatory(struct kexec_info *info)
 	elf_rel_set_symbol(&info->rhdr, "panic_kernel",
 				&panic_kernel, sizeof(panic_kernel));
 }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/kexec-syscall.h +1 -1
index 73e5254..4675c46 100644
@@ -112,7 +112,7 @@ static inline long kexec_file_load(int kernel_fd, int initrd_fd,
 
 #define KEXEC_ON_CRASH		0x00000001
 #define KEXEC_PRESERVE_CONTEXT	0x00000002
-#define KEXEC_UPDATE_ELFCOREHDR	0x00000004
+#define KEXEC_CRASH_HOTPLUG_SUPPORT	0x00000008
 #define KEXEC_ARCH_MASK		0xffff0000
 
 /* Flags for kexec file based system call */
kexec/kexec.c +8 -6
index 222f79e..034cea6 100644
@@ -701,10 +701,13 @@ static void update_purgatory(struct kexec_info *info)
 			continue;
 		}
 
-		/* Don't include elfcorehdr in the checksum, if hotplug
-		 * support enabled.
+		/*
+		 * Let architecture decide which segments to exclude from checksum
+		 * if hotplug support is enabled.
 		 */
-		if (do_hotplug && (info->segment[i].mem == (void *)info->elfcorehdr)) {
+		if (do_hotplug && arch_do_exclude_segment(&info->segment[i], info)) {
+			dbgprintf("Skipping segment mem: 0x%lx from SHA calculation\n",
+				  (unsigned long)info->segment[i].mem);
 			continue;
 		}
 
@@ -1651,7 +1654,6 @@ int main(int argc, char *argv[])
 		die("--load-live-update can only be used with xen\n");
 	}
 
-	/* NOTE: Xen KEXEC_LIVE_UPDATE and KEXEC_UPDATE_ELFCOREHDR collide */
 	if (do_hotplug) {
 		const char *ces = "/sys/kernel/crash_elfcorehdr_size";
 		char *buf, *endptr = NULL;
@@ -1665,8 +1667,8 @@ int main(int argc, char *argv[])
 		if (!elfcorehdrsz || (endptr && *endptr != '\0'))
 			die("Path %s does not exist, the kernel needs CONFIG_CRASH_HOTPLUG\n", ces);
 		dbgprintf("ELFCOREHDR_SIZE %lu\n", elfcorehdrsz);
-		/* Indicate to the kernel it is ok to modify the elfcorehdr */
-		kexec_flags |= KEXEC_UPDATE_ELFCOREHDR;
+		/* Indicate to the kernel it is ok to modify the relevant kexec segments */
+		kexec_flags |= KEXEC_CRASH_HOTPLUG_SUPPORT;
 	}
 
 	fileind = optind;
kexec/kexec.h +2 -0
index 1004aff..2d758c9 100644
@@ -307,6 +307,8 @@ extern int do_hotplug;
 #define BOOTLOADER_VERSION PACKAGE_VERSION
 
 void arch_usage(void);
+/* Return non-zero if segment needs to be excluded from SHA calculation, else 0. */
+int arch_do_exclude_segment(struct kexec_segment *seg_ptr, struct kexec_info *info);
 int arch_process_options(int argc, char **argv);
 int arch_compat_trampoline(struct kexec_info *info);
 void arch_update_purgatory(struct kexec_info *info);
Signature · 7 lines
2.44.0


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

PATCH 2/3 powerpc/kexec_load: add hotplug support

Kernel commits b741092d5976 ("powerpc/crash: add crash CPU hotplug support") and 849599b702ef ("powerpc/crash: add crash memory hotplug support") added crash CPU/Memory hotplug support on PowerPC. This patch extends that support for the kexec_load syscall.

During CPU/Memory hotplug events on PowerPC, two kexec segments, elfcorehdr, and FDT, get updated by the kernel. To ensure the kernel can safely update these two kexec segments for the kdump image loaded using the kexec_load system call, the following changes are made:

1. Extra size is allocated for both elfcorehdr and FDT to accommodate additional resources in the future. For the elfcorehdr, the size hint is taken from /sys/kernel/crash_elfcorehdr_size sysfs, while for FDT, extra size is allocated to hold possible CPU nodes.

2. Both elfcorehdr and FDT are skipped from SHA calculation.

Cc Aditya Gupta <[email protected]>
Cc Baoquan He <[email protected]>
Cc Coiby Xu <[email protected]>
Cc Hari Bathini <[email protected]>
Cc Mahesh Salgaonkar <[email protected]>
---
 kexec/arch/ppc64/crashdump-ppc64.c  |  16 ++-
 kexec/arch/ppc64/fdt.c              | 200 +++++++++++++++++++++++++++-
 kexec/arch/ppc64/include/arch/fdt.h |   2 +-
 kexec/arch/ppc64/kexec-elf-ppc64.c  |   2 +-
 kexec/arch/ppc64/kexec-ppc64.c      |  12 +-
 5 files changed, 225 insertions(+), 7 deletions(-)
kexec/arch/ppc64/crashdump-ppc64.c +13 -3
index 6d47898..c14b593 100644
@@ -476,7 +476,7 @@ int load_crashdump_segments(struct kexec_info *info, char* mod_cmdline,
 				uint64_t max_addr, unsigned long min_base)
 {
 	void *tmp;
-	unsigned long sz;
+	unsigned long sz, memsz;
 	uint64_t elfcorehdr;
 	int nr_ranges, align = 1024, i;
 	unsigned long long end;
@@ -531,8 +531,18 @@ int load_crashdump_segments(struct kexec_info *info, char* mod_cmdline,
 		}
 	}
 
-	elfcorehdr = add_buffer(info, tmp, sz, sz, align, min_base,
-				max_addr, 1);
+	memsz = sz;
+	/* To support --hotplug, replace the calculated minimum size with the
+	 * value from /sys/kernel/crash_elfcorehdr_size and align it correctly.
+	 */
+	if (do_hotplug) {
+		if (elfcorehdrsz > sz)
+			memsz = _ALIGN(elfcorehdrsz, align);
+	}
+
+	/* Record the location of the elfcorehdr for hotplug handling */
+	info->elfcorehdr = elfcorehdr = add_buffer(info, tmp, sz, memsz, align,
+						   min_base, max_addr, 1);
 	reserve(elfcorehdr, sz);
 	/* modify and store the cmdline in a global array. This is later
 	 * read by flatten_device_tree and modified if required
kexec/arch/ppc64/fdt.c +199 -1

222 lines not on this page · raw message

kexec/arch/ppc64/include/arch/fdt.h +1 -1
index b19f185..5f340b0 100644
@@ -3,6 +3,6 @@
 
 #include <sys/types.h>
 
-int fixup_dt(char **fdt, off_t *size);
+int fixup_dt(char **fdt, off_t *size, unsigned long kexec_flags);
 
 #endif
kexec/arch/ppc64/kexec-elf-ppc64.c +1 -1
index bdcfd20..858c994 100644
@@ -345,7 +345,7 @@ int elf_ppc64_load(int argc, char **argv, const char *buf, off_t len,
 		create_flatten_tree(&seg_buf, &seg_size, cmdline);
 	}
 
-	result = fixup_dt(&seg_buf, &seg_size);
+	result = fixup_dt(&seg_buf, &seg_size, info->kexec_flags);
 	if (result < 0)
 		return result;
 
kexec/arch/ppc64/kexec-ppc64.c +11 -1
index fb27b6b..f27d76b 100644
@@ -24,6 +24,7 @@
 #include <errno.h>
 #include <stdint.h>
 #include <string.h>
+#include <libfdt.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <dirent.h>
@@ -968,7 +969,16 @@ void arch_update_purgatory(struct kexec_info *UNUSED(info))
 {
 }
 
-int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+int arch_do_exclude_segment(struct kexec_segment *seg_ptr, struct kexec_info *info)
 {
+	if (!seg_ptr)
+		return 0;
+
+	if (info->elfcorehdr == (unsigned long) seg_ptr->mem)
+		return 1;
+
+	if (seg_ptr->buf && fdt_magic(seg_ptr->buf) == FDT_MAGIC)
+		return 1;
+
 	return 0;
 }
Signature · 7 lines
2.44.0


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

Re: [PATCH 2/3] powerpc/kexec_load: add hotplug support

Quoted 242 lines · Sourabh Jain

Kernel commits b741092d5976 ("powerpc/crash: add crash CPU hotplug support") and 849599b702ef ("powerpc/crash: add crash memory hotplug support") added crash CPU/Memory hotplug support on PowerPC. This patch extends that support for the kexec_load syscall.

During CPU/Memory hotplug events on PowerPC, two kexec segments, elfcorehdr, and FDT, get updated by the kernel. To ensure the kernel can safely update these two kexec segments for the kdump image loaded using the kexec_load system call, the following changes are made:

1. Extra size is allocated for both elfcorehdr and FDT to accommodate additional resources in the future. For the elfcorehdr, the size hint is taken from /sys/kernel/crash_elfcorehdr_size sysfs, while for FDT, extra size is allocated to hold possible CPU nodes.

2. Both elfcorehdr and FDT are skipped from SHA calculation.

Cc Aditya Gupta <[email protected]>
Cc Baoquan He <[email protected]>
Cc Coiby Xu <[email protected]>
Cc Hari Bathini <[email protected]>
Cc Mahesh Salgaonkar <[email protected]>
---
  kexec/arch/ppc64/crashdump-ppc64.c  |  16 ++-
  kexec/arch/ppc64/fdt.c              | 200 +++++++++++++++++++++++++++-
  kexec/arch/ppc64/include/arch/fdt.h |   2 +-
  kexec/arch/ppc64/kexec-elf-ppc64.c  |   2 +-
  kexec/arch/ppc64/kexec-ppc64.c      |  12 +-
  5 files changed, 225 insertions(+), 7 deletions(-)
kexec/arch/ppc64/crashdump-ppc64.c +13 -3
index 6d47898..c14b593 100644
@@ -476,7 +476,7 @@ int load_crashdump_segments(struct kexec_info *info, char* mod_cmdline,
  				uint64_t max_addr, unsigned long min_base)
  {
  	void *tmp;
-	unsigned long sz;
+	unsigned long sz, memsz;
  	uint64_t elfcorehdr;
  	int nr_ranges, align = 1024, i;
  	unsigned long long end;
@@ -531,8 +531,18 @@ int load_crashdump_segments(struct kexec_info *info, char* mod_cmdline,
  		}
  	}
 
-	elfcorehdr = add_buffer(info, tmp, sz, sz, align, min_base,
-				max_addr, 1);
+	memsz = sz;
+	/* To support --hotplug, replace the calculated minimum size with the
+	 * value from /sys/kernel/crash_elfcorehdr_size and align it correctly.
+	 */
+	if (do_hotplug) {
+		if (elfcorehdrsz > sz)
+			memsz = _ALIGN(elfcorehdrsz, align);
+	}
+
+	/* Record the location of the elfcorehdr for hotplug handling */
+	info->elfcorehdr = elfcorehdr = add_buffer(info, tmp, sz, memsz, align,
+						   min_base, max_addr, 1);
  	reserve(elfcorehdr, sz);
  	/* modify and store the cmdline in a global array. This is later
  	 * read by flatten_device_tree and modified if required
kexec/arch/ppc64/fdt.c +162 -0
index 8bc6d2d..10abc29 100644
@@ -17,6 +17,13 @@
  #include <libfdt.h>
  #include <stdio.h>
  #include <stdlib.h>
+#include <limits.h>
+#include <stdbool.h>
+#include <dirent.h>
+#include <sys/stat.h>
+
+#include "../../kexec.h"
+#include "../../kexec-syscall.h"
 
  /*
   * Let the kernel know it booted from kexec, as some things (e.g.
@@ -46,17 +53,208 @@ static int fixup_kexec_prop(void *fdt)
  	return 0;
  }
 
+static inline bool is_dot_dir(char * d_path)
+{
+	return d_path[0] == '.';
+}
+
+/*
+ * Returns size of files including file name size under the given
+ * @cpu_node_path.
+ */
+static unsigned int get_cpu_node_size(char *cpu_node_path)
+{
+	DIR *d;
+	struct dirent *de;
+	struct stat statbuf;
+	unsigned int cpu_node_size = 0;
+	char cpu_prop_path[2 * PATH_MAX];
+
+	d = opendir(cpu_node_path);
+	if (!d)
+		return 0;
+
+	while ((de = readdir(d)) != NULL) {
+		if (de->d_type != DT_REG)
+			continue;
+
+		memset(cpu_prop_path, '\0', PATH_MAX);
+		snprintf(cpu_prop_path, 2 * PATH_MAX, "%s/%s", cpu_node_path, de->d_name);
+
+		if (stat(cpu_prop_path, &statbuf))
+			continue;
+
+		cpu_node_size += statbuf.st_size;
+		cpu_node_size += strlen(de->d_name);
+	}
+
+	return cpu_node_size;
+}
+
+/*
+ * Checks if the node specified by the given @path represents a CPU node.
+ *
+ * Returns true if the @path has a "device_type" file containing "cpu";
+ * otherwise, returns false.
+ */
+static bool is_cpu_node(char *path)
+{
+	FILE *file;
+	bool ret = false;
+	char device_type[4];
+
+	file = fopen(path, "r");
+	if (!file)
+		return false;
+
+	memset(device_type, '\0', 4);
+	if (fread(device_type, 1, 3, file) < 3)
+		goto out;
+
+	if (strcmp(device_type, "cpu"))
+		goto out;
+
+	ret = true;
+
+out:
+	fclose(file);
+	return ret;
+}
+
+static unsigned int get_threads_per_cpu(char *path)
+{
+	struct stat statbuf;
+	if (stat(path, &statbuf))
+		return 0;
+
+	return statbuf.st_size / 4;
+}
+
+/*
+ * Finds the following CPU attributes:
+ *
+ * cpus_in_system: Currently available CPU nodes present under
+ *                 /proc/device-tree/cpus.
+ * threads_per_cpu: Number of threads per CPU, based on the device tree entry
+ *                  /proc/device-tree/cpus/<cpu_node>/ibm,ppc-interrupt-server#s.
+ * cpu_node_size: Size of files including file name size under a CPU node.
+ *
+ * Returns 0 on success, else -1.
+ */
+static unsigned int get_cpu_info(int *_cpus_in_system, int *_threads_per_cpu,
+				 int *_cpu_node_size)
+{
+	DIR *d;
+	struct dirent *de;
+	int first_cpu = 1;
+	char path[PATH_MAX];
+	char *cpus_node_path = "/proc/device-tree/cpus";
+	int cpus_in_system = 0, threads_per_cpu = 0, cpu_node_size = 0;
+
+	d = opendir(cpus_node_path);
+	if (!d)
+		return -1;
+
+	while ((de = readdir(d)) != NULL) {
+		if ((de->d_type != DT_DIR) || is_dot_dir(de->d_name))
+			continue;
+
+		memset(path, '\0', PATH_MAX);
+		snprintf(path, PATH_MAX, "%s/%s/%s", cpus_node_path,
+			 de->d_name, "device_type");
+
+		/* Skip nodes with device_type != "cpu" */
+		if (!is_cpu_node(path))
+			continue;
+
+		/*
+		 * Found the first node under /proc/device-tree/cpus with
+		 * device_type == "cpu"
+		 */
+		if (first_cpu) {
+			memset(path, '\0', PATH_MAX);
+			snprintf(path, PATH_MAX, "%s/%s", cpus_node_path, de->d_name);
+			cpu_node_size = get_cpu_node_size(path);
+
+			memset(path, '\0', PATH_MAX);
+			snprintf(path, PATH_MAX, "%s/%s/%s", cpus_node_path,
+				 de->d_name, "ibm,ppc-interrupt-server#s");
+			threads_per_cpu = get_threads_per_cpu(path);
+
+			first_cpu = 0;
+		}
+
+		cpus_in_system++;
+	}
+
+	closedir(d);
+
+	dbgprintf("cpus_in_system: %d, threads_per_cpus: %d, cpu_node_size: %d\n",
+		  cpus_in_system, threads_per_cpu, cpu_node_size);
+
+	if (!(cpus_in_system && threads_per_cpu && cpu_node_size))
+		return -1;
+
+	*_cpus_in_system = cpus_in_system;
+	*_threads_per_cpu = threads_per_cpu;
+	*_cpu_node_size = cpu_node_size;
+
+	return 0;
+}
+
+/*
+ * Calculates the extra size needed for the flattened device tree (FDT) based
+ * on the difference between the possible number of CPU nodes and the number
+ * of CPU nodes present under /proc/device-tree/cpus.
+ */
+static unsigned int kdump_fdt_extra_size(void)

kexec/arch/ppc64/fdt.c static int fixup_kexec_prop(void *fdt) · line 220

Quoted 10 lines
kexec/arch/ppc64/fdt.c +10 -0
+{
+	unsigned int extra_size = 0;
+	int cpus_in_system = 0, threads_per_cpu = 0, cpu_node_size = 0;
+	int possible_cpus;
+
+	/* ALL possible CPUs are present in FDT so no extra size required */
+	if (sysconf(_SC_NPROCESSORS_ONLN) == sysconf(_SC_NPROCESSORS_CONF))
+		return 0;
+
+	if (get_cpu_info(&cpus_in_system, &threads_per_cpu, &cpu_node_size)) {

Is (sysconf(_SC_NPROCESSORS_ONLN) / threads_per_cpu) not the same as 'cpus_in_system'? If they are same, should be able to get cpu_node_size & threads_per_cpu by examining a single core instead of going through all cores on the system??

Quoted 79 lines
kexec/arch/ppc64/fdt.c +27 -1
+		die("Failed to get cpu info\n");
+	}
+
+	/*
+	 * Maximum number of CPU nodes with device_type = "cpu" possible under
+	 * /proc/device-tree/cpus/
+	 */
+	possible_cpus = sysconf(_SC_NPROCESSORS_CONF) / threads_per_cpu;
+
+	if (cpus_in_system > possible_cpus)
+		die("Possible CPU nodes can't be less than active CPU nodes\n");
+
+
+	extra_size = (possible_cpus - cpus_in_system) * cpu_node_size;
+	dbgprintf("kdump fdt extra size: %u\n", extra_size);
+
+	return extra_size;
+}
 
  /*
   * For now, assume that the added content fits in the file.
   * This should be the case when flattening from /proc/device-tree,
   * and when passing in a dtb, dtc can be told to add padding.
   */
-int fixup_dt(char **fdt, off_t *size)
+int fixup_dt(char **fdt, off_t *size, unsigned long kexec_flags)
  {
  	int ret;
 
  	*size += 4096;
+
+	/* To support --hotplug option for the kexec_load syscall, consider
+	 * adding extra buffer to FDT so that the kernel can add CPU nodes
+	 * of hot-added CPUs.
+	 */
+	if (do_hotplug && (kexec_flags & KEXEC_ON_CRASH))
+		*size += kdump_fdt_extra_size();
+
  	*fdt = realloc(*fdt, *size);
  	if (!*fdt) {
  		fprintf(stderr, "%s: out of memory\n", __func__);
kexec/arch/ppc64/include/arch/fdt.h +1 -1
index b19f185..5f340b0 100644
@@ -3,6 +3,6 @@
 
  #include <sys/types.h>
 
-int fixup_dt(char **fdt, off_t *size);
+int fixup_dt(char **fdt, off_t *size, unsigned long kexec_flags);
 
  #endif
kexec/arch/ppc64/kexec-elf-ppc64.c +1 -1
index bdcfd20..858c994 100644
@@ -345,7 +345,7 @@ int elf_ppc64_load(int argc, char **argv, const char *buf, off_t len,
  		create_flatten_tree(&seg_buf, &seg_size, cmdline);
  	}
 
-	result = fixup_dt(&seg_buf, &seg_size);
+	result = fixup_dt(&seg_buf, &seg_size, info->kexec_flags);
  	if (result < 0)
  		return result;
 
kexec/arch/ppc64/kexec-ppc64.c +1 -0
index fb27b6b..f27d76b 100644
@@ -24,6 +24,7 @@
  #include <errno.h>
  #include <stdint.h>
  #include <string.h>
+#include <libfdt.h>
  #include <sys/stat.h>
  #include <sys/types.h>
  #include <dirent.h>

kexec/arch/ppc64/kexec-ppc64.c void arch_update_purgatory(struct kexec_info *UNUSED(info)) · line 975

Quoted 8 lines
kexec/arch/ppc64/kexec-ppc64.c +2 -1
@@ -968,7 +969,16 @@ void arch_update_purgatory(struct kexec_info *UNUSED(info))
  {
  }
 
-int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+int arch_do_exclude_segment(struct kexec_segment *seg_ptr, struct kexec_info *info)
  {
 
+	if (!seg_ptr)

When can this be true? If this is a possiblilty, why do we not have the same thing for i386?

- Hari

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

#3 lore raw

Re: [PATCH 2/3] powerpc/kexec_load: add hotplug support

Hello Hari,

Quoted 265 lines · Hari Bathini
Quoted 262 lines · Sourabh Jain

Kernel commits b741092d5976 ("powerpc/crash: add crash CPU hotplug support") and 849599b702ef ("powerpc/crash: add crash memory hotplug support") added crash CPU/Memory hotplug support on PowerPC. This patch extends that support for the kexec_load syscall.

During CPU/Memory hotplug events on PowerPC, two kexec segments, elfcorehdr, and FDT, get updated by the kernel. To ensure the kernel can safely update these two kexec segments for the kdump image loaded using the kexec_load system call, the following changes are made:

1. Extra size is allocated for both elfcorehdr and FDT to accommodate additional resources in the future. For the elfcorehdr, the size hint is taken from /sys/kernel/crash_elfcorehdr_size sysfs, while for FDT, extra size is allocated to hold possible CPU nodes.

2. Both elfcorehdr and FDT are skipped from SHA calculation.

Cc Aditya Gupta <[email protected]>
Cc Baoquan He <[email protected]>
Cc Coiby Xu <[email protected]>
Cc Hari Bathini <[email protected]>
Cc Mahesh Salgaonkar <[email protected]>

---
  kexec/arch/ppc64/crashdump-ppc64.c  |  16 ++- kexec/arch/ppc64/fdt.c              | 200 +++++++++++++++++++++++++++- kexec/arch/ppc64/include/arch/fdt.h |   2 +- kexec/arch/ppc64/kexec-elf-ppc64.c  |   2 +- kexec/arch/ppc64/kexec-ppc64.c      |  12 +-

  5 files changed, 225 insertions(+), 7 deletions(-)
kexec/arch/ppc64/crashdump-ppc64.c +1 -1
index 6d47898..c14b593 100644
@@ -476,7 +476,7 @@ int load_crashdump_segments(struct kexec_info 
 *info, char* mod_cmdline,
                   uint64_t max_addr, unsigned long min_base)
   {
       void *tmp;
-    unsigned long sz;
+    unsigned long sz, memsz;
       uint64_t elfcorehdr;
       int nr_ranges, align = 1024, i;

      unsigned long long end;

kexec/arch/ppc64/crashdump-ppc64.c +2 -1
@@ -531,8 +531,18 @@ int load_crashdump_segments(struct kexec_info 
 *info, char* mod_cmdline,
           }
       }
   -    elfcorehdr = add_buffer(info, tmp, sz, sz, align, min_base,
-                max_addr, 1);
+    memsz = sz;
+    /* To support --hotplug, replace the calculated minimum size 

with the
+     * value from /sys/kernel/crash_elfcorehdr_size and align it correctly.
+     */
+    if (do_hotplug) {
+        if (elfcorehdrsz > sz)
+            memsz = _ALIGN(elfcorehdrsz, align);
+    }
+
+    /* Record the location of the elfcorehdr for hotplug handling */ +    info->elfcorehdr = elfcorehdr = add_buffer(info, tmp, sz, memsz, align,
+                           min_base, max_addr, 1); reserve(elfcorehdr, sz);
      /* modify and store the cmdline in a global array. This is later
       * read by flatten_device_tree and modified if required

kexec/arch/ppc64/fdt.c +46 -0
index 8bc6d2d..10abc29 100644
@@ -17,6 +17,13 @@
   #include <libfdt.h>
   #include <stdio.h>
   #include <stdlib.h>
+#include <limits.h>
+#include <stdbool.h>
+#include <dirent.h>
+#include <sys/stat.h>
+
+#include "../../kexec.h"
+#include "../../kexec-syscall.h"
     /*
    * Let the kernel know it booted from kexec, as some things (e.g.
@@ -46,17 +53,208 @@ static int fixup_kexec_prop(void *fdt)
       return 0;
   }
   +static inline bool is_dot_dir(char * d_path)
+{
+    return d_path[0] == '.';
+}
+
+/*
+ * Returns size of files including file name size under the given
+ * @cpu_node_path.
+ */
+static unsigned int get_cpu_node_size(char *cpu_node_path)
+{
+    DIR *d;
+    struct dirent *de;
+    struct stat statbuf;
+    unsigned int cpu_node_size = 0;
+    char cpu_prop_path[2 * PATH_MAX];
+
+    d = opendir(cpu_node_path);
+    if (!d)
+        return 0;
+
+    while ((de = readdir(d)) != NULL) {
+        if (de->d_type != DT_REG)
+            continue;
+
+        memset(cpu_prop_path, '\0', PATH_MAX);
+        snprintf(cpu_prop_path, 2 * PATH_MAX, "%s/%s", 
 cpu_node_path, de->d_name);
+
+        if (stat(cpu_prop_path, &statbuf))
+            continue;
+
+        cpu_node_size += statbuf.st_size;
+        cpu_node_size += strlen(de->d_name);
+    }
+
+    return cpu_node_size;
+}
+
+/*
+ * Checks if the node specified by the given @path represents a CPU 

node.
+ *
+ * Returns true if the @path has a "device_type" file containing "cpu";
+ * otherwise, returns false.
+ */

kexec/arch/ppc64/fdt.c +39 -0
+static bool is_cpu_node(char *path)
+{
+    FILE *file;
+    bool ret = false;
+    char device_type[4];
+
+    file = fopen(path, "r");
+    if (!file)
+        return false;
+
+    memset(device_type, '\0', 4);
+    if (fread(device_type, 1, 3, file) < 3)
+        goto out;
+
+    if (strcmp(device_type, "cpu"))
+        goto out;
+
+    ret = true;
+
+out:
+    fclose(file);
+    return ret;
+}
+
+static unsigned int get_threads_per_cpu(char *path)
+{
+    struct stat statbuf;
+    if (stat(path, &statbuf))
+        return 0;
+
+    return statbuf.st_size / 4;
+}
+
+/*
+ * Finds the following CPU attributes:
+ *
+ * cpus_in_system: Currently available CPU nodes present under
+ *                 /proc/device-tree/cpus.
+ * threads_per_cpu: Number of threads per CPU, based on the device 

tree entry
+ * /proc/device-tree/cpus/<cpu_node>/ibm,ppc-interrupt-server#s.
+ * cpu_node_size: Size of files including file name size under a CPU node.
+ *
+ * Returns 0 on success, else -1.
+ */
+static unsigned int get_cpu_info(int *_cpus_in_system, int *_threads_per_cpu,
+                 int *_cpu_node_size)

kexec/arch/ppc64/fdt.c +31 -0
+{
+    DIR *d;
+    struct dirent *de;
+    int first_cpu = 1;
+    char path[PATH_MAX];
+    char *cpus_node_path = "/proc/device-tree/cpus";
+    int cpus_in_system = 0, threads_per_cpu = 0, cpu_node_size = 0;
+
+    d = opendir(cpus_node_path);
+    if (!d)
+        return -1;
+
+    while ((de = readdir(d)) != NULL) {
+        if ((de->d_type != DT_DIR) || is_dot_dir(de->d_name))
+            continue;
+
+        memset(path, '\0', PATH_MAX);
+        snprintf(path, PATH_MAX, "%s/%s/%s", cpus_node_path,
+             de->d_name, "device_type");
+
+        /* Skip nodes with device_type != "cpu" */
+        if (!is_cpu_node(path))
+            continue;
+
+        /*
+         * Found the first node under /proc/device-tree/cpus with
+         * device_type == "cpu"
+         */
+        if (first_cpu) {
+            memset(path, '\0', PATH_MAX);
+            snprintf(path, PATH_MAX, "%s/%s", cpus_node_path, 

de->d_name);
+            cpu_node_size = get_cpu_node_size(path);

kexec/arch/ppc64/fdt.c +15 -0
+
+            memset(path, '\0', PATH_MAX);
+            snprintf(path, PATH_MAX, "%s/%s/%s", cpus_node_path,
+                 de->d_name, "ibm,ppc-interrupt-server#s");
+            threads_per_cpu = get_threads_per_cpu(path);
+
+            first_cpu = 0;
+        }
+
+        cpus_in_system++;
+    }
+
+    closedir(d);
+
+    dbgprintf("cpus_in_system: %d, threads_per_cpus: %d, 

cpu_node_size: %d\n",
+          cpus_in_system, threads_per_cpu, cpu_node_size);

kexec/arch/ppc64/fdt.c +13 -0
+
+    if (!(cpus_in_system && threads_per_cpu && cpu_node_size))
+        return -1;
+
+    *_cpus_in_system = cpus_in_system;
+    *_threads_per_cpu = threads_per_cpu;
+    *_cpu_node_size = cpu_node_size;
+
+    return 0;
+}
+
+/*
+ * Calculates the extra size needed for the flattened device tree 

(FDT) based
+ * on the difference between the possible number of CPU nodes and the number
+ * of CPU nodes present under /proc/device-tree/cpus.
+ */

kexec/arch/ppc64/fdt.c +7 -0
+static unsigned int kdump_fdt_extra_size(void)
+{
+    unsigned int extra_size = 0;
+    int cpus_in_system = 0, threads_per_cpu = 0, cpu_node_size = 0;
+    int possible_cpus;
+
+    /* ALL possible CPUs are present in FDT so no extra size 

required */
+    if (sysconf(_SC_NPROCESSORS_ONLN) == sysconf(_SC_NPROCESSORS_CONF)) +        return 0;

Quoted 8 lines
Quoted 3 lines

+
+    if (get_cpu_info(&cpus_in_system, &threads_per_cpu, &cpu_node_size)) {

Is (sysconf(_SC_NPROCESSORS_ONLN) / threads_per_cpu) not the same as 'cpus_in_system'? If they are same, should be able to get cpu_node_size & threads_per_cpu by examining a single core instead of going through all cores on the system??

Agree we can avoid traversing all cpu nodes. I will include the above suggestion in next version.

Quoted 84 lines
Quoted 83 lines

+        die("Failed to get cpu info\n");
+    }
+
+    /*
+     * Maximum number of CPU nodes with device_type = "cpu" possible under
+     * /proc/device-tree/cpus/
+     */
+    possible_cpus = sysconf(_SC_NPROCESSORS_CONF) / threads_per_cpu; +
+    if (cpus_in_system > possible_cpus)
+        die("Possible CPU nodes can't be less than active CPU nodes\n");

kexec/arch/ppc64/fdt.c +7 -0
+
+
+    extra_size = (possible_cpus - cpus_in_system) * cpu_node_size;
+    dbgprintf("kdump fdt extra size: %u\n", extra_size);
+
+    return extra_size;
+}

    /*
   * For now, assume that the added content fits in the file.
   * This should be the case when flattening from /proc/device-tree,
   * and when passing in a dtb, dtc can be told to add padding. */

kexec/arch/ppc64/fdt.c +1 -1
-int fixup_dt(char **fdt, off_t *size)
+int fixup_dt(char **fdt, off_t *size, unsigned long kexec_flags)

  {
      int ret;
        *size += 4096;

kexec/arch/ppc64/fdt.c +8 -0
+
+    /* To support --hotplug option for the kexec_load syscall, consider
+     * adding extra buffer to FDT so that the kernel can add CPU nodes
+     * of hot-added CPUs.
+     */
+    if (do_hotplug && (kexec_flags & KEXEC_ON_CRASH))
+        *size += kdump_fdt_extra_size();
+

      *fdt = realloc(*fdt, *size);
      if (!*fdt) {
          fprintf(stderr, "%s: out of memory\n", __func__);

kexec/arch/ppc64/include/arch/fdt.h +1 -0
index b19f185..5f340b0 100644
@@ -3,6 +3,6 @@
     #include <sys/types.h>
   -int fixup_dt(char **fdt, off_t *size);
+int fixup_dt(char **fdt, off_t *size, unsigned long kexec_flags);
     #endif
kexec/arch/ppc64/kexec-elf-ppc64.c +1 -0
index bdcfd20..858c994 100644
@@ -345,7 +345,7 @@ int elf_ppc64_load(int argc, char **argv, const 
 char *buf, off_t len,
           create_flatten_tree(&seg_buf, &seg_size, cmdline);
       }
   -    result = fixup_dt(&seg_buf, &seg_size);
+    result = fixup_dt(&seg_buf, &seg_size, info->kexec_flags);
       if (result < 0)
           return result;

  diff --git a/kexec/arch/ppc64/kexec-ppc64.c b/kexec/arch/ppc64/kexec-ppc64.c index fb27b6b..f27d76b 100644

kexec/arch/ppc64/kexec-ppc64.c +2 -0
@@ -24,6 +24,7 @@
   #include <errno.h>
   #include <stdint.h>
   #include <string.h>
+#include <libfdt.h>
   #include <sys/stat.h>
   #include <sys/types.h>
   #include <dirent.h>
@@ -968,7 +969,16 @@ void arch_update_purgatory(struct kexec_info 
 *UNUSED(info))
   {
   }
   -int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+int arch_do_exclude_segment(struct kexec_segment *seg_ptr, struct 
 kexec_info *info)
   {
Quoted 4 lines

kexec/arch/ppc64/kexec-ppc64.c void arch_update_purgatory(struct kexec_info *UNUSED(info)) · line 974

Quoted 1 line
kexec/arch/ppc64/kexec-ppc64.c +1 -0
+    if (!seg_ptr)

When can this be true? If this is a possiblilty, why do we not have the same thing for i386?

I agree that seg_ptr can't be NULL, which makes the above check unnecessary.

I will remove it in the next version.

Thanks,
Sourabh Jain

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

#4 lore raw

PATCH 3/3 doc/hotplug: update man and --help

In reply to Sourabh Jain

Update the man page and --help option to make the description of the --hotplug option easier to understand.

Cc Aditya Gupta <[email protected]>
Cc Baoquan He <[email protected]>
Cc Coiby Xu <[email protected]>
Cc Hari Bathini <[email protected]>
Cc Mahesh Salgaonkar <[email protected]>
---
 kexec/kexec.8 | 8 ++++----
 kexec/kexec.c | 3 ++-
 2 files changed, 6 insertions(+), 5 deletions(-)
kexec/kexec.8 +4 -4
index 9e995fe..7dddae9 100644
@@ -140,10 +140,10 @@ Open a help file for
 .BR kexec .
 .TP
 .B \-\-hotplug
-Setup for kernel modification of the elfcorehdr. This option performs
-the steps needed to support kernel updates to the elfcorehdr in the
-presence of hot un/plug and/or on/offline events. This option only
-useful for KEXEC_LOAD syscall.
+Helps avoid kdump kernel reload on CPU/Memory hotplug or on/offline events.
+If this option is enabled, the kexec segments will be set up in a way that
+the kernel can safely update them on CPU/memory hotplug and/or on/offline
+events. This option is only useful for the KEXEC_LOAD syscall.
 .TP
 .B \-i\ (\-\-no-checks)
 Fast reboot, no memory integrity checks.
kexec/kexec.c +2 -1
index 034cea6..2b06438 100644
@@ -1093,7 +1093,8 @@ void usage(void)
 	       "                      back to the compatibility syscall when file based\n"
 	       "                      syscall is not supported or the kernel did not\n"
 	       "                      understand the image (default)\n"
-	       " --hotplug            Setup for kernel modification of elfcorehdr.\n"
+	       " --hotplug            Helps avoid kdump kernel reload on CPU/Memory hotplug\n"
+	       "		      or on/offline events.\n"
 	       " -d, --debug          Enable debugging to help spot a failure.\n"
 	       " -S, --status         Return 1 if the type (by default crash) is loaded,\n"
 	       "                      0 if not.\n"
Signature · 7 lines
2.44.0


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

Re: [PATCH 3/3] doc/hotplug: update man and --help

Quoted 19 lines · Sourabh Jain

Update the man page and --help option to make the description of the --hotplug option easier to understand.

Cc Aditya Gupta <[email protected]>
Cc Baoquan He <[email protected]>
Cc Coiby Xu <[email protected]>
Cc Hari Bathini <[email protected]>
Cc Mahesh Salgaonkar <[email protected]>
---
  kexec/kexec.8 | 8 ++++----
  kexec/kexec.c | 3 ++-
  2 files changed, 6 insertions(+), 5 deletions(-)
kexec/kexec.8 +0 -0
index 9e995fe..7dddae9 100644

kexec/kexec.8 Open a help file for · line 142

Quoted 3 lines
kexec/kexec.8 +0 -0
@@ -140,10 +140,10 @@ Open a help file for
  .BR kexec .
  .TP
  .B \-\-hotplug

Can we have the description changed like:

kexec/kexec.8 Open a help file for · line 146

Quoted 8 lines
kexec/kexec.8 +4 -4
-Setup for kernel modification of the elfcorehdr. This option performs
-the steps needed to support kernel updates to the elfcorehdr in the
-presence of hot un/plug and/or on/offline events. This option only
-useful for KEXEC_LOAD syscall.
+Helps avoid kdump kernel reload on CPU/Memory hotplug or on/offline events.
+If this option is enabled, the kexec segments will be set up in a way that
+the kernel can safely update them on CPU/memory hotplug and/or on/offline
+events. This option is only useful for the KEXEC_LOAD syscall.

"Setup kexec segments such that kernel can safely update them on CPU/Memory hot add/remove events. If this option is enabled, kernel does in-kernel update of kexec segments on CPU/Memory hot add/remove events.
Helps avoid the need to reload kdump kernel."

Quoted 8 lines
kexec/kexec.8 +0 -0
  .TP
  .B \-i\ (\-\-no-checks)
  Fast reboot, no memory integrity checks.
kexec/kexec.c +0 -0
index 034cea6..2b06438 100644

kexec/kexec.c void usage(void) · line 1098

Quoted 7 lines
kexec/kexec.c +2 -1
@@ -1093,7 +1093,8 @@ void usage(void)
  	       "                      back to the compatibility syscall when file based\n"
  	       "                      syscall is not supported or the kernel did not\n"
  	       "                      understand the image (default)\n"
-	       " --hotplug            Setup for kernel modification of elfcorehdr.\n"
 
+	       " --hotplug            Helps avoid kdump kernel reload on CPU/Memory hotplug\n"
+	       "		      or on/offline events.\n"

"Do in-kernel update of kexec segments on CPU/Memory hot add/remove events. This avoids the need to reload kdump kernel."

- Hari

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

#6 lore raw

Re: [PATCH 3/3] doc/hotplug: update man and --help

Hello Hari,

Quoted 59 lines · Hari Bathini
Quoted 19 lines · Sourabh Jain

Update the man page and --help option to make the description of the --hotplug option easier to understand.

Cc Aditya Gupta <[email protected]>
Cc Baoquan He <[email protected]>
Cc Coiby Xu <[email protected]>
Cc Hari Bathini <[email protected]>
Cc Mahesh Salgaonkar <[email protected]>

---
  kexec/kexec.8 | 8 ++++----
  kexec/kexec.c | 3 ++-

  2 files changed, 6 insertions(+), 5 deletions(-)
kexec/kexec.8 +0 -0
index 9e995fe..7dddae9 100644
@@ -140,10 +140,10 @@ Open a help file for
Quoted 3 lines

  .BR kexec .
  .TP
  .B \-\-hotplug

Can we have the description changed like:

Quoted 11 lines
kexec/kexec.8 +1 -4
-Setup for kernel modification of the elfcorehdr. This option performs
-the steps needed to support kernel updates to the elfcorehdr in the
-presence of hot un/plug and/or on/offline events. This option only
-useful for KEXEC_LOAD syscall.
+Helps avoid kdump kernel reload on CPU/Memory hotplug or on/offline 

events.
+If this option is enabled, the kexec segments will be set up in a way that
+the kernel can safely update them on CPU/memory hotplug and/or on/offline
+events. This option is only useful for the KEXEC_LOAD syscall.

"Setup kexec segments such that kernel can safely update them on CPU/Memory hot add/remove events. If this option is enabled, kernel does in-kernel update of kexec segments on CPU/Memory hot add/remove events.
Helps avoid the need to reload kdump kernel."

Quoted 13 lines

  .TP
  .B \-i\ (\-\-no-checks)
  Fast reboot, no memory integrity checks.

kexec/kexec.c +0 -0
index 034cea6..2b06438 100644
@@ -1093,7 +1093,8 @@ void usage(void)

             "                      back to the compatibility syscall when file based\n" "                      syscall is not supported or the kernel did not\n" "                      understand the image (default)\n"
-           " --hotplug            Setup for kernel modification of elfcorehdr.\n"

Quoted 5 lines
Quoted 3 lines

+           " --hotplug            Helps avoid kdump kernel reload on CPU/Memory hotplug\n"
+           "              or on/offline events.\n"

"Do in-kernel update of kexec segments on CPU/Memory hot add/remove events. This avoids the need to reload kdump kernel."

The suggested descriptions look good to me. I will update them in the next version.

Thanks,
Sourabh Jain

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

#7 lore raw
In reply to Sourabh Jain

Hello sourabh,

Quoted 215 lines · Sourabh Jain

Kernel commit 79365026f869 (crash: add a new kexec flag for hotplug support) has introduced a new kexec flag to generalize hotplug support. The newly introduced kexec flags for hotplug allow architectures to exclude all the required kexec segments from SHA calculation so that the kernel can update them on hotplug events. This was not possible earlier with the KEXEC_UPDATE_ELFCOREHDR kexec flags since it was added only for the elfcorehdr segment.

To enable architectures to control the list of kexec segments to exclude when hotplug support is enabled, add a new architecture-specific function named arch_do_exclude_segment. During the SHA calculation, this function gets called to let the architecture decide whether a specific kexec segment should be considered for SHA calculation or not.

Given that the KEXEC_UPDATE_ELFCOREHDR is no longer required and was colliding with the KEXEC_LIVE_UPDATE update flag, it is removed.

Cc Aditya Gupta <[email protected]>
Cc Baoquan He <[email protected]>
Cc Coiby Xu <[email protected]>
Cc Hari Bathini <[email protected]>
Cc Mahesh Salgaonkar <[email protected]>
---
 kexec/arch/arm/kexec-arm.c             |  5 +++++
 kexec/arch/arm64/kexec-arm64.c         |  4 ++++
 kexec/arch/cris/kexec-cris.c           |  4 ++++
 kexec/arch/hppa/kexec-hppa.c           |  5 +++++
 kexec/arch/i386/kexec-x86.c            |  8 ++++++++
 kexec/arch/ia64/kexec-ia64.c           |  4 ++++
 kexec/arch/loongarch/kexec-loongarch.c |  5 +++++
 kexec/arch/m68k/kexec-m68k.c           |  5 +++++
 kexec/arch/mips/kexec-mips.c           |  4 ++++
 kexec/arch/ppc/kexec-ppc.c             |  4 ++++
 kexec/arch/ppc64/kexec-ppc64.c         |  5 +++++
 kexec/arch/s390/kexec-s390.c           |  5 +++++
 kexec/arch/sh/kexec-sh.c               |  5 +++++
 kexec/arch/x86_64/kexec-x86_64.c       |  5 +++++
 kexec/kexec-syscall.h                  |  2 +-
 kexec/kexec.c                          | 14 ++++++++------
 kexec/kexec.h                          |  2 ++
 17 files changed, 79 insertions(+), 7 deletions(-)
kexec/arch/arm/kexec-arm.c +5 -0
index 49f35b1..34531f9 100644
@@ -148,3 +148,8 @@ int have_sysfs_fdt(void)
 {
 	return !access(SYSFS_FDT, F_OK);
 }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/arm64/kexec-arm64.c +4 -0
index 4a67b0d..9d052b0 100644
@@ -1363,3 +1363,7 @@ void arch_reuse_initrd(void)
 void arch_update_purgatory(struct kexec_info *UNUSED(info))
 {
 }
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/cris/kexec-cris.c +4 -0
index 3b69709..7f09121 100644
@@ -109,3 +109,7 @@ unsigned long add_buffer(struct kexec_info *info, const void *buf,
                                     buf_min, buf_max, buf_end, 1);
 }
 
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/hppa/kexec-hppa.c +5 -0
index 77c9739..a64dc3d 100644
@@ -146,3 +146,8 @@ unsigned long virt_to_phys(unsigned long addr)
 {
 	return addr - phys_offset;
 }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/i386/kexec-x86.c +8 -0
index 444cb69..b4947a0 100644
@@ -208,3 +208,11 @@ void arch_update_purgatory(struct kexec_info *info)
 	elf_rel_set_symbol(&info->rhdr, "panic_kernel",
 		&panic_kernel, sizeof(panic_kernel));
 }
+
+int arch_do_exclude_segment(struct kexec_segment *seg_ptr, struct kexec_info *info)
+{
+	if (info->elfcorehdr == (unsigned long) seg_ptr->mem)
+		return 1;
+
+	return 0;
+}
kexec/arch/ia64/kexec-ia64.c +4 -0
index 418d997..8d9c1f3 100644
@@ -245,3 +245,7 @@ void arch_update_purgatory(struct kexec_info *UNUSED(info))
 {
 }
 
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/loongarch/kexec-loongarch.c +5 -0
index 32a42d2..9a50ff6 100644
@@ -378,3 +378,8 @@ unsigned long add_buffer(struct kexec_info *info, const void *buf,
 	return add_buffer_phys_virt(info, buf, bufsz, memsz, buf_align,
 				    buf_min, buf_max, buf_end, 1);
 }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/m68k/kexec-m68k.c +5 -0
index cb54927..0c7dbaf 100644
@@ -108,3 +108,8 @@ void add_segment(struct kexec_info *info, const void *buf, size_t bufsz,
 {
 	add_segment_phys_virt(info, buf, bufsz, base, memsz, 1);
 }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/mips/kexec-mips.c +4 -0
index d8cbea8..94224ee 100644
@@ -189,3 +189,7 @@ unsigned long add_buffer(struct kexec_info *info, const void *buf,
 				    buf_min, buf_max, buf_end, 1);
 }
 
+int arch_do_exclude_segment(const void *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/ppc/kexec-ppc.c +4 -0
index 03bec36..c8af870 100644
@@ -966,3 +966,7 @@ void arch_update_purgatory(struct kexec_info *UNUSED(info))
 {
 }
 
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/ppc64/kexec-ppc64.c +5 -0
index bd5274c..fb27b6b 100644
@@ -967,3 +967,8 @@ int arch_compat_trampoline(struct kexec_info *UNUSED(info))
 void arch_update_purgatory(struct kexec_info *UNUSED(info))
 {
 }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/s390/kexec-s390.c +5 -0
index 33ba6b9..0561ee7 100644
@@ -267,3 +267,8 @@ int get_crash_kernel_load_range(uint64_t *start, uint64_t *end)
 {
 	return parse_iomem_single("Crash kernel\n", start, end);
 }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/sh/kexec-sh.c +5 -0
index ce341c8..f84c40c 100644
@@ -257,3 +257,8 @@ unsigned long add_buffer(struct kexec_info *info, const void *buf,
 	return add_buffer_phys_virt(info, buf, bufsz, memsz, buf_align,
 				    buf_min, buf_max, buf_end, 1);
 }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/x86_64/kexec-x86_64.c +0 -0
index ffd84f0..42af90a 100644

kexec/arch/x86_64/kexec-x86_64.c void arch_update_purgatory(struct kexec_info *info) · line 195

Quoted 8 lines
kexec/arch/x86_64/kexec-x86_64.c +5 -0
@@ -188,3 +188,8 @@ void arch_update_purgatory(struct kexec_info *info)
 	elf_rel_set_symbol(&info->rhdr, "panic_kernel",
 				&panic_kernel, sizeof(panic_kernel));
 }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}

Should all arch_do_exclude_segment return 1 for elfcorehdr ? Please refer my below comment.

Quoted 23 lines
kexec/kexec-syscall.h +1 -1
index 73e5254..4675c46 100644
@@ -112,7 +112,7 @@ static inline long kexec_file_load(int kernel_fd, int initrd_fd,
 
 #define KEXEC_ON_CRASH		0x00000001
 #define KEXEC_PRESERVE_CONTEXT	0x00000002
-#define KEXEC_UPDATE_ELFCOREHDR	0x00000004
+#define KEXEC_CRASH_HOTPLUG_SUPPORT	0x00000008
 #define KEXEC_ARCH_MASK		0xffff0000
 
 /* Flags for kexec file based system call */
kexec/kexec.c +0 -2
index 222f79e..034cea6 100644
@@ -701,10 +701,13 @@ static void update_purgatory(struct kexec_info *info)
 			continue;
 		}
 
-		/* Don't include elfcorehdr in the checksum, if hotplug
-		 * support enabled.

kexec/kexec.c static void update_purgatory(struct kexec_info *info) · line 712

Quoted 10 lines
kexec/kexec.c +6 -1
+		/*
+		 * Let architecture decide which segments to exclude from checksum
+		 * if hotplug support is enabled.
 		 */
-		if (do_hotplug && (info->segment[i].mem == (void *)info->elfcorehdr)) {
+		if (do_hotplug && arch_do_exclude_segment(&info->segment[i], info)) {
+			dbgprintf("Skipping segment mem: 0x%lx from SHA calculation\n",
+				  (unsigned long)info->segment[i].mem);
 			continue;
 		}

Current behaviour seems to skip elfcorehdr segment in all architectures.

But now as all architectures are returning 0 in arch_do_exclude_segment, will elfcorehdr still be skipped ?

Rest all looks good to me.

Thanks,
Aditya Gupta

Quoted 36 lines
kexec/kexec.c +2 -3
@@ -1651,7 +1654,6 @@ int main(int argc, char *argv[])
 		die("--load-live-update can only be used with xen\n");
 	}
 
-	/* NOTE: Xen KEXEC_LIVE_UPDATE and KEXEC_UPDATE_ELFCOREHDR collide */
 	if (do_hotplug) {
 		const char *ces = "/sys/kernel/crash_elfcorehdr_size";
 		char *buf, *endptr = NULL;
@@ -1665,8 +1667,8 @@ int main(int argc, char *argv[])
 		if (!elfcorehdrsz || (endptr && *endptr != '\0'))
 			die("Path %s does not exist, the kernel needs CONFIG_CRASH_HOTPLUG\n", ces);
 		dbgprintf("ELFCOREHDR_SIZE %lu\n", elfcorehdrsz);
-		/* Indicate to the kernel it is ok to modify the elfcorehdr */
-		kexec_flags |= KEXEC_UPDATE_ELFCOREHDR;
+		/* Indicate to the kernel it is ok to modify the relevant kexec segments */
+		kexec_flags |= KEXEC_CRASH_HOTPLUG_SUPPORT;
 	}
 
 	fileind = optind;
kexec/kexec.h +2 -0
index 1004aff..2d758c9 100644
@@ -307,6 +307,8 @@ extern int do_hotplug;
 #define BOOTLOADER_VERSION PACKAGE_VERSION
 
 void arch_usage(void);
+/* Return non-zero if segment needs to be excluded from SHA calculation, else 0. */
+int arch_do_exclude_segment(struct kexec_segment *seg_ptr, struct kexec_info *info);
 int arch_process_options(int argc, char **argv);
 int arch_compat_trampoline(struct kexec_info *info);
 void arch_update_purgatory(struct kexec_info *info);
Signature · 1 line
2.44.0

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

#8 lore raw

Hello Aditya,

Quoted 220 lines · Aditya Gupta

Hello sourabh,

Quoted 217 lines · Sourabh Jain

Kernel commit 79365026f869 (crash: add a new kexec flag for hotplug support) has introduced a new kexec flag to generalize hotplug support. The newly introduced kexec flags for hotplug allow architectures to exclude all the required kexec segments from SHA calculation so that the kernel can update them on hotplug events. This was not possible earlier with the KEXEC_UPDATE_ELFCOREHDR kexec flags since it was added only for the elfcorehdr segment.

To enable architectures to control the list of kexec segments to exclude when hotplug support is enabled, add a new architecture-specific function named arch_do_exclude_segment. During the SHA calculation, this function gets called to let the architecture decide whether a specific kexec segment should be considered for SHA calculation or not.

Given that the KEXEC_UPDATE_ELFCOREHDR is no longer required and was colliding with the KEXEC_LIVE_UPDATE update flag, it is removed.

Cc Aditya Gupta <[email protected]>
Cc Baoquan He <[email protected]>
Cc Coiby Xu <[email protected]>
Cc Hari Bathini <[email protected]>
Cc Mahesh Salgaonkar <[email protected]>
---
  kexec/arch/arm/kexec-arm.c             |  5 +++++
  kexec/arch/arm64/kexec-arm64.c         |  4 ++++
  kexec/arch/cris/kexec-cris.c           |  4 ++++
  kexec/arch/hppa/kexec-hppa.c           |  5 +++++
  kexec/arch/i386/kexec-x86.c            |  8 ++++++++
  kexec/arch/ia64/kexec-ia64.c           |  4 ++++
  kexec/arch/loongarch/kexec-loongarch.c |  5 +++++
  kexec/arch/m68k/kexec-m68k.c           |  5 +++++
  kexec/arch/mips/kexec-mips.c           |  4 ++++
  kexec/arch/ppc/kexec-ppc.c             |  4 ++++
  kexec/arch/ppc64/kexec-ppc64.c         |  5 +++++
  kexec/arch/s390/kexec-s390.c           |  5 +++++
  kexec/arch/sh/kexec-sh.c               |  5 +++++
  kexec/arch/x86_64/kexec-x86_64.c       |  5 +++++
  kexec/kexec-syscall.h                  |  2 +-
  kexec/kexec.c                          | 14 ++++++++------
  kexec/kexec.h                          |  2 ++
  17 files changed, 79 insertions(+), 7 deletions(-)
kexec/arch/arm/kexec-arm.c +5 -0
index 49f35b1..34531f9 100644
@@ -148,3 +148,8 @@ int have_sysfs_fdt(void)
  {
  	return !access(SYSFS_FDT, F_OK);
  }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/arm64/kexec-arm64.c +4 -0
index 4a67b0d..9d052b0 100644
@@ -1363,3 +1363,7 @@ void arch_reuse_initrd(void)
  void arch_update_purgatory(struct kexec_info *UNUSED(info))
  {
  }
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/cris/kexec-cris.c +4 -0
index 3b69709..7f09121 100644
@@ -109,3 +109,7 @@ unsigned long add_buffer(struct kexec_info *info, const void *buf,
                                      buf_min, buf_max, buf_end, 1);
  }
 
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/hppa/kexec-hppa.c +5 -0
index 77c9739..a64dc3d 100644
@@ -146,3 +146,8 @@ unsigned long virt_to_phys(unsigned long addr)
  {
  	return addr - phys_offset;
  }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/i386/kexec-x86.c +8 -0
index 444cb69..b4947a0 100644
@@ -208,3 +208,11 @@ void arch_update_purgatory(struct kexec_info *info)
  	elf_rel_set_symbol(&info->rhdr, "panic_kernel",
  		&panic_kernel, sizeof(panic_kernel));
  }
+
+int arch_do_exclude_segment(struct kexec_segment *seg_ptr, struct kexec_info *info)
+{
+	if (info->elfcorehdr == (unsigned long) seg_ptr->mem)
+		return 1;
+
+	return 0;
+}
kexec/arch/ia64/kexec-ia64.c +4 -0
index 418d997..8d9c1f3 100644
@@ -245,3 +245,7 @@ void arch_update_purgatory(struct kexec_info *UNUSED(info))
  {
  }
 
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/loongarch/kexec-loongarch.c +5 -0
index 32a42d2..9a50ff6 100644
@@ -378,3 +378,8 @@ unsigned long add_buffer(struct kexec_info *info, const void *buf,
  	return add_buffer_phys_virt(info, buf, bufsz, memsz, buf_align,
  				    buf_min, buf_max, buf_end, 1);
  }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/m68k/kexec-m68k.c +5 -0
index cb54927..0c7dbaf 100644
@@ -108,3 +108,8 @@ void add_segment(struct kexec_info *info, const void *buf, size_t bufsz,
  {
  	add_segment_phys_virt(info, buf, bufsz, base, memsz, 1);
  }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/mips/kexec-mips.c +4 -0
index d8cbea8..94224ee 100644
@@ -189,3 +189,7 @@ unsigned long add_buffer(struct kexec_info *info, const void *buf,
  				    buf_min, buf_max, buf_end, 1);
  }
 
+int arch_do_exclude_segment(const void *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/ppc/kexec-ppc.c +4 -0
index 03bec36..c8af870 100644
@@ -966,3 +966,7 @@ void arch_update_purgatory(struct kexec_info *UNUSED(info))
  {
  }
 
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/ppc64/kexec-ppc64.c +5 -0
index bd5274c..fb27b6b 100644
@@ -967,3 +967,8 @@ int arch_compat_trampoline(struct kexec_info *UNUSED(info))
  void arch_update_purgatory(struct kexec_info *UNUSED(info))
  {
  }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/s390/kexec-s390.c +5 -0
index 33ba6b9..0561ee7 100644
@@ -267,3 +267,8 @@ int get_crash_kernel_load_range(uint64_t *start, uint64_t *end)
  {
  	return parse_iomem_single("Crash kernel\n", start, end);
  }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/sh/kexec-sh.c +5 -0
index ce341c8..f84c40c 100644
@@ -257,3 +257,8 @@ unsigned long add_buffer(struct kexec_info *info, const void *buf,
  	return add_buffer_phys_virt(info, buf, bufsz, memsz, buf_align,
  				    buf_min, buf_max, buf_end, 1);
  }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/x86_64/kexec-x86_64.c +0 -0
index ffd84f0..42af90a 100644
@@ -188,3 +188,8 @@ void arch_update_purgatory(struct kexec_info *info)
  	elf_rel_set_symbol(&info->rhdr, "panic_kernel",
  				&panic_kernel, sizeof(panic_kernel));
Quoted 8 lines

kexec/arch/x86_64/kexec-x86_64.c void arch_update_purgatory(struct kexec_info *info) · line 195

Quoted 6 lines
kexec/arch/x86_64/kexec-x86_64.c +5 -0
  }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}

Should all arch_do_exclude_segment return 1 for elfcorehdr ? Please refer my below comment.

No they shouldn't until they have CRASH_HTOPLUG support in the kernel.

Quoted 36 lines
Quoted 24 lines
kexec/kexec-syscall.h +1 -1
index 73e5254..4675c46 100644
@@ -112,7 +112,7 @@ static inline long kexec_file_load(int kernel_fd, int initrd_fd,
 
  #define KEXEC_ON_CRASH		0x00000001
  #define KEXEC_PRESERVE_CONTEXT	0x00000002
-#define KEXEC_UPDATE_ELFCOREHDR	0x00000004
+#define KEXEC_CRASH_HOTPLUG_SUPPORT	0x00000008
  #define KEXEC_ARCH_MASK		0xffff0000
 
  /* Flags for kexec file based system call */
kexec/kexec.c +0 -2
index 222f79e..034cea6 100644
@@ -701,10 +701,13 @@ static void update_purgatory(struct kexec_info *info)
  			continue;
  		}
 
-		/* Don't include elfcorehdr in the checksum, if hotplug
-		 * support enabled.

kexec/kexec.c static void update_purgatory(struct kexec_info *info) · line 712

Quoted 10 lines
kexec/kexec.c +6 -1
+		/*
+		 * Let architecture decide which segments to exclude from checksum
+		 * if hotplug support is enabled.
  		 */
-		if (do_hotplug && (info->segment[i].mem == (void *)info->elfcorehdr)) {
+		if (do_hotplug && arch_do_exclude_segment(&info->segment[i], info)) {
+			dbgprintf("Skipping segment mem: 0x%lx from SHA calculation\n",
+				  (unsigned long)info->segment[i].mem);
  			continue;
  		}

Current behaviour seems to skip elfcorehdr segment in all architectures.

Quoted 2 lines

But now as all architectures are returning 0 in arch_do_exclude_segment, will elfcorehdr still be skipped ?

Skipping elfcorehdr for architectures that don't support CRASH_HOTPLUG is, I think, incorrect. Therefore, I believe the proposed approach in this patch, which asks the architecture which segments to exclude, is better.

Quoted 1 line

Rest all looks good to me.

Thanks for the review.

- Sourabh Jain

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

#9 lore raw

Hello sourabh,

Quoted 246 lines · Sourabh Jain

Hello Aditya,

Quoted 191 lines · Aditya Gupta
Quoted 191 lines
kexec/arch/arm/kexec-arm.c +2 -0
index 49f35b1..34531f9 100644
@@ -148,3 +148,8 @@ int have_sysfs_fdt(void)
   {
       return !access(SYSFS_FDT, F_OK);
   }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), 

struct kexec_info *UNUSED(info))

kexec/arch/arm/kexec-arm.c +3 -0
+{
+    return 0;
+}
kexec/arch/arm64/kexec-arm64.c +1 -0
index 4a67b0d..9d052b0 100644
@@ -1363,3 +1363,7 @@ void arch_reuse_initrd(void)
   void arch_update_purgatory(struct kexec_info *UNUSED(info))
   {
   }
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), 

struct kexec_info *UNUSED(info))

kexec/arch/arm64/kexec-arm64.c +3 -0
+{
+    return 0;
+}
kexec/arch/cris/kexec-cris.c +0 -0
index 3b69709..7f09121 100644
@@ -109,3 +109,7 @@ unsigned long add_buffer(struct kexec_info 
 *info, const void *buf,
                                       buf_min, buf_max, buf_end, 1);
   }

  +int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))

kexec/arch/cris/kexec-cris.c +3 -0
+{
+    return 0;
+}
kexec/arch/hppa/kexec-hppa.c +2 -0
index 77c9739..a64dc3d 100644
@@ -146,3 +146,8 @@ unsigned long virt_to_phys(unsigned long addr)
   {
       return addr - phys_offset;
   }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), 

struct kexec_info *UNUSED(info))

kexec/arch/hppa/kexec-hppa.c +3 -0
+{
+    return 0;
+}
kexec/arch/i386/kexec-x86.c +0 -0
index 444cb69..b4947a0 100644
@@ -208,3 +208,11 @@ void arch_update_purgatory(struct kexec_info 
 *info)
       elf_rel_set_symbol(&info->rhdr, "panic_kernel",
           &panic_kernel, sizeof(panic_kernel));

  }

kexec/arch/i386/kexec-x86.c +2 -0
+
+int arch_do_exclude_segment(struct kexec_segment *seg_ptr, struct 

kexec_info *info)

kexec/arch/i386/kexec-x86.c +6 -0
+{
+    if (info->elfcorehdr == (unsigned long) seg_ptr->mem)
+        return 1;
+
+    return 0;
+}
kexec/arch/ia64/kexec-ia64.c +0 -0
index 418d997..8d9c1f3 100644
@@ -245,3 +245,7 @@ void arch_update_purgatory(struct kexec_info 
 *UNUSED(info))
   {
   }

  +int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))

kexec/arch/ia64/kexec-ia64.c +3 -0
+{
+    return 0;
+}
kexec/arch/loongarch/kexec-loongarch.c +0 -0
index 32a42d2..9a50ff6 100644
@@ -378,3 +378,8 @@ unsigned long add_buffer(struct kexec_info 
 *info, const void *buf,
       return add_buffer_phys_virt(info, buf, bufsz, memsz, buf_align,
                       buf_min, buf_max, buf_end, 1);

  }

kexec/arch/loongarch/kexec-loongarch.c +2 -0
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), 

struct kexec_info *UNUSED(info))

kexec/arch/loongarch/kexec-loongarch.c +3 -0
+{
+    return 0;
+}
kexec/arch/m68k/kexec-m68k.c +0 -0
index cb54927..0c7dbaf 100644
@@ -108,3 +108,8 @@ void add_segment(struct kexec_info *info, const 
 void *buf, size_t bufsz,
   {
       add_segment_phys_virt(info, buf, bufsz, base, memsz, 1);

  }

kexec/arch/m68k/kexec-m68k.c +2 -0
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), 

struct kexec_info *UNUSED(info))

kexec/arch/m68k/kexec-m68k.c +3 -0
+{
+    return 0;
+}
kexec/arch/mips/kexec-mips.c +0 -0
index d8cbea8..94224ee 100644
@@ -189,3 +189,7 @@ unsigned long add_buffer(struct kexec_info 
 *info, const void *buf,
                       buf_min, buf_max, buf_end, 1);
   }

  +int arch_do_exclude_segment(const void *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))

kexec/arch/mips/kexec-mips.c +3 -0
+{
+    return 0;
+}
kexec/arch/ppc/kexec-ppc.c +0 -0
index 03bec36..c8af870 100644
@@ -966,3 +966,7 @@ void arch_update_purgatory(struct kexec_info 
 *UNUSED(info))
   {
   }

  +int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))

kexec/arch/ppc/kexec-ppc.c +3 -0
+{
+    return 0;
+}
kexec/arch/ppc64/kexec-ppc64.c +0 -0
index bd5274c..fb27b6b 100644
@@ -967,3 +967,8 @@ int arch_compat_trampoline(struct kexec_info 
 *UNUSED(info))
   void arch_update_purgatory(struct kexec_info *UNUSED(info))
   {

  }

kexec/arch/ppc64/kexec-ppc64.c +2 -0
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), 

struct kexec_info *UNUSED(info))

kexec/arch/ppc64/kexec-ppc64.c +3 -0
+{
+    return 0;
+}
kexec/arch/s390/kexec-s390.c +0 -0
index 33ba6b9..0561ee7 100644
@@ -267,3 +267,8 @@ int get_crash_kernel_load_range(uint64_t *start, 
 uint64_t *end)
   {
       return parse_iomem_single("Crash kernel\n", start, end);

  }

kexec/arch/s390/kexec-s390.c +2 -0
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), 

struct kexec_info *UNUSED(info))

kexec/arch/s390/kexec-s390.c +3 -0
+{
+    return 0;
+}
kexec/arch/sh/kexec-sh.c +0 -0
index ce341c8..f84c40c 100644
@@ -257,3 +257,8 @@ unsigned long add_buffer(struct kexec_info 
 *info, const void *buf,
       return add_buffer_phys_virt(info, buf, bufsz, memsz, buf_align,
                       buf_min, buf_max, buf_end, 1);

  }

kexec/arch/sh/kexec-sh.c +2 -0
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), 

struct kexec_info *UNUSED(info))

kexec/arch/sh/kexec-sh.c +3 -0
+{
+    return 0;
+}
kexec/arch/x86_64/kexec-x86_64.c +0 -0
index ffd84f0..42af90a 100644
@@ -188,3 +188,8 @@ void arch_update_purgatory(struct kexec_info *info)
       elf_rel_set_symbol(&info->rhdr, "panic_kernel",
                   &panic_kernel, sizeof(panic_kernel));
   }
Quoted 8 lines

kexec/arch/x86_64/kexec-x86_64.c

Quoted 6 lines
kexec/arch/x86_64/kexec-x86_64.c +2 -0
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), 

struct kexec_info *UNUSED(info))

kexec/arch/x86_64/kexec-x86_64.c +3 -0
+{
+    return 0;
+}

Should all arch_do_exclude_segment return 1 for elfcorehdr ? Please refer my below comment.

No they shouldn't until they have CRASH_HTOPLUG support in the kernel.

Quoted 39 lines
Quoted 29 lines
kexec/kexec-syscall.h +1 -1
index 73e5254..4675c46 100644
@@ -112,7 +112,7 @@ static inline long kexec_file_load(int 
 kernel_fd, int initrd_fd,
     #define KEXEC_ON_CRASH        0x00000001
   #define KEXEC_PRESERVE_CONTEXT    0x00000002
-#define KEXEC_UPDATE_ELFCOREHDR    0x00000004
+#define KEXEC_CRASH_HOTPLUG_SUPPORT    0x00000008
   #define KEXEC_ARCH_MASK        0xffff0000
     /* Flags for kexec file based system call */
kexec/kexec.c +0 -0
index 222f79e..034cea6 100644
@@ -701,10 +701,13 @@ static void update_purgatory(struct kexec_info 
 *info)
               continue;
           }

  -        /* Don't include elfcorehdr in the checksum, if hotplug -         * support enabled.
+        /*
+         * Let architecture decide which segments to exclude from checksum
+         * if hotplug support is enabled.
           */
-        if (do_hotplug && (info->segment[i].mem == (void

Quoted 8 lines

*)info->elfcorehdr)) {
+        if (do_hotplug && arch_do_exclude_segment(&info->segment[i], info)) { +            dbgprintf("Skipping segment mem: 0x%lx from SHA calculation\n",
+                  (unsigned long)info->segment[i].mem); continue;
          }

Current behaviour seems to skip elfcorehdr segment in all architectures.

Quoted 7 lines
Quoted 2 lines

But now as all architectures are returning 0 in arch_do_exclude_segment, will elfcorehdr still be skipped ?

Skipping elfcorehdr for architectures that don't support CRASH_HOTPLUG is, I think, incorrect. Therefore, I believe the proposed approach in this patch, which asks the architecture which segments to exclude, is better.

Got it, makes sense to me. Thanks for the explanation sourabh.

- Aditya Gupta

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

Acked-by on v1 1/3
#10 lore raw
In reply to Sourabh Jain
Quoted 216 lines · Sourabh Jain

Kernel commit 79365026f869 (crash: add a new kexec flag for hotplug support) has introduced a new kexec flag to generalize hotplug support. The newly introduced kexec flags for hotplug allow architectures to exclude all the required kexec segments from SHA calculation so that the kernel can update them on hotplug events. This was not possible earlier with the KEXEC_UPDATE_ELFCOREHDR kexec flags since it was added only for the elfcorehdr segment.

To enable architectures to control the list of kexec segments to exclude when hotplug support is enabled, add a new architecture-specific function named arch_do_exclude_segment. During the SHA calculation, this function gets called to let the architecture decide whether a specific kexec segment should be considered for SHA calculation or not.

Given that the KEXEC_UPDATE_ELFCOREHDR is no longer required and was colliding with the KEXEC_LIVE_UPDATE update flag, it is removed.

Cc Aditya Gupta <[email protected]>
Cc Baoquan He <[email protected]>
Cc Coiby Xu <[email protected]>
Cc Hari Bathini <[email protected]>
Cc Mahesh Salgaonkar <[email protected]>
---
  kexec/arch/arm/kexec-arm.c             |  5 +++++
  kexec/arch/arm64/kexec-arm64.c         |  4 ++++
  kexec/arch/cris/kexec-cris.c           |  4 ++++
  kexec/arch/hppa/kexec-hppa.c           |  5 +++++
  kexec/arch/i386/kexec-x86.c            |  8 ++++++++
  kexec/arch/ia64/kexec-ia64.c           |  4 ++++
  kexec/arch/loongarch/kexec-loongarch.c |  5 +++++
  kexec/arch/m68k/kexec-m68k.c           |  5 +++++
  kexec/arch/mips/kexec-mips.c           |  4 ++++
  kexec/arch/ppc/kexec-ppc.c             |  4 ++++
  kexec/arch/ppc64/kexec-ppc64.c         |  5 +++++
  kexec/arch/s390/kexec-s390.c           |  5 +++++
  kexec/arch/sh/kexec-sh.c               |  5 +++++
  kexec/arch/x86_64/kexec-x86_64.c       |  5 +++++
  kexec/kexec-syscall.h                  |  2 +-
  kexec/kexec.c                          | 14 ++++++++------
  kexec/kexec.h                          |  2 ++
  17 files changed, 79 insertions(+), 7 deletions(-)
kexec/arch/arm/kexec-arm.c +5 -0
index 49f35b1..34531f9 100644
@@ -148,3 +148,8 @@ int have_sysfs_fdt(void)
  {
  	return !access(SYSFS_FDT, F_OK);
  }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/arm64/kexec-arm64.c +4 -0
index 4a67b0d..9d052b0 100644
@@ -1363,3 +1363,7 @@ void arch_reuse_initrd(void)
  void arch_update_purgatory(struct kexec_info *UNUSED(info))
  {
  }
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/cris/kexec-cris.c +4 -0
index 3b69709..7f09121 100644
@@ -109,3 +109,7 @@ unsigned long add_buffer(struct kexec_info *info, const void *buf,
                                      buf_min, buf_max, buf_end, 1);
  }
 
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/hppa/kexec-hppa.c +5 -0
index 77c9739..a64dc3d 100644
@@ -146,3 +146,8 @@ unsigned long virt_to_phys(unsigned long addr)
  {
  	return addr - phys_offset;
  }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/i386/kexec-x86.c +8 -0
index 444cb69..b4947a0 100644
@@ -208,3 +208,11 @@ void arch_update_purgatory(struct kexec_info *info)
  	elf_rel_set_symbol(&info->rhdr, "panic_kernel",
  		&panic_kernel, sizeof(panic_kernel));
  }
+
+int arch_do_exclude_segment(struct kexec_segment *seg_ptr, struct kexec_info *info)
+{
+	if (info->elfcorehdr == (unsigned long) seg_ptr->mem)
+		return 1;
+
+	return 0;
+}
kexec/arch/ia64/kexec-ia64.c +4 -0
index 418d997..8d9c1f3 100644
@@ -245,3 +245,7 @@ void arch_update_purgatory(struct kexec_info *UNUSED(info))
  {
  }
 
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/loongarch/kexec-loongarch.c +5 -0
index 32a42d2..9a50ff6 100644
@@ -378,3 +378,8 @@ unsigned long add_buffer(struct kexec_info *info, const void *buf,
  	return add_buffer_phys_virt(info, buf, bufsz, memsz, buf_align,
  				    buf_min, buf_max, buf_end, 1);
  }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/m68k/kexec-m68k.c +5 -0
index cb54927..0c7dbaf 100644
@@ -108,3 +108,8 @@ void add_segment(struct kexec_info *info, const void *buf, size_t bufsz,
  {
  	add_segment_phys_virt(info, buf, bufsz, base, memsz, 1);
  }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/mips/kexec-mips.c +4 -0
index d8cbea8..94224ee 100644
@@ -189,3 +189,7 @@ unsigned long add_buffer(struct kexec_info *info, const void *buf,
  				    buf_min, buf_max, buf_end, 1);
  }
 
+int arch_do_exclude_segment(const void *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/ppc/kexec-ppc.c +4 -0
index 03bec36..c8af870 100644
@@ -966,3 +966,7 @@ void arch_update_purgatory(struct kexec_info *UNUSED(info))
  {
  }
 
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/ppc64/kexec-ppc64.c +5 -0
index bd5274c..fb27b6b 100644
@@ -967,3 +967,8 @@ int arch_compat_trampoline(struct kexec_info *UNUSED(info))
  void arch_update_purgatory(struct kexec_info *UNUSED(info))
  {
  }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/s390/kexec-s390.c +5 -0
index 33ba6b9..0561ee7 100644
@@ -267,3 +267,8 @@ int get_crash_kernel_load_range(uint64_t *start, uint64_t *end)
  {
  	return parse_iomem_single("Crash kernel\n", start, end);
  }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/sh/kexec-sh.c +5 -0
index ce341c8..f84c40c 100644
@@ -257,3 +257,8 @@ unsigned long add_buffer(struct kexec_info *info, const void *buf,
  	return add_buffer_phys_virt(info, buf, bufsz, memsz, buf_align,
  				    buf_min, buf_max, buf_end, 1);
  }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{
+	return 0;
+}
kexec/arch/x86_64/kexec-x86_64.c +0 -0
index ffd84f0..42af90a 100644

kexec/arch/x86_64/kexec-x86_64.c void arch_update_purgatory(struct kexec_info *info) · line 193

Quoted 6 lines
kexec/arch/x86_64/kexec-x86_64.c +3 -0
@@ -188,3 +188,8 @@ void arch_update_purgatory(struct kexec_info *info)
  	elf_rel_set_symbol(&info->rhdr, "panic_kernel",
  				&panic_kernel, sizeof(panic_kernel));
  }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))
+{

This should also be similar to i386, no?
Except for that, rest looks good..

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

#11 lore raw

Hello Hari,

Quoted 228 lines · Hari Bathini
Quoted 224 lines · Sourabh Jain

Kernel commit 79365026f869 (crash: add a new kexec flag for hotplug support) has introduced a new kexec flag to generalize hotplug support. The newly introduced kexec flags for hotplug allow architectures to exclude all the required kexec segments from SHA calculation so that the kernel can update them on hotplug events. This was not possible earlier with the KEXEC_UPDATE_ELFCOREHDR kexec flags since it was added only for the elfcorehdr segment.

To enable architectures to control the list of kexec segments to exclude when hotplug support is enabled, add a new architecture-specific function named arch_do_exclude_segment. During the SHA calculation, this function gets called to let the architecture decide whether a specific kexec segment should be considered for SHA calculation or not.

Given that the KEXEC_UPDATE_ELFCOREHDR is no longer required and was colliding with the KEXEC_LIVE_UPDATE update flag, it is removed.

Cc Aditya Gupta <[email protected]>
Cc Baoquan He <[email protected]>
Cc Coiby Xu <[email protected]>
Cc Hari Bathini <[email protected]>
Cc Mahesh Salgaonkar <[email protected]>

---
  kexec/arch/arm/kexec-arm.c             |  5 +++++ kexec/arch/arm64/kexec-arm64.c         |  4 ++++ kexec/arch/cris/kexec-cris.c           |  4 ++++ kexec/arch/hppa/kexec-hppa.c           |  5 +++++ kexec/arch/i386/kexec-x86.c            |  8 ++++++++ kexec/arch/ia64/kexec-ia64.c           |  4 ++++ kexec/arch/loongarch/kexec-loongarch.c |  5 +++++ kexec/arch/m68k/kexec-m68k.c           |  5 +++++ kexec/arch/mips/kexec-mips.c           |  4 ++++ kexec/arch/ppc/kexec-ppc.c             |  4 ++++ kexec/arch/ppc64/kexec-ppc64.c         |  5 +++++ kexec/arch/s390/kexec-s390.c           |  5 +++++ kexec/arch/sh/kexec-sh.c               |  5 +++++ kexec/arch/x86_64/kexec-x86_64.c       |  5 +++++ kexec/kexec-syscall.h                  |  2 +- kexec/kexec.c                          | 14 ++++++++------ kexec/kexec.h                          |  2 ++

  17 files changed, 79 insertions(+), 7 deletions(-)
kexec/arch/arm/kexec-arm.c +2 -0
index 49f35b1..34531f9 100644
@@ -148,3 +148,8 @@ int have_sysfs_fdt(void)
   {
       return !access(SYSFS_FDT, F_OK);
   }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), 

struct kexec_info *UNUSED(info))

kexec/arch/arm/kexec-arm.c +3 -0
+{
+    return 0;
+}
kexec/arch/arm64/kexec-arm64.c +1 -0
index 4a67b0d..9d052b0 100644
@@ -1363,3 +1363,7 @@ void arch_reuse_initrd(void)
   void arch_update_purgatory(struct kexec_info *UNUSED(info))
   {
   }
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), 

struct kexec_info *UNUSED(info))

kexec/arch/arm64/kexec-arm64.c +3 -0
+{
+    return 0;
+}
kexec/arch/cris/kexec-cris.c +0 -0
index 3b69709..7f09121 100644
@@ -109,3 +109,7 @@ unsigned long add_buffer(struct kexec_info *info, 
 const void *buf,
                                       buf_min, buf_max, buf_end, 1);
   }

  +int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))

kexec/arch/cris/kexec-cris.c +3 -0
+{
+    return 0;
+}
kexec/arch/hppa/kexec-hppa.c +2 -0
index 77c9739..a64dc3d 100644
@@ -146,3 +146,8 @@ unsigned long virt_to_phys(unsigned long addr)
   {
       return addr - phys_offset;
   }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), 

struct kexec_info *UNUSED(info))

kexec/arch/hppa/kexec-hppa.c +3 -0
+{
+    return 0;
+}
kexec/arch/i386/kexec-x86.c +2 -0
index 444cb69..b4947a0 100644
@@ -208,3 +208,11 @@ void arch_update_purgatory(struct kexec_info *info)
       elf_rel_set_symbol(&info->rhdr, "panic_kernel",
           &panic_kernel, sizeof(panic_kernel));
   }
+
+int arch_do_exclude_segment(struct kexec_segment *seg_ptr, struct 

kexec_info *info)

kexec/arch/i386/kexec-x86.c +6 -0
+{
+    if (info->elfcorehdr == (unsigned long) seg_ptr->mem)
+        return 1;
+
+    return 0;
+}
kexec/arch/ia64/kexec-ia64.c +0 -0
index 418d997..8d9c1f3 100644
@@ -245,3 +245,7 @@ void arch_update_purgatory(struct kexec_info 
 *UNUSED(info))
   {
   }

  +int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))

kexec/arch/ia64/kexec-ia64.c +3 -0
+{
+    return 0;
+}
kexec/arch/loongarch/kexec-loongarch.c +0 -0
index 32a42d2..9a50ff6 100644
@@ -378,3 +378,8 @@ unsigned long add_buffer(struct kexec_info *info, 
 const void *buf,
       return add_buffer_phys_virt(info, buf, bufsz, memsz, buf_align,
                       buf_min, buf_max, buf_end, 1);

  }

kexec/arch/loongarch/kexec-loongarch.c +2 -0
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), 

struct kexec_info *UNUSED(info))

kexec/arch/loongarch/kexec-loongarch.c +3 -0
+{
+    return 0;
+}
kexec/arch/m68k/kexec-m68k.c +0 -0
index cb54927..0c7dbaf 100644
@@ -108,3 +108,8 @@ void add_segment(struct kexec_info *info, const 
 void *buf, size_t bufsz,
   {
       add_segment_phys_virt(info, buf, bufsz, base, memsz, 1);

  }

kexec/arch/m68k/kexec-m68k.c +2 -0
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), 

struct kexec_info *UNUSED(info))

kexec/arch/m68k/kexec-m68k.c +3 -0
+{
+    return 0;
+}
kexec/arch/mips/kexec-mips.c +0 -0
index d8cbea8..94224ee 100644
@@ -189,3 +189,7 @@ unsigned long add_buffer(struct kexec_info *info, 
 const void *buf,
                       buf_min, buf_max, buf_end, 1);
   }

  +int arch_do_exclude_segment(const void *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))

kexec/arch/mips/kexec-mips.c +3 -0
+{
+    return 0;
+}
kexec/arch/ppc/kexec-ppc.c +0 -0
index 03bec36..c8af870 100644
@@ -966,3 +966,7 @@ void arch_update_purgatory(struct kexec_info 
 *UNUSED(info))
   {
   }

  +int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), struct kexec_info *UNUSED(info))

kexec/arch/ppc/kexec-ppc.c +3 -0
+{
+    return 0;
+}
kexec/arch/ppc64/kexec-ppc64.c +0 -0
index bd5274c..fb27b6b 100644
@@ -967,3 +967,8 @@ int arch_compat_trampoline(struct kexec_info 
 *UNUSED(info))
   void arch_update_purgatory(struct kexec_info *UNUSED(info))
   {

  }

kexec/arch/ppc64/kexec-ppc64.c +2 -0
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), 

struct kexec_info *UNUSED(info))

kexec/arch/ppc64/kexec-ppc64.c +3 -0
+{
+    return 0;
+}
kexec/arch/s390/kexec-s390.c +0 -0
index 33ba6b9..0561ee7 100644
@@ -267,3 +267,8 @@ int get_crash_kernel_load_range(uint64_t *start, 
 uint64_t *end)
   {
       return parse_iomem_single("Crash kernel\n", start, end);

  }

kexec/arch/s390/kexec-s390.c +2 -0
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), 

struct kexec_info *UNUSED(info))

kexec/arch/s390/kexec-s390.c +3 -0
+{
+    return 0;
+}
kexec/arch/sh/kexec-sh.c +0 -0
index ce341c8..f84c40c 100644
@@ -257,3 +257,8 @@ unsigned long add_buffer(struct kexec_info *info, 
 const void *buf,
       return add_buffer_phys_virt(info, buf, bufsz, memsz, buf_align,
                       buf_min, buf_max, buf_end, 1);

  }

kexec/arch/sh/kexec-sh.c +2 -0
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), 

struct kexec_info *UNUSED(info))

kexec/arch/sh/kexec-sh.c +3 -0
+{
+    return 0;
+}
Quoted 15 lines
Quoted 10 lines
kexec/arch/x86_64/kexec-x86_64.c +2 -0
index ffd84f0..42af90a 100644
@@ -188,3 +188,8 @@ void arch_update_purgatory(struct kexec_info *info)
       elf_rel_set_symbol(&info->rhdr, "panic_kernel",
                   &panic_kernel, sizeof(panic_kernel));
   }
+
+int arch_do_exclude_segment(struct kexec_segment *UNUSED(seg_ptr), 
Quoted 2 lines

struct kexec_info *UNUSED(info))
+{

This should also be similar to i386, no?
Except for that, rest looks good..

In kexec tools, hotplug support for the kexec_load syscall is not yet enabled for x86_64. Hence, the function returns 0.

Quoted 2 lines

Thank you for reviewing and giving an Ack to the patch.

- Sourabh Jain

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