x86-32, hibernate: Switch to relocated restore code during resume on 32bit system
authorZhimin Gu <kookoo.gu@intel.com>
Fri, 21 Sep 2018 06:28:22 +0000 (14:28 +0800)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 3 Oct 2018 09:56:34 +0000 (11:56 +0200)
On 64bit system, code should be executed in a safe page
during page restoring, as the page where instruction is
running during resume might be scribbled and causes issues.

Although on 32 bit, we only suspend resuming by same kernel
that did the suspend, we'd like to remove that restriction
in the future.

Porting corresponding code from
64bit system: Allocate a safe page, and copy the restore
code to it, then jump to the safe page to run the code.

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>
arch/x86/power/hibernate.c
arch/x86/power/hibernate_32.c
arch/x86/power/hibernate_asm_32.S

index 4935b8139229679f722e9d59f42e8a92f8d33723..7383cb67ffd71f90b68b55042914305bbd2a4cb2 100644 (file)
@@ -212,7 +212,6 @@ int arch_hibernation_header_restore(void *addr)
        return 0;
 }
 
-#ifdef CONFIG_X86_64
 int relocate_restore_code(void)
 {
        pgd_t *pgd;
@@ -251,4 +250,3 @@ out:
        __flush_tlb_all();
        return 0;
 }
-#endif
index a44bdada4e4e9da83b7a6a0716556c74fe861f38..a9861095fbb85a2bf823a7bda562192ae342f5ad 100644 (file)
@@ -158,6 +158,10 @@ asmlinkage int swsusp_arch_resume(void)
 
        temp_pgt = __pa(resume_pg_dir);
 
+       error = relocate_restore_code();
+       if (error)
+               return error;
+
        /* We have got enough memory and from now on we cannot recover */
        restore_image();
        return 0;
index 6b2b94937113f85f577a9aba7278499fe1c38103..e9adda6b6b022640127947b40f0876e92877a9a7 100644 (file)
@@ -39,6 +39,13 @@ ENTRY(restore_image)
        movl    restore_cr3, %ebp
 
        movl    mmu_cr4_features, %ecx
+
+       /* jump to relocated restore code */
+       movl    relocated_restore_code, %eax
+       jmpl    *%eax
+
+/* code below has been relocated to a safe page */
+ENTRY(core_restore_code)
        movl    temp_pgt, %eax
        movl    %eax, %cr3