Skip to content

Commit 8757dc9

Browse files
osandovsuryasaimadhu
authored andcommitted
x86/crash: Define arch_crash_save_vmcoreinfo() if CONFIG_CRASH_CORE=y
On x86 kernels configured with CONFIG_PROC_KCORE=y and CONFIG_KEXEC_CORE=n, the vmcoreinfo note in /proc/kcore is incomplete. Specifically, it is missing arch-specific information like the KASLR offset and whether 5-level page tables are enabled. This breaks applications like drgn [1] and crash [2], which need this information for live debugging via /proc/kcore. This happens because: 1. CONFIG_PROC_KCORE selects CONFIG_CRASH_CORE. 2. kernel/crash_core.c (compiled if CONFIG_CRASH_CORE=y) calls arch_crash_save_vmcoreinfo() to get the arch-specific parts of vmcoreinfo. If it is not defined, then it uses a no-op fallback. 3. x86 defines arch_crash_save_vmcoreinfo() in arch/x86/kernel/machine_kexec_*.c, which is only compiled if CONFIG_KEXEC_CORE=y. Therefore, an x86 kernel with CONFIG_CRASH_CORE=y and CONFIG_KEXEC_CORE=n uses the no-op fallback and gets incomplete vmcoreinfo data. This isn't relevant to kdump, which requires CONFIG_KEXEC_CORE. It only affects applications which read vmcoreinfo at runtime, like the ones mentioned above. Fix it by moving arch_crash_save_vmcoreinfo() into two new arch/x86/kernel/crash_core_*.c files, which are gated behind CONFIG_CRASH_CORE. 1: https://github.com/osandov/drgn/blob/73dd7def1217e24cc83d8ca95c995decbd9ba24c/libdrgn/program.c#L385 2: crash-utility/crash@60a42d7 Signed-off-by: Omar Sandoval <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Kairui Song <[email protected]> Cc: Lianbo Jiang <[email protected]> Cc: Masahiro Yamada <[email protected]> Cc: "Peter Zijlstra (Intel)" <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: x86-ml <[email protected]> Link: https://lkml.kernel.org/r/0589961254102cca23e3618b96541b89f2b249e2.1576858905.git.osandov@fb.com
1 parent 46cf053 commit 8757dc9

File tree

5 files changed

+42
-31
lines changed

5 files changed

+42
-31
lines changed

arch/x86/kernel/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ obj-$(CONFIG_FUNCTION_TRACER) += ftrace_$(BITS).o
9494
obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o
9595
obj-$(CONFIG_FTRACE_SYSCALLS) += ftrace.o
9696
obj-$(CONFIG_X86_TSC) += trace_clock.o
97+
obj-$(CONFIG_CRASH_CORE) += crash_core_$(BITS).o
9798
obj-$(CONFIG_KEXEC_CORE) += machine_kexec_$(BITS).o
9899
obj-$(CONFIG_KEXEC_CORE) += relocate_kernel_$(BITS).o crash.o
99100
obj-$(CONFIG_KEXEC_FILE) += kexec-bzimage64.o

arch/x86/kernel/crash_core_32.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
3+
#include <linux/crash_core.h>
4+
5+
#include <asm/pgtable.h>
6+
#include <asm/setup.h>
7+
8+
void arch_crash_save_vmcoreinfo(void)
9+
{
10+
#ifdef CONFIG_NUMA
11+
VMCOREINFO_SYMBOL(node_data);
12+
VMCOREINFO_LENGTH(node_data, MAX_NUMNODES);
13+
#endif
14+
#ifdef CONFIG_X86_PAE
15+
VMCOREINFO_CONFIG(X86_PAE);
16+
#endif
17+
}

arch/x86/kernel/crash_core_64.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
3+
#include <linux/crash_core.h>
4+
5+
#include <asm/pgtable.h>
6+
#include <asm/setup.h>
7+
8+
void arch_crash_save_vmcoreinfo(void)
9+
{
10+
u64 sme_mask = sme_me_mask;
11+
12+
VMCOREINFO_NUMBER(phys_base);
13+
VMCOREINFO_SYMBOL(init_top_pgt);
14+
vmcoreinfo_append_str("NUMBER(pgtable_l5_enabled)=%d\n",
15+
pgtable_l5_enabled());
16+
17+
#ifdef CONFIG_NUMA
18+
VMCOREINFO_SYMBOL(node_data);
19+
VMCOREINFO_LENGTH(node_data, MAX_NUMNODES);
20+
#endif
21+
vmcoreinfo_append_str("KERNELOFFSET=%lx\n", kaslr_offset());
22+
VMCOREINFO_NUMBER(KERNEL_IMAGE_SIZE);
23+
VMCOREINFO_NUMBER(sme_mask);
24+
}

arch/x86/kernel/machine_kexec_32.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,3 @@ void machine_kexec(struct kimage *image)
250250

251251
__ftrace_enabled_restore(save_ftrace_enabled);
252252
}
253-
254-
void arch_crash_save_vmcoreinfo(void)
255-
{
256-
#ifdef CONFIG_NUMA
257-
VMCOREINFO_SYMBOL(node_data);
258-
VMCOREINFO_LENGTH(node_data, MAX_NUMNODES);
259-
#endif
260-
#ifdef CONFIG_X86_PAE
261-
VMCOREINFO_CONFIG(X86_PAE);
262-
#endif
263-
}
264-

arch/x86/kernel/machine_kexec_64.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -398,25 +398,6 @@ void machine_kexec(struct kimage *image)
398398
__ftrace_enabled_restore(save_ftrace_enabled);
399399
}
400400

401-
void arch_crash_save_vmcoreinfo(void)
402-
{
403-
u64 sme_mask = sme_me_mask;
404-
405-
VMCOREINFO_NUMBER(phys_base);
406-
VMCOREINFO_SYMBOL(init_top_pgt);
407-
vmcoreinfo_append_str("NUMBER(pgtable_l5_enabled)=%d\n",
408-
pgtable_l5_enabled());
409-
410-
#ifdef CONFIG_NUMA
411-
VMCOREINFO_SYMBOL(node_data);
412-
VMCOREINFO_LENGTH(node_data, MAX_NUMNODES);
413-
#endif
414-
vmcoreinfo_append_str("KERNELOFFSET=%lx\n",
415-
kaslr_offset());
416-
VMCOREINFO_NUMBER(KERNEL_IMAGE_SIZE);
417-
VMCOREINFO_NUMBER(sme_mask);
418-
}
419-
420401
/* arch-dependent functionality related to kexec file-based syscall */
421402

422403
#ifdef CONFIG_KEXEC_FILE

0 commit comments

Comments
 (0)