xref: /openbmc/linux/include/linux/kexec.h (revision a72bbec7)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2dc009d92SEric W. Biederman #ifndef LINUX_KEXEC_H
3dc009d92SEric W. Biederman #define LINUX_KEXEC_H
4dc009d92SEric W. Biederman 
5cf2df639SGeoff Levand #define IND_DESTINATION_BIT 0
6cf2df639SGeoff Levand #define IND_INDIRECTION_BIT 1
7cf2df639SGeoff Levand #define IND_DONE_BIT        2
8cf2df639SGeoff Levand #define IND_SOURCE_BIT      3
9cf2df639SGeoff Levand 
10cf2df639SGeoff Levand #define IND_DESTINATION  (1 << IND_DESTINATION_BIT)
11cf2df639SGeoff Levand #define IND_INDIRECTION  (1 << IND_INDIRECTION_BIT)
12cf2df639SGeoff Levand #define IND_DONE         (1 << IND_DONE_BIT)
13cf2df639SGeoff Levand #define IND_SOURCE       (1 << IND_SOURCE_BIT)
14b28c2ee8SGeoff Levand #define IND_FLAGS (IND_DESTINATION | IND_INDIRECTION | IND_DONE | IND_SOURCE)
15cf2df639SGeoff Levand 
16cf2df639SGeoff Levand #if !defined(__ASSEMBLY__)
17cf2df639SGeoff Levand 
18692f66f2SHari Bathini #include <linux/crash_core.h>
1943546d86SRussell King #include <asm/io.h>
20cade589fSLi Chen #include <linux/range.h>
2143546d86SRussell King 
22607ca46eSDavid Howells #include <uapi/linux/kexec.h>
23c903dae8SCoiby Xu #include <linux/verification.h>
2429a5c67eSmaximilian attems 
25f05fa109SJisheng Zhang /* Location of a reserved region to hold the crash kernel.
26f05fa109SJisheng Zhang  */
27f05fa109SJisheng Zhang extern struct resource crashk_res;
28f05fa109SJisheng Zhang extern struct resource crashk_low_res;
29f05fa109SJisheng Zhang extern note_buf_t __percpu *crash_notes;
30f05fa109SJisheng Zhang 
312965faa5SDave Young #ifdef CONFIG_KEXEC_CORE
32dc009d92SEric W. Biederman #include <linux/list.h>
33dc009d92SEric W. Biederman #include <linux/compat.h>
349c15e852SHaren Myneni #include <linux/ioport.h>
3512db5562SVivek Goyal #include <linux/module.h>
3624726275SEric DeVolder #include <linux/highmem.h>
37dc009d92SEric W. Biederman #include <asm/kexec.h>
38dc009d92SEric W. Biederman 
39dc009d92SEric W. Biederman /* Verify architecture specific macros are defined */
40dc009d92SEric W. Biederman 
41dc009d92SEric W. Biederman #ifndef KEXEC_SOURCE_MEMORY_LIMIT
42dc009d92SEric W. Biederman #error KEXEC_SOURCE_MEMORY_LIMIT not defined
43dc009d92SEric W. Biederman #endif
44dc009d92SEric W. Biederman 
45dc009d92SEric W. Biederman #ifndef KEXEC_DESTINATION_MEMORY_LIMIT
46dc009d92SEric W. Biederman #error KEXEC_DESTINATION_MEMORY_LIMIT not defined
47dc009d92SEric W. Biederman #endif
48dc009d92SEric W. Biederman 
49dc009d92SEric W. Biederman #ifndef KEXEC_CONTROL_MEMORY_LIMIT
50dc009d92SEric W. Biederman #error KEXEC_CONTROL_MEMORY_LIMIT not defined
51dc009d92SEric W. Biederman #endif
52dc009d92SEric W. Biederman 
537e01b5acSMartin Schwidefsky #ifndef KEXEC_CONTROL_MEMORY_GFP
54dc5cccacSRussell King #define KEXEC_CONTROL_MEMORY_GFP (GFP_KERNEL | __GFP_NORETRY)
557e01b5acSMartin Schwidefsky #endif
567e01b5acSMartin Schwidefsky 
57163f6876SHuang Ying #ifndef KEXEC_CONTROL_PAGE_SIZE
58163f6876SHuang Ying #error KEXEC_CONTROL_PAGE_SIZE not defined
59dc009d92SEric W. Biederman #endif
60dc009d92SEric W. Biederman 
61dc009d92SEric W. Biederman #ifndef KEXEC_ARCH
62dc009d92SEric W. Biederman #error KEXEC_ARCH not defined
63dc009d92SEric W. Biederman #endif
64dc009d92SEric W. Biederman 
653d214faeSMichael Holzheu #ifndef KEXEC_CRASH_CONTROL_MEMORY_LIMIT
663d214faeSMichael Holzheu #define KEXEC_CRASH_CONTROL_MEMORY_LIMIT KEXEC_CONTROL_MEMORY_LIMIT
673d214faeSMichael Holzheu #endif
683d214faeSMichael Holzheu 
69558df720SMichael Holzheu #ifndef KEXEC_CRASH_MEM_ALIGN
70558df720SMichael Holzheu #define KEXEC_CRASH_MEM_ALIGN PAGE_SIZE
71558df720SMichael Holzheu #endif
72558df720SMichael Holzheu 
73692f66f2SHari Bathini #define KEXEC_CORE_NOTE_NAME	CRASH_CORE_NOTE_NAME
74692f66f2SHari Bathini 
756672f76aSSimon Horman /*
76dc009d92SEric W. Biederman  * This structure is used to hold the arguments that are used when loading
77dc009d92SEric W. Biederman  * kernel binaries.
78dc009d92SEric W. Biederman  */
79dc009d92SEric W. Biederman 
80dc009d92SEric W. Biederman typedef unsigned long kimage_entry_t;
81dc009d92SEric W. Biederman 
82dc009d92SEric W. Biederman struct kexec_segment {
83815d5704SVivek Goyal 	/*
84815d5704SVivek Goyal 	 * This pointer can point to user memory if kexec_load() system
85815d5704SVivek Goyal 	 * call is used or will point to kernel memory if
86815d5704SVivek Goyal 	 * kexec_file_load() system call is used.
87815d5704SVivek Goyal 	 *
88815d5704SVivek Goyal 	 * Use ->buf when expecting to deal with user memory and use ->kbuf
89815d5704SVivek Goyal 	 * when expecting to deal with kernel memory.
90815d5704SVivek Goyal 	 */
91815d5704SVivek Goyal 	union {
92dc009d92SEric W. Biederman 		void __user *buf;
93815d5704SVivek Goyal 		void *kbuf;
94815d5704SVivek Goyal 	};
95dc009d92SEric W. Biederman 	size_t bufsz;
9629a5c67eSmaximilian attems 	unsigned long mem;
97dc009d92SEric W. Biederman 	size_t memsz;
98dc009d92SEric W. Biederman };
99dc009d92SEric W. Biederman 
100dc009d92SEric W. Biederman #ifdef CONFIG_COMPAT
101dc009d92SEric W. Biederman struct compat_kexec_segment {
102dc009d92SEric W. Biederman 	compat_uptr_t buf;
103dc009d92SEric W. Biederman 	compat_size_t bufsz;
104dc009d92SEric W. Biederman 	compat_ulong_t mem;	/* User space sees this as a (void *) ... */
105dc009d92SEric W. Biederman 	compat_size_t memsz;
106dc009d92SEric W. Biederman };
107dc009d92SEric W. Biederman #endif
108dc009d92SEric W. Biederman 
109978e30c9SXunlei Pang #ifdef CONFIG_KEXEC_FILE
11012db5562SVivek Goyal struct purgatory_info {
11165c225d3SPhilipp Rudo 	/*
11265c225d3SPhilipp Rudo 	 * Pointer to elf header at the beginning of kexec_purgatory.
11365c225d3SPhilipp Rudo 	 * Note: kexec_purgatory is read only
11465c225d3SPhilipp Rudo 	 */
11565c225d3SPhilipp Rudo 	const Elf_Ehdr *ehdr;
11665c225d3SPhilipp Rudo 	/*
11765c225d3SPhilipp Rudo 	 * Temporary, modifiable buffer for sechdrs used for relocation.
11865c225d3SPhilipp Rudo 	 * This memory can be freed post image load.
11965c225d3SPhilipp Rudo 	 */
12012db5562SVivek Goyal 	Elf_Shdr *sechdrs;
12112db5562SVivek Goyal 	/*
12265c225d3SPhilipp Rudo 	 * Temporary, modifiable buffer for stripped purgatory used for
12365c225d3SPhilipp Rudo 	 * relocation. This memory can be freed post image load.
12412db5562SVivek Goyal 	 */
12512db5562SVivek Goyal 	void *purgatory_buf;
12612db5562SVivek Goyal };
12712db5562SVivek Goyal 
128ee6ebedaSPhilipp Rudo struct kimage;
129ee6ebedaSPhilipp Rudo 
130978e30c9SXunlei Pang typedef int (kexec_probe_t)(const char *kernel_buf, unsigned long kernel_size);
131978e30c9SXunlei Pang typedef void *(kexec_load_t)(struct kimage *image, char *kernel_buf,
132978e30c9SXunlei Pang 			     unsigned long kernel_len, char *initrd,
133978e30c9SXunlei Pang 			     unsigned long initrd_len, char *cmdline,
134978e30c9SXunlei Pang 			     unsigned long cmdline_len);
135978e30c9SXunlei Pang typedef int (kexec_cleanup_t)(void *loader_data);
136978e30c9SXunlei Pang 
13799d5cadfSJiri Bohac #ifdef CONFIG_KEXEC_SIG
138978e30c9SXunlei Pang typedef int (kexec_verify_sig_t)(const char *kernel_buf,
139978e30c9SXunlei Pang 				 unsigned long kernel_len);
140978e30c9SXunlei Pang #endif
141978e30c9SXunlei Pang 
142978e30c9SXunlei Pang struct kexec_file_ops {
143978e30c9SXunlei Pang 	kexec_probe_t *probe;
144978e30c9SXunlei Pang 	kexec_load_t *load;
145978e30c9SXunlei Pang 	kexec_cleanup_t *cleanup;
14699d5cadfSJiri Bohac #ifdef CONFIG_KEXEC_SIG
147978e30c9SXunlei Pang 	kexec_verify_sig_t *verify_sig;
148978e30c9SXunlei Pang #endif
149978e30c9SXunlei Pang };
15060fe3910SThiago Jung Bauermann 
1519ec4ecefSAKASHI Takahiro extern const struct kexec_file_ops * const kexec_file_loaders[];
1529ec4ecefSAKASHI Takahiro 
1539ec4ecefSAKASHI Takahiro int kexec_image_probe_default(struct kimage *image, void *buf,
1549ec4ecefSAKASHI Takahiro 			      unsigned long buf_len);
15592a98a2bSAKASHI Takahiro int kexec_image_post_load_cleanup_default(struct kimage *image);
1569ec4ecefSAKASHI Takahiro 
157b6664ba4SAKASHI Takahiro /*
158b6664ba4SAKASHI Takahiro  * If kexec_buf.mem is set to this value, kexec_locate_mem_hole()
159b6664ba4SAKASHI Takahiro  * will try to allocate free memory. Arch may overwrite it.
160b6664ba4SAKASHI Takahiro  */
161b6664ba4SAKASHI Takahiro #ifndef KEXEC_BUF_MEM_UNKNOWN
162b6664ba4SAKASHI Takahiro #define KEXEC_BUF_MEM_UNKNOWN 0
163b6664ba4SAKASHI Takahiro #endif
164b6664ba4SAKASHI Takahiro 
16560fe3910SThiago Jung Bauermann /**
16660fe3910SThiago Jung Bauermann  * struct kexec_buf - parameters for finding a place for a buffer in memory
16760fe3910SThiago Jung Bauermann  * @image:	kexec image in which memory to search.
16860fe3910SThiago Jung Bauermann  * @buffer:	Contents which will be copied to the allocated memory.
16960fe3910SThiago Jung Bauermann  * @bufsz:	Size of @buffer.
17060fe3910SThiago Jung Bauermann  * @mem:	On return will have address of the buffer in memory.
17160fe3910SThiago Jung Bauermann  * @memsz:	Size for the buffer in memory.
17260fe3910SThiago Jung Bauermann  * @buf_align:	Minimum alignment needed.
17360fe3910SThiago Jung Bauermann  * @buf_min:	The buffer can't be placed below this address.
17460fe3910SThiago Jung Bauermann  * @buf_max:	The buffer can't be placed above this address.
17560fe3910SThiago Jung Bauermann  * @top_down:	Allocate from top of memory.
17660fe3910SThiago Jung Bauermann  */
17760fe3910SThiago Jung Bauermann struct kexec_buf {
17860fe3910SThiago Jung Bauermann 	struct kimage *image;
179ec2b9bfaSThiago Jung Bauermann 	void *buffer;
18060fe3910SThiago Jung Bauermann 	unsigned long bufsz;
18160fe3910SThiago Jung Bauermann 	unsigned long mem;
18260fe3910SThiago Jung Bauermann 	unsigned long memsz;
18360fe3910SThiago Jung Bauermann 	unsigned long buf_align;
18460fe3910SThiago Jung Bauermann 	unsigned long buf_min;
18560fe3910SThiago Jung Bauermann 	unsigned long buf_max;
18660fe3910SThiago Jung Bauermann 	bool top_down;
18760fe3910SThiago Jung Bauermann };
18860fe3910SThiago Jung Bauermann 
1893be3f61dSPhilipp Rudo int kexec_load_purgatory(struct kimage *image, struct kexec_buf *kbuf);
1903be3f61dSPhilipp Rudo int kexec_purgatory_get_set_symbol(struct kimage *image, const char *name,
1913be3f61dSPhilipp Rudo 				   void *buf, unsigned int size,
1923be3f61dSPhilipp Rudo 				   bool get_value);
1933be3f61dSPhilipp Rudo void *kexec_purgatory_get_symbol_addr(struct kimage *image, const char *name);
1943be3f61dSPhilipp Rudo 
19565d9a9a6SNaveen N. Rao #ifndef arch_kexec_kernel_image_probe
19665d9a9a6SNaveen N. Rao static inline int
arch_kexec_kernel_image_probe(struct kimage * image,void * buf,unsigned long buf_len)19765d9a9a6SNaveen N. Rao arch_kexec_kernel_image_probe(struct kimage *image, void *buf, unsigned long buf_len)
19865d9a9a6SNaveen N. Rao {
19965d9a9a6SNaveen N. Rao 	return kexec_image_probe_default(image, buf, buf_len);
20065d9a9a6SNaveen N. Rao }
20165d9a9a6SNaveen N. Rao #endif
20265d9a9a6SNaveen N. Rao 
20365d9a9a6SNaveen N. Rao #ifndef arch_kimage_file_post_load_cleanup
arch_kimage_file_post_load_cleanup(struct kimage * image)20465d9a9a6SNaveen N. Rao static inline int arch_kimage_file_post_load_cleanup(struct kimage *image)
20565d9a9a6SNaveen N. Rao {
20665d9a9a6SNaveen N. Rao 	return kexec_image_post_load_cleanup_default(image);
20765d9a9a6SNaveen N. Rao }
20865d9a9a6SNaveen N. Rao #endif
20965d9a9a6SNaveen N. Rao 
210c903dae8SCoiby Xu #ifdef CONFIG_KEXEC_SIG
211c903dae8SCoiby Xu #ifdef CONFIG_SIGNED_PE_FILE_VERIFICATION
212c903dae8SCoiby Xu int kexec_kernel_verify_pe_sig(const char *kernel, unsigned long kernel_len);
213c903dae8SCoiby Xu #endif
214c903dae8SCoiby Xu #endif
215c903dae8SCoiby Xu 
216ec2b9bfaSThiago Jung Bauermann extern int kexec_add_buffer(struct kexec_buf *kbuf);
217e2e806f9SThiago Jung Bauermann int kexec_locate_mem_hole(struct kexec_buf *kbuf);
218babac4a8SAKASHI Takahiro 
21965d9a9a6SNaveen N. Rao #ifndef arch_kexec_locate_mem_hole
22065d9a9a6SNaveen N. Rao /**
22165d9a9a6SNaveen N. Rao  * arch_kexec_locate_mem_hole - Find free memory to place the segments.
22265d9a9a6SNaveen N. Rao  * @kbuf:                       Parameters for the memory search.
22365d9a9a6SNaveen N. Rao  *
22465d9a9a6SNaveen N. Rao  * On success, kbuf->mem will have the start address of the memory region found.
22565d9a9a6SNaveen N. Rao  *
22665d9a9a6SNaveen N. Rao  * Return: 0 on success, negative errno on error.
22765d9a9a6SNaveen N. Rao  */
arch_kexec_locate_mem_hole(struct kexec_buf * kbuf)22865d9a9a6SNaveen N. Rao static inline int arch_kexec_locate_mem_hole(struct kexec_buf *kbuf)
22965d9a9a6SNaveen N. Rao {
23065d9a9a6SNaveen N. Rao 	return kexec_locate_mem_hole(kbuf);
23165d9a9a6SNaveen N. Rao }
23265d9a9a6SNaveen N. Rao #endif
23365d9a9a6SNaveen N. Rao 
2343e35142eSNaveen N. Rao #ifndef arch_kexec_apply_relocations_add
2353e35142eSNaveen N. Rao /*
2363e35142eSNaveen N. Rao  * arch_kexec_apply_relocations_add - apply relocations of type RELA
2373e35142eSNaveen N. Rao  * @pi:		Purgatory to be relocated.
2383e35142eSNaveen N. Rao  * @section:	Section relocations applying to.
2393e35142eSNaveen N. Rao  * @relsec:	Section containing RELAs.
2403e35142eSNaveen N. Rao  * @symtab:	Corresponding symtab.
2413e35142eSNaveen N. Rao  *
2423e35142eSNaveen N. Rao  * Return: 0 on success, negative errno on error.
2433e35142eSNaveen N. Rao  */
2443e35142eSNaveen N. Rao static inline int
arch_kexec_apply_relocations_add(struct purgatory_info * pi,Elf_Shdr * section,const Elf_Shdr * relsec,const Elf_Shdr * symtab)2453e35142eSNaveen N. Rao arch_kexec_apply_relocations_add(struct purgatory_info *pi, Elf_Shdr *section,
2463e35142eSNaveen N. Rao 				 const Elf_Shdr *relsec, const Elf_Shdr *symtab)
2473e35142eSNaveen N. Rao {
2483e35142eSNaveen N. Rao 	pr_err("RELA relocation unsupported.\n");
2493e35142eSNaveen N. Rao 	return -ENOEXEC;
2503e35142eSNaveen N. Rao }
2513e35142eSNaveen N. Rao #endif
2523e35142eSNaveen N. Rao 
2533e35142eSNaveen N. Rao #ifndef arch_kexec_apply_relocations
2543e35142eSNaveen N. Rao /*
2553e35142eSNaveen N. Rao  * arch_kexec_apply_relocations - apply relocations of type REL
2563e35142eSNaveen N. Rao  * @pi:		Purgatory to be relocated.
2573e35142eSNaveen N. Rao  * @section:	Section relocations applying to.
2583e35142eSNaveen N. Rao  * @relsec:	Section containing RELs.
2593e35142eSNaveen N. Rao  * @symtab:	Corresponding symtab.
2603e35142eSNaveen N. Rao  *
2613e35142eSNaveen N. Rao  * Return: 0 on success, negative errno on error.
2623e35142eSNaveen N. Rao  */
2633e35142eSNaveen N. Rao static inline int
arch_kexec_apply_relocations(struct purgatory_info * pi,Elf_Shdr * section,const Elf_Shdr * relsec,const Elf_Shdr * symtab)2643e35142eSNaveen N. Rao arch_kexec_apply_relocations(struct purgatory_info *pi, Elf_Shdr *section,
2653e35142eSNaveen N. Rao 			     const Elf_Shdr *relsec, const Elf_Shdr *symtab)
2663e35142eSNaveen N. Rao {
2673e35142eSNaveen N. Rao 	pr_err("REL relocation unsupported.\n");
2683e35142eSNaveen N. Rao 	return -ENOEXEC;
2693e35142eSNaveen N. Rao }
2703e35142eSNaveen N. Rao #endif
27160fe3910SThiago Jung Bauermann #endif /* CONFIG_KEXEC_FILE */
272978e30c9SXunlei Pang 
273175fca3bSSven Schnelle #ifdef CONFIG_KEXEC_ELF
274175fca3bSSven Schnelle struct kexec_elf_info {
275175fca3bSSven Schnelle 	/*
276175fca3bSSven Schnelle 	 * Where the ELF binary contents are kept.
277175fca3bSSven Schnelle 	 * Memory managed by the user of the struct.
278175fca3bSSven Schnelle 	 */
279175fca3bSSven Schnelle 	const char *buffer;
280175fca3bSSven Schnelle 
281175fca3bSSven Schnelle 	const struct elfhdr *ehdr;
282175fca3bSSven Schnelle 	const struct elf_phdr *proghdrs;
283175fca3bSSven Schnelle };
284175fca3bSSven Schnelle 
285175fca3bSSven Schnelle int kexec_build_elf_info(const char *buf, size_t len, struct elfhdr *ehdr,
286175fca3bSSven Schnelle 			       struct kexec_elf_info *elf_info);
287175fca3bSSven Schnelle 
288175fca3bSSven Schnelle int kexec_elf_load(struct kimage *image, struct elfhdr *ehdr,
289175fca3bSSven Schnelle 			 struct kexec_elf_info *elf_info,
290175fca3bSSven Schnelle 			 struct kexec_buf *kbuf,
291175fca3bSSven Schnelle 			 unsigned long *lowest_load_addr);
292175fca3bSSven Schnelle 
293175fca3bSSven Schnelle void kexec_free_elf_info(struct kexec_elf_info *elf_info);
294175fca3bSSven Schnelle int kexec_elf_probe(const char *buf, unsigned long len);
295175fca3bSSven Schnelle #endif
296dc009d92SEric W. Biederman struct kimage {
297dc009d92SEric W. Biederman 	kimage_entry_t head;
298dc009d92SEric W. Biederman 	kimage_entry_t *entry;
299dc009d92SEric W. Biederman 	kimage_entry_t *last_entry;
300dc009d92SEric W. Biederman 
301dc009d92SEric W. Biederman 	unsigned long start;
302dc009d92SEric W. Biederman 	struct page *control_code_page;
3033ab83521SHuang Ying 	struct page *swap_page;
3041229384fSXunlei Pang 	void *vmcoreinfo_data_copy; /* locates in the crash memory */
305dc009d92SEric W. Biederman 
306dc009d92SEric W. Biederman 	unsigned long nr_segments;
307dc009d92SEric W. Biederman 	struct kexec_segment segment[KEXEC_SEGMENT_MAX];
308dc009d92SEric W. Biederman 
309dc009d92SEric W. Biederman 	struct list_head control_pages;
310dc009d92SEric W. Biederman 	struct list_head dest_pages;
3117d3e2bcaSVivek Goyal 	struct list_head unusable_pages;
312dc009d92SEric W. Biederman 
313dc009d92SEric W. Biederman 	/* Address of next control page to allocate for crash kernels. */
314dc009d92SEric W. Biederman 	unsigned long control_page;
315dc009d92SEric W. Biederman 
316dc009d92SEric W. Biederman 	/* Flags to indicate special processing */
317dc009d92SEric W. Biederman 	unsigned int type : 1;
318dc009d92SEric W. Biederman #define KEXEC_TYPE_DEFAULT 0
319dc009d92SEric W. Biederman #define KEXEC_TYPE_CRASH   1
3203ab83521SHuang Ying 	unsigned int preserve_context : 1;
321cb105258SVivek Goyal 	/* If set, we are using file mode kexec syscall */
322cb105258SVivek Goyal 	unsigned int file_mode:1;
323*a72bbec7SEric DeVolder #ifdef CONFIG_CRASH_HOTPLUG
324*a72bbec7SEric DeVolder 	/* If set, allow changes to elfcorehdr of kexec_load'd image */
325*a72bbec7SEric DeVolder 	unsigned int update_elfcorehdr:1;
326*a72bbec7SEric DeVolder #endif
32792be3d6bSHuang Ying 
32892be3d6bSHuang Ying #ifdef ARCH_HAS_KIMAGE_ARCH
32992be3d6bSHuang Ying 	struct kimage_arch arch;
33092be3d6bSHuang Ying #endif
331cb105258SVivek Goyal 
332978e30c9SXunlei Pang #ifdef CONFIG_KEXEC_FILE
333cb105258SVivek Goyal 	/* Additional fields for file based kexec syscall */
334cb105258SVivek Goyal 	void *kernel_buf;
335cb105258SVivek Goyal 	unsigned long kernel_buf_len;
336cb105258SVivek Goyal 
337cb105258SVivek Goyal 	void *initrd_buf;
338cb105258SVivek Goyal 	unsigned long initrd_buf_len;
339cb105258SVivek Goyal 
340cb105258SVivek Goyal 	char *cmdline_buf;
341cb105258SVivek Goyal 	unsigned long cmdline_buf_len;
342cb105258SVivek Goyal 
343cb105258SVivek Goyal 	/* File operations provided by image loader */
3449ec4ecefSAKASHI Takahiro 	const struct kexec_file_ops *fops;
345cb105258SVivek Goyal 
346cb105258SVivek Goyal 	/* Image loader handling the kernel can store a pointer here */
347cb105258SVivek Goyal 	void *image_loader_data;
34812db5562SVivek Goyal 
34912db5562SVivek Goyal 	/* Information for loading purgatory */
35012db5562SVivek Goyal 	struct purgatory_info purgatory_info;
351978e30c9SXunlei Pang #endif
352f31e3386SLakshmi Ramasubramanian 
35324726275SEric DeVolder #ifdef CONFIG_CRASH_HOTPLUG
35424726275SEric DeVolder 	int hp_action;
35524726275SEric DeVolder 	int elfcorehdr_index;
35624726275SEric DeVolder 	bool elfcorehdr_updated;
35724726275SEric DeVolder #endif
35824726275SEric DeVolder 
359f31e3386SLakshmi Ramasubramanian #ifdef CONFIG_IMA_KEXEC
360f31e3386SLakshmi Ramasubramanian 	/* Virtual address of IMA measurement buffer for kexec syscall */
361f31e3386SLakshmi Ramasubramanian 	void *ima_buffer;
3620c605158SLakshmi Ramasubramanian 
3630c605158SLakshmi Ramasubramanian 	phys_addr_t ima_buffer_addr;
3640c605158SLakshmi Ramasubramanian 	size_t ima_buffer_size;
365f31e3386SLakshmi Ramasubramanian #endif
3669336a5f6SLakshmi Ramasubramanian 
3679336a5f6SLakshmi Ramasubramanian 	/* Core ELF header buffer */
3689336a5f6SLakshmi Ramasubramanian 	void *elf_headers;
3699336a5f6SLakshmi Ramasubramanian 	unsigned long elf_headers_sz;
3709336a5f6SLakshmi Ramasubramanian 	unsigned long elf_load_addr;
371cb105258SVivek Goyal };
372dc009d92SEric W. Biederman 
373dc009d92SEric W. Biederman /* kexec interface functions */
3743ab83521SHuang Ying extern void machine_kexec(struct kimage *image);
375dc009d92SEric W. Biederman extern int machine_kexec_prepare(struct kimage *image);
376dc009d92SEric W. Biederman extern void machine_kexec_cleanup(struct kimage *image);
3773ab83521SHuang Ying extern int kernel_kexec(void);
37872414d3fSManeesh Soni extern struct page *kimage_alloc_control_pages(struct kimage *image,
37972414d3fSManeesh Soni 						unsigned int order);
3800738ecebSNaveen N. Rao 
3810738ecebSNaveen N. Rao #ifndef machine_kexec_post_load
machine_kexec_post_load(struct kimage * image)3820738ecebSNaveen N. Rao static inline int machine_kexec_post_load(struct kimage *image) { return 0; }
3830738ecebSNaveen N. Rao #endif
3842596b6aeSPavel Tatashin 
3857bbee5caSHidehiro Kawai extern void __crash_kexec(struct pt_regs *);
3866e274d14SAlexander Nyberg extern void crash_kexec(struct pt_regs *);
3876e274d14SAlexander Nyberg int kexec_should_crash(struct task_struct *);
38821db79e8SPetr Tesarik int kexec_crash_loaded(void);
38985916f81SMagnus Damm void crash_save_cpu(struct pt_regs *regs, int cpu);
3901229384fSXunlei Pang extern int kimage_crash_copy_vmcoreinfo(struct kimage *image);
391fd59d231SKen'ichi Ohmichi 
392dc009d92SEric W. Biederman extern struct kimage *kexec_image;
393c330dda9SJeff Moyer extern struct kimage *kexec_crash_image;
3947e99f8b6SRicardo Ribalda 
395a42aaad2SRicardo Ribalda bool kexec_load_permitted(int kexec_image_type);
396dc009d92SEric W. Biederman 
397a7956113SZou Nan hai #ifndef kexec_flush_icache_page
398a7956113SZou Nan hai #define kexec_flush_icache_page(page)
399a7956113SZou Nan hai #endif
400a7956113SZou Nan hai 
4013ab83521SHuang Ying /* List of defined/legal kexec flags */
4023ab83521SHuang Ying #ifndef CONFIG_KEXEC_JUMP
403*a72bbec7SEric DeVolder #define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_UPDATE_ELFCOREHDR)
4043ab83521SHuang Ying #else
405*a72bbec7SEric DeVolder #define KEXEC_FLAGS    (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT | KEXEC_UPDATE_ELFCOREHDR)
4063ab83521SHuang Ying #endif
407dc009d92SEric W. Biederman 
408cb105258SVivek Goyal /* List of defined/legal kexec file flags */
409cb105258SVivek Goyal #define KEXEC_FILE_FLAGS	(KEXEC_FILE_UNLOAD | KEXEC_FILE_ON_CRASH | \
410cb105258SVivek Goyal 				 KEXEC_FILE_NO_INITRAMFS)
411cb105258SVivek Goyal 
4124fc9bbf9SKhalid Aziz /* flag to track if kexec reboot is in progress */
4134fc9bbf9SKhalid Aziz extern bool kexec_in_progress;
4144fc9bbf9SKhalid Aziz 
41506a7f711SAmerigo Wang int crash_shrink_memory(unsigned long new_size);
4167bb5da0dSValentin Schneider ssize_t crash_get_memory_size(void);
417a7956113SZou Nan hai 
4180738ecebSNaveen N. Rao #ifndef arch_kexec_protect_crashkres
4190738ecebSNaveen N. Rao /*
4200738ecebSNaveen N. Rao  * Protection mechanism for crashkernel reserved memory after
4210738ecebSNaveen N. Rao  * the kdump kernel is loaded.
4220738ecebSNaveen N. Rao  *
4230738ecebSNaveen N. Rao  * Provide an empty default implementation here -- architecture
4240738ecebSNaveen N. Rao  * code may override this
4250738ecebSNaveen N. Rao  */
arch_kexec_protect_crashkres(void)4260738ecebSNaveen N. Rao static inline void arch_kexec_protect_crashkres(void) { }
4270738ecebSNaveen N. Rao #endif
4280738ecebSNaveen N. Rao 
4290738ecebSNaveen N. Rao #ifndef arch_kexec_unprotect_crashkres
arch_kexec_unprotect_crashkres(void)4300738ecebSNaveen N. Rao static inline void arch_kexec_unprotect_crashkres(void) { }
4310738ecebSNaveen N. Rao #endif
432a43cac0dSDave Young 
43343546d86SRussell King #ifndef page_to_boot_pfn
page_to_boot_pfn(struct page * page)43443546d86SRussell King static inline unsigned long page_to_boot_pfn(struct page *page)
43543546d86SRussell King {
43643546d86SRussell King 	return page_to_pfn(page);
43743546d86SRussell King }
43843546d86SRussell King #endif
43943546d86SRussell King 
44043546d86SRussell King #ifndef boot_pfn_to_page
boot_pfn_to_page(unsigned long boot_pfn)44143546d86SRussell King static inline struct page *boot_pfn_to_page(unsigned long boot_pfn)
44243546d86SRussell King {
44343546d86SRussell King 	return pfn_to_page(boot_pfn);
44443546d86SRussell King }
44543546d86SRussell King #endif
44643546d86SRussell King 
44743546d86SRussell King #ifndef phys_to_boot_phys
phys_to_boot_phys(phys_addr_t phys)44843546d86SRussell King static inline unsigned long phys_to_boot_phys(phys_addr_t phys)
44943546d86SRussell King {
45043546d86SRussell King 	return phys;
45143546d86SRussell King }
45243546d86SRussell King #endif
45343546d86SRussell King 
45443546d86SRussell King #ifndef boot_phys_to_phys
boot_phys_to_phys(unsigned long boot_phys)45543546d86SRussell King static inline phys_addr_t boot_phys_to_phys(unsigned long boot_phys)
45643546d86SRussell King {
45743546d86SRussell King 	return boot_phys;
45843546d86SRussell King }
45943546d86SRussell King #endif
46043546d86SRussell King 
4610738ecebSNaveen N. Rao #ifndef crash_free_reserved_phys_range
crash_free_reserved_phys_range(unsigned long begin,unsigned long end)4620738ecebSNaveen N. Rao static inline void crash_free_reserved_phys_range(unsigned long begin, unsigned long end)
4630738ecebSNaveen N. Rao {
4640738ecebSNaveen N. Rao 	unsigned long addr;
4650738ecebSNaveen N. Rao 
4660738ecebSNaveen N. Rao 	for (addr = begin; addr < end; addr += PAGE_SIZE)
4670738ecebSNaveen N. Rao 		free_reserved_page(boot_pfn_to_page(addr >> PAGE_SHIFT));
4680738ecebSNaveen N. Rao }
4690738ecebSNaveen N. Rao #endif
4700738ecebSNaveen N. Rao 
virt_to_boot_phys(void * addr)47143546d86SRussell King static inline unsigned long virt_to_boot_phys(void *addr)
47243546d86SRussell King {
47343546d86SRussell King 	return phys_to_boot_phys(__pa((unsigned long)addr));
47443546d86SRussell King }
47543546d86SRussell King 
boot_phys_to_virt(unsigned long entry)47643546d86SRussell King static inline void *boot_phys_to_virt(unsigned long entry)
47743546d86SRussell King {
47843546d86SRussell King 	return phys_to_virt(boot_phys_to_phys(entry));
47943546d86SRussell King }
48043546d86SRussell King 
481bba4ed01STom Lendacky #ifndef arch_kexec_post_alloc_pages
arch_kexec_post_alloc_pages(void * vaddr,unsigned int pages,gfp_t gfp)482bba4ed01STom Lendacky static inline int arch_kexec_post_alloc_pages(void *vaddr, unsigned int pages, gfp_t gfp) { return 0; }
483bba4ed01STom Lendacky #endif
484bba4ed01STom Lendacky 
485bba4ed01STom Lendacky #ifndef arch_kexec_pre_free_pages
arch_kexec_pre_free_pages(void * vaddr,unsigned int pages)486bba4ed01STom Lendacky static inline void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages) { }
487bba4ed01STom Lendacky #endif
488bba4ed01STom Lendacky 
48924726275SEric DeVolder #ifndef arch_crash_handle_hotplug_event
arch_crash_handle_hotplug_event(struct kimage * image)49024726275SEric DeVolder static inline void arch_crash_handle_hotplug_event(struct kimage *image) { }
49124726275SEric DeVolder #endif
49224726275SEric DeVolder 
493*a72bbec7SEric DeVolder int crash_check_update_elfcorehdr(void);
494*a72bbec7SEric DeVolder 
49588a6f899SEric DeVolder #ifndef crash_hotplug_cpu_support
crash_hotplug_cpu_support(void)49688a6f899SEric DeVolder static inline int crash_hotplug_cpu_support(void) { return 0; }
49788a6f899SEric DeVolder #endif
49888a6f899SEric DeVolder 
49988a6f899SEric DeVolder #ifndef crash_hotplug_memory_support
crash_hotplug_memory_support(void)50088a6f899SEric DeVolder static inline int crash_hotplug_memory_support(void) { return 0; }
50188a6f899SEric DeVolder #endif
50288a6f899SEric DeVolder 
503*a72bbec7SEric DeVolder #ifndef crash_get_elfcorehdr_size
crash_get_elfcorehdr_size(void)504*a72bbec7SEric DeVolder static inline unsigned int crash_get_elfcorehdr_size(void) { return 0; }
505*a72bbec7SEric DeVolder #endif
506*a72bbec7SEric DeVolder 
5072965faa5SDave Young #else /* !CONFIG_KEXEC_CORE */
5086e274d14SAlexander Nyberg struct pt_regs;
5096e274d14SAlexander Nyberg struct task_struct;
__crash_kexec(struct pt_regs * regs)5107bbee5caSHidehiro Kawai static inline void __crash_kexec(struct pt_regs *regs) { }
crash_kexec(struct pt_regs * regs)5116e274d14SAlexander Nyberg static inline void crash_kexec(struct pt_regs *regs) { }
kexec_should_crash(struct task_struct * p)5126e274d14SAlexander Nyberg static inline int kexec_should_crash(struct task_struct *p) { return 0; }
kexec_crash_loaded(void)51321db79e8SPetr Tesarik static inline int kexec_crash_loaded(void) { return 0; }
5142b94ed24SVitaly Kuznetsov #define kexec_in_progress false
5152965faa5SDave Young #endif /* CONFIG_KEXEC_CORE */
516cf2df639SGeoff Levand 
517af16df54SCoiby Xu #ifdef CONFIG_KEXEC_SIG
518af16df54SCoiby Xu void set_kexec_sig_enforced(void);
519af16df54SCoiby Xu #else
set_kexec_sig_enforced(void)520af16df54SCoiby Xu static inline void set_kexec_sig_enforced(void) {}
521af16df54SCoiby Xu #endif
522af16df54SCoiby Xu 
523cf2df639SGeoff Levand #endif /* !defined(__ASSEBMLY__) */
524cf2df639SGeoff Levand 
525dc009d92SEric W. Biederman #endif /* LINUX_KEXEC_H */
526