Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crash: split vmcoreinfo exporting code out from crash_core.c

Now move the relevant codes into separate files:
kernel/crash_reserve.c, include/linux/crash_reserve.h.

And add config item CRASH_RESERVE to control its enabling.

And also update the old ifdeffery of CONFIG_CRASH_CORE, including of
<linux/crash_core.h> and config item dependency on CRASH_CORE
accordingly.

And also do renaming as follows:
- arch/xxx/kernel/{crash_core.c => vmcore_info.c}
because they are only related to vmcoreinfo exporting on x86, arm64,
riscv.

And also Remove config item CRASH_CORE, and rely on CONFIG_KEXEC_CORE to
decide if build in crash_core.c.

[yang.lee@linux.alibaba.com: remove duplicated include in vmcore_info.c]
Link: https://lkml.kernel.org/r/20240126005744.16561-1-yang.lee@linux.alibaba.com
Link: https://lkml.kernel.org/r/20240124051254.67105-3-bhe@redhat.com
Signed-off-by: Baoquan He <bhe@redhat.com>
Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
Acked-by: Hari Bathini <hbathini@linux.ibm.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Pingfan Liu <piliu@redhat.com>
Cc: Klara Modin <klarasmodin@gmail.com>
Cc: Michael Kelley <mhklinux@outlook.com>
Cc: Nathan Chancellor <nathan@kernel.org>
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>

authored by

Baoquan He and committed by
Andrew Morton
443cbaf9 85fcde40

+342 -309
+1 -1
arch/arm64/kernel/Makefile
··· 66 66 obj-$(CONFIG_ARM64_RELOC_TEST) += arm64-reloc-test.o 67 67 arm64-reloc-test-y := reloc_test_core.o reloc_test_syms.o 68 68 obj-$(CONFIG_CRASH_DUMP) += crash_dump.o 69 - obj-$(CONFIG_CRASH_CORE) += crash_core.o 69 + obj-$(CONFIG_VMCORE_INFO) += vmcore_info.o 70 70 obj-$(CONFIG_ARM_SDE_INTERFACE) += sdei.o 71 71 obj-$(CONFIG_ARM64_PTR_AUTH) += pointer_auth.o 72 72 obj-$(CONFIG_ARM64_MTE) += mte.o
+1 -1
arch/arm64/kernel/crash_core.c arch/arm64/kernel/vmcore_info.c
··· 4 4 * Copyright (C) Huawei Futurewei Technologies. 5 5 */ 6 6 7 - #include <linux/crash_core.h> 7 + #include <linux/vmcore_info.h> 8 8 #include <asm/cpufeature.h> 9 9 #include <asm/memory.h> 10 10 #include <asm/pgtable-hwdef.h>
+1 -1
arch/powerpc/Kconfig
··· 690 690 config FA_DUMP 691 691 bool "Firmware-assisted dump" 692 692 depends on PPC64 && (PPC_RTAS || PPC_POWERNV) 693 - select CRASH_CORE 693 + select VMCORE_INFO 694 694 select CRASH_RESERVE 695 695 select CRASH_DUMP 696 696 help
+1 -1
arch/powerpc/kernel/setup-common.c
··· 109 109 EXPORT_SYMBOL(ppc_do_canonicalize_irqs); 110 110 #endif 111 111 112 - #ifdef CONFIG_CRASH_CORE 112 + #ifdef CONFIG_VMCORE_INFO 113 113 /* This keeps a track of which one is the crashing cpu. */ 114 114 int crashing_cpu = -1; 115 115 #endif
+1 -1
arch/powerpc/platforms/powernv/opal-core.c
··· 16 16 #include <linux/kobject.h> 17 17 #include <linux/sysfs.h> 18 18 #include <linux/slab.h> 19 - #include <linux/crash_core.h> 19 + #include <linux/vmcore_info.h> 20 20 #include <linux/of.h> 21 21 22 22 #include <asm/page.h>
+1 -1
arch/riscv/kernel/Makefile
··· 92 92 obj-$(CONFIG_KEXEC_CORE) += kexec_relocate.o crash_save_regs.o machine_kexec.o 93 93 obj-$(CONFIG_KEXEC_FILE) += elf_kexec.o machine_kexec_file.o 94 94 obj-$(CONFIG_CRASH_DUMP) += crash_dump.o 95 - obj-$(CONFIG_CRASH_CORE) += crash_core.o 95 + obj-$(CONFIG_VMCORE_INFO) += vmcore_info.o 96 96 97 97 obj-$(CONFIG_JUMP_LABEL) += jump_label.o 98 98
+1 -1
arch/riscv/kernel/crash_core.c arch/riscv/kernel/vmcore_info.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 2 3 - #include <linux/crash_core.h> 3 + #include <linux/vmcore_info.h> 4 4 #include <linux/pagemap.h> 5 5 6 6 void arch_crash_save_vmcoreinfo(void)
+1 -1
arch/x86/kernel/Makefile
··· 98 98 obj-$(CONFIG_X86_TSC) += trace_clock.o 99 99 obj-$(CONFIG_TRACING) += trace.o 100 100 obj-$(CONFIG_RETHOOK) += rethook.o 101 - obj-$(CONFIG_CRASH_CORE) += crash_core_$(BITS).o 101 + obj-$(CONFIG_VMCORE_INFO) += vmcore_info_$(BITS).o 102 102 obj-$(CONFIG_KEXEC_CORE) += machine_kexec_$(BITS).o 103 103 obj-$(CONFIG_KEXEC_CORE) += relocate_kernel_$(BITS).o crash.o 104 104 obj-$(CONFIG_KEXEC_FILE) += kexec-bzimage64.o
+1 -1
arch/x86/kernel/crash_core_32.c arch/x86/kernel/vmcore_info_32.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 2 3 - #include <linux/crash_core.h> 3 + #include <linux/vmcore_info.h> 4 4 #include <linux/pgtable.h> 5 5 6 6 #include <asm/setup.h>
+1 -1
arch/x86/kernel/crash_core_64.c arch/x86/kernel/vmcore_info_64.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 2 3 - #include <linux/crash_core.h> 3 + #include <linux/vmcore_info.h> 4 4 #include <linux/pgtable.h> 5 5 6 6 #include <asm/setup.h>
+7 -7
drivers/firmware/qemu_fw_cfg.c
··· 37 37 #include <uapi/linux/qemu_fw_cfg.h> 38 38 #include <linux/delay.h> 39 39 #include <linux/crash_dump.h> 40 - #include <linux/crash_core.h> 40 + #include <linux/vmcore_info.h> 41 41 42 42 MODULE_AUTHOR("Gabriel L. Somlo <somlo@cmu.edu>"); 43 43 MODULE_DESCRIPTION("QEMU fw_cfg sysfs support"); ··· 67 67 iowrite16(key, fw_cfg_reg_ctrl); 68 68 } 69 69 70 - #ifdef CONFIG_CRASH_CORE 70 + #ifdef CONFIG_VMCORE_INFO 71 71 static inline bool fw_cfg_dma_enabled(void) 72 72 { 73 73 return (fw_cfg_rev & FW_CFG_VERSION_DMA) && fw_cfg_reg_dma; ··· 156 156 return count; 157 157 } 158 158 159 - #ifdef CONFIG_CRASH_CORE 159 + #ifdef CONFIG_VMCORE_INFO 160 160 /* write chunk of given fw_cfg blob (caller responsible for sanity-check) */ 161 161 static ssize_t fw_cfg_write_blob(u16 key, 162 162 void *buf, loff_t pos, size_t count) ··· 195 195 196 196 return ret; 197 197 } 198 - #endif /* CONFIG_CRASH_CORE */ 198 + #endif /* CONFIG_VMCORE_INFO */ 199 199 200 200 /* clean up fw_cfg device i/o */ 201 201 static void fw_cfg_io_cleanup(void) ··· 319 319 struct list_head list; 320 320 }; 321 321 322 - #ifdef CONFIG_CRASH_CORE 322 + #ifdef CONFIG_VMCORE_INFO 323 323 static ssize_t fw_cfg_write_vmcoreinfo(const struct fw_cfg_file *f) 324 324 { 325 325 static struct fw_cfg_vmcoreinfo *data; ··· 343 343 kfree(data); 344 344 return ret; 345 345 } 346 - #endif /* CONFIG_CRASH_CORE */ 346 + #endif /* CONFIG_VMCORE_INFO */ 347 347 348 348 /* get fw_cfg_sysfs_entry from kobject member */ 349 349 static inline struct fw_cfg_sysfs_entry *to_entry(struct kobject *kobj) ··· 583 583 int err; 584 584 struct fw_cfg_sysfs_entry *entry; 585 585 586 - #ifdef CONFIG_CRASH_CORE 586 + #ifdef CONFIG_VMCORE_INFO 587 587 if (fw_cfg_dma_enabled() && 588 588 strcmp(f->name, FW_CFG_VMCOREINFO_FILENAME) == 0 && 589 589 !is_kdump_kernel()) {
+1 -1
fs/proc/Kconfig
··· 32 32 config PROC_KCORE 33 33 bool "/proc/kcore support" if !ARM 34 34 depends on PROC_FS && MMU 35 - select CRASH_CORE 35 + select VMCORE_INFO 36 36 help 37 37 Provides a virtual ELF core file of the live kernel. This can 38 38 be read with gdb and other ELF tools. No modifications can be
+1 -1
fs/proc/kcore.c
··· 10 10 * Safe accesses to vmalloc/direct-mapped discontiguous areas, Kanoj Sarcar <kanoj@sgi.com> 11 11 */ 12 12 13 - #include <linux/crash_core.h> 13 + #include <linux/vmcore_info.h> 14 14 #include <linux/mm.h> 15 15 #include <linux/proc_fs.h> 16 16 #include <linux/kcore.h>
+1 -1
include/linux/buildid.h
··· 11 11 __u32 *size); 12 12 int build_id_parse_buf(const void *buf, unsigned char *build_id, u32 buf_size); 13 13 14 - #if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID) || IS_ENABLED(CONFIG_CRASH_CORE) 14 + #if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID) || IS_ENABLED(CONFIG_VMCORE_INFO) 15 15 extern unsigned char vmlinux_build_id[BUILD_ID_SIZE_MAX]; 16 16 void init_vmlinux_build_id(void); 17 17 #else
-73
include/linux/crash_core.h
··· 6 6 #include <linux/elfcore.h> 7 7 #include <linux/elf.h> 8 8 9 - #define CRASH_CORE_NOTE_NAME "CORE" 10 - #define CRASH_CORE_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4) 11 - #define CRASH_CORE_NOTE_NAME_BYTES ALIGN(sizeof(CRASH_CORE_NOTE_NAME), 4) 12 - #define CRASH_CORE_NOTE_DESC_BYTES ALIGN(sizeof(struct elf_prstatus), 4) 13 - 14 - /* 15 - * The per-cpu notes area is a list of notes terminated by a "NULL" 16 - * note header. For kdump, the code in vmcore.c runs in the context 17 - * of the second kernel to combine them into one note. 18 - */ 19 - #define CRASH_CORE_NOTE_BYTES ((CRASH_CORE_NOTE_HEAD_BYTES * 2) + \ 20 - CRASH_CORE_NOTE_NAME_BYTES + \ 21 - CRASH_CORE_NOTE_DESC_BYTES) 22 - 23 - #define VMCOREINFO_BYTES PAGE_SIZE 24 - #define VMCOREINFO_NOTE_NAME "VMCOREINFO" 25 - #define VMCOREINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCOREINFO_NOTE_NAME), 4) 26 - #define VMCOREINFO_NOTE_SIZE ((CRASH_CORE_NOTE_HEAD_BYTES * 2) + \ 27 - VMCOREINFO_NOTE_NAME_BYTES + \ 28 - VMCOREINFO_BYTES) 29 - 30 - typedef u32 note_buf_t[CRASH_CORE_NOTE_BYTES/4]; 31 - /* Per cpu memory for storing cpu states in case of system crash. */ 32 - extern note_buf_t __percpu *crash_notes; 33 - 34 - void crash_update_vmcoreinfo_safecopy(void *ptr); 35 - void crash_save_vmcoreinfo(void); 36 - void arch_crash_save_vmcoreinfo(void); 37 - __printf(1, 2) 38 - void vmcoreinfo_append_str(const char *fmt, ...); 39 - phys_addr_t paddr_vmcoreinfo_note(void); 40 - 41 - #define VMCOREINFO_OSRELEASE(value) \ 42 - vmcoreinfo_append_str("OSRELEASE=%s\n", value) 43 - #define VMCOREINFO_BUILD_ID() \ 44 - ({ \ 45 - static_assert(sizeof(vmlinux_build_id) == 20); \ 46 - vmcoreinfo_append_str("BUILD-ID=%20phN\n", vmlinux_build_id); \ 47 - }) 48 - 49 - #define VMCOREINFO_PAGESIZE(value) \ 50 - vmcoreinfo_append_str("PAGESIZE=%ld\n", value) 51 - #define VMCOREINFO_SYMBOL(name) \ 52 - vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name) 53 - #define VMCOREINFO_SYMBOL_ARRAY(name) \ 54 - vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)name) 55 - #define VMCOREINFO_SIZE(name) \ 56 - vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \ 57 - (unsigned long)sizeof(name)) 58 - #define VMCOREINFO_STRUCT_SIZE(name) \ 59 - vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \ 60 - (unsigned long)sizeof(struct name)) 61 - #define VMCOREINFO_OFFSET(name, field) \ 62 - vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \ 63 - (unsigned long)offsetof(struct name, field)) 64 - #define VMCOREINFO_TYPE_OFFSET(name, field) \ 65 - vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \ 66 - (unsigned long)offsetof(name, field)) 67 - #define VMCOREINFO_LENGTH(name, value) \ 68 - vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value) 69 - #define VMCOREINFO_NUMBER(name) \ 70 - vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name) 71 - #define VMCOREINFO_CONFIG(name) \ 72 - vmcoreinfo_append_str("CONFIG_%s=y\n", #name) 73 - 74 - extern unsigned char *vmcoreinfo_data; 75 - extern size_t vmcoreinfo_size; 76 - extern u32 *vmcoreinfo_note; 77 - 78 - Elf_Word *append_elf_note(Elf_Word *buf, char *name, unsigned int type, 79 - void *data, size_t data_len); 80 - void final_note(Elf_Word *buf); 81 - 82 9 /* Alignment required for elf header segment */ 83 10 #define ELF_CORE_HEADER_ALIGN 4096 84 11
+1
include/linux/kexec.h
··· 16 16 #if !defined(__ASSEMBLY__) 17 17 18 18 #include <linux/crash_core.h> 19 + #include <linux/vmcore_info.h> 19 20 #include <linux/crash_reserve.h> 20 21 #include <asm/io.h> 21 22 #include <linux/range.h>
+81
include/linux/vmcore_info.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef LINUX_VMCORE_INFO_H 3 + #define LINUX_VMCORE_INFO_H 4 + 5 + #include <linux/linkage.h> 6 + #include <linux/elfcore.h> 7 + #include <linux/elf.h> 8 + 9 + #define CRASH_CORE_NOTE_NAME "CORE" 10 + #define CRASH_CORE_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4) 11 + #define CRASH_CORE_NOTE_NAME_BYTES ALIGN(sizeof(CRASH_CORE_NOTE_NAME), 4) 12 + #define CRASH_CORE_NOTE_DESC_BYTES ALIGN(sizeof(struct elf_prstatus), 4) 13 + 14 + /* 15 + * The per-cpu notes area is a list of notes terminated by a "NULL" 16 + * note header. For kdump, the code in vmcore.c runs in the context 17 + * of the second kernel to combine them into one note. 18 + */ 19 + #define CRASH_CORE_NOTE_BYTES ((CRASH_CORE_NOTE_HEAD_BYTES * 2) + \ 20 + CRASH_CORE_NOTE_NAME_BYTES + \ 21 + CRASH_CORE_NOTE_DESC_BYTES) 22 + 23 + #define VMCOREINFO_BYTES PAGE_SIZE 24 + #define VMCOREINFO_NOTE_NAME "VMCOREINFO" 25 + #define VMCOREINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCOREINFO_NOTE_NAME), 4) 26 + #define VMCOREINFO_NOTE_SIZE ((CRASH_CORE_NOTE_HEAD_BYTES * 2) + \ 27 + VMCOREINFO_NOTE_NAME_BYTES + \ 28 + VMCOREINFO_BYTES) 29 + 30 + typedef u32 note_buf_t[CRASH_CORE_NOTE_BYTES/4]; 31 + /* Per cpu memory for storing cpu states in case of system crash. */ 32 + extern note_buf_t __percpu *crash_notes; 33 + 34 + void crash_update_vmcoreinfo_safecopy(void *ptr); 35 + void crash_save_vmcoreinfo(void); 36 + void arch_crash_save_vmcoreinfo(void); 37 + __printf(1, 2) 38 + void vmcoreinfo_append_str(const char *fmt, ...); 39 + phys_addr_t paddr_vmcoreinfo_note(void); 40 + 41 + #define VMCOREINFO_OSRELEASE(value) \ 42 + vmcoreinfo_append_str("OSRELEASE=%s\n", value) 43 + #define VMCOREINFO_BUILD_ID() \ 44 + ({ \ 45 + static_assert(sizeof(vmlinux_build_id) == 20); \ 46 + vmcoreinfo_append_str("BUILD-ID=%20phN\n", vmlinux_build_id); \ 47 + }) 48 + 49 + #define VMCOREINFO_PAGESIZE(value) \ 50 + vmcoreinfo_append_str("PAGESIZE=%ld\n", value) 51 + #define VMCOREINFO_SYMBOL(name) \ 52 + vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name) 53 + #define VMCOREINFO_SYMBOL_ARRAY(name) \ 54 + vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)name) 55 + #define VMCOREINFO_SIZE(name) \ 56 + vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \ 57 + (unsigned long)sizeof(name)) 58 + #define VMCOREINFO_STRUCT_SIZE(name) \ 59 + vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \ 60 + (unsigned long)sizeof(struct name)) 61 + #define VMCOREINFO_OFFSET(name, field) \ 62 + vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \ 63 + (unsigned long)offsetof(struct name, field)) 64 + #define VMCOREINFO_TYPE_OFFSET(name, field) \ 65 + vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \ 66 + (unsigned long)offsetof(name, field)) 67 + #define VMCOREINFO_LENGTH(name, value) \ 68 + vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value) 69 + #define VMCOREINFO_NUMBER(name) \ 70 + vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name) 71 + #define VMCOREINFO_CONFIG(name) \ 72 + vmcoreinfo_append_str("CONFIG_%s=y\n", #name) 73 + 74 + extern unsigned char *vmcoreinfo_data; 75 + extern size_t vmcoreinfo_size; 76 + extern u32 *vmcoreinfo_note; 77 + 78 + Elf_Word *append_elf_note(Elf_Word *buf, char *name, unsigned int type, 79 + void *data, size_t data_len); 80 + void final_note(Elf_Word *buf); 81 + #endif /* LINUX_VMCORE_INFO_H */
+2 -2
kernel/Kconfig.kexec
··· 5 5 config CRASH_RESERVE 6 6 bool 7 7 8 - config CRASH_CORE 8 + config VMCORE_INFO 9 9 bool 10 10 11 11 config KEXEC_CORE 12 - select CRASH_CORE 12 + select VMCORE_INFO 13 13 select CRASH_RESERVE 14 14 bool 15 15
+2 -2
kernel/Makefile
··· 68 68 obj-$(CONFIG_KALLSYMS) += kallsyms.o 69 69 obj-$(CONFIG_KALLSYMS_SELFTEST) += kallsyms_selftest.o 70 70 obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o 71 - obj-$(CONFIG_CRASH_CORE) += crash_core.o 71 + obj-$(CONFIG_VMCORE_INFO) += vmcore_info.o 72 72 obj-$(CONFIG_CRASH_RESERVE) += crash_reserve.o 73 - obj-$(CONFIG_KEXEC_CORE) += kexec_core.o 73 + obj-$(CONFIG_KEXEC_CORE) += kexec_core.o crash_core.o 74 74 obj-$(CONFIG_KEXEC) += kexec.o 75 75 obj-$(CONFIG_KEXEC_FILE) += kexec_file.o 76 76 obj-$(CONFIG_KEXEC_ELF) += kexec_elf.o
-206
kernel/crash_core.c
··· 26 26 /* Per cpu memory for storing cpu states in case of system crash. */ 27 27 note_buf_t __percpu *crash_notes; 28 28 29 - /* vmcoreinfo stuff */ 30 - unsigned char *vmcoreinfo_data; 31 - size_t vmcoreinfo_size; 32 - u32 *vmcoreinfo_note; 33 - 34 - /* trusted vmcoreinfo, e.g. we can make a copy in the crash memory */ 35 - static unsigned char *vmcoreinfo_data_safecopy; 36 - 37 29 int crash_prepare_elf64_headers(struct crash_mem *mem, int need_kernel_map, 38 30 void **addr, unsigned long *sz) 39 31 { ··· 186 194 187 195 return 0; 188 196 } 189 - 190 - Elf_Word *append_elf_note(Elf_Word *buf, char *name, unsigned int type, 191 - void *data, size_t data_len) 192 - { 193 - struct elf_note *note = (struct elf_note *)buf; 194 - 195 - note->n_namesz = strlen(name) + 1; 196 - note->n_descsz = data_len; 197 - note->n_type = type; 198 - buf += DIV_ROUND_UP(sizeof(*note), sizeof(Elf_Word)); 199 - memcpy(buf, name, note->n_namesz); 200 - buf += DIV_ROUND_UP(note->n_namesz, sizeof(Elf_Word)); 201 - memcpy(buf, data, data_len); 202 - buf += DIV_ROUND_UP(data_len, sizeof(Elf_Word)); 203 - 204 - return buf; 205 - } 206 - 207 - void final_note(Elf_Word *buf) 208 - { 209 - memset(buf, 0, sizeof(struct elf_note)); 210 - } 211 - 212 - static void update_vmcoreinfo_note(void) 213 - { 214 - u32 *buf = vmcoreinfo_note; 215 - 216 - if (!vmcoreinfo_size) 217 - return; 218 - buf = append_elf_note(buf, VMCOREINFO_NOTE_NAME, 0, vmcoreinfo_data, 219 - vmcoreinfo_size); 220 - final_note(buf); 221 - } 222 - 223 - void crash_update_vmcoreinfo_safecopy(void *ptr) 224 - { 225 - if (ptr) 226 - memcpy(ptr, vmcoreinfo_data, vmcoreinfo_size); 227 - 228 - vmcoreinfo_data_safecopy = ptr; 229 - } 230 - 231 - void crash_save_vmcoreinfo(void) 232 - { 233 - if (!vmcoreinfo_note) 234 - return; 235 - 236 - /* Use the safe copy to generate vmcoreinfo note if have */ 237 - if (vmcoreinfo_data_safecopy) 238 - vmcoreinfo_data = vmcoreinfo_data_safecopy; 239 - 240 - vmcoreinfo_append_str("CRASHTIME=%lld\n", ktime_get_real_seconds()); 241 - update_vmcoreinfo_note(); 242 - } 243 - 244 - void vmcoreinfo_append_str(const char *fmt, ...) 245 - { 246 - va_list args; 247 - char buf[0x50]; 248 - size_t r; 249 - 250 - va_start(args, fmt); 251 - r = vscnprintf(buf, sizeof(buf), fmt, args); 252 - va_end(args); 253 - 254 - r = min(r, (size_t)VMCOREINFO_BYTES - vmcoreinfo_size); 255 - 256 - memcpy(&vmcoreinfo_data[vmcoreinfo_size], buf, r); 257 - 258 - vmcoreinfo_size += r; 259 - 260 - WARN_ONCE(vmcoreinfo_size == VMCOREINFO_BYTES, 261 - "vmcoreinfo data exceeds allocated size, truncating"); 262 - } 263 - 264 - /* 265 - * provide an empty default implementation here -- architecture 266 - * code may override this 267 - */ 268 - void __weak arch_crash_save_vmcoreinfo(void) 269 - {} 270 - 271 - phys_addr_t __weak paddr_vmcoreinfo_note(void) 272 - { 273 - return __pa(vmcoreinfo_note); 274 - } 275 - EXPORT_SYMBOL(paddr_vmcoreinfo_note); 276 - 277 - static int __init crash_save_vmcoreinfo_init(void) 278 - { 279 - vmcoreinfo_data = (unsigned char *)get_zeroed_page(GFP_KERNEL); 280 - if (!vmcoreinfo_data) { 281 - pr_warn("Memory allocation for vmcoreinfo_data failed\n"); 282 - return -ENOMEM; 283 - } 284 - 285 - vmcoreinfo_note = alloc_pages_exact(VMCOREINFO_NOTE_SIZE, 286 - GFP_KERNEL | __GFP_ZERO); 287 - if (!vmcoreinfo_note) { 288 - free_page((unsigned long)vmcoreinfo_data); 289 - vmcoreinfo_data = NULL; 290 - pr_warn("Memory allocation for vmcoreinfo_note failed\n"); 291 - return -ENOMEM; 292 - } 293 - 294 - VMCOREINFO_OSRELEASE(init_uts_ns.name.release); 295 - VMCOREINFO_BUILD_ID(); 296 - VMCOREINFO_PAGESIZE(PAGE_SIZE); 297 - 298 - VMCOREINFO_SYMBOL(init_uts_ns); 299 - VMCOREINFO_OFFSET(uts_namespace, name); 300 - VMCOREINFO_SYMBOL(node_online_map); 301 - #ifdef CONFIG_MMU 302 - VMCOREINFO_SYMBOL_ARRAY(swapper_pg_dir); 303 - #endif 304 - VMCOREINFO_SYMBOL(_stext); 305 - vmcoreinfo_append_str("NUMBER(VMALLOC_START)=0x%lx\n", (unsigned long) VMALLOC_START); 306 - 307 - #ifndef CONFIG_NUMA 308 - VMCOREINFO_SYMBOL(mem_map); 309 - VMCOREINFO_SYMBOL(contig_page_data); 310 - #endif 311 - #ifdef CONFIG_SPARSEMEM 312 - VMCOREINFO_SYMBOL_ARRAY(mem_section); 313 - VMCOREINFO_LENGTH(mem_section, NR_SECTION_ROOTS); 314 - VMCOREINFO_STRUCT_SIZE(mem_section); 315 - VMCOREINFO_OFFSET(mem_section, section_mem_map); 316 - VMCOREINFO_NUMBER(SECTION_SIZE_BITS); 317 - VMCOREINFO_NUMBER(MAX_PHYSMEM_BITS); 318 - #endif 319 - VMCOREINFO_STRUCT_SIZE(page); 320 - VMCOREINFO_STRUCT_SIZE(pglist_data); 321 - VMCOREINFO_STRUCT_SIZE(zone); 322 - VMCOREINFO_STRUCT_SIZE(free_area); 323 - VMCOREINFO_STRUCT_SIZE(list_head); 324 - VMCOREINFO_SIZE(nodemask_t); 325 - VMCOREINFO_OFFSET(page, flags); 326 - VMCOREINFO_OFFSET(page, _refcount); 327 - VMCOREINFO_OFFSET(page, mapping); 328 - VMCOREINFO_OFFSET(page, lru); 329 - VMCOREINFO_OFFSET(page, _mapcount); 330 - VMCOREINFO_OFFSET(page, private); 331 - VMCOREINFO_OFFSET(page, compound_head); 332 - VMCOREINFO_OFFSET(pglist_data, node_zones); 333 - VMCOREINFO_OFFSET(pglist_data, nr_zones); 334 - #ifdef CONFIG_FLATMEM 335 - VMCOREINFO_OFFSET(pglist_data, node_mem_map); 336 - #endif 337 - VMCOREINFO_OFFSET(pglist_data, node_start_pfn); 338 - VMCOREINFO_OFFSET(pglist_data, node_spanned_pages); 339 - VMCOREINFO_OFFSET(pglist_data, node_id); 340 - VMCOREINFO_OFFSET(zone, free_area); 341 - VMCOREINFO_OFFSET(zone, vm_stat); 342 - VMCOREINFO_OFFSET(zone, spanned_pages); 343 - VMCOREINFO_OFFSET(free_area, free_list); 344 - VMCOREINFO_OFFSET(list_head, next); 345 - VMCOREINFO_OFFSET(list_head, prev); 346 - VMCOREINFO_LENGTH(zone.free_area, NR_PAGE_ORDERS); 347 - log_buf_vmcoreinfo_setup(); 348 - VMCOREINFO_LENGTH(free_area.free_list, MIGRATE_TYPES); 349 - VMCOREINFO_NUMBER(NR_FREE_PAGES); 350 - VMCOREINFO_NUMBER(PG_lru); 351 - VMCOREINFO_NUMBER(PG_private); 352 - VMCOREINFO_NUMBER(PG_swapcache); 353 - VMCOREINFO_NUMBER(PG_swapbacked); 354 - VMCOREINFO_NUMBER(PG_slab); 355 - #ifdef CONFIG_MEMORY_FAILURE 356 - VMCOREINFO_NUMBER(PG_hwpoison); 357 - #endif 358 - VMCOREINFO_NUMBER(PG_head_mask); 359 - #define PAGE_BUDDY_MAPCOUNT_VALUE (~PG_buddy) 360 - VMCOREINFO_NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE); 361 - #ifdef CONFIG_HUGETLB_PAGE 362 - VMCOREINFO_NUMBER(PG_hugetlb); 363 - #define PAGE_OFFLINE_MAPCOUNT_VALUE (~PG_offline) 364 - VMCOREINFO_NUMBER(PAGE_OFFLINE_MAPCOUNT_VALUE); 365 - #endif 366 - 367 - #ifdef CONFIG_KALLSYMS 368 - VMCOREINFO_SYMBOL(kallsyms_names); 369 - VMCOREINFO_SYMBOL(kallsyms_num_syms); 370 - VMCOREINFO_SYMBOL(kallsyms_token_table); 371 - VMCOREINFO_SYMBOL(kallsyms_token_index); 372 - #ifdef CONFIG_KALLSYMS_BASE_RELATIVE 373 - VMCOREINFO_SYMBOL(kallsyms_offsets); 374 - VMCOREINFO_SYMBOL(kallsyms_relative_base); 375 - #else 376 - VMCOREINFO_SYMBOL(kallsyms_addresses); 377 - #endif /* CONFIG_KALLSYMS_BASE_RELATIVE */ 378 - #endif /* CONFIG_KALLSYMS */ 379 - 380 - arch_crash_save_vmcoreinfo(); 381 - update_vmcoreinfo_note(); 382 - 383 - return 0; 384 - } 385 - 386 - subsys_initcall(crash_save_vmcoreinfo_init); 387 197 388 198 static int __init crash_notes_memory_init(void) 389 199 {
+3 -3
kernel/ksysfs.c
··· 154 154 155 155 #endif /* CONFIG_KEXEC_CORE */ 156 156 157 - #ifdef CONFIG_CRASH_CORE 157 + #ifdef CONFIG_VMCORE_INFO 158 158 159 159 static ssize_t vmcoreinfo_show(struct kobject *kobj, 160 160 struct kobj_attribute *attr, char *buf) ··· 177 177 178 178 #endif 179 179 180 - #endif /* CONFIG_CRASH_CORE */ 180 + #endif /* CONFIG_VMCORE_INFO */ 181 181 182 182 /* whether file capabilities are enabled */ 183 183 static ssize_t fscaps_show(struct kobject *kobj, ··· 265 265 &kexec_crash_loaded_attr.attr, 266 266 &kexec_crash_size_attr.attr, 267 267 #endif 268 - #ifdef CONFIG_CRASH_CORE 268 + #ifdef CONFIG_VMCORE_INFO 269 269 &vmcoreinfo_attr.attr, 270 270 #ifdef CONFIG_CRASH_HOTPLUG 271 271 &crash_elfcorehdr_size_attr.attr,
+2 -2
kernel/printk/printk.c
··· 34 34 #include <linux/security.h> 35 35 #include <linux/memblock.h> 36 36 #include <linux/syscalls.h> 37 - #include <linux/crash_core.h> 37 + #include <linux/vmcore_info.h> 38 38 #include <linux/ratelimit.h> 39 39 #include <linux/kmsg_dump.h> 40 40 #include <linux/syslog.h> ··· 951 951 .release = devkmsg_release, 952 952 }; 953 953 954 - #ifdef CONFIG_CRASH_CORE 954 + #ifdef CONFIG_VMCORE_INFO 955 955 /* 956 956 * This appends the listed symbols to /proc/vmcore 957 957 *
+230
kernel/vmcore_info.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * crash.c - kernel crash support code. 4 + * Copyright (C) 2002-2004 Eric Biederman <ebiederm@xmission.com> 5 + */ 6 + 7 + #include <linux/buildid.h> 8 + #include <linux/init.h> 9 + #include <linux/utsname.h> 10 + #include <linux/vmalloc.h> 11 + #include <linux/sizes.h> 12 + #include <linux/kexec.h> 13 + #include <linux/memory.h> 14 + #include <linux/cpuhotplug.h> 15 + #include <linux/memblock.h> 16 + #include <linux/kmemleak.h> 17 + 18 + #include <asm/page.h> 19 + #include <asm/sections.h> 20 + 21 + #include <crypto/sha1.h> 22 + 23 + #include "kallsyms_internal.h" 24 + #include "kexec_internal.h" 25 + 26 + /* vmcoreinfo stuff */ 27 + unsigned char *vmcoreinfo_data; 28 + size_t vmcoreinfo_size; 29 + u32 *vmcoreinfo_note; 30 + 31 + /* trusted vmcoreinfo, e.g. we can make a copy in the crash memory */ 32 + static unsigned char *vmcoreinfo_data_safecopy; 33 + 34 + Elf_Word *append_elf_note(Elf_Word *buf, char *name, unsigned int type, 35 + void *data, size_t data_len) 36 + { 37 + struct elf_note *note = (struct elf_note *)buf; 38 + 39 + note->n_namesz = strlen(name) + 1; 40 + note->n_descsz = data_len; 41 + note->n_type = type; 42 + buf += DIV_ROUND_UP(sizeof(*note), sizeof(Elf_Word)); 43 + memcpy(buf, name, note->n_namesz); 44 + buf += DIV_ROUND_UP(note->n_namesz, sizeof(Elf_Word)); 45 + memcpy(buf, data, data_len); 46 + buf += DIV_ROUND_UP(data_len, sizeof(Elf_Word)); 47 + 48 + return buf; 49 + } 50 + 51 + void final_note(Elf_Word *buf) 52 + { 53 + memset(buf, 0, sizeof(struct elf_note)); 54 + } 55 + 56 + static void update_vmcoreinfo_note(void) 57 + { 58 + u32 *buf = vmcoreinfo_note; 59 + 60 + if (!vmcoreinfo_size) 61 + return; 62 + buf = append_elf_note(buf, VMCOREINFO_NOTE_NAME, 0, vmcoreinfo_data, 63 + vmcoreinfo_size); 64 + final_note(buf); 65 + } 66 + 67 + void crash_update_vmcoreinfo_safecopy(void *ptr) 68 + { 69 + if (ptr) 70 + memcpy(ptr, vmcoreinfo_data, vmcoreinfo_size); 71 + 72 + vmcoreinfo_data_safecopy = ptr; 73 + } 74 + 75 + void crash_save_vmcoreinfo(void) 76 + { 77 + if (!vmcoreinfo_note) 78 + return; 79 + 80 + /* Use the safe copy to generate vmcoreinfo note if have */ 81 + if (vmcoreinfo_data_safecopy) 82 + vmcoreinfo_data = vmcoreinfo_data_safecopy; 83 + 84 + vmcoreinfo_append_str("CRASHTIME=%lld\n", ktime_get_real_seconds()); 85 + update_vmcoreinfo_note(); 86 + } 87 + 88 + void vmcoreinfo_append_str(const char *fmt, ...) 89 + { 90 + va_list args; 91 + char buf[0x50]; 92 + size_t r; 93 + 94 + va_start(args, fmt); 95 + r = vscnprintf(buf, sizeof(buf), fmt, args); 96 + va_end(args); 97 + 98 + r = min(r, (size_t)VMCOREINFO_BYTES - vmcoreinfo_size); 99 + 100 + memcpy(&vmcoreinfo_data[vmcoreinfo_size], buf, r); 101 + 102 + vmcoreinfo_size += r; 103 + 104 + WARN_ONCE(vmcoreinfo_size == VMCOREINFO_BYTES, 105 + "vmcoreinfo data exceeds allocated size, truncating"); 106 + } 107 + 108 + /* 109 + * provide an empty default implementation here -- architecture 110 + * code may override this 111 + */ 112 + void __weak arch_crash_save_vmcoreinfo(void) 113 + {} 114 + 115 + phys_addr_t __weak paddr_vmcoreinfo_note(void) 116 + { 117 + return __pa(vmcoreinfo_note); 118 + } 119 + EXPORT_SYMBOL(paddr_vmcoreinfo_note); 120 + 121 + static int __init crash_save_vmcoreinfo_init(void) 122 + { 123 + vmcoreinfo_data = (unsigned char *)get_zeroed_page(GFP_KERNEL); 124 + if (!vmcoreinfo_data) { 125 + pr_warn("Memory allocation for vmcoreinfo_data failed\n"); 126 + return -ENOMEM; 127 + } 128 + 129 + vmcoreinfo_note = alloc_pages_exact(VMCOREINFO_NOTE_SIZE, 130 + GFP_KERNEL | __GFP_ZERO); 131 + if (!vmcoreinfo_note) { 132 + free_page((unsigned long)vmcoreinfo_data); 133 + vmcoreinfo_data = NULL; 134 + pr_warn("Memory allocation for vmcoreinfo_note failed\n"); 135 + return -ENOMEM; 136 + } 137 + 138 + VMCOREINFO_OSRELEASE(init_uts_ns.name.release); 139 + VMCOREINFO_BUILD_ID(); 140 + VMCOREINFO_PAGESIZE(PAGE_SIZE); 141 + 142 + VMCOREINFO_SYMBOL(init_uts_ns); 143 + VMCOREINFO_OFFSET(uts_namespace, name); 144 + VMCOREINFO_SYMBOL(node_online_map); 145 + #ifdef CONFIG_MMU 146 + VMCOREINFO_SYMBOL_ARRAY(swapper_pg_dir); 147 + #endif 148 + VMCOREINFO_SYMBOL(_stext); 149 + vmcoreinfo_append_str("NUMBER(VMALLOC_START)=0x%lx\n", (unsigned long) VMALLOC_START); 150 + 151 + #ifndef CONFIG_NUMA 152 + VMCOREINFO_SYMBOL(mem_map); 153 + VMCOREINFO_SYMBOL(contig_page_data); 154 + #endif 155 + #ifdef CONFIG_SPARSEMEM 156 + VMCOREINFO_SYMBOL_ARRAY(mem_section); 157 + VMCOREINFO_LENGTH(mem_section, NR_SECTION_ROOTS); 158 + VMCOREINFO_STRUCT_SIZE(mem_section); 159 + VMCOREINFO_OFFSET(mem_section, section_mem_map); 160 + VMCOREINFO_NUMBER(SECTION_SIZE_BITS); 161 + VMCOREINFO_NUMBER(MAX_PHYSMEM_BITS); 162 + #endif 163 + VMCOREINFO_STRUCT_SIZE(page); 164 + VMCOREINFO_STRUCT_SIZE(pglist_data); 165 + VMCOREINFO_STRUCT_SIZE(zone); 166 + VMCOREINFO_STRUCT_SIZE(free_area); 167 + VMCOREINFO_STRUCT_SIZE(list_head); 168 + VMCOREINFO_SIZE(nodemask_t); 169 + VMCOREINFO_OFFSET(page, flags); 170 + VMCOREINFO_OFFSET(page, _refcount); 171 + VMCOREINFO_OFFSET(page, mapping); 172 + VMCOREINFO_OFFSET(page, lru); 173 + VMCOREINFO_OFFSET(page, _mapcount); 174 + VMCOREINFO_OFFSET(page, private); 175 + VMCOREINFO_OFFSET(page, compound_head); 176 + VMCOREINFO_OFFSET(pglist_data, node_zones); 177 + VMCOREINFO_OFFSET(pglist_data, nr_zones); 178 + #ifdef CONFIG_FLATMEM 179 + VMCOREINFO_OFFSET(pglist_data, node_mem_map); 180 + #endif 181 + VMCOREINFO_OFFSET(pglist_data, node_start_pfn); 182 + VMCOREINFO_OFFSET(pglist_data, node_spanned_pages); 183 + VMCOREINFO_OFFSET(pglist_data, node_id); 184 + VMCOREINFO_OFFSET(zone, free_area); 185 + VMCOREINFO_OFFSET(zone, vm_stat); 186 + VMCOREINFO_OFFSET(zone, spanned_pages); 187 + VMCOREINFO_OFFSET(free_area, free_list); 188 + VMCOREINFO_OFFSET(list_head, next); 189 + VMCOREINFO_OFFSET(list_head, prev); 190 + VMCOREINFO_LENGTH(zone.free_area, NR_PAGE_ORDERS); 191 + log_buf_vmcoreinfo_setup(); 192 + VMCOREINFO_LENGTH(free_area.free_list, MIGRATE_TYPES); 193 + VMCOREINFO_NUMBER(NR_FREE_PAGES); 194 + VMCOREINFO_NUMBER(PG_lru); 195 + VMCOREINFO_NUMBER(PG_private); 196 + VMCOREINFO_NUMBER(PG_swapcache); 197 + VMCOREINFO_NUMBER(PG_swapbacked); 198 + VMCOREINFO_NUMBER(PG_slab); 199 + #ifdef CONFIG_MEMORY_FAILURE 200 + VMCOREINFO_NUMBER(PG_hwpoison); 201 + #endif 202 + VMCOREINFO_NUMBER(PG_head_mask); 203 + #define PAGE_BUDDY_MAPCOUNT_VALUE (~PG_buddy) 204 + VMCOREINFO_NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE); 205 + #ifdef CONFIG_HUGETLB_PAGE 206 + VMCOREINFO_NUMBER(PG_hugetlb); 207 + #define PAGE_OFFLINE_MAPCOUNT_VALUE (~PG_offline) 208 + VMCOREINFO_NUMBER(PAGE_OFFLINE_MAPCOUNT_VALUE); 209 + #endif 210 + 211 + #ifdef CONFIG_KALLSYMS 212 + VMCOREINFO_SYMBOL(kallsyms_names); 213 + VMCOREINFO_SYMBOL(kallsyms_num_syms); 214 + VMCOREINFO_SYMBOL(kallsyms_token_table); 215 + VMCOREINFO_SYMBOL(kallsyms_token_index); 216 + #ifdef CONFIG_KALLSYMS_BASE_RELATIVE 217 + VMCOREINFO_SYMBOL(kallsyms_offsets); 218 + VMCOREINFO_SYMBOL(kallsyms_relative_base); 219 + #else 220 + VMCOREINFO_SYMBOL(kallsyms_addresses); 221 + #endif /* CONFIG_KALLSYMS_BASE_RELATIVE */ 222 + #endif /* CONFIG_KALLSYMS */ 223 + 224 + arch_crash_save_vmcoreinfo(); 225 + update_vmcoreinfo_note(); 226 + 227 + return 0; 228 + } 229 + 230 + subsys_initcall(crash_save_vmcoreinfo_init);
+1 -1
lib/buildid.c
··· 174 174 return parse_build_id_buf(build_id, NULL, buf, buf_size); 175 175 } 176 176 177 - #if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID) || IS_ENABLED(CONFIG_CRASH_CORE) 177 + #if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID) || IS_ENABLED(CONFIG_VMCORE_INFO) 178 178 unsigned char vmlinux_build_id[BUILD_ID_SIZE_MAX] __ro_after_init; 179 179 180 180 /**