Skip to content

Commit 02aff84

Browse files
Baoquan Heakpm00
authored andcommitted
crash: split crash dumping code out from kexec_core.c
Currently, KEXEC_CORE select CRASH_CORE automatically because crash codes need be built in to avoid compiling error when building kexec code even though the crash dumping functionality is not enabled. E.g -------------------- CONFIG_CRASH_CORE=y CONFIG_KEXEC_CORE=y CONFIG_KEXEC=y CONFIG_KEXEC_FILE=y --------------------- After splitting out crashkernel reservation code and vmcoreinfo exporting code, there's only crash related code left in kernel/crash_core.c. Now move crash related codes from kexec_core.c to crash_core.c and only build it in when CONFIG_CRASH_DUMP=y. And also wrap up crash codes inside CONFIG_CRASH_DUMP ifdeffery scope, or replace inappropriate CONFIG_KEXEC_CORE ifdef with CONFIG_CRASH_DUMP ifdef in generic kernel files. With these changes, crash_core codes are abstracted from kexec codes and can be disabled at all if only kexec reboot feature is wanted. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Baoquan He <[email protected]> Cc: Al Viro <[email protected]> Cc: Eric W. Biederman <[email protected]> Cc: Hari Bathini <[email protected]> Cc: Pingfan Liu <[email protected]> Cc: Klara Modin <[email protected]> Cc: Michael Kelley <[email protected]> Cc: Nathan Chancellor <[email protected]> Cc: Stephen Rothwell <[email protected]> Cc: Yang Li <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 2c44b67 commit 02aff84

File tree

10 files changed

+359
-292
lines changed

10 files changed

+359
-292
lines changed

drivers/base/cpu.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ static DEVICE_ATTR(release, S_IWUSR, NULL, cpu_release_store);
144144
#endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */
145145
#endif /* CONFIG_HOTPLUG_CPU */
146146

147-
#ifdef CONFIG_KEXEC_CORE
147+
#ifdef CONFIG_CRASH_DUMP
148148
#include <linux/kexec.h>
149149

150150
static ssize_t crash_notes_show(struct device *dev,
@@ -189,14 +189,14 @@ static const struct attribute_group crash_note_cpu_attr_group = {
189189
#endif
190190

191191
static const struct attribute_group *common_cpu_attr_groups[] = {
192-
#ifdef CONFIG_KEXEC_CORE
192+
#ifdef CONFIG_CRASH_DUMP
193193
&crash_note_cpu_attr_group,
194194
#endif
195195
NULL
196196
};
197197

198198
static const struct attribute_group *hotplugable_cpu_attr_groups[] = {
199-
#ifdef CONFIG_KEXEC_CORE
199+
#ifdef CONFIG_CRASH_DUMP
200200
&crash_note_cpu_attr_group,
201201
#endif
202202
NULL

include/linux/crash_core.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,48 @@
66
#include <linux/elfcore.h>
77
#include <linux/elf.h>
88

9+
struct kimage;
10+
11+
#ifdef CONFIG_CRASH_DUMP
12+
13+
int crash_shrink_memory(unsigned long new_size);
14+
ssize_t crash_get_memory_size(void);
15+
16+
#ifndef arch_kexec_protect_crashkres
17+
/*
18+
* Protection mechanism for crashkernel reserved memory after
19+
* the kdump kernel is loaded.
20+
*
21+
* Provide an empty default implementation here -- architecture
22+
* code may override this
23+
*/
24+
static inline void arch_kexec_protect_crashkres(void) { }
25+
#endif
26+
27+
#ifndef arch_kexec_unprotect_crashkres
28+
static inline void arch_kexec_unprotect_crashkres(void) { }
29+
#endif
30+
31+
32+
33+
#ifndef arch_crash_handle_hotplug_event
34+
static inline void arch_crash_handle_hotplug_event(struct kimage *image) { }
35+
#endif
36+
37+
int crash_check_update_elfcorehdr(void);
38+
39+
#ifndef crash_hotplug_cpu_support
40+
static inline int crash_hotplug_cpu_support(void) { return 0; }
41+
#endif
42+
43+
#ifndef crash_hotplug_memory_support
44+
static inline int crash_hotplug_memory_support(void) { return 0; }
45+
#endif
46+
47+
#ifndef crash_get_elfcorehdr_size
48+
static inline unsigned int crash_get_elfcorehdr_size(void) { return 0; }
49+
#endif
50+
951
/* Alignment required for elf header segment */
1052
#define ELF_CORE_HEADER_ALIGN 4096
1153

@@ -31,4 +73,23 @@ struct kexec_segment;
3173
#define KEXEC_CRASH_HP_REMOVE_MEMORY 4
3274
#define KEXEC_CRASH_HP_INVALID_CPU -1U
3375

76+
extern void __crash_kexec(struct pt_regs *regs);
77+
extern void crash_kexec(struct pt_regs *regs);
78+
int kexec_should_crash(struct task_struct *p);
79+
int kexec_crash_loaded(void);
80+
void crash_save_cpu(struct pt_regs *regs, int cpu);
81+
extern int kimage_crash_copy_vmcoreinfo(struct kimage *image);
82+
83+
#else /* !CONFIG_CRASH_DUMP*/
84+
struct pt_regs;
85+
struct task_struct;
86+
struct kimage;
87+
static inline void __crash_kexec(struct pt_regs *regs) { }
88+
static inline void crash_kexec(struct pt_regs *regs) { }
89+
static inline int kexec_should_crash(struct task_struct *p) { return 0; }
90+
static inline int kexec_crash_loaded(void) { return 0; }
91+
static inline void crash_save_cpu(struct pt_regs *regs, int cpu) {};
92+
static inline int kimage_crash_copy_vmcoreinfo(struct kimage *image) { return 0; };
93+
#endif /* CONFIG_CRASH_DUMP*/
94+
3495
#endif /* LINUX_CRASH_CORE_H */

include/linux/kexec.h

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#if !defined(__ASSEMBLY__)
1717

18-
#include <linux/crash_core.h>
1918
#include <linux/vmcore_info.h>
2019
#include <linux/crash_reserve.h>
2120
#include <asm/io.h>
@@ -33,6 +32,7 @@ extern note_buf_t __percpu *crash_notes;
3332
#include <linux/module.h>
3433
#include <linux/highmem.h>
3534
#include <asm/kexec.h>
35+
#include <linux/crash_core.h>
3636

3737
/* Verify architecture specific macros are defined */
3838

@@ -380,13 +380,6 @@ extern struct page *kimage_alloc_control_pages(struct kimage *image,
380380
static inline int machine_kexec_post_load(struct kimage *image) { return 0; }
381381
#endif
382382

383-
extern void __crash_kexec(struct pt_regs *);
384-
extern void crash_kexec(struct pt_regs *);
385-
int kexec_should_crash(struct task_struct *);
386-
int kexec_crash_loaded(void);
387-
void crash_save_cpu(struct pt_regs *regs, int cpu);
388-
extern int kimage_crash_copy_vmcoreinfo(struct kimage *image);
389-
390383
extern struct kimage *kexec_image;
391384
extern struct kimage *kexec_crash_image;
392385

@@ -410,24 +403,6 @@ bool kexec_load_permitted(int kexec_image_type);
410403
/* flag to track if kexec reboot is in progress */
411404
extern bool kexec_in_progress;
412405

413-
int crash_shrink_memory(unsigned long new_size);
414-
ssize_t crash_get_memory_size(void);
415-
416-
#ifndef arch_kexec_protect_crashkres
417-
/*
418-
* Protection mechanism for crashkernel reserved memory after
419-
* the kdump kernel is loaded.
420-
*
421-
* Provide an empty default implementation here -- architecture
422-
* code may override this
423-
*/
424-
static inline void arch_kexec_protect_crashkres(void) { }
425-
#endif
426-
427-
#ifndef arch_kexec_unprotect_crashkres
428-
static inline void arch_kexec_unprotect_crashkres(void) { }
429-
#endif
430-
431406
#ifndef page_to_boot_pfn
432407
static inline unsigned long page_to_boot_pfn(struct page *page)
433408
{
@@ -484,24 +459,6 @@ static inline int arch_kexec_post_alloc_pages(void *vaddr, unsigned int pages, g
484459
static inline void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages) { }
485460
#endif
486461

487-
#ifndef arch_crash_handle_hotplug_event
488-
static inline void arch_crash_handle_hotplug_event(struct kimage *image) { }
489-
#endif
490-
491-
int crash_check_update_elfcorehdr(void);
492-
493-
#ifndef crash_hotplug_cpu_support
494-
static inline int crash_hotplug_cpu_support(void) { return 0; }
495-
#endif
496-
497-
#ifndef crash_hotplug_memory_support
498-
static inline int crash_hotplug_memory_support(void) { return 0; }
499-
#endif
500-
501-
#ifndef crash_get_elfcorehdr_size
502-
static inline unsigned int crash_get_elfcorehdr_size(void) { return 0; }
503-
#endif
504-
505462
extern bool kexec_file_dbg_print;
506463

507464
#define kexec_dprintk(fmt, ...) \

init/initramfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ void __weak __init free_initrd_mem(unsigned long start, unsigned long end)
642642
"initrd");
643643
}
644644

645-
#ifdef CONFIG_KEXEC_CORE
645+
#ifdef CONFIG_CRASH_RESERVE
646646
static bool __init kexec_free_initrd(void)
647647
{
648648
unsigned long crashk_start = (unsigned long)__va(crashk_res.start);

kernel/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ obj-$(CONFIG_KALLSYMS_SELFTEST) += kallsyms_selftest.o
7070
obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o
7171
obj-$(CONFIG_VMCORE_INFO) += vmcore_info.o elfcorehdr.o
7272
obj-$(CONFIG_CRASH_RESERVE) += crash_reserve.o
73-
obj-$(CONFIG_KEXEC_CORE) += kexec_core.o crash_core.o
73+
obj-$(CONFIG_KEXEC_CORE) += kexec_core.o
74+
obj-$(CONFIG_CRASH_DUMP) += crash_core.o
7475
obj-$(CONFIG_KEXEC) += kexec.o
7576
obj-$(CONFIG_KEXEC_FILE) += kexec_file.o
7677
obj-$(CONFIG_KEXEC_ELF) += kexec_elf.o

0 commit comments

Comments
 (0)