Skip to content

Commit 692f66f

Browse files
Hari Bathinitorvalds
authored andcommitted
crash: move crashkernel parsing and vmcore related code under CONFIG_CRASH_CORE
Patch series "kexec/fadump: remove dependency with CONFIG_KEXEC and reuse crashkernel parameter for fadump", v4. Traditionally, kdump is used to save vmcore in case of a crash. Some architectures like powerpc can save vmcore using architecture specific support instead of kexec/kdump mechanism. Such architecture specific support also needs to reserve memory, to be used by dump capture kernel. crashkernel parameter can be a reused, for memory reservation, by such architecture specific infrastructure. This patchset removes dependency with CONFIG_KEXEC for crashkernel parameter and vmcoreinfo related code as it can be reused without kexec support. Also, crashkernel parameter is reused instead of fadump_reserve_mem to reserve memory for fadump. The first patch moves crashkernel parameter parsing and vmcoreinfo related code under CONFIG_CRASH_CORE instead of CONFIG_KEXEC_CORE. The second patch reuses the definitions of append_elf_note() & final_note() functions under CONFIG_CRASH_CORE in IA64 arch code. The third patch removes dependency on CONFIG_KEXEC for firmware-assisted dump (fadump) in powerpc. The next patch reuses crashkernel parameter for reserving memory for fadump, instead of the fadump_reserve_mem parameter. This has the advantage of using all syntaxes crashkernel parameter supports, for fadump as well. The last patch updates fadump kernel documentation about use of crashkernel parameter. This patch (of 5): Traditionally, kdump is used to save vmcore in case of a crash. Some architectures like powerpc can save vmcore using architecture specific support instead of kexec/kdump mechanism. Such architecture specific support also needs to reserve memory, to be used by dump capture kernel. crashkernel parameter can be a reused, for memory reservation, by such architecture specific infrastructure. But currently, code related to vmcoreinfo and parsing of crashkernel parameter is built under CONFIG_KEXEC_CORE. This patch introduces CONFIG_CRASH_CORE and moves the above mentioned code under this config, allowing code reuse without dependency on CONFIG_KEXEC. There is no functional change with this patch. Link: http://lkml.kernel.org/r/149035338104.6881.4550894432615189948.stgit@hbathini.in.ibm.com Signed-off-by: Hari Bathini <hbathini@linux.vnet.ibm.com> Acked-by: Dave Young <dyoung@redhat.com> Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: Tony Luck <tony.luck@intel.com> Cc: Eric Biederman <ebiederm@xmission.com> Cc: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com> Cc: Vivek Goyal <vgoyal@redhat.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent c311c79 commit 692f66f

9 files changed

Lines changed: 531 additions & 462 deletions

File tree

‎arch/Kconfig‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
# General architecture dependent options
33
#
44

5+
config CRASH_CORE
6+
bool
7+
58
config KEXEC_CORE
9+
select CRASH_CORE
610
bool
711

812
config HAVE_IMA_KEXEC

‎include/linux/crash_core.h‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#ifndef LINUX_CRASH_CORE_H
2+
#define LINUX_CRASH_CORE_H
3+
4+
#include <linux/linkage.h>
5+
#include <linux/elfcore.h>
6+
#include <linux/elf.h>
7+
8+
#define CRASH_CORE_NOTE_NAME "CORE"
9+
#define CRASH_CORE_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4)
10+
#define CRASH_CORE_NOTE_NAME_BYTES ALIGN(sizeof(CRASH_CORE_NOTE_NAME), 4)
11+
#define CRASH_CORE_NOTE_DESC_BYTES ALIGN(sizeof(struct elf_prstatus), 4)
12+
13+
#define CRASH_CORE_NOTE_BYTES ((CRASH_CORE_NOTE_HEAD_BYTES * 2) + \
14+
CRASH_CORE_NOTE_NAME_BYTES + \
15+
CRASH_CORE_NOTE_DESC_BYTES)
16+
17+
#define VMCOREINFO_BYTES (4096)
18+
#define VMCOREINFO_NOTE_NAME "VMCOREINFO"
19+
#define VMCOREINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCOREINFO_NOTE_NAME), 4)
20+
#define VMCOREINFO_NOTE_SIZE ((CRASH_CORE_NOTE_HEAD_BYTES * 2) + \
21+
VMCOREINFO_NOTE_NAME_BYTES + \
22+
VMCOREINFO_BYTES)
23+
24+
typedef u32 note_buf_t[CRASH_CORE_NOTE_BYTES/4];
25+
26+
void crash_save_vmcoreinfo(void);
27+
void arch_crash_save_vmcoreinfo(void);
28+
__printf(1, 2)
29+
void vmcoreinfo_append_str(const char *fmt, ...);
30+
phys_addr_t paddr_vmcoreinfo_note(void);
31+
32+
#define VMCOREINFO_OSRELEASE(value) \
33+
vmcoreinfo_append_str("OSRELEASE=%s\n", value)
34+
#define VMCOREINFO_PAGESIZE(value) \
35+
vmcoreinfo_append_str("PAGESIZE=%ld\n", value)
36+
#define VMCOREINFO_SYMBOL(name) \
37+
vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name)
38+
#define VMCOREINFO_SIZE(name) \
39+
vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
40+
(unsigned long)sizeof(name))
41+
#define VMCOREINFO_STRUCT_SIZE(name) \
42+
vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
43+
(unsigned long)sizeof(struct name))
44+
#define VMCOREINFO_OFFSET(name, field) \
45+
vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \
46+
(unsigned long)offsetof(struct name, field))
47+
#define VMCOREINFO_LENGTH(name, value) \
48+
vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value)
49+
#define VMCOREINFO_NUMBER(name) \
50+
vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name)
51+
#define VMCOREINFO_CONFIG(name) \
52+
vmcoreinfo_append_str("CONFIG_%s=y\n", #name)
53+
54+
extern u32 vmcoreinfo_note[VMCOREINFO_NOTE_SIZE/4];
55+
extern size_t vmcoreinfo_size;
56+
extern size_t vmcoreinfo_max_size;
57+
58+
int __init parse_crashkernel(char *cmdline, unsigned long long system_ram,
59+
unsigned long long *crash_size, unsigned long long *crash_base);
60+
int parse_crashkernel_high(char *cmdline, unsigned long long system_ram,
61+
unsigned long long *crash_size, unsigned long long *crash_base);
62+
int parse_crashkernel_low(char *cmdline, unsigned long long system_ram,
63+
unsigned long long *crash_size, unsigned long long *crash_base);
64+
65+
#endif /* LINUX_CRASH_CORE_H */

‎include/linux/kexec.h‎

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,15 @@
1414

1515
#if !defined(__ASSEMBLY__)
1616

17+
#include <linux/crash_core.h>
1718
#include <asm/io.h>
1819

1920
#include <uapi/linux/kexec.h>
2021

2122
#ifdef CONFIG_KEXEC_CORE
2223
#include <linux/list.h>
23-
#include <linux/linkage.h>
2424
#include <linux/compat.h>
2525
#include <linux/ioport.h>
26-
#include <linux/elfcore.h>
27-
#include <linux/elf.h>
2826
#include <linux/module.h>
2927
#include <asm/kexec.h>
3028

@@ -62,19 +60,15 @@
6260
#define KEXEC_CRASH_MEM_ALIGN PAGE_SIZE
6361
#endif
6462

65-
#define KEXEC_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4)
66-
#define KEXEC_CORE_NOTE_NAME "CORE"
67-
#define KEXEC_CORE_NOTE_NAME_BYTES ALIGN(sizeof(KEXEC_CORE_NOTE_NAME), 4)
68-
#define KEXEC_CORE_NOTE_DESC_BYTES ALIGN(sizeof(struct elf_prstatus), 4)
63+
#define KEXEC_CORE_NOTE_NAME CRASH_CORE_NOTE_NAME
64+
6965
/*
7066
* The per-cpu notes area is a list of notes terminated by a "NULL"
7167
* note header. For kdump, the code in vmcore.c runs in the context
7268
* of the second kernel to combine them into one note.
7369
*/
7470
#ifndef KEXEC_NOTE_BYTES
75-
#define KEXEC_NOTE_BYTES ( (KEXEC_NOTE_HEAD_BYTES * 2) + \
76-
KEXEC_CORE_NOTE_NAME_BYTES + \
77-
KEXEC_CORE_NOTE_DESC_BYTES )
71+
#define KEXEC_NOTE_BYTES CRASH_CORE_NOTE_BYTES
7872
#endif
7973

8074
/*
@@ -256,33 +250,6 @@ extern void crash_kexec(struct pt_regs *);
256250
int kexec_should_crash(struct task_struct *);
257251
int kexec_crash_loaded(void);
258252
void crash_save_cpu(struct pt_regs *regs, int cpu);
259-
void crash_save_vmcoreinfo(void);
260-
void arch_crash_save_vmcoreinfo(void);
261-
__printf(1, 2)
262-
void vmcoreinfo_append_str(const char *fmt, ...);
263-
phys_addr_t paddr_vmcoreinfo_note(void);
264-
265-
#define VMCOREINFO_OSRELEASE(value) \
266-
vmcoreinfo_append_str("OSRELEASE=%s\n", value)
267-
#define VMCOREINFO_PAGESIZE(value) \
268-
vmcoreinfo_append_str("PAGESIZE=%ld\n", value)
269-
#define VMCOREINFO_SYMBOL(name) \
270-
vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name)
271-
#define VMCOREINFO_SIZE(name) \
272-
vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
273-
(unsigned long)sizeof(name))
274-
#define VMCOREINFO_STRUCT_SIZE(name) \
275-
vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
276-
(unsigned long)sizeof(struct name))
277-
#define VMCOREINFO_OFFSET(name, field) \
278-
vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \
279-
(unsigned long)offsetof(struct name, field))
280-
#define VMCOREINFO_LENGTH(name, value) \
281-
vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value)
282-
#define VMCOREINFO_NUMBER(name) \
283-
vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name)
284-
#define VMCOREINFO_CONFIG(name) \
285-
vmcoreinfo_append_str("CONFIG_%s=y\n", #name)
286253

287254
extern struct kimage *kexec_image;
288255
extern struct kimage *kexec_crash_image;
@@ -303,31 +270,15 @@ extern int kexec_load_disabled;
303270
#define KEXEC_FILE_FLAGS (KEXEC_FILE_UNLOAD | KEXEC_FILE_ON_CRASH | \
304271
KEXEC_FILE_NO_INITRAMFS)
305272

306-
#define VMCOREINFO_BYTES (4096)
307-
#define VMCOREINFO_NOTE_NAME "VMCOREINFO"
308-
#define VMCOREINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCOREINFO_NOTE_NAME), 4)
309-
#define VMCOREINFO_NOTE_SIZE (KEXEC_NOTE_HEAD_BYTES*2 + VMCOREINFO_BYTES \
310-
+ VMCOREINFO_NOTE_NAME_BYTES)
311-
312273
/* Location of a reserved region to hold the crash kernel.
313274
*/
314275
extern struct resource crashk_res;
315276
extern struct resource crashk_low_res;
316-
typedef u32 note_buf_t[KEXEC_NOTE_BYTES/4];
317277
extern note_buf_t __percpu *crash_notes;
318-
extern u32 vmcoreinfo_note[VMCOREINFO_NOTE_SIZE/4];
319-
extern size_t vmcoreinfo_size;
320-
extern size_t vmcoreinfo_max_size;
321278

322279
/* flag to track if kexec reboot is in progress */
323280
extern bool kexec_in_progress;
324281

325-
int __init parse_crashkernel(char *cmdline, unsigned long long system_ram,
326-
unsigned long long *crash_size, unsigned long long *crash_base);
327-
int parse_crashkernel_high(char *cmdline, unsigned long long system_ram,
328-
unsigned long long *crash_size, unsigned long long *crash_base);
329-
int parse_crashkernel_low(char *cmdline, unsigned long long system_ram,
330-
unsigned long long *crash_size, unsigned long long *crash_base);
331282
int crash_shrink_memory(unsigned long new_size);
332283
size_t crash_get_memory_size(void);
333284
void crash_free_reserved_phys_range(unsigned long begin, unsigned long end);

‎include/linux/printk.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ extern void wake_up_klogd(void);
198198

199199
char *log_buf_addr_get(void);
200200
u32 log_buf_len_get(void);
201-
void log_buf_kexec_setup(void);
201+
void log_buf_vmcoreinfo_setup(void);
202202
void __init setup_log_buf(int early);
203203
__printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...);
204204
void dump_stack_print_info(const char *log_lvl);
@@ -246,7 +246,7 @@ static inline u32 log_buf_len_get(void)
246246
return 0;
247247
}
248248

249-
static inline void log_buf_kexec_setup(void)
249+
static inline void log_buf_vmcoreinfo_setup(void)
250250
{
251251
}
252252

‎kernel/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ obj-$(CONFIG_MODULES) += module.o
5959
obj-$(CONFIG_MODULE_SIG) += module_signing.o
6060
obj-$(CONFIG_KALLSYMS) += kallsyms.o
6161
obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o
62+
obj-$(CONFIG_CRASH_CORE) += crash_core.o
6263
obj-$(CONFIG_KEXEC_CORE) += kexec_core.o
6364
obj-$(CONFIG_KEXEC) += kexec.o
6465
obj-$(CONFIG_KEXEC_FILE) += kexec_file.o

0 commit comments

Comments
 (0)