From: Sourabh Jain <sourabhjain@linux.ibm.com>
To: linuxppc-dev@ozlabs.org, mpe@ellerman.id.au
Cc: eric.devolder@oracle.com, bhe@redhat.com,
mahesh@linux.vnet.ibm.com, kexec@lists.infradead.org,
ldufour@linux.ibm.com, hbathini@linux.ibm.com
Subject: [PATCH v8 6/8] powerpc/crash: add crash CPU hotplug support
Date: Wed, 1 Feb 2023 12:08:39 +0530 [thread overview]
Message-ID: <20230201063841.965316-7-sourabhjain@linux.ibm.com> (raw)
In-Reply-To: <20230201063841.965316-1-sourabhjain@linux.ibm.com>
Introduce powerpc crash hotplug handler to update the necessary kexec
segments on CPU/Memory hotplug events. A common crash hotplug handler is
triggered from generic infrastructure for both CPU/Memory hot un/plugged
events but in this patch, only CPU hot un/plugged events are introduced.
The memory hotplug support is added in upcoming patches.
The elfcorehdr segment is used to exchange the CPU and other dump related
information between the kernels. Ideally, the elfcorehdr segment needs to
be recreated on CPU hotplug events to reflect the changes. But on PowerPC
elfcorehdr is built with all possible CPUs instead of just online CPUs
hence no elfcorehdr segment update/recreation is needed.
In addition to elfcorehdr there is one more kexec segment that holds CPU
data FDT (Flattened Device Tree). To boot the PowerPC kernel the crashing
CPU has to be part of the FDT segment. If the kdump kernel doesn't find
the crashing CPU in the FDT segment, it fails to boot.
The only action needed on PowerPC to handle the crash CPU hotplug event
is to add hot added CPUs in the FDT segment to avoid kdump kernel boot
failure in case the system crashes on hot added CPU.
So for the CPU hot add events, the FDT segment is updated with hot added
CPU and Since there is no need to remove the hot unplugged CPUs from the
FDT segment hence no action taken on CPU hot remove event in PowerPC arch
crash hotplug handler.
To accommodate a growing number of CPUs, FDT is built with additional
buffer space to ensure that it can hold all possible CPUs.
The changes done here will also work for kexec_load system call given
that the kexec tool builds the FDT segment with additional space to
accommodate all possible CPUs as it is done for kexec_file_load system
call in the kernel.
Since memory crash hotplug support is not there yet the crash hotplug
handler simply warns the user and returns.
Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
---
arch/powerpc/include/asm/kexec.h | 5 ++
arch/powerpc/kexec/core_64.c | 82 +++++++++++++++++++++++++++++++
arch/powerpc/kexec/elf_64.c | 19 ++++++-
arch/powerpc/kexec/file_load_64.c | 39 ---------------
4 files changed, 105 insertions(+), 40 deletions(-)
diff --git a/arch/powerpc/include/asm/kexec.h b/arch/powerpc/include/asm/kexec.h
index 5a322c1737661..c2b8debc11a61 100644
--- a/arch/powerpc/include/asm/kexec.h
+++ b/arch/powerpc/include/asm/kexec.h
@@ -101,11 +101,16 @@ void kexec_copy_flush(struct kimage *image);
#ifdef CONFIG_PPC64
struct crash_mem;
+unsigned int cpu_node_size(void);
int update_cpus_node(void *fdt);
int get_crash_memory_ranges(struct crash_mem **mem_ranges);
#if defined(CONFIG_CRASH_HOTPLUG)
int machine_kexec_post_load(struct kimage *image);
#define machine_kexec_post_load machine_kexec_post_load
+
+void arch_crash_handle_hotplug_event(struct kimage *image, unsigned int hp_action);
+#define arch_crash_handle_hotplug_event arch_crash_handle_hotplug_event
+
#endif
#endif
diff --git a/arch/powerpc/kexec/core_64.c b/arch/powerpc/kexec/core_64.c
index a9918084b1eba..5fdc9fe4e7fe0 100644
--- a/arch/powerpc/kexec/core_64.c
+++ b/arch/powerpc/kexec/core_64.c
@@ -516,6 +516,45 @@ static int add_node_props(void *fdt, int node_offset, const struct device_node *
return ret;
}
+/**
+ * cpu_node_size - Compute the size of a CPU node in the FDT.
+ * This should be done only once and the value is stored in
+ * a static variable.
+ * Returns the max size of a CPU node in the FDT.
+ */
+unsigned int cpu_node_size(void)
+{
+ static unsigned int size;
+ struct device_node *dn;
+ struct property *pp;
+
+ /*
+ * Don't compute it twice, we are assuming that the per CPU node size
+ * doesn't change during the system's life.
+ */
+ if (size)
+ return size;
+
+ dn = of_find_node_by_type(NULL, "cpu");
+ if (WARN_ON_ONCE(!dn)) {
+ // Unlikely to happen
+ return 0;
+ }
+
+ /*
+ * We compute the sub node size for a CPU node, assuming it
+ * will be the same for all.
+ */
+ size += strlen(dn->name) + 5;
+ for_each_property_of_node(dn, pp) {
+ size += strlen(pp->name);
+ size += pp->length;
+ }
+
+ of_node_put(dn);
+ return size;
+}
+
/**
* update_cpus_node - Update cpus node of flattened device tree using of_root
* device node.
@@ -576,6 +615,49 @@ int update_cpus_node(void *fdt)
return ret;
}
+#if defined(CONFIG_CRASH_HOTPLUG)
+/**
+ * arch_crash_hotplug_handler() - Handle hotplug kexec segements changes FDT, elfcorehdr
+ * @image: the active struct kimage
+ * @hp_action: the hot un/plug action being handled
+ *
+ * To accurately reflect CPU hot un/plug changes, the FDT must be updated with the
+ * new list of CPUs.
+ */
+void arch_crash_handle_hotplug_event(struct kimage *image, unsigned int hp_action)
+{
+ void *fdt;
+
+ /* No action needed for CPU hot-unplug */
+ if (hp_action == KEXEC_CRASH_HP_REMOVE_CPU)
+ return;
+
+ /* crash update on memory hotplug is not support yet */
+ if (hp_action == KEXEC_CRASH_HP_REMOVE_MEMORY || hp_action == KEXEC_CRASH_HP_ADD_MEMORY) {
+ pr_info_once("crash hp: crash update is not supported with memory hotplug\n");
+ return;
+ }
+
+ /* Must have valid FDT index */
+ if (image->arch.fdt_index < 0) {
+ pr_err("crash hp: unable to locate FDT segment");
+ return;
+ }
+
+ fdt = __va((void *)image->segment[image->arch.fdt_index].mem);
+
+ /* Temporarily invalidate the crash image while it is replaced */
+ xchg(&kexec_crash_image, NULL);
+
+ /* update FDT to refelect changes to CPU resrouces */
+ if (update_cpus_node(fdt))
+ pr_err("crash hp: failed to update crash FDT");
+
+ /* The crash image is now valid once again */
+ xchg(&kexec_crash_image, image);
+}
+#endif
+
#ifdef CONFIG_PPC_64S_HASH_MMU
/* Values we need to export to the second kernel via the device tree. */
static unsigned long htab_base;
diff --git a/arch/powerpc/kexec/elf_64.c b/arch/powerpc/kexec/elf_64.c
index eeb258002d1e0..ace48e517427e 100644
--- a/arch/powerpc/kexec/elf_64.c
+++ b/arch/powerpc/kexec/elf_64.c
@@ -42,6 +42,9 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
struct kexec_buf pbuf = { .image = image, .buf_min = 0,
.buf_max = ppc64_rma_size, .top_down = true,
.mem = KEXEC_BUF_MEM_UNKNOWN };
+#if defined(CONFIG_CRASH_HOTPLUG)
+ unsigned int offline_core_count;
+#endif
ret = kexec_build_elf_info(kernel_buf, kernel_len, &ehdr, &elf_info);
if (ret)
@@ -119,10 +122,24 @@ static void *elf64_load(struct kimage *image, char *kernel_buf,
fdt_pack(fdt);
kbuf.buffer = fdt;
- kbuf.bufsz = kbuf.memsz = fdt_totalsize(fdt);
+ kbuf.bufsz = fdt_totalsize(fdt);
kbuf.buf_align = PAGE_SIZE;
kbuf.top_down = true;
kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
+#if defined(CONFIG_CRASH_HOTPLUG)
+ if (image->type == KEXEC_TYPE_CRASH) {
+ /* Calculate the buffer space needed to accommodate more CPU nodes in
+ * crash FDT post capture kernel load due to CPU hotplug events.
+ */
+ offline_core_count = (num_possible_cpus() - num_present_cpus()) / threads_per_core;
+ kbuf.memsz = fdt_totalsize(fdt) + offline_core_count * cpu_node_size();
+ fdt_set_totalsize(fdt, kbuf.memsz);
+ } else
+#endif
+ {
+ kbuf.memsz = fdt_totalsize(fdt);
+ }
+
ret = kexec_add_buffer(&kbuf);
if (ret)
goto out_free_fdt;
diff --git a/arch/powerpc/kexec/file_load_64.c b/arch/powerpc/kexec/file_load_64.c
index 9bc70b4d8eafc..ceac592be72b9 100644
--- a/arch/powerpc/kexec/file_load_64.c
+++ b/arch/powerpc/kexec/file_load_64.c
@@ -854,45 +854,6 @@ int setup_purgatory_ppc64(struct kimage *image, const void *slave_code,
return ret;
}
-/**
- * get_cpu_node_size - Compute the size of a CPU node in the FDT.
- * This should be done only once and the value is stored in
- * a static variable.
- * Returns the max size of a CPU node in the FDT.
- */
-static unsigned int cpu_node_size(void)
-{
- static unsigned int size;
- struct device_node *dn;
- struct property *pp;
-
- /*
- * Don't compute it twice, we are assuming that the per CPU node size
- * doesn't change during the system's life.
- */
- if (size)
- return size;
-
- dn = of_find_node_by_type(NULL, "cpu");
- if (WARN_ON_ONCE(!dn)) {
- // Unlikely to happen
- return 0;
- }
-
- /*
- * We compute the sub node size for a CPU node, assuming it
- * will be the same for all.
- */
- size += strlen(dn->name) + 5;
- for_each_property_of_node(dn, pp) {
- size += strlen(pp->name);
- size += pp->length;
- }
-
- of_node_put(dn);
- return size;
-}
-
/**
* kexec_extra_fdt_size_ppc64 - Return the estimated additional size needed to
* setup FDT for kexec/kdump kernel.
--
2.39.1
next prev parent reply other threads:[~2023-02-01 6:46 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-01 6:38 [PATCH v8 0/8] In kernel handling of CPU hotplug events for crash kernel Sourabh Jain
2023-02-01 6:38 ` [PATCH v8 1/8] powerpc/kexec: turn some static helper functions public Sourabh Jain
2023-02-01 6:38 ` [PATCH v8 2/8] powerpc/crash hp: introduce a new config option CRASH_HOTPLUG Sourabh Jain
2023-02-01 6:38 ` [PATCH v8 3/8] powerpc/crash: update kimage_arch struct Sourabh Jain
2023-02-01 6:38 ` [PATCH v8 4/8] crash: add phdr for possible CPUs in elfcorehdr Sourabh Jain
2023-02-02 15:37 ` Eric DeVolder
2023-02-02 21:01 ` Eric DeVolder
2023-02-06 6:36 ` Sourabh Jain
2023-02-06 5:52 ` Sourabh Jain
2023-02-06 5:56 ` Sourabh Jain
2023-02-01 6:38 ` [PATCH v8 5/8] crash: pass hotplug action type to arch crash hotplug handler Sourabh Jain
2023-02-01 6:38 ` Sourabh Jain [this message]
2023-02-01 6:38 ` [PATCH v8 7/8] crash: forward memory_notify args " Sourabh Jain
2023-02-01 6:38 ` [PATCH v8 8/8] powerpc/kexec: add crash memory hotplug support Sourabh Jain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230201063841.965316-7-sourabhjain@linux.ibm.com \
--to=sourabhjain@linux.ibm.com \
--cc=bhe@redhat.com \
--cc=eric.devolder@oracle.com \
--cc=hbathini@linux.ibm.com \
--cc=kexec@lists.infradead.org \
--cc=ldufour@linux.ibm.com \
--cc=linuxppc-dev@ozlabs.org \
--cc=mahesh@linux.vnet.ibm.com \
--cc=mpe@ellerman.id.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).