Skip to content

Commit efa4d2f

Browse files
rjwysockiLinus Torvalds
authored andcommitted
Hibernation: Use temporary page tables for kernel text mapping on x86_64
Use temporary page tables for the kernel text mapping during hibernation restore on x86_64. Without the patch, the original boot kernel's page tables that represent the kernel text mapping are used while the core of the image kernel is being restored. However, in principle, if the boot kernel is not identical to the image kernel, the location of these page tables in the image kernel need not be the same, so we should create a safe copy of the kernel text mapping prior to restoring the core of the image kernel. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Acked-by: Pavel Machek <pavel@ucw.cz> Cc: Andi Kleen <ak@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent c30bb68 commit efa4d2f

1 file changed

Lines changed: 33 additions & 6 deletions

File tree

‎arch/x86/kernel/suspend_64.c‎

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,25 +197,42 @@ static int res_phys_pud_init(pud_t *pud, unsigned long address, unsigned long en
197197
return 0;
198198
}
199199

200+
static int res_kernel_text_pud_init(pud_t *pud, unsigned long start)
201+
{
202+
pmd_t *pmd;
203+
unsigned long paddr;
204+
205+
pmd = (pmd_t *)get_safe_page(GFP_ATOMIC);
206+
if (!pmd)
207+
return -ENOMEM;
208+
set_pud(pud + pud_index(start), __pud(__pa(pmd) | _KERNPG_TABLE));
209+
for (paddr = 0; paddr < KERNEL_TEXT_SIZE; pmd++, paddr += PMD_SIZE) {
210+
unsigned long pe;
211+
212+
pe = __PAGE_KERNEL_LARGE_EXEC | _PAGE_GLOBAL | paddr;
213+
pe &= __supported_pte_mask;
214+
set_pmd(pmd, __pmd(pe));
215+
}
216+
217+
return 0;
218+
}
219+
200220
static int set_up_temporary_mappings(void)
201221
{
202222
unsigned long start, end, next;
223+
pud_t *pud;
203224
int error;
204225

205226
temp_level4_pgt = (pgd_t *)get_safe_page(GFP_ATOMIC);
206227
if (!temp_level4_pgt)
207228
return -ENOMEM;
208229

209-
/* It is safe to reuse the original kernel mapping */
210-
set_pgd(temp_level4_pgt + pgd_index(__START_KERNEL_map),
211-
init_level4_pgt[pgd_index(__START_KERNEL_map)]);
212-
213230
/* Set up the direct mapping from scratch */
214231
start = (unsigned long)pfn_to_kaddr(0);
215232
end = (unsigned long)pfn_to_kaddr(end_pfn);
216233

217234
for (; start < end; start = next) {
218-
pud_t *pud = (pud_t *)get_safe_page(GFP_ATOMIC);
235+
pud = (pud_t *)get_safe_page(GFP_ATOMIC);
219236
if (!pud)
220237
return -ENOMEM;
221238
next = start + PGDIR_SIZE;
@@ -226,7 +243,17 @@ static int set_up_temporary_mappings(void)
226243
set_pgd(temp_level4_pgt + pgd_index(start),
227244
mk_kernel_pgd(__pa(pud)));
228245
}
229-
return 0;
246+
247+
/* Set up the kernel text mapping from scratch */
248+
pud = (pud_t *)get_safe_page(GFP_ATOMIC);
249+
if (!pud)
250+
return -ENOMEM;
251+
error = res_kernel_text_pud_init(pud, __START_KERNEL_map);
252+
if (!error)
253+
set_pgd(temp_level4_pgt + pgd_index(__START_KERNEL_map),
254+
__pgd(__pa(pud) | _PAGE_TABLE));
255+
256+
return error;
230257
}
231258

232259
int swsusp_arch_resume(void)

0 commit comments

Comments
 (0)