Skip to contentSkip to conversation

x86/S3: Drop {save, restore}_rest_processor_state() completely

PATCH In review Andrew Cooper 2 participants 6 messages Apr 29, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/S3: Drop {save, restore}_rest_processor_state() completely

There is no need to save/restore FS/GS/XCR0 state. It will be handled suitably on the context switch away from the idle.

The CR4 restoration in restore_rest_processor_state() was actually fighting later code in enter_state() which tried to keep CR4.MCE clear until everything was set up. Delete the intermediate restoration, and defer final restoration until after MCE is reconfigured.

Changing PAT should be done before paging is enabled. Move it into the trampoline during setup for 64bit.

The only remaing piece of restoration is load_system_tables(), so suspend.c can be deleted in its entirety.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monne <[email protected]>

---
 xen/arch/x86/acpi/Makefile      |  2 +-
 xen/arch/x86/acpi/power.c       |  9 ++++----
 xen/arch/x86/acpi/suspend.c     | 49 -----------------------------------------
 xen/arch/x86/acpi/wakeup_prot.S |  4 +---
 xen/arch/x86/boot/trampoline.S  |  5 +++++
 5 files changed, 11 insertions(+), 58 deletions(-)
 delete mode 100644 xen/arch/x86/acpi/suspend.c
xen/arch/x86/acpi/Makefile +1 -1
index 1b9e625713..041377e2bb 100644
@@ -1,4 +1,4 @@
 obj-y += cpufreq/
 
-obj-y += lib.o power.o suspend.o cpu_idle.o cpuidle_menu.o
+obj-y += lib.o power.o cpu_idle.o cpuidle_menu.o
 obj-bin-y += boot.init.o wakeup_prot.o
xen/arch/x86/acpi/power.c +4 -5
index 6dfd4c7891..0cda362045 100644
@@ -195,7 +195,6 @@ static int enter_state(u32 state)
     unsigned long flags;
     int error;
     struct cpu_info *ci;
-    unsigned long cr4;
 
     if ( (state <= ACPI_STATE_S0) || (state > ACPI_S_STATES_MAX) )
         return -EINVAL;
@@ -270,15 +269,15 @@ static int enter_state(u32 state)
 
     system_state = SYS_STATE_resume;
 
-    /* Restore CR4 and EFER from cached values. */
-    cr4 = read_cr4();
-    write_cr4(cr4 & ~X86_CR4_MCE);
+    /* Restore EFER from cached value. */
     write_efer(read_efer());
 
     device_power_up(SAVED_ALL);
 
     mcheck_init(&boot_cpu_data, false);
-    write_cr4(cr4);
+
+    /* Restore CR4 from cached value, now MCE is set up. */
+    write_cr4(read_cr4());
 
     printk(XENLOG_INFO "Finishing wakeup from ACPI S%d state.\n", state);
 
xen/arch/x86/acpi/suspend.c deleted +0 -49

49 lines not on this page · raw message

xen/arch/x86/acpi/wakeup_prot.S +1 -3
index 0ce96e26a9..4dba6020a7 100644
@@ -15,8 +15,6 @@ ENTRY(do_suspend_lowlevel)
         mov     %cr0, %rax
         mov     %rax, saved_cr0(%rip)
 
-        call    save_rest_processor_state
-
         /* enter sleep state physically */
         mov     $3, %edi
         call    acpi_enter_sleep_state
@@ -51,7 +49,7 @@ ENTRY(s3_resume)
         lretq
 1:
 
-        call restore_rest_processor_state
+        call    load_system_tables
 
 .Lsuspend_err:
         pop     %r15
xen/arch/x86/boot/trampoline.S +5 -0
index 18c6638924..662e6bdd3c 100644
@@ -91,6 +91,11 @@ trampoline_protmode_entry:
         and     %edi,%edx
         wrmsr
 1:
+        /* Set up PAT before enabling paging. */
+        mov     $XEN_MSR_PAT & 0xffffffff, %eax
+        mov     $XEN_MSR_PAT >> 32, %edx
+        mov     $MSR_IA32_CR_PAT, %ecx
+        wrmsr
 
         /* Set up EFER (Extended Feature Enable Register). */
         movl    $MSR_EFER,%ecx
Signature · 1 line
2.11.0
Reviewed-by on v1 1/1
#1 lore raw

Re: [PATCH] x86/S3: Drop {save,restore}_rest_processor_state() completely

xen/arch/x86/boot/trampoline.S trampoline_protmode_entry: · line 98

Quoted 11 lines · Andrew Cooper
xen/arch/x86/boot/trampoline.S +5 -0
@@ -91,6 +91,11 @@ trampoline_protmode_entry:
         and     %edi,%edx
         wrmsr
 1:
+        /* Set up PAT before enabling paging. */
+        mov     $XEN_MSR_PAT & 0xffffffff, %eax
+        mov     $XEN_MSR_PAT >> 32, %edx
+        mov     $MSR_IA32_CR_PAT, %ecx
+        wrmsr

Doesn't this also eliminate the need for cpu_init() doing this? If you agree with that one also dropped

Jan

#2 lore raw

Re: [PATCH] x86/S3: Drop {save,restore}_rest_processor_state() completely

Quoted 14 lines · Jan Beulich

xen/arch/x86/boot/trampoline.S trampoline_protmode_entry: · line 98

Quoted 11 lines · Andrew Cooper
xen/arch/x86/boot/trampoline.S +5 -0
@@ -91,6 +91,11 @@ trampoline_protmode_entry:
         and     %edi,%edx
         wrmsr
 1:
+        /* Set up PAT before enabling paging. */
+        mov     $XEN_MSR_PAT & 0xffffffff, %eax
+        mov     $XEN_MSR_PAT >> 32, %edx
+        mov     $MSR_IA32_CR_PAT, %ecx
+        wrmsr

Doesn't this also eliminate the need for cpu_init() doing this? If you agree with that one also dropped

Quoted 1 line

That doesn't cover the BSP on either the legacy or EFI paths.

~Andrew

#3 lore raw

Re: [PATCH] x86/S3: Drop {save,restore}_rest_processor_state() completely

Quoted 17 lines · Andrew Cooper
Quoted 14 lines · Jan Beulich

xen/arch/x86/boot/trampoline.S trampoline_protmode_entry: · line 98

Quoted 11 lines · Andrew Cooper
xen/arch/x86/boot/trampoline.S +5 -0
@@ -91,6 +91,11 @@ trampoline_protmode_entry:
         and     %edi,%edx
         wrmsr
 1:
+        /* Set up PAT before enabling paging. */
+        mov     $XEN_MSR_PAT & 0xffffffff, %eax
+        mov     $XEN_MSR_PAT >> 32, %edx
+        mov     $MSR_IA32_CR_PAT, %ecx
+        wrmsr

Doesn't this also eliminate the need for cpu_init() doing this? If you agree with that one also dropped

Quoted 1 line
Quoted 1 line

That doesn't cover the BSP on either the legacy or EFI paths.

The legacy path, afaict, uses it:

.Lskip_realmode:

        /* EBX == 0 indicates we are the BP (Boot Processor). */
        xor     %ebx,%ebx

        /* Jump to the common bootstrap entry point. */
        jmp     trampoline_protmode_entry

The xen.efi entry path really should have the change you make mirrored anyway.

Jan

#4 lore raw

Re: [PATCH] x86/S3: Drop {save,restore}_rest_processor_state() completely

Quoted 18 lines · Jan Beulich
Quoted 16 lines · Andrew Cooper
Quoted 14 lines · Jan Beulich

xen/arch/x86/boot/trampoline.S trampoline_protmode_entry: · line 98

Quoted 11 lines · Andrew Cooper
xen/arch/x86/boot/trampoline.S +5 -0
@@ -91,6 +91,11 @@ trampoline_protmode_entry:
         and     %edi,%edx
         wrmsr
 1:
+        /* Set up PAT before enabling paging. */
+        mov     $XEN_MSR_PAT & 0xffffffff, %eax
+        mov     $XEN_MSR_PAT >> 32, %edx
+        mov     $MSR_IA32_CR_PAT, %ecx
+        wrmsr

Doesn't this also eliminate the need for cpu_init() doing this? If you agree with that one also dropped

Quoted 1 line
Quoted 1 line

That doesn't cover the BSP on either the legacy or EFI paths.

Quoted 8 lines

The legacy path, afaict, uses it:

.Lskip_realmode:

        /* EBX == 0 indicates we are the BP (Boot Processor). */
        xor     %ebx,%ebx

        /* Jump to the common bootstrap entry point. */
        jmp     trampoline_protmode_entry

Oh, of course.

Quoted 2 lines

The xen.efi entry path really should have the change you make mirrored anyway.

Are you happy for it to go in efi_arch_post_exit_boot()?  We don't disable paging, but that is the point where we switch from the EFI pagetables to Xen's.

~Andrew

#5 lore raw

Re: [PATCH] x86/S3: Drop {save,restore}_rest_processor_state() completely

Quoted 28 lines · Andrew Cooper
Quoted 18 lines · Jan Beulich
Quoted 16 lines · Andrew Cooper
Quoted 14 lines · Jan Beulich

xen/arch/x86/boot/trampoline.S trampoline_protmode_entry: · line 98

Quoted 11 lines · Andrew Cooper
xen/arch/x86/boot/trampoline.S +5 -0
@@ -91,6 +91,11 @@ trampoline_protmode_entry:
         and     %edi,%edx
         wrmsr
 1:
+        /* Set up PAT before enabling paging. */
+        mov     $XEN_MSR_PAT & 0xffffffff, %eax
+        mov     $XEN_MSR_PAT >> 32, %edx
+        mov     $MSR_IA32_CR_PAT, %ecx
+        wrmsr

Doesn't this also eliminate the need for cpu_init() doing this? If you agree with that one also dropped

Quoted 1 line
Quoted 1 line

That doesn't cover the BSP on either the legacy or EFI paths.

Quoted 8 lines

The legacy path, afaict, uses it:

.Lskip_realmode:

        /* EBX == 0 indicates we are the BP (Boot Processor). */
        xor     %ebx,%ebx

        /* Jump to the common bootstrap entry point. */
        jmp     trampoline_protmode_entry
Quoted 8 lines

Oh, of course.

Quoted 2 lines

The xen.efi entry path really should have the change you make mirrored anyway.

Are you happy for it to go in efi_arch_post_exit_boot()?  We don't disable paging, but that is the point where we switch from the EFI pagetables to Xen's.

Yes, that's the most "symmetrical" place, I think.

Jan