]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/kexec.h
8021q: fix a potential memory leak
[mirror_ubuntu-bionic-kernel.git] / include / linux / kexec.h
CommitLineData
dc009d92
EB
1#ifndef LINUX_KEXEC_H
2#define LINUX_KEXEC_H
3
607ca46e 4#include <uapi/linux/kexec.h>
29a5c67e 5
29a5c67e 6#ifdef CONFIG_KEXEC
dc009d92
EB
7#include <linux/list.h>
8#include <linux/linkage.h>
9#include <linux/compat.h>
9c15e852 10#include <linux/ioport.h>
6672f76a
SH
11#include <linux/elfcore.h>
12#include <linux/elf.h>
dc009d92
EB
13#include <asm/kexec.h>
14
15/* Verify architecture specific macros are defined */
16
17#ifndef KEXEC_SOURCE_MEMORY_LIMIT
18#error KEXEC_SOURCE_MEMORY_LIMIT not defined
19#endif
20
21#ifndef KEXEC_DESTINATION_MEMORY_LIMIT
22#error KEXEC_DESTINATION_MEMORY_LIMIT not defined
23#endif
24
25#ifndef KEXEC_CONTROL_MEMORY_LIMIT
26#error KEXEC_CONTROL_MEMORY_LIMIT not defined
27#endif
28
163f6876
HY
29#ifndef KEXEC_CONTROL_PAGE_SIZE
30#error KEXEC_CONTROL_PAGE_SIZE not defined
dc009d92
EB
31#endif
32
33#ifndef KEXEC_ARCH
34#error KEXEC_ARCH not defined
35#endif
36
3d214fae
MH
37#ifndef KEXEC_CRASH_CONTROL_MEMORY_LIMIT
38#define KEXEC_CRASH_CONTROL_MEMORY_LIMIT KEXEC_CONTROL_MEMORY_LIMIT
39#endif
40
558df720
MH
41#ifndef KEXEC_CRASH_MEM_ALIGN
42#define KEXEC_CRASH_MEM_ALIGN PAGE_SIZE
43#endif
44
6672f76a
SH
45#define KEXEC_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4)
46#define KEXEC_CORE_NOTE_NAME "CORE"
47#define KEXEC_CORE_NOTE_NAME_BYTES ALIGN(sizeof(KEXEC_CORE_NOTE_NAME), 4)
48#define KEXEC_CORE_NOTE_DESC_BYTES ALIGN(sizeof(struct elf_prstatus), 4)
49/*
50 * The per-cpu notes area is a list of notes terminated by a "NULL"
51 * note header. For kdump, the code in vmcore.c runs in the context
52 * of the second kernel to combine them into one note.
53 */
cb78edfd 54#ifndef KEXEC_NOTE_BYTES
6672f76a
SH
55#define KEXEC_NOTE_BYTES ( (KEXEC_NOTE_HEAD_BYTES * 2) + \
56 KEXEC_CORE_NOTE_NAME_BYTES + \
57 KEXEC_CORE_NOTE_DESC_BYTES )
cb78edfd 58#endif
6672f76a 59
dc009d92
EB
60/*
61 * This structure is used to hold the arguments that are used when loading
62 * kernel binaries.
63 */
64
65typedef unsigned long kimage_entry_t;
66#define IND_DESTINATION 0x1
67#define IND_INDIRECTION 0x2
68#define IND_DONE 0x4
69#define IND_SOURCE 0x8
70
dc009d92
EB
71struct kexec_segment {
72 void __user *buf;
73 size_t bufsz;
29a5c67e 74 unsigned long mem;
dc009d92
EB
75 size_t memsz;
76};
77
78#ifdef CONFIG_COMPAT
79struct compat_kexec_segment {
80 compat_uptr_t buf;
81 compat_size_t bufsz;
82 compat_ulong_t mem; /* User space sees this as a (void *) ... */
83 compat_size_t memsz;
84};
85#endif
86
87struct kimage {
88 kimage_entry_t head;
89 kimage_entry_t *entry;
90 kimage_entry_t *last_entry;
91
92 unsigned long destination;
93
94 unsigned long start;
95 struct page *control_code_page;
3ab83521 96 struct page *swap_page;
dc009d92
EB
97
98 unsigned long nr_segments;
99 struct kexec_segment segment[KEXEC_SEGMENT_MAX];
100
101 struct list_head control_pages;
102 struct list_head dest_pages;
103 struct list_head unuseable_pages;
104
105 /* Address of next control page to allocate for crash kernels. */
106 unsigned long control_page;
107
108 /* Flags to indicate special processing */
109 unsigned int type : 1;
110#define KEXEC_TYPE_DEFAULT 0
111#define KEXEC_TYPE_CRASH 1
3ab83521 112 unsigned int preserve_context : 1;
92be3d6b
HY
113
114#ifdef ARCH_HAS_KIMAGE_ARCH
115 struct kimage_arch arch;
116#endif
dc009d92
EB
117};
118
119
120
121/* kexec interface functions */
3ab83521 122extern void machine_kexec(struct kimage *image);
dc009d92
EB
123extern int machine_kexec_prepare(struct kimage *image);
124extern void machine_kexec_cleanup(struct kimage *image);
125extern asmlinkage long sys_kexec_load(unsigned long entry,
72414d3f
MS
126 unsigned long nr_segments,
127 struct kexec_segment __user *segments,
128 unsigned long flags);
3ab83521 129extern int kernel_kexec(void);
72414d3f
MS
130extern struct page *kimage_alloc_control_pages(struct kimage *image,
131 unsigned int order);
6e274d14
AN
132extern void crash_kexec(struct pt_regs *);
133int kexec_should_crash(struct task_struct *);
85916f81 134void crash_save_cpu(struct pt_regs *regs, int cpu);
fd59d231 135void crash_save_vmcoreinfo(void);
558df720
MH
136void crash_map_reserved_pages(void);
137void crash_unmap_reserved_pages(void);
fd59d231 138void arch_crash_save_vmcoreinfo(void);
b9075fa9
JP
139__printf(1, 2)
140void vmcoreinfo_append_str(const char *fmt, ...);
fd59d231
KO
141unsigned long paddr_vmcoreinfo_note(void);
142
c6e2bee2
BW
143#define VMCOREINFO_OSRELEASE(value) \
144 vmcoreinfo_append_str("OSRELEASE=%s\n", value)
bba1f603
KO
145#define VMCOREINFO_PAGESIZE(value) \
146 vmcoreinfo_append_str("PAGESIZE=%ld\n", value)
bcbba6c1 147#define VMCOREINFO_SYMBOL(name) \
fd59d231 148 vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name)
bcbba6c1 149#define VMCOREINFO_SIZE(name) \
6cfa062f
KO
150 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
151 (unsigned long)sizeof(name))
c76f860c
KO
152#define VMCOREINFO_STRUCT_SIZE(name) \
153 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
154 (unsigned long)sizeof(struct name))
bcbba6c1 155#define VMCOREINFO_OFFSET(name, field) \
d768281e 156 vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \
1e4f2955 157 (unsigned long)offsetof(struct name, field))
bcbba6c1 158#define VMCOREINFO_LENGTH(name, value) \
d768281e 159 vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value)
bcbba6c1 160#define VMCOREINFO_NUMBER(name) \
6cfa062f 161 vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name)
bcbba6c1 162#define VMCOREINFO_CONFIG(name) \
fd59d231
KO
163 vmcoreinfo_append_str("CONFIG_%s=y\n", #name)
164
dc009d92 165extern struct kimage *kexec_image;
c330dda9 166extern struct kimage *kexec_crash_image;
7984754b 167extern int kexec_load_disabled;
dc009d92 168
a7956113
ZN
169#ifndef kexec_flush_icache_page
170#define kexec_flush_icache_page(page)
171#endif
172
3ab83521
HY
173/* List of defined/legal kexec flags */
174#ifndef CONFIG_KEXEC_JUMP
175#define KEXEC_FLAGS KEXEC_ON_CRASH
176#else
177#define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT)
178#endif
dc009d92 179
fd59d231
KO
180#define VMCOREINFO_BYTES (4096)
181#define VMCOREINFO_NOTE_NAME "VMCOREINFO"
182#define VMCOREINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCOREINFO_NOTE_NAME), 4)
183#define VMCOREINFO_NOTE_SIZE (KEXEC_NOTE_HEAD_BYTES*2 + VMCOREINFO_BYTES \
184 + VMCOREINFO_NOTE_NAME_BYTES)
185
dc009d92
EB
186/* Location of a reserved region to hold the crash kernel.
187 */
188extern struct resource crashk_res;
0212f915 189extern struct resource crashk_low_res;
6672f76a 190typedef u32 note_buf_t[KEXEC_NOTE_BYTES/4];
43cf38eb 191extern note_buf_t __percpu *crash_notes;
fd59d231 192extern u32 vmcoreinfo_note[VMCOREINFO_NOTE_SIZE/4];
d768281e
KO
193extern size_t vmcoreinfo_size;
194extern size_t vmcoreinfo_max_size;
dc009d92 195
4fc9bbf9
KA
196/* flag to track if kexec reboot is in progress */
197extern bool kexec_in_progress;
198
cba63c30
BW
199int __init parse_crashkernel(char *cmdline, unsigned long long system_ram,
200 unsigned long long *crash_size, unsigned long long *crash_base);
55a20ee7
YL
201int parse_crashkernel_high(char *cmdline, unsigned long long system_ram,
202 unsigned long long *crash_size, unsigned long long *crash_base);
0212f915
YL
203int parse_crashkernel_low(char *cmdline, unsigned long long system_ram,
204 unsigned long long *crash_size, unsigned long long *crash_base);
06a7f711
AW
205int crash_shrink_memory(unsigned long new_size);
206size_t crash_get_memory_size(void);
c0bb9e45 207void crash_free_reserved_phys_range(unsigned long begin, unsigned long end);
a7956113 208
dc009d92 209#else /* !CONFIG_KEXEC */
6e274d14
AN
210struct pt_regs;
211struct task_struct;
212static inline void crash_kexec(struct pt_regs *regs) { }
213static inline int kexec_should_crash(struct task_struct *p) { return 0; }
dc009d92
EB
214#endif /* CONFIG_KEXEC */
215#endif /* LINUX_KEXEC_H */