summaryrefslogtreecommitdiffstats
path: root/arch/x86/power
diff options
context:
space:
mode:
authorZhimin Gu <kookoo.gu@intel.com>2018-09-21 02:28:32 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2018-10-03 05:56:34 -0400
commit5331d2c7efbccab436aa11639d7fa00a1d58abe2 (patch)
treebdfbb771fe84707394cf5c91d3015bf59c4dc786 /arch/x86/power
parent6bae499a0ad437efb67b7c378e6fb4abef1885a1 (diff)
x86-32, hibernate: Set up temporary text mapping for 32bit system
Set up the temporary text mapping for the final jump address so that the system could jump to the right address after all the pages have been copied back to their original address - otherwise the final mapping for the jump address is invalid. Analogous changes were made for 64-bit in commit 65c0554b73c9 (x86/power/64: Fix kernel text mapping corruption during image restoration). Signed-off-by: Zhimin Gu <kookoo.gu@intel.com> Acked-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Chen Yu <yu.c.chen@intel.com> Acked-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'arch/x86/power')
-rw-r--r--arch/x86/power/hibernate.c4
-rw-r--r--arch/x86/power/hibernate_32.c31
-rw-r--r--arch/x86/power/hibernate_asm_32.S3
3 files changed, 34 insertions, 4 deletions
diff --git a/arch/x86/power/hibernate.c b/arch/x86/power/hibernate.c
index 7383cb67ffd7..bcddf09b5aa3 100644
--- a/arch/x86/power/hibernate.c
+++ b/arch/x86/power/hibernate.c
@@ -157,10 +157,8 @@ int arch_hibernation_header_save(void *addr, unsigned int max_size)
157 if (max_size < sizeof(struct restore_data_record)) 157 if (max_size < sizeof(struct restore_data_record))
158 return -EOVERFLOW; 158 return -EOVERFLOW;
159 rdr->magic = RESTORE_MAGIC; 159 rdr->magic = RESTORE_MAGIC;
160#ifdef CONFIG_X86_64
161 rdr->jump_address = (unsigned long)restore_registers; 160 rdr->jump_address = (unsigned long)restore_registers;
162 rdr->jump_address_phys = __pa_symbol(restore_registers); 161 rdr->jump_address_phys = __pa_symbol(restore_registers);
163#endif
164 162
165 /* 163 /*
166 * The restore code fixes up CR3 and CR4 in the following sequence: 164 * The restore code fixes up CR3 and CR4 in the following sequence:
@@ -198,10 +196,8 @@ int arch_hibernation_header_restore(void *addr)
198 return -EINVAL; 196 return -EINVAL;
199 } 197 }
200 198
201#ifdef CONFIG_X86_64
202 restore_jump_address = rdr->jump_address; 199 restore_jump_address = rdr->jump_address;
203 jump_address_phys = rdr->jump_address_phys; 200 jump_address_phys = rdr->jump_address_phys;
204#endif
205 restore_cr3 = rdr->cr3; 201 restore_cr3 = rdr->cr3;
206 202
207 if (hibernation_e820_mismatch(rdr->e820_digest)) { 203 if (hibernation_e820_mismatch(rdr->e820_digest)) {
diff --git a/arch/x86/power/hibernate_32.c b/arch/x86/power/hibernate_32.c
index a9861095fbb8..15695e30f982 100644
--- a/arch/x86/power/hibernate_32.c
+++ b/arch/x86/power/hibernate_32.c
@@ -143,6 +143,32 @@ static inline void resume_init_first_level_page_table(pgd_t *pg_dir)
143#endif 143#endif
144} 144}
145 145
146static int set_up_temporary_text_mapping(pgd_t *pgd_base)
147{
148 pgd_t *pgd;
149 pmd_t *pmd;
150 pte_t *pte;
151
152 pgd = pgd_base + pgd_index(restore_jump_address);
153
154 pmd = resume_one_md_table_init(pgd);
155 if (!pmd)
156 return -ENOMEM;
157
158 if (boot_cpu_has(X86_FEATURE_PSE)) {
159 set_pmd(pmd + pmd_index(restore_jump_address),
160 __pmd((jump_address_phys & PMD_MASK) | pgprot_val(PAGE_KERNEL_LARGE_EXEC)));
161 } else {
162 pte = resume_one_page_table_init(pmd);
163 if (!pte)
164 return -ENOMEM;
165 set_pte(pte + pte_index(restore_jump_address),
166 __pte((jump_address_phys & PAGE_MASK) | pgprot_val(PAGE_KERNEL_EXEC)));
167 }
168
169 return 0;
170}
171
146asmlinkage int swsusp_arch_resume(void) 172asmlinkage int swsusp_arch_resume(void)
147{ 173{
148 int error; 174 int error;
@@ -152,6 +178,11 @@ asmlinkage int swsusp_arch_resume(void)
152 return -ENOMEM; 178 return -ENOMEM;
153 179
154 resume_init_first_level_page_table(resume_pg_dir); 180 resume_init_first_level_page_table(resume_pg_dir);
181
182 error = set_up_temporary_text_mapping(resume_pg_dir);
183 if (error)
184 return error;
185
155 error = resume_physical_mapping_init(resume_pg_dir); 186 error = resume_physical_mapping_init(resume_pg_dir);
156 if (error) 187 if (error)
157 return error; 188 return error;
diff --git a/arch/x86/power/hibernate_asm_32.S b/arch/x86/power/hibernate_asm_32.S
index e9adda6b6b02..01f653fae7bd 100644
--- a/arch/x86/power/hibernate_asm_32.S
+++ b/arch/x86/power/hibernate_asm_32.S
@@ -36,6 +36,8 @@ ENTRY(swsusp_arch_suspend)
36ENDPROC(swsusp_arch_suspend) 36ENDPROC(swsusp_arch_suspend)
37 37
38ENTRY(restore_image) 38ENTRY(restore_image)
39 /* prepare to jump to the image kernel */
40 movl restore_jump_address, %ebx
39 movl restore_cr3, %ebp 41 movl restore_cr3, %ebp
40 42
41 movl mmu_cr4_features, %ecx 43 movl mmu_cr4_features, %ecx
@@ -74,6 +76,7 @@ copy_loop:
74 .p2align 4,,7 76 .p2align 4,,7
75 77
76done: 78done:
79 jmpl *%ebx
77 80
78 /* code below belongs to the image kernel */ 81 /* code below belongs to the image kernel */
79 .align PAGE_SIZE 82 .align PAGE_SIZE