Linux Audio

Check our new training course

Loading...
v6.2
  1/* SPDX-License-Identifier: GPL-2.0 */
  2#ifndef _ASM_X86_KEXEC_H
  3#define _ASM_X86_KEXEC_H
  4
  5#ifdef CONFIG_X86_32
  6# define PA_CONTROL_PAGE	0
  7# define VA_CONTROL_PAGE	1
  8# define PA_PGD			2
  9# define PA_SWAP_PAGE		3
 10# define PAGES_NR		4
 11#else
 12# define PA_CONTROL_PAGE	0
 13# define VA_CONTROL_PAGE	1
 14# define PA_TABLE_PAGE		2
 15# define PA_SWAP_PAGE		3
 16# define PAGES_NR		4
 17#endif
 18
 19# define KEXEC_CONTROL_CODE_MAX_SIZE	2048
 20
 21#ifndef __ASSEMBLY__
 22
 23#include <linux/string.h>
 24#include <linux/kernel.h>
 25
 26#include <asm/page.h>
 27#include <asm/ptrace.h>
 28#include <asm/bootparam.h>
 29
 30struct kimage;
 31
 32/*
 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.
 36 *
 37 * So far x86_64 is limited to 40 physical address bits.
 38 */
 39#ifdef CONFIG_X86_32
 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
 46
 47# define KEXEC_CONTROL_PAGE_SIZE	4096
 48
 49/* The native architecture */
 50# define KEXEC_ARCH KEXEC_ARCH_386
 51
 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)
 54#else
 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)
 61
 62/* Allocate one page for the pdp and the second for the code */
 63# define KEXEC_CONTROL_PAGE_SIZE  (4096UL + 4096UL)
 64
 65/* The native architecture */
 66# define KEXEC_ARCH KEXEC_ARCH_X86_64
 67#endif
 68
 69/*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 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
 72 * mode exception.
 73 */
 74static inline void crash_setup_regs(struct pt_regs *newregs,
 75				    struct pt_regs *oldregs)
 76{
 77	if (oldregs) {
 78		memcpy(newregs, oldregs, sizeof(*newregs));
 
 79	} else {
 80#ifdef CONFIG_X86_32
 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));
 94#else
 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));
114#endif
115		newregs->ip = _THIS_IP_;
116	}
117}
118
119#ifdef CONFIG_X86_32
120asmlinkage unsigned long
121relocate_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);
126#else
127unsigned long
128relocate_kernel(unsigned long indirection_page,
129		unsigned long page_list,
130		unsigned long start_address,
131		unsigned int preserve_context,
132		unsigned int host_mem_enc_active);
133#endif
134
135#define ARCH_HAS_KIMAGE_ARCH
136
137#ifdef CONFIG_X86_32
138struct kimage_arch {
139	pgd_t *pgd;
140#ifdef CONFIG_X86_PAE
141	pmd_t *pmd0;
142	pmd_t *pmd1;
143#endif
144	pte_t *pte0;
145	pte_t *pte1;
146};
147#else
148struct kimage_arch {
149	p4d_t *p4d;
150	pud_t *pud;
151	pmd_t *pmd;
152	pte_t *pte;
153};
154#endif /* CONFIG_X86_32 */
155
156#ifdef CONFIG_X86_64
157/*
158 * Number of elements and order of elements in this structure should match
159 * with the ones in arch/x86/purgatory/entry64.S. If you make a change here
160 * make an appropriate change in purgatory too.
161 */
162struct kexec_entry64_regs {
163	uint64_t rax;
164	uint64_t rcx;
165	uint64_t rdx;
166	uint64_t rbx;
167	uint64_t rsp;
168	uint64_t rbp;
169	uint64_t rsi;
170	uint64_t rdi;
171	uint64_t r8;
172	uint64_t r9;
173	uint64_t r10;
174	uint64_t r11;
175	uint64_t r12;
176	uint64_t r13;
177	uint64_t r14;
178	uint64_t r15;
179	uint64_t rip;
180};
181
182extern int arch_kexec_post_alloc_pages(void *vaddr, unsigned int pages,
183				       gfp_t gfp);
184#define arch_kexec_post_alloc_pages arch_kexec_post_alloc_pages
185
186extern void arch_kexec_pre_free_pages(void *vaddr, unsigned int pages);
187#define arch_kexec_pre_free_pages arch_kexec_pre_free_pages
188
189void arch_kexec_protect_crashkres(void);
190#define arch_kexec_protect_crashkres arch_kexec_protect_crashkres
191
192void arch_kexec_unprotect_crashkres(void);
193#define arch_kexec_unprotect_crashkres arch_kexec_unprotect_crashkres
194
195#ifdef CONFIG_KEXEC_FILE
196struct purgatory_info;
197int arch_kexec_apply_relocations_add(struct purgatory_info *pi,
198				     Elf_Shdr *section,
199				     const Elf_Shdr *relsec,
200				     const Elf_Shdr *symtab);
201#define arch_kexec_apply_relocations_add arch_kexec_apply_relocations_add
202
203void *arch_kexec_kernel_image_load(struct kimage *image);
204#define arch_kexec_kernel_image_load arch_kexec_kernel_image_load
205
206int arch_kimage_file_post_load_cleanup(struct kimage *image);
207#define arch_kimage_file_post_load_cleanup arch_kimage_file_post_load_cleanup
208#endif
209#endif
210
211typedef void crash_vmclear_fn(void);
212extern crash_vmclear_fn __rcu *crash_vmclear_loaded_vmcss;
213extern void kdump_nmi_shootdown_cpus(void);
214
215#endif /* __ASSEMBLY__ */
216
217#endif /* _ASM_X86_KEXEC_H */
v3.1
 
  1#ifndef _ASM_X86_KEXEC_H
  2#define _ASM_X86_KEXEC_H
  3
  4#ifdef CONFIG_X86_32
  5# define PA_CONTROL_PAGE	0
  6# define VA_CONTROL_PAGE	1
  7# define PA_PGD			2
  8# define PA_SWAP_PAGE		3
  9# define PAGES_NR		4
 10#else
 11# define PA_CONTROL_PAGE	0
 12# define VA_CONTROL_PAGE	1
 13# define PA_TABLE_PAGE		2
 14# define PA_SWAP_PAGE		3
 15# define PAGES_NR		4
 16#endif
 17
 18# define KEXEC_CONTROL_CODE_MAX_SIZE	2048
 19
 20#ifndef __ASSEMBLY__
 21
 22#include <linux/string.h>
 
 23
 24#include <asm/page.h>
 25#include <asm/ptrace.h>
 
 
 
 26
 27/*
 28 * KEXEC_SOURCE_MEMORY_LIMIT maximum page get_free_page can return.
 29 * I.e. Maximum page that is mapped directly into kernel memory,
 30 * and kmap is not required.
 31 *
 32 * So far x86_64 is limited to 40 physical address bits.
 33 */
 34#ifdef CONFIG_X86_32
 35/* Maximum physical address we can use pages from */
 36# define KEXEC_SOURCE_MEMORY_LIMIT (-1UL)
 37/* Maximum address we can reach in physical address mode */
 38# define KEXEC_DESTINATION_MEMORY_LIMIT (-1UL)
 39/* Maximum address we can use for the control code buffer */
 40# define KEXEC_CONTROL_MEMORY_LIMIT TASK_SIZE
 41
 42# define KEXEC_CONTROL_PAGE_SIZE	4096
 43
 44/* The native architecture */
 45# define KEXEC_ARCH KEXEC_ARCH_386
 46
 47/* We can also handle crash dumps from 64 bit kernel. */
 48# define vmcore_elf_check_arch_cross(x) ((x)->e_machine == EM_X86_64)
 49#else
 50/* Maximum physical address we can use pages from */
 51# define KEXEC_SOURCE_MEMORY_LIMIT      (0xFFFFFFFFFFUL)
 52/* Maximum address we can reach in physical address mode */
 53# define KEXEC_DESTINATION_MEMORY_LIMIT (0xFFFFFFFFFFUL)
 54/* Maximum address we can use for the control pages */
 55# define KEXEC_CONTROL_MEMORY_LIMIT     (0xFFFFFFFFFFUL)
 56
 57/* Allocate one page for the pdp and the second for the code */
 58# define KEXEC_CONTROL_PAGE_SIZE  (4096UL + 4096UL)
 59
 60/* The native architecture */
 61# define KEXEC_ARCH KEXEC_ARCH_X86_64
 62#endif
 63
 64/*
 65 * CPU does not save ss and sp on stack if execution is already
 66 * running in kernel mode at the time of NMI occurrence. This code
 67 * fixes it.
 68 */
 69static inline void crash_fixup_ss_esp(struct pt_regs *newregs,
 70				      struct pt_regs *oldregs)
 71{
 72#ifdef CONFIG_X86_32
 73	newregs->sp = (unsigned long)&(oldregs->sp);
 74	asm volatile("xorl %%eax, %%eax\n\t"
 75		     "movw %%ss, %%ax\n\t"
 76		     :"=a"(newregs->ss));
 77#endif
 78}
 79
 80/*
 81 * This function is responsible for capturing register states if coming
 82 * via panic otherwise just fix up the ss and sp if coming via kernel
 83 * mode exception.
 84 */
 85static inline void crash_setup_regs(struct pt_regs *newregs,
 86				    struct pt_regs *oldregs)
 87{
 88	if (oldregs) {
 89		memcpy(newregs, oldregs, sizeof(*newregs));
 90		crash_fixup_ss_esp(newregs, oldregs);
 91	} else {
 92#ifdef CONFIG_X86_32
 93		asm volatile("movl %%ebx,%0" : "=m"(newregs->bx));
 94		asm volatile("movl %%ecx,%0" : "=m"(newregs->cx));
 95		asm volatile("movl %%edx,%0" : "=m"(newregs->dx));
 96		asm volatile("movl %%esi,%0" : "=m"(newregs->si));
 97		asm volatile("movl %%edi,%0" : "=m"(newregs->di));
 98		asm volatile("movl %%ebp,%0" : "=m"(newregs->bp));
 99		asm volatile("movl %%eax,%0" : "=m"(newregs->ax));
100		asm volatile("movl %%esp,%0" : "=m"(newregs->sp));
101		asm volatile("movl %%ss, %%eax;" :"=a"(newregs->ss));
102		asm volatile("movl %%cs, %%eax;" :"=a"(newregs->cs));
103		asm volatile("movl %%ds, %%eax;" :"=a"(newregs->ds));
104		asm volatile("movl %%es, %%eax;" :"=a"(newregs->es));
105		asm volatile("pushfl; popl %0" :"=m"(newregs->flags));
106#else
107		asm volatile("movq %%rbx,%0" : "=m"(newregs->bx));
108		asm volatile("movq %%rcx,%0" : "=m"(newregs->cx));
109		asm volatile("movq %%rdx,%0" : "=m"(newregs->dx));
110		asm volatile("movq %%rsi,%0" : "=m"(newregs->si));
111		asm volatile("movq %%rdi,%0" : "=m"(newregs->di));
112		asm volatile("movq %%rbp,%0" : "=m"(newregs->bp));
113		asm volatile("movq %%rax,%0" : "=m"(newregs->ax));
114		asm volatile("movq %%rsp,%0" : "=m"(newregs->sp));
115		asm volatile("movq %%r8,%0" : "=m"(newregs->r8));
116		asm volatile("movq %%r9,%0" : "=m"(newregs->r9));
117		asm volatile("movq %%r10,%0" : "=m"(newregs->r10));
118		asm volatile("movq %%r11,%0" : "=m"(newregs->r11));
119		asm volatile("movq %%r12,%0" : "=m"(newregs->r12));
120		asm volatile("movq %%r13,%0" : "=m"(newregs->r13));
121		asm volatile("movq %%r14,%0" : "=m"(newregs->r14));
122		asm volatile("movq %%r15,%0" : "=m"(newregs->r15));
123		asm volatile("movl %%ss, %%eax;" :"=a"(newregs->ss));
124		asm volatile("movl %%cs, %%eax;" :"=a"(newregs->cs));
125		asm volatile("pushfq; popq %0" :"=m"(newregs->flags));
126#endif
127		newregs->ip = (unsigned long)current_text_addr();
128	}
129}
130
131#ifdef CONFIG_X86_32
132asmlinkage unsigned long
133relocate_kernel(unsigned long indirection_page,
134		unsigned long control_page,
135		unsigned long start_address,
136		unsigned int has_pae,
137		unsigned int preserve_context);
138#else
139unsigned long
140relocate_kernel(unsigned long indirection_page,
141		unsigned long page_list,
142		unsigned long start_address,
143		unsigned int preserve_context);
 
144#endif
145
146#define ARCH_HAS_KIMAGE_ARCH
147
148#ifdef CONFIG_X86_32
149struct kimage_arch {
150	pgd_t *pgd;
151#ifdef CONFIG_X86_PAE
152	pmd_t *pmd0;
153	pmd_t *pmd1;
154#endif
155	pte_t *pte0;
156	pte_t *pte1;
157};
158#else
159struct kimage_arch {
 
160	pud_t *pud;
161	pmd_t *pmd;
162	pte_t *pte;
163};
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164#endif
 
 
 
 
 
165
166#endif /* __ASSEMBLY__ */
167
168#endif /* _ASM_X86_KEXEC_H */