1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_KEXEC_H
3 #define _ASM_X86_KEXEC_H
6 # define PA_CONTROL_PAGE 0
7 # define VA_CONTROL_PAGE 1
9 # define PA_SWAP_PAGE 3
12 # define PA_CONTROL_PAGE 0
13 # define VA_CONTROL_PAGE 1
14 # define PA_TABLE_PAGE 2
15 # define PA_SWAP_PAGE 3
19 # define KEXEC_CONTROL_CODE_MAX_SIZE 2048
23 #include <linux/string.h>
24 #include <linux/kernel.h>
27 #include <asm/ptrace.h>
28 #include <asm/bootparam.h>
33 * KEXEC_SOURCE_MEMORY_LIMIT maximum page get_free_page can return.
34 * I.e. Maximum page that is mapped directly into kernel memory,
35 * and kmap is not required.
37 * So far x86_64 is limited to 40 physical address bits.
40 /* Maximum physical address we can use pages from */
41 # define KEXEC_SOURCE_MEMORY_LIMIT (-1UL)
42 /* Maximum address we can reach in physical address mode */
43 # define KEXEC_DESTINATION_MEMORY_LIMIT (-1UL)
44 /* Maximum address we can use for the control code buffer */
45 # define KEXEC_CONTROL_MEMORY_LIMIT TASK_SIZE
47 # define KEXEC_CONTROL_PAGE_SIZE 4096
49 /* The native architecture */
50 # define KEXEC_ARCH KEXEC_ARCH_386
52 /* We can also handle crash dumps from 64 bit kernel. */
53 # define vmcore_elf_check_arch_cross(x) ((x)->e_machine == EM_X86_64)
55 /* Maximum physical address we can use pages from */
56 # define KEXEC_SOURCE_MEMORY_LIMIT (MAXMEM-1)
57 /* Maximum address we can reach in physical address mode */
58 # define KEXEC_DESTINATION_MEMORY_LIMIT (MAXMEM-1)
59 /* Maximum address we can use for the control pages */
60 # define KEXEC_CONTROL_MEMORY_LIMIT (MAXMEM-1)
62 /* Allocate one page for the pdp and the second for the code */
63 # define KEXEC_CONTROL_PAGE_SIZE (4096UL + 4096UL)
65 /* The native architecture */
66 # define KEXEC_ARCH KEXEC_ARCH_X86_64
70 * This function is responsible for capturing register states if coming
71 * via panic otherwise just fix up the ss and sp if coming via kernel
74 static inline void crash_setup_regs(struct pt_regs
*newregs
,
75 struct pt_regs
*oldregs
)
78 memcpy(newregs
, oldregs
, sizeof(*newregs
));
81 asm volatile("movl %%ebx,%0" : "=m"(newregs
->bx
));
82 asm volatile("movl %%ecx,%0" : "=m"(newregs
->cx
));
83 asm volatile("movl %%edx,%0" : "=m"(newregs
->dx
));
84 asm volatile("movl %%esi,%0" : "=m"(newregs
->si
));
85 asm volatile("movl %%edi,%0" : "=m"(newregs
->di
));
86 asm volatile("movl %%ebp,%0" : "=m"(newregs
->bp
));
87 asm volatile("movl %%eax,%0" : "=m"(newregs
->ax
));
88 asm volatile("movl %%esp,%0" : "=m"(newregs
->sp
));
89 asm volatile("movl %%ss, %%eax;" :"=a"(newregs
->ss
));
90 asm volatile("movl %%cs, %%eax;" :"=a"(newregs
->cs
));
91 asm volatile("movl %%ds, %%eax;" :"=a"(newregs
->ds
));
92 asm volatile("movl %%es, %%eax;" :"=a"(newregs
->es
));
93 asm volatile("pushfl; popl %0" :"=m"(newregs
->flags
));
95 asm volatile("movq %%rbx,%0" : "=m"(newregs
->bx
));
96 asm volatile("movq %%rcx,%0" : "=m"(newregs
->cx
));
97 asm volatile("movq %%rdx,%0" : "=m"(newregs
->dx
));
98 asm volatile("movq %%rsi,%0" : "=m"(newregs
->si
));
99 asm volatile("movq %%rdi,%0" : "=m"(newregs
->di
));
100 asm volatile("movq %%rbp,%0" : "=m"(newregs
->bp
));
101 asm volatile("movq %%rax,%0" : "=m"(newregs
->ax
));
102 asm volatile("movq %%rsp,%0" : "=m"(newregs
->sp
));
103 asm volatile("movq %%r8,%0" : "=m"(newregs
->r8
));
104 asm volatile("movq %%r9,%0" : "=m"(newregs
->r9
));
105 asm volatile("movq %%r10,%0" : "=m"(newregs
->r10
));
106 asm volatile("movq %%r11,%0" : "=m"(newregs
->r11
));
107 asm volatile("movq %%r12,%0" : "=m"(newregs
->r12
));
108 asm volatile("movq %%r13,%0" : "=m"(newregs
->r13
));
109 asm volatile("movq %%r14,%0" : "=m"(newregs
->r14
));
110 asm volatile("movq %%r15,%0" : "=m"(newregs
->r15
));
111 asm volatile("movl %%ss, %%eax;" :"=a"(newregs
->ss
));
112 asm volatile("movl %%cs, %%eax;" :"=a"(newregs
->cs
));
113 asm volatile("pushfq; popq %0" :"=m"(newregs
->flags
));
115 newregs
->ip
= _THIS_IP_
;
120 asmlinkage
unsigned long
121 relocate_kernel(unsigned long indirection_page
,
122 unsigned long control_page
,
123 unsigned long start_address
,
124 unsigned int has_pae
,
125 unsigned int preserve_context
);
128 relocate_kernel(unsigned long indirection_page
,
129 unsigned long page_list
,
130 unsigned long start_address
,
131 unsigned int preserve_context
,
132 unsigned int sme_active
);
135 #define ARCH_HAS_KIMAGE_ARCH
140 #ifdef CONFIG_X86_PAE
154 /* Core ELF header buffer */
156 unsigned long elf_headers_sz
;
157 unsigned long elf_load_addr
;
159 #endif /* CONFIG_X86_32 */
163 * Number of elements and order of elements in this structure should match
164 * with the ones in arch/x86/purgatory/entry64.S. If you make a change here
165 * make an appropriate change in purgatory too.
167 struct kexec_entry64_regs
{
187 extern int arch_kexec_post_alloc_pages(void *vaddr
, unsigned int pages
,
189 #define arch_kexec_post_alloc_pages arch_kexec_post_alloc_pages
191 extern void arch_kexec_pre_free_pages(void *vaddr
, unsigned int pages
);
192 #define arch_kexec_pre_free_pages arch_kexec_pre_free_pages
196 typedef void crash_vmclear_fn(void);
197 extern crash_vmclear_fn __rcu
*crash_vmclear_loaded_vmcss
;
198 extern void kdump_nmi_shootdown_cpus(void);
200 #endif /* __ASSEMBLY__ */
202 #endif /* _ASM_X86_KEXEC_H */