linux/include/linux/kexec.h
<<
>>
Prefs
   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 <asm/io.h>
  18
  19#include <uapi/linux/kexec.h>
  20
  21#ifdef CONFIG_KEXEC_CORE
  22#include <linux/list.h>
  23#include <linux/linkage.h>
  24#include <linux/compat.h>
  25#include <linux/ioport.h>
  26#include <linux/elfcore.h>
  27#include <linux/elf.h>
  28#include <linux/module.h>
  29#include <asm/kexec.h>
  30
  31/* Verify architecture specific macros are defined */
  32
  33#ifndef KEXEC_SOURCE_MEMORY_LIMIT
  34#error KEXEC_SOURCE_MEMORY_LIMIT not defined
  35#endif
  36
  37#ifndef KEXEC_DESTINATION_MEMORY_LIMIT
  38#error KEXEC_DESTINATION_MEMORY_LIMIT not defined
  39#endif
  40
  41#ifndef KEXEC_CONTROL_MEMORY_LIMIT
  42#error KEXEC_CONTROL_MEMORY_LIMIT not defined
  43#endif
  44
  45#ifndef KEXEC_CONTROL_MEMORY_GFP
  46#define KEXEC_CONTROL_MEMORY_GFP (GFP_KERNEL | __GFP_NORETRY)
  47#endif
  48
  49#ifndef KEXEC_CONTROL_PAGE_SIZE
  50#error KEXEC_CONTROL_PAGE_SIZE not defined
  51#endif
  52
  53#ifndef KEXEC_ARCH
  54#error KEXEC_ARCH not defined
  55#endif
  56
  57#ifndef KEXEC_CRASH_CONTROL_MEMORY_LIMIT
  58#define KEXEC_CRASH_CONTROL_MEMORY_LIMIT KEXEC_CONTROL_MEMORY_LIMIT
  59#endif
  60
  61#ifndef KEXEC_CRASH_MEM_ALIGN
  62#define KEXEC_CRASH_MEM_ALIGN PAGE_SIZE
  63#endif
  64
  65#define KEXEC_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4)
  66#define KEXEC_CORE_NOTE_NAME "CORE"
  67#define KEXEC_CORE_NOTE_NAME_BYTES ALIGN(sizeof(KEXEC_CORE_NOTE_NAME), 4)
  68#define KEXEC_CORE_NOTE_DESC_BYTES ALIGN(sizeof(struct elf_prstatus), 4)
  69/*
  70 * The per-cpu notes area is a list of notes terminated by a "NULL"
  71 * note header.  For kdump, the code in vmcore.c runs in the context
  72 * of the second kernel to combine them into one note.
  73 */
  74#ifndef KEXEC_NOTE_BYTES
  75#define KEXEC_NOTE_BYTES ( (KEXEC_NOTE_HEAD_BYTES * 2) +                \
  76                            KEXEC_CORE_NOTE_NAME_BYTES +                \
  77                            KEXEC_CORE_NOTE_DESC_BYTES )
  78#endif
  79
  80/*
  81 * This structure is used to hold the arguments that are used when loading
  82 * kernel binaries.
  83 */
  84
  85typedef unsigned long kimage_entry_t;
  86
  87struct kexec_segment {
  88        /*
  89         * This pointer can point to user memory if kexec_load() system
  90         * call is used or will point to kernel memory if
  91         * kexec_file_load() system call is used.
  92         *
  93         * Use ->buf when expecting to deal with user memory and use ->kbuf
  94         * when expecting to deal with kernel memory.
  95         */
  96        union {
  97                void __user *buf;
  98                void *kbuf;
  99        };
 100        size_t bufsz;
 101        unsigned long mem;
 102        size_t memsz;
 103};
 104
 105#ifdef CONFIG_COMPAT
 106struct compat_kexec_segment {
 107        compat_uptr_t buf;
 108        compat_size_t bufsz;
 109        compat_ulong_t mem;     /* User space sees this as a (void *) ... */
 110        compat_size_t memsz;
 111};
 112#endif
 113
 114#ifdef CONFIG_KEXEC_FILE
 115struct purgatory_info {
 116        /* Pointer to elf header of read only purgatory */
 117        Elf_Ehdr *ehdr;
 118
 119        /* Pointer to purgatory sechdrs which are modifiable */
 120        Elf_Shdr *sechdrs;
 121        /*
 122         * Temporary buffer location where purgatory is loaded and relocated
 123         * This memory can be freed post image load
 124         */
 125        void *purgatory_buf;
 126
 127        /* Address where purgatory is finally loaded and is executed from */
 128        unsigned long purgatory_load_addr;
 129};
 130
 131typedef int (kexec_probe_t)(const char *kernel_buf, unsigned long kernel_size);
 132typedef void *(kexec_load_t)(struct kimage *image, char *kernel_buf,
 133                             unsigned long kernel_len, char *initrd,
 134                             unsigned long initrd_len, char *cmdline,
 135                             unsigned long cmdline_len);
 136typedef int (kexec_cleanup_t)(void *loader_data);
 137
 138#ifdef CONFIG_KEXEC_VERIFY_SIG
 139typedef int (kexec_verify_sig_t)(const char *kernel_buf,
 140                                 unsigned long kernel_len);
 141#endif
 142
 143struct kexec_file_ops {
 144        kexec_probe_t *probe;
 145        kexec_load_t *load;
 146        kexec_cleanup_t *cleanup;
 147#ifdef CONFIG_KEXEC_VERIFY_SIG
 148        kexec_verify_sig_t *verify_sig;
 149#endif
 150};
 151#endif
 152
 153struct kimage {
 154        kimage_entry_t head;
 155        kimage_entry_t *entry;
 156        kimage_entry_t *last_entry;
 157
 158        unsigned long start;
 159        struct page *control_code_page;
 160        struct page *swap_page;
 161
 162        unsigned long nr_segments;
 163        struct kexec_segment segment[KEXEC_SEGMENT_MAX];
 164
 165        struct list_head control_pages;
 166        struct list_head dest_pages;
 167        struct list_head unusable_pages;
 168
 169        /* Address of next control page to allocate for crash kernels. */
 170        unsigned long control_page;
 171
 172        /* Flags to indicate special processing */
 173        unsigned int type : 1;
 174#define KEXEC_TYPE_DEFAULT 0
 175#define KEXEC_TYPE_CRASH   1
 176        unsigned int preserve_context : 1;
 177        /* If set, we are using file mode kexec syscall */
 178        unsigned int file_mode:1;
 179
 180#ifdef ARCH_HAS_KIMAGE_ARCH
 181        struct kimage_arch arch;
 182#endif
 183
 184#ifdef CONFIG_KEXEC_FILE
 185        /* Additional fields for file based kexec syscall */
 186        void *kernel_buf;
 187        unsigned long kernel_buf_len;
 188
 189        void *initrd_buf;
 190        unsigned long initrd_buf_len;
 191
 192        char *cmdline_buf;
 193        unsigned long cmdline_buf_len;
 194
 195        /* File operations provided by image loader */
 196        struct kexec_file_ops *fops;
 197
 198        /* Image loader handling the kernel can store a pointer here */
 199        void *image_loader_data;
 200
 201        /* Information for loading purgatory */
 202        struct purgatory_info purgatory_info;
 203#endif
 204};
 205
 206/* kexec interface functions */
 207extern void machine_kexec(struct kimage *image);
 208extern int machine_kexec_prepare(struct kimage *image);
 209extern void machine_kexec_cleanup(struct kimage *image);
 210extern asmlinkage long sys_kexec_load(unsigned long entry,
 211                                        unsigned long nr_segments,
 212                                        struct kexec_segment __user *segments,
 213                                        unsigned long flags);
 214extern int kernel_kexec(void);
 215extern int kexec_add_buffer(struct kimage *image, char *buffer,
 216                            unsigned long bufsz, unsigned long memsz,
 217                            unsigned long buf_align, unsigned long buf_min,
 218                            unsigned long buf_max, bool top_down,
 219                            unsigned long *load_addr);
 220extern struct page *kimage_alloc_control_pages(struct kimage *image,
 221                                                unsigned int order);
 222extern int kexec_load_purgatory(struct kimage *image, unsigned long min,
 223                                unsigned long max, int top_down,
 224                                unsigned long *load_addr);
 225extern int kexec_purgatory_get_set_symbol(struct kimage *image,
 226                                          const char *name, void *buf,
 227                                          unsigned int size, bool get_value);
 228extern void *kexec_purgatory_get_symbol_addr(struct kimage *image,
 229                                             const char *name);
 230extern void __crash_kexec(struct pt_regs *);
 231extern void crash_kexec(struct pt_regs *);
 232int kexec_should_crash(struct task_struct *);
 233int kexec_crash_loaded(void);
 234void crash_save_cpu(struct pt_regs *regs, int cpu);
 235void crash_save_vmcoreinfo(void);
 236void arch_crash_save_vmcoreinfo(void);
 237__printf(1, 2)
 238void vmcoreinfo_append_str(const char *fmt, ...);
 239phys_addr_t paddr_vmcoreinfo_note(void);
 240
 241#define VMCOREINFO_OSRELEASE(value) \
 242        vmcoreinfo_append_str("OSRELEASE=%s\n", value)
 243#define VMCOREINFO_PAGESIZE(value) \
 244        vmcoreinfo_append_str("PAGESIZE=%ld\n", value)
 245#define VMCOREINFO_SYMBOL(name) \
 246        vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name)
 247#define VMCOREINFO_SIZE(name) \
 248        vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
 249                              (unsigned long)sizeof(name))
 250#define VMCOREINFO_STRUCT_SIZE(name) \
 251        vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
 252                              (unsigned long)sizeof(struct name))
 253#define VMCOREINFO_OFFSET(name, field) \
 254        vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \
 255                              (unsigned long)offsetof(struct name, field))
 256#define VMCOREINFO_LENGTH(name, value) \
 257        vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value)
 258#define VMCOREINFO_NUMBER(name) \
 259        vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name)
 260#define VMCOREINFO_CONFIG(name) \
 261        vmcoreinfo_append_str("CONFIG_%s=y\n", #name)
 262#define VMCOREINFO_PAGE_OFFSET(value) \
 263        vmcoreinfo_append_str("PAGE_OFFSET=%lx\n", (unsigned long)value)
 264#define VMCOREINFO_VMALLOC_START(value) \
 265        vmcoreinfo_append_str("VMALLOC_START=%lx\n", (unsigned long)value)
 266#define VMCOREINFO_VMEMMAP_START(value) \
 267        vmcoreinfo_append_str("VMEMMAP_START=%lx\n", (unsigned long)value)
 268
 269extern struct kimage *kexec_image;
 270extern struct kimage *kexec_crash_image;
 271extern int kexec_load_disabled;
 272
 273#ifndef kexec_flush_icache_page
 274#define kexec_flush_icache_page(page)
 275#endif
 276
 277/* List of defined/legal kexec flags */
 278#ifndef CONFIG_KEXEC_JUMP
 279#define KEXEC_FLAGS    KEXEC_ON_CRASH
 280#else
 281#define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT)
 282#endif
 283
 284/* List of defined/legal kexec file flags */
 285#define KEXEC_FILE_FLAGS        (KEXEC_FILE_UNLOAD | KEXEC_FILE_ON_CRASH | \
 286                                 KEXEC_FILE_NO_INITRAMFS)
 287
 288#define VMCOREINFO_BYTES           (4096)
 289#define VMCOREINFO_NOTE_NAME       "VMCOREINFO"
 290#define VMCOREINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCOREINFO_NOTE_NAME), 4)
 291#define VMCOREINFO_NOTE_SIZE       (KEXEC_NOTE_HEAD_BYTES*2 + VMCOREINFO_BYTES \
 292                                    + VMCOREINFO_NOTE_NAME_BYTES)
 293
 294/* Location of a reserved region to hold the crash kernel.
 295 */
 296extern struct resource crashk_res;
 297extern struct resource crashk_low_res;
 298typedef u32 note_buf_t[KEXEC_NOTE_BYTES/4];
 299extern note_buf_t __percpu *crash_notes;
 300extern u32 vmcoreinfo_note[VMCOREINFO_NOTE_SIZE/4];
 301extern size_t vmcoreinfo_size;
 302extern size_t vmcoreinfo_max_size;
 303
 304/* flag to track if kexec reboot is in progress */
 305extern bool kexec_in_progress;
 306
 307int __init parse_crashkernel(char *cmdline, unsigned long long system_ram,
 308                unsigned long long *crash_size, unsigned long long *crash_base);
 309int parse_crashkernel_high(char *cmdline, unsigned long long system_ram,
 310                unsigned long long *crash_size, unsigned long long *crash_base);
 311int parse_crashkernel_low(char *cmdline, unsigned long long system_ram,
 312                unsigned long long *crash_size, unsigned long long *crash_base);
 313int crash_shrink_memory(unsigned long new_size);
 314size_t crash_get_memory_size(void);
 315void crash_free_reserved_phys_range(unsigned long begin, unsigned long end);
 316
 317int __weak arch_kexec_kernel_image_probe(struct kimage *image, void *buf,
 318                                         unsigned long buf_len);
 319void * __weak arch_kexec_kernel_image_load(struct kimage *image);
 320int __weak arch_kimage_file_post_load_cleanup(struct kimage *image);
 321int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf,
 322                                        unsigned long buf_len);
 323int __weak arch_kexec_apply_relocations_add(const Elf_Ehdr *ehdr,
 324                                        Elf_Shdr *sechdrs, unsigned int relsec);
 325int __weak arch_kexec_apply_relocations(const Elf_Ehdr *ehdr, Elf_Shdr *sechdrs,
 326                                        unsigned int relsec);
 327void arch_kexec_protect_crashkres(void);
 328void arch_kexec_unprotect_crashkres(void);
 329
 330#ifndef page_to_boot_pfn
 331static inline unsigned long page_to_boot_pfn(struct page *page)
 332{
 333        return page_to_pfn(page);
 334}
 335#endif
 336
 337#ifndef boot_pfn_to_page
 338static inline struct page *boot_pfn_to_page(unsigned long boot_pfn)
 339{
 340        return pfn_to_page(boot_pfn);
 341}
 342#endif
 343
 344#ifndef phys_to_boot_phys
 345static inline unsigned long phys_to_boot_phys(phys_addr_t phys)
 346{
 347        return phys;
 348}
 349#endif
 350
 351#ifndef boot_phys_to_phys
 352static inline phys_addr_t boot_phys_to_phys(unsigned long boot_phys)
 353{
 354        return boot_phys;
 355}
 356#endif
 357
 358static inline unsigned long virt_to_boot_phys(void *addr)
 359{
 360        return phys_to_boot_phys(__pa((unsigned long)addr));
 361}
 362
 363static inline void *boot_phys_to_virt(unsigned long entry)
 364{
 365        return phys_to_virt(boot_phys_to_phys(entry));
 366}
 367
 368#else /* !CONFIG_KEXEC_CORE */
 369struct pt_regs;
 370struct task_struct;
 371static inline void __crash_kexec(struct pt_regs *regs) { }
 372static inline void crash_kexec(struct pt_regs *regs) { }
 373static inline int kexec_should_crash(struct task_struct *p) { return 0; }
 374static inline int kexec_crash_loaded(void) { return 0; }
 375#define kexec_in_progress false
 376#endif /* CONFIG_KEXEC_CORE */
 377
 378#endif /* !defined(__ASSEBMLY__) */
 379
 380#endif /* LINUX_KEXEC_H */
 381