1 #ifndef LINUX_KEXEC_H 2 #define LINUX_KEXEC_H 3 4 #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) 13 #define IND_FLAGS (IND_DESTINATION | IND_INDIRECTION | IND_DONE | IND_SOURCE) 14 15 #if !defined(__ASSEMBLY__) 16 17 #include <uapi/linux/kexec.h> 18 19 #ifdef CONFIG_KEXEC 20 #include <linux/list.h> 21 #include <linux/linkage.h> 22 #include <linux/compat.h> 23 #include <linux/ioport.h> 24 #include <linux/elfcore.h> 25 #include <linux/elf.h> 26 #include <linux/module.h> 27 #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 43 #ifndef KEXEC_CONTROL_MEMORY_GFP 44 #define KEXEC_CONTROL_MEMORY_GFP GFP_KERNEL 45 #endif 46 47 #ifndef KEXEC_CONTROL_PAGE_SIZE 48 #error KEXEC_CONTROL_PAGE_SIZE not defined 49 #endif 50 51 #ifndef KEXEC_ARCH 52 #error KEXEC_ARCH not defined 53 #endif 54 55 #ifndef KEXEC_CRASH_CONTROL_MEMORY_LIMIT 56 #define KEXEC_CRASH_CONTROL_MEMORY_LIMIT KEXEC_CONTROL_MEMORY_LIMIT 57 #endif 58 59 #ifndef KEXEC_CRASH_MEM_ALIGN 60 #define KEXEC_CRASH_MEM_ALIGN PAGE_SIZE 61 #endif 62 63 #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 */ 72 #ifndef KEXEC_NOTE_BYTES 73 #define KEXEC_NOTE_BYTES ( (KEXEC_NOTE_HEAD_BYTES * 2) + \ 74 KEXEC_CORE_NOTE_NAME_BYTES + \ 75 KEXEC_CORE_NOTE_DESC_BYTES ) 76 #endif 77 78 /* 79 * This structure is used to hold the arguments that are used when loading 80 * kernel binaries. 81 */ 82 83 typedef unsigned long kimage_entry_t; 84 85 struct kexec_segment { 86 /* 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 }; 98 size_t bufsz; 99 unsigned long mem; 100 size_t memsz; 101 }; 102 103 #ifdef CONFIG_COMPAT 104 struct 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 112 struct kexec_sha_region { 113 unsigned long start; 114 unsigned long len; 115 }; 116 117 struct 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 133 struct kimage { 134 kimage_entry_t head; 135 kimage_entry_t *entry; 136 kimage_entry_t *last_entry; 137 138 unsigned long start; 139 struct page *control_code_page; 140 struct page *swap_page; 141 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; 147 struct list_head unusable_pages; 148 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 156 unsigned int preserve_context : 1; 157 /* If set, we are using file mode kexec syscall */ 158 unsigned int file_mode:1; 159 160 #ifdef ARCH_HAS_KIMAGE_ARCH 161 struct kimage_arch arch; 162 #endif 163 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; 179 180 /* Information for loading purgatory */ 181 struct purgatory_info purgatory_info; 182 }; 183 184 /* 185 * Keeps track of buffer parameters as provided by caller for requesting 186 * memory placement of buffer. 187 */ 188 struct kexec_buf { 189 struct kimage *image; 190 char *buffer; 191 unsigned long bufsz; 192 unsigned long mem; 193 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 }; 199 200 typedef int (kexec_probe_t)(const char *kernel_buf, unsigned long kernel_size); 201 typedef 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); 205 typedef int (kexec_cleanup_t)(void *loader_data); 206 typedef int (kexec_verify_sig_t)(const char *kernel_buf, 207 unsigned long kernel_len); 208 209 struct kexec_file_ops { 210 kexec_probe_t *probe; 211 kexec_load_t *load; 212 kexec_cleanup_t *cleanup; 213 kexec_verify_sig_t *verify_sig; 214 }; 215 216 /* kexec interface functions */ 217 extern void machine_kexec(struct kimage *image); 218 extern int machine_kexec_prepare(struct kimage *image); 219 extern void machine_kexec_cleanup(struct kimage *image); 220 extern asmlinkage long sys_kexec_load(unsigned long entry, 221 unsigned long nr_segments, 222 struct kexec_segment __user *segments, 223 unsigned long flags); 224 extern int kernel_kexec(void); 225 extern 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); 230 extern struct page *kimage_alloc_control_pages(struct kimage *image, 231 unsigned int order); 232 extern int kexec_load_purgatory(struct kimage *image, unsigned long min, 233 unsigned long max, int top_down, 234 unsigned long *load_addr); 235 extern int kexec_purgatory_get_set_symbol(struct kimage *image, 236 const char *name, void *buf, 237 unsigned int size, bool get_value); 238 extern void *kexec_purgatory_get_symbol_addr(struct kimage *image, 239 const char *name); 240 extern void crash_kexec(struct pt_regs *); 241 int kexec_should_crash(struct task_struct *); 242 void crash_save_cpu(struct pt_regs *regs, int cpu); 243 void crash_save_vmcoreinfo(void); 244 void crash_map_reserved_pages(void); 245 void crash_unmap_reserved_pages(void); 246 void arch_crash_save_vmcoreinfo(void); 247 __printf(1, 2) 248 void vmcoreinfo_append_str(const char *fmt, ...); 249 unsigned long paddr_vmcoreinfo_note(void); 250 251 #define VMCOREINFO_OSRELEASE(value) \ 252 vmcoreinfo_append_str("OSRELEASE=%s\n", value) 253 #define VMCOREINFO_PAGESIZE(value) \ 254 vmcoreinfo_append_str("PAGESIZE=%ld\n", value) 255 #define VMCOREINFO_SYMBOL(name) \ 256 vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name) 257 #define VMCOREINFO_SIZE(name) \ 258 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \ 259 (unsigned long)sizeof(name)) 260 #define VMCOREINFO_STRUCT_SIZE(name) \ 261 vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \ 262 (unsigned long)sizeof(struct name)) 263 #define VMCOREINFO_OFFSET(name, field) \ 264 vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \ 265 (unsigned long)offsetof(struct name, field)) 266 #define VMCOREINFO_LENGTH(name, value) \ 267 vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value) 268 #define VMCOREINFO_NUMBER(name) \ 269 vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name) 270 #define VMCOREINFO_CONFIG(name) \ 271 vmcoreinfo_append_str("CONFIG_%s=y\n", #name) 272 273 extern struct kimage *kexec_image; 274 extern struct kimage *kexec_crash_image; 275 extern int kexec_load_disabled; 276 277 #ifndef kexec_flush_icache_page 278 #define kexec_flush_icache_page(page) 279 #endif 280 281 /* 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 287 288 /* 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 292 #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 298 /* Location of a reserved region to hold the crash kernel. 299 */ 300 extern struct resource crashk_res; 301 extern struct resource crashk_low_res; 302 typedef u32 note_buf_t[KEXEC_NOTE_BYTES/4]; 303 extern note_buf_t __percpu *crash_notes; 304 extern u32 vmcoreinfo_note[VMCOREINFO_NOTE_SIZE/4]; 305 extern size_t vmcoreinfo_size; 306 extern size_t vmcoreinfo_max_size; 307 308 /* flag to track if kexec reboot is in progress */ 309 extern bool kexec_in_progress; 310 311 int __init parse_crashkernel(char *cmdline, unsigned long long system_ram, 312 unsigned long long *crash_size, unsigned long long *crash_base); 313 int parse_crashkernel_high(char *cmdline, unsigned long long system_ram, 314 unsigned long long *crash_size, unsigned long long *crash_base); 315 int parse_crashkernel_low(char *cmdline, unsigned long long system_ram, 316 unsigned long long *crash_size, unsigned long long *crash_base); 317 int crash_shrink_memory(unsigned long new_size); 318 size_t crash_get_memory_size(void); 319 void crash_free_reserved_phys_range(unsigned long begin, unsigned long end); 320 321 #else /* !CONFIG_KEXEC */ 322 struct pt_regs; 323 struct task_struct; 324 static inline void crash_kexec(struct pt_regs *regs) { } 325 static inline int kexec_should_crash(struct task_struct *p) { return 0; } 326 #endif /* CONFIG_KEXEC */ 327 328 #endif /* !defined(__ASSEBMLY__) */ 329 330 #endif /* LINUX_KEXEC_H */ 331