blob: e804306ef5e88d7b02b8b7399b4d525c16b69cd3 [file] [log] [blame]
Eric W. Biedermandc009d92005-06-25 14:57:52 -07001#ifndef LINUX_KEXEC_H
2#define LINUX_KEXEC_H
3
Geoff Levandcf2df632015-02-17 13:45:56 -08004#define IND_DESTINATION_BIT 0
5#define IND_INDIRECTION_BIT 1
6#define IND_DONE_BIT 2
7#define IND_SOURCE_BIT 3
8
9#define IND_DESTINATION (1 << IND_DESTINATION_BIT)
10#define IND_INDIRECTION (1 << IND_INDIRECTION_BIT)
11#define IND_DONE (1 << IND_DONE_BIT)
12#define IND_SOURCE (1 << IND_SOURCE_BIT)
Geoff Levandb28c2ee2015-02-17 13:45:58 -080013#define IND_FLAGS (IND_DESTINATION | IND_INDIRECTION | IND_DONE | IND_SOURCE)
Geoff Levandcf2df632015-02-17 13:45:56 -080014
15#if !defined(__ASSEMBLY__)
16
David Howells607ca462012-10-13 10:46:48 +010017#include <uapi/linux/kexec.h>
maximilian attems29a5c672012-05-31 16:26:27 -070018
maximilian attems29a5c672012-05-31 16:26:27 -070019#ifdef CONFIG_KEXEC
Eric W. Biedermandc009d92005-06-25 14:57:52 -070020#include <linux/list.h>
21#include <linux/linkage.h>
22#include <linux/compat.h>
Haren Myneni9c15e852006-02-10 01:51:05 -080023#include <linux/ioport.h>
Simon Horman6672f762007-05-08 00:28:22 -070024#include <linux/elfcore.h>
25#include <linux/elf.h>
Vivek Goyal12db5562014-08-08 14:26:04 -070026#include <linux/module.h>
Eric W. Biedermandc009d92005-06-25 14:57:52 -070027#include <asm/kexec.h>
28
29/* Verify architecture specific macros are defined */
30
31#ifndef KEXEC_SOURCE_MEMORY_LIMIT
32#error KEXEC_SOURCE_MEMORY_LIMIT not defined
33#endif
34
35#ifndef KEXEC_DESTINATION_MEMORY_LIMIT
36#error KEXEC_DESTINATION_MEMORY_LIMIT not defined
37#endif
38
39#ifndef KEXEC_CONTROL_MEMORY_LIMIT
40#error KEXEC_CONTROL_MEMORY_LIMIT not defined
41#endif
42
Martin Schwidefsky7e01b5a2015-04-16 14:47:33 +020043#ifndef KEXEC_CONTROL_MEMORY_GFP
44#define KEXEC_CONTROL_MEMORY_GFP GFP_KERNEL
45#endif
46
Huang Ying163f6872008-08-15 00:40:22 -070047#ifndef KEXEC_CONTROL_PAGE_SIZE
48#error KEXEC_CONTROL_PAGE_SIZE not defined
Eric W. Biedermandc009d92005-06-25 14:57:52 -070049#endif
50
51#ifndef KEXEC_ARCH
52#error KEXEC_ARCH not defined
53#endif
54
Michael Holzheu3d214fa2011-10-30 15:16:36 +010055#ifndef KEXEC_CRASH_CONTROL_MEMORY_LIMIT
56#define KEXEC_CRASH_CONTROL_MEMORY_LIMIT KEXEC_CONTROL_MEMORY_LIMIT
57#endif
58
Michael Holzheu558df722011-10-30 15:16:43 +010059#ifndef KEXEC_CRASH_MEM_ALIGN
60#define KEXEC_CRASH_MEM_ALIGN PAGE_SIZE
61#endif
62
Simon Horman6672f762007-05-08 00:28:22 -070063#define KEXEC_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4)
64#define KEXEC_CORE_NOTE_NAME "CORE"
65#define KEXEC_CORE_NOTE_NAME_BYTES ALIGN(sizeof(KEXEC_CORE_NOTE_NAME), 4)
66#define KEXEC_CORE_NOTE_DESC_BYTES ALIGN(sizeof(struct elf_prstatus), 4)
67/*
68 * The per-cpu notes area is a list of notes terminated by a "NULL"
69 * note header. For kdump, the code in vmcore.c runs in the context
70 * of the second kernel to combine them into one note.
71 */
Michael Holzheucb78edf2012-01-20 14:34:16 -080072#ifndef KEXEC_NOTE_BYTES
Simon Horman6672f762007-05-08 00:28:22 -070073#define KEXEC_NOTE_BYTES ( (KEXEC_NOTE_HEAD_BYTES * 2) + \
74 KEXEC_CORE_NOTE_NAME_BYTES + \
75 KEXEC_CORE_NOTE_DESC_BYTES )
Michael Holzheucb78edf2012-01-20 14:34:16 -080076#endif
Simon Horman6672f762007-05-08 00:28:22 -070077
Eric W. Biedermandc009d92005-06-25 14:57:52 -070078/*
79 * This structure is used to hold the arguments that are used when loading
80 * kernel binaries.
81 */
82
83typedef unsigned long kimage_entry_t;
Eric W. Biedermandc009d92005-06-25 14:57:52 -070084
Eric W. Biedermandc009d92005-06-25 14:57:52 -070085struct kexec_segment {
Vivek Goyal815d5702014-08-08 14:25:52 -070086 /*
87 * This pointer can point to user memory if kexec_load() system
88 * call is used or will point to kernel memory if
89 * kexec_file_load() system call is used.
90 *
91 * Use ->buf when expecting to deal with user memory and use ->kbuf
92 * when expecting to deal with kernel memory.
93 */
94 union {
95 void __user *buf;
96 void *kbuf;
97 };
Eric W. Biedermandc009d92005-06-25 14:57:52 -070098 size_t bufsz;
maximilian attems29a5c672012-05-31 16:26:27 -070099 unsigned long mem;
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700100 size_t memsz;
101};
102
103#ifdef CONFIG_COMPAT
104struct compat_kexec_segment {
105 compat_uptr_t buf;
106 compat_size_t bufsz;
107 compat_ulong_t mem; /* User space sees this as a (void *) ... */
108 compat_size_t memsz;
109};
110#endif
111
Vivek Goyal12db5562014-08-08 14:26:04 -0700112struct kexec_sha_region {
113 unsigned long start;
114 unsigned long len;
115};
116
117struct purgatory_info {
118 /* Pointer to elf header of read only purgatory */
119 Elf_Ehdr *ehdr;
120
121 /* Pointer to purgatory sechdrs which are modifiable */
122 Elf_Shdr *sechdrs;
123 /*
124 * Temporary buffer location where purgatory is loaded and relocated
125 * This memory can be freed post image load
126 */
127 void *purgatory_buf;
128
129 /* Address where purgatory is finally loaded and is executed from */
130 unsigned long purgatory_load_addr;
131};
132
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700133struct kimage {
134 kimage_entry_t head;
135 kimage_entry_t *entry;
136 kimage_entry_t *last_entry;
137
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700138 unsigned long start;
139 struct page *control_code_page;
Huang Ying3ab83522008-07-25 19:45:07 -0700140 struct page *swap_page;
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700141
142 unsigned long nr_segments;
143 struct kexec_segment segment[KEXEC_SEGMENT_MAX];
144
145 struct list_head control_pages;
146 struct list_head dest_pages;
Vivek Goyal7d3e2bc2014-08-08 14:25:43 -0700147 struct list_head unusable_pages;
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700148
149 /* Address of next control page to allocate for crash kernels. */
150 unsigned long control_page;
151
152 /* Flags to indicate special processing */
153 unsigned int type : 1;
154#define KEXEC_TYPE_DEFAULT 0
155#define KEXEC_TYPE_CRASH 1
Huang Ying3ab83522008-07-25 19:45:07 -0700156 unsigned int preserve_context : 1;
Vivek Goyalcb105252014-08-08 14:25:57 -0700157 /* If set, we are using file mode kexec syscall */
158 unsigned int file_mode:1;
Huang Ying92be3d62008-10-31 09:48:08 +0800159
160#ifdef ARCH_HAS_KIMAGE_ARCH
161 struct kimage_arch arch;
162#endif
Vivek Goyalcb105252014-08-08 14:25:57 -0700163
164 /* Additional fields for file based kexec syscall */
165 void *kernel_buf;
166 unsigned long kernel_buf_len;
167
168 void *initrd_buf;
169 unsigned long initrd_buf_len;
170
171 char *cmdline_buf;
172 unsigned long cmdline_buf_len;
173
174 /* File operations provided by image loader */
175 struct kexec_file_ops *fops;
176
177 /* Image loader handling the kernel can store a pointer here */
178 void *image_loader_data;
Vivek Goyal12db5562014-08-08 14:26:04 -0700179
180 /* Information for loading purgatory */
181 struct purgatory_info purgatory_info;
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700182};
183
Vivek Goyalcb105252014-08-08 14:25:57 -0700184/*
185 * Keeps track of buffer parameters as provided by caller for requesting
186 * memory placement of buffer.
187 */
188struct kexec_buf {
189 struct kimage *image;
190 char *buffer;
191 unsigned long bufsz;
Baoquan He669280a2014-10-13 15:53:40 -0700192 unsigned long mem;
Vivek Goyalcb105252014-08-08 14:25:57 -0700193 unsigned long memsz;
194 unsigned long buf_align;
195 unsigned long buf_min;
196 unsigned long buf_max;
197 bool top_down; /* allocate from top of memory hole */
198};
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700199
Vivek Goyalcb105252014-08-08 14:25:57 -0700200typedef int (kexec_probe_t)(const char *kernel_buf, unsigned long kernel_size);
201typedef void *(kexec_load_t)(struct kimage *image, char *kernel_buf,
202 unsigned long kernel_len, char *initrd,
203 unsigned long initrd_len, char *cmdline,
204 unsigned long cmdline_len);
Vivek Goyal27f48d32014-08-08 14:26:06 -0700205typedef int (kexec_cleanup_t)(void *loader_data);
Vivek Goyal8e7d8382014-08-08 14:26:13 -0700206typedef int (kexec_verify_sig_t)(const char *kernel_buf,
207 unsigned long kernel_len);
Vivek Goyalcb105252014-08-08 14:25:57 -0700208
209struct kexec_file_ops {
210 kexec_probe_t *probe;
211 kexec_load_t *load;
212 kexec_cleanup_t *cleanup;
Vivek Goyal8e7d8382014-08-08 14:26:13 -0700213 kexec_verify_sig_t *verify_sig;
Vivek Goyalcb105252014-08-08 14:25:57 -0700214};
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700215
216/* kexec interface functions */
Huang Ying3ab83522008-07-25 19:45:07 -0700217extern void machine_kexec(struct kimage *image);
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700218extern int machine_kexec_prepare(struct kimage *image);
219extern void machine_kexec_cleanup(struct kimage *image);
220extern asmlinkage long sys_kexec_load(unsigned long entry,
Maneesh Soni72414d32005-06-25 14:58:28 -0700221 unsigned long nr_segments,
222 struct kexec_segment __user *segments,
223 unsigned long flags);
Huang Ying3ab83522008-07-25 19:45:07 -0700224extern int kernel_kexec(void);
Vivek Goyalcb105252014-08-08 14:25:57 -0700225extern int kexec_add_buffer(struct kimage *image, char *buffer,
226 unsigned long bufsz, unsigned long memsz,
227 unsigned long buf_align, unsigned long buf_min,
228 unsigned long buf_max, bool top_down,
229 unsigned long *load_addr);
Maneesh Soni72414d32005-06-25 14:58:28 -0700230extern struct page *kimage_alloc_control_pages(struct kimage *image,
231 unsigned int order);
Vivek Goyal12db5562014-08-08 14:26:04 -0700232extern int kexec_load_purgatory(struct kimage *image, unsigned long min,
233 unsigned long max, int top_down,
234 unsigned long *load_addr);
235extern int kexec_purgatory_get_set_symbol(struct kimage *image,
236 const char *name, void *buf,
237 unsigned int size, bool get_value);
238extern void *kexec_purgatory_get_symbol_addr(struct kimage *image,
239 const char *name);
Alexander Nyberg6e274d12005-06-25 14:58:26 -0700240extern void crash_kexec(struct pt_regs *);
241int kexec_should_crash(struct task_struct *);
Magnus Damm85916f82006-12-06 20:40:41 -0800242void crash_save_cpu(struct pt_regs *regs, int cpu);
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700243void crash_save_vmcoreinfo(void);
Michael Holzheu558df722011-10-30 15:16:43 +0100244void crash_map_reserved_pages(void);
245void crash_unmap_reserved_pages(void);
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700246void arch_crash_save_vmcoreinfo(void);
Joe Perchesb9075fa2011-10-31 17:11:33 -0700247__printf(1, 2)
248void vmcoreinfo_append_str(const char *fmt, ...);
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700249unsigned long paddr_vmcoreinfo_note(void);
250
Bernhard Wallec6e2bee2008-08-05 13:01:05 -0700251#define VMCOREINFO_OSRELEASE(value) \
252 vmcoreinfo_append_str("OSRELEASE=%s\n", value)
Ken'ichi Ohmichibba1f602008-02-07 00:15:22 -0800253#define VMCOREINFO_PAGESIZE(value) \
254 vmcoreinfo_append_str("PAGESIZE=%ld\n", value)
Ken'ichi Ohmichibcbba6c2007-10-16 23:27:30 -0700255#define VMCOREINFO_SYMBOL(name) \
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700256 vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name)
Ken'ichi Ohmichibcbba6c2007-10-16 23:27:30 -0700257#define VMCOREINFO_SIZE(name) \
Ken'ichi Ohmichid7682812007-10-16 23:27:28 -0700258 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
Ken'ichi Ohmichi6cfa0622007-10-16 23:27:28 -0700259 (unsigned long)sizeof(name))
Ken'ichi Ohmichic76f8602008-02-07 00:15:20 -0800260#define VMCOREINFO_STRUCT_SIZE(name) \
261 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
262 (unsigned long)sizeof(struct name))
Ken'ichi Ohmichibcbba6c2007-10-16 23:27:30 -0700263#define VMCOREINFO_OFFSET(name, field) \
Ken'ichi Ohmichid7682812007-10-16 23:27:28 -0700264 vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \
Ken'ichi Ohmichi1e4f2952008-02-07 00:15:22 -0800265 (unsigned long)offsetof(struct name, field))
Ken'ichi Ohmichibcbba6c2007-10-16 23:27:30 -0700266#define VMCOREINFO_LENGTH(name, value) \
Ken'ichi Ohmichid7682812007-10-16 23:27:28 -0700267 vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value)
Ken'ichi Ohmichibcbba6c2007-10-16 23:27:30 -0700268#define VMCOREINFO_NUMBER(name) \
Ken'ichi Ohmichi6cfa0622007-10-16 23:27:28 -0700269 vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name)
Ken'ichi Ohmichibcbba6c2007-10-16 23:27:30 -0700270#define VMCOREINFO_CONFIG(name) \
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700271 vmcoreinfo_append_str("CONFIG_%s=y\n", #name)
272
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700273extern struct kimage *kexec_image;
Jeff Moyerc330dda2006-06-23 02:05:07 -0700274extern struct kimage *kexec_crash_image;
Kees Cook79847542014-01-23 15:55:59 -0800275extern int kexec_load_disabled;
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700276
Zou Nan haia79561132006-12-07 09:51:35 -0800277#ifndef kexec_flush_icache_page
278#define kexec_flush_icache_page(page)
279#endif
280
Huang Ying3ab83522008-07-25 19:45:07 -0700281/* List of defined/legal kexec flags */
282#ifndef CONFIG_KEXEC_JUMP
283#define KEXEC_FLAGS KEXEC_ON_CRASH
284#else
285#define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT)
286#endif
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700287
Vivek Goyalcb105252014-08-08 14:25:57 -0700288/* List of defined/legal kexec file flags */
289#define KEXEC_FILE_FLAGS (KEXEC_FILE_UNLOAD | KEXEC_FILE_ON_CRASH | \
290 KEXEC_FILE_NO_INITRAMFS)
291
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700292#define VMCOREINFO_BYTES (4096)
293#define VMCOREINFO_NOTE_NAME "VMCOREINFO"
294#define VMCOREINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCOREINFO_NOTE_NAME), 4)
295#define VMCOREINFO_NOTE_SIZE (KEXEC_NOTE_HEAD_BYTES*2 + VMCOREINFO_BYTES \
296 + VMCOREINFO_NOTE_NAME_BYTES)
297
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700298/* Location of a reserved region to hold the crash kernel.
299 */
300extern struct resource crashk_res;
Yinghai Lu0212f912013-01-24 12:20:11 -0800301extern struct resource crashk_low_res;
Simon Horman6672f762007-05-08 00:28:22 -0700302typedef u32 note_buf_t[KEXEC_NOTE_BYTES/4];
Tejun Heo43cf38e2010-02-02 14:38:57 +0900303extern note_buf_t __percpu *crash_notes;
Ken'ichi Ohmichifd59d232007-10-16 23:27:27 -0700304extern u32 vmcoreinfo_note[VMCOREINFO_NOTE_SIZE/4];
Ken'ichi Ohmichid7682812007-10-16 23:27:28 -0700305extern size_t vmcoreinfo_size;
306extern size_t vmcoreinfo_max_size;
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700307
Khalid Aziz4fc9bbf2013-11-27 15:19:25 -0700308/* flag to track if kexec reboot is in progress */
309extern bool kexec_in_progress;
310
Bernhard Wallecba63c32007-10-18 23:40:58 -0700311int __init parse_crashkernel(char *cmdline, unsigned long long system_ram,
312 unsigned long long *crash_size, unsigned long long *crash_base);
Yinghai Lu55a20ee2013-04-15 22:23:47 -0700313int parse_crashkernel_high(char *cmdline, unsigned long long system_ram,
314 unsigned long long *crash_size, unsigned long long *crash_base);
Yinghai Lu0212f912013-01-24 12:20:11 -0800315int parse_crashkernel_low(char *cmdline, unsigned long long system_ram,
316 unsigned long long *crash_size, unsigned long long *crash_base);
Amerigo Wang06a7f712009-12-15 16:47:46 -0800317int crash_shrink_memory(unsigned long new_size);
318size_t crash_get_memory_size(void);
Anton Blanchardc0bb9e42010-08-25 10:22:58 +1000319void crash_free_reserved_phys_range(unsigned long begin, unsigned long end);
Zou Nan haia79561132006-12-07 09:51:35 -0800320
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700321#else /* !CONFIG_KEXEC */
Alexander Nyberg6e274d12005-06-25 14:58:26 -0700322struct pt_regs;
323struct task_struct;
324static inline void crash_kexec(struct pt_regs *regs) { }
325static inline int kexec_should_crash(struct task_struct *p) { return 0; }
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700326#endif /* CONFIG_KEXEC */
Geoff Levandcf2df632015-02-17 13:45:56 -0800327
328#endif /* !defined(__ASSEBMLY__) */
329
Eric W. Biedermandc009d92005-06-25 14:57:52 -0700330#endif /* LINUX_KEXEC_H */