blob: 4b2a0e11cc5be7245f343ded8049f7d3e86f0855 [file] [log] [blame]
Eric W. Biedermandc009d92005-06-25 14:57:52 -07001#ifndef LINUX_KEXEC_H
2#define LINUX_KEXEC_H
3
David Howells607ca462012-10-13 10:46:48 +01004#include <uapi/linux/kexec.h>
maximilian attems29a5c672012-05-31 16:26:27 -07005
maximilian attems29a5c672012-05-31 16:26:27 -07006#ifdef CONFIG_KEXEC
Eric W. Biedermandc009d92005-06-25 14:57:52 -07007#include <linux/list.h>
8#include <linux/linkage.h>
9#include <linux/compat.h>
Haren Myneni9c15e852006-02-10 01:51:05 -080010#include <linux/ioport.h>
Simon Horman6672f762007-05-08 00:28:22 -070011#include <linux/elfcore.h>
12#include <linux/elf.h>
Vivek Goyal12db5562014-08-08 14:26:04 -070013#include <linux/module.h>
Eric W. Biedermandc009d92005-06-25 14:57:52 -070014#include <asm/kexec.h>
15
16/* Verify architecture specific macros are defined */
17
18#ifndef KEXEC_SOURCE_MEMORY_LIMIT
19#error KEXEC_SOURCE_MEMORY_LIMIT not defined
20#endif
21
22#ifndef KEXEC_DESTINATION_MEMORY_LIMIT
23#error KEXEC_DESTINATION_MEMORY_LIMIT not defined
24#endif
25
26#ifndef KEXEC_CONTROL_MEMORY_LIMIT
27#error KEXEC_CONTROL_MEMORY_LIMIT not defined
28#endif
29
Huang Ying163f6872008-08-15 00:40:22 -070030#ifndef KEXEC_CONTROL_PAGE_SIZE
31#error KEXEC_CONTROL_PAGE_SIZE not defined
Eric W. Biedermandc009d92005-06-25 14:57:52 -070032#endif
33
34#ifndef KEXEC_ARCH
35#error KEXEC_ARCH not defined
36#endif
37
Michael Holzheu3d214fa2011-10-30 15:16:36 +010038#ifndef KEXEC_CRASH_CONTROL_MEMORY_LIMIT
39#define KEXEC_CRASH_CONTROL_MEMORY_LIMIT KEXEC_CONTROL_MEMORY_LIMIT
40#endif
41
Michael Holzheu558df722011-10-30 15:16:43 +010042#ifndef KEXEC_CRASH_MEM_ALIGN
43#define KEXEC_CRASH_MEM_ALIGN PAGE_SIZE
44#endif
45
Simon Horman6672f762007-05-08 00:28:22 -070046#define KEXEC_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4)
47#define KEXEC_CORE_NOTE_NAME "CORE"
48#define KEXEC_CORE_NOTE_NAME_BYTES ALIGN(sizeof(KEXEC_CORE_NOTE_NAME), 4)
49#define KEXEC_CORE_NOTE_DESC_BYTES ALIGN(sizeof(struct elf_prstatus), 4)
50/*
51 * The per-cpu notes area is a list of notes terminated by a "NULL"
52 * note header. For kdump, the code in vmcore.c runs in the context
53 * of the second kernel to combine them into one note.
54 */
Michael Holzheucb78edf2012-01-20 14:34:16 -080055#ifndef KEXEC_NOTE_BYTES
Simon Horman6672f762007-05-08 00:28:22 -070056#define KEXEC_NOTE_BYTES ( (KEXEC_NOTE_HEAD_BYTES * 2) + \
57 KEXEC_CORE_NOTE_NAME_BYTES + \
58 KEXEC_CORE_NOTE_DESC_BYTES )
Michael Holzheucb78edf2012-01-20 14:34:16 -080059#endif
Simon Horman6672f762007-05-08 00:28:22 -070060
Eric W. Biedermandc009d92005-06-25 14:57:52 -070061/*
62 * This structure is used to hold the arguments that are used when loading
63 * kernel binaries.
64 */
65
66typedef unsigned long kimage_entry_t;
67#define IND_DESTINATION 0x1
68#define IND_INDIRECTION 0x2
69#define IND_DONE 0x4
70#define IND_SOURCE 0x8
71
Eric W. Biedermandc009d92005-06-25 14:57:52 -070072struct kexec_segment {
Vivek Goyal815d5702014-08-08 14:25:52 -070073 /*
74 * This pointer can point to user memory if kexec_load() system
75 * call is used or will point to kernel memory if
76 * kexec_file_load() system call is used.
77 *
78 * Use ->buf when expecting to deal with user memory and use ->kbuf
79 * when expecting to deal with kernel memory.
80 */
81 union {
82 void __user *buf;
83 void *kbuf;
84 };
Eric W. Biedermandc009d92005-06-25 14:57:52 -070085 size_t bufsz;
maximilian attems29a5c672012-05-31 16:26:27 -070086 unsigned long mem;
Eric W. Biedermandc009d92005-06-25 14:57:52 -070087 size_t memsz;
88};
89
90#ifdef CONFIG_COMPAT
91struct compat_kexec_segment {
92 compat_uptr_t buf;
93 compat_size_t bufsz;
94 compat_ulong_t mem; /* User space sees this as a (void *) ... */
95 compat_size_t memsz;
96};
97#endif
98
Vivek Goyal12db5562014-08-08 14:26:04 -070099struct kexec_sha_region {
100 unsigned long start;
101 unsigned long len;
102};
103
104struct purgatory_info {
105 /* Pointer to elf header of read only purgatory */
106 Elf_Ehdr *ehdr;
107
108 /* Pointer to purgatory sechdrs which are modifiable */
109 Elf_Shdr *sechdrs;
110 /*
111 * Temporary buffer location where purgatory is loaded and relocated
112 * This memory can be freed post image load
113 */
114 void *purgatory_buf;
115
116 /* Address where purgatory is finally loaded and is executed from */
117 unsigned long purgatory_load_addr;
118};
119
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700120struct kimage {
121 kimage_entry_t head;
122 kimage_entry_t *entry;
123 kimage_entry_t *last_entry;
124
125 unsigned long destination;
126
127 unsigned long start;
128 struct page *control_code_page;
Huang Ying3ab83522008-07-25 19:45:07 -0700129 struct page *swap_page;
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700130
131 unsigned long nr_segments;
132 struct kexec_segment segment[KEXEC_SEGMENT_MAX];
133
134 struct list_head control_pages;
135 struct list_head dest_pages;
Vivek Goyal7d3e2bc2014-08-08 14:25:43 -0700136 struct list_head unusable_pages;
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700137
138 /* Address of next control page to allocate for crash kernels. */
139 unsigned long control_page;
140
141 /* Flags to indicate special processing */
142 unsigned int type : 1;
143#define KEXEC_TYPE_DEFAULT 0
144#define KEXEC_TYPE_CRASH 1
Huang Ying3ab83522008-07-25 19:45:07 -0700145 unsigned int preserve_context : 1;
Vivek Goyalcb105252014-08-08 14:25:57 -0700146 /* If set, we are using file mode kexec syscall */
147 unsigned int file_mode:1;
Huang Ying92be3d62008-10-31 09:48:08 +0800148
149#ifdef ARCH_HAS_KIMAGE_ARCH
150 struct kimage_arch arch;
151#endif
Vivek Goyalcb105252014-08-08 14:25:57 -0700152
153 /* Additional fields for file based kexec syscall */
154 void *kernel_buf;
155 unsigned long kernel_buf_len;
156
157 void *initrd_buf;
158 unsigned long initrd_buf_len;
159
160 char *cmdline_buf;
161 unsigned long cmdline_buf_len;
162
163 /* File operations provided by image loader */
164 struct kexec_file_ops *fops;
165
166 /* Image loader handling the kernel can store a pointer here */
167 void *image_loader_data;
Vivek Goyal12db5562014-08-08 14:26:04 -0700168
169 /* Information for loading purgatory */
170 struct purgatory_info purgatory_info;
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700171};
172
Vivek Goyalcb105252014-08-08 14:25:57 -0700173/*
174 * Keeps track of buffer parameters as provided by caller for requesting
175 * memory placement of buffer.
176 */
177struct kexec_buf {
178 struct kimage *image;
179 char *buffer;
180 unsigned long bufsz;
181 unsigned long memsz;
182 unsigned long buf_align;
183 unsigned long buf_min;
184 unsigned long buf_max;
185 bool top_down; /* allocate from top of memory hole */
186};
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700187
Vivek Goyalcb105252014-08-08 14:25:57 -0700188typedef int (kexec_probe_t)(const char *kernel_buf, unsigned long kernel_size);
189typedef void *(kexec_load_t)(struct kimage *image, char *kernel_buf,
190 unsigned long kernel_len, char *initrd,
191 unsigned long initrd_len, char *cmdline,
192 unsigned long cmdline_len);
Vivek Goyal27f48d32014-08-08 14:26:06 -0700193typedef int (kexec_cleanup_t)(void *loader_data);
Vivek Goyal8e7d8382014-08-08 14:26:13 -0700194typedef int (kexec_verify_sig_t)(const char *kernel_buf,
195 unsigned long kernel_len);
Vivek Goyalcb105252014-08-08 14:25:57 -0700196
197struct kexec_file_ops {
198 kexec_probe_t *probe;
199 kexec_load_t *load;
200 kexec_cleanup_t *cleanup;
Vivek Goyal8e7d8382014-08-08 14:26:13 -0700201 kexec_verify_sig_t *verify_sig;
Vivek Goyalcb105252014-08-08 14:25:57 -0700202};
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700203
204/* kexec interface functions */
Huang Ying3ab83522008-07-25 19:45:07 -0700205extern void machine_kexec(struct kimage *image);
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700206extern int machine_kexec_prepare(struct kimage *image);
207extern void machine_kexec_cleanup(struct kimage *image);
208extern asmlinkage long sys_kexec_load(unsigned long entry,
Maneesh Soni72414d32005-06-25 14:58:28 -0700209 unsigned long nr_segments,
210 struct kexec_segment __user *segments,
211 unsigned long flags);
Huang Ying3ab83522008-07-25 19:45:07 -0700212extern int kernel_kexec(void);
Vivek Goyalcb105252014-08-08 14:25:57 -0700213extern int kexec_add_buffer(struct kimage *image, char *buffer,
214 unsigned long bufsz, unsigned long memsz,
215 unsigned long buf_align, unsigned long buf_min,
216 unsigned long buf_max, bool top_down,
217 unsigned long *load_addr);
Maneesh Soni72414d32005-06-25 14:58:28 -0700218extern struct page *kimage_alloc_control_pages(struct kimage *image,
219 unsigned int order);
Vivek Goyal12db5562014-08-08 14:26:04 -0700220extern int kexec_load_purgatory(struct kimage *image, unsigned long min,
221 unsigned long max, int top_down,
222 unsigned long *load_addr);
223extern int kexec_purgatory_get_set_symbol(struct kimage *image,
224 const char *name, void *buf,
225 unsigned int size, bool get_value);
226extern void *kexec_purgatory_get_symbol_addr(struct kimage *image,
227 const char *name);
Alexander Nyberg6e274d12005-06-25 14:58:26 -0700228extern void crash_kexec(struct pt_regs *);
229int kexec_should_crash(struct task_struct *);
Magnus Damm85916f82006-12-06 20:40:41 -0800230void crash_save_cpu(struct pt_regs *regs, int cpu);
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700231void crash_save_vmcoreinfo(void);
Michael Holzheu558df722011-10-30 15:16:43 +0100232void crash_map_reserved_pages(void);
233void crash_unmap_reserved_pages(void);
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700234void arch_crash_save_vmcoreinfo(void);
Joe Perchesb9075fa2011-10-31 17:11:33 -0700235__printf(1, 2)
236void vmcoreinfo_append_str(const char *fmt, ...);
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700237unsigned long paddr_vmcoreinfo_note(void);
238
Bernhard Wallec6e2bee2008-08-05 13:01:05 -0700239#define VMCOREINFO_OSRELEASE(value) \
240 vmcoreinfo_append_str("OSRELEASE=%s\n", value)
Ken'ichi Ohmichibba1f602008-02-07 00:15:22 -0800241#define VMCOREINFO_PAGESIZE(value) \
242 vmcoreinfo_append_str("PAGESIZE=%ld\n", value)
Ken'ichi Ohmichibcbba6c2007-10-16 23:27:30 -0700243#define VMCOREINFO_SYMBOL(name) \
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700244 vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name)
Ken'ichi Ohmichibcbba6c2007-10-16 23:27:30 -0700245#define VMCOREINFO_SIZE(name) \
Ken'ichi Ohmichid7682812007-10-16 23:27:28 -0700246 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
Ken'ichi Ohmichi6cfa0622007-10-16 23:27:28 -0700247 (unsigned long)sizeof(name))
Ken'ichi Ohmichic76f8602008-02-07 00:15:20 -0800248#define VMCOREINFO_STRUCT_SIZE(name) \
249 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
250 (unsigned long)sizeof(struct name))
Ken'ichi Ohmichibcbba6c2007-10-16 23:27:30 -0700251#define VMCOREINFO_OFFSET(name, field) \
Ken'ichi Ohmichid7682812007-10-16 23:27:28 -0700252 vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \
Ken'ichi Ohmichi1e4f2952008-02-07 00:15:22 -0800253 (unsigned long)offsetof(struct name, field))
Ken'ichi Ohmichibcbba6c2007-10-16 23:27:30 -0700254#define VMCOREINFO_LENGTH(name, value) \
Ken'ichi Ohmichid7682812007-10-16 23:27:28 -0700255 vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value)
Ken'ichi Ohmichibcbba6c2007-10-16 23:27:30 -0700256#define VMCOREINFO_NUMBER(name) \
Ken'ichi Ohmichi6cfa0622007-10-16 23:27:28 -0700257 vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name)
Ken'ichi Ohmichibcbba6c2007-10-16 23:27:30 -0700258#define VMCOREINFO_CONFIG(name) \
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700259 vmcoreinfo_append_str("CONFIG_%s=y\n", #name)
260
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700261extern struct kimage *kexec_image;
Jeff Moyerc330dda2006-06-23 02:05:07 -0700262extern struct kimage *kexec_crash_image;
Kees Cook79847542014-01-23 15:55:59 -0800263extern int kexec_load_disabled;
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700264
Zou Nan haia79561132006-12-07 09:51:35 -0800265#ifndef kexec_flush_icache_page
266#define kexec_flush_icache_page(page)
267#endif
268
Huang Ying3ab83522008-07-25 19:45:07 -0700269/* List of defined/legal kexec flags */
270#ifndef CONFIG_KEXEC_JUMP
271#define KEXEC_FLAGS KEXEC_ON_CRASH
272#else
273#define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT)
274#endif
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700275
Vivek Goyalcb105252014-08-08 14:25:57 -0700276/* List of defined/legal kexec file flags */
277#define KEXEC_FILE_FLAGS (KEXEC_FILE_UNLOAD | KEXEC_FILE_ON_CRASH | \
278 KEXEC_FILE_NO_INITRAMFS)
279
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700280#define VMCOREINFO_BYTES (4096)
281#define VMCOREINFO_NOTE_NAME "VMCOREINFO"
282#define VMCOREINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCOREINFO_NOTE_NAME), 4)
283#define VMCOREINFO_NOTE_SIZE (KEXEC_NOTE_HEAD_BYTES*2 + VMCOREINFO_BYTES \
284 + VMCOREINFO_NOTE_NAME_BYTES)
285
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700286/* Location of a reserved region to hold the crash kernel.
287 */
288extern struct resource crashk_res;
Yinghai Lu0212f912013-01-24 12:20:11 -0800289extern struct resource crashk_low_res;
Simon Horman6672f762007-05-08 00:28:22 -0700290typedef u32 note_buf_t[KEXEC_NOTE_BYTES/4];
Tejun Heo43cf38e2010-02-02 14:38:57 +0900291extern note_buf_t __percpu *crash_notes;
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700292extern u32 vmcoreinfo_note[VMCOREINFO_NOTE_SIZE/4];
Ken'ichi Ohmichid7682812007-10-16 23:27:28 -0700293extern size_t vmcoreinfo_size;
294extern size_t vmcoreinfo_max_size;
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700295
Khalid Aziz4fc9bbf2013-11-27 15:19:25 -0700296/* flag to track if kexec reboot is in progress */
297extern bool kexec_in_progress;
298
Bernhard Wallecba63c32007-10-18 23:40:58 -0700299int __init parse_crashkernel(char *cmdline, unsigned long long system_ram,
300 unsigned long long *crash_size, unsigned long long *crash_base);
Yinghai Lu55a20ee2013-04-15 22:23:47 -0700301int parse_crashkernel_high(char *cmdline, unsigned long long system_ram,
302 unsigned long long *crash_size, unsigned long long *crash_base);
Yinghai Lu0212f912013-01-24 12:20:11 -0800303int parse_crashkernel_low(char *cmdline, unsigned long long system_ram,
304 unsigned long long *crash_size, unsigned long long *crash_base);
Amerigo Wang06a7f712009-12-15 16:47:46 -0800305int crash_shrink_memory(unsigned long new_size);
306size_t crash_get_memory_size(void);
Anton Blanchardc0bb9e42010-08-25 10:22:58 +1000307void crash_free_reserved_phys_range(unsigned long begin, unsigned long end);
Zou Nan haia79561132006-12-07 09:51:35 -0800308
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700309#else /* !CONFIG_KEXEC */
Alexander Nyberg6e274d12005-06-25 14:58:26 -0700310struct pt_regs;
311struct task_struct;
312static inline void crash_kexec(struct pt_regs *regs) { }
313static inline int kexec_should_crash(struct task_struct *p) { return 0; }
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700314#endif /* CONFIG_KEXEC */
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700315#endif /* LINUX_KEXEC_H */