Skip to content

Commit d49b856

Browse files
author
Mamatha Inamdar
committed
powerpc/crash: add crash CPU hotplug support
JIRA: https://issues.redhat.com/browse/RHEL-101851 commit b741092 Author: Sourabh Jain <sourabhjain@linux.ibm.com> Date: Tue Mar 26 11:24:12 2024 +0530 powerpc/crash: add crash CPU hotplug support 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 2472627 ("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 36ae37e ("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. Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com> Acked-by: Hari Bathini <hbathini@linux.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://msgid.link/20240326055413.186534-6-sourabhjain@linux.ibm.com Signed-off-by: Mamatha Inamdar <minamdar@redhat.com>
1 parent 8c14e6a commit d49b856

File tree

5 files changed

+134
-1
lines changed

5 files changed

+134
-1
lines changed

arch/powerpc/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,10 @@ config ARCH_SELECTS_CRASH_DUMP
600600
depends on CRASH_DUMP
601601
select RELOCATABLE if PPC64 || 44x || FSL_BOOKE
602602

603+
config ARCH_SUPPORTS_CRASH_HOTPLUG
604+
def_bool y
605+
depends on PPC64
606+
603607
config FA_DUMP
604608
bool "Firmware-assisted dump"
605609
depends on CRASH_DUMP && PPC64 && (PPC_RTAS || PPC_POWERNV)

arch/powerpc/include/asm/kexec.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ static inline void crash_setup_regs(struct pt_regs *newregs,
135135
ppc_save_regs(newregs);
136136
}
137137

138+
#ifdef CONFIG_CRASH_HOTPLUG
139+
void arch_crash_handle_hotplug_event(struct kimage *image, void *arg);
140+
#define arch_crash_handle_hotplug_event arch_crash_handle_hotplug_event
141+
142+
int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_flags);
143+
#define arch_crash_hotplug_support arch_crash_hotplug_support
144+
#endif /* CONFIG_CRASH_HOTPLUG */
145+
138146
extern int crashing_cpu;
139147
extern void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *));
140148
extern void crash_ipi_callback(struct pt_regs *regs);

arch/powerpc/kexec/crash.c

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/delay.h>
1717
#include <linux/irq.h>
1818
#include <linux/types.h>
19+
#include <linux/libfdt.h>
1920

2021
#include <asm/processor.h>
2122
#include <asm/machdep.h>
@@ -376,3 +377,105 @@ void default_machine_crash_shutdown(struct pt_regs *regs)
376377
if (ppc_md.kexec_cpu_down)
377378
ppc_md.kexec_cpu_down(1, 0);
378379
}
380+
381+
#ifdef CONFIG_CRASH_HOTPLUG
382+
#undef pr_fmt
383+
#define pr_fmt(fmt) "crash hp: " fmt
384+
385+
/**
386+
* get_fdt_index - Loop through the kexec segment array and find
387+
* the index of the FDT segment.
388+
* @image: a pointer to kexec_crash_image
389+
*
390+
* Returns the index of FDT segment in the kexec segment array
391+
* if found; otherwise -1.
392+
*/
393+
static int get_fdt_index(struct kimage *image)
394+
{
395+
void *ptr;
396+
unsigned long mem;
397+
int i, fdt_index = -1;
398+
399+
/* Find the FDT segment index in kexec segment array. */
400+
for (i = 0; i < image->nr_segments; i++) {
401+
mem = image->segment[i].mem;
402+
ptr = __va(mem);
403+
404+
if (ptr && fdt_magic(ptr) == FDT_MAGIC) {
405+
fdt_index = i;
406+
break;
407+
}
408+
}
409+
410+
return fdt_index;
411+
}
412+
413+
/**
414+
* update_crash_fdt - updates the cpus node of the crash FDT.
415+
*
416+
* @image: a pointer to kexec_crash_image
417+
*/
418+
static void update_crash_fdt(struct kimage *image)
419+
{
420+
void *fdt;
421+
int fdt_index;
422+
423+
fdt_index = get_fdt_index(image);
424+
if (fdt_index < 0) {
425+
pr_err("Unable to locate FDT segment.\n");
426+
return;
427+
}
428+
429+
fdt = __va((void *)image->segment[fdt_index].mem);
430+
431+
/* Temporarily invalidate the crash image while it is replaced */
432+
xchg(&kexec_crash_image, NULL);
433+
434+
/* update FDT to reflect changes in CPU resources */
435+
if (update_cpus_node(fdt))
436+
pr_err("Failed to update crash FDT");
437+
438+
/* The crash image is now valid once again */
439+
xchg(&kexec_crash_image, image);
440+
}
441+
442+
int arch_crash_hotplug_support(struct kimage *image, unsigned long kexec_flags)
443+
{
444+
#ifdef CONFIG_KEXEC_FILE
445+
if (image->file_mode)
446+
return 1;
447+
#endif
448+
return kexec_flags & KEXEC_CRASH_HOTPLUG_SUPPORT;
449+
}
450+
451+
/**
452+
* arch_crash_handle_hotplug_event - Handle crash CPU/Memory hotplug events to update the
453+
* necessary kexec segments based on the hotplug event.
454+
* @image: a pointer to kexec_crash_image
455+
* @arg: struct memory_notify handler for memory hotplug case and NULL for CPU hotplug case.
456+
*
457+
* Update the kdump image based on the type of hotplug event, represented by image->hp_action.
458+
* CPU add: Update the FDT segment to include the newly added CPU.
459+
* CPU remove: No action is needed, with the assumption that it's okay to have offline CPUs
460+
* part of the FDT.
461+
* Memory add/remove: No action is taken as this is not yet supported.
462+
*/
463+
void arch_crash_handle_hotplug_event(struct kimage *image, void *arg)
464+
{
465+
switch (image->hp_action) {
466+
case KEXEC_CRASH_HP_REMOVE_CPU:
467+
return;
468+
469+
case KEXEC_CRASH_HP_ADD_CPU:
470+
update_crash_fdt(image);
471+
break;
472+
473+
case KEXEC_CRASH_HP_REMOVE_MEMORY:
474+
case KEXEC_CRASH_HP_ADD_MEMORY:
475+
pr_info_once("Crash update is not supported for memory hotplug\n");
476+
return;
477+
default:
478+
pr_warn_once("Unknown hotplug action\n");
479+
}
480+
}
481+
#endif /* CONFIG_CRASH_HOTPLUG */

arch/powerpc/kexec/elf_64.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
116116
if (ret)
117117
goto out_free_fdt;
118118

119-
fdt_pack(fdt);
119+
if (!IS_ENABLED(CONFIG_CRASH_HOTPLUG) || image->type != KEXEC_TYPE_CRASH)
120+
fdt_pack(fdt);
120121

121122
kbuf.buffer = fdt;
122123
kbuf.bufsz = kbuf.memsz = fdt_totalsize(fdt);

arch/powerpc/kexec/file_load_64.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <asm/mmzone.h>
3030
#include <asm/prom.h>
3131
#include <asm/plpks.h>
32+
#include <asm/cputhreads.h>
3233

3334
struct umem_info {
3435
u64 *buf; /* data buffer for usable-memory property */
@@ -786,6 +787,9 @@ static unsigned int kdump_extra_fdt_size_ppc64(struct kimage *image)
786787
unsigned int cpu_nodes, extra_size = 0;
787788
struct device_node *dn;
788789
u64 usm_entries;
790+
#ifdef CONFIG_CRASH_HOTPLUG
791+
unsigned int possible_cpu_nodes;
792+
#endif
789793

790794
if (!IS_ENABLED(CONFIG_CRASH_DUMP) || image->type != KEXEC_TYPE_CRASH)
791795
return 0;
@@ -813,6 +817,19 @@ static unsigned int kdump_extra_fdt_size_ppc64(struct kimage *image)
813817
if (cpu_nodes > boot_cpu_node_count)
814818
extra_size += (cpu_nodes - boot_cpu_node_count) * cpu_node_size();
815819

820+
#ifdef CONFIG_CRASH_HOTPLUG
821+
/*
822+
* Make sure enough space is reserved to accommodate possible CPU nodes
823+
* in the crash FDT. This allows packing possible CPU nodes which are
824+
* not yet present in the system without regenerating the entire FDT.
825+
*/
826+
if (image->type == KEXEC_TYPE_CRASH) {
827+
possible_cpu_nodes = num_possible_cpus() / threads_per_core;
828+
if (possible_cpu_nodes > cpu_nodes)
829+
extra_size += (possible_cpu_nodes - cpu_nodes) * cpu_node_size();
830+
}
831+
#endif
832+
816833
return extra_size;
817834
}
818835

0 commit comments

Comments
 (0)