Skip to content

Commit c30bb68

Browse files
rjwysockiLinus Torvalds
authored andcommitted
Hibernation: Pass CR3 in the image header on x86_64
Since we already pass the address of restore_registers() in the image header, we can also pass the value of the CR3 register from before the hibernation in the same way. This will allow us to avoid using init_level4_pgt page tables during the restore. 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 d158cbd commit c30bb68

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

‎arch/x86/kernel/suspend_64.c‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ extern int restore_image(void);
156156
*/
157157
unsigned long restore_jump_address;
158158

159+
/*
160+
* Value of the cr3 register from before the hibernation (this value is passed
161+
* in the image header).
162+
*/
163+
unsigned long restore_cr3;
164+
159165
pgd_t *temp_level4_pgt;
160166

161167
void *relocated_restore_code;
@@ -254,7 +260,8 @@ int pfn_is_nosave(unsigned long pfn)
254260

255261
struct restore_data_record {
256262
unsigned long jump_address;
257-
unsigned long control;
263+
unsigned long cr3;
264+
unsigned long magic;
258265
};
259266

260267
#define RESTORE_MAGIC 0x0123456789ABCDEFUL
@@ -271,7 +278,8 @@ int arch_hibernation_header_save(void *addr, unsigned int max_size)
271278
if (max_size < sizeof(struct restore_data_record))
272279
return -EOVERFLOW;
273280
rdr->jump_address = restore_jump_address;
274-
rdr->control = (restore_jump_address ^ RESTORE_MAGIC);
281+
rdr->cr3 = restore_cr3;
282+
rdr->magic = RESTORE_MAGIC;
275283
return 0;
276284
}
277285

@@ -285,7 +293,7 @@ int arch_hibernation_header_restore(void *addr)
285293
struct restore_data_record *rdr = addr;
286294

287295
restore_jump_address = rdr->jump_address;
288-
return (rdr->control == (restore_jump_address ^ RESTORE_MAGIC)) ?
289-
0 : -EINVAL;
296+
restore_cr3 = rdr->cr3;
297+
return (rdr->magic == RESTORE_MAGIC) ? 0 : -EINVAL;
290298
}
291299
#endif /* CONFIG_HIBERNATION */

‎arch/x86/kernel/suspend_asm_64.S‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ ENTRY(swsusp_arch_suspend)
3939
/* save the address of restore_registers */
4040
movq $restore_registers, %rax
4141
movq %rax, restore_jump_address(%rip)
42+
/* save cr3 */
43+
movq %cr3, %rax
44+
movq %rax, restore_cr3(%rip)
4245

4346
call swsusp_save
4447
ret
@@ -60,6 +63,7 @@ ENTRY(restore_image)
6063

6164
/* prepare to jump to the image kernel */
6265
movq restore_jump_address(%rip), %rax
66+
movq restore_cr3(%rip), %rbx
6367

6468
/* prepare to copy image data to their original locations */
6569
movq restore_pblist(%rip), %rdx
@@ -98,9 +102,7 @@ done:
98102

99103
ENTRY(restore_registers)
100104
/* go back to the original page tables */
101-
movq $(init_level4_pgt - __START_KERNEL_map), %rax
102-
addq phys_base(%rip), %rax
103-
movq %rax, %cr3
105+
movq %rbx, %cr3
104106

105107
/* Flush TLB, including "global" things (vmalloc) */
106108
movq mmu_cr4_features(%rip), %rax

0 commit comments

Comments
 (0)