4 #include <uapi/linux/kexec.h>
7 #include <linux/list.h>
8 #include <linux/linkage.h>
9 #include <linux/compat.h>
10 #include <linux/ioport.h>
11 #include <linux/elfcore.h>
12 #include <linux/elf.h>
13 #include <linux/module.h>
14 #include <asm/kexec.h>
16 /* Verify architecture specific macros are defined */
18 #ifndef KEXEC_SOURCE_MEMORY_LIMIT
19 #error KEXEC_SOURCE_MEMORY_LIMIT not defined
22 #ifndef KEXEC_DESTINATION_MEMORY_LIMIT
23 #error KEXEC_DESTINATION_MEMORY_LIMIT not defined
26 #ifndef KEXEC_CONTROL_MEMORY_LIMIT
27 #error KEXEC_CONTROL_MEMORY_LIMIT not defined
30 #ifndef KEXEC_CONTROL_PAGE_SIZE
31 #error KEXEC_CONTROL_PAGE_SIZE not defined
35 #error KEXEC_ARCH not defined
38 #ifndef KEXEC_CRASH_CONTROL_MEMORY_LIMIT
39 #define KEXEC_CRASH_CONTROL_MEMORY_LIMIT KEXEC_CONTROL_MEMORY_LIMIT
42 #ifndef KEXEC_CRASH_MEM_ALIGN
43 #define KEXEC_CRASH_MEM_ALIGN PAGE_SIZE
46 #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)
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.
55 #ifndef KEXEC_NOTE_BYTES
56 #define KEXEC_NOTE_BYTES ( (KEXEC_NOTE_HEAD_BYTES * 2) + \
57 KEXEC_CORE_NOTE_NAME_BYTES + \
58 KEXEC_CORE_NOTE_DESC_BYTES )
62 * This structure is used to hold the arguments that are used when loading
66 typedef unsigned long kimage_entry_t
;
67 #define IND_DESTINATION 0x1
68 #define IND_INDIRECTION 0x2
70 #define IND_SOURCE 0x8
72 struct kexec_segment
{
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.
78 * Use ->buf when expecting to deal with user memory and use ->kbuf
79 * when expecting to deal with kernel memory.
91 struct compat_kexec_segment
{
94 compat_ulong_t mem
; /* User space sees this as a (void *) ... */
99 struct kexec_sha_region
{
104 struct purgatory_info
{
105 /* Pointer to elf header of read only purgatory */
108 /* Pointer to purgatory sechdrs which are modifiable */
111 * Temporary buffer location where purgatory is loaded and relocated
112 * This memory can be freed post image load
116 /* Address where purgatory is finally loaded and is executed from */
117 unsigned long purgatory_load_addr
;
122 kimage_entry_t
*entry
;
123 kimage_entry_t
*last_entry
;
126 struct page
*control_code_page
;
127 struct page
*swap_page
;
129 unsigned long nr_segments
;
130 struct kexec_segment segment
[KEXEC_SEGMENT_MAX
];
132 struct list_head control_pages
;
133 struct list_head dest_pages
;
134 struct list_head unusable_pages
;
136 /* Address of next control page to allocate for crash kernels. */
137 unsigned long control_page
;
139 /* Flags to indicate special processing */
140 unsigned int type
: 1;
141 #define KEXEC_TYPE_DEFAULT 0
142 #define KEXEC_TYPE_CRASH 1
143 unsigned int preserve_context
: 1;
144 /* If set, we are using file mode kexec syscall */
145 unsigned int file_mode
:1;
147 #ifdef ARCH_HAS_KIMAGE_ARCH
148 struct kimage_arch arch
;
151 /* Additional fields for file based kexec syscall */
153 unsigned long kernel_buf_len
;
156 unsigned long initrd_buf_len
;
159 unsigned long cmdline_buf_len
;
161 /* File operations provided by image loader */
162 struct kexec_file_ops
*fops
;
164 /* Image loader handling the kernel can store a pointer here */
165 void *image_loader_data
;
167 /* Information for loading purgatory */
168 struct purgatory_info purgatory_info
;
172 * Keeps track of buffer parameters as provided by caller for requesting
173 * memory placement of buffer.
176 struct kimage
*image
;
181 unsigned long buf_align
;
182 unsigned long buf_min
;
183 unsigned long buf_max
;
184 bool top_down
; /* allocate from top of memory hole */
187 typedef int (kexec_probe_t
)(const char *kernel_buf
, unsigned long kernel_size
);
188 typedef void *(kexec_load_t
)(struct kimage
*image
, char *kernel_buf
,
189 unsigned long kernel_len
, char *initrd
,
190 unsigned long initrd_len
, char *cmdline
,
191 unsigned long cmdline_len
);
192 typedef int (kexec_cleanup_t
)(void *loader_data
);
193 typedef int (kexec_verify_sig_t
)(const char *kernel_buf
,
194 unsigned long kernel_len
);
196 struct kexec_file_ops
{
197 kexec_probe_t
*probe
;
199 kexec_cleanup_t
*cleanup
;
200 kexec_verify_sig_t
*verify_sig
;
203 /* kexec interface functions */
204 extern void machine_kexec(struct kimage
*image
);
205 extern int machine_kexec_prepare(struct kimage
*image
);
206 extern void machine_kexec_cleanup(struct kimage
*image
);
207 extern asmlinkage
long sys_kexec_load(unsigned long entry
,
208 unsigned long nr_segments
,
209 struct kexec_segment __user
*segments
,
210 unsigned long flags
);
211 extern int kernel_kexec(void);
212 extern int kexec_add_buffer(struct kimage
*image
, char *buffer
,
213 unsigned long bufsz
, unsigned long memsz
,
214 unsigned long buf_align
, unsigned long buf_min
,
215 unsigned long buf_max
, bool top_down
,
216 unsigned long *load_addr
);
217 extern struct page
*kimage_alloc_control_pages(struct kimage
*image
,
219 extern int kexec_load_purgatory(struct kimage
*image
, unsigned long min
,
220 unsigned long max
, int top_down
,
221 unsigned long *load_addr
);
222 extern int kexec_purgatory_get_set_symbol(struct kimage
*image
,
223 const char *name
, void *buf
,
224 unsigned int size
, bool get_value
);
225 extern void *kexec_purgatory_get_symbol_addr(struct kimage
*image
,
227 extern void crash_kexec(struct pt_regs
*);
228 int kexec_should_crash(struct task_struct
*);
229 void crash_save_cpu(struct pt_regs
*regs
, int cpu
);
230 void crash_save_vmcoreinfo(void);
231 void crash_map_reserved_pages(void);
232 void crash_unmap_reserved_pages(void);
233 void arch_crash_save_vmcoreinfo(void);
235 void vmcoreinfo_append_str(const char *fmt
, ...);
236 unsigned long paddr_vmcoreinfo_note(void);
238 #define VMCOREINFO_OSRELEASE(value) \
239 vmcoreinfo_append_str("OSRELEASE=%s\n", value)
240 #define VMCOREINFO_PAGESIZE(value) \
241 vmcoreinfo_append_str("PAGESIZE=%ld\n", value)
242 #define VMCOREINFO_SYMBOL(name) \
243 vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name)
244 #define VMCOREINFO_SIZE(name) \
245 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
246 (unsigned long)sizeof(name))
247 #define VMCOREINFO_STRUCT_SIZE(name) \
248 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
249 (unsigned long)sizeof(struct name))
250 #define VMCOREINFO_OFFSET(name, field) \
251 vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \
252 (unsigned long)offsetof(struct name, field))
253 #define VMCOREINFO_LENGTH(name, value) \
254 vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value)
255 #define VMCOREINFO_NUMBER(name) \
256 vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name)
257 #define VMCOREINFO_CONFIG(name) \
258 vmcoreinfo_append_str("CONFIG_%s=y\n", #name)
260 extern struct kimage
*kexec_image
;
261 extern struct kimage
*kexec_crash_image
;
262 extern int kexec_load_disabled
;
264 #ifndef kexec_flush_icache_page
265 #define kexec_flush_icache_page(page)
268 /* List of defined/legal kexec flags */
269 #ifndef CONFIG_KEXEC_JUMP
270 #define KEXEC_FLAGS KEXEC_ON_CRASH
272 #define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT)
275 /* List of defined/legal kexec file flags */
276 #define KEXEC_FILE_FLAGS (KEXEC_FILE_UNLOAD | KEXEC_FILE_ON_CRASH | \
277 KEXEC_FILE_NO_INITRAMFS)
279 #define VMCOREINFO_BYTES (4096)
280 #define VMCOREINFO_NOTE_NAME "VMCOREINFO"
281 #define VMCOREINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCOREINFO_NOTE_NAME), 4)
282 #define VMCOREINFO_NOTE_SIZE (KEXEC_NOTE_HEAD_BYTES*2 + VMCOREINFO_BYTES \
283 + VMCOREINFO_NOTE_NAME_BYTES)
285 /* Location of a reserved region to hold the crash kernel.
287 extern struct resource crashk_res
;
288 extern struct resource crashk_low_res
;
289 typedef u32 note_buf_t
[KEXEC_NOTE_BYTES
/4];
290 extern note_buf_t __percpu
*crash_notes
;
291 extern u32 vmcoreinfo_note
[VMCOREINFO_NOTE_SIZE
/4];
292 extern size_t vmcoreinfo_size
;
293 extern size_t vmcoreinfo_max_size
;
295 /* flag to track if kexec reboot is in progress */
296 extern bool kexec_in_progress
;
298 int __init
parse_crashkernel(char *cmdline
, unsigned long long system_ram
,
299 unsigned long long *crash_size
, unsigned long long *crash_base
);
300 int parse_crashkernel_high(char *cmdline
, unsigned long long system_ram
,
301 unsigned long long *crash_size
, unsigned long long *crash_base
);
302 int parse_crashkernel_low(char *cmdline
, unsigned long long system_ram
,
303 unsigned long long *crash_size
, unsigned long long *crash_base
);
304 int crash_shrink_memory(unsigned long new_size
);
305 size_t crash_get_memory_size(void);
306 void crash_free_reserved_phys_range(unsigned long begin
, unsigned long end
);
308 #else /* !CONFIG_KEXEC */
311 static inline void crash_kexec(struct pt_regs
*regs
) { }
312 static inline int kexec_should_crash(struct task_struct
*p
) { return 0; }
313 #endif /* CONFIG_KEXEC */
314 #endif /* LINUX_KEXEC_H */