kexec.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #ifndef _ASM_X86_KEXEC_H
  2. #define _ASM_X86_KEXEC_H
  3. #ifdef CONFIG_X86_32
  4. # define PA_CONTROL_PAGE 0
  5. # define VA_CONTROL_PAGE 1
  6. # define PA_PGD 2
  7. # define PA_SWAP_PAGE 3
  8. # define PAGES_NR 4
  9. #else
  10. # define PA_CONTROL_PAGE 0
  11. # define VA_CONTROL_PAGE 1
  12. # define PA_TABLE_PAGE 2
  13. # define PA_SWAP_PAGE 3
  14. # define PAGES_NR 4
  15. #endif
  16. # define KEXEC_CONTROL_CODE_MAX_SIZE 2048
  17. #ifndef __ASSEMBLY__
  18. #include <linux/string.h>
  19. #include <asm/page.h>
  20. #include <asm/ptrace.h>
  21. /*
  22. * KEXEC_SOURCE_MEMORY_LIMIT maximum page get_free_page can return.
  23. * I.e. Maximum page that is mapped directly into kernel memory,
  24. * and kmap is not required.
  25. *
  26. * So far x86_64 is limited to 40 physical address bits.
  27. */
  28. #ifdef CONFIG_X86_32
  29. /* Maximum physical address we can use pages from */
  30. # define KEXEC_SOURCE_MEMORY_LIMIT (-1UL)
  31. /* Maximum address we can reach in physical address mode */
  32. # define KEXEC_DESTINATION_MEMORY_LIMIT (-1UL)
  33. /* Maximum address we can use for the control code buffer */
  34. # define KEXEC_CONTROL_MEMORY_LIMIT TASK_SIZE
  35. # define KEXEC_CONTROL_PAGE_SIZE 4096
  36. /* The native architecture */
  37. # define KEXEC_ARCH KEXEC_ARCH_386
  38. /* We can also handle crash dumps from 64 bit kernel. */
  39. # define vmcore_elf_check_arch_cross(x) ((x)->e_machine == EM_X86_64)
  40. #else
  41. /* Maximum physical address we can use pages from */
  42. # define KEXEC_SOURCE_MEMORY_LIMIT (0xFFFFFFFFFFUL)
  43. /* Maximum address we can reach in physical address mode */
  44. # define KEXEC_DESTINATION_MEMORY_LIMIT (0xFFFFFFFFFFUL)
  45. /* Maximum address we can use for the control pages */
  46. # define KEXEC_CONTROL_MEMORY_LIMIT (0xFFFFFFFFFFUL)
  47. /* Allocate one page for the pdp and the second for the code */
  48. # define KEXEC_CONTROL_PAGE_SIZE (4096UL + 4096UL)
  49. /* The native architecture */
  50. # define KEXEC_ARCH KEXEC_ARCH_X86_64
  51. #endif
  52. /*
  53. * CPU does not save ss and sp on stack if execution is already
  54. * running in kernel mode at the time of NMI occurrence. This code
  55. * fixes it.
  56. */
  57. static inline void crash_fixup_ss_esp(struct pt_regs *newregs,
  58. struct pt_regs *oldregs)
  59. {
  60. #ifdef CONFIG_X86_32
  61. newregs->sp = (unsigned long)&(oldregs->sp);
  62. asm volatile("xorl %%eax, %%eax\n\t"
  63. "movw %%ss, %%ax\n\t"
  64. :"=a"(newregs->ss));
  65. #endif
  66. }
  67. /*
  68. * This function is responsible for capturing register states if coming
  69. * via panic otherwise just fix up the ss and sp if coming via kernel
  70. * mode exception.
  71. */
  72. static inline void crash_setup_regs(struct pt_regs *newregs,
  73. struct pt_regs *oldregs)
  74. {
  75. if (oldregs) {
  76. memcpy(newregs, oldregs, sizeof(*newregs));
  77. crash_fixup_ss_esp(newregs, oldregs);
  78. } else {
  79. #ifdef CONFIG_X86_32
  80. asm volatile("movl %%ebx,%0" : "=m"(newregs->bx));
  81. asm volatile("movl %%ecx,%0" : "=m"(newregs->cx));
  82. asm volatile("movl %%edx,%0" : "=m"(newregs->dx));
  83. asm volatile("movl %%esi,%0" : "=m"(newregs->si));
  84. asm volatile("movl %%edi,%0" : "=m"(newregs->di));
  85. asm volatile("movl %%ebp,%0" : "=m"(newregs->bp));
  86. asm volatile("movl %%eax,%0" : "=m"(newregs->ax));
  87. asm volatile("movl %%esp,%0" : "=m"(newregs->sp));
  88. asm volatile("movl %%ss, %%eax;" :"=a"(newregs->ss));
  89. asm volatile("movl %%cs, %%eax;" :"=a"(newregs->cs));
  90. asm volatile("movl %%ds, %%eax;" :"=a"(newregs->ds));
  91. asm volatile("movl %%es, %%eax;" :"=a"(newregs->es));
  92. asm volatile("pushfl; popl %0" :"=m"(newregs->flags));
  93. #else
  94. asm volatile("movq %%rbx,%0" : "=m"(newregs->bx));
  95. asm volatile("movq %%rcx,%0" : "=m"(newregs->cx));
  96. asm volatile("movq %%rdx,%0" : "=m"(newregs->dx));
  97. asm volatile("movq %%rsi,%0" : "=m"(newregs->si));
  98. asm volatile("movq %%rdi,%0" : "=m"(newregs->di));
  99. asm volatile("movq %%rbp,%0" : "=m"(newregs->bp));
  100. asm volatile("movq %%rax,%0" : "=m"(newregs->ax));
  101. asm volatile("movq %%rsp,%0" : "=m"(newregs->sp));
  102. asm volatile("movq %%r8,%0" : "=m"(newregs->r8));
  103. asm volatile("movq %%r9,%0" : "=m"(newregs->r9));
  104. asm volatile("movq %%r10,%0" : "=m"(newregs->r10));
  105. asm volatile("movq %%r11,%0" : "=m"(newregs->r11));
  106. asm volatile("movq %%r12,%0" : "=m"(newregs->r12));
  107. asm volatile("movq %%r13,%0" : "=m"(newregs->r13));
  108. asm volatile("movq %%r14,%0" : "=m"(newregs->r14));
  109. asm volatile("movq %%r15,%0" : "=m"(newregs->r15));
  110. asm volatile("movl %%ss, %%eax;" :"=a"(newregs->ss));
  111. asm volatile("movl %%cs, %%eax;" :"=a"(newregs->cs));
  112. asm volatile("pushfq; popq %0" :"=m"(newregs->flags));
  113. #endif
  114. newregs->ip = (unsigned long)current_text_addr();
  115. }
  116. }
  117. #ifdef CONFIG_X86_32
  118. asmlinkage unsigned long
  119. relocate_kernel(unsigned long indirection_page,
  120. unsigned long control_page,
  121. unsigned long start_address,
  122. unsigned int has_pae,
  123. unsigned int preserve_context);
  124. #else
  125. unsigned long
  126. relocate_kernel(unsigned long indirection_page,
  127. unsigned long page_list,
  128. unsigned long start_address,
  129. unsigned int preserve_context);
  130. #endif
  131. #define ARCH_HAS_KIMAGE_ARCH
  132. #ifdef CONFIG_X86_32
  133. struct kimage_arch {
  134. pgd_t *pgd;
  135. #ifdef CONFIG_X86_PAE
  136. pmd_t *pmd0;
  137. pmd_t *pmd1;
  138. #endif
  139. pte_t *pte0;
  140. pte_t *pte1;
  141. };
  142. #else
  143. struct kimage_arch {
  144. pud_t *pud;
  145. pmd_t *pmd;
  146. pte_t *pte;
  147. };
  148. #endif
  149. #endif /* __ASSEMBLY__ */
  150. #endif /* _ASM_X86_KEXEC_H */