Skip to contentSkip to conversation

powerpc/crash: Kernel handling of CPU and memory hotplug

PATCH Superseded Sourabh Jain 2 participants 9 messages Feb 17, 2024 – Feb 22, 2024

Subsystems (8)
x86 PowerPC Driver core Live update +4 more subsystems

v16 of 19 Superseded Latest is v19 →

lore
Share & tools
lore
#0 lore raw

v16 cover powerpc/crash: Kernel handling of CPU and memory hotplug

Commit 247262756121 ("crash: add generic infrastructure for crash hotplug support") added a generic infrastructure that allows architectures to selectively update the kdump image component during CPU or memory add/remove events within the kernel itself.

This patch series adds crash hotplug handler for PowerPC and enable support to update the kdump image on CPU/Memory add/remove events.

Among the 5 patches in this series, the first two patches make changes to the generic crash hotplug handler to assist PowerPC in adding support for this feature. The last three patches add support for this feature.

The following section outlines the problem addressed by this patch series, along with the current solution, its shortcomings, and the proposed resolution.

Problem:
========
Due to CPU/Memory hotplug or online/offline events the elfcorehdr (which describes the CPUs and memory of the crashed kernel) and FDT (Flattened Device Tree) of kdump image becomes outdated. Consequently, attempting dump collection with an outdated elfcorehdr or FDT can lead to failed or inaccurate dump collection.

Going forward CPU hotplug or online/offline events are referred as CPU/Memory add/remove events.

Existing solution and its shortcoming:
======================================
The current solution to address the above issue involves monitoring the CPU/memory add/remove events in userspace using udev rules and whenever there are changes in CPU and memory resources, the entire kdump image is loaded again. The kdump image includes kernel, initrd, elfcorehdr, FDT, purgatory. Given that only elfcorehdr and FDT get outdated due to CPU/Memory add/remove events, reloading the entire kdump image is inefficient. More importantly, kdump remains inactive for a substantial amount of time until the kdump reload completes.

Proposed solution:
==================
Instead of initiating a full kdump image reload from userspace on CPU/Memory hotplug and online/offline events, the proposed solution aims to update only the necessary kdump image component within the kernel itself.

Git tree for testing:
=====================
Git tree rebased on top of v6.8-rc4:
https://github.com/sourabhjains/linux/tree/kdump-in-kernel-crash-update-v16

To realize this feature, the kdump udev rule must be updated. On RHEL, add the following two lines at the top of the "/usr/lib/udev/rules.d/98-kexec.rules" file.

SUBSYSTEM=="cpu", ATTRS{crash_hotplug}=="1", GOTO="kdump_reload_end" SUBSYSTEM=="memory", ATTRS{crash_hotplug}=="1", GOTO="kdump_reload_end"

With the above change to the kdump udev rule, kdump reload is avoided during CPU/Memory add/remove events if this feature is enabled in the kernel.

Note: only kexec_file_load syscall will work. For kexec_load minor changes are required in kexec tool.

Changelog:
----------
v16:
- Remove the unused #define crash_hotplug_cpu_support
and crash_hotplug_memory_support in arch/x86/include/asm/kexec.h.
- Document why two kexec flag bits are used in

    `arch_crash_hotplug_memory_support` (x86).

- Use a switch case to handle different hotplug operations in arch_crash_handle_hotplug_event for PowerPC.
- Fix a typo in 4/5.

v15:
- Remove the patch that adds a new kexec flag for FDT update.
- Introduce a generic kexec flag bit to share hotplug support intent between the kexec tool and the kernel for the kexec_load syscall. (2/5)
- Introduce an architecture-specific handler to process the kexec flag for crash hotplug support. (2/5)
- Rename the @update_elfcorehdr member of the struct kimage to

    @hotplug_support. (2/5)
  - Use a common function to advertise hotplug support for both CPU
    and Memory. (2/5)

v14:
- Fix build warnings by including necessary header files
- Rebase to v6.7-rc5

v13:
- Fix a build warning, take ranges.c out of CONFIG_KEXEC_FILE
- Rebase to v6.7-rc4

v12:
- A patch to add new kexec flags to support this feature on kexec_load system call
- Change in the way this feature is advertise to userspace for both kexec_load syscall
- Rebase to v6.6-rc7

v11:
- Rebase to v6.4-rc6
- The patch that introduced CONFIG_CRASH_HOTPLUG for PowerPC has been removed. The config is now part of common configuration:
https://lore.kernel.org/all/[email protected]/

v10:
- Drop the patch that adds fdt_index attribute to struct kimage_arch Find the fdt segment index when needed.
- Added more details into commits messages.
- Rebased onto 6.3.0-rc5

v9:
- Removed patch to prepare elfcorehdr crash notes for possible CPUs. The patch is moved to generic patch series that introduces generic infrastructure for in kernel crash update.
- Removed patch to pass the hotplug action type to the arch crash hotplug handler function. The generic patch series has introduced the hotplug action type in kimage struct.
- Add detail commit message for better understanding.

v8:
- Restrict fdt_index initialization to machine_kexec_post_load it work for both kexec_load and kexec_file_load.[3/8] Laurent Dufour

- Updated the logic to find the number of offline core. [6/8]

- Changed the logic to find the elfcore program header to accommodate future memory ranges due memory hotplug events. [8/8]

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

v6
- Added crash memory hotplug support

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

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

v3
- Move fdt_index and fdt_index_vaild variables to kimage_arch struct.
- Rebase patche on top of

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

- Fixed warning reported by checpatch script

v2:
- Use generic hotplug handler introduced by
https://lore.kernel.org/lkml/[email protected]/
a significant change from v1.

Cc Akhil Raj <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Aneesh Kumar K.V <[email protected]>
Cc Baoquan He <[email protected]>
Cc Borislav Petkov (AMD) <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Christophe Leroy <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Dave Young <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Hari Bathini <[email protected]>
Cc Laurent Dufour <[email protected]>
Cc Mahesh Salgaonkar <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Mimi Zohar <[email protected]>
Cc Naveen N Rao <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Valentin Schneider <[email protected]>
Cc Vivek Goyal <[email protected]>

Sourabh Jain (5):
crash: forward memory_notify arg to arch crash hotplug handler
crash: add a new kexec flag for hotplug support powerpc/kexec: turn some static helper functions public
powerpc: add crash CPU hotplug support
powerpc: add crash memory hotplug support

 arch/powerpc/Kconfig                    |   4 +
 arch/powerpc/include/asm/kexec.h        |  15 +
 arch/powerpc/include/asm/kexec_ranges.h |   1 +
 arch/powerpc/kexec/Makefile             |   4 +-
 arch/powerpc/kexec/core_64.c            | 362 ++++++++++++++++++++++++
 arch/powerpc/kexec/elf_64.c             |  12 +-
 arch/powerpc/kexec/file_load_64.c       | 211 ++++----------
 arch/powerpc/kexec/ranges.c             |  85 ++++++
 arch/x86/include/asm/kexec.h            |  13 +-
 arch/x86/kernel/crash.c                 |  31 +-
 drivers/base/cpu.c                      |   2 +-
 drivers/base/memory.c                   |   2 +-
 include/linux/kexec.h                   |  29 +-
 include/uapi/linux/kexec.h              |   1 +
 kernel/crash_core.c                     |  25 +-
 kernel/kexec.c                          |   4 +-
 kernel/kexec_file.c                     |   5 +
 17 files changed, 589 insertions(+), 217 deletions(-)
Signature · 7 lines
2.43.0


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

PATCH v16 1/5 crash: forward memory_notify arg to arch crash hotplug handler

In the event of memory hotplug or online/offline events, the crash memory hotplug notifier crash_memhp_notifier() receives a memory_notify object but doesn't forward that object to the generic and architecture-specific crash hotplug handler.

The memory_notify object contains the starting PFN (Page Frame Number) and the number of pages in the hot-removed memory. This information is necessary for architectures like PowerPC to update/recreate the kdump image, specifically elfcorehdr.

So update the function signature of crash_handle_hotplug_event() and arch_crash_handle_hotplug_event() to accept the memory_notify object as an argument from crash memory hotplug notifier.

Since no such object is available in the case of CPU hotplug event, the crash CPU hotplug notifier crash_cpuhp_online() passes NULL to the crash hotplug handler.

Cc Akhil Raj <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Aneesh Kumar K.V <[email protected]>
Cc Borislav Petkov (AMD) <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Christophe Leroy <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Dave Young <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Hari Bathini <[email protected]>
Cc Laurent Dufour <[email protected]>
Cc Mahesh Salgaonkar <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Mimi Zohar <[email protected]>
Cc Naveen N Rao <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Valentin Schneider <[email protected]>
Cc Vivek Goyal <[email protected]>
---
 arch/x86/include/asm/kexec.h |  2 +-
 arch/x86/kernel/crash.c      |  3 ++-
 include/linux/kexec.h        |  2 +-
 kernel/crash_core.c          | 14 +++++++-------
 4 files changed, 11 insertions(+), 10 deletions(-)
arch/x86/include/asm/kexec.h +1 -1
index c9f6a6c5de3c..9bb6607e864e 100644
@@ -208,7 +208,7 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image);
 extern void kdump_nmi_shootdown_cpus(void);
 
 #ifdef CONFIG_CRASH_HOTPLUG
-void arch_crash_handle_hotplug_event(struct kimage *image);
+void arch_crash_handle_hotplug_event(struct kimage *image, void *arg);
 #define arch_crash_handle_hotplug_event arch_crash_handle_hotplug_event
 
 #ifdef CONFIG_HOTPLUG_CPU
arch/x86/kernel/crash.c +2 -1
index b6b044356f1b..44744e9c68ec 100644
@@ -428,10 +428,11 @@ unsigned int arch_crash_get_elfcorehdr_size(void)
 /**
  * arch_crash_handle_hotplug_event() - Handle hotplug elfcorehdr changes
  * @image: a pointer to kexec_crash_image
+ * @arg: struct memory_notify handler for memory hotplug case and NULL for CPU hotplug case.
  *
  * Prepare the new elfcorehdr and replace the existing elfcorehdr.
  */
-void arch_crash_handle_hotplug_event(struct kimage *image)
+void arch_crash_handle_hotplug_event(struct kimage *image, void *arg)
 {
 	void *elfbuf = NULL, *old_elfcorehdr;
 	unsigned long nr_mem_ranges;
include/linux/kexec.h +1 -1
index 400cb6c02176..802052d9c64b 100644
@@ -483,7 +483,7 @@ static inline void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages) {
 #endif
 
 #ifndef arch_crash_handle_hotplug_event
-static inline void arch_crash_handle_hotplug_event(struct kimage *image) { }
+static inline void arch_crash_handle_hotplug_event(struct kimage *image, void *arg) { }
 #endif
 
 int crash_check_update_elfcorehdr(void);
kernel/crash_core.c +7 -7
index 75cd6a736d03..b692ec5955de 100644
@@ -924,7 +924,7 @@ int crash_check_update_elfcorehdr(void)
  * list of segments it checks (since the elfcorehdr changes and thus
  * would require an update to purgatory itself to update the digest).
  */
-static void crash_handle_hotplug_event(unsigned int hp_action, unsigned int cpu)
+static void crash_handle_hotplug_event(unsigned int hp_action, unsigned int cpu, void *arg)
 {
 	struct kimage *image;
 
@@ -986,7 +986,7 @@ static void crash_handle_hotplug_event(unsigned int hp_action, unsigned int cpu)
 	image->hp_action = hp_action;
 
 	/* Now invoke arch-specific update handler */
-	arch_crash_handle_hotplug_event(image);
+	arch_crash_handle_hotplug_event(image, arg);
 
 	/* No longer handling a hotplug event */
 	image->hp_action = KEXEC_CRASH_HP_NONE;
@@ -1002,17 +1002,17 @@ static void crash_handle_hotplug_event(unsigned int hp_action, unsigned int cpu)
 	crash_hotplug_unlock();
 }
 
-static int crash_memhp_notifier(struct notifier_block *nb, unsigned long val, void *v)
+static int crash_memhp_notifier(struct notifier_block *nb, unsigned long val, void *arg)
 {
 	switch (val) {
 	case MEM_ONLINE:
 		crash_handle_hotplug_event(KEXEC_CRASH_HP_ADD_MEMORY,
-			KEXEC_CRASH_HP_INVALID_CPU);
+			KEXEC_CRASH_HP_INVALID_CPU, arg);
 		break;
 
 	case MEM_OFFLINE:
 		crash_handle_hotplug_event(KEXEC_CRASH_HP_REMOVE_MEMORY,
-			KEXEC_CRASH_HP_INVALID_CPU);
+			KEXEC_CRASH_HP_INVALID_CPU, arg);
 		break;
 	}
 	return NOTIFY_OK;
@@ -1025,13 +1025,13 @@ static struct notifier_block crash_memhp_nb = {
 
 static int crash_cpuhp_online(unsigned int cpu)
 {
-	crash_handle_hotplug_event(KEXEC_CRASH_HP_ADD_CPU, cpu);
+	crash_handle_hotplug_event(KEXEC_CRASH_HP_ADD_CPU, cpu, NULL);
 	return 0;
 }
 
 static int crash_cpuhp_offline(unsigned int cpu)
 {
-	crash_handle_hotplug_event(KEXEC_CRASH_HP_REMOVE_CPU, cpu);
+	crash_handle_hotplug_event(KEXEC_CRASH_HP_REMOVE_CPU, cpu, NULL);
 	return 0;
 }
 
Signature · 7 lines
2.43.0


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

PATCH v16 2/5 crash: add a new kexec flag for hotplug support

In reply to Sourabh Jain

Commit a72bbec70da2 ("crash: hotplug support for kexec_load()") introduced a new kexec flag, KEXEC_UPDATE_ELFCOREHDR. Kexec tool uses this flag to indicate to the kernel that it is safe to modify the elfcorehdr of the kdump image loaded using the kexec_load system call.

However, it is possible that architectures may need to update kexec segments other then elfcorehdr. For example, FDT (Flatten Device Tree) on PowerPC. Introducing a new kexec flag for every new kexec segment may not be a good solution. Hence, a generic kexec flag bit, KEXEC_CRASH_HOTPLUG_SUPPORT, is introduced to share the CPU/Memory hotplug support intent between the kexec tool and the kernel for the kexec_load system call.

Now, if the kexec tool sends KEXEC_CRASH_HOTPLUG_SUPPORT kexec flag to the kernel, it indicates to the kernel that all the required kexec segment is skipped from SHA calculation and it is safe to update kdump image loaded using the kexec_load syscall.

While loading the kdump image using the kexec_load syscall, the @update_elfcorehdr member of struct kimage is set if the kexec tool sends the KEXEC_UPDATE_ELFCOREHDR kexec flag. This member is later used to determine whether it is safe to update elfcorehdr on hotplug events. However, with the introduction of the KEXEC_CRASH_HOTPLUG_SUPPORT kexec flag, the kexec tool could mark all the required kexec segments on an architecture as safe to update. So rename the @update_elfcorehdr to @hotplug_support. If @hotplug_support is set, the kernel can safely update all the required kexec segments of the kdump image during CPU/Memory hotplug events.

Introduce an architecture-specific function to process kexec flags for determining hotplug support. Set the @hotplug_support member of struct kimage for both kexec_load and kexec_file_load system calls. This simplifies kernel checks to identify hotplug support for the currently loaded kdump image by just examining the value of @hotplug_support.

Cc Akhil Raj <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Aneesh Kumar K.V <[email protected]>
Cc Baoquan He <[email protected]>
Cc Borislav Petkov (AMD) <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Christophe Leroy <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Dave Young <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Eric DeVolder <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Hari Bathini <[email protected]>
Cc Laurent Dufour <[email protected]>
Cc Mahesh Salgaonkar <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Mimi Zohar <[email protected]>
Cc Naveen N Rao <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Valentin Schneider <[email protected]>
Cc Vivek Goyal <[email protected]>
---
 arch/x86/include/asm/kexec.h | 11 ++---------
 arch/x86/kernel/crash.c      | 28 +++++++++++++++++-----------
 drivers/base/cpu.c           |  2 +-
 drivers/base/memory.c        |  2 +-
 include/linux/kexec.h        | 27 +++++++++++++++++----------
 include/uapi/linux/kexec.h   |  1 +
 kernel/crash_core.c          | 11 ++++-------
 kernel/kexec.c               |  4 ++--
 kernel/kexec_file.c          |  5 +++++
 9 files changed, 50 insertions(+), 41 deletions(-)
arch/x86/include/asm/kexec.h +2 -9
index 9bb6607e864e..8be622e82ba8 100644
@@ -211,15 +211,8 @@ extern void kdump_nmi_shootdown_cpus(void);
 void arch_crash_handle_hotplug_event(struct kimage *image, void *arg);
 #define arch_crash_handle_hotplug_event arch_crash_handle_hotplug_event
 
-#ifdef CONFIG_HOTPLUG_CPU
-int arch_crash_hotplug_cpu_support(void);
-#define crash_hotplug_cpu_support arch_crash_hotplug_cpu_support
-#endif
-
-#ifdef CONFIG_MEMORY_HOTPLUG
-int arch_crash_hotplug_memory_support(void);
-#define crash_hotplug_memory_support arch_crash_hotplug_memory_support
-#endif
+int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_flags);
+#define arch_crash_hotplug_support arch_crash_hotplug_support
 
 unsigned int arch_crash_get_elfcorehdr_size(void);
 #define crash_get_elfcorehdr_size arch_crash_get_elfcorehdr_size
arch/x86/kernel/crash.c +17 -11
index 44744e9c68ec..7072aaee2ea0 100644
@@ -398,20 +398,26 @@ int crash_load_segments(struct kimage *image)
 #undef pr_fmt
 #define pr_fmt(fmt) "crash hp: " fmt
 
-/* These functions provide the value for the sysfs crash_hotplug nodes */
-#ifdef CONFIG_HOTPLUG_CPU
-int arch_crash_hotplug_cpu_support(void)
+int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_flags)
 {
-	return crash_check_update_elfcorehdr();
-}
-#endif
 
-#ifdef CONFIG_MEMORY_HOTPLUG
-int arch_crash_hotplug_memory_support(void)
-{
-	return crash_check_update_elfcorehdr();
-}
+#ifdef CONFIG_KEXEC_FILE
+	if (image->file_mode)
+		return 1;
 #endif
+	/*
+	 * Initially, crash hotplug support for kexec_load was added
+	 * with the KEXEC_UPDATE_ELFCOREHDR flag. Later, this
+	 * functionality was expanded to accommodate multiple kexec
+	 * segment updates, leading to the introduction of the
+	 * KEXEC_CRASH_HOTPLUG_SUPPORT kexec flag bit. Consequently,
+	 * when the kexec tool sends either of these flags, it indicates
+	 * that the required kexec segment (elfcorehdr) is excluded from
+	 * the SHA calculation.
+	 */
+	return (kexec_flags & KEXEC_UPDATE_ELFCOREHDR ||
+		kexec_flags & KEXEC_CRASH_HOTPLUG_SUPPORT);
+}
 
 unsigned int arch_crash_get_elfcorehdr_size(void)
 {
drivers/base/cpu.c +1 -1
index 47de0f140ba6..24eb52607151 100644
@@ -306,7 +306,7 @@ static ssize_t crash_hotplug_show(struct device *dev,
 				     struct device_attribute *attr,
 				     char *buf)
 {
-	return sysfs_emit(buf, "%d\n", crash_hotplug_cpu_support());
+	return sysfs_emit(buf, "%d\n", crash_check_hotplug_support());
 }
 static DEVICE_ATTR_ADMIN_RO(crash_hotplug);
 #endif
drivers/base/memory.c +1 -1
index 14f964a7719b..b80be8193970 100644
@@ -514,7 +514,7 @@ static DEVICE_ATTR_RW(auto_online_blocks);
 static ssize_t crash_hotplug_show(struct device *dev,
 				       struct device_attribute *attr, char *buf)
 {
-	return sysfs_emit(buf, "%d\n", crash_hotplug_memory_support());
+	return sysfs_emit(buf, "%d\n", crash_check_hotplug_support());
 }
 static DEVICE_ATTR_RO(crash_hotplug);
 #endif
include/linux/kexec.h +17 -10
index 802052d9c64b..175152b99cb7 100644
@@ -317,8 +317,10 @@ struct kimage {
 	/* If set, we are using file mode kexec syscall */
 	unsigned int file_mode:1;
 #ifdef CONFIG_CRASH_HOTPLUG
-	/* If set, allow changes to elfcorehdr of kexec_load'd image */
-	unsigned int update_elfcorehdr:1;
+	/* If set, it is safe to update kexec segments that are
+	 * excluded from SHA calculation.
+	 */
+	unsigned int hotplug_support:1;
 #endif
 
 #ifdef ARCH_HAS_KIMAGE_ARCH
@@ -396,9 +398,10 @@ bool kexec_load_permitted(int kexec_image_type);
 
 /* List of defined/legal kexec flags */
 #ifndef CONFIG_KEXEC_JUMP
-#define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_UPDATE_ELFCOREHDR)
+#define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_UPDATE_ELFCOREHDR | KEXEC_CRASH_HOTPLUG_SUPPORT)
 #else
-#define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT | KEXEC_UPDATE_ELFCOREHDR)
+#define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT | KEXEC_UPDATE_ELFCOREHDR | \
+			KEXEC_CRASH_HOTPLUG_SUPPORT)
 #endif
 
 /* List of defined/legal kexec file flags */
@@ -486,14 +489,18 @@ static inline void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages) {
 static inline void arch_crash_handle_hotplug_event(struct kimage *image, void *arg) { }
 #endif
 
-int crash_check_update_elfcorehdr(void);
+int crash_check_hotplug_support(void);
 
-#ifndef crash_hotplug_cpu_support
-static inline int crash_hotplug_cpu_support(void) { return 0; }
-#endif
+#ifndef arch_crash_hotplug_support
+static inline int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_flags)
+{
 
-#ifndef crash_hotplug_memory_support
-static inline int crash_hotplug_memory_support(void) { return 0; }
+#ifdef CONFIG_KEXEC_FILE
+	if (image->file_mode)
+		return 1;
+#endif
+	return kexec_flags & KEXEC_CRASH_HOTPLUG_SUPPORT;
+}
 #endif
 
 #ifndef crash_get_elfcorehdr_size
include/uapi/linux/kexec.h +1 -0
index c17bb096ea68..5ae1741ea8ea 100644
@@ -13,6 +13,7 @@
 #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
 
 /*
kernel/crash_core.c +4 -7
index b692ec5955de..3142884a5a5b 100644
@@ -886,7 +886,7 @@ static DEFINE_MUTEX(__crash_hotplug_lock);
  * It reflects the kernel's ability/permission to update the crash
  * elfcorehdr directly.
  */
-int crash_check_update_elfcorehdr(void)
+int crash_check_hotplug_support(void)
 {
 	int rc = 0;
 
@@ -898,10 +898,7 @@ int crash_check_update_elfcorehdr(void)
 		return 0;
 	}
 	if (kexec_crash_image) {
-		if (kexec_crash_image->file_mode)
-			rc = 1;
-		else
-			rc = kexec_crash_image->update_elfcorehdr;
+		rc = kexec_crash_image->hotplug_support;
 	}
 	/* Release lock now that update complete */
 	kexec_unlock();
@@ -942,8 +939,8 @@ static void crash_handle_hotplug_event(unsigned int hp_action, unsigned int cpu,
 
 	image = kexec_crash_image;
 
-	/* Check that updating elfcorehdr is permitted */
-	if (!(image->file_mode || image->update_elfcorehdr))
+	/* Check that kexec segments update is permitted */
+	if (!image->hotplug_support)
 		goto out;
 
 	if (hp_action == KEXEC_CRASH_HP_ADD_CPU ||
kernel/kexec.c +2 -2
index 8f35a5a42af8..9dc5b7ed5b73 100644
@@ -130,8 +130,8 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
 		image->preserve_context = 1;
 
 #ifdef CONFIG_CRASH_HOTPLUG
-	if (flags & KEXEC_UPDATE_ELFCOREHDR)
-		image->update_elfcorehdr = 1;
+	if ((flags & KEXEC_ON_CRASH) && arch_crash_hotplug_support(image, flags))
+		image->hotplug_support = 1;
 #endif
 
 	ret = machine_kexec_prepare(image);
kernel/kexec_file.c +5 -0
index bef2f6f2571b..4dddf9264a69 100644
@@ -373,6 +373,11 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd,
 	if (ret)
 		goto out;
 
+#ifdef CONFIG_CRASH_HOTPLUG
+	if ((flags & KEXEC_FILE_ON_CRASH) && arch_crash_hotplug_support(image, flags))
+		image->hotplug_support = 1;
+#endif
+
 	ret = machine_kexec_prepare(image);
 	if (ret)
 		goto out;
Signature · 7 lines
2.43.0


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

Re: [PATCH v16 2/5] crash: add a new kexec flag for hotplug support

Hello Baoquan,

There are a lot of code movements introduced by your patch series, 'Split crash out from kexec and clean up related config items.'

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

Do you want me to rebase this patch series on top of the above patch series?

Thanks,
Sourabh Jain

Quoted 286 lines · Sourabh Jain

Commit a72bbec70da2 ("crash: hotplug support for kexec_load()") introduced a new kexec flag, KEXEC_UPDATE_ELFCOREHDR. Kexec tool uses this flag to indicate to the kernel that it is safe to modify the elfcorehdr of the kdump image loaded using the kexec_load system call.

However, it is possible that architectures may need to update kexec segments other then elfcorehdr. For example, FDT (Flatten Device Tree) on PowerPC. Introducing a new kexec flag for every new kexec segment may not be a good solution. Hence, a generic kexec flag bit, KEXEC_CRASH_HOTPLUG_SUPPORT, is introduced to share the CPU/Memory hotplug support intent between the kexec tool and the kernel for the kexec_load system call.

Now, if the kexec tool sends KEXEC_CRASH_HOTPLUG_SUPPORT kexec flag to the kernel, it indicates to the kernel that all the required kexec segment is skipped from SHA calculation and it is safe to update kdump image loaded using the kexec_load syscall.

While loading the kdump image using the kexec_load syscall, the @update_elfcorehdr member of struct kimage is set if the kexec tool sends the KEXEC_UPDATE_ELFCOREHDR kexec flag. This member is later used to determine whether it is safe to update elfcorehdr on hotplug events. However, with the introduction of the KEXEC_CRASH_HOTPLUG_SUPPORT kexec flag, the kexec tool could mark all the required kexec segments on an architecture as safe to update. So rename the @update_elfcorehdr to @hotplug_support. If @hotplug_support is set, the kernel can safely update all the required kexec segments of the kdump image during CPU/Memory hotplug events.

Introduce an architecture-specific function to process kexec flags for determining hotplug support. Set the @hotplug_support member of struct kimage for both kexec_load and kexec_file_load system calls. This simplifies kernel checks to identify hotplug support for the currently loaded kdump image by just examining the value of @hotplug_support.

Cc Akhil Raj <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Aneesh Kumar K.V <[email protected]>
Cc Baoquan He <[email protected]>
Cc Borislav Petkov (AMD) <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Christophe Leroy <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Dave Young <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Eric DeVolder <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Hari Bathini <[email protected]>
Cc Laurent Dufour <[email protected]>
Cc Mahesh Salgaonkar <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Mimi Zohar <[email protected]>
Cc Naveen N Rao <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Valentin Schneider <[email protected]>
Cc Vivek Goyal <[email protected]>
---
  arch/x86/include/asm/kexec.h | 11 ++---------
  arch/x86/kernel/crash.c      | 28 +++++++++++++++++-----------
  drivers/base/cpu.c           |  2 +-
  drivers/base/memory.c        |  2 +-
  include/linux/kexec.h        | 27 +++++++++++++++++----------
  include/uapi/linux/kexec.h   |  1 +
  kernel/crash_core.c          | 11 ++++-------
  kernel/kexec.c               |  4 ++--
  kernel/kexec_file.c          |  5 +++++
  9 files changed, 50 insertions(+), 41 deletions(-)
arch/x86/include/asm/kexec.h +2 -9
index 9bb6607e864e..8be622e82ba8 100644
@@ -211,15 +211,8 @@ extern void kdump_nmi_shootdown_cpus(void);
  void arch_crash_handle_hotplug_event(struct kimage *image, void *arg);
  #define arch_crash_handle_hotplug_event arch_crash_handle_hotplug_event
 
-#ifdef CONFIG_HOTPLUG_CPU
-int arch_crash_hotplug_cpu_support(void);
-#define crash_hotplug_cpu_support arch_crash_hotplug_cpu_support
-#endif
-
-#ifdef CONFIG_MEMORY_HOTPLUG
-int arch_crash_hotplug_memory_support(void);
-#define crash_hotplug_memory_support arch_crash_hotplug_memory_support
-#endif
+int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_flags);
+#define arch_crash_hotplug_support arch_crash_hotplug_support
 
  unsigned int arch_crash_get_elfcorehdr_size(void);
  #define crash_get_elfcorehdr_size arch_crash_get_elfcorehdr_size
arch/x86/kernel/crash.c +17 -11
index 44744e9c68ec..7072aaee2ea0 100644
@@ -398,20 +398,26 @@ int crash_load_segments(struct kimage *image)
  #undef pr_fmt
  #define pr_fmt(fmt) "crash hp: " fmt
 
-/* These functions provide the value for the sysfs crash_hotplug nodes */
-#ifdef CONFIG_HOTPLUG_CPU
-int arch_crash_hotplug_cpu_support(void)
+int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_flags)
  {
-	return crash_check_update_elfcorehdr();
-}
-#endif
 
-#ifdef CONFIG_MEMORY_HOTPLUG
-int arch_crash_hotplug_memory_support(void)
-{
-	return crash_check_update_elfcorehdr();
-}
+#ifdef CONFIG_KEXEC_FILE
+	if (image->file_mode)
+		return 1;
  #endif
+	/*
+	 * Initially, crash hotplug support for kexec_load was added
+	 * with the KEXEC_UPDATE_ELFCOREHDR flag. Later, this
+	 * functionality was expanded to accommodate multiple kexec
+	 * segment updates, leading to the introduction of the
+	 * KEXEC_CRASH_HOTPLUG_SUPPORT kexec flag bit. Consequently,
+	 * when the kexec tool sends either of these flags, it indicates
+	 * that the required kexec segment (elfcorehdr) is excluded from
+	 * the SHA calculation.
+	 */
+	return (kexec_flags & KEXEC_UPDATE_ELFCOREHDR ||
+		kexec_flags & KEXEC_CRASH_HOTPLUG_SUPPORT);
+}
 
  unsigned int arch_crash_get_elfcorehdr_size(void)
  {
drivers/base/cpu.c +1 -1
index 47de0f140ba6..24eb52607151 100644
@@ -306,7 +306,7 @@ static ssize_t crash_hotplug_show(struct device *dev,
  				     struct device_attribute *attr,
  				     char *buf)
  {
-	return sysfs_emit(buf, "%d\n", crash_hotplug_cpu_support());
+	return sysfs_emit(buf, "%d\n", crash_check_hotplug_support());
  }
  static DEVICE_ATTR_ADMIN_RO(crash_hotplug);
  #endif
drivers/base/memory.c +1 -1
index 14f964a7719b..b80be8193970 100644
@@ -514,7 +514,7 @@ static DEVICE_ATTR_RW(auto_online_blocks);
  static ssize_t crash_hotplug_show(struct device *dev,
  				       struct device_attribute *attr, char *buf)
  {
-	return sysfs_emit(buf, "%d\n", crash_hotplug_memory_support());
+	return sysfs_emit(buf, "%d\n", crash_check_hotplug_support());
  }
  static DEVICE_ATTR_RO(crash_hotplug);
  #endif
include/linux/kexec.h +17 -10
index 802052d9c64b..175152b99cb7 100644
@@ -317,8 +317,10 @@ struct kimage {
  	/* If set, we are using file mode kexec syscall */
  	unsigned int file_mode:1;
  #ifdef CONFIG_CRASH_HOTPLUG
-	/* If set, allow changes to elfcorehdr of kexec_load'd image */
-	unsigned int update_elfcorehdr:1;
+	/* If set, it is safe to update kexec segments that are
+	 * excluded from SHA calculation.
+	 */
+	unsigned int hotplug_support:1;
  #endif
 
  #ifdef ARCH_HAS_KIMAGE_ARCH
@@ -396,9 +398,10 @@ bool kexec_load_permitted(int kexec_image_type);
 
  /* List of defined/legal kexec flags */
  #ifndef CONFIG_KEXEC_JUMP
-#define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_UPDATE_ELFCOREHDR)
+#define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_UPDATE_ELFCOREHDR | KEXEC_CRASH_HOTPLUG_SUPPORT)
  #else
-#define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT | KEXEC_UPDATE_ELFCOREHDR)
+#define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT | KEXEC_UPDATE_ELFCOREHDR | \
+			KEXEC_CRASH_HOTPLUG_SUPPORT)
  #endif
 
  /* List of defined/legal kexec file flags */
@@ -486,14 +489,18 @@ static inline void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages) {
  static inline void arch_crash_handle_hotplug_event(struct kimage *image, void *arg) { }
  #endif
 
-int crash_check_update_elfcorehdr(void);
+int crash_check_hotplug_support(void);
 
-#ifndef crash_hotplug_cpu_support
-static inline int crash_hotplug_cpu_support(void) { return 0; }
-#endif
+#ifndef arch_crash_hotplug_support
+static inline int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_flags)
+{
 
-#ifndef crash_hotplug_memory_support
-static inline int crash_hotplug_memory_support(void) { return 0; }
+#ifdef CONFIG_KEXEC_FILE
+	if (image->file_mode)
+		return 1;
+#endif
+	return kexec_flags & KEXEC_CRASH_HOTPLUG_SUPPORT;
+}
  #endif
 
  #ifndef crash_get_elfcorehdr_size
include/uapi/linux/kexec.h +1 -0
index c17bb096ea68..5ae1741ea8ea 100644
@@ -13,6 +13,7 @@
  #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
 
  /*
kernel/crash_core.c +4 -7
index b692ec5955de..3142884a5a5b 100644
@@ -886,7 +886,7 @@ static DEFINE_MUTEX(__crash_hotplug_lock);
   * It reflects the kernel's ability/permission to update the crash
   * elfcorehdr directly.
   */
-int crash_check_update_elfcorehdr(void)
+int crash_check_hotplug_support(void)
  {
  	int rc = 0;
 
@@ -898,10 +898,7 @@ int crash_check_update_elfcorehdr(void)
  		return 0;
  	}
  	if (kexec_crash_image) {
-		if (kexec_crash_image->file_mode)
-			rc = 1;
-		else
-			rc = kexec_crash_image->update_elfcorehdr;
+		rc = kexec_crash_image->hotplug_support;
  	}
  	/* Release lock now that update complete */
  	kexec_unlock();
@@ -942,8 +939,8 @@ static void crash_handle_hotplug_event(unsigned int hp_action, unsigned int cpu,
 
  	image = kexec_crash_image;
 
-	/* Check that updating elfcorehdr is permitted */
-	if (!(image->file_mode || image->update_elfcorehdr))
+	/* Check that kexec segments update is permitted */
+	if (!image->hotplug_support)
  		goto out;
 
  	if (hp_action == KEXEC_CRASH_HP_ADD_CPU ||
kernel/kexec.c +2 -2
index 8f35a5a42af8..9dc5b7ed5b73 100644
@@ -130,8 +130,8 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
  		image->preserve_context = 1;
 
  #ifdef CONFIG_CRASH_HOTPLUG
-	if (flags & KEXEC_UPDATE_ELFCOREHDR)
-		image->update_elfcorehdr = 1;
+	if ((flags & KEXEC_ON_CRASH) && arch_crash_hotplug_support(image, flags))
+		image->hotplug_support = 1;
  #endif
 
  	ret = machine_kexec_prepare(image);
kernel/kexec_file.c +0 -0
index bef2f6f2571b..4dddf9264a69 100644
@@ -373,6 +373,11 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd,
  	if (ret)

kernel/kexec_file.c SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd, · line 383

Quoted 10 lines
kernel/kexec_file.c +5 -0
  		goto out;
 
+#ifdef CONFIG_CRASH_HOTPLUG
+	if ((flags & KEXEC_FILE_ON_CRASH) && arch_crash_hotplug_support(image, flags))
+		image->hotplug_support = 1;
+#endif
+
  	ret = machine_kexec_prepare(image);
  	if (ret)
  		goto out;

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

#4 lore raw

Re: [PATCH v16 2/5] crash: add a new kexec flag for hotplug support

Quoted 8 lines · Sourabh Jain

Hello Baoquan,

There are a lot of code movements introduced by your patch series, 'Split crash out from kexec and clean up related config items.'

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

Do you want me to rebase this patch series on top of the above patch series?

Yes, appreciate that, that would be very helpful. Rebasing this to latest next/master. And I saw Hari's patch sereis, basically it's fine to me. It will be great if this patch can sit on that patchset.

Thanks
Baoquan

Quoted 270 lines · Sourabh Jain
Quoted 268 lines

Commit a72bbec70da2 ("crash: hotplug support for kexec_load()") introduced a new kexec flag, KEXEC_UPDATE_ELFCOREHDR. Kexec tool uses this flag to indicate to the kernel that it is safe to modify the elfcorehdr of the kdump image loaded using the kexec_load system call.

However, it is possible that architectures may need to update kexec segments other then elfcorehdr. For example, FDT (Flatten Device Tree) on PowerPC. Introducing a new kexec flag for every new kexec segment may not be a good solution. Hence, a generic kexec flag bit, KEXEC_CRASH_HOTPLUG_SUPPORT, is introduced to share the CPU/Memory hotplug support intent between the kexec tool and the kernel for the kexec_load system call.

Now, if the kexec tool sends KEXEC_CRASH_HOTPLUG_SUPPORT kexec flag to the kernel, it indicates to the kernel that all the required kexec segment is skipped from SHA calculation and it is safe to update kdump image loaded using the kexec_load syscall.

While loading the kdump image using the kexec_load syscall, the @update_elfcorehdr member of struct kimage is set if the kexec tool sends the KEXEC_UPDATE_ELFCOREHDR kexec flag. This member is later used to determine whether it is safe to update elfcorehdr on hotplug events. However, with the introduction of the KEXEC_CRASH_HOTPLUG_SUPPORT kexec flag, the kexec tool could mark all the required kexec segments on an architecture as safe to update. So rename the @update_elfcorehdr to @hotplug_support. If @hotplug_support is set, the kernel can safely update all the required kexec segments of the kdump image during CPU/Memory hotplug events.

Introduce an architecture-specific function to process kexec flags for determining hotplug support. Set the @hotplug_support member of struct kimage for both kexec_load and kexec_file_load system calls. This simplifies kernel checks to identify hotplug support for the currently loaded kdump image by just examining the value of @hotplug_support.

Cc Akhil Raj <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Aneesh Kumar K.V <[email protected]>
Cc Baoquan He <[email protected]>
Cc Borislav Petkov (AMD) <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Christophe Leroy <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Dave Young <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Eric DeVolder <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Hari Bathini <[email protected]>
Cc Laurent Dufour <[email protected]>
Cc Mahesh Salgaonkar <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Mimi Zohar <[email protected]>
Cc Naveen N Rao <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Valentin Schneider <[email protected]>
Cc Vivek Goyal <[email protected]>
---
  arch/x86/include/asm/kexec.h | 11 ++---------
  arch/x86/kernel/crash.c      | 28 +++++++++++++++++-----------
  drivers/base/cpu.c           |  2 +-
  drivers/base/memory.c        |  2 +-
  include/linux/kexec.h        | 27 +++++++++++++++++----------
  include/uapi/linux/kexec.h   |  1 +
  kernel/crash_core.c          | 11 ++++-------
  kernel/kexec.c               |  4 ++--
  kernel/kexec_file.c          |  5 +++++
  9 files changed, 50 insertions(+), 41 deletions(-)
arch/x86/include/asm/kexec.h +2 -9
index 9bb6607e864e..8be622e82ba8 100644
@@ -211,15 +211,8 @@ extern void kdump_nmi_shootdown_cpus(void);
  void arch_crash_handle_hotplug_event(struct kimage *image, void *arg);
  #define arch_crash_handle_hotplug_event arch_crash_handle_hotplug_event
-#ifdef CONFIG_HOTPLUG_CPU
-int arch_crash_hotplug_cpu_support(void);
-#define crash_hotplug_cpu_support arch_crash_hotplug_cpu_support
-#endif
-
-#ifdef CONFIG_MEMORY_HOTPLUG
-int arch_crash_hotplug_memory_support(void);
-#define crash_hotplug_memory_support arch_crash_hotplug_memory_support
-#endif
+int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_flags);
+#define arch_crash_hotplug_support arch_crash_hotplug_support
  unsigned int arch_crash_get_elfcorehdr_size(void);
  #define crash_get_elfcorehdr_size arch_crash_get_elfcorehdr_size
arch/x86/kernel/crash.c +17 -11
index 44744e9c68ec..7072aaee2ea0 100644
@@ -398,20 +398,26 @@ int crash_load_segments(struct kimage *image)
  #undef pr_fmt
  #define pr_fmt(fmt) "crash hp: " fmt
-/* These functions provide the value for the sysfs crash_hotplug nodes */
-#ifdef CONFIG_HOTPLUG_CPU
-int arch_crash_hotplug_cpu_support(void)
+int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_flags)
  {
-	return crash_check_update_elfcorehdr();
-}
-#endif
-#ifdef CONFIG_MEMORY_HOTPLUG
-int arch_crash_hotplug_memory_support(void)
-{
-	return crash_check_update_elfcorehdr();
-}
+#ifdef CONFIG_KEXEC_FILE
+	if (image->file_mode)
+		return 1;
  #endif
+	/*
+	 * Initially, crash hotplug support for kexec_load was added
+	 * with the KEXEC_UPDATE_ELFCOREHDR flag. Later, this
+	 * functionality was expanded to accommodate multiple kexec
+	 * segment updates, leading to the introduction of the
+	 * KEXEC_CRASH_HOTPLUG_SUPPORT kexec flag bit. Consequently,
+	 * when the kexec tool sends either of these flags, it indicates
+	 * that the required kexec segment (elfcorehdr) is excluded from
+	 * the SHA calculation.
+	 */
+	return (kexec_flags & KEXEC_UPDATE_ELFCOREHDR ||
+		kexec_flags & KEXEC_CRASH_HOTPLUG_SUPPORT);
+}
  unsigned int arch_crash_get_elfcorehdr_size(void)
  {
drivers/base/cpu.c +1 -1
index 47de0f140ba6..24eb52607151 100644
@@ -306,7 +306,7 @@ static ssize_t crash_hotplug_show(struct device *dev,
  				     struct device_attribute *attr,
  				     char *buf)
  {
-	return sysfs_emit(buf, "%d\n", crash_hotplug_cpu_support());
+	return sysfs_emit(buf, "%d\n", crash_check_hotplug_support());
  }
  static DEVICE_ATTR_ADMIN_RO(crash_hotplug);
  #endif
drivers/base/memory.c +1 -1
index 14f964a7719b..b80be8193970 100644
@@ -514,7 +514,7 @@ static DEVICE_ATTR_RW(auto_online_blocks);
  static ssize_t crash_hotplug_show(struct device *dev,
  				       struct device_attribute *attr, char *buf)
  {
-	return sysfs_emit(buf, "%d\n", crash_hotplug_memory_support());
+	return sysfs_emit(buf, "%d\n", crash_check_hotplug_support());
  }
  static DEVICE_ATTR_RO(crash_hotplug);
  #endif
include/linux/kexec.h +17 -10
index 802052d9c64b..175152b99cb7 100644
@@ -317,8 +317,10 @@ struct kimage {
  	/* If set, we are using file mode kexec syscall */
  	unsigned int file_mode:1;
  #ifdef CONFIG_CRASH_HOTPLUG
-	/* If set, allow changes to elfcorehdr of kexec_load'd image */
-	unsigned int update_elfcorehdr:1;
+	/* If set, it is safe to update kexec segments that are
+	 * excluded from SHA calculation.
+	 */
+	unsigned int hotplug_support:1;
  #endif
  #ifdef ARCH_HAS_KIMAGE_ARCH
@@ -396,9 +398,10 @@ bool kexec_load_permitted(int kexec_image_type);
  /* List of defined/legal kexec flags */
  #ifndef CONFIG_KEXEC_JUMP
-#define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_UPDATE_ELFCOREHDR)
+#define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_UPDATE_ELFCOREHDR | KEXEC_CRASH_HOTPLUG_SUPPORT)
  #else
-#define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT | KEXEC_UPDATE_ELFCOREHDR)
+#define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT | KEXEC_UPDATE_ELFCOREHDR | \
+			KEXEC_CRASH_HOTPLUG_SUPPORT)
  #endif
  /* List of defined/legal kexec file flags */
@@ -486,14 +489,18 @@ static inline void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages) {
  static inline void arch_crash_handle_hotplug_event(struct kimage *image, void *arg) { }
  #endif
-int crash_check_update_elfcorehdr(void);
+int crash_check_hotplug_support(void);
-#ifndef crash_hotplug_cpu_support
-static inline int crash_hotplug_cpu_support(void) { return 0; }
-#endif
+#ifndef arch_crash_hotplug_support
+static inline int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_flags)
+{
-#ifndef crash_hotplug_memory_support
-static inline int crash_hotplug_memory_support(void) { return 0; }
+#ifdef CONFIG_KEXEC_FILE
+	if (image->file_mode)
+		return 1;
+#endif
+	return kexec_flags & KEXEC_CRASH_HOTPLUG_SUPPORT;
+}
  #endif
  #ifndef crash_get_elfcorehdr_size
include/uapi/linux/kexec.h +1 -0
index c17bb096ea68..5ae1741ea8ea 100644
@@ -13,6 +13,7 @@
  #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
  /*
kernel/crash_core.c +4 -7
index b692ec5955de..3142884a5a5b 100644
@@ -886,7 +886,7 @@ static DEFINE_MUTEX(__crash_hotplug_lock);
   * It reflects the kernel's ability/permission to update the crash
   * elfcorehdr directly.
   */
-int crash_check_update_elfcorehdr(void)
+int crash_check_hotplug_support(void)
  {
  	int rc = 0;
@@ -898,10 +898,7 @@ int crash_check_update_elfcorehdr(void)
  		return 0;
  	}
  	if (kexec_crash_image) {
-		if (kexec_crash_image->file_mode)
-			rc = 1;
-		else
-			rc = kexec_crash_image->update_elfcorehdr;
+		rc = kexec_crash_image->hotplug_support;
  	}
  	/* Release lock now that update complete */
  	kexec_unlock();
@@ -942,8 +939,8 @@ static void crash_handle_hotplug_event(unsigned int hp_action, unsigned int cpu,
  	image = kexec_crash_image;
-	/* Check that updating elfcorehdr is permitted */
-	if (!(image->file_mode || image->update_elfcorehdr))
+	/* Check that kexec segments update is permitted */
+	if (!image->hotplug_support)
  		goto out;
  	if (hp_action == KEXEC_CRASH_HP_ADD_CPU ||
kernel/kexec.c +2 -2
index 8f35a5a42af8..9dc5b7ed5b73 100644
@@ -130,8 +130,8 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
  		image->preserve_context = 1;
  #ifdef CONFIG_CRASH_HOTPLUG
-	if (flags & KEXEC_UPDATE_ELFCOREHDR)
-		image->update_elfcorehdr = 1;
+	if ((flags & KEXEC_ON_CRASH) && arch_crash_hotplug_support(image, flags))
+		image->hotplug_support = 1;
  #endif
  	ret = machine_kexec_prepare(image);
kernel/kexec_file.c +0 -0
index bef2f6f2571b..4dddf9264a69 100644
@@ -373,6 +373,11 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd,
  	if (ret)
  		goto out;
Quoted 9 lines

kernel/kexec_file.c SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd, · line 383

Quoted 8 lines
kernel/kexec_file.c +5 -0
+#ifdef CONFIG_CRASH_HOTPLUG
+	if ((flags & KEXEC_FILE_ON_CRASH) && arch_crash_hotplug_support(image, flags))
+		image->hotplug_support = 1;
+#endif
+
  	ret = machine_kexec_prepare(image);
  	if (ret)
  		goto out;

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

#5 lore raw

Re: [PATCH v16 2/5] crash: add a new kexec flag for hotplug support

Quoted 6 lines · Baoquan He
Quoted 5 lines · Sourabh Jain

Hello Baoquan,

There are a lot of code movements introduced by your patch series, 'Split crash out from kexec and clean up related config items.'

Quoted 6 lines
Quoted 3 lines

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

Do you want me to rebase this patch series on top of the above patch series?

Yes, appreciate that, that would be very helpful. Rebasing this to latest next/master. And I saw Hari's patch sereis, basically it's fine to me. It will be great if this patch can sit on that patchset.

Sure, let me rebase it and send v17.

Thanks,
Sourabh

Quoted 269 lines
Quoted 269 lines · Sourabh Jain
Quoted 268 lines

Commit a72bbec70da2 ("crash: hotplug support for kexec_load()") introduced a new kexec flag, KEXEC_UPDATE_ELFCOREHDR. Kexec tool uses this flag to indicate to the kernel that it is safe to modify the elfcorehdr of the kdump image loaded using the kexec_load system call.

However, it is possible that architectures may need to update kexec segments other then elfcorehdr. For example, FDT (Flatten Device Tree) on PowerPC. Introducing a new kexec flag for every new kexec segment may not be a good solution. Hence, a generic kexec flag bit, KEXEC_CRASH_HOTPLUG_SUPPORT, is introduced to share the CPU/Memory hotplug support intent between the kexec tool and the kernel for the kexec_load system call.

Now, if the kexec tool sends KEXEC_CRASH_HOTPLUG_SUPPORT kexec flag to the kernel, it indicates to the kernel that all the required kexec segment is skipped from SHA calculation and it is safe to update kdump image loaded using the kexec_load syscall.

While loading the kdump image using the kexec_load syscall, the @update_elfcorehdr member of struct kimage is set if the kexec tool sends the KEXEC_UPDATE_ELFCOREHDR kexec flag. This member is later used to determine whether it is safe to update elfcorehdr on hotplug events. However, with the introduction of the KEXEC_CRASH_HOTPLUG_SUPPORT kexec flag, the kexec tool could mark all the required kexec segments on an architecture as safe to update. So rename the @update_elfcorehdr to @hotplug_support. If @hotplug_support is set, the kernel can safely update all the required kexec segments of the kdump image during CPU/Memory hotplug events.

Introduce an architecture-specific function to process kexec flags for determining hotplug support. Set the @hotplug_support member of struct kimage for both kexec_load and kexec_file_load system calls. This simplifies kernel checks to identify hotplug support for the currently loaded kdump image by just examining the value of @hotplug_support.

Cc Akhil Raj <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Aneesh Kumar K.V <[email protected]>
Cc Baoquan He <[email protected]>
Cc Borislav Petkov (AMD) <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Christophe Leroy <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Dave Young <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Eric DeVolder <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Hari Bathini <[email protected]>
Cc Laurent Dufour <[email protected]>
Cc Mahesh Salgaonkar <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Mimi Zohar <[email protected]>
Cc Naveen N Rao <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Valentin Schneider <[email protected]>
Cc Vivek Goyal <[email protected]>
---
   arch/x86/include/asm/kexec.h | 11 ++---------
   arch/x86/kernel/crash.c      | 28 +++++++++++++++++-----------
   drivers/base/cpu.c           |  2 +-
   drivers/base/memory.c        |  2 +-
   include/linux/kexec.h        | 27 +++++++++++++++++----------
   include/uapi/linux/kexec.h   |  1 +
   kernel/crash_core.c          | 11 ++++-------
   kernel/kexec.c               |  4 ++--
   kernel/kexec_file.c          |  5 +++++
   9 files changed, 50 insertions(+), 41 deletions(-)
arch/x86/include/asm/kexec.h +2 -9
index 9bb6607e864e..8be622e82ba8 100644
@@ -211,15 +211,8 @@ extern void kdump_nmi_shootdown_cpus(void);
   void arch_crash_handle_hotplug_event(struct kimage *image, void *arg);
   #define arch_crash_handle_hotplug_event arch_crash_handle_hotplug_event
-#ifdef CONFIG_HOTPLUG_CPU
-int arch_crash_hotplug_cpu_support(void);
-#define crash_hotplug_cpu_support arch_crash_hotplug_cpu_support
-#endif
-
-#ifdef CONFIG_MEMORY_HOTPLUG
-int arch_crash_hotplug_memory_support(void);
-#define crash_hotplug_memory_support arch_crash_hotplug_memory_support
-#endif
+int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_flags);
+#define arch_crash_hotplug_support arch_crash_hotplug_support
   unsigned int arch_crash_get_elfcorehdr_size(void);
   #define crash_get_elfcorehdr_size arch_crash_get_elfcorehdr_size
arch/x86/kernel/crash.c +17 -11
index 44744e9c68ec..7072aaee2ea0 100644
@@ -398,20 +398,26 @@ int crash_load_segments(struct kimage *image)
   #undef pr_fmt
   #define pr_fmt(fmt) "crash hp: " fmt
-/* These functions provide the value for the sysfs crash_hotplug nodes */
-#ifdef CONFIG_HOTPLUG_CPU
-int arch_crash_hotplug_cpu_support(void)
+int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_flags)
   {
-	return crash_check_update_elfcorehdr();
-}
-#endif
-#ifdef CONFIG_MEMORY_HOTPLUG
-int arch_crash_hotplug_memory_support(void)
-{
-	return crash_check_update_elfcorehdr();
-}
+#ifdef CONFIG_KEXEC_FILE
+	if (image->file_mode)
+		return 1;
   #endif
+	/*
+	 * Initially, crash hotplug support for kexec_load was added
+	 * with the KEXEC_UPDATE_ELFCOREHDR flag. Later, this
+	 * functionality was expanded to accommodate multiple kexec
+	 * segment updates, leading to the introduction of the
+	 * KEXEC_CRASH_HOTPLUG_SUPPORT kexec flag bit. Consequently,
+	 * when the kexec tool sends either of these flags, it indicates
+	 * that the required kexec segment (elfcorehdr) is excluded from
+	 * the SHA calculation.
+	 */
+	return (kexec_flags & KEXEC_UPDATE_ELFCOREHDR ||
+		kexec_flags & KEXEC_CRASH_HOTPLUG_SUPPORT);
+}
   unsigned int arch_crash_get_elfcorehdr_size(void)
   {
drivers/base/cpu.c +1 -1
index 47de0f140ba6..24eb52607151 100644
@@ -306,7 +306,7 @@ static ssize_t crash_hotplug_show(struct device *dev,
   				     struct device_attribute *attr,
   				     char *buf)
   {
-	return sysfs_emit(buf, "%d\n", crash_hotplug_cpu_support());
+	return sysfs_emit(buf, "%d\n", crash_check_hotplug_support());
   }
   static DEVICE_ATTR_ADMIN_RO(crash_hotplug);
   #endif
drivers/base/memory.c +1 -1
index 14f964a7719b..b80be8193970 100644
@@ -514,7 +514,7 @@ static DEVICE_ATTR_RW(auto_online_blocks);
   static ssize_t crash_hotplug_show(struct device *dev,
   				       struct device_attribute *attr, char *buf)
   {
-	return sysfs_emit(buf, "%d\n", crash_hotplug_memory_support());
+	return sysfs_emit(buf, "%d\n", crash_check_hotplug_support());
   }
   static DEVICE_ATTR_RO(crash_hotplug);
   #endif
include/linux/kexec.h +17 -10
index 802052d9c64b..175152b99cb7 100644
@@ -317,8 +317,10 @@ struct kimage {
   	/* If set, we are using file mode kexec syscall */
   	unsigned int file_mode:1;
   #ifdef CONFIG_CRASH_HOTPLUG
-	/* If set, allow changes to elfcorehdr of kexec_load'd image */
-	unsigned int update_elfcorehdr:1;
+	/* If set, it is safe to update kexec segments that are
+	 * excluded from SHA calculation.
+	 */
+	unsigned int hotplug_support:1;
   #endif
   #ifdef ARCH_HAS_KIMAGE_ARCH
@@ -396,9 +398,10 @@ bool kexec_load_permitted(int kexec_image_type);
   /* List of defined/legal kexec flags */
   #ifndef CONFIG_KEXEC_JUMP
-#define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_UPDATE_ELFCOREHDR)
+#define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_UPDATE_ELFCOREHDR | KEXEC_CRASH_HOTPLUG_SUPPORT)
   #else
-#define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT | KEXEC_UPDATE_ELFCOREHDR)
+#define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT | KEXEC_UPDATE_ELFCOREHDR | \
+			KEXEC_CRASH_HOTPLUG_SUPPORT)
   #endif
   /* List of defined/legal kexec file flags */
@@ -486,14 +489,18 @@ static inline void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages) {
   static inline void arch_crash_handle_hotplug_event(struct kimage *image, void *arg) { }
   #endif
-int crash_check_update_elfcorehdr(void);
+int crash_check_hotplug_support(void);
-#ifndef crash_hotplug_cpu_support
-static inline int crash_hotplug_cpu_support(void) { return 0; }
-#endif
+#ifndef arch_crash_hotplug_support
+static inline int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_flags)
+{
-#ifndef crash_hotplug_memory_support
-static inline int crash_hotplug_memory_support(void) { return 0; }
+#ifdef CONFIG_KEXEC_FILE
+	if (image->file_mode)
+		return 1;
+#endif
+	return kexec_flags & KEXEC_CRASH_HOTPLUG_SUPPORT;
+}
   #endif
   #ifndef crash_get_elfcorehdr_size
include/uapi/linux/kexec.h +1 -0
index c17bb096ea68..5ae1741ea8ea 100644
@@ -13,6 +13,7 @@
   #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
   /*
kernel/crash_core.c +4 -7
index b692ec5955de..3142884a5a5b 100644
@@ -886,7 +886,7 @@ static DEFINE_MUTEX(__crash_hotplug_lock);
    * It reflects the kernel's ability/permission to update the crash
    * elfcorehdr directly.
    */
-int crash_check_update_elfcorehdr(void)
+int crash_check_hotplug_support(void)
   {
   	int rc = 0;
@@ -898,10 +898,7 @@ int crash_check_update_elfcorehdr(void)
   		return 0;
   	}
   	if (kexec_crash_image) {
-		if (kexec_crash_image->file_mode)
-			rc = 1;
-		else
-			rc = kexec_crash_image->update_elfcorehdr;
+		rc = kexec_crash_image->hotplug_support;
   	}
   	/* Release lock now that update complete */
   	kexec_unlock();
@@ -942,8 +939,8 @@ static void crash_handle_hotplug_event(unsigned int hp_action, unsigned int cpu,
   	image = kexec_crash_image;
-	/* Check that updating elfcorehdr is permitted */
-	if (!(image->file_mode || image->update_elfcorehdr))
+	/* Check that kexec segments update is permitted */
+	if (!image->hotplug_support)
   		goto out;
   	if (hp_action == KEXEC_CRASH_HP_ADD_CPU ||
kernel/kexec.c +2 -2
index 8f35a5a42af8..9dc5b7ed5b73 100644
@@ -130,8 +130,8 @@ static int do_kexec_load(unsigned long entry, unsigned long nr_segments,
   		image->preserve_context = 1;
   #ifdef CONFIG_CRASH_HOTPLUG
-	if (flags & KEXEC_UPDATE_ELFCOREHDR)
-		image->update_elfcorehdr = 1;
+	if ((flags & KEXEC_ON_CRASH) && arch_crash_hotplug_support(image, flags))
+		image->hotplug_support = 1;
   #endif
   	ret = machine_kexec_prepare(image);
kernel/kexec_file.c +0 -0
index bef2f6f2571b..4dddf9264a69 100644
@@ -373,6 +373,11 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd,
   	if (ret)
   		goto out;
Quoted 8 lines
Quoted 8 lines

kernel/kexec_file.c SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd, · line 383

Quoted 8 lines
kernel/kexec_file.c +5 -0
+#ifdef CONFIG_CRASH_HOTPLUG
+	if ((flags & KEXEC_FILE_ON_CRASH) && arch_crash_hotplug_support(image, flags))
+		image->hotplug_support = 1;
+#endif
+
   	ret = machine_kexec_prepare(image);
   	if (ret)
   		goto out;

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

#6 lore raw

PATCH v16 3/5 powerpc/kexec: turn some static helper functions public

In reply to Sourabh Jain

Move the functions update_cpus_node and get_crash_memory_ranges from kexec/file_load_64.c to kexec/core_64.c to make these functions usable by other kexec components.

get_crash_memory_ranges uses functions defined in ranges.c, so take ranges.c out of CONFIG_KEXEC_FILE.

Later in the series, these functions are utilized for in-kernel updates to kdump image during CPU/Memory hotplug or online/offline events for both kexec_load and kexec_file_load syscalls.

There is no intended functional change.

Cc Akhil Raj <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Aneesh Kumar K.V <[email protected]>
Cc Baoquan He <[email protected]>
Cc Borislav Petkov (AMD) <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Christophe Leroy <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Dave Young <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Hari Bathini <[email protected]>
Cc Mahesh Salgaonkar <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Mimi Zohar <[email protected]>
Cc Naveen N Rao <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Valentin Schneider <[email protected]>
Cc Vivek Goyal <[email protected]>
---
 arch/powerpc/include/asm/kexec.h  |   6 ++
 arch/powerpc/kexec/Makefile       |   4 +-
 arch/powerpc/kexec/core_64.c      | 166 ++++++++++++++++++++++++++++++
 arch/powerpc/kexec/file_load_64.c | 162 -----------------------------
 4 files changed, 174 insertions(+), 164 deletions(-)
arch/powerpc/include/asm/kexec.h +6 -0
index e1b43aa12175..562e1bb689da 100644
@@ -108,6 +108,12 @@ void crash_free_reserved_phys_range(unsigned long begin, unsigned long end);
 #endif /* CONFIG_PPC_RTAS */
 #endif /* CONFIG_CRASH_DUMP */
 
+#ifdef CONFIG_PPC64
+struct crash_mem;
+int update_cpus_node(void *fdt);
+int get_crash_memory_ranges(struct crash_mem **mem_ranges);
+#endif /* CONFIG_PPC64 */
+
 #ifdef CONFIG_KEXEC_FILE
 extern const struct kexec_file_ops kexec_elf64_ops;
 
arch/powerpc/kexec/Makefile +2 -2
index 0c2abe7f9908..f2ed5b85b912 100644
@@ -3,11 +3,11 @@
 # Makefile for the linux kernel.
 #
 
-obj-y				+= core.o crash.o core_$(BITS).o
+obj-y				+= core.o crash.o ranges.o core_$(BITS).o
 
 obj-$(CONFIG_PPC32)		+= relocate_32.o
 
-obj-$(CONFIG_KEXEC_FILE)	+= file_load.o ranges.o file_load_$(BITS).o elf_$(BITS).o
+obj-$(CONFIG_KEXEC_FILE)	+= file_load.o file_load_$(BITS).o elf_$(BITS).o
 
 # Disable GCOV, KCOV & sanitizers in odd or sensitive code
 GCOV_PROFILE_core_$(BITS).o := n
arch/powerpc/kexec/core_64.c +166 -0

184 lines not on this page · raw message

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

174 lines not on this page · raw message

Signature · 7 lines
2.43.0


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

PATCH v16 4/5 powerpc: add crash CPU hotplug support

In reply to Sourabh Jain

Due to CPU/Memory hotplug or online/offline events, the elfcorehdr (which describes the CPUs and memory of the crashed kernel) and FDT (Flattened Device Tree) of kdump image becomes outdated. Consequently, attempting dump collection with an outdated elfcorehdr or FDT can lead to failed or inaccurate dump collection.

Going forward, CPU hotplug or online/offline events are referred as CPU/Memory add/remove events.

The current solution to address the above issue involves monitoring the CPU/Memory add/remove events in userspace using udev rules and whenever there are changes in CPU and memory resources, the entire kdump image is loaded again. The kdump image includes kernel, initrd, elfcorehdr, FDT, purgatory. Given that only elfcorehdr and FDT get outdated due to CPU/Memory add/remove events, reloading the entire kdump image is inefficient. More importantly, kdump remains inactive for a substantial amount of time until the kdump reload completes.

To address the aforementioned issue, commit 247262756121 ("crash: add generic infrastructure for crash hotplug support") added a generic infrastructure that allows architectures to selectively update the kdump image component during CPU or memory add/remove events within the kernel itself.

In the event of a CPU or memory add/remove events, the generic crash hotplug event handler, crash_handle_hotplug_event(), is triggered. It then acquires the necessary locks to update the kdump image and invokes the architecture-specific crash hotplug handler, arch_crash_handle_hotplug_event(), to update the required kdump image components.

This patch adds crash hotplug handler for PowerPC and enable support to update the kdump image on CPU add/remove events. Support for memory add/remove events is added in a subsequent patch with the title "powerpc: add crash memory hotplug support"

As mentioned earlier, only the elfcorehdr and FDT kdump image components need to be updated in the event of CPU or memory add/remove events. However, on PowerPC architecture crash hotplug handler only updates the FDT to enable crash hotplug support for CPU add/remove events. Here's why.

The elfcorehdr on PowerPC is built with possible CPUs, and thus, it does not need an update on CPU add/remove events. On the other hand, the FDT needs to be updated on CPU add events to include the newly added CPU. If the FDT is not updated and the kernel crashes on a newly added CPU, the kdump kernel will fail to boot due to the unavailability of the crashing CPU in the FDT. During the early boot, it is expected that the boot CPU must be a part of the FDT; otherwise, the kernel will raise a BUG and fail to boot. For more information, refer to commit 36ae37e3436b0 ("powerpc: Make boot_cpuid common between 32 and 64-bit"). Since it is okay to have an offline CPU in the kdump FDT, no action is taken in case of CPU removal.

There are two system calls, kexec_file_load and kexec_load, used to load the kdump image. Few changes have been made to ensure kernel can safely update the FDT of kdump image loaded using both system calls.

For kexec_file_load syscall the kdump image is prepared in kernel. So to support an increasing number of CPUs, the FDT is constructed with extra buffer space to ensure it can accommodate a possible number of CPU nodes. Additionally, a call to fdt_pack (which trims the unused space once the FDT is prepared) is avoided if this feature is enabled.

For the kexec_load syscall, the FDT is updated only if the KEXEC_CRASH_HOTPLUG_SUPPORT kexec flag is passed to the kernel by userspace (kexec tools). When userspace passes this flag to the kernel, it indicates that the FDT is built to accommodate possible CPUs, and the FDT segment is excluded from SHA calculation, making it safe to update.

The changes related to this feature are kept under the CRASH_HOTPLUG config, and it is enabled by default.

Cc Akhil Raj <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Aneesh Kumar K.V <[email protected]>
Cc Baoquan He <[email protected]>
Cc Borislav Petkov (AMD) <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Christophe Leroy <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Dave Young <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Hari Bathini <[email protected]>
Cc Laurent Dufour <[email protected]>
Cc Mahesh Salgaonkar <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Mimi Zohar <[email protected]>
Cc Naveen N Rao <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Valentin Schneider <[email protected]>
Cc Vivek Goyal <[email protected]>
---
 arch/powerpc/Kconfig              |  4 ++
 arch/powerpc/include/asm/kexec.h  |  6 ++
 arch/powerpc/kexec/core_64.c      | 93 +++++++++++++++++++++++++++++++
 arch/powerpc/kexec/elf_64.c       | 12 +++-
 arch/powerpc/kexec/file_load_64.c | 17 ++++++
 5 files changed, 131 insertions(+), 1 deletion(-)
arch/powerpc/Kconfig +4 -0
index b9fc064d38d2..fd1bf07244c6 100644
@@ -682,6 +682,10 @@ config RELOCATABLE_TEST
 config ARCH_SUPPORTS_CRASH_DUMP
 	def_bool PPC64 || PPC_BOOK3S_32 || PPC_85xx || (44x && !SMP)
 
+config ARCH_SUPPORTS_CRASH_HOTPLUG
+	def_bool y
+	depends on PPC64
+
 config ARCH_SELECTS_CRASH_DUMP
 	def_bool y
 	depends on CRASH_DUMP
arch/powerpc/include/asm/kexec.h +6 -0
index 562e1bb689da..67bace4c90cf 100644
@@ -112,6 +112,12 @@ void crash_free_reserved_phys_range(unsigned long begin, unsigned long end);
 struct crash_mem;
 int update_cpus_node(void *fdt);
 int get_crash_memory_ranges(struct crash_mem **mem_ranges);
+
+#ifdef CONFIG_CRASH_HOTPLUG
+void arch_crash_handle_hotplug_event(struct kimage *image, void *arg);
+#define arch_crash_handle_hotplug_event arch_crash_handle_hotplug_event
+#endif /* CONFIG_CRASH_HOTPLUG */
+
 #endif /* CONFIG_PPC64 */
 
 #ifdef CONFIG_KEXEC_FILE
arch/powerpc/kexec/core_64.c +93 -0

96 lines not on this page · raw message

arch/powerpc/kexec/elf_64.c +11 -1
index 904016cf89ea..f2cc53f8ebe3 100644
@@ -30,6 +30,7 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
 			unsigned long cmdline_len)
 {
 	int ret;
+	bool do_pack_fdt = true;
 	unsigned long kernel_load_addr;
 	unsigned long initrd_load_addr = 0, fdt_load_addr;
 	void *fdt;
@@ -116,7 +117,16 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
 	if (ret)
 		goto out_free_fdt;
 
-	fdt_pack(fdt);
+#ifdef CONFIG_CRASH_HOTPLUG
+	/*
+	 * Do not pack FDT, additional space is reserved to accommodate
+	 * possible CPU nodes which are not yet present in the system yet.
+	 */
+	if (image->type == KEXEC_TYPE_CRASH)
+		do_pack_fdt = false;
+#endif
+	if (do_pack_fdt)
+		fdt_pack(fdt);
 
 	kbuf.buffer = fdt;
 	kbuf.bufsz = kbuf.memsz = fdt_totalsize(fdt);
arch/powerpc/kexec/file_load_64.c +17 -0
index 923e24103808..d4f4fb19377b 100644
@@ -22,6 +22,7 @@
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
 #include <asm/setup.h>
+#include <asm/cputhreads.h>
 #include <asm/drmem.h>
 #include <asm/firmware.h>
 #include <asm/kexec_ranges.h>
@@ -909,6 +910,9 @@ unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image)
 	unsigned int cpu_nodes, extra_size = 0;
 	struct device_node *dn;
 	u64 usm_entries;
+#ifdef CONFIG_CRASH_HOTPLUG
+	unsigned int possible_cpu_nodes;
+#endif
 
 	// Budget some space for the password blob. There's already extra space
 	// for the key name
@@ -941,6 +945,19 @@ unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image)
 	if (cpu_nodes > boot_cpu_node_count)
 		extra_size += (cpu_nodes - boot_cpu_node_count) * cpu_node_size();
 
+#ifdef CONFIG_CRASH_HOTPLUG
+	/*
+	 * Make sure enough space is reserved to accommodate possible CPU nodes
+	 * in the crash FDT. This allows packing possible CPU nodes which are
+	 * not yet present in the system without regenerating the entire FDT.
+	 */
+	if (image->type == KEXEC_TYPE_CRASH) {
+		possible_cpu_nodes = num_possible_cpus() / threads_per_core;
+		if (possible_cpu_nodes > cpu_nodes)
+			extra_size += (possible_cpu_nodes - cpu_nodes) * cpu_node_size();
+	}
+#endif
+
 	return extra_size;
 }
 
Signature · 7 lines
2.43.0


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

PATCH v16 5/5 powerpc: add crash memory hotplug support

In reply to Sourabh Jain

Extend the arch crash hotplug handler, as introduced by the patch title ("powerpc: add crash CPU hotplug support"), to also support memory add/remove events.

Elfcorehdr describes the memory of the crash kernel to capture the kernel; hence, it needs to be updated if memory resources change due to memory add/remove events. Therefore, arch_crash_handle_hotplug_event() is updated to recreate the elfcorehdr and replace it with the previous one on memory add/remove events.

The memblock list is used to prepare the elfcorehdr. In the case of memory hot remove, the memblock list is updated after the arch crash hotplug handler is triggered, as depicted in Figure 1. Thus, the hot-removed memory is explicitly removed from the crash memory ranges to ensure that the memory ranges added to elfcorehdr do not include the hot-removed memory.

    Memory remove
          |
          v
    Offline pages
          |
          v
 Initiate memory notify call <----> crash hotplug handler
 chain for MEM_OFFLINE event
          |
          v

Update memblock list

Figure 1

There are two system calls, kexec_file_load and kexec_load, used to load the kdump image. A few changes have been made to ensure that the kernel can safely update the elfcorehdr component of the kdump image for both system calls.

For the kexec_file_load syscall, kdump image is prepared in the kernel. To support an increasing number of memory regions, the elfcorehdr is built with extra buffer space to ensure that it can accommodate additional memory ranges in future.

For the kexec_load syscall, the elfcorehdr is updated only if the KEXEC_CRASH_HOTPLUG_SUPPORT kexec flag is passed to the kernel by the kexec tool. Passing this flag to the kernel indicates that the elfcorehdr is built to accommodate additional memory ranges and the elfcorehdr segment is not considered for SHA calculation, making it safe to update.

The changes related to this feature are kept under the CRASH_HOTPLUG config, and it is enabled by default.

Cc Akhil Raj <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Aneesh Kumar K.V <[email protected]>
Cc Baoquan He <[email protected]>
Cc Borislav Petkov (AMD) <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc Christophe Leroy <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Dave Young <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Hari Bathini <[email protected]>
Cc Laurent Dufour <[email protected]>
Cc Mahesh Salgaonkar <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Mimi Zohar <[email protected]>
Cc Naveen N Rao <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Valentin Schneider <[email protected]>
Cc Vivek Goyal <[email protected]>
---
 arch/powerpc/include/asm/kexec.h        |   5 +-
 arch/powerpc/include/asm/kexec_ranges.h |   1 +
 arch/powerpc/kexec/core_64.c            | 105 +++++++++++++++++++++++-
 arch/powerpc/kexec/file_load_64.c       |  34 +++++++-
 arch/powerpc/kexec/ranges.c             |  85 +++++++++++++++++++
 5 files changed, 226 insertions(+), 4 deletions(-)
arch/powerpc/include/asm/kexec.h +4 -1
index 67bace4c90cf..a4193d922d99 100644
@@ -116,8 +116,11 @@ int get_crash_memory_ranges(struct crash_mem **mem_ranges);
 #ifdef CONFIG_CRASH_HOTPLUG
 void arch_crash_handle_hotplug_event(struct kimage *image, void *arg);
 #define arch_crash_handle_hotplug_event arch_crash_handle_hotplug_event
-#endif /* CONFIG_CRASH_HOTPLUG */
 
+unsigned int arch_crash_get_elfcorehdr_size(void);
+#define crash_get_elfcorehdr_size arch_crash_get_elfcorehdr_size
+
+#endif /* CONFIG_CRASH_HOTPLUG */
 #endif /* CONFIG_PPC64 */
 
 #ifdef CONFIG_KEXEC_FILE
arch/powerpc/include/asm/kexec_ranges.h +1 -0
index f83866a19e87..802abf580cf0 100644
@@ -7,6 +7,7 @@
 void sort_memory_ranges(struct crash_mem *mrngs, bool merge);
 struct crash_mem *realloc_mem_ranges(struct crash_mem **mem_ranges);
 int add_mem_range(struct crash_mem **mem_ranges, u64 base, u64 size);
+int remove_mem_range(struct crash_mem **mem_ranges, u64 base, u64 size);
 int add_tce_mem_ranges(struct crash_mem **mem_ranges);
 int add_initrd_mem_range(struct crash_mem **mem_ranges);
 #ifdef CONFIG_PPC_64S_HASH_MMU
arch/powerpc/kexec/core_64.c +104 -1

131 lines not on this page · raw message

arch/powerpc/kexec/file_load_64.c +32 -2
index d4f4fb19377b..8e5fb774e8b0 100644
@@ -21,6 +21,8 @@
 #include <linux/memblock.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
+#include <linux/elf.h>
+
 #include <asm/setup.h>
 #include <asm/cputhreads.h>
 #include <asm/drmem.h>
@@ -740,7 +742,35 @@ static int load_elfcorehdr_segment(struct kimage *image, struct kexec_buf *kbuf)
 
 	kbuf->buffer = headers;
 	kbuf->mem = KEXEC_BUF_MEM_UNKNOWN;
-	kbuf->bufsz = kbuf->memsz = headers_sz;
+	kbuf->bufsz = headers_sz;
+#if defined(CONFIG_CRASH_HOTPLUG) && defined(CONFIG_MEMORY_HOTPLUG)
+	/* Adjust the elfcorehdr segment size to accommodate
+	 * future crash memory ranges.
+	 */
+	int max_lmb;
+	unsigned long pnum;
+
+	/* In the worst case, a Phdr is needed for every other LMB to be
+	 * represented as an individual crash range.
+	 */
+	max_lmb = memory_hotplug_max() / (2 * drmem_lmb_size());
+
+	/* Do not cross the Phdr max limit of the elf header.
+	 * Avoid counting Phdr for crash ranges (cmem->nr_ranges)
+	 * which are already part of elfcorehdr.
+	 */
+	if (max_lmb > PN_XNUM)
+		pnum = PN_XNUM - cmem->nr_ranges;
+	else
+		pnum = max_lmb - cmem->nr_ranges;
+
+	/* Additional buffer space for elfcorehdr to accommodate
+	 * future memory ranges.
+	 */
+	kbuf->memsz = headers_sz + pnum * sizeof(Elf64_Phdr);
+#else
+	kbuf->memsz = headers_sz;
+#endif
 	kbuf->top_down = false;
 
 	ret = kexec_add_buffer(kbuf);
@@ -750,7 +780,7 @@ static int load_elfcorehdr_segment(struct kimage *image, struct kexec_buf *kbuf)
 	}
 
 	image->elf_load_addr = kbuf->mem;
-	image->elf_headers_sz = headers_sz;
+	image->elf_headers_sz = kbuf->memsz;
 	image->elf_headers = headers;
 out:
 	kfree(cmem);
arch/powerpc/kexec/ranges.c +85 -0

91 lines not on this page · raw message

Signature · 7 lines
2.43.0


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