machine_kexec_32.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. #define PAGE_ALIGNED __attribute__ ((__aligned__(PAGE_SIZE)))
  24. static u32 kexec_pgd[1024] PAGE_ALIGNED;
  25. #ifdef CONFIG_X86_PAE
  26. static u32 kexec_pmd0[1024] PAGE_ALIGNED;
  27. static u32 kexec_pmd1[1024] PAGE_ALIGNED;
  28. #endif
  29. static u32 kexec_pte0[1024] PAGE_ALIGNED;
  30. static u32 kexec_pte1[1024] PAGE_ALIGNED;
  31. static void set_idt(void *newidt, __u16 limit)
  32. {
  33. struct desc_ptr curidt;
  34. /* ia32 supports unaliged loads & stores */
  35. curidt.size = limit;
  36. curidt.address = (unsigned long)newidt;
  37. load_idt(&curidt);
  38. }
  39. static void set_gdt(void *newgdt, __u16 limit)
  40. {
  41. struct desc_ptr curgdt;
  42. /* ia32 supports unaligned loads & stores */
  43. curgdt.size = limit;
  44. curgdt.address = (unsigned long)newgdt;
  45. load_gdt(&curgdt);
  46. }
  47. static void load_segments(void)
  48. {
  49. #define __STR(X) #X
  50. #define STR(X) __STR(X)
  51. __asm__ __volatile__ (
  52. "\tljmp $"STR(__KERNEL_CS)",$1f\n"
  53. "\t1:\n"
  54. "\tmovl $"STR(__KERNEL_DS)",%%eax\n"
  55. "\tmovl %%eax,%%ds\n"
  56. "\tmovl %%eax,%%es\n"
  57. "\tmovl %%eax,%%fs\n"
  58. "\tmovl %%eax,%%gs\n"
  59. "\tmovl %%eax,%%ss\n"
  60. ::: "eax", "memory");
  61. #undef STR
  62. #undef __STR
  63. }
  64. /*
  65. * A architecture hook called to validate the
  66. * proposed image and prepare the control pages
  67. * as needed. The pages for KEXEC_CONTROL_CODE_SIZE
  68. * have been allocated, but the segments have yet
  69. * been copied into the kernel.
  70. *
  71. * Do what every setup is needed on image and the
  72. * reboot code buffer to allow us to avoid allocations
  73. * later.
  74. *
  75. * Currently nothing.
  76. */
  77. int machine_kexec_prepare(struct kimage *image)
  78. {
  79. return 0;
  80. }
  81. /*
  82. * Undo anything leftover by machine_kexec_prepare
  83. * when an image is freed.
  84. */
  85. void machine_kexec_cleanup(struct kimage *image)
  86. {
  87. }
  88. /*
  89. * Do not allocate memory (or fail in any way) in machine_kexec().
  90. * We are past the point of no return, committed to rebooting now.
  91. */
  92. NORET_TYPE void machine_kexec(struct kimage *image)
  93. {
  94. unsigned long page_list[PAGES_NR];
  95. void *control_page;
  96. tracer_disable();
  97. /* Interrupts aren't acceptable while we reboot */
  98. local_irq_disable();
  99. control_page = page_address(image->control_code_page);
  100. memcpy(control_page, relocate_kernel, PAGE_SIZE);
  101. page_list[PA_CONTROL_PAGE] = __pa(control_page);
  102. page_list[VA_CONTROL_PAGE] = (unsigned long)relocate_kernel;
  103. page_list[PA_PGD] = __pa(kexec_pgd);
  104. page_list[VA_PGD] = (unsigned long)kexec_pgd;
  105. #ifdef CONFIG_X86_PAE
  106. page_list[PA_PMD_0] = __pa(kexec_pmd0);
  107. page_list[VA_PMD_0] = (unsigned long)kexec_pmd0;
  108. page_list[PA_PMD_1] = __pa(kexec_pmd1);
  109. page_list[VA_PMD_1] = (unsigned long)kexec_pmd1;
  110. #endif
  111. page_list[PA_PTE_0] = __pa(kexec_pte0);
  112. page_list[VA_PTE_0] = (unsigned long)kexec_pte0;
  113. page_list[PA_PTE_1] = __pa(kexec_pte1);
  114. page_list[VA_PTE_1] = (unsigned long)kexec_pte1;
  115. /* The segment registers are funny things, they have both a
  116. * visible and an invisible part. Whenever the visible part is
  117. * set to a specific selector, the invisible part is loaded
  118. * with from a table in memory. At no other time is the
  119. * descriptor table in memory accessed.
  120. *
  121. * I take advantage of this here by force loading the
  122. * segments, before I zap the gdt with an invalid value.
  123. */
  124. load_segments();
  125. /* The gdt & idt are now invalid.
  126. * If you want to load them you must set up your own idt & gdt.
  127. */
  128. set_gdt(phys_to_virt(0),0);
  129. set_idt(phys_to_virt(0),0);
  130. /* now call it */
  131. relocate_kernel((unsigned long)image->head, (unsigned long)page_list,
  132. image->start, cpu_has_pae);
  133. }
  134. void arch_crash_save_vmcoreinfo(void)
  135. {
  136. #ifdef CONFIG_NUMA
  137. VMCOREINFO_SYMBOL(node_data);
  138. VMCOREINFO_LENGTH(node_data, MAX_NUMNODES);
  139. #endif
  140. #ifdef CONFIG_X86_PAE
  141. VMCOREINFO_CONFIG(X86_PAE);
  142. #endif
  143. }