diff options
| author | Huang Ying <ying.huang@intel.com> | 2008-10-30 21:48:15 -0400 |
|---|---|---|
| committer | Ingo Molnar <mingo@elte.hu> | 2008-10-31 05:01:57 -0400 |
| commit | 9868ee63b896ee4d2ceb8c292e88d7f4e66caaf9 (patch) | |
| tree | 688fff3c2f44fa260a3a05589fa8b7529ddc9fb8 | |
| parent | 92be3d6bdf2cb34972ab50e12ad4da1076e690da (diff) | |
kexec/i386: setup kexec page table in C
Impact: change the kexec bootstrap code implementation from assembly to C
This patch transforms the kexec page tables setup code from assembler
code to C code in machine_kexec_prepare. This improves readability and
reduces code line number.
Signed-off-by: Huang Ying <ying.huang@intel.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
| -rw-r--r-- | arch/x86/include/asm/kexec.h | 17 | ||||
| -rw-r--r-- | arch/x86/kernel/machine_kexec_32.c | 59 | ||||
| -rw-r--r-- | arch/x86/kernel/relocate_kernel_32.S | 114 |
3 files changed, 49 insertions, 141 deletions
diff --git a/arch/x86/include/asm/kexec.h b/arch/x86/include/asm/kexec.h index df9c41a9c6a..c61d8b2ab8b 100644 --- a/arch/x86/include/asm/kexec.h +++ b/arch/x86/include/asm/kexec.h | |||
| @@ -5,21 +5,8 @@ | |||
| 5 | # define PA_CONTROL_PAGE 0 | 5 | # define PA_CONTROL_PAGE 0 |
| 6 | # define VA_CONTROL_PAGE 1 | 6 | # define VA_CONTROL_PAGE 1 |
| 7 | # define PA_PGD 2 | 7 | # define PA_PGD 2 |
| 8 | # define VA_PGD 3 | 8 | # define PA_SWAP_PAGE 3 |
| 9 | # define PA_PTE_0 4 | 9 | # define PAGES_NR 4 |
| 10 | # define VA_PTE_0 5 | ||
| 11 | # define PA_PTE_1 6 | ||
| 12 | # define VA_PTE_1 7 | ||
| 13 | # define PA_SWAP_PAGE 8 | ||
| 14 | # ifdef CONFIG_X86_PAE | ||
| 15 | # define PA_PMD_0 9 | ||
| 16 | # define VA_PMD_0 10 | ||
| 17 | # define PA_PMD_1 11 | ||
| 18 | # define VA_PMD_1 12 | ||
| 19 | # define PAGES_NR 13 | ||
| 20 | # else | ||
| 21 | # define PAGES_NR 9 | ||
| 22 | # endif | ||
| 23 | #else | 10 | #else |
| 24 | # define PA_CONTROL_PAGE 0 | 11 | # define PA_CONTROL_PAGE 0 |
| 25 | # define VA_CONTROL_PAGE 1 | 12 | # define VA_CONTROL_PAGE 1 |
diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c index 1100312847a..37f420018a4 100644 --- a/arch/x86/kernel/machine_kexec_32.c +++ b/arch/x86/kernel/machine_kexec_32.c | |||
| @@ -99,6 +99,45 @@ static int machine_kexec_alloc_page_tables(struct kimage *image) | |||
| 99 | return 0; | 99 | return 0; |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | static void machine_kexec_page_table_set_one( | ||
| 103 | pgd_t *pgd, pmd_t *pmd, pte_t *pte, | ||
| 104 | unsigned long vaddr, unsigned long paddr) | ||
| 105 | { | ||
| 106 | pud_t *pud; | ||
| 107 | |||
| 108 | pgd += pgd_index(vaddr); | ||
| 109 | #ifdef CONFIG_X86_PAE | ||
| 110 | if (!(pgd_val(*pgd) & _PAGE_PRESENT)) | ||
| 111 | set_pgd(pgd, __pgd(__pa(pmd) | _PAGE_PRESENT)); | ||
| 112 | #endif | ||
| 113 | pud = pud_offset(pgd, vaddr); | ||
| 114 | pmd = pmd_offset(pud, vaddr); | ||
| 115 | if (!(pmd_val(*pmd) & _PAGE_PRESENT)) | ||
| 116 | set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE)); | ||
| 117 | pte = pte_offset_kernel(pmd, vaddr); | ||
| 118 | set_pte(pte, pfn_pte(paddr >> PAGE_SHIFT, PAGE_KERNEL_EXEC)); | ||
| 119 | } | ||
| 120 | |||
| 121 | static void machine_kexec_prepare_page_tables(struct kimage *image) | ||
| 122 | { | ||
| 123 | void *control_page; | ||
| 124 | pmd_t *pmd = 0; | ||
| 125 | |||
| 126 | control_page = page_address(image->control_code_page); | ||
| 127 | #ifdef CONFIG_X86_PAE | ||
| 128 | pmd = image->arch.pmd0; | ||
| 129 | #endif | ||
| 130 | machine_kexec_page_table_set_one( | ||
| 131 | image->arch.pgd, pmd, image->arch.pte0, | ||
| 132 | (unsigned long)control_page, __pa(control_page)); | ||
| 133 | #ifdef CONFIG_X86_PAE | ||
| 134 | pmd = image->arch.pmd1; | ||
| 135 | #endif | ||
| 136 | machine_kexec_page_table_set_one( | ||
| 137 | image->arch.pgd, pmd, image->arch.pte1, | ||
| 138 | __pa(control_page), __pa(control_page)); | ||
| 139 | } | ||
| 140 | |||
| 102 | /* | 141 | /* |
| 103 | * A architecture hook called to validate the | 142 | * A architecture hook called to validate the |
| 104 | * proposed image and prepare the control pages | 143 | * proposed image and prepare the control pages |
| @@ -112,12 +151,19 @@ static int machine_kexec_alloc_page_tables(struct kimage *image) | |||
| 112 | * | 151 | * |
| 113 | * - Make control page executable. | 152 | * - Make control page executable. |
| 114 | * - Allocate page tables | 153 | * - Allocate page tables |
| 154 | * - Setup page tables | ||
| 115 | */ | 155 | */ |
| 116 | int machine_kexec_prepare(struct kimage *image) | 156 | int machine_kexec_prepare(struct kimage *image) |
| 117 | { | 157 | { |
| 158 | int error; | ||
| 159 | |||
| 118 | if (nx_enabled) | 160 | if (nx_enabled) |
| 119 | set_pages_x(image->control_code_page, 1); | 161 | set_pages_x(image->control_code_page, 1); |
| 120 | return machine_kexec_alloc_page_tables(image); | 162 | error = machine_kexec_alloc_page_tables(image); |
| 163 | if (error) | ||
| 164 | return error; | ||
| 165 | machine_kexec_prepare_page_tables(image); | ||
| 166 | return 0; | ||
| 121 | } | 167 | } |
| 122 | 168 | ||
| 123 | /* | 169 | /* |
| @@ -176,17 +222,6 @@ void machine_kexec(struct kimage *image) | |||
| 176 | page_list[PA_CONTROL_PAGE] = __pa(control_page); | 222 | page_list[PA_CONTROL_PAGE] = __pa(control_page); |
| 177 | page_list[VA_CONTROL_PAGE] = (unsigned long)control_page; | 223 | page_list[VA_CONTROL_PAGE] = (unsigned long)control_page; |
| 178 | page_list[PA_PGD] = __pa(image->arch.pgd); | 224 | page_list[PA_PGD] = __pa(image->arch.pgd); |
| 179 | page_list[VA_PGD] = (unsigned long)image->arch.pgd; | ||
| 180 | #ifdef CONFIG_X86_PAE | ||
| 181 | page_list[PA_PMD_0] = __pa(image->arch.pmd0); | ||
| 182 | page_list[VA_PMD_0] = (unsigned long)image->arch.pmd0; | ||
| 183 | page_list[PA_PMD_1] = __pa(image->arch.pmd1); | ||
| 184 | page_list[VA_PMD_1] = (unsigned long)image->arch.pmd1; | ||
| 185 | #endif | ||
| 186 | page_list[PA_PTE_0] = __pa(image->arch.pte0); | ||
| 187 | page_list[VA_PTE_0] = (unsigned long)image->arch.pte0; | ||
| 188 | page_list[PA_PTE_1] = __pa(image->arch.pte1); | ||
| 189 | page_list[VA_PTE_1] = (unsigned long)image->arch.pte1; | ||
| 190 | 225 | ||
| 191 | if (image->type == KEXEC_TYPE_DEFAULT) | 226 | if (image->type == KEXEC_TYPE_DEFAULT) |
| 192 | page_list[PA_SWAP_PAGE] = (page_to_pfn(image->swap_page) | 227 | page_list[PA_SWAP_PAGE] = (page_to_pfn(image->swap_page) |
diff --git a/arch/x86/kernel/relocate_kernel_32.S b/arch/x86/kernel/relocate_kernel_32.S index 377da3f78e8..a160f311972 100644 --- a/arch/x86/kernel/relocate_kernel_32.S +++ b/arch/x86/kernel/relocate_kernel_32.S | |||
| @@ -10,15 +10,12 @@ | |||
| 10 | #include <asm/page.h> | 10 | #include <asm/page.h> |
| 11 | #include <asm/kexec.h> | 11 | #include <asm/kexec.h> |
| 12 | #include <asm/processor-flags.h> | 12 | #include <asm/processor-flags.h> |
| 13 | #include <asm/pgtable.h> | ||
| 14 | 13 | ||
| 15 | /* | 14 | /* |
| 16 | * Must be relocatable PIC code callable as a C function | 15 | * Must be relocatable PIC code callable as a C function |
| 17 | */ | 16 | */ |
| 18 | 17 | ||
| 19 | #define PTR(x) (x << 2) | 18 | #define PTR(x) (x << 2) |
| 20 | #define PAGE_ATTR (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | _PAGE_DIRTY) | ||
| 21 | #define PAE_PGD_ATTR (_PAGE_PRESENT) | ||
| 22 | 19 | ||
| 23 | /* control_page + KEXEC_CONTROL_CODE_MAX_SIZE | 20 | /* control_page + KEXEC_CONTROL_CODE_MAX_SIZE |
| 24 | * ~ control_page + PAGE_SIZE are used as data storage and stack for | 21 | * ~ control_page + PAGE_SIZE are used as data storage and stack for |
| @@ -59,117 +56,6 @@ relocate_kernel: | |||
| 59 | movl %cr4, %eax | 56 | movl %cr4, %eax |
| 60 | movl %eax, CR4(%edi) | 57 | movl %eax, CR4(%edi) |
| 61 | 58 | ||
| 62 | #ifdef CONFIG_X86_PAE | ||
| 63 | /* map the control page at its virtual address */ | ||
| 64 | |||
| 65 | movl PTR(VA_PGD)(%ebp), %edi | ||
| 66 | movl PTR(VA_CONTROL_PAGE)(%ebp), %eax | ||
| 67 | andl $0xc0000000, %eax | ||
| 68 | shrl $27, %eax | ||
| 69 | addl %edi, %eax | ||
| 70 | |||
| 71 | movl PTR(PA_PMD_0)(%ebp), %edx | ||
| 72 | orl $PAE_PGD_ATTR, %edx | ||
| 73 | movl %edx, (%eax) | ||
| 74 | |||
| 75 | movl PTR(VA_PMD_0)(%ebp), %edi | ||
| 76 | movl PTR(VA_CONTROL_PAGE)(%ebp), %eax | ||
| 77 | andl $0x3fe00000, %eax | ||
| 78 | shrl $18, %eax | ||
| 79 | addl %edi, %eax | ||
| 80 | |||
| 81 | movl PTR(PA_PTE_0)(%ebp), %edx | ||
| 82 | orl $PAGE_ATTR, %edx | ||
| 83 | movl %edx, (%eax) | ||
| 84 | |||
| 85 | movl PTR(VA_PTE_0)(%ebp), %edi | ||
| 86 | movl PTR(VA_CONTROL_PAGE)(%ebp), %eax | ||
| 87 | andl $0x001ff000, %eax | ||
| 88 | shrl $9, %eax | ||
| 89 | addl %edi, %eax | ||
| 90 | |||
| 91 | movl PTR(PA_CONTROL_PAGE)(%ebp), %edx | ||
| 92 | orl $PAGE_ATTR, %edx | ||
| 93 | movl %edx, (%eax) | ||
| 94 | |||
| 95 | /* identity map the control page at its physical address */ | ||
| 96 | |||
| 97 | movl PTR(VA_PGD)(%ebp), %edi | ||
| 98 | movl PTR(PA_CONTROL_PAGE)(%ebp), %eax | ||
| 99 | andl $0xc0000000, %eax | ||
| 100 | shrl $27, %eax | ||
| 101 | addl %edi, %eax | ||
| 102 | |||
| 103 | movl PTR(PA_PMD_1)(%ebp), %edx | ||
| 104 | orl $PAE_PGD_ATTR, %edx | ||
| 105 | movl %edx, (%eax) | ||
| 106 | |||
| 107 | movl PTR(VA_PMD_1)(%ebp), %edi | ||
| 108 | movl PTR(PA_CONTROL_PAGE)(%ebp), %eax | ||
| 109 | andl $0x3fe00000, %eax | ||
| 110 | shrl $18, %eax | ||
| 111 | addl %edi, %eax | ||
| 112 | |||
| 113 | movl PTR(PA_PTE_1)(%ebp), %edx | ||
| 114 | orl $PAGE_ATTR, %edx | ||
| 115 | movl %edx, (%eax) | ||
| 116 | |||
| 117 | movl PTR(VA_PTE_1)(%ebp), %edi | ||
| 118 | movl PTR(PA_CONTROL_PAGE)(%ebp), %eax | ||
| 119 | andl $0x001ff000, %eax | ||
| 120 | shrl $9, %eax | ||
| 121 | addl %edi, %eax | ||
| 122 | |||
| 123 | movl PTR(PA_CONTROL_PAGE)(%ebp), %edx | ||
| 124 | orl $PAGE_ATTR, %edx | ||
| 125 | movl %edx, (%eax) | ||
| 126 | #else | ||
| 127 | /* map the control page at its virtual address */ | ||
| 128 | |||
| 129 | movl PTR(VA_PGD)(%ebp), %edi | ||
| 130 | movl PTR(VA_CONTROL_PAGE)(%ebp), %eax | ||
| 131 | andl $0xffc00000, %eax | ||
| 132 | shrl $20, %eax | ||
| 133 | addl %edi, %eax | ||
| 134 | |||
| 135 | movl PTR(PA_PTE_0)(%ebp), %edx | ||
| 136 | orl $PAGE_ATTR, %edx | ||
| 137 | movl %edx, (%eax) | ||
| 138 | |||
| 139 | movl PTR(VA_PTE_0)(%ebp), %edi | ||
| 140 | movl PTR(VA_CONTROL_PAGE)(%ebp), %eax | ||
| 141 | andl $0x003ff000, %eax | ||
| 142 | shrl $10, %eax | ||
| 143 | addl %edi, %eax | ||
| 144 | |||
| 145 | movl PTR(PA_CONTROL_PAGE)(%ebp), %edx | ||
| 146 | orl $PAGE_ATTR, %edx | ||
| 147 | movl %edx, (%eax) | ||
| 148 | |||
| 149 | /* identity map the control page at its physical address */ | ||
| 150 | |||
| 151 | movl PTR(VA_PGD)(%ebp), %edi | ||
| 152 | movl PTR(PA_CONTROL_PAGE)(%ebp), %eax | ||
| 153 | andl $0xffc00000, %eax | ||
| 154 | shrl $20, %eax | ||
| 155 | addl %edi, %eax | ||
| 156 | |||
| 157 | movl PTR(PA_PTE_1)(%ebp), %edx | ||
| 158 | orl $PAGE_ATTR, %edx | ||
| 159 | movl %edx, (%eax) | ||
| 160 | |||
| 161 | movl PTR(VA_PTE_1)(%ebp), %edi | ||
| 162 | movl PTR(PA_CONTROL_PAGE)(%ebp), %eax | ||
| 163 | andl $0x003ff000, %eax | ||
| 164 | shrl $10, %eax | ||
| 165 | addl %edi, %eax | ||
| 166 | |||
| 167 | movl PTR(PA_CONTROL_PAGE)(%ebp), %edx | ||
| 168 | orl $PAGE_ATTR, %edx | ||
| 169 | movl %edx, (%eax) | ||
| 170 | #endif | ||
| 171 | |||
| 172 | relocate_new_kernel: | ||
| 173 | /* read the arguments and say goodbye to the stack */ | 59 | /* read the arguments and say goodbye to the stack */ |
| 174 | movl 20+4(%esp), %ebx /* page_list */ | 60 | movl 20+4(%esp), %ebx /* page_list */ |
| 175 | movl 20+8(%esp), %ebp /* list of pages */ | 61 | movl 20+8(%esp), %ebp /* list of pages */ |
