arch, crash: move arch_crash_save_vmcoreinfo() out to file vmcore_info.c
authorBaoquan He <bhe@redhat.com>
Mon, 29 Jan 2024 13:50:33 +0000 (21:50 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 24 Feb 2024 01:48:25 +0000 (17:48 -0800)
Nathan reported below building error:

=====
$ curl -LSso .config https://git.alpinelinux.org/aports/plain/community/linux-edge/config-edge.armv7
$ make -skj"$(nproc)" ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- olddefconfig all
..
arm-linux-gnueabi-ld: arch/arm/kernel/machine_kexec.o: in function `arch_crash_save_vmcoreinfo':
machine_kexec.c:(.text+0x488): undefined reference to `vmcoreinfo_append_str'
====

On architecutres, like arm, s390, ppc, sh, function
arch_crash_save_vmcoreinfo() is located in machine_kexec.c and it can
only be compiled in when CONFIG_KEXEC_CORE=y.

That's not right because arch_crash_save_vmcoreinfo() is used to export
arch specific vmcoreinfo. CONFIG_VMCORE_INFO is supposed to control its
compiling in. However, CONFIG_VMVCORE_INFO could be independent of
CONFIG_KEXEC_CORE, e.g CONFIG_PROC_KCORE=y will select CONFIG_VMVCORE_INFO.
Or CONFIG_KEXEC/CONFIG_KEXEC_FILE is set while CONFIG_CRASH_DUMP is
not set, it will report linking error.

So, on arm, s390, ppc and sh, move arch_crash_save_vmcoreinfo out to
a new file vmcore_info.c. Let CONFIG_VMCORE_INFO decide if compiling in
arch_crash_save_vmcoreinfo().

[akpm@linux-foundation.org: remove stray newlines at eof]
Link: https://lkml.kernel.org/r/20240129135033.157195-3-bhe@redhat.com
Signed-off-by: Baoquan He <bhe@redhat.com>
Reported-by: Nathan Chancellor <nathan@kernel.org>
Closes: https://lore.kernel.org/all/20240126045551.GA126645@dev-arch.thelio-3990X/T/#u
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Klara Modin <klarasmodin@gmail.com>
Cc: Michael Kelley <mhklinux@outlook.com>
Cc: Pingfan Liu <piliu@redhat.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Yang Li <yang.lee@linux.alibaba.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
12 files changed:
arch/arm/kernel/Makefile
arch/arm/kernel/machine_kexec.c
arch/arm/kernel/vmcore_info.c [new file with mode: 0644]
arch/powerpc/kexec/Makefile
arch/powerpc/kexec/core.c
arch/powerpc/kexec/vmcore_info.c [new file with mode: 0644]
arch/s390/kernel/Makefile
arch/s390/kernel/machine_kexec.c
arch/s390/kernel/vmcore_info.c [new file with mode: 0644]
arch/sh/kernel/Makefile
arch/sh/kernel/machine_kexec.c
arch/sh/kernel/vmcore_info.c [new file with mode: 0644]

index 771264d4726a732030c9af167ab535a3395a532b..6a9de826ffd3c035d938b8177d06ab1476cbf951 100644 (file)
@@ -60,6 +60,7 @@ obj-$(CONFIG_DYNAMIC_FTRACE)  += ftrace.o insn.o patch.o
 obj-$(CONFIG_FUNCTION_GRAPH_TRACER)    += ftrace.o insn.o patch.o
 obj-$(CONFIG_JUMP_LABEL)       += jump_label.o insn.o patch.o
 obj-$(CONFIG_KEXEC_CORE)       += machine_kexec.o relocate_kernel.o
+obj-$(CONFIG_VMCORE_INFO)      += vmcore_info.o
 # Main staffs in KPROBES are in arch/arm/probes/ .
 obj-$(CONFIG_KPROBES)          += patch.o insn.o
 obj-$(CONFIG_OABI_COMPAT)      += sys_oabi-compat.o
index 5d07cf9e0044d152e7bb43cc8e3e2e164dd85f16..80ceb5bd2680bc253af2f8affe84d08231d1d4e6 100644 (file)
@@ -198,10 +198,3 @@ void machine_kexec(struct kimage *image)
 
        soft_restart(reboot_entry_phys);
 }
-
-void arch_crash_save_vmcoreinfo(void)
-{
-#ifdef CONFIG_ARM_LPAE
-       VMCOREINFO_CONFIG(ARM_LPAE);
-#endif
-}
diff --git a/arch/arm/kernel/vmcore_info.c b/arch/arm/kernel/vmcore_info.c
new file mode 100644 (file)
index 0000000..1437aba
--- /dev/null
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/vmcore_info.h>
+
+void arch_crash_save_vmcoreinfo(void)
+{
+#ifdef CONFIG_ARM_LPAE
+       VMCOREINFO_CONFIG(ARM_LPAE);
+#endif
+}
index 0c2abe7f99087495098d37be69041ef698819dc2..91e96f5168b753ea8e358c8820ccfdc368bb8004 100644 (file)
@@ -8,6 +8,7 @@ obj-y                           += core.o crash.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_VMCORE_INFO)      += vmcore_info.o
 
 # Disable GCOV, KCOV & sanitizers in odd or sensitive code
 GCOV_PROFILE_core_$(BITS).o := n
index 27fa9098a5b74be8a55b7ad8a51830674628dbd4..3ff4411ed49671baf2a6834d611d20346622f57b 100644 (file)
@@ -53,34 +53,6 @@ void machine_kexec_cleanup(struct kimage *image)
 {
 }
 
-void arch_crash_save_vmcoreinfo(void)
-{
-
-#ifdef CONFIG_NUMA
-       VMCOREINFO_SYMBOL(node_data);
-       VMCOREINFO_LENGTH(node_data, MAX_NUMNODES);
-#endif
-#ifndef CONFIG_NUMA
-       VMCOREINFO_SYMBOL(contig_page_data);
-#endif
-#if defined(CONFIG_PPC64) && defined(CONFIG_SPARSEMEM_VMEMMAP)
-       VMCOREINFO_SYMBOL(vmemmap_list);
-       VMCOREINFO_SYMBOL(mmu_vmemmap_psize);
-       VMCOREINFO_SYMBOL(mmu_psize_defs);
-       VMCOREINFO_STRUCT_SIZE(vmemmap_backing);
-       VMCOREINFO_OFFSET(vmemmap_backing, list);
-       VMCOREINFO_OFFSET(vmemmap_backing, phys);
-       VMCOREINFO_OFFSET(vmemmap_backing, virt_addr);
-       VMCOREINFO_STRUCT_SIZE(mmu_psize_def);
-       VMCOREINFO_OFFSET(mmu_psize_def, shift);
-#endif
-       VMCOREINFO_SYMBOL(cur_cpu_spec);
-       VMCOREINFO_OFFSET(cpu_spec, cpu_features);
-       VMCOREINFO_OFFSET(cpu_spec, mmu_features);
-       vmcoreinfo_append_str("NUMBER(RADIX_MMU)=%d\n", early_radix_enabled());
-       vmcoreinfo_append_str("KERNELOFFSET=%lx\n", kaslr_offset());
-}
-
 /*
  * Do not allocate memory (or fail in any way) in machine_kexec().
  * We are past the point of no return, committed to rebooting now.
diff --git a/arch/powerpc/kexec/vmcore_info.c b/arch/powerpc/kexec/vmcore_info.c
new file mode 100644 (file)
index 0000000..2b65d2a
--- /dev/null
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/vmcore_info.h>
+#include <asm/pgalloc.h>
+
+void arch_crash_save_vmcoreinfo(void)
+{
+
+#ifdef CONFIG_NUMA
+       VMCOREINFO_SYMBOL(node_data);
+       VMCOREINFO_LENGTH(node_data, MAX_NUMNODES);
+#endif
+#ifndef CONFIG_NUMA
+       VMCOREINFO_SYMBOL(contig_page_data);
+#endif
+#if defined(CONFIG_PPC64) && defined(CONFIG_SPARSEMEM_VMEMMAP)
+       VMCOREINFO_SYMBOL(vmemmap_list);
+       VMCOREINFO_SYMBOL(mmu_vmemmap_psize);
+       VMCOREINFO_SYMBOL(mmu_psize_defs);
+       VMCOREINFO_STRUCT_SIZE(vmemmap_backing);
+       VMCOREINFO_OFFSET(vmemmap_backing, list);
+       VMCOREINFO_OFFSET(vmemmap_backing, phys);
+       VMCOREINFO_OFFSET(vmemmap_backing, virt_addr);
+       VMCOREINFO_STRUCT_SIZE(mmu_psize_def);
+       VMCOREINFO_OFFSET(mmu_psize_def, shift);
+#endif
+       VMCOREINFO_SYMBOL(cur_cpu_spec);
+       VMCOREINFO_OFFSET(cpu_spec, cpu_features);
+       VMCOREINFO_OFFSET(cpu_spec, mmu_features);
+       vmcoreinfo_append_str("NUMBER(RADIX_MMU)=%d\n", early_radix_enabled());
+       vmcoreinfo_append_str("KERNELOFFSET=%lx\n", kaslr_offset());
+}
index 7a562b4199c81b2b2bcb30f4efe0a84e59075a99..fa029d0dc28ff90567a47ec2ff264198c1342890 100644 (file)
@@ -64,6 +64,7 @@ obj-$(CONFIG_FUNCTION_TRACER) += ftrace.o
 obj-$(CONFIG_FUNCTION_TRACER)  += mcount.o
 obj-$(CONFIG_CRASH_DUMP)       += crash_dump.o
 obj-$(CONFIG_KEXEC_CORE)       += machine_kexec.o relocate_kernel.o
+obj-$(CONFIG_VMCORE_INFO)      += vmcore_info.o
 obj-$(CONFIG_UPROBES)          += uprobes.o
 obj-$(CONFIG_JUMP_LABEL)       += jump_label.o
 
index aa22ffc16bcd3d5e2467e7093204f682a036e42b..10277a4602049b2c4c85b1cf3abb7dba2db77047 100644 (file)
@@ -209,21 +209,6 @@ void machine_kexec_cleanup(struct kimage *image)
 {
 }
 
-void arch_crash_save_vmcoreinfo(void)
-{
-       struct lowcore *abs_lc;
-
-       VMCOREINFO_SYMBOL(lowcore_ptr);
-       VMCOREINFO_SYMBOL(high_memory);
-       VMCOREINFO_LENGTH(lowcore_ptr, NR_CPUS);
-       vmcoreinfo_append_str("SAMODE31=%lx\n", (unsigned long)__samode31);
-       vmcoreinfo_append_str("EAMODE31=%lx\n", (unsigned long)__eamode31);
-       vmcoreinfo_append_str("KERNELOFFSET=%lx\n", kaslr_offset());
-       abs_lc = get_abs_lowcore();
-       abs_lc->vmcore_info = paddr_vmcoreinfo_note();
-       put_abs_lowcore(abs_lc);
-}
-
 void machine_shutdown(void)
 {
 }
diff --git a/arch/s390/kernel/vmcore_info.c b/arch/s390/kernel/vmcore_info.c
new file mode 100644 (file)
index 0000000..d296dfc
--- /dev/null
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/vmcore_info.h>
+#include <asm/abs_lowcore.h>
+#include <linux/mm.h>
+#include <asm/setup.h>
+
+void arch_crash_save_vmcoreinfo(void)
+{
+       struct lowcore *abs_lc;
+
+       VMCOREINFO_SYMBOL(lowcore_ptr);
+       VMCOREINFO_SYMBOL(high_memory);
+       VMCOREINFO_LENGTH(lowcore_ptr, NR_CPUS);
+       vmcoreinfo_append_str("SAMODE31=%lx\n", (unsigned long)__samode31);
+       vmcoreinfo_append_str("EAMODE31=%lx\n", (unsigned long)__eamode31);
+       vmcoreinfo_append_str("KERNELOFFSET=%lx\n", kaslr_offset());
+       abs_lc = get_abs_lowcore();
+       abs_lc->vmcore_info = paddr_vmcoreinfo_note();
+       put_abs_lowcore(abs_lc);
+}
index 2d7e70537de04c9b731de0ffcadc807c62238754..ba917008d63ed9808badc2d24db886e10dd32d4d 100644 (file)
@@ -34,6 +34,7 @@ obj-$(CONFIG_SH_STANDARD_BIOS)        += sh_bios.o
 obj-$(CONFIG_KGDB)             += kgdb.o
 obj-$(CONFIG_MODULES)          += sh_ksyms_32.o module.o
 obj-$(CONFIG_KEXEC_CORE)       += machine_kexec.o relocate_kernel.o
+obj-$(CONFIG_VMCORE_INFO)      += vmcore_info.o
 obj-$(CONFIG_CRASH_DUMP)       += crash_dump.o
 obj-$(CONFIG_STACKTRACE)       += stacktrace.o
 obj-$(CONFIG_IO_TRAPPED)       += io_trapped.o
index 8daa8a6e6fa683bcbc0f0895ac4eb089ccdc0943..8321b31d2e19dc0c5af57020d4225398bd9790fc 100644 (file)
@@ -137,17 +137,6 @@ void machine_kexec(struct kimage *image)
        __ftrace_enabled_restore(save_ftrace_enabled);
 }
 
-void arch_crash_save_vmcoreinfo(void)
-{
-#ifdef CONFIG_NUMA
-       VMCOREINFO_SYMBOL(node_data);
-       VMCOREINFO_LENGTH(node_data, MAX_NUMNODES);
-#endif
-#ifdef CONFIG_X2TLB
-       VMCOREINFO_CONFIG(X2TLB);
-#endif
-}
-
 void __init reserve_crashkernel(void)
 {
        unsigned long long crash_size, crash_base;
diff --git a/arch/sh/kernel/vmcore_info.c b/arch/sh/kernel/vmcore_info.c
new file mode 100644 (file)
index 0000000..a244a20
--- /dev/null
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/vmcore_info.h>
+#include <linux/mm.h>
+
+void arch_crash_save_vmcoreinfo(void)
+{
+#ifdef CONFIG_NUMA
+       VMCOREINFO_SYMBOL(node_data);
+       VMCOREINFO_LENGTH(node_data, MAX_NUMNODES);
+#endif
+#ifdef CONFIG_X2TLB
+       VMCOREINFO_CONFIG(X2TLB);
+#endif
+}