machine_kexec_32.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * handle transition of Linux booting another kernel
  3. * Copyright (C) 2002-2005 Eric Biederman <ebiederm@xmission.com>
  4. *
  5. * This source code is licensed under the GNU General Public License,
  6. * Version 2. See the file COPYING for more details.
  7. */
  8. #include <linux/mm.h>
  9. #include <linux/kexec.h>
  10. #include <linux/delay.h>
  11. #include <linux/init.h>
  12. #include <linux/numa.h>
  13. #include <linux/ftrace.h>
  14. #include <asm/pgtable.h>
  15. #include <asm/pgalloc.h>
  16. #include <asm/tlbflush.h>
  17. #include <asm/mmu_context.h>
  18. #include <asm/io.h>
  19. #include <asm/apic.h>
  20. #include <asm/cpufeature.h>
  21. #include <asm/desc.h>
  22. #include <asm/system.h>
  23. #include <asm/cacheflush.h>
  24. #define PAGE_ALIGNED __attribute__ ((__aligned__(PAGE_SIZE)))
  25. static u32 kexec_pgd[1024] PAGE_ALIGNED;
  26. #ifdef CONFIG_X86_PAE
  27. static u32 kexec_pmd0[1024] PAGE_ALIGNED;
  28. static u32 kexec_pmd1[1024] PAGE_ALIGNED;
  29. #endif
  30. static u32 kexec_pte0[1024] PAGE_ALIGNED;
  31. static u32 kexec_pte1[1024] PAGE_ALIGNED;
  32. static void set_idt(void *newidt, __u16 limit)
  33. {
  34. struct desc_ptr curidt;
  35. /* ia32 supports unaliged loads & stores */
  36. curidt.size = limit;
  37. curidt.address = (unsigned long)newidt;
  38. load_idt(&curidt);
  39. }
  40. static void set_gdt(void *newgdt, __u16 limit)
  41. {
  42. struct desc_ptr curgdt;
  43. /* ia32 supports unaligned loads & stores */
  44. curgdt.size = limit;
  45. curgdt.address = (unsigned long)newgdt;
  46. load_gdt(&curgdt);
  47. }
  48. static void load_segments(void)
  49. {
  50. #define __STR(X) #X
  51. #define STR(X) __STR(X)
  52. __asm__ __volatile__ (
  53. "\tljmp $"STR(__KERNEL_CS)",$1f\n"
  54. "\t1:\n"
  55. "\tmovl $"STR(__KERNEL_DS)",%%eax\n"
  56. "\tmovl %%eax,%%ds\n"
  57. "\tmovl %%eax,%%es\n"
  58. "\tmovl %%eax,%%fs\n"
  59. "\tmovl %%eax,%%gs\n"
  60. "\tmovl %%eax,%%ss\n"
  61. ::: "eax", "memory");
  62. #undef STR
  63. #undef __STR
  64. }
  65. /*
  66. * A architecture hook called to validate the
  67. * proposed image and prepare the control pages
  68. * as needed. The pages for KEXEC_CONTROL_CODE_SIZE
  69. * have been allocated, but the segments have yet
  70. * been copied into the kernel.
  71. *
  72. * Do what every setup is needed on image and the
  73. * reboot code buffer to allow us to avoid allocations
  74. * later.
  75. *
  76. * Make control page executable.
  77. */
  78. int machine_kexec_prepare(struct kimage *image)
  79. {
  80. if (nx_enabled)
  81. set_pages_x(image->control_code_page, 1);
  82. return 0;
  83. }
  84. /*
  85. * Undo anything leftover by machine_kexec_prepare
  86. * when an image is freed.
  87. */
  88. void machine_kexec_cleanup(struct kimage *image)
  89. {
  90. if (nx_enabled)
  91. set_pages_nx(image->control_code_page, 1);
  92. }
  93. /*
  94. * Do not allocate memory (or fail in any way) in machine_kexec().
  95. * We are past the point of no return, committed to rebooting now.
  96. */
  97. void machine_kexec(struct kimage *image)
  98. {
  99. unsigned long page_list[PAGES_NR];
  100. void *control_page;
  101. asmlinkage unsigned long
  102. (*relocate_kernel_ptr)(unsigned long indirection_page,
  103. unsigned long control_page,
  104. unsigned long start_address,
  105. unsigned int has_pae,
  106. unsigned int preserve_context);
  107. tracer_disable();
  108. /* Interrupts aren't acceptable while we reboot */
  109. local_irq_disable();
  110. if (image->preserve_context) {
  111. #ifdef CONFIG_X86_IO_APIC
  112. /* We need to put APICs in legacy mode so that we can
  113. * get timer interrupts in second kernel. kexec/kdump
  114. * paths already have calls to disable_IO_APIC() in
  115. * one form or other. kexec jump path also need
  116. * one.
  117. */
  118. disable_IO_APIC();
  119. #endif
  120. }
  121. control_page = page_address(image->control_code_page);
  122. memcpy(control_page, relocate_kernel, PAGE_SIZE/2);
  123. relocate_kernel_ptr = control_page;
  124. page_list[PA_CONTROL_PAGE] = __pa(control_page);
  125. page_list[VA_CONTROL_PAGE] = (unsigned long)control_page;
  126. page_list[PA_PGD] = __pa(kexec_pgd);
  127. page_list[VA_PGD] = (unsigned long)kexec_pgd;
  128. #ifdef CONFIG_X86_PAE
  129. page_list[PA_PMD_0] = __pa(kexec_pmd0);
  130. page_list[VA_PMD_0] = (unsigned long)kexec_pmd0;
  131. page_list[PA_PMD_1] = __pa(kexec_pmd1);
  132. page_list[VA_PMD_1] = (unsigned long)kexec_pmd1;
  133. #endif
  134. page_list[PA_PTE_0] = __pa(kexec_pte0);
  135. page_list[VA_PTE_0] = (unsigned long)kexec_pte0;
  136. page_list[PA_PTE_1] = __pa(kexec_pte1);
  137. page_list[VA_PTE_1] = (unsigned long)kexec_pte1;
  138. page_list[PA_SWAP_PAGE] = (page_to_pfn(image->swap_page) << PAGE_SHIFT);
  139. /* The segment registers are funny things, they have both a
  140. * visible and an invisible part. Whenever the visible part is
  141. * set to a specific selector, the invisible part is loaded
  142. * with from a table in memory. At no other time is the
  143. * descriptor table in memory accessed.
  144. *
  145. * I take advantage of this here by force loading the
  146. * segments, before I zap the gdt with an invalid value.
  147. */
  148. load_segments();
  149. /* The gdt & idt are now invalid.
  150. * If you want to load them you must set up your own idt & gdt.
  151. */
  152. set_gdt(phys_to_virt(0),0);
  153. set_idt(phys_to_virt(0),0);
  154. /* now call it */
  155. image->start = relocate_kernel_ptr((unsigned long)image->head,
  156. (unsigned long)page_list,
  157. image->start, cpu_has_pae,
  158. image->preserve_context);
  159. }
  160. void arch_crash_save_vmcoreinfo(void)
  161. {
  162. #ifdef CONFIG_NUMA
  163. VMCOREINFO_SYMBOL(node_data);
  164. VMCOREINFO_LENGTH(node_data, MAX_NUMNODES);
  165. #endif
  166. #ifdef CONFIG_X86_PAE
  167. VMCOREINFO_CONFIG(X86_PAE);
  168. #endif
  169. }