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

proc/kcore: add vmcoreinfo note to /proc/kcore

The vmcoreinfo information is useful for runtime debugging tools, not just
for crash dumps. A lot of this information can be determined by other
means, but this is much more convenient, and it only adds a page at most
to the file.

Link: http://lkml.kernel.org/r/fddbcd08eed76344863303878b12de1c1e2a04b6.1531953780.git.osandov@fb.com
Signed-off-by: Omar Sandoval <osandov@fb.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Bhupesh Sharma <bhsharma@redhat.com>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: James Morse <james.morse@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Omar Sandoval and committed by
Linus Torvalds
23c85094 eff4345e

+21 -4
+1
fs/proc/Kconfig
··· 31 31 config PROC_KCORE 32 32 bool "/proc/kcore support" if !ARM 33 33 depends on PROC_FS && MMU 34 + select CRASH_CORE 34 35 help 35 36 Provides a virtual ELF core file of the live kernel. This can 36 37 be read with gdb and other ELF tools. No modifications can be
+16 -2
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 14 #include <linux/mm.h> 14 15 #include <linux/proc_fs.h> 15 16 #include <linux/kcore.h> ··· 82 81 } 83 82 84 83 *phdrs_len = *nphdr * sizeof(struct elf_phdr); 85 - *notes_len = (3 * (sizeof(struct elf_note) + ALIGN(sizeof(CORE_STR), 4)) + 84 + *notes_len = (4 * sizeof(struct elf_note) + 85 + 3 * ALIGN(sizeof(CORE_STR), 4) + 86 + VMCOREINFO_NOTE_NAME_BYTES + 86 87 ALIGN(sizeof(struct elf_prstatus), 4) + 87 88 ALIGN(sizeof(struct elf_prpsinfo), 4) + 88 - ALIGN(arch_task_struct_size, 4)); 89 + ALIGN(arch_task_struct_size, 4) + 90 + ALIGN(vmcoreinfo_size, 4)); 89 91 *data_offset = PAGE_ALIGN(sizeof(struct elfhdr) + *phdrs_len + 90 92 *notes_len); 91 93 return *data_offset + size; ··· 410 406 sizeof(prpsinfo)); 411 407 append_kcore_note(notes, &i, CORE_STR, NT_TASKSTRUCT, current, 412 408 arch_task_struct_size); 409 + /* 410 + * vmcoreinfo_size is mostly constant after init time, but it 411 + * can be changed by crash_save_vmcoreinfo(). Racing here with a 412 + * panic on another CPU before the machine goes down is insanely 413 + * unlikely, but it's better to not leave potential buffer 414 + * overflows lying around, regardless. 415 + */ 416 + append_kcore_note(notes, &i, VMCOREINFO_NOTE_NAME, 0, 417 + vmcoreinfo_data, 418 + min(vmcoreinfo_size, notes_len - i)); 413 419 414 420 tsz = min_t(size_t, buflen, notes_offset + notes_len - *fpos); 415 421 if (copy_to_user(buffer, notes + *fpos - notes_offset, tsz)) {
+2
include/linux/crash_core.h
··· 60 60 #define VMCOREINFO_CONFIG(name) \ 61 61 vmcoreinfo_append_str("CONFIG_%s=y\n", #name) 62 62 63 + extern unsigned char *vmcoreinfo_data; 64 + extern size_t vmcoreinfo_size; 63 65 extern u32 *vmcoreinfo_note; 64 66 65 67 Elf_Word *append_elf_note(Elf_Word *buf, char *name, unsigned int type,
+2 -2
kernel/crash_core.c
··· 14 14 #include <asm/sections.h> 15 15 16 16 /* vmcoreinfo stuff */ 17 - static unsigned char *vmcoreinfo_data; 18 - static size_t vmcoreinfo_size; 17 + unsigned char *vmcoreinfo_data; 18 + size_t vmcoreinfo_size; 19 19 u32 *vmcoreinfo_note; 20 20 21 21 /* trusted vmcoreinfo, e.g. we can make a copy in the crash memory */